summaryrefslogtreecommitdiffstats
path: root/src/base/abci/abcGen.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/abci/abcGen.c')
-rw-r--r--src/base/abci/abcGen.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/src/base/abci/abcGen.c b/src/base/abci/abcGen.c
index 5d74bda5..bfb41374 100644
--- a/src/base/abci/abcGen.c
+++ b/src/base/abci/abcGen.c
@@ -360,6 +360,150 @@ void Abc_GenMesh( char * pFileName, int nVars )
}
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_WriteKLut( FILE * pFile, int nLutSize )
+{
+ int i, iVar, iNext, nPars = (1 << nLutSize);
+ fprintf( pFile, "\n" );
+ fprintf( pFile, ".model lut%d\n", nLutSize );
+ fprintf( pFile, ".inputs" );
+ for ( i = 0; i < nPars; i++ )
+ fprintf( pFile, " p%02d", i );
+ fprintf( pFile, "\n" );
+ fprintf( pFile, ".inputs" );
+ for ( i = 0; i < nLutSize; i++ )
+ fprintf( pFile, " i%d", i );
+ fprintf( pFile, "\n" );
+ fprintf( pFile, ".outputs o\n" );
+ fprintf( pFile, ".names n01 o\n" );
+ fprintf( pFile, "1 1\n" );
+ // write internal MUXes
+ iVar = 0;
+ iNext = 2;
+ for ( i = 1; i < nPars; i++ )
+ {
+ if ( i == iNext )
+ {
+ iNext *= 2;
+ iVar++;
+ }
+ if ( iVar == nLutSize - 1 )
+ fprintf( pFile, ".names i%d p%02d p%02d n%02d\n", iVar, 2*(i-nPars/2), 2*(i-nPars/2)+1, i );
+ else
+ fprintf( pFile, ".names i%d n%02d n%02d n%02d\n", iVar, 2*i, 2*i+1, i );
+ fprintf( pFile, "01- 1\n" );
+ fprintf( pFile, "1-1 1\n" );
+ }
+ fprintf( pFile, ".end\n" );
+ fprintf( pFile, "\n" );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Generates structure of L K-LUTs implementing an N-var function.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_GenFpga( char * pFileName, int nLutSize, int nLuts, int nVars )
+{
+ FILE * pFile;
+ int nVarsLut = (1 << nLutSize); // the number of LUT variables
+ int nVarsLog = Extra_Base2Log( nVars + nLuts - 1 ); // the number of encoding vars
+ int nVarsDeg = (1 << nVarsLog); // the number of LUT variables (total)
+ int nParsLut = nLuts * (1 << nLutSize); // the number of LUT params
+ int nParsVar = nLuts * nLutSize * nVarsLog; // the number of var params
+ int i, j, k;
+
+ assert( nVars > 0 );
+
+ pFile = fopen( pFileName, "w" );
+ fprintf( pFile, "# Structure with %d %d-LUTs for %d-var function generated by ABC on %s\n", nLuts, nLutSize, nVars, Extra_TimeStamp() );
+ fprintf( pFile, ".model struct%dx%d_%d\n", nLuts, nLutSize, nVars );
+
+ fprintf( pFile, ".inputs" );
+ for ( i = 0; i < nParsLut; i++ )
+ fprintf( pFile, " pl%02d", i );
+ fprintf( pFile, "\n" );
+
+ fprintf( pFile, ".inputs" );
+ for ( i = 0; i < nParsVar; i++ )
+ fprintf( pFile, " pv%02d", i );
+ fprintf( pFile, "\n" );
+
+ fprintf( pFile, ".inputs" );
+ for ( i = 0; i < nVars; i++ )
+ fprintf( pFile, " v%02d", i );
+ fprintf( pFile, "\n" );
+
+ fprintf( pFile, ".outputs" );
+ fprintf( pFile, " v%02d", nVars + nLuts - 1 );
+ fprintf( pFile, "\n" );
+ fprintf( pFile, ".names Gnd\n" );
+ fprintf( pFile, " 0\n" );
+
+ // generate LUTs
+ for ( i = 0; i < nLuts; i++ )
+ {
+ fprintf( pFile, ".subckt lut%d", nLutSize );
+ // generate config parameters
+ for ( k = 0; k < nVarsLut; k++ )
+ fprintf( pFile, " p%02d=pl%02d", k, i * nVarsLut + k );
+ // generate the inputs
+ for ( k = 0; k < nLutSize; k++ )
+ fprintf( pFile, " i%d=s%02d", k, i * nLutSize + k );
+ // generate the output
+ fprintf( pFile, " o=v%02d", nVars + i );
+ fprintf( pFile, "\n" );
+ }
+
+ // generate LUT inputs
+ for ( i = 0; i < nLuts; i++ )
+ {
+ for ( j = 0; j < nLutSize; j++ )
+ {
+ fprintf( pFile, ".subckt lut%d", nVarsLog );
+ // generate config parameters
+ for ( k = 0; k < nVarsDeg; k++ )
+ {
+ if ( k < nVars + nLuts - 1 && k < nVars + i )
+ fprintf( pFile, " p%02d=v%02d", k, k );
+ else
+ fprintf( pFile, " p%02d=Gnd", k );
+ }
+ // generate the inputs
+ for ( k = 0; k < nVarsLog; k++ )
+ fprintf( pFile, " i%d=pv%02d", k, (i * nLutSize + j) * nVarsLog + k );
+ // generate the output
+ fprintf( pFile, " o=s%02d", i * nLutSize + j );
+ fprintf( pFile, "\n" );
+ }
+ }
+
+ fprintf( pFile, ".end\n" );
+ fprintf( pFile, "\n" );
+
+ // generate LUTs
+ Abc_WriteKLut( pFile, nLutSize );
+ if ( nVarsLog != nLutSize )
+ Abc_WriteKLut( pFile, nVarsLog );
+ fclose( pFile );
+}
+
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////