00001
00021 #include "cutInt.h"
00022
00026
00027 extern void Npn_StartTruth8( uint8 uTruths[][32] );
00028
00032
00044 Cut_Man_t * Cut_ManStart( Cut_Params_t * pParams )
00045 {
00046 Cut_Man_t * p;
00047 int clk = clock();
00048
00049
00050 assert( pParams->nVarsMax >= 3 && pParams->nVarsMax <= CUT_SIZE_MAX );
00051 p = ALLOC( Cut_Man_t, 1 );
00052 memset( p, 0, sizeof(Cut_Man_t) );
00053
00054 p->pParams = pParams;
00055
00056 p->vCutsNew = Vec_PtrAlloc( pParams->nIdsMax );
00057 Vec_PtrFill( p->vCutsNew, pParams->nIdsMax, NULL );
00058
00059 if ( pParams->fSeq )
00060 {
00061 p->pParams->fFilter = 1;
00062 p->vCutsOld = Vec_PtrAlloc( pParams->nIdsMax );
00063 Vec_PtrFill( p->vCutsOld, pParams->nIdsMax, NULL );
00064 p->vCutsTemp = Vec_PtrAlloc( pParams->nCutSet );
00065 Vec_PtrFill( p->vCutsTemp, pParams->nCutSet, NULL );
00066 if ( pParams->fTruth && pParams->nVarsMax > 5 )
00067 {
00068 pParams->fTruth = 0;
00069 printf( "Skipping computation of truth tables for sequential cuts with more than 5 inputs.\n" );
00070 }
00071 }
00072
00073 p->EntrySize = sizeof(Cut_Cut_t) + pParams->nVarsMax * sizeof(int);
00074 if ( pParams->fTruth )
00075 {
00076 if ( pParams->nVarsMax > 14 )
00077 {
00078 pParams->fTruth = 0;
00079 printf( "Skipping computation of truth table for more than %d inputs.\n", 14 );
00080 }
00081 else
00082 {
00083 p->nTruthWords = Cut_TruthWords( pParams->nVarsMax );
00084 p->EntrySize += p->nTruthWords * sizeof(unsigned);
00085 }
00086 p->puTemp[0] = ALLOC( unsigned, 4 * p->nTruthWords );
00087 p->puTemp[1] = p->puTemp[0] + p->nTruthWords;
00088 p->puTemp[2] = p->puTemp[1] + p->nTruthWords;
00089 p->puTemp[3] = p->puTemp[2] + p->nTruthWords;
00090 }
00091
00092 if ( pParams->fRecord )
00093 {
00094 p->vNodeCuts = Vec_IntStart( pParams->nIdsMax );
00095 p->vNodeStarts = Vec_IntStart( pParams->nIdsMax );
00096 p->vCutPairs = Vec_IntAlloc( 0 );
00097 }
00098
00099 if ( pParams->fMap && !p->pParams->fSeq )
00100 {
00101 p->vDelays = Vec_IntStart( pParams->nIdsMax );
00102 p->vDelays2 = Vec_IntStart( pParams->nIdsMax );
00103 p->vCutsMax = Vec_PtrStart( pParams->nIdsMax );
00104 }
00105
00106 p->pMmCuts = Extra_MmFixedStart( p->EntrySize );
00107 p->vTemp = Vec_PtrAlloc( 100 );
00108 return p;
00109 }
00110
00122 void Cut_ManStop( Cut_Man_t * p )
00123 {
00124 Cut_Cut_t * pCut;
00125 int i;
00126
00127
00128
00129 Vec_PtrForEachEntry( p->vCutsNew, pCut, i )
00130 if ( pCut != NULL )
00131 {
00132 int k = 0;
00133 }
00134 if ( p->vCutsNew ) Vec_PtrFree( p->vCutsNew );
00135 if ( p->vCutsOld ) Vec_PtrFree( p->vCutsOld );
00136 if ( p->vCutsTemp ) Vec_PtrFree( p->vCutsTemp );
00137 if ( p->vFanCounts ) Vec_IntFree( p->vFanCounts );
00138 if ( p->vTemp ) Vec_PtrFree( p->vTemp );
00139
00140 if ( p->vCutsMax ) Vec_PtrFree( p->vCutsMax );
00141 if ( p->vDelays ) Vec_IntFree( p->vDelays );
00142 if ( p->vDelays2 ) Vec_IntFree( p->vDelays2 );
00143 if ( p->vNodeCuts ) Vec_IntFree( p->vNodeCuts );
00144 if ( p->vNodeStarts ) Vec_IntFree( p->vNodeStarts );
00145 if ( p->vCutPairs ) Vec_IntFree( p->vCutPairs );
00146 if ( p->puTemp[0] ) free( p->puTemp[0] );
00147
00148 Extra_MmFixedStop( p->pMmCuts );
00149 free( p );
00150 }
00151
00163 void Cut_ManPrintStats( Cut_Man_t * p )
00164 {
00165 if ( p->pReady )
00166 {
00167 Cut_CutRecycle( p, p->pReady );
00168 p->pReady = NULL;
00169 }
00170 printf( "Cut computation statistics:\n" );
00171 printf( "Current cuts = %8d. (Trivial = %d.)\n", p->nCutsCur-p->nCutsTriv, p->nCutsTriv );
00172 printf( "Peak cuts = %8d.\n", p->nCutsPeak );
00173 printf( "Total allocated = %8d.\n", p->nCutsAlloc );
00174 printf( "Total deallocated = %8d.\n", p->nCutsDealloc );
00175 printf( "Cuts filtered = %8d.\n", p->nCutsFilter );
00176 printf( "Nodes saturated = %8d. (Max cuts = %d.)\n", p->nCutsLimit, p->pParams->nKeepMax );
00177 printf( "Cuts per node = %8.1f\n", ((float)(p->nCutsCur-p->nCutsTriv))/p->nNodes );
00178 printf( "The cut size = %8d bytes.\n", p->EntrySize );
00179 printf( "Peak memory = %8.2f Mb.\n", (float)p->nCutsPeak * p->EntrySize / (1<<20) );
00180 printf( "Total nodes = %8d.\n", p->nNodes );
00181 if ( p->pParams->fDag || p->pParams->fTree )
00182 {
00183 printf( "DAG nodes = %8d.\n", p->nNodesDag );
00184 printf( "Tree nodes = %8d.\n", p->nNodes - p->nNodesDag );
00185 }
00186 printf( "Nodes w/o cuts = %8d.\n", p->nNodesNoCuts );
00187 if ( p->pParams->fMap && !p->pParams->fSeq )
00188 printf( "Mapping delay = %8d.\n", p->nDelayMin );
00189
00190 PRT( "Merge ", p->timeMerge );
00191 PRT( "Union ", p->timeUnion );
00192 PRT( "Filter", p->timeFilter );
00193 PRT( "Truth ", p->timeTruth );
00194 PRT( "Map ", p->timeMap );
00195
00196
00197
00198 }
00199
00200
00212 void Cut_ManPrintStatsToFile( Cut_Man_t * p, char * pFileName, int TimeTotal )
00213 {
00214 FILE * pTable;
00215 pTable = fopen( "cut_stats.txt", "a+" );
00216 fprintf( pTable, "%-20s ", pFileName );
00217 fprintf( pTable, "%8d ", p->nNodes );
00218 fprintf( pTable, "%6.1f ", ((float)(p->nCutsCur))/p->nNodes );
00219 fprintf( pTable, "%6.2f ", ((float)(100.0 * p->nCutsLimit))/p->nNodes );
00220 fprintf( pTable, "%6.2f ", (float)p->nCutsPeak * p->EntrySize / (1<<20) );
00221 fprintf( pTable, "%6.2f ", (float)(TimeTotal)/(float)(CLOCKS_PER_SEC) );
00222 fprintf( pTable, "\n" );
00223 fclose( pTable );
00224 }
00225
00237 void Cut_ManSetFanoutCounts( Cut_Man_t * p, Vec_Int_t * vFanCounts )
00238 {
00239 p->vFanCounts = vFanCounts;
00240 }
00241
00253 void Cut_ManSetNodeAttrs( Cut_Man_t * p, Vec_Int_t * vNodeAttrs )
00254 {
00255 p->vNodeAttrs = vNodeAttrs;
00256 }
00257
00269 int Cut_ManReadVarsMax( Cut_Man_t * p )
00270 {
00271 return p->pParams->nVarsMax;
00272 }
00273
00285 Cut_Params_t * Cut_ManReadParams( Cut_Man_t * p )
00286 {
00287 return p->pParams;
00288 }
00289
00301 Vec_Int_t * Cut_ManReadNodeAttrs( Cut_Man_t * p )
00302 {
00303 return p->vNodeAttrs;
00304 }
00305
00317 void Cut_ManIncrementDagNodes( Cut_Man_t * p )
00318 {
00319 p->nNodesDag++;
00320 }
00321
00325
00326