diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2005-11-27 08:01:00 -0800 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2005-11-27 08:01:00 -0800 |
commit | 3a1ca9fa0ebfb2ae431501067d1a1a63fe6ecba5 (patch) | |
tree | d574e57b40998f09f5868ffd1be35b8c7baf5f27 /src/base/abci | |
parent | e3c40ed61ee3febefb002d3b929f157ccdffca81 (diff) | |
download | abc-3a1ca9fa0ebfb2ae431501067d1a1a63fe6ecba5.tar.gz abc-3a1ca9fa0ebfb2ae431501067d1a1a63fe6ecba5.tar.bz2 abc-3a1ca9fa0ebfb2ae431501067d1a1a63fe6ecba5.zip |
Version abc51127
Diffstat (limited to 'src/base/abci')
-rw-r--r-- | src/base/abci/abc.c | 240 | ||||
-rw-r--r-- | src/base/abci/abcPrint.c | 92 | ||||
-rw-r--r-- | src/base/abci/abcSweep.c | 5 |
3 files changed, 305 insertions, 32 deletions
diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 0b24b3ff..db2d08a7 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -41,10 +41,12 @@ static int Abc_CommandPrintLevel ( Abc_Frame_t * pAbc, int argc, char ** argv static int Abc_CommandPrintSupport ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandPrintSymms ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandPrintKMap ( Abc_Frame_t * pAbc, int argc, char ** argv ); +static int Abc_CommandPrintGates ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandShowBdd ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandShowCut ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandShowAig ( Abc_Frame_t * pAbc, int argc, char ** argv ); +static int Abc_CommandShowNtk ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandCollapse ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandStrash ( Abc_Frame_t * pAbc, int argc, char ** argv ); @@ -133,10 +135,12 @@ void Abc_Init( Abc_Frame_t * pAbc ) Cmd_CommandAdd( pAbc, "Printing", "print_supp", Abc_CommandPrintSupport, 0 ); Cmd_CommandAdd( pAbc, "Printing", "print_symm", Abc_CommandPrintSymms, 0 ); Cmd_CommandAdd( pAbc, "Printing", "print_kmap", Abc_CommandPrintKMap, 0 ); + Cmd_CommandAdd( pAbc, "Printing", "print_gates", Abc_CommandPrintGates, 0 ); Cmd_CommandAdd( pAbc, "Printing", "show_bdd", Abc_CommandShowBdd, 0 ); Cmd_CommandAdd( pAbc, "Printing", "show_cut", Abc_CommandShowCut, 0 ); Cmd_CommandAdd( pAbc, "Printing", "show_aig", Abc_CommandShowAig, 0 ); + Cmd_CommandAdd( pAbc, "Printing", "show_ntk", Abc_CommandShowNtk, 0 ); Cmd_CommandAdd( pAbc, "Synthesis", "collapse", Abc_CommandCollapse, 1 ); Cmd_CommandAdd( pAbc, "Synthesis", "strash", Abc_CommandStrash, 1 ); @@ -950,6 +954,69 @@ usage: SeeAlso [] ***********************************************************************/ +int Abc_CommandPrintGates( Abc_Frame_t * pAbc, int argc, char ** argv ) +{ + FILE * pOut, * pErr; + Abc_Ntk_t * pNtk; + int c; + int fUseLibrary; + + extern void Abc_NtkPrintGates( Abc_Ntk_t * pNtk, int fUseLibrary ); + + pNtk = Abc_FrameReadNet(pAbc); + pOut = Abc_FrameReadOut(pAbc); + pErr = Abc_FrameReadErr(pAbc); + + // set defaults + fUseLibrary = 1; + util_getopt_reset(); + while ( ( c = util_getopt( argc, argv, "lh" ) ) != EOF ) + { + switch ( c ) + { + case 'l': + fUseLibrary ^= 1; + break; + case 'h': + goto usage; + default: + goto usage; + } + } + + if ( pNtk == NULL ) + { + fprintf( pErr, "Empty network.\n" ); + return 1; + } + if ( Abc_NtkHasAig(pNtk) ) + { + fprintf( pErr, "Printing gates does not work for AIGs and sequential AIGs.\n" ); + return 1; + } + + Abc_NtkPrintGates( pNtk, fUseLibrary ); + return 0; + +usage: + fprintf( pErr, "usage: print_gates [-lh]\n" ); + fprintf( pErr, "\t prints statistics about gates used in the network\n" ); + fprintf( pErr, "\t-l : used library gate names (if mapped) [default = %s]\n", fUseLibrary? "yes": "no" ); + fprintf( pErr, "\t-h : print the command usage\n"); + return 1; +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ int Abc_CommandShowBdd( Abc_Frame_t * pAbc, int argc, char ** argv ) { FILE * pOut, * pErr; @@ -1174,9 +1241,10 @@ int Abc_CommandShowAig( Abc_Frame_t * pAbc, int argc, char ** argv ) if ( !Abc_NtkHasAig(pNtk) ) { - fprintf( pErr, "Visualizing AIG can only be done for AIGs (run \"strash\" or \"seq\").\n" ); + fprintf( pErr, "Visualizing networks other than AIGs can be done using command \"show_ntk\".\n" ); return 1; } + if ( fMulti && !Abc_NtkIsStrash(pNtk) ) { fprintf( pErr, "Visualizing multi-input ANDs cannot be done for sequential network (run \"unseq\").\n" ); @@ -1201,6 +1269,70 @@ usage: return 1; } +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Abc_CommandShowNtk( Abc_Frame_t * pAbc, int argc, char ** argv ) +{ + FILE * pOut, * pErr; + Abc_Ntk_t * pNtk; + int c; + int fGateNames; + extern void Abc_NtkShow( Abc_Ntk_t * pNtk, int fGateNames ); + + pNtk = Abc_FrameReadNet(pAbc); + pOut = Abc_FrameReadOut(pAbc); + pErr = Abc_FrameReadErr(pAbc); + + // set defaults + fGateNames = 0; + util_getopt_reset(); + while ( ( c = util_getopt( argc, argv, "gh" ) ) != EOF ) + { + switch ( c ) + { + case 'n': + fGateNames ^= 1; + break; + default: + goto usage; + } + } + + if ( pNtk == NULL ) + { + fprintf( pErr, "Empty network.\n" ); + return 1; + } + + if ( Abc_NtkHasAig(pNtk) ) + { + fprintf( pErr, "Visualizing AIG can only be done using command \"show_aig\".\n" ); + return 1; + } + Abc_NtkShow( pNtk, fGateNames ); + return 0; + +usage: + fprintf( pErr, "usage: show_ntk [-gh]\n" ); + fprintf( pErr, " visualizes the network structure using DOT and GSVIEW\n" ); +#ifdef WIN32 + fprintf( pErr, " \"dot.exe\" and \"gsview32.exe\" should be set in the paths\n" ); + fprintf( pErr, " (\"gsview32.exe\" may be in \"C:\\Program Files\\Ghostgum\\gsview\\\")\n" ); +#endif + fprintf( pErr, "\t-g : toggles printing gate names for mapped network [default = %s].\n", fGateNames? "yes": "no" ); + fprintf( pErr, "\t-h : print the command usage\n"); + return 1; +} + /**Function************************************************************* @@ -4056,6 +4188,12 @@ int Abc_CommandMap( Abc_Frame_t * pAbc, int argc, char ** argv ) return 1; } + if ( Abc_NtkIsSeq(pNtk) ) + { + fprintf( pErr, "Cannot map a sequential AIG.\n" ); + return 1; + } + if ( !Abc_NtkIsStrash(pNtk) ) { pNtk = Abc_NtkStrash( pNtk, 0, 0 ); @@ -4364,6 +4502,12 @@ int Abc_CommandFpga( Abc_Frame_t * pAbc, int argc, char ** argv ) return 1; } + if ( Abc_NtkIsSeq(pNtk) ) + { + fprintf( pErr, "Cannot FPGA map a sequential AIG.\n" ); + return 1; + } + if ( !Abc_NtkIsStrash(pNtk) ) { // strash and balance the network @@ -4741,7 +4885,7 @@ int Abc_CommandSeq( Abc_Frame_t * pAbc, int argc, char ** argv ) { FILE * pOut, * pErr; Abc_Ntk_t * pNtk, * pNtkRes; - int c;//, nLoops; + int c; pNtk = Abc_FrameReadNet(pAbc); pOut = Abc_FrameReadOut(pAbc); @@ -4772,18 +4916,18 @@ int Abc_CommandSeq( Abc_Frame_t * pAbc, int argc, char ** argv ) return 1; } + if ( Abc_NtkLatchNum(pNtk) == 0 ) + { + fprintf( pErr, "The network has no latches.\n" ); + return 0; + } + if ( !Abc_NtkIsStrash(pNtk) ) { fprintf( pErr, "Conversion to sequential AIG works only for combinational AIGs (run \"strash\").\n" ); return 1; } -// if ( nLoops = Abc_NtkCountSelfFeedLatches(pNtk) ) -// { -// fprintf( pErr, "Cannot create sequential AIG because the network contains %d self-feeding latches.\n", nLoops ); -// return 0; -// } - // get the new network pNtkRes = Abc_NtkAigToSeq( pNtk ); if ( pNtkRes == NULL ) @@ -4890,13 +5034,12 @@ usage: int Abc_CommandRetime( Abc_Frame_t * pAbc, int argc, char ** argv ) { FILE * pOut, * pErr; - Abc_Ntk_t * pNtk; - int c; + Abc_Ntk_t * pNtk, * pNtkRes, * pNtkTemp; + int c, nMaxIters; int fForward; int fBackward; int fInitial; int fVerbose; - int nLoops; pNtk = Abc_FrameReadNet(pAbc); pOut = Abc_FrameReadOut(pAbc); @@ -4907,11 +5050,23 @@ int Abc_CommandRetime( Abc_Frame_t * pAbc, int argc, char ** argv ) fBackward = 0; fInitial = 1; fVerbose = 0; + nMaxIters = 15; util_getopt_reset(); - while ( ( c = util_getopt( argc, argv, "fbivh" ) ) != EOF ) + while ( ( c = util_getopt( argc, argv, "Ifbivh" ) ) != EOF ) { switch ( c ) { + case 'I': + if ( util_optind >= argc ) + { + fprintf( pErr, "Command line switch \"-I\" should be followed by a positive integer.\n" ); + goto usage; + } + nMaxIters = atoi(argv[util_optind]); + util_optind++; + if ( nMaxIters < 0 ) + goto usage; + break; case 'f': fForward ^= 1; break; @@ -4937,34 +5092,59 @@ int Abc_CommandRetime( Abc_Frame_t * pAbc, int argc, char ** argv ) return 1; } - if ( !Abc_NtkIsSeq(pNtk) ) + if ( !Abc_NtkIsSeq(pNtk) && Abc_NtkLatchNum(pNtk) == 0 ) { - fprintf( pErr, "Retiming works only for sequential AIG (run \"seq\").\n" ); + fprintf( pErr, "The network has no latches. Retiming is not performed.\n" ); return 0; } - if ( nLoops = Abc_NtkCountSelfFeedLatches(pNtk) ) + if ( Abc_NtkHasAig(pNtk) ) { - fprintf( pErr, "Cannot retime because the network contains %d self-feeding latches.\n", nLoops ); - return 0; + if ( Abc_NtkIsStrash(pNtk) ) + pNtkRes = Abc_NtkAigToSeq(pNtk); + else + { + if ( Abc_NtkGetChoiceNum(pNtk) ) + { + fprintf( pErr, "Currently cannot retime networks with choice nodes.\n" ); + return 0; + } + pNtkRes = Abc_NtkDup(pNtk); + } + // retime the network + if ( fForward ) + Seq_NtkSeqRetimeForward( pNtkRes, fInitial, fVerbose ); + else if ( fBackward ) + Seq_NtkSeqRetimeBackward( pNtkRes, fInitial, fVerbose ); + else + Seq_NtkSeqRetimeDelay( pNtkRes, nMaxIters, fInitial, fVerbose ); + // convert from the sequential AIG + if ( Abc_NtkIsStrash(pNtk) ) + { + pNtkRes = Abc_NtkSeqToLogicSop( pNtkTemp = pNtkRes ); + Abc_NtkDelete( pNtkTemp ); + } } - - // get the new network - if ( fForward ) - Seq_NtkSeqRetimeForward( pNtk, fInitial, fVerbose ); - else if ( fBackward ) - Seq_NtkSeqRetimeBackward( pNtk, fInitial, fVerbose ); else - Seq_NtkSeqRetimeDelay( pNtk, fInitial, fVerbose ); + pNtkRes = Seq_NtkRetime( pNtk, nMaxIters, fInitial, fVerbose ); + // replace the network + if ( pNtkRes == NULL ) + { + fprintf( pErr, "Retiming has failed.\n" ); + return 1; + } + // replace the current network + Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes ); return 0; usage: - fprintf( pErr, "usage: retime [-fbih]\n" ); - fprintf( pErr, "\t retimes sequential AIG (default is Pan's delay-optimal retiming)\n" ); - fprintf( pErr, "\t-f : toggle forward retiming [default = %s]\n", fForward? "yes": "no" ); - fprintf( pErr, "\t-b : toggle backward retiming [default = %s]\n", fBackward? "yes": "no" ); - fprintf( pErr, "\t-i : toggle computation of initial state [default = %s]\n", fInitial? "yes": "no" ); - fprintf( pErr, "\t-h : print the command usage\n"); + fprintf( pErr, "usage: retime [-I num] [-fbih]\n" ); + fprintf( pErr, "\t retimes the current network using Pan's delay-optimal retiming\n" ); + fprintf( pErr, "\t-I num : max number of iterations of l-value computation [default = %d]\n", nMaxIters ); + fprintf( pErr, "\t-f : toggle forward retiming (for AIGs) [default = %s]\n", fForward? "yes": "no" ); + fprintf( pErr, "\t-b : toggle backward retiming (for AIGs) [default = %s]\n", fBackward? "yes": "no" ); + fprintf( pErr, "\t-i : toggle computation of initial state [default = %s]\n", fInitial? "yes": "no" ); + fprintf( pErr, "\t-h : print the command usage\n"); return 1; } diff --git a/src/base/abci/abcPrint.c b/src/base/abci/abcPrint.c index e96825bb..4b4c01ae 100644 --- a/src/base/abci/abcPrint.c +++ b/src/base/abci/abcPrint.c @@ -20,6 +20,8 @@ #include "abc.h" #include "dec.h" +#include "main.h" +#include "mio.h" #include "seq.h" //////////////////////////////////////////////////////////////////////// @@ -524,6 +526,96 @@ void Abc_NodePrintKMap( Abc_Obj_t * pNode, int fUseRealNames ) } +/**Function************************************************************* + + Synopsis [Prints statistics about gates used in the network.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Abc_NtkPrintGates( Abc_Ntk_t * pNtk, int fUseLibrary ) +{ + Abc_Obj_t * pObj; + int fHasBdds, i; + int CountConst, CountBuf, CountInv, CountAnd, CountOr, CountOther, CounterTotal; + char * pSop; + + if ( fUseLibrary && Abc_NtkHasMapping(pNtk) ) + { + stmm_table * tTable; + stmm_generator * gen; + char * pName; + int * pCounter, Counter; + double Area, AreaTotal; + + // count the gates by name + CounterTotal = 0; + tTable = stmm_init_table(strcmp, stmm_strhash); + Abc_NtkForEachNode( pNtk, pObj, i ) + { + if ( i == 0 ) continue; + if ( !stmm_find_or_add( tTable, Mio_GateReadName(pObj->pData), (char ***)&pCounter ) ) + *pCounter = 0; + (*pCounter)++; + CounterTotal++; + } + // print the gates + AreaTotal = Abc_NtkGetMappedArea(pNtk); + stmm_foreach_item( tTable, gen, (char **)&pName, (char **)&Counter ) + { + Area = Counter * Mio_GateReadArea(Mio_LibraryReadGateByName(pNtk->pManFunc,pName)); + printf( "%-12s = %8d %10.2f %6.2f %%\n", pName, Counter, Area, 100.0 * Area / AreaTotal ); + } + printf( "%-12s = %8d %10.2f %6.2f %%\n", "TOTAL", CounterTotal, AreaTotal, 100.0 ); + stmm_free_table( tTable ); + return; + } + + // transform logic functions from BDD to SOP + if ( fHasBdds = Abc_NtkIsBddLogic(pNtk) ) + Abc_NtkBddToSop(pNtk); + + // get hold of the SOP of the node + CountConst = CountBuf = CountInv = CountAnd = CountOr = CountOther = CounterTotal = 0; + Abc_NtkForEachNode( pNtk, pObj, i ) + { + if ( i == 0 ) continue; + if ( Abc_NtkHasMapping(pNtk) ) + pSop = Mio_GateReadSop(pObj->pData); + else + pSop = pObj->pData; + // collect the stats + if ( Abc_SopIsConst0(pSop) || Abc_SopIsConst1(pSop) ) + CountConst++; + else if ( Abc_SopIsBuf(pSop) ) + CountBuf++; + else if ( Abc_SopIsInv(pSop) ) + CountInv++; + else if ( !Abc_SopIsComplement(pSop) && Abc_SopIsAndType(pSop) || Abc_SopIsComplement(pSop) && Abc_SopIsOrType(pSop) ) + CountAnd++; + else if ( Abc_SopIsComplement(pSop) && Abc_SopIsAndType(pSop) || !Abc_SopIsComplement(pSop) && Abc_SopIsOrType(pSop) ) + CountOr++; + else + CountOther++; + CounterTotal++; + } + printf( "Const = %8d %6.2f %%\n", CountConst , 100.0 * CountConst / CounterTotal ); + printf( "Buffer = %8d %6.2f %%\n", CountBuf , 100.0 * CountBuf / CounterTotal ); + printf( "Inverter = %8d %6.2f %%\n", CountInv , 100.0 * CountInv / CounterTotal ); + printf( "And = %8d %6.2f %%\n", CountAnd , 100.0 * CountAnd / CounterTotal ); + printf( "Or = %8d %6.2f %%\n", CountOr , 100.0 * CountOr / CounterTotal ); + printf( "Other = %8d %6.2f %%\n", CountOther , 100.0 * CountOther / CounterTotal ); + printf( "TOTAL = %8d %6.2f %%\n", CounterTotal, 100.0 * CounterTotal / CounterTotal ); + + // convert the network back into BDDs if this is how it was + if ( fHasBdds ) + Abc_NtkSopToBdd(pNtk); +} + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// diff --git a/src/base/abci/abcSweep.c b/src/base/abci/abcSweep.c index 9fe5bea0..1841ba8c 100644 --- a/src/base/abci/abcSweep.c +++ b/src/base/abci/abcSweep.c @@ -449,6 +449,7 @@ int Abc_NtkCleanup( Abc_Ntk_t * pNtk, int fVerbose ) Vec_Ptr_t * vNodes; Abc_Obj_t * pNode; int i, Counter; + assert( !Abc_NtkHasAig(pNtk) ); // mark the nodes reachable from the POs vNodes = Abc_NtkDfs( pNtk, 0 ); for ( i = 0; i < vNodes->nSize; i++ ) @@ -458,7 +459,7 @@ int Abc_NtkCleanup( Abc_Ntk_t * pNtk, int fVerbose ) } Vec_PtrFree( vNodes ); // if it is an AIG, also mark the constant 1 node - if ( Abc_NtkIsStrash(pNtk) ) + if ( Abc_NtkConst1(pNtk) ) Abc_NtkConst1(pNtk)->fMarkA = 1; // remove the non-marked nodes Counter = 0; @@ -514,7 +515,7 @@ int Abc_NtkSweep( Abc_Ntk_t * pNtk, int fVerbose ) { // sweep constants and single-input nodes Abc_NtkForEachNode( pNtk, pNode, i ) - if ( Abc_ObjFaninNum(pNode) < 2 ) + if ( i && Abc_ObjFaninNum(pNode) < 2 ) Abc_NodeSweep( pNode, fVerbose ); // make the network minimum base Abc_NtkRemoveDupFanins(pNtk); |