Skip to content

Commit

Permalink
LUT cascade mapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanminko committed Feb 27, 2025
1 parent 45c250f commit 75ef060
Show file tree
Hide file tree
Showing 5 changed files with 585 additions and 80 deletions.
59 changes: 44 additions & 15 deletions src/base/abci/abc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8853,7 +8853,7 @@ int Abc_CommandCascade( Abc_Frame_t * pAbc, int argc, char ** argv )

if ( pNtk == NULL )
{
Abc_Print( -1, "Empty network.\n" );
Abc_Print( -1, "Empty neAtwork.\n" );
return 1;
}

Expand Down Expand Up @@ -8910,12 +8910,12 @@ int Abc_CommandCascade( Abc_Frame_t * pAbc, int argc, char ** argv )
***********************************************************************/
int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern Abc_Ntk_t * Abc_NtkLutCascade( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose );
extern Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose );
Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkRes;
int c, nLutSize = 6, nLuts = 8, nRails = 1, nIters = 1, fVerbose = 0;
extern Abc_Ntk_t * Abc_NtkLutCascadeGen( int nLutSize, int nStages, int nRails, int nShared, int fVerbose );
extern Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose, char * pGuide );
Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkRes; char * pGuide = NULL;
int c, nLutSize = 6, nStages = 8, nRails = 1, nShared = 2, nIters = 1, fGen = 0, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "KNRIvh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "KMRSIgvh" ) ) != EOF )
{
switch ( c )
{
Expand All @@ -8930,15 +8930,15 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
if ( nLutSize < 0 )
goto usage;
break;
case 'N':
case 'M':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
goto usage;
}
nLuts = atoi(argv[globalUtilOptind]);
nStages = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nLuts < 0 )
if ( nStages < 0 )
goto usage;
break;
case 'R':
Expand All @@ -8952,6 +8952,17 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
if ( nRails < 0 )
goto usage;
break;
case 'S':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
goto usage;
}
nShared = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nShared < 0 )
goto usage;
break;
case 'I':
if ( globalUtilOptind >= argc )
{
Expand All @@ -8963,6 +8974,9 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
if ( nIters < 0 )
goto usage;
break;
case 'g':
fGen ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
Expand All @@ -8972,6 +8986,17 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
goto usage;
}
}
if ( fGen )
{
pNtkRes = Abc_NtkLutCascadeGen( nLutSize, nStages, nRails, nShared, fVerbose );
if ( pNtkRes == NULL )
{
Abc_Print( -1, "LUT cascade generation failed.\n" );
return 1;
}
Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
return 0;
}

if ( pNtk == NULL )
{
Expand All @@ -8988,13 +9013,15 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Print( -1, "Run command \"strash\" to convert the network into an AIG.\n" );
return 1;
}
if ( Abc_NtkCiNum(pNtk) > nLutSize + (nLutSize - nRails) * (nLuts - 1) )
if ( Abc_NtkCiNum(pNtk) > nLutSize + (nLutSize - nRails) * (nStages - 1) )
{
Abc_Print( -1, "Cannot decompose %d-input function into a %d-rail cascade of %d %d-LUTs (max suppose size = %d).\n",
Abc_NtkCiNum(pNtk), nRails, nLuts, nLutSize, nLutSize + (nLutSize - nRails) * (nLuts - 1) );
Abc_NtkCiNum(pNtk), nRails, nStages, nLutSize, nLutSize + (nLutSize - nRails) * (nStages - 1) );
return 1;
}
pNtkRes = Abc_NtkLutCascade2( pNtk, nLutSize, nLuts, nRails, nIters, fVerbose );
if ( argc == globalUtilOptind + 1 )
pGuide = argv[globalUtilOptind];
pNtkRes = Abc_NtkLutCascade2( pNtk, nLutSize, nStages, nRails, nIters, fVerbose, pGuide );
if ( pNtkRes == NULL )
{
Abc_Print( -1, "LUT cascade mapping failed.\n" );
Expand All @@ -9004,12 +9031,14 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
return 0;

usage:
Abc_Print( -2, "usage: lutcasdec [-KNRI <num>] [-vh]\n" );
Abc_Print( -2, "usage: lutcasdec [-KMRSI <num>] [-vh]\n" );
Abc_Print( -2, "\t decomposes the primary output functions into LUT cascades\n" );
Abc_Print( -2, "\t-K <num> : the number of LUT inputs [default = %d]\n", nLutSize );
Abc_Print( -2, "\t-N <num> : the number of LUTs in the cascade [default = %d]\n", nLuts );
Abc_Print( -2, "\t-M <num> : the maximum delay (the number of stages) [default = %d]\n", nStages );
Abc_Print( -2, "\t-R <num> : the number of direct connections (rails) [default = %d]\n", nRails );
Abc_Print( -2, "\t-S <num> : the number of shared variables in each stage [default = %d]\n", nShared );
Abc_Print( -2, "\t-I <num> : the number of iterations when looking for a solution [default = %d]\n", nIters );
Abc_Print( -2, "\t-g : toggle generating random cascade with these parameters [default = %s]\n", fGen? "yes": "no" );
Abc_Print( -2, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
Expand Down
Loading

0 comments on commit 75ef060

Please sign in to comment.