summaryrefslogtreecommitdiffstats
path: root/src/base/abci/abcGen.c
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2012-05-15 09:34:24 +0700
committerAlan Mishchenko <alanmi@berkeley.edu>2012-05-15 09:34:24 +0700
commit76539c1956b1d694dba2700326a915b0c64a3117 (patch)
treebe49dc2b55e41173b87c98b3636f0207ebdf37a5 /src/base/abci/abcGen.c
parent675437b214074d41fc43448ecb99d55e5fa9dccf (diff)
downloadabc-76539c1956b1d694dba2700326a915b0c64a3117.tar.gz
abc-76539c1956b1d694dba2700326a915b0c64a3117.tar.bz2
abc-76539c1956b1d694dba2700326a915b0c64a3117.zip
Added generation of multipliers in 'gen'.
Diffstat (limited to 'src/base/abci/abcGen.c')
-rw-r--r--src/base/abci/abcGen.c235
1 files changed, 135 insertions, 100 deletions
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*************************************************************