Commit 76539c19 by Alan Mishchenko

Added generation of multipliers in 'gen'.

parent 675437b2
...@@ -8443,14 +8443,17 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -8443,14 +8443,17 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv )
int fAdder; int fAdder;
int fSorter; int fSorter;
int fMesh; int fMesh;
int fMulti;
int fFpga; int fFpga;
int fOneHot; int fOneHot;
int fRandom; int fRandom;
int fVerbose; int fVerbose;
char * FileName; char * FileName;
char Command[1000];
extern void Abc_GenAdder( char * pFileName, int nVars ); extern void Abc_GenAdder( char * pFileName, int nVars );
extern void Abc_GenSorter( char * pFileName, int nVars ); extern void Abc_GenSorter( char * pFileName, int nVars );
extern void Abc_GenMesh( 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_GenFpga( char * pFileName, int nLutSize, int nLuts, int nVars );
extern void Abc_GenOneHot( char * pFileName, int nVars ); extern void Abc_GenOneHot( char * pFileName, int nVars );
extern void Abc_GenRandom( char * pFileName, int nPis ); extern void Abc_GenRandom( char * pFileName, int nPis );
...@@ -8460,12 +8463,13 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -8460,12 +8463,13 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv )
fAdder = 0; fAdder = 0;
fSorter = 0; fSorter = 0;
fMesh = 0; fMesh = 0;
fMulti = 0;
fFpga = 0; fFpga = 0;
fOneHot = 0; fOneHot = 0;
fRandom = 0; fRandom = 0;
fVerbose = 0; fVerbose = 0;
Extra_UtilGetoptReset(); Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "NKLasmftrvh" ) ) != EOF ) while ( ( c = Extra_UtilGetopt( argc, argv, "NKLasemftrvh" ) ) != EOF )
{ {
switch ( c ) switch ( c )
{ {
...@@ -8508,9 +8512,12 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -8508,9 +8512,12 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv )
case 's': case 's':
fSorter ^= 1; fSorter ^= 1;
break; break;
case 'm': case 'e':
fMesh ^= 1; fMesh ^= 1;
break; break;
case 'm':
fMulti ^= 1;
break;
case 'f': case 'f':
fFpga ^= 1; fFpga ^= 1;
break; break;
...@@ -8534,7 +8541,11 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -8534,7 +8541,11 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv )
{ {
goto usage; 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 // get the input file name
FileName = argv[globalUtilOptind]; FileName = argv[globalUtilOptind];
if ( fAdder ) if ( fAdder )
...@@ -8543,6 +8554,8 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -8543,6 +8554,8 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_GenSorter( FileName, nVars ); Abc_GenSorter( FileName, nVars );
else if ( fMesh ) else if ( fMesh )
Abc_GenMesh( FileName, nVars ); Abc_GenMesh( FileName, nVars );
else if ( fMulti )
Abc_GenMulti( FileName, nVars );
else if ( fFpga ) else if ( fFpga )
Abc_GenFpga( FileName, nLutSize, nLuts, nVars ); Abc_GenFpga( FileName, nLutSize, nLuts, nVars );
// Abc_GenFpga( FileName, 2, 2, 3 ); // Abc_GenFpga( FileName, 2, 2, 3 );
...@@ -8552,18 +8565,25 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -8552,18 +8565,25 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv )
else if ( fRandom ) else if ( fRandom )
Abc_GenRandom( FileName, nVars ); Abc_GenRandom( FileName, nVars );
else else
{
Abc_Print( -1, "Type of circuit is not specified.\n" ); 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; return 0;
usage: usage:
Abc_Print( -2, "usage: gen [-NKL num] [-asmftrvh] <file>\n" ); Abc_Print( -2, "usage: gen [-NKL num] [-asemftrvh] <file>\n" );
Abc_Print( -2, "\t generates simple circuits\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-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-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-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-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-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-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-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" ); Abc_Print( -2, "\t-r : generate random single-output function [default = %s]\n", fRandom? "yes": "no" );
......
...@@ -26,13 +26,6 @@ ABC_NAMESPACE_IMPL_START ...@@ -26,13 +26,6 @@ ABC_NAMESPACE_IMPL_START
/// DECLARATIONS /// /// 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 /// /// FUNCTION DEFINITIONS ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
...@@ -48,43 +41,64 @@ void Abc_GenSorter( char * pFileName, int nVars ); ...@@ -48,43 +41,64 @@ void Abc_GenSorter( char * pFileName, int nVars );
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Abc_GenAdder( char * pFileName, int nVars ) void Abc_WriteFullAdder( FILE * pFile )
{ {
FILE * pFile; fprintf( pFile, ".model FA\n" );
int i; 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 ); assert( nVars > 0 );
fprintf( pFile, ".model ADD%d\n", nVars );
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, ".inputs" ); fprintf( pFile, ".inputs" );
for ( i = 0; i < nVars; i++ ) for ( i = 0; i < nVars; i++ )
fprintf( pFile, " a%02d", i ); fprintf( pFile, " a%0*d", nDigits, i );
for ( i = 0; i < nVars; i++ ) for ( i = 0; i < nVars; i++ )
fprintf( pFile, " b%02d", i ); fprintf( pFile, " b%0*d", nDigits, i );
fprintf( pFile, "\n" ); fprintf( pFile, "\n" );
fprintf( pFile, ".outputs" ); fprintf( pFile, ".outputs" );
for ( i = 0; i <= nVars; i++ ) for ( i = 0; i <= nVars; i++ )
fprintf( pFile, " y%02d", i ); fprintf( pFile, " s%0*d", nDigits, i );
fprintf( pFile, "\n" ); fprintf( pFile, "\n" );
fprintf( pFile, ".names c\n" ); fprintf( pFile, ".names c\n" );
if ( nVars == 1 ) 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 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++ ) 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%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%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=s%0*d\n", nDigits, i, nDigits, i, nDigits, i-1, nDigits, i, nDigits, i+1 );
} }
fprintf( pFile, ".end\n" ); fprintf( pFile, ".end\n" );
fprintf( pFile, "\n" ); fprintf( pFile, "\n" );
Abc_WriteFullAdder( pFile ); 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 ); fclose( pFile );
} }
...@@ -99,63 +113,56 @@ void Abc_GenAdder( char * pFileName, int nVars ) ...@@ -99,63 +113,56 @@ void Abc_GenAdder( char * pFileName, int nVars )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Abc_GenSorter( char * pFileName, int nVars ) void Abc_WriteMulti( FILE * pFile, int nVars )
{ {
FILE * pFile; int i, k, nDigits = Abc_Base10Log( nVars ), nDigits2 = Abc_Base10Log( 2*nVars );
int i, k, Counter, nDigits;
assert( nVars > 1 );
pFile = fopen( pFileName, "w" ); assert( nVars > 0 );
fprintf( pFile, "# %d-bit sorter generated by ABC on %s\n", nVars, Extra_TimeStamp() ); fprintf( pFile, ".model Multi%d\n", nVars );
fprintf( pFile, ".model Sorter%02d\n", nVars );
fprintf( pFile, ".inputs" ); fprintf( pFile, ".inputs" );
for ( i = 0; i < nVars; i++ ) 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, "\n" );
fprintf( pFile, ".outputs" ); fprintf( pFile, ".outputs" );
for ( i = 0; i < nVars; i++ ) for ( i = 0; i < 2*nVars; i++ )
fprintf( pFile, " y%02d", i ); fprintf( pFile, " m%0*d", nDigits2, i );
fprintf( pFile, "\n" ); fprintf( pFile, "\n" );
Counter = 0; for ( i = 0; i < 2*nVars; i++ )
nDigits = Abc_Base10Log( (nVars-2)*nVars ); fprintf( pFile, ".names x%0*d_%0*d\n", nDigits, 0, nDigits2, i );
if ( nVars == 2 ) for ( k = 0; k < nVars; k++ )
fprintf( pFile, ".subckt Comp a=x00 b=x01 x=y00 y=y01\n" );
else
{ {
fprintf( pFile, ".subckt Layer0" ); for ( i = 0; i < 2 * nVars; i++ )
for ( k = 0; k < nVars; k++ ) if ( i >= k && i < k + nVars )
fprintf( pFile, " x%02d=x%02d", k, k ); 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 );
for ( k = 0; k < nVars; k++ ) else
fprintf( pFile, " y%02d=%0*d", k, nDigits, Counter++ ); fprintf( pFile, ".names y%0*d_%0*d\n", nDigits, k, nDigits2, i );
fprintf( pFile, "\n" ); fprintf( pFile, ".subckt ADD%d", 2*nVars );
Counter -= nVars; for ( i = 0; i < 2*nVars; i++ )
for ( i = 1; i < 2*nVars-2; 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, ".subckt Layer%d", (i&1) ); fprintf( pFile, " b%0*d=y%0*d_%0*d", nDigits2, i, nDigits, k, nDigits2, i );
for ( k = 0; k < nVars; k++ ) for ( i = 0; i <= 2*nVars; i++ )
fprintf( pFile, " x%02d=%0*d", k, nDigits, Counter++ ); fprintf( pFile, " s%0*d=x%0*d_%0*d", nDigits2, i, nDigits, k+1, nDigits2, i );
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, "\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, ".end\n" );
fprintf( pFile, "\n" ); fprintf( pFile, "\n" );
Abc_WriteAdder( pFile, 2*nVars );
Abc_WriteLayer( pFile, nVars, 0 ); }
Abc_WriteLayer( pFile, nVars, 1 ); void Abc_GenMulti( char * pFileName, int nVars )
Abc_WriteComp( pFile ); {
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 ); fclose( pFile );
} }
...@@ -170,6 +177,19 @@ void Abc_GenSorter( char * pFileName, int nVars ) ...@@ -170,6 +177,19 @@ void Abc_GenSorter( char * pFileName, int nVars )
SeeAlso [] 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 ) void Abc_WriteLayer( FILE * pFile, int nVars, int fSkip1 )
{ {
int i; int i;
...@@ -212,50 +232,65 @@ void Abc_WriteLayer( FILE * pFile, int nVars, int fSkip1 ) ...@@ -212,50 +232,65 @@ void Abc_WriteLayer( FILE * pFile, int nVars, int fSkip1 )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Abc_WriteComp( FILE * pFile ) void Abc_GenSorter( char * pFileName, int nVars )
{ {
fprintf( pFile, ".model Comp\n" ); FILE * pFile;
fprintf( pFile, ".inputs a b\n" ); int i, k, Counter, nDigits;
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" );
}
/**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 [] fprintf( pFile, ".inputs" );
for ( i = 0; i < nVars; i++ )
SideEffects [] 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" );
***********************************************************************/ Counter = 0;
void Abc_WriteFullAdder( FILE * pFile ) nDigits = Abc_Base10Log( (nVars-2)*nVars );
{ if ( nVars == 2 )
fprintf( pFile, ".model FA\n" ); fprintf( pFile, ".subckt Comp a=x00 b=x01 x=y00 y=y01\n" );
fprintf( pFile, ".inputs a b cin\n" ); else
fprintf( pFile, ".outputs s cout\n" ); {
fprintf( pFile, ".names a b k\n" ); fprintf( pFile, ".subckt Layer0" );
fprintf( pFile, "10 1\n" ); for ( k = 0; k < nVars; k++ )
fprintf( pFile, "01 1\n" ); fprintf( pFile, " x%02d=x%02d", k, k );
fprintf( pFile, ".names k cin s\n" ); for ( k = 0; k < nVars; k++ )
fprintf( pFile, "10 1\n" ); fprintf( pFile, " y%02d=%0*d", k, nDigits, Counter++ );
fprintf( pFile, "01 1\n" ); fprintf( pFile, "\n" );
fprintf( pFile, ".names a b cin cout\n" ); Counter -= nVars;
fprintf( pFile, "11- 1\n" ); for ( i = 1; i < 2*nVars-2; i++ )
fprintf( pFile, "1-1 1\n" ); {
fprintf( pFile, "-11 1\n" ); 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, ".end\n" );
fprintf( pFile, "\n" ); fprintf( pFile, "\n" );
}
Abc_WriteLayer( pFile, nVars, 0 );
Abc_WriteLayer( pFile, nVars, 1 );
Abc_WriteComp( pFile );
fclose( pFile );
}
/**Function************************************************************* /**Function*************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment