00001
00021 #include "abc.h"
00022
00026
00027 static void Abc_NtkAutoPrintAll( DdManager * dd, int nInputs, DdNode * pbOutputs[], int nOutputs, char * pInputNames[], char * pOutputNames[], int fNaive );
00028 static void Abc_NtkAutoPrintOne( DdManager * dd, int nInputs, DdNode * pbOutputs[], int Output, char * pInputNames[], char * pOutputNames[], int fNaive );
00029
00033
00045 void Abc_NtkAutoPrint( Abc_Ntk_t * pNtk, int Output, int fNaive, int fVerbose )
00046 {
00047 DdManager * dd;
00048 DdNode ** pbGlobal;
00049 char ** pInputNames;
00050 char ** pOutputNames;
00051 int nOutputs, nInputs, i;
00052 Vec_Ptr_t * vFuncsGlob;
00053 Abc_Obj_t * pObj;
00054
00055
00056 if ( Abc_NtkBuildGlobalBdds(pNtk, 10000000, 1, 1, fVerbose) == NULL )
00057 return;
00058
00059
00060 nInputs = Abc_NtkCiNum(pNtk);
00061 nOutputs = Abc_NtkCoNum(pNtk);
00062
00063 dd = Abc_NtkGlobalBddMan( pNtk );
00064
00065
00066 vFuncsGlob = Vec_PtrAlloc( Abc_NtkCoNum(pNtk) );
00067 Abc_NtkForEachCo( pNtk, pObj, i )
00068 Vec_PtrPush( vFuncsGlob, Abc_ObjGlobalBdd(pObj) );
00069 pbGlobal = (DdNode **)Vec_PtrArray( vFuncsGlob );
00070
00071
00072 pInputNames = Abc_NtkCollectCioNames( pNtk, 0 );
00073 pOutputNames = Abc_NtkCollectCioNames( pNtk, 1 );
00074
00075
00076 if ( fVerbose )
00077 printf( "Shared BDD size = %6d nodes.\n", Cudd_ReadKeys(dd) - Cudd_ReadDead(dd) );
00078
00079
00080 for ( i = 0; i < nInputs; i++ )
00081 Cudd_bddNewVar( dd );
00082 assert( Cudd_ReadSize(dd) == 2 * nInputs );
00083
00084
00085 Cudd_zddVarsFromBddVars( dd, 2 );
00086
00087
00088 if ( Output == -1 )
00089 Abc_NtkAutoPrintAll( dd, nInputs, pbGlobal, nOutputs, pInputNames, pOutputNames, fNaive );
00090 else
00091 Abc_NtkAutoPrintOne( dd, nInputs, pbGlobal, Output, pInputNames, pOutputNames, fNaive );
00092
00093
00094
00095
00096
00097
00098 Abc_NtkFreeGlobalBdds( pNtk, 1 );
00099 free( pInputNames );
00100 free( pOutputNames );
00101 Vec_PtrFree( vFuncsGlob );
00102 }
00103
00115 void Abc_NtkAutoPrintAll( DdManager * dd, int nInputs, DdNode * pbOutputs[], int nOutputs, char * pInputNames[], char * pOutputNames[], int fNaive )
00116 {
00117 DdNode * bSpace1, * bSpace2, * bCanVars, * bReduced, * zEquations;
00118 double nMints;
00119 int nSupp, SigCounter, o;
00120
00121 int nAutos;
00122 int nAutoSyms;
00123 int nAutoSymsMax;
00124 int nAutoSymsMaxSupp;
00125 int nAutoSymOuts;
00126 int nSuppSizeMax;
00127 int clk;
00128
00129 nAutoSymOuts = 0;
00130 nAutoSyms = 0;
00131 nAutoSymsMax = 0;
00132 nAutoSymsMaxSupp = 0;
00133 nSuppSizeMax = 0;
00134 clk = clock();
00135
00136 SigCounter = 0;
00137 for ( o = 0; o < nOutputs; o++ )
00138 {
00139
00140 bSpace1 = Extra_bddSpaceFromFunction( dd, pbOutputs[o], pbOutputs[o] ); Cudd_Ref( bSpace1 );
00141 bCanVars = Extra_bddSpaceCanonVars( dd, bSpace1 ); Cudd_Ref( bCanVars );
00142 bReduced = Extra_bddSpaceReduce( dd, pbOutputs[o], bCanVars ); Cudd_Ref( bReduced );
00143 zEquations = Extra_bddSpaceEquations( dd, bSpace1 ); Cudd_Ref( zEquations );
00144
00145 nSupp = Cudd_SupportSize( dd, bSpace1 );
00146 nMints = Cudd_CountMinterm( dd, bSpace1, nSupp );
00147 nAutos = Extra_Base2LogDouble(nMints);
00148 printf( "Output #%3d: Inputs = %2d. AutoK = %2d.\n", o, nSupp, nAutos );
00149
00150 if ( nAutos > 0 )
00151 {
00152 nAutoSymOuts++;
00153 nAutoSyms += nAutos;
00154 if ( nAutoSymsMax < nAutos )
00155 {
00156 nAutoSymsMax = nAutos;
00157 nAutoSymsMaxSupp = nSupp;
00158 }
00159 }
00160 if ( nSuppSizeMax < nSupp )
00161 nSuppSizeMax = nSupp;
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 bSpace2 = Extra_bddSpaceFromMatrixPos( dd, zEquations ); Cudd_Ref( bSpace2 );
00173
00174
00175 if ( bSpace1 != bSpace2 )
00176 printf( "Spaces are NOT EQUAL!\n" );
00177
00178
00179
00180 Cudd_RecursiveDeref( dd, bSpace1 );
00181 Cudd_RecursiveDeref( dd, bSpace2 );
00182 Cudd_RecursiveDeref( dd, bCanVars );
00183 Cudd_RecursiveDeref( dd, bReduced );
00184 Cudd_RecursiveDerefZdd( dd, zEquations );
00185 }
00186
00187 printf( "The cumulative statistics for all outputs:\n" );
00188 printf( "Ins=%3d ", nInputs );
00189 printf( "InMax=%3d ", nSuppSizeMax );
00190 printf( "Outs=%3d ", nOutputs );
00191 printf( "Auto=%3d ", nAutoSymOuts );
00192 printf( "SumK=%3d ", nAutoSyms );
00193 printf( "KMax=%2d ", nAutoSymsMax );
00194 printf( "Supp=%3d ", nAutoSymsMaxSupp );
00195 printf( "Time=%4.2f ", (float)(clock() - clk)/(float)(CLOCKS_PER_SEC) );
00196 printf( "\n" );
00197 }
00198
00210 void Abc_NtkAutoPrintOne( DdManager * dd, int nInputs, DdNode * pbOutputs[], int Output, char * pInputNames[], char * pOutputNames[], int fNaive )
00211 {
00212 DdNode * bSpace1, * bCanVars, * bReduced, * zEquations;
00213 double nMints;
00214 int nSupp, SigCounter;
00215 int nAutos;
00216
00217 SigCounter = 0;
00218 bSpace1 = Extra_bddSpaceFromFunctionFast( dd, pbOutputs[Output] ); Cudd_Ref( bSpace1 );
00219
00220 bCanVars = Extra_bddSpaceCanonVars( dd, bSpace1 ); Cudd_Ref( bCanVars );
00221 bReduced = Extra_bddSpaceReduce( dd, pbOutputs[Output], bCanVars ); Cudd_Ref( bReduced );
00222 zEquations = Extra_bddSpaceEquations( dd, bSpace1 ); Cudd_Ref( zEquations );
00223
00224 nSupp = Cudd_SupportSize( dd, bSpace1 );
00225 nMints = Cudd_CountMinterm( dd, bSpace1, nSupp );
00226 nAutos = Extra_Base2LogDouble(nMints);
00227 printf( "Output #%3d: Inputs = %2d. AutoK = %2d.\n", Output, nSupp, nAutos );
00228
00229 Cudd_RecursiveDeref( dd, bSpace1 );
00230 Cudd_RecursiveDeref( dd, bCanVars );
00231 Cudd_RecursiveDeref( dd, bReduced );
00232 Cudd_RecursiveDerefZdd( dd, zEquations );
00233 }
00234
00238
00239