From 4656ae10e08a086d111e6982f057d18babad1150 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Sun, 30 Mar 2025 19:55:07 -0700 Subject: [PATCH] Updates to the GPC-based mapping. --- src/base/abc/abcUtil.c | 47 +++++++++++++++++++++++------------------- src/base/abci/abc.c | 26 +++++++++++++++++------ 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/base/abc/abcUtil.c b/src/base/abc/abcUtil.c index e3633da4d..fddc04beb 100644 --- a/src/base/abc/abcUtil.c +++ b/src/base/abc/abcUtil.c @@ -3445,7 +3445,7 @@ int Abc_NtkCheckGpc( char * pGPC, char * pGPC0 ) RetValue = 1; return RetValue; } -void Abc_NtkATMap( int nXVars, int nYVars, char ** pGPCs0, int nGPCs, int fReturn, int fVerbose ) +void Abc_NtkATMap( int nXVars, int nYVars, int nAdder, char ** pGPCs0, int nGPCs, int fReturn, int fVerbose ) { abctime clkStart = Abc_Clock(); char ** pGPCs = Abc_NtkTransformGPCs(pGPCs0, nGPCs); @@ -3490,13 +3490,15 @@ void Abc_NtkATMap( int nXVars, int nYVars, char ** pGPCs0, int nGPCs, int fRetur Vec_IntClear( vRank[2] ); Vec_IntAppend( vRank[2], vRank[0] ); fFinished = 1; - for ( x = 0; x < nBits; x++ ) - if ( (nGpcs = Abc_NtkMatchGpcPattern(vRank[0], x, pGPCs[n])) ) - Abc_NtkUpdateGpcPattern(vRank[0], x, pGPCs[n], nGpcs, vRank[1], vLevel), fFinished = 0, fAdded = 1; - nLuts += Vec_IntSum(vLevel) * nGPCluts[n]; - Vec_IntForEachEntry( vRank[1], Entry, x ) - Vec_IntAddToEntry( vRank[0], x, Entry ); - if ( fVerbose && (fAdded || Vec_IntFindMax(vRank[2]) <= 2 ) ) { + if ( Vec_IntFindMax(vRank[0]) > nAdder ) { + for ( x = 0; x < nBits; x++ ) + if ( (nGpcs = Abc_NtkMatchGpcPattern(vRank[0], x, pGPCs[n])) ) + Abc_NtkUpdateGpcPattern(vRank[0], x, pGPCs[n], nGpcs, vRank[1], vLevel), fFinished = 0, fAdded = 1; + nLuts += Vec_IntSum(vLevel) * nGPCluts[n]; + Vec_IntForEachEntry( vRank[1], Entry, x ) + Vec_IntAddToEntry( vRank[0], x, Entry ); + } + if ( fVerbose && (fAdded || Vec_IntFindMax(vRank[2]) <= nAdder ) ) { printf( "Lev%02d: ", iLevel++ ); Abc_PrintAT( vRank[2] ); if ( fAdded ) { @@ -3504,15 +3506,16 @@ void Abc_NtkATMap( int nXVars, int nYVars, char ** pGPCs0, int nGPCs, int fRetur Abc_PrintAT( vLevel ); printf( " %4d", Vec_IntSum(vLevel) * nGPCluts[n] ); } - else if ( Vec_IntFindMax(vRank[2]) == 2 ) { - printf( " RCA : " ); - x = Vec_IntArgMax(vRank[2]); - assert( Vec_IntEntry(vRank[2], x) == 2 ); + else if ( Vec_IntFindMax(vRank[2]) <= nAdder ) { + printf( " ADD%d: ", nAdder ); + for ( x = 0; x < nBits; x++ ) + if ( Vec_IntEntry(vRank[2], x) > 1 ) + break; for ( i = nBits-1; i >= x; i-- ) printf( "%4d", 1 ); for ( ; i >= 0; i-- ) printf( " " ); - printf( " %4d", (nBits-x+1)/2 ); + printf( " %4d", (nBits-x)*(nAdder == 4 ? 2 : 1) ); } printf( "\n" ); } @@ -3522,14 +3525,14 @@ void Abc_NtkATMap( int nXVars, int nYVars, char ** pGPCs0, int nGPCs, int fRetur n = -1; } } - else if ( Vec_IntFindMax(vRank[2]) <= 2 ) { + else if ( Vec_IntFindMax(vRank[2]) <= nAdder ) { fFinished = 1; n = nGPCs; } } - if ( Vec_IntFindMax(vRank[0]) > 2 ) + if ( Vec_IntFindMax(vRank[0]) > nAdder ) printf( "Synthesis of the adder tree is incomplete. Try using the full adder \"3:11:1\" as the last GPC.\n" ); - else if ( fVerbose && Vec_IntFindMax(vRank[0]) == 2 ) { + else if ( fVerbose && Vec_IntFindMax(vRank[0]) <= nAdder ) { printf( "Lev%02d: ", iLevel++ ); for ( i = nBits-1; i >= 0; i-- ) printf( "%4d", 1 ); @@ -3538,12 +3541,14 @@ void Abc_NtkATMap( int nXVars, int nYVars, char ** pGPCs0, int nGPCs, int fRetur printf( "Statistics: " ); for ( n = 0; n < nGPCs; n++ ) printf( "GPC%d = %d. ", n, Vec_WecSum(vGPCs[n]) ); - x = Vec_IntArgMax(vRank[0]); - nRcaLuts = Vec_IntFindMax(vRank[0]) == 2 ? (nBits-x+1)/2 : 0; - printf( "RCA = %d. ", nRcaLuts ); + for ( x = 0; x < nBits; x++ ) + if ( Vec_IntEntry(vRank[0], x) > 1 ) + break; + nRcaLuts = (nBits-x)*(nAdder == 4 ? 2 : 1); + printf( "ADD%d = %d. ", nAdder, nRcaLuts ); printf( "Total LUT count = %d. ", nLuts+nRcaLuts ); - Vec_IntFree( vRank[0] ); - Vec_IntFree( vRank[1] ); + for ( i = 0; i < 3; i++ ) + Vec_IntFree( vRank[i] ); for ( i = 0; i < nGPCs; i++ ) Vec_WecFree( vGPCs[i] ); ABC_FREE( vGPCs ); diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 0ec80baeb..2a00d2297 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -26089,12 +26089,12 @@ usage: ***********************************************************************/ int Abc_CommandATMap( Abc_Frame_t * pAbc, int argc, char ** argv ) { - extern void Abc_NtkATMap( int nXVars, int nYVars, char ** pGPC, int nGPCs, int fReturn, int fVerbose ); - int c, nXVars = -1, nYVars = -1, fReturn = 0, fVerbose = 1; + extern void Abc_NtkATMap( int nXVars, int nYVars, int nAdder, char ** pGPC, int nGPCs, int fReturn, int fVerbose ); + int c, nXVars = -1, nYVars = -1, nAdder = 2, fReturn = 0, fVerbose = 1; char * pGPCs0[1] = { (char*)"3:11:1" }; char ** pGPCs = NULL; int nGPCs = 0; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "XYrvh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "XYArvh" ) ) != EOF ) { switch ( c ) { @@ -26116,6 +26116,15 @@ int Abc_CommandATMap( Abc_Frame_t * pAbc, int argc, char ** argv ) nYVars = atoi(argv[globalUtilOptind]); globalUtilOptind++; break; + case 'A': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-A\" should be followed by a file name.\n" ); + goto usage; + } + nAdder = atoi(argv[globalUtilOptind]); + globalUtilOptind++; + break; case 'r': fReturn ^= 1; break; @@ -26125,10 +26134,14 @@ int Abc_CommandATMap( Abc_Frame_t * pAbc, int argc, char ** argv ) case 'h': goto usage; default: - //Abc_Print( -2, "Unknown switch.\n"); goto usage; } } + if ( nAdder < 2 || nAdder > 4 ) + { + printf( "The terminal adder should have 2, 3, or 4 bits.\n" ); + return 0; + } pGPCs = argv + globalUtilOptind; nGPCs = argc - globalUtilOptind; if ( nGPCs == 0 ) @@ -26137,14 +26150,15 @@ int Abc_CommandATMap( Abc_Frame_t * pAbc, int argc, char ** argv ) pGPCs = pGPCs0; nGPCs = 1; } - Abc_NtkATMap( nXVars, nYVars, pGPCs, nGPCs, fReturn, fVerbose ); + Abc_NtkATMap( nXVars, nYVars, nAdder, pGPCs, nGPCs, fReturn, fVerbose ); return 0; usage: - Abc_Print( -2, "usage: atmap [-XY num] [-G str] [-rv] ... \n" ); + Abc_Print( -2, "usage: atmap [-XYA num] [-G str] [-rv] ... \n" ); Abc_Print( -2, "\t maps rectangular adder tree using GPCs\n" ); Abc_Print( -2, "\t-X : the number of different ranks [default = %d]\n", nXVars ); Abc_Print( -2, "\t-Y : the number of bits of each rank [default = %d]\n", nYVars ); + Abc_Print( -2, "\t-A : the number of arguments in the terminal adder [default = %d]\n", nAdder ); Abc_Print( -2, "\t-r : return to the first GPC after each step [default = %s]\n", fReturn? "yes": "no" ); Abc_Print( -2, "\t-v : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" ); Abc_Print( -2, "\t-h : print the command usage\n\n");