From 76539c1956b1d694dba2700326a915b0c64a3117 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Tue, 15 May 2012 09:34:24 +0700 Subject: Added generation of multipliers in 'gen'. --- src/base/abci/abc.c | 30 +++++-- src/base/abci/abcGen.c | 235 ++++++++++++++++++++++++++++--------------------- 2 files changed, 160 insertions(+), 105 deletions(-) (limited to 'src') diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 3e5d67c6..1b64803c 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -8443,14 +8443,17 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) int fAdder; int fSorter; int fMesh; + int fMulti; int fFpga; int fOneHot; int fRandom; int fVerbose; char * FileName; + char Command[1000]; extern void Abc_GenAdder( char * pFileName, int nVars ); extern void Abc_GenSorter( char * pFileName, int nVars ); extern void Abc_GenMesh( char * pFileName, int nVars ); + extern void Abc_GenMulti( char * pFileName, int nVars ); extern void Abc_GenFpga( char * pFileName, int nLutSize, int nLuts, int nVars ); extern void Abc_GenOneHot( char * pFileName, int nVars ); extern void Abc_GenRandom( char * pFileName, int nPis ); @@ -8460,12 +8463,13 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) fAdder = 0; fSorter = 0; fMesh = 0; + fMulti = 0; fFpga = 0; fOneHot = 0; fRandom = 0; fVerbose = 0; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "NKLasmftrvh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "NKLasemftrvh" ) ) != EOF ) { switch ( c ) { @@ -8508,9 +8512,12 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) case 's': fSorter ^= 1; break; - case 'm': + case 'e': fMesh ^= 1; break; + case 'm': + fMulti ^= 1; + break; case 'f': fFpga ^= 1; break; @@ -8534,7 +8541,11 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) { goto usage; } - + if ( nVars < 1 ) + { + Abc_Print( -1, "The number of variables should be a positive integer.\n" ); + return 0; + } // get the input file name FileName = argv[globalUtilOptind]; if ( fAdder ) @@ -8543,6 +8554,8 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_GenSorter( FileName, nVars ); else if ( fMesh ) Abc_GenMesh( FileName, nVars ); + else if ( fMulti ) + Abc_GenMulti( FileName, nVars ); else if ( fFpga ) Abc_GenFpga( FileName, nLutSize, nLuts, nVars ); // Abc_GenFpga( FileName, 2, 2, 3 ); @@ -8552,18 +8565,25 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) else if ( fRandom ) Abc_GenRandom( FileName, nVars ); else + { Abc_Print( -1, "Type of circuit is not specified.\n" ); + return 0; + } + // read the file just produced + sprintf( Command, "read %s", FileName ); + Cmd_CommandExecute( pAbc, Command ); return 0; usage: - Abc_Print( -2, "usage: gen [-NKL num] [-asmftrvh] \n" ); + Abc_Print( -2, "usage: gen [-NKL num] [-asemftrvh] \n" ); Abc_Print( -2, "\t generates simple circuits\n" ); Abc_Print( -2, "\t-N num : the number of variables [default = %d]\n", nVars ); Abc_Print( -2, "\t-K num : the LUT size (to be used with switch -f) [default = %d]\n", nLutSize ); Abc_Print( -2, "\t-L num : the LUT count (to be used with switch -f) [default = %d]\n", nLuts ); Abc_Print( -2, "\t-a : generate ripple-carry adder [default = %s]\n", fAdder? "yes": "no" ); Abc_Print( -2, "\t-s : generate a sorter [default = %s]\n", fSorter? "yes": "no" ); - Abc_Print( -2, "\t-m : generate a mesh [default = %s]\n", fMesh? "yes": "no" ); + Abc_Print( -2, "\t-e : generate a mesh [default = %s]\n", fMesh? "yes": "no" ); + Abc_Print( -2, "\t-m : generate a multiplier [default = %s]\n", fMulti? "yes": "no" ); Abc_Print( -2, "\t-f : generate a LUT FPGA structure [default = %s]\n", fFpga? "yes": "no" ); Abc_Print( -2, "\t-t : generate one-hotness conditions [default = %s]\n", fOneHot? "yes": "no" ); Abc_Print( -2, "\t-r : generate random single-output function [default = %s]\n", fRandom? "yes": "no" ); diff --git a/src/base/abci/abcGen.c b/src/base/abci/abcGen.c index 55191021..4f3ef5bc 100644 --- a/src/base/abci/abcGen.c +++ b/src/base/abci/abcGen.c @@ -26,13 +26,6 @@ ABC_NAMESPACE_IMPL_START /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// -void Abc_WriteLayer( FILE * pFile, int nVars, int fSkip1 ); -void Abc_WriteComp( FILE * pFile ); -void Abc_WriteFullAdder( FILE * pFile ); - -void Abc_GenAdder( char * pFileName, int nVars ); -void Abc_GenSorter( char * pFileName, int nVars ); - //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// @@ -48,43 +41,64 @@ void Abc_GenSorter( char * pFileName, int nVars ); SeeAlso [] ***********************************************************************/ -void Abc_GenAdder( char * pFileName, int nVars ) +void Abc_WriteFullAdder( FILE * pFile ) { - FILE * pFile; - int i; + fprintf( pFile, ".model FA\n" ); + fprintf( pFile, ".inputs a b cin\n" ); + fprintf( pFile, ".outputs s cout\n" ); + fprintf( pFile, ".names a b k\n" ); + fprintf( pFile, "10 1\n" ); + fprintf( pFile, "01 1\n" ); + fprintf( pFile, ".names k cin s\n" ); + fprintf( pFile, "10 1\n" ); + fprintf( pFile, "01 1\n" ); + fprintf( pFile, ".names a b cin cout\n" ); + fprintf( pFile, "11- 1\n" ); + fprintf( pFile, "1-1 1\n" ); + fprintf( pFile, "-11 1\n" ); + fprintf( pFile, ".end\n" ); + fprintf( pFile, "\n" ); +} +void Abc_WriteAdder( FILE * pFile, int nVars ) +{ + int i, nDigits = Abc_Base10Log( nVars ); assert( nVars > 0 ); - - pFile = fopen( pFileName, "w" ); - fprintf( pFile, "# %d-bit ripple-carry adder generated by ABC on %s\n", nVars, Extra_TimeStamp() ); - fprintf( pFile, ".model Adder%02d\n", nVars ); + fprintf( pFile, ".model ADD%d\n", nVars ); fprintf( pFile, ".inputs" ); for ( i = 0; i < nVars; i++ ) - fprintf( pFile, " a%02d", i ); + fprintf( pFile, " a%0*d", nDigits, i ); for ( i = 0; i < nVars; i++ ) - fprintf( pFile, " b%02d", i ); + fprintf( pFile, " b%0*d", nDigits, i ); fprintf( pFile, "\n" ); fprintf( pFile, ".outputs" ); for ( i = 0; i <= nVars; i++ ) - fprintf( pFile, " y%02d", i ); + fprintf( pFile, " s%0*d", nDigits, i ); fprintf( pFile, "\n" ); fprintf( pFile, ".names c\n" ); if ( nVars == 1 ) - fprintf( pFile, ".subckt FA a=a00 b=b00 cin=c s=y00 cout=y01\n" ); + fprintf( pFile, ".subckt FA a=a0 b=b0 cin=c s=y0 cout=s1\n" ); else { - fprintf( pFile, ".subckt FA a=a00 b=b00 cin=c s=y00 cout=%02d\n", 0 ); + fprintf( pFile, ".subckt FA a=a%0*d b=b%0*d cin=c s=s%0*d cout=%0*d\n", nDigits, 0, nDigits, 0, nDigits, 0, nDigits, 0 ); for ( i = 1; i < nVars-1; i++ ) - fprintf( pFile, ".subckt FA a=a%02d b=b%02d cin=%02d s=y%02d cout=%02d\n", i, i, i-1, i, i ); - fprintf( pFile, ".subckt FA a=a%02d b=b%02d cin=%02d s=y%02d cout=y%02d\n", i, i, i-1, i, i+1 ); + fprintf( pFile, ".subckt FA a=a%0*d b=b%0*d cin=%0*d s=s%0*d cout=%0*d\n", nDigits, i, nDigits, i, nDigits, i-1, nDigits, i, nDigits, i ); + fprintf( pFile, ".subckt FA a=a%0*d b=b%0*d cin=%0*d s=s%0*d cout=s%0*d\n", nDigits, i, nDigits, i, nDigits, i-1, nDigits, i, nDigits, i+1 ); } fprintf( pFile, ".end\n" ); fprintf( pFile, "\n" ); - Abc_WriteFullAdder( pFile ); +} +void Abc_GenAdder( char * pFileName, int nVars ) +{ + FILE * pFile; + assert( nVars > 0 ); + pFile = fopen( pFileName, "w" ); + fprintf( pFile, "# %d-bit ripple-carry adder generated by ABC on %s\n", nVars, Extra_TimeStamp() ); + Abc_WriteAdder( pFile, nVars ); fclose( pFile ); } @@ -99,63 +113,56 @@ void Abc_GenAdder( char * pFileName, int nVars ) SeeAlso [] ***********************************************************************/ -void Abc_GenSorter( char * pFileName, int nVars ) +void Abc_WriteMulti( FILE * pFile, int nVars ) { - FILE * pFile; - int i, k, Counter, nDigits; - - assert( nVars > 1 ); + int i, k, nDigits = Abc_Base10Log( nVars ), nDigits2 = Abc_Base10Log( 2*nVars ); - pFile = fopen( pFileName, "w" ); - fprintf( pFile, "# %d-bit sorter generated by ABC on %s\n", nVars, Extra_TimeStamp() ); - fprintf( pFile, ".model Sorter%02d\n", nVars ); + assert( nVars > 0 ); + fprintf( pFile, ".model Multi%d\n", nVars ); fprintf( pFile, ".inputs" ); for ( i = 0; i < nVars; i++ ) - fprintf( pFile, " x%02d", i ); + fprintf( pFile, " a%0*d", nDigits, i ); + for ( i = 0; i < nVars; i++ ) + fprintf( pFile, " b%0*d", nDigits, i ); fprintf( pFile, "\n" ); fprintf( pFile, ".outputs" ); - for ( i = 0; i < nVars; i++ ) - fprintf( pFile, " y%02d", i ); + for ( i = 0; i < 2*nVars; i++ ) + fprintf( pFile, " m%0*d", nDigits2, i ); fprintf( pFile, "\n" ); - Counter = 0; - nDigits = Abc_Base10Log( (nVars-2)*nVars ); - if ( nVars == 2 ) - fprintf( pFile, ".subckt Comp a=x00 b=x01 x=y00 y=y01\n" ); - else + for ( i = 0; i < 2*nVars; i++ ) + fprintf( pFile, ".names x%0*d_%0*d\n", nDigits, 0, nDigits2, i ); + for ( k = 0; k < nVars; k++ ) { - fprintf( pFile, ".subckt Layer0" ); - for ( k = 0; k < nVars; k++ ) - fprintf( pFile, " x%02d=x%02d", k, k ); - for ( k = 0; k < nVars; k++ ) - fprintf( pFile, " y%02d=%0*d", k, nDigits, Counter++ ); - fprintf( pFile, "\n" ); - Counter -= nVars; - for ( i = 1; i < 2*nVars-2; i++ ) - { - fprintf( pFile, ".subckt Layer%d", (i&1) ); - for ( k = 0; k < nVars; k++ ) - fprintf( pFile, " x%02d=%0*d", k, nDigits, Counter++ ); - for ( k = 0; k < nVars; k++ ) - fprintf( pFile, " y%02d=%0*d", k, nDigits, Counter++ ); - fprintf( pFile, "\n" ); - Counter -= nVars; - } - fprintf( pFile, ".subckt Layer%d", (i&1) ); - for ( k = 0; k < nVars; k++ ) - fprintf( pFile, " x%02d=%0*d", k, nDigits, Counter++ ); - for ( k = 0; k < nVars; k++ ) - fprintf( pFile, " y%02d=y%02d", k, k ); + for ( i = 0; i < 2 * nVars; i++ ) + if ( i >= k && i < k + nVars ) + fprintf( pFile, ".names b%0*d a%0*d y%0*d_%0*d\n11 1\n", nDigits, k, nDigits, i-k, nDigits, k, nDigits2, i ); + else + fprintf( pFile, ".names y%0*d_%0*d\n", nDigits, k, nDigits2, i ); + fprintf( pFile, ".subckt ADD%d", 2*nVars ); + for ( i = 0; i < 2*nVars; i++ ) + fprintf( pFile, " a%0*d=x%0*d_%0*d", nDigits2, i, nDigits, k, nDigits2, i ); + for ( i = 0; i < 2*nVars; i++ ) + fprintf( pFile, " b%0*d=y%0*d_%0*d", nDigits2, i, nDigits, k, nDigits2, i ); + for ( i = 0; i <= 2*nVars; i++ ) + fprintf( pFile, " s%0*d=x%0*d_%0*d", nDigits2, i, nDigits, k+1, nDigits2, i ); fprintf( pFile, "\n" ); } + for ( i = 0; i < 2 * nVars; i++ ) + fprintf( pFile, ".names x%0*d_%0*d m%0*d\n1 1\n", nDigits, k, nDigits2, i, nDigits2, i ); fprintf( pFile, ".end\n" ); fprintf( pFile, "\n" ); - - Abc_WriteLayer( pFile, nVars, 0 ); - Abc_WriteLayer( pFile, nVars, 1 ); - Abc_WriteComp( pFile ); + Abc_WriteAdder( pFile, 2*nVars ); +} +void Abc_GenMulti( char * pFileName, int nVars ) +{ + FILE * pFile; + assert( nVars > 0 ); + pFile = fopen( pFileName, "w" ); + fprintf( pFile, "# %d-bit multiplier generated by ABC on %s\n", nVars, Extra_TimeStamp() ); + Abc_WriteMulti( pFile, nVars ); fclose( pFile ); } @@ -170,6 +177,19 @@ void Abc_GenSorter( char * pFileName, int nVars ) SeeAlso [] ***********************************************************************/ +void Abc_WriteComp( FILE * pFile ) +{ + fprintf( pFile, ".model Comp\n" ); + fprintf( pFile, ".inputs a b\n" ); + fprintf( pFile, ".outputs x y\n" ); + fprintf( pFile, ".names a b x\n" ); + fprintf( pFile, "11 1\n" ); + fprintf( pFile, ".names a b y\n" ); + fprintf( pFile, "1- 1\n" ); + fprintf( pFile, "-1 1\n" ); + fprintf( pFile, ".end\n" ); + fprintf( pFile, "\n" ); +} void Abc_WriteLayer( FILE * pFile, int nVars, int fSkip1 ) { int i; @@ -212,50 +232,65 @@ void Abc_WriteLayer( FILE * pFile, int nVars, int fSkip1 ) SeeAlso [] ***********************************************************************/ -void Abc_WriteComp( FILE * pFile ) +void Abc_GenSorter( char * pFileName, int nVars ) { - fprintf( pFile, ".model Comp\n" ); - fprintf( pFile, ".inputs a b\n" ); - fprintf( pFile, ".outputs x y\n" ); - fprintf( pFile, ".names a b x\n" ); - fprintf( pFile, "11 1\n" ); - fprintf( pFile, ".names a b y\n" ); - fprintf( pFile, "1- 1\n" ); - fprintf( pFile, "-1 1\n" ); - fprintf( pFile, ".end\n" ); - fprintf( pFile, "\n" ); -} + FILE * pFile; + int i, k, Counter, nDigits; -/**Function************************************************************* + assert( nVars > 1 ); - Synopsis [] + pFile = fopen( pFileName, "w" ); + fprintf( pFile, "# %d-bit sorter generated by ABC on %s\n", nVars, Extra_TimeStamp() ); + fprintf( pFile, ".model Sorter%02d\n", nVars ); - Description [] - - SideEffects [] + fprintf( pFile, ".inputs" ); + for ( i = 0; i < nVars; i++ ) + fprintf( pFile, " x%02d", i ); + fprintf( pFile, "\n" ); - SeeAlso [] + fprintf( pFile, ".outputs" ); + for ( i = 0; i < nVars; i++ ) + fprintf( pFile, " y%02d", i ); + fprintf( pFile, "\n" ); -***********************************************************************/ -void Abc_WriteFullAdder( FILE * pFile ) -{ - fprintf( pFile, ".model FA\n" ); - fprintf( pFile, ".inputs a b cin\n" ); - fprintf( pFile, ".outputs s cout\n" ); - fprintf( pFile, ".names a b k\n" ); - fprintf( pFile, "10 1\n" ); - fprintf( pFile, "01 1\n" ); - fprintf( pFile, ".names k cin s\n" ); - fprintf( pFile, "10 1\n" ); - fprintf( pFile, "01 1\n" ); - fprintf( pFile, ".names a b cin cout\n" ); - fprintf( pFile, "11- 1\n" ); - fprintf( pFile, "1-1 1\n" ); - fprintf( pFile, "-11 1\n" ); + Counter = 0; + nDigits = Abc_Base10Log( (nVars-2)*nVars ); + if ( nVars == 2 ) + fprintf( pFile, ".subckt Comp a=x00 b=x01 x=y00 y=y01\n" ); + else + { + fprintf( pFile, ".subckt Layer0" ); + for ( k = 0; k < nVars; k++ ) + fprintf( pFile, " x%02d=x%02d", k, k ); + for ( k = 0; k < nVars; k++ ) + fprintf( pFile, " y%02d=%0*d", k, nDigits, Counter++ ); + fprintf( pFile, "\n" ); + Counter -= nVars; + for ( i = 1; i < 2*nVars-2; i++ ) + { + fprintf( pFile, ".subckt Layer%d", (i&1) ); + for ( k = 0; k < nVars; k++ ) + fprintf( pFile, " x%02d=%0*d", k, nDigits, Counter++ ); + for ( k = 0; k < nVars; k++ ) + fprintf( pFile, " y%02d=%0*d", k, nDigits, Counter++ ); + fprintf( pFile, "\n" ); + Counter -= nVars; + } + fprintf( pFile, ".subckt Layer%d", (i&1) ); + for ( k = 0; k < nVars; k++ ) + fprintf( pFile, " x%02d=%0*d", k, nDigits, Counter++ ); + for ( k = 0; k < nVars; k++ ) + fprintf( pFile, " y%02d=y%02d", k, k ); + fprintf( pFile, "\n" ); + } fprintf( pFile, ".end\n" ); - fprintf( pFile, "\n" ); -} + fprintf( pFile, "\n" ); + Abc_WriteLayer( pFile, nVars, 0 ); + Abc_WriteLayer( pFile, nVars, 1 ); + Abc_WriteComp( pFile ); + fclose( pFile ); +} /**Function************************************************************* -- cgit v1.2.3