00001
00021 #include "rwt.h"
00022 #include "deco.h"
00023
00027
00028 static unsigned short * s_puCanons = NULL;
00029 static char * s_pPhases = NULL;
00030 static char * s_pPerms = NULL;
00031 static unsigned char * s_pMap = NULL;
00032
00036
00048 void Rwt_ManGlobalStart()
00049 {
00050 if ( s_puCanons == NULL )
00051 Extra_Truth4VarNPN( &s_puCanons, &s_pPhases, &s_pPerms, &s_pMap );
00052 }
00053
00065 void Rwt_ManGlobalStop()
00066 {
00067 FREE( s_puCanons );
00068 FREE( s_pPhases );
00069 FREE( s_pPerms );
00070 FREE( s_pMap );
00071 }
00072
00084 Rwt_Man_t * Rwt_ManStart( int fPrecompute )
00085 {
00086 Rwt_Man_t * p;
00087 int clk = clock();
00088 clk = clock();
00089 p = ALLOC( Rwt_Man_t, 1 );
00090 memset( p, 0, sizeof(Rwt_Man_t) );
00091 p->nFuncs = (1<<16);
00092
00093 Rwt_ManGlobalStart();
00094 p->puCanons = s_puCanons;
00095 p->pPhases = s_pPhases;
00096 p->pPerms = s_pPerms;
00097 p->pMap = s_pMap;
00098
00099 p->pPractical = Rwt_ManGetPractical( p );
00100
00101 p->pTable = ALLOC( Rwt_Node_t *, p->nFuncs );
00102 memset( p->pTable, 0, sizeof(Rwt_Node_t *) * p->nFuncs );
00103
00104 p->pMmNode = Mem_FixedStart( sizeof(Rwt_Node_t) );
00105 p->vForest = Vec_PtrAlloc( 100 );
00106 Rwt_ManAddVar( p, 0x0000, fPrecompute );
00107 Rwt_ManAddVar( p, 0xAAAA, fPrecompute );
00108 Rwt_ManAddVar( p, 0xCCCC, fPrecompute );
00109 Rwt_ManAddVar( p, 0xF0F0, fPrecompute );
00110 Rwt_ManAddVar( p, 0xFF00, fPrecompute );
00111 p->nClasses = 5;
00112
00113 p->nTravIds = 1;
00114 p->pPerms4 = Extra_Permutations( 4 );
00115 p->vLevNums = Vec_IntAlloc( 50 );
00116 p->vFanins = Vec_PtrAlloc( 50 );
00117 p->vFaninsCur = Vec_PtrAlloc( 50 );
00118 p->vNodesTemp = Vec_PtrAlloc( 50 );
00119 if ( fPrecompute )
00120 {
00121
00122
00123
00124 }
00125 else
00126 {
00127 Rwt_ManLoadFromArray( p, 0 );
00128
00129 Rwt_ManPreprocess( p );
00130 }
00131 p->timeStart = clock() - clk;
00132 return p;
00133 }
00134
00146 void Rwt_ManStop( Rwt_Man_t * p )
00147 {
00148 if ( p->vClasses )
00149 {
00150 Rwt_Node_t * pNode;
00151 int i, k;
00152 Vec_VecForEachEntry( p->vClasses, pNode, i, k )
00153 Dec_GraphFree( (Dec_Graph_t *)pNode->pNext );
00154 }
00155 if ( p->vClasses ) Vec_VecFree( p->vClasses );
00156 Vec_PtrFree( p->vNodesTemp );
00157 Vec_PtrFree( p->vForest );
00158 Vec_IntFree( p->vLevNums );
00159 Vec_PtrFree( p->vFanins );
00160 Vec_PtrFree( p->vFaninsCur );
00161 Mem_FixedStop( p->pMmNode, 0 );
00162 FREE( p->pMapInv );
00163 free( p->pTable );
00164 free( p->pPractical );
00165 free( p->pPerms4 );
00166 free( p );
00167 }
00168
00180 void Rwt_ManPrintStats( Rwt_Man_t * p )
00181 {
00182 int i, Counter = 0;
00183 for ( i = 0; i < 222; i++ )
00184 Counter += (p->nScores[i] > 0);
00185
00186 printf( "Rewriting statistics:\n" );
00187 printf( "Total cuts tries = %8d.\n", p->nCutsGood );
00188 printf( "Bad cuts found = %8d.\n", p->nCutsBad );
00189 printf( "Total subgraphs = %8d.\n", p->nSubgraphs );
00190 printf( "Used NPN classes = %8d.\n", Counter );
00191 printf( "Nodes considered = %8d.\n", p->nNodesConsidered );
00192 printf( "Nodes rewritten = %8d.\n", p->nNodesRewritten );
00193 printf( "Calculated gain = %8d.\n", p->nNodesGained );
00194 PRT( "Start ", p->timeStart );
00195 PRT( "Cuts ", p->timeCut );
00196 PRT( "Truth ", p->timeTruth );
00197 PRT( "Resynthesis ", p->timeRes );
00198 PRT( " Mffc ", p->timeMffc );
00199 PRT( " Eval ", p->timeEval );
00200 PRT( "Update ", p->timeUpdate );
00201 PRT( "TOTAL ", p->timeTotal );
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 }
00215
00227 void Rwt_ManPrintStatsFile( Rwt_Man_t * p )
00228 {
00229 FILE * pTable;
00230 pTable = fopen( "stats.txt", "a+" );
00231 fprintf( pTable, "%d ", p->nCutsGood );
00232 fprintf( pTable, "%d ", p->nSubgraphs );
00233 fprintf( pTable, "%d ", p->nNodesRewritten );
00234 fprintf( pTable, "%d", p->nNodesGained );
00235 fprintf( pTable, "\n" );
00236 fclose( pTable );
00237 }
00238
00250 void * Rwt_ManReadDecs( Rwt_Man_t * p )
00251 {
00252 return p->pGraph;
00253 }
00254
00266 Vec_Ptr_t * Rwt_ManReadLeaves( Rwt_Man_t * p )
00267 {
00268 return p->vFanins;
00269 }
00270
00282 int Rwt_ManReadCompl( Rwt_Man_t * p )
00283 {
00284 return p->fCompl;
00285 }
00286
00298 void Rwt_ManAddTimeCuts( Rwt_Man_t * p, int Time )
00299 {
00300 p->timeCut += Time;
00301 }
00302
00314 void Rwt_ManAddTimeUpdate( Rwt_Man_t * p, int Time )
00315 {
00316 p->timeUpdate += Time;
00317 }
00318
00330 void Rwt_ManAddTimeTotal( Rwt_Man_t * p, int Time )
00331 {
00332 p->timeTotal += Time;
00333 }
00334
00335
00347 void Rwt_Precompute()
00348 {
00349 Rwt_Man_t * p;
00350 p = Rwt_ManStart( 1 );
00351 Rwt_ManStop( p );
00352 }
00353
00357
00358