From ccafa23e40953c71ac7672b4cb5dcb2e0b53a299 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Tue, 3 Feb 2026 11:17:26 -0800 Subject: [PATCH] Extending &funtrace. --- src/base/abci/abc.c | 59 ++++++++++++++++++++++++++++++++------------ src/opt/dau/dauNpn.c | 47 ++++++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 17 deletions(-) diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 4205c4cd8..db68e00ae 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -58764,10 +58764,11 @@ int Abc_CommandAbc9FunTrace( Abc_Frame_t * pAbc, int argc, char ** argv ) extern void Gia_ManMatchCuts( Vec_Mem_t * vTtMem, Gia_Man_t * pGia, int nCutSize, int nCutNum, int fVerbose ); extern Vec_Mem_t * Abc_TruthDecRead( char * pFileName, int nVarNum ); extern void Abc_TtStoreDump( char * pFileName, Vec_Mem_t * vTtMem, int nBytes ); - int c, nVars, nVars2, nCutNum = 8, nCutSize = 0, nNumFuncs = 5, nNumCones = 3, fOutputs = 0, fVerbose = 0; word * pTruth = NULL; + extern Vec_Mem_t * Dau_CollectBoothFunctions( int nLog2Radix ); + int c, nVars, nVars2, nCutNum = 32, nCutSize = 0, nBooth = 0, nNumFuncs = 5, nNumCones = 3, fOutputs = 0, fVerbose = 0; word * pTruth = NULL; char * pStr = NULL, * pFuncFileName = "_npn_member_funcs_.data"; Vec_Mem_t * vTtMem = NULL; Gia_Man_t * pTemp; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "CKNMFovh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "CKBNMFovh" ) ) != EOF ) { switch ( c ) { @@ -58793,6 +58794,24 @@ int Abc_CommandAbc9FunTrace( Abc_Frame_t * pAbc, int argc, char ** argv ) if ( nCutSize < 0 ) goto usage; break; + case 'B': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" ); + goto usage; + } + nBooth = atoi(argv[globalUtilOptind]); + if ( nBooth < 4 || nBooth > 1024 ) { + Abc_Print( -1, "Currently support radix value from 4 to 1024.\n" ); + goto usage; + } + nBooth = Abc_Base2Log(nBooth); + if ( (1 << nBooth) != atoi(argv[globalUtilOptind]) ) { + Abc_Print( -1, "The Booth radix value %s is not a degree of 2.\n", argv[globalUtilOptind] ); + goto usage; + } + globalUtilOptind++; + break; case 'N': if ( globalUtilOptind >= argc ) { @@ -58843,21 +58862,28 @@ int Abc_CommandAbc9FunTrace( Abc_Frame_t * pAbc, int argc, char ** argv ) } if ( argc == globalUtilOptind ) { - abctime clkStart = Abc_Clock(); - int nFileSize = Gia_FileSize( pFuncFileName ); - if ( nFileSize == 0 ) - { - Abc_Print( -1, "Abc_CommandAbc9FunTrace(): Truth table in hex notation (or file name with the functions) should be given on the command line.\n" ); - return 0; + if ( nBooth ) { + vTtMem = Dau_CollectBoothFunctions( nBooth ); + printf( "Generated %d %d-input booth radix-%d encoder functions.\n", 1<<(nBooth-1), nBooth+1, 1<) when precomputed functions are used.\n" ); - return 0; + else { + abctime clkStart = Abc_Clock(); + int nFileSize = Gia_FileSize( pFuncFileName ); + if ( nFileSize == 0 ) + { + Abc_Print( -1, "Abc_CommandAbc9FunTrace(): Truth table in hex notation (or file name with the functions) should be given on the command line.\n" ); + return 0; + } + if ( nCutSize == 0 ) + { + Abc_Print( -1, "Abc_CommandAbc9FunTrace(): The cut size needs to be specified on the command line (-K ) when precomputed functions are used.\n" ); + return 0; + } + vTtMem = Abc_TruthDecRead( pFuncFileName, nCutSize ); + printf( "Finished reading %d %d-input function from file \"%s\". ", nFileSize / 8 / Abc_Truth6WordNum(nCutSize), nCutSize, pFuncFileName ); + Abc_PrintTime( 1, "Time", Abc_Clock() - clkStart ); } - vTtMem = Abc_TruthDecRead( pFuncFileName, nCutSize ); - printf( "Finished reading %d %d-input function from file \"%s\". ", nFileSize / 8 / Abc_Truth6WordNum(nCutSize), nCutSize, pFuncFileName ); - Abc_PrintTime( 1, "Time", Abc_Clock() - clkStart ); Gia_ManMatchCuts( vTtMem, pAbc->pGia, nCutSize, nCutNum, fVerbose ); Vec_MemHashFree( vTtMem ); Vec_MemFree( vTtMem ); @@ -58919,10 +58945,11 @@ int Abc_CommandAbc9FunTrace( Abc_Frame_t * pAbc, int argc, char ** argv ) return 0; usage: - Abc_Print( -2, "usage: &funtrace [-CKNM num] [-F file] [-ovh] { or }\n" ); + Abc_Print( -2, "usage: &funtrace [-CKBNM num] [-F file] [-ovh] { or }\n" ); Abc_Print( -2, "\t traces the presence of the function in the current AIG\n" ); Abc_Print( -2, "\t-C num : the number of cuts to compute at each node [default = %d]\n", nCutNum ); Abc_Print( -2, "\t-K num : the LUT size to use when is given [default = %d]\n", nCutSize ); + Abc_Print( -2, "\t-B num : the radix of booth partial products to detect [default = %d]\n", nBooth ); Abc_Print( -2, "\t-N num : the number of functions to use when or -F are used [default = %d]\n", nNumFuncs ); Abc_Print( -2, "\t-M num : the number of logic cones to use when is given [default = %d]\n", nNumCones ); Abc_Print( -2, "\t-F file : the file name to store the NPN member functions [default = %s]\n", pFuncFileName ); diff --git a/src/opt/dau/dauNpn.c b/src/opt/dau/dauNpn.c index 96f81c508..f4a4bb531 100644 --- a/src/opt/dau/dauNpn.c +++ b/src/opt/dau/dauNpn.c @@ -859,6 +859,52 @@ Vec_Mem_t * Dau_CollectNpnFunctions( word * p, int nVars, int fVerbose ) return vTtMem; } +/**Function************************************************************* + + Synopsis [Function enumeration.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Vec_Mem_t * Dau_CollectBoothFunctions( int nLog2Radix ) +{ + assert( nLog2Radix >=2 && nLog2Radix <= 10 ); + int nVars = nLog2Radix + 1; + int nWords = Abc_Truth6WordNum( nVars ); + int nFuncs = 1 << (nLog2Radix - 1); + int nMints = 1 << nVars; + Vec_Mem_t * vTtMem = Vec_MemAllocForTTSimple( nVars ); + word * pFuncs = ABC_CALLOC( word, nWords * nFuncs ); + int m, k, i; + for ( m = 0; m < nMints; m++ ) + { + int d = (m & 1); + for ( k = 1; k < nLog2Radix; k++ ) + if ( m & (1 << k) ) + d += 1 << (k-1); + if ( m & (1 << nLog2Radix) ) + d -= 1 << (nLog2Radix-1); + if ( d == 0 ) + continue; + if ( d < 0 ) + d = -d; + assert( d >= 1 && d <= nFuncs ); + Abc_TtSetBit( pFuncs + (d-1)*nWords, m ); + } + for ( i = 0; i < nFuncs; i++ ) { + if ( nVars < 6 ) + pFuncs[i] = Abc_Tt6Stretch( pFuncs[i], nVars ); + Vec_MemHashInsert( vTtMem, pFuncs + i*nWords ); + } + ABC_FREE( pFuncs ); + //Vec_MemDump( stdout, vTtMem ); + return vTtMem; +} + /**Function************************************************************* Synopsis [Function enumeration.] @@ -1065,4 +1111,3 @@ void Dau_CanonicizeArray( Vec_Wrd_t * vFuncs, int nVars, int fVerbose ) //////////////////////////////////////////////////////////////////////// ABC_NAMESPACE_IMPL_END -