00001
00021 #include "cutInt.h"
00022
00026
00027 #define CUT_CELL_MVAR 9
00028
00029 typedef struct Cut_Cell_t_ Cut_Cell_t;
00030 typedef struct Cut_CMan_t_ Cut_CMan_t;
00031
00032 struct Cut_Cell_t_
00033 {
00034 Cut_Cell_t * pNext;
00035 Cut_Cell_t * pNextVar;
00036 Cut_Cell_t * pParent;
00037 int nUsed;
00038 char Box[4];
00039 unsigned nVars : 4;
00040 unsigned CrossBar0 : 4;
00041 unsigned CrossBar1 : 4;
00042 unsigned CrossBarPhase : 2;
00043 unsigned CanonPhase : 18;
00044 char CanonPerm[CUT_CELL_MVAR+3];
00045 short Store[2*CUT_CELL_MVAR];
00046 unsigned uTruth[1<<(CUT_CELL_MVAR-5)];
00047 };
00048
00049 struct Cut_CMan_t_
00050 {
00051
00052 Extra_MmFixed_t * pMem;
00053 st_table * tTable;
00054 Cut_Cell_t * pSameVar[CUT_CELL_MVAR+1];
00055
00056 unsigned uInputs[CUT_CELL_MVAR][1<<(CUT_CELL_MVAR-5)];
00057
00058 unsigned uTemp1[22][1<<(CUT_CELL_MVAR-5)];
00059 unsigned uTemp2[22][1<<(CUT_CELL_MVAR-5)];
00060 unsigned uTemp3[22][1<<(CUT_CELL_MVAR-5)];
00061 unsigned uFinal[1<<(CUT_CELL_MVAR-5)];
00062 unsigned puAux[1<<(CUT_CELL_MVAR-5)];
00063
00064 int nTotal;
00065 int nGood;
00066 int nVarCounts[CUT_CELL_MVAR+1];
00067 int nSymGroups[CUT_CELL_MVAR+1];
00068 int nSymGroupsE[CUT_CELL_MVAR+1];
00069 int timeCanon;
00070 int timeSupp;
00071 int timeTable;
00072 int nCellFound;
00073 int nCellNotFound;
00074 };
00075
00076
00077 static char * s_NP3[22] = {
00078 " 0\n",
00079 " 1\n",
00080 "1 1\n",
00081 "11 1\n",
00082 "11 0\n",
00083 "10 1\n01 1\n",
00084 "111 1\n",
00085 "111 0\n",
00086 "11- 1\n1-1 1\n",
00087 "11- 0\n1-1 0\n",
00088 "111 1\n100 1\n010 1\n001 1\n",
00089 "10- 0\n1-0 0\n011 0\n",
00090 "101 1\n110 1\n",
00091 "101 0\n110 0\n",
00092 "11- 1\n1-1 1\n-11 1\n",
00093 "111 1\n000 1\n",
00094 "111 0\n000 0\n",
00095 "11- 1\n-11 1\n0-1 1\n",
00096 "011 1\n101 1\n110 1\n",
00097 "011 0\n101 0\n110 0\n",
00098 "100 1\n-11 1\n",
00099 "100 0\n-11 0\n"
00100 };
00101
00102
00103 static char * s_NP3Names[22] = {
00104 " const 0 ",
00105 " const 1 ",
00106 " a ",
00107 " ab ",
00108 " (ab)' ",
00109 " a<+>b ",
00110 "0s abc ",
00111 " (abc)' ",
00112 "1p a(b+c) ",
00113 " (a(b+c))' ",
00114 "2s a<+>b<+>c ",
00115 "3p a<+>bc ",
00116 "4p a(b<+>c) ",
00117 " (a(b<+>c))' ",
00118 "5s ab+bc+ac ",
00119 "6s abc+a'b'c' ",
00120 " (abc+a'b'c')' ",
00121 "7 ab+bc+a'c ",
00122 "8s a'bc+ab'c+abc' ",
00123 " (a'bc+ab'c+abc')' ",
00124 "9p ab'c'+bc ",
00125 " (ab'c'+bc)' "
00126 };
00127
00128
00129 static int s_NP3VarNums[22] = { 0, 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };
00130
00131
00132 static int s_NPNe3[10] = { 6, 8, 10, 11, 12, 14, 15, 17, 18, 20 };
00133
00134
00135 static int s_NPNe3s[10] = { 6, 10, 14, 15, 18 };
00136
00137
00138 static int s_NPNe3p[10] = { 8, 11, 12, 20 };
00139
00140 static Cut_CMan_t * Cut_CManStart();
00141 static void Cut_CManStop( Cut_CMan_t * p );
00142 static void Cut_CellTruthElem( unsigned * InA, unsigned * InB, unsigned * InC, unsigned * pOut, int nVars, int Type );
00143 static void Cut_CellCanonicize( Cut_CMan_t * p, Cut_Cell_t * pCell );
00144 static int Cut_CellTableLookup( Cut_CMan_t * p, Cut_Cell_t * pCell );
00145 static void Cut_CellSuppMin( Cut_Cell_t * pCell );
00146 static void Cut_CellCrossBar( Cut_Cell_t * pCell );
00147
00148
00149 static Cut_CMan_t * s_pCMan = NULL;
00150
00154
00166 void Cut_CellLoad()
00167 {
00168 FILE * pFile;
00169 char * pFileName = "cells22_daomap_iwls.txt";
00170 char pString[1000];
00171 Cut_CMan_t * p;
00172 Cut_Cell_t * pCell;
00173 int Length;
00174 pFile = fopen( pFileName, "r" );
00175 if ( pFile == NULL )
00176 {
00177 printf( "Cannot open file \"%s\".\n", pFileName );
00178 return;
00179 }
00180
00181 p = Cut_CManStart();
00182
00183 while ( fgets(pString, 1000, pFile) )
00184 {
00185 Length = strlen(pString);
00186 pString[Length--] = 0;
00187 if ( Length == 0 )
00188 continue;
00189
00190 pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
00191 memset( pCell, 0, sizeof(Cut_Cell_t) );
00192 pCell->nVars = Extra_Base2Log(Length*4);
00193 pCell->nUsed = 1;
00194
00195 Extra_ReadHexadecimal( pCell->uTruth, pString, pCell->nVars );
00196 Cut_CellSuppMin( pCell );
00197
00198
00199
00200
00201
00202
00203
00204
00205 p->nTotal++;
00206
00207
00208
00209
00210
00211 if ( !Cut_CellTableLookup( p, pCell ) )
00212 p->nGood++;
00213 }
00214 printf( "Read %d cells from file \"%s\". Added %d cells to the table.\n", p->nTotal, pFileName, p->nGood );
00215 fclose( pFile );
00216
00217 }
00218
00230 void Cut_CellPrecompute()
00231 {
00232 Cut_CMan_t * p;
00233 Cut_Cell_t * pCell, * pTemp;
00234 int i1, i2, i3, i, j, k, c, clk = clock(), clk2 = clock();
00235
00236 p = Cut_CManStart();
00237
00238
00239 for ( i = 0; i < 22; i++ )
00240 Cut_CellTruthElem( p->uInputs[0], p->uInputs[1], p->uInputs[2], p->uTemp1[i], 9, i );
00241 for ( i = 0; i < 22; i++ )
00242 Cut_CellTruthElem( p->uInputs[3], p->uInputs[4], p->uInputs[5], p->uTemp2[i], 9, i );
00243 for ( i = 0; i < 22; i++ )
00244 Cut_CellTruthElem( p->uInputs[6], p->uInputs[7], p->uInputs[8], p->uTemp3[i], 9, i );
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 for ( k = 0; k < 10; k++ )
00339 for ( i1 = 0; i1 < 22; i1++ )
00340 for ( i2 = 0; i2 < 22; i2++ )
00341 for ( i3 = 0; i3 < 22; i3++ )
00342 {
00343
00344 pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
00345 memset( pCell, 0, sizeof(Cut_Cell_t) );
00346 pCell->nVars = 9;
00347 pCell->Box[0] = s_NPNe3[k];
00348 pCell->Box[1] = i1;
00349 pCell->Box[2] = i2;
00350 pCell->Box[3] = i3;
00351
00352 for ( i = 0; i < (int)pCell->nVars; i++ )
00353 pCell->CanonPerm[i] = i;
00354
00355 Cut_CellTruthElem( p->uTemp1[i1], p->uTemp2[i2], p->uTemp3[i3], pCell->uTruth, 9, s_NPNe3[k] );
00356
00357 Cut_CellSuppMin( pCell );
00358
00359
00360 pCell->CanonPhase = Extra_TruthSemiCanonicize( pCell->uTruth, p->puAux, pCell->nVars, pCell->CanonPerm, pCell->Store );
00361
00362
00363 p->nTotal++;
00364 if ( Cut_CellTableLookup( p, pCell ) )
00365 Extra_MmFixedEntryRecycle( p->pMem, (char *)pCell );
00366 else
00367 {
00368 p->nGood++;
00369 p->nVarCounts[pCell->nVars]++;
00370
00371 if ( pCell->nVars )
00372 for ( i = 0; i < (int)pCell->nVars-1; i++ )
00373 {
00374 if ( pCell->Store[2*i] != pCell->Store[2*(i+1)] )
00375 continue;
00376
00377
00378 for ( j = i+1; j < (int)pCell->nVars; j++ )
00379 if ( pCell->Store[2*i] != pCell->Store[2*j] )
00380 break;
00381
00382 if ( pCell->Store[2*i] == pCell->Store[2*i+1] )
00383 p->nSymGroupsE[j-i]++;
00384 else
00385 p->nSymGroups[j-i]++;
00386 i = j - 1;
00387 }
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397 }
00398 }
00399
00400 printf( "BASIC: Total = %d. Good = %d. Entry = %d. ", p->nTotal, p->nGood, sizeof(Cut_Cell_t) );
00401 PRT( "Time", clock() - clk );
00402 printf( "Cells: " );
00403 for ( i = 0; i <= 9; i++ )
00404 printf( "%d=%d ", i, p->nVarCounts[i] );
00405 printf( "\nDiffs: " );
00406 for ( i = 0; i <= 9; i++ )
00407 printf( "%d=%d ", i, p->nSymGroups[i] );
00408 printf( "\nEquals: " );
00409 for ( i = 0; i <= 9; i++ )
00410 printf( "%d=%d ", i, p->nSymGroupsE[i] );
00411 printf( "\n" );
00412
00413
00414 for ( k = CUT_CELL_MVAR; k > 3; k-- )
00415 {
00416 for ( pTemp = p->pSameVar[k]; pTemp; pTemp = pTemp->pNextVar )
00417 for ( i1 = 0; i1 < k; i1++ )
00418 for ( i2 = i1+1; i2 < k; i2++ )
00419 for ( c = 0; c < 3; c++ )
00420 {
00421
00422 pCell = (Cut_Cell_t *)Extra_MmFixedEntryFetch( p->pMem );
00423 memset( pCell, 0, sizeof(Cut_Cell_t) );
00424 pCell->nVars = pTemp->nVars;
00425 pCell->pParent = pTemp;
00426
00427 for ( i = 0; i < (int)pCell->nVars; i++ )
00428 pCell->CanonPerm[i] = i;
00429
00430 Extra_TruthCopy( pCell->uTruth, pTemp->uTruth, pTemp->nVars );
00431
00432 pCell->CrossBar0 = i1;
00433 pCell->CrossBar1 = i2;
00434 pCell->CrossBarPhase = c;
00435 Cut_CellCrossBar( pCell );
00436
00437
00438 Cut_CellSuppMin( pCell );
00439
00440
00441
00442 pCell->CanonPhase = Extra_TruthSemiCanonicize( pCell->uTruth, p->puAux, pCell->nVars, pCell->CanonPerm, pCell->Store );
00443
00444
00445
00446
00447 p->nTotal++;
00448 if ( Cut_CellTableLookup( p, pCell ) )
00449 Extra_MmFixedEntryRecycle( p->pMem, (char *)pCell );
00450 else
00451 {
00452 p->nGood++;
00453 p->nVarCounts[pCell->nVars]++;
00454
00455 for ( i = 0; i < (int)pCell->nVars-1; i++ )
00456 {
00457 if ( pCell->Store[2*i] != pCell->Store[2*(i+1)] )
00458 continue;
00459
00460
00461 for ( j = i+1; j < (int)pCell->nVars; j++ )
00462 if ( pCell->Store[2*i] != pCell->Store[2*j] )
00463 break;
00464
00465 if ( pCell->Store[2*i] == pCell->Store[2*i+1] )
00466 p->nSymGroupsE[j-i]++;
00467 else
00468 p->nSymGroups[j-i]++;
00469 i = j - 1;
00470 }
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480 }
00481
00482 }
00483
00484 printf( "VAR %d: Total = %d. Good = %d. Entry = %d. ", k, p->nTotal, p->nGood, sizeof(Cut_Cell_t) );
00485 PRT( "Time", clock() - clk );
00486 printf( "Cells: " );
00487 for ( i = 0; i <= 9; i++ )
00488 printf( "%d=%d ", i, p->nVarCounts[i] );
00489 printf( "\nDiffs: " );
00490 for ( i = 0; i <= 9; i++ )
00491 printf( "%d=%d ", i, p->nSymGroups[i] );
00492 printf( "\nEquals: " );
00493 for ( i = 0; i <= 9; i++ )
00494 printf( "%d=%d ", i, p->nSymGroupsE[i] );
00495 printf( "\n" );
00496 }
00497
00498 PRT( "Supp ", p->timeSupp );
00499 PRT( "Canon", p->timeCanon );
00500 PRT( "Table", p->timeTable );
00501
00502 }
00503
00515 int Cut_CellTableLookup( Cut_CMan_t * p, Cut_Cell_t * pCell )
00516 {
00517 Cut_Cell_t ** pSlot, * pTemp;
00518 unsigned Hash;
00519 Hash = Extra_TruthHash( pCell->uTruth, Extra_TruthWordNum( pCell->nVars ) );
00520 if ( !st_find_or_add( p->tTable, (char *)Hash, (char ***)&pSlot ) )
00521 *pSlot = NULL;
00522 for ( pTemp = *pSlot; pTemp; pTemp = pTemp->pNext )
00523 {
00524 if ( pTemp->nVars != pCell->nVars )
00525 continue;
00526 if ( Extra_TruthIsEqual(pTemp->uTruth, pCell->uTruth, pCell->nVars) )
00527 return 1;
00528 }
00529
00530 pCell->pNext = *pSlot;
00531 *pSlot = pCell;
00532
00533 pCell->pNextVar = p->pSameVar[pCell->nVars];
00534 p->pSameVar[pCell->nVars] = pCell;
00535 return 0;
00536 }
00537
00549 void Cut_CellSuppMin( Cut_Cell_t * pCell )
00550 {
00551 static unsigned uTemp[1<<(CUT_CELL_MVAR-5)];
00552 unsigned * pIn, * pOut, * pTemp;
00553 int i, k, Counter, Temp;
00554
00555
00556 for ( k = pCell->nVars - 1; k >= 0; k-- )
00557 if ( !Extra_TruthVarInSupport(pCell->uTruth, pCell->nVars, k) )
00558 {
00559
00560 Counter = 0;
00561 pIn = pCell->uTruth; pOut = uTemp;
00562 for ( i = k; i < (int)pCell->nVars - 1; i++ )
00563 {
00564 Extra_TruthSwapAdjacentVars( pOut, pIn, pCell->nVars, i );
00565 pTemp = pIn; pIn = pOut; pOut = pTemp;
00566
00567 Temp = pCell->CanonPerm[i];
00568 pCell->CanonPerm[i] = pCell->CanonPerm[i+1];
00569 pCell->CanonPerm[i+1] = Temp;
00570 Counter++;
00571 }
00572
00573 if ( Counter & 1 )
00574 Extra_TruthCopy( pOut, pIn, pCell->nVars );
00575
00576 pCell->nVars--;
00577
00578 }
00579 }
00580
00592 void Cut_CellCrossBar( Cut_Cell_t * pCell )
00593 {
00594 static unsigned uTemp0[1<<(CUT_CELL_MVAR-5)];
00595 static unsigned uTemp1[1<<(CUT_CELL_MVAR-5)];
00596 Extra_TruthCopy( uTemp0, pCell->uTruth, pCell->nVars );
00597 Extra_TruthCopy( uTemp1, pCell->uTruth, pCell->nVars );
00598 if ( pCell->CanonPhase == 0 )
00599 {
00600 Extra_TruthCofactor0( uTemp0, pCell->nVars, pCell->CrossBar0 );
00601 Extra_TruthCofactor0( uTemp0, pCell->nVars, pCell->CrossBar1 );
00602 Extra_TruthCofactor1( uTemp1, pCell->nVars, pCell->CrossBar0 );
00603 Extra_TruthCofactor1( uTemp1, pCell->nVars, pCell->CrossBar1 );
00604 }
00605 else if ( pCell->CanonPhase == 1 )
00606 {
00607 Extra_TruthCofactor1( uTemp0, pCell->nVars, pCell->CrossBar0 );
00608 Extra_TruthCofactor0( uTemp0, pCell->nVars, pCell->CrossBar1 );
00609 Extra_TruthCofactor0( uTemp1, pCell->nVars, pCell->CrossBar0 );
00610 Extra_TruthCofactor1( uTemp1, pCell->nVars, pCell->CrossBar1 );
00611 }
00612 else if ( pCell->CanonPhase == 2 )
00613 {
00614 Extra_TruthCofactor0( uTemp0, pCell->nVars, pCell->CrossBar0 );
00615 Extra_TruthCofactor1( uTemp0, pCell->nVars, pCell->CrossBar1 );
00616 Extra_TruthCofactor1( uTemp1, pCell->nVars, pCell->CrossBar0 );
00617 Extra_TruthCofactor0( uTemp1, pCell->nVars, pCell->CrossBar1 );
00618 }
00619 else assert( 0 );
00620 Extra_TruthMux( pCell->uTruth, uTemp0, uTemp1, pCell->nVars, pCell->CrossBar0 );
00621 }
00622
00634 void Cut_CellTruthElem( unsigned * InA, unsigned * InB, unsigned * InC, unsigned * pOut, int nVars, int Type )
00635 {
00636 int nWords = Extra_TruthWordNum( nVars );
00637 int i;
00638
00639 assert( Type < 22 );
00640 switch ( Type )
00641 {
00642
00643 case 0:
00644 for ( i = 0; i < nWords; i++ )
00645 pOut[i] = 0;
00646 return;
00647
00648 case 1:
00649 for ( i = 0; i < nWords; i++ )
00650 pOut[i] = 0xFFFFFFFF;
00651 return;
00652
00653 case 2:
00654 for ( i = 0; i < nWords; i++ )
00655 pOut[i] = InA[i];
00656 return;
00657
00658 case 3:
00659 for ( i = 0; i < nWords; i++ )
00660 pOut[i] = InA[i] & InB[i];
00661 return;
00662
00663 case 4:
00664 for ( i = 0; i < nWords; i++ )
00665 pOut[i] = ~(InA[i] & InB[i]);
00666 return;
00667
00668 case 5:
00669 for ( i = 0; i < nWords; i++ )
00670 pOut[i] = InA[i] ^ InB[i];
00671 return;
00672
00673 case 6:
00674 for ( i = 0; i < nWords; i++ )
00675 pOut[i] = InA[i] & InB[i] & InC[i];
00676 return;
00677
00678 case 7:
00679 for ( i = 0; i < nWords; i++ )
00680 pOut[i] = ~(InA[i] & InB[i] & InC[i]);
00681 return;
00682
00683 case 8:
00684 for ( i = 0; i < nWords; i++ )
00685 pOut[i] = InA[i] & (InB[i] | InC[i]);
00686 return;
00687
00688 case 9:
00689 for ( i = 0; i < nWords; i++ )
00690 pOut[i] = ~(InA[i] & (InB[i] | InC[i]));
00691 return;
00692
00693 case 10:
00694 for ( i = 0; i < nWords; i++ )
00695 pOut[i] = InA[i] ^ InB[i] ^ InC[i];
00696 return;
00697
00698 case 11:
00699 for ( i = 0; i < nWords; i++ )
00700 pOut[i] = InA[i] ^ (InB[i] & InC[i]);
00701 return;
00702
00703 case 12:
00704 for ( i = 0; i < nWords; i++ )
00705 pOut[i] = InA[i] & (InB[i] ^ InC[i]);
00706 return;
00707
00708 case 13:
00709 for ( i = 0; i < nWords; i++ )
00710 pOut[i] = ~(InA[i] & (InB[i] ^ InC[i]));
00711 return;
00712
00713 case 14:
00714 for ( i = 0; i < nWords; i++ )
00715 pOut[i] = (InA[i] & InB[i]) | (InB[i] & InC[i]) | (InA[i] & InC[i]);
00716 return;
00717
00718 case 15:
00719 for ( i = 0; i < nWords; i++ )
00720 pOut[i] = (InA[i] & InB[i] & InC[i]) | (~InA[i] & ~InB[i] & ~InC[i]);
00721 return;
00722
00723 case 16:
00724 for ( i = 0; i < nWords; i++ )
00725 pOut[i] = ~((InA[i] & InB[i] & InC[i]) | (~InA[i] & ~InB[i] & ~InC[i]));
00726 return;
00727
00728 case 17:
00729 for ( i = 0; i < nWords; i++ )
00730 pOut[i] = (InA[i] & InB[i]) | (InB[i] & InC[i]) | (~InA[i] & InC[i]);
00731 return;
00732
00733 case 18:
00734 for ( i = 0; i < nWords; i++ )
00735 pOut[i] = (~InA[i] & InB[i] & InC[i]) | (InA[i] & ~InB[i] & InC[i]) | (InA[i] & InB[i] & ~InC[i]);
00736 return;
00737
00738 case 19:
00739 for ( i = 0; i < nWords; i++ )
00740 pOut[i] = ~((~InA[i] & InB[i] & InC[i]) | (InA[i] & ~InB[i] & InC[i]) | (InA[i] & InB[i] & ~InC[i]));
00741 return;
00742
00743 case 20:
00744 for ( i = 0; i < nWords; i++ )
00745 pOut[i] = (InA[i] & ~InB[i] & ~InC[i]) | (InB[i] & InC[i]);
00746 return;
00747
00748 case 21:
00749 for ( i = 0; i < nWords; i++ )
00750 pOut[i] = ~((InA[i] & ~InB[i] & ~InC[i]) | (InB[i] & InC[i]));
00751 return;
00752 }
00753 }
00754
00755
00767 Cut_CMan_t * Cut_CManStart()
00768 {
00769 Cut_CMan_t * p;
00770 int i, k;
00771
00772 assert( sizeof(unsigned) == 4 );
00773 p = ALLOC( Cut_CMan_t, 1 );
00774 memset( p, 0, sizeof(Cut_CMan_t) );
00775
00776 p->tTable = st_init_table(st_ptrcmp,st_ptrhash);
00777 p->pMem = Extra_MmFixedStart( sizeof(Cut_Cell_t) );
00778
00779 for ( k = 0; k < CUT_CELL_MVAR; k++ )
00780 for ( i = 0; i < (1<<CUT_CELL_MVAR); i++ )
00781 if ( i & (1 << k) )
00782 p->uInputs[k][i>>5] |= (1 << (i&31));
00783 s_pCMan = p;
00784 return p;
00785 }
00786
00798 void Cut_CManStop( Cut_CMan_t * p )
00799 {
00800 st_free_table( p->tTable );
00801 Extra_MmFixedStop( p->pMem );
00802 free( p );
00803 }
00815 int Cut_CellIsRunning()
00816 {
00817 return s_pCMan != NULL;
00818 }
00819
00831 void Cut_CellDumpToFile()
00832 {
00833 FILE * pFile;
00834 Cut_CMan_t * p = s_pCMan;
00835 Cut_Cell_t * pTemp;
00836 char * pFileName = "celllib22.txt";
00837 int NumUsed[10][5] = {{0}};
00838 int BoxUsed[22][5] = {{0}};
00839 int i, k, Counter;
00840 int clk = clock();
00841
00842 if ( p == NULL )
00843 {
00844 printf( "Cut_CellDumpToFile: Cell manager is not defined.\n" );
00845 return;
00846 }
00847
00848
00849 for ( k = CUT_CELL_MVAR; k >= 0; k-- )
00850 {
00851 for ( pTemp = p->pSameVar[k]; pTemp; pTemp = pTemp->pNextVar )
00852 {
00853 if ( pTemp->nUsed == 0 )
00854 NumUsed[k][0]++;
00855 else if ( pTemp->nUsed < 10 )
00856 NumUsed[k][1]++;
00857 else if ( pTemp->nUsed < 100 )
00858 NumUsed[k][2]++;
00859 else if ( pTemp->nUsed < 1000 )
00860 NumUsed[k][3]++;
00861 else
00862 NumUsed[k][4]++;
00863
00864 for ( i = 0; i < 4; i++ )
00865 if ( pTemp->nUsed == 0 )
00866 BoxUsed[ pTemp->Box[i] ][0]++;
00867 else if ( pTemp->nUsed < 10 )
00868 BoxUsed[ pTemp->Box[i] ][1]++;
00869 else if ( pTemp->nUsed < 100 )
00870 BoxUsed[ pTemp->Box[i] ][2]++;
00871 else if ( pTemp->nUsed < 1000 )
00872 BoxUsed[ pTemp->Box[i] ][3]++;
00873 else
00874 BoxUsed[ pTemp->Box[i] ][4]++;
00875 }
00876 }
00877
00878 printf( "Functions found = %10d. Functions not found = %10d.\n", p->nCellFound, p->nCellNotFound );
00879 for ( k = 0; k <= CUT_CELL_MVAR; k++ )
00880 {
00881 printf( "%3d : ", k );
00882 for ( i = 0; i < 5; i++ )
00883 printf( "%8d ", NumUsed[k][i] );
00884 printf( "\n" );
00885 }
00886 printf( "Box usage:\n" );
00887 for ( k = 0; k < 22; k++ )
00888 {
00889 printf( "%3d : ", k );
00890 for ( i = 0; i < 5; i++ )
00891 printf( "%8d ", BoxUsed[k][i] );
00892 printf( " %s", s_NP3Names[k] );
00893 printf( "\n" );
00894 }
00895
00896 pFile = fopen( pFileName, "w" );
00897 if ( pFile == NULL )
00898 {
00899 printf( "Cut_CellDumpToFile: Cannout open output file.\n" );
00900 return;
00901 }
00902
00903 Counter = 0;
00904 for ( k = 0; k <= CUT_CELL_MVAR; k++ )
00905 {
00906 for ( pTemp = p->pSameVar[k]; pTemp; pTemp = pTemp->pNextVar )
00907 if ( pTemp->nUsed > 0 )
00908 {
00909 Extra_PrintHexadecimal( pFile, pTemp->uTruth, (k <= 5? 5 : k) );
00910 fprintf( pFile, "\n" );
00911 Counter++;
00912 }
00913 fprintf( pFile, "\n" );
00914 }
00915 fclose( pFile );
00916
00917 printf( "Library composed of %d functions is written into file \"%s\". ", Counter, pFileName );
00918
00919 PRT( "Time", clock() - clk );
00920 }
00921
00922
00936 int Cut_CellTruthLookup( unsigned * pTruth, int nVars )
00937 {
00938 Cut_CMan_t * p = s_pCMan;
00939 Cut_Cell_t * pTemp;
00940 Cut_Cell_t Cell, * pCell = &Cell;
00941 unsigned Hash;
00942 int i;
00943
00944
00945 if ( p == NULL )
00946 {
00947 printf( "Cut_CellTruthLookup: Cell manager is not defined.\n" );
00948 return 0;
00949 }
00950
00951
00952 memset( pCell, 0, sizeof(Cut_Cell_t) );
00953 pCell->nVars = nVars;
00954 Extra_TruthCopy( pCell->uTruth, pTruth, nVars );
00955 Cut_CellSuppMin( pCell );
00956
00957 for ( i = 0; i < (int)pCell->nVars; i++ )
00958 pCell->CanonPerm[i] = i;
00959
00960 pCell->CanonPhase = Extra_TruthSemiCanonicize( pCell->uTruth, p->puAux, pCell->nVars, pCell->CanonPerm, pCell->Store );
00961
00962
00963
00964 Hash = Extra_TruthHash( pCell->uTruth, Extra_TruthWordNum(pCell->nVars) );
00965 if ( st_lookup( p->tTable, (char *)Hash, (char **)&pTemp ) )
00966 {
00967 for ( ; pTemp; pTemp = pTemp->pNext )
00968 {
00969 if ( pTemp->nVars != pCell->nVars )
00970 continue;
00971 if ( Extra_TruthIsEqual(pTemp->uTruth, pCell->uTruth, pCell->nVars) )
00972 {
00973 pTemp->nUsed++;
00974 p->nCellFound++;
00975 return 1;
00976 }
00977 }
00978 }
00979 p->nCellNotFound++;
00980 return 0;
00981 }
00982
00983
00987
00988