00001
00021 #include "abc.h"
00022
00026
00027 static void Abc_NtkSymmetriesUsingBdds( Abc_Ntk_t * pNtk, int fNaive, int fReorder, int fVerbose );
00028 static void Abc_NtkSymmetriesUsingSandS( Abc_Ntk_t * pNtk, int fVerbose );
00029 static void Ntk_NetworkSymmsBdd( DdManager * dd, Abc_Ntk_t * pNtk, int fNaive, int fVerbose );
00030 static void Ntk_NetworkSymmsPrint( Abc_Ntk_t * pNtk, Extra_SymmInfo_t * pSymms );
00031
00035
00047 void Abc_NtkSymmetries( Abc_Ntk_t * pNtk, int fUseBdds, int fNaive, int fReorder, int fVerbose )
00048 {
00049 if ( fUseBdds || fNaive )
00050 Abc_NtkSymmetriesUsingBdds( pNtk, fNaive, fReorder, fVerbose );
00051 else
00052 Abc_NtkSymmetriesUsingSandS( pNtk, fVerbose );
00053 }
00054
00066 void Abc_NtkSymmetriesUsingSandS( Abc_Ntk_t * pNtk, int fVerbose )
00067 {
00068 extern int Sim_ComputeTwoVarSymms( Abc_Ntk_t * pNtk, int fVerbose );
00069 int nSymms = Sim_ComputeTwoVarSymms( pNtk, fVerbose );
00070 printf( "The total number of symmetries is %d.\n", nSymms );
00071 }
00072
00084 void Abc_NtkSymmetriesUsingBdds( Abc_Ntk_t * pNtk, int fNaive, int fReorder, int fVerbose )
00085 {
00086 DdManager * dd;
00087 int clk, clkBdd, clkSym;
00088 int fGarbCollect = 1;
00089
00090
00091 clk = clock();
00092 dd = Abc_NtkBuildGlobalBdds( pNtk, 10000000, 1, fReorder, fVerbose );
00093 printf( "Shared BDD size = %d nodes.\n", Abc_NtkSizeOfGlobalBdds(pNtk) );
00094 Cudd_AutodynDisable( dd );
00095 if ( !fGarbCollect )
00096 Cudd_DisableGarbageCollection( dd );
00097 Cudd_zddVarsFromBddVars( dd, 2 );
00098 clkBdd = clock() - clk;
00099
00100 clk = clock();
00101 Ntk_NetworkSymmsBdd( dd, pNtk, fNaive, fVerbose );
00102 clkSym = clock() - clk;
00103
00104 Abc_NtkFreeGlobalBdds( pNtk, 1 );
00105 printf( "Statistics of BDD-based symmetry detection:\n" );
00106 printf( "Algorithm = %s. Reordering = %s. Garbage collection = %s.\n",
00107 fNaive? "naive" : "fast", fReorder? "yes" : "no", fGarbCollect? "yes" : "no" );
00108 PRT( "Constructing BDDs", clkBdd );
00109 PRT( "Computing symms ", clkSym );
00110 PRT( "TOTAL ", clkBdd + clkSym );
00111 }
00112
00124 void Ntk_NetworkSymmsBdd( DdManager * dd, Abc_Ntk_t * pNtk, int fNaive, int fVerbose )
00125 {
00126 Extra_SymmInfo_t * pSymms;
00127 Abc_Obj_t * pNode;
00128 DdNode * bFunc;
00129 int nSymms = 0;
00130 int nSupps = 0;
00131 int i;
00132
00133
00134 Abc_NtkForEachCo( pNtk, pNode, i )
00135 {
00136
00137 bFunc = Abc_ObjGlobalBdd( pNode );
00138 nSupps += Cudd_SupportSize( dd, bFunc );
00139 if ( Cudd_IsConstant(bFunc) )
00140 continue;
00141 if ( fNaive )
00142 pSymms = Extra_SymmPairsComputeNaive( dd, bFunc );
00143 else
00144 pSymms = Extra_SymmPairsCompute( dd, bFunc );
00145 nSymms += pSymms->nSymms;
00146 if ( fVerbose )
00147 {
00148 printf( "Output %6s (%d): ", Abc_ObjName(pNode), pSymms->nSymms );
00149 Ntk_NetworkSymmsPrint( pNtk, pSymms );
00150 }
00151
00152 Extra_SymmPairsDissolve( pSymms );
00153 }
00154 printf( "Total number of vars in functional supports = %8d.\n", nSupps );
00155 printf( "Total number of two-variable symmetries = %8d.\n", nSymms );
00156 }
00157
00169 void Ntk_NetworkSymmsPrint( Abc_Ntk_t * pNtk, Extra_SymmInfo_t * pSymms )
00170 {
00171 char ** pInputNames;
00172 int * pVarTaken;
00173 int i, k, nVars, nSize, fStart;
00174
00175
00176 nVars = Abc_NtkCiNum(pNtk);
00177 pInputNames = Abc_NtkCollectCioNames( pNtk, 0 );
00178
00179
00180 pVarTaken = ALLOC( int, nVars );
00181 memset( pVarTaken, 0, sizeof(int) * nVars );
00182
00183
00184 fStart = 1;
00185 nSize = pSymms->nVars;
00186 for ( i = 0; i < nSize; i++ )
00187 {
00188
00189 if ( pVarTaken[i] )
00190 continue;
00191
00192 for ( k = 0; k < nSize; k++ )
00193 {
00194 if ( k == i )
00195 continue;
00196 if ( pSymms->pSymms[i][k] == 0 )
00197 continue;
00198
00199 assert( pVarTaken[k] == 0 );
00200
00201 if ( fStart == 1 )
00202 {
00203 fStart = 0;
00204 printf( " { %s", pInputNames[ pSymms->pVars[i] ] );
00205
00206 pVarTaken[i] = 1;
00207 }
00208 printf( " %s", pInputNames[ pSymms->pVars[k] ] );
00209
00210 pVarTaken[k] = 1;
00211 }
00212 if ( fStart == 0 )
00213 {
00214 printf( " }" );
00215 fStart = 1;
00216 }
00217 }
00218 printf( "\n" );
00219
00220 free( pInputNames );
00221 free( pVarTaken );
00222 }
00223
00224
00228
00229