00001
00021 #include "rwr.h"
00022 #include "main.h"
00023 #include "dec.h"
00024
00028
00032
00044 Rwr_Man_t * Rwr_ManStart( bool fPrecompute )
00045 {
00046 Dec_Man_t * pManDec;
00047 Rwr_Man_t * p;
00048 int clk = clock();
00049 clk = clock();
00050 p = ALLOC( Rwr_Man_t, 1 );
00051 memset( p, 0, sizeof(Rwr_Man_t) );
00052 p->nFuncs = (1<<16);
00053 pManDec = Abc_FrameReadManDec();
00054 p->puCanons = pManDec->puCanons;
00055 p->pPhases = pManDec->pPhases;
00056 p->pPerms = pManDec->pPerms;
00057 p->pMap = pManDec->pMap;
00058
00059 p->pPractical = Rwr_ManGetPractical( p );
00060
00061 p->pTable = ALLOC( Rwr_Node_t *, p->nFuncs );
00062 memset( p->pTable, 0, sizeof(Rwr_Node_t *) * p->nFuncs );
00063
00064 p->pMmNode = Extra_MmFixedStart( sizeof(Rwr_Node_t) );
00065 p->vForest = Vec_PtrAlloc( 100 );
00066 Rwr_ManAddVar( p, 0x0000, fPrecompute );
00067 Rwr_ManAddVar( p, 0xAAAA, fPrecompute );
00068 Rwr_ManAddVar( p, 0xCCCC, fPrecompute );
00069 Rwr_ManAddVar( p, 0xF0F0, fPrecompute );
00070 Rwr_ManAddVar( p, 0xFF00, fPrecompute );
00071 p->nClasses = 5;
00072
00073 p->nTravIds = 1;
00074 p->pPerms4 = Extra_Permutations( 4 );
00075 p->vLevNums = Vec_IntAlloc( 50 );
00076 p->vFanins = Vec_PtrAlloc( 50 );
00077 p->vFaninsCur = Vec_PtrAlloc( 50 );
00078 p->vNodesTemp = Vec_PtrAlloc( 50 );
00079 if ( fPrecompute )
00080 {
00081 Rwr_ManPrecompute( p );
00082
00083 Rwr_ManWriteToArray( p );
00084 }
00085 else
00086 {
00087 Rwr_ManLoadFromArray( p, 0 );
00088
00089 Rwr_ManPreprocess( p );
00090 }
00091 p->timeStart = clock() - clk;
00092 return p;
00093 }
00094
00106 void Rwr_ManStop( Rwr_Man_t * p )
00107 {
00108 if ( p->vClasses )
00109 {
00110 Rwr_Node_t * pNode;
00111 int i, k;
00112 Vec_VecForEachEntry( p->vClasses, pNode, i, k )
00113 Dec_GraphFree( (Dec_Graph_t *)pNode->pNext );
00114 }
00115 if ( p->vClasses ) Vec_VecFree( p->vClasses );
00116 Vec_PtrFree( p->vNodesTemp );
00117 Vec_PtrFree( p->vForest );
00118 Vec_IntFree( p->vLevNums );
00119 Vec_PtrFree( p->vFanins );
00120 Vec_PtrFree( p->vFaninsCur );
00121 Extra_MmFixedStop( p->pMmNode );
00122 FREE( p->pMapInv );
00123 free( p->pTable );
00124 free( p->pPractical );
00125 free( p->pPerms4 );
00126 free( p );
00127 }
00128
00140 void Rwr_ManPrintStats( Rwr_Man_t * p )
00141 {
00142 int i, Counter = 0;
00143 for ( i = 0; i < 222; i++ )
00144 Counter += (p->nScores[i] > 0);
00145
00146 printf( "Rewriting statistics:\n" );
00147 printf( "Total cuts tries = %8d.\n", p->nCutsGood );
00148 printf( "Bad cuts found = %8d.\n", p->nCutsBad );
00149 printf( "Total subgraphs = %8d.\n", p->nSubgraphs );
00150 printf( "Used NPN classes = %8d.\n", Counter );
00151 printf( "Nodes considered = %8d.\n", p->nNodesConsidered );
00152 printf( "Nodes rewritten = %8d.\n", p->nNodesRewritten );
00153 printf( "Gain = %8d. (%6.2f %%).\n", p->nNodesBeg-p->nNodesEnd, 100.0*(p->nNodesBeg-p->nNodesEnd)/p->nNodesBeg );
00154 PRT( "Start ", p->timeStart );
00155 PRT( "Cuts ", p->timeCut );
00156 PRT( "Resynthesis ", p->timeRes );
00157 PRT( " Mffc ", p->timeMffc );
00158 PRT( " Eval ", p->timeEval );
00159 PRT( "Update ", p->timeUpdate );
00160 PRT( "TOTAL ", p->timeTotal );
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 printf( "\n" );
00173
00174 }
00175
00187 void Rwr_ManPrintStatsFile( Rwr_Man_t * p )
00188 {
00189 FILE * pTable;
00190 pTable = fopen( "stats.txt", "a+" );
00191 fprintf( pTable, "%d ", p->nCutsGood );
00192 fprintf( pTable, "%d ", p->nSubgraphs );
00193 fprintf( pTable, "%d ", p->nNodesRewritten );
00194 fprintf( pTable, "%d", p->nNodesGained );
00195 fprintf( pTable, "\n" );
00196 fclose( pTable );
00197 }
00198
00210 void * Rwr_ManReadDecs( Rwr_Man_t * p )
00211 {
00212 return p->pGraph;
00213 }
00214
00226 Vec_Ptr_t * Rwr_ManReadLeaves( Rwr_Man_t * p )
00227 {
00228 return p->vFanins;
00229 }
00230
00242 int Rwr_ManReadCompl( Rwr_Man_t * p )
00243 {
00244 return p->fCompl;
00245 }
00246
00258 void Rwr_ManAddTimeCuts( Rwr_Man_t * p, int Time )
00259 {
00260 p->timeCut += Time;
00261 }
00262
00274 void Rwr_ManAddTimeUpdate( Rwr_Man_t * p, int Time )
00275 {
00276 p->timeUpdate += Time;
00277 }
00278
00290 void Rwr_ManAddTimeTotal( Rwr_Man_t * p, int Time )
00291 {
00292 p->timeTotal += Time;
00293 }
00294
00295
00307 void Rwr_Precompute()
00308 {
00309 Rwr_Man_t * p;
00310 p = Rwr_ManStart( 1 );
00311 Rwr_ManStop( p );
00312 }
00313
00317
00318