Integrating prefix adder generation code by Martin Povišer

This commit is contained in:
Alan Mishchenko 2025-08-05 22:50:06 -07:00
parent 0218e3e4cb
commit c738ed6e86
5 changed files with 1157 additions and 1 deletions

View File

@ -4991,6 +4991,10 @@ SOURCE=.\src\misc\util\utilPth.c
# End Source File
# Begin Source File
SOURCE=.\src\misc\util\utilPrefix.cpp
# End Source File
# Begin Source File
SOURCE=.\src\misc\util\utilSignal.c
# End Source File
# Begin Source File

View File

@ -2373,6 +2373,38 @@ Gia_Man_t * Gia_GenPutOnTop( char ** pFNames, int nFNames )
return pNew;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Gia_Man_t * Gia_ManDupFromArray( int * pObjs, int nObjs, int nIns, int nLatches, int nOuts, int nAnds )
{
Gia_Man_t * pNew = Gia_ManStart( nObjs ); int i;
for ( i = 0; i < nIns + nLatches; i++ )
Gia_ManAppendCi(pNew);
for ( i = 0; i < nAnds; i++ )
{
int uLit = 2*(1+nIns+nLatches+i);
int uLit0 = pObjs[uLit+0];
int uLit1 = pObjs[uLit+1];
int uLit2 = Gia_ManAppendAnd( pNew, uLit0, uLit1 );
assert( uLit2 == uLit );
}
for ( i = 0; i < nOuts + nLatches; i++ )
Gia_ManAppendCo( pNew, pObjs[2*(nObjs-nOuts-nLatches+i)+0] );
Gia_ManSetRegNum(pNew, nLatches);
return pNew;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////

View File

@ -636,6 +636,7 @@ static int Abc_CommandAbc9GenComp ( Abc_Frame_t * pAbc, int argc, cha
static int Abc_CommandAbc9GenSorter ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9GenNeuron ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9GenAdder ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9GenPrefix ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Window ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9FunAbs ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9DsdInfo ( Abc_Frame_t * pAbc, int argc, char ** argv );
@ -1461,6 +1462,7 @@ void Abc_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "ABC9", "&gensorter", Abc_CommandAbc9GenSorter, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&genneuron", Abc_CommandAbc9GenNeuron, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&genadder", Abc_CommandAbc9GenAdder, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&genprefix", Abc_CommandAbc9GenPrefix, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&window", Abc_CommandAbc9Window, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&funabs", Abc_CommandAbc9FunAbs, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&dsdinfo", Abc_CommandAbc9DsdInfo, 0 );
@ -56697,7 +56699,7 @@ int Abc_CommandAbc9GenAdder( Abc_Frame_t * pAbc, int argc, char ** argv )
return 0;
usage:
Abc_Print( -2, "usage: &genadder [-N <num>] [-sbhcv] <file>\n" );
Abc_Print( -2, "usage: &genadder [-N <num>] [-sbhcv]\n" );
Abc_Print( -2, "\t generates a prefix adder (by default, the ripple carry adder)\n" );
Abc_Print( -2, "\t-N num : the bit-width of the adder [default = undefined]\n" );
Abc_Print( -2, "\t-s : toggles using Sklansky adder [default = %s]\n", fSK ? "yes": "no" );
@ -56708,6 +56710,94 @@ usage:
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_CommandAbc9GenPrefix( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern int* adder_return_array(int width, int mfo, int* pnObjs, int* pnIns, int* pnLatches, int* pnOuts, int* pnAnds, int fDumpVer, int fDumpMiter, int fVerbose);
extern Gia_Man_t * Gia_ManDupFromArray( int * pObjs, int nObjs, int nIns, int nLatches, int nOuts, int nAnds );
int c, nBits = 8, nFans = 4, fDumpVer = 0, fDumpMiter = 0, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "NFdmv" ) ) != EOF )
{
switch ( c )
{
case 'N':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
goto usage;
}
nBits = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nBits < 0 )
goto usage;
break;
case 'F':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
goto usage;
}
nFans = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nFans < 0 )
goto usage;
break;
case 'd':
fDumpVer ^= 1;
break;
case 'm':
fDumpMiter ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
default:
goto usage;
}
}
if ( nBits < 1 )
{
Abc_Print( -1, "Abc_CommandAbc9GenPrefix(): The number of inputs should be defined on the command line \"-N num\".\n" );
return 0;
}
else
{
int nObjs = 0, nIns = 0, nLatches = 0, nOuts = 0, nAnds = 0;
int * pObjs = adder_return_array( nBits, nFans, &nObjs, &nIns, &nLatches, &nOuts, &nAnds, fDumpVer, fDumpMiter, fVerbose );
Gia_Man_t * pTemp = Gia_ManDupFromArray( pObjs, nObjs, nIns, nLatches, nOuts, nAnds );
Abc_FrameUpdateGia( pAbc, pTemp );
ABC_FREE( pObjs );
}
return 0;
usage:
Abc_Print( -2, "usage: &genprefix [-NF <num>] [-dcv]\n" );
Abc_Print( -2, "\t generates a prefix adder with minimum depth\n" );
Abc_Print( -2, "\t-N num : the bit-width of the adder [default = %d]\n", nBits );
Abc_Print( -2, "\t-F num : the limit on the fanout count [default = %d]\n", nFans );
Abc_Print( -2, "\t-d : toggles dumping the adder in Verilog [default = %s]\n", fDumpVer ? "yes": "no" );
Abc_Print( -2, "\t-c : toggles dumping the miter in Verilog [default = %s]\n", fDumpMiter ? "yes": "no" );
Abc_Print( -2, "\t-v : toggles printing verbose information [default = %s]\n\n", fVerbose ? "yes": "no" );
Abc_Print( -2, "\t The code of this command is contributed by Martin Povišer <povik@cutebit.org>\n\n" );
Abc_Print( -2, "\t The implementation is inspired by S. Roy, M. Choudhury, R. Puri, D. Pan,\n" );
Abc_Print( -2, "\t \"Polynomial time algorithm for area and power efficient adder synthesis\n" );
Abc_Print( -2, "\t in high-performance designs\", Proc. ASP-DAC 2025.\n" );
Abc_Print( -2, "\t https://www.cerc.utexas.edu/utda/publications/C166.pdf\n" );
return 1;
}
/**Function*************************************************************
Synopsis []

View File

@ -5,6 +5,7 @@ SRC += src/misc/util/utilBridge.c \
src/misc/util/utilFile.c \
src/misc/util/utilIsop.c \
src/misc/util/utilNam.c \
src/misc/util/utilPrefix.cpp \
src/misc/util/utilPth.c \
src/misc/util/utilSignal.c \
src/misc/util/utilSort.c

1029
src/misc/util/utilPrefix.cpp Normal file

File diff suppressed because it is too large Load Diff