30#define CUT_CELL_MVAR 9
106static char * s_NP3Names[22] = {
125 "8s a'bc+ab'c+abc' ",
126 " (a'bc+ab'c+abc')' ",
135static int s_NPNe3[10] = { 6, 8, 10, 11, 12, 14, 15, 17, 18, 20 };
145static void Cut_CellTruthElem(
unsigned * InA,
unsigned * InB,
unsigned * InC,
unsigned * pOut,
int nVars,
int Type );
148static void Cut_CellSuppMin(
Cut_Cell_t * pCell );
149static void Cut_CellCrossBar(
Cut_Cell_t * pCell );
172 char * pFileName =
"cells22_daomap_iwls.txt";
177 pFile = fopen( pFileName,
"r" );
180 printf(
"Cannot open file \"%s\".\n", pFileName );
186 while ( fgets(pString, 1000, pFile) )
189 pString[Length--] = 0;
195 pCell->
nVars = Abc_Base2Log(Length*4);
199 Cut_CellSuppMin( pCell );
214 if ( !Cut_CellTableLookup(
p, pCell ) )
217 printf(
"Read %d cells from file \"%s\". Added %d cells to the table.\n",
p->nTotal, pFileName,
p->nGood );
237 int i1, i2, i3, i, j, k, c;
243 for ( i = 0; i < 22; i++ )
244 Cut_CellTruthElem(
p->uInputs[0],
p->uInputs[1],
p->uInputs[2],
p->uTemp1[i], 9, i );
245 for ( i = 0; i < 22; i++ )
246 Cut_CellTruthElem(
p->uInputs[3],
p->uInputs[4],
p->uInputs[5],
p->uTemp2[i], 9, i );
247 for ( i = 0; i < 22; i++ )
248 Cut_CellTruthElem(
p->uInputs[6],
p->uInputs[7],
p->uInputs[8],
p->uTemp3[i], 9, i );
342 for ( k = 0; k < 10; k++ )
343 for ( i1 = 0; i1 < 22; i1++ )
344 for ( i2 = 0; i2 < 22; i2++ )
345 for ( i3 = 0; i3 < 22; i3++ )
351 pCell->
Box[0] = s_NPNe3[k];
356 for ( i = 0; i < (int)pCell->
nVars; i++ )
359 Cut_CellTruthElem(
p->uTemp1[i1],
p->uTemp2[i2],
p->uTemp3[i3], pCell->
uTruth, 9, s_NPNe3[k] );
361 Cut_CellSuppMin( pCell );
368 if ( Cut_CellTableLookup(
p, pCell ) )
373 p->nVarCounts[pCell->nVars]++;
376 for ( i = 0; i < (int)pCell->nVars-1; i++ )
378 if ( pCell->Store[2*i] != pCell->Store[2*(i+1)] )
382 for ( j = i+1; j < (int)pCell->nVars; j++ )
383 if ( pCell->Store[2*i] != pCell->Store[2*j] )
386 if ( pCell->Store[2*i] == pCell->Store[2*i+1] )
387 p->nSymGroupsE[j-i]++;
389 p->nSymGroups[j-i]++;
404 printf(
"BASIC: Total = %d. Good = %d. Entry = %d. ", (
int)
p->nTotal, (
int)
p->nGood, (
int)
sizeof(
Cut_Cell_t) );
405 ABC_PRT(
"Time", Abc_Clock() - clk );
407 for ( i = 0; i <= 9; i++ )
408 printf(
"%d=%d ", i,
p->nVarCounts[i] );
409 printf(
"\nDiffs: " );
410 for ( i = 0; i <= 9; i++ )
411 printf(
"%d=%d ", i,
p->nSymGroups[i] );
412 printf(
"\nEquals: " );
413 for ( i = 0; i <= 9; i++ )
414 printf(
"%d=%d ", i,
p->nSymGroupsE[i] );
420 for ( pTemp =
p->pSameVar[k]; pTemp; pTemp = pTemp->
pNextVar )
421 for ( i1 = 0; i1 < k; i1++ )
422 for ( i2 = i1+1; i2 < k; i2++ )
423 for ( c = 0; c < 3; c++ )
431 for ( i = 0; i < (int)pCell->
nVars; i++ )
439 Cut_CellCrossBar( pCell );
442 Cut_CellSuppMin( pCell );
452 if ( Cut_CellTableLookup(
p, pCell ) )
457 p->nVarCounts[pCell->nVars]++;
459 for ( i = 0; i < (int)pCell->nVars-1; i++ )
461 if ( pCell->Store[2*i] != pCell->Store[2*(i+1)] )
465 for ( j = i+1; j < (int)pCell->nVars; j++ )
466 if ( pCell->Store[2*i] != pCell->Store[2*j] )
469 if ( pCell->Store[2*i] == pCell->Store[2*i+1] )
470 p->nSymGroupsE[j-i]++;
472 p->nSymGroups[j-i]++;
488 printf(
"VAR %d: Total = %d. Good = %d. Entry = %d. ", k,
p->nTotal,
p->nGood, (
int)
sizeof(
Cut_Cell_t) );
489 ABC_PRT(
"Time", Abc_Clock() - clk );
491 for ( i = 0; i <= 9; i++ )
492 printf(
"%d=%d ", i,
p->nVarCounts[i] );
493 printf(
"\nDiffs: " );
494 for ( i = 0; i <= 9; i++ )
495 printf(
"%d=%d ", i,
p->nSymGroups[i] );
496 printf(
"\nEquals: " );
497 for ( i = 0; i <= 9; i++ )
498 printf(
"%d=%d ", i,
p->nSymGroupsE[i] );
524 if ( !
st__find_or_add(
p->tTable, (
char *)(ABC_PTRUINT_T)Hash, (
char ***)&pSlot ) )
526 for ( pTemp = *pSlot; pTemp; pTemp = pTemp->
pNext )
534 pCell->
pNext = *pSlot;
538 p->pSameVar[pCell->
nVars] = pCell;
556 unsigned * pIn, * pOut, * pTemp;
557 int i, k, Counter, Temp;
560 for ( k = pCell->
nVars - 1; k >= 0; k-- )
565 pIn = pCell->
uTruth; pOut = uTemp;
566 for ( i = k; i < (int)pCell->
nVars - 1; i++ )
569 pTemp = pIn; pIn = pOut; pOut = pTemp;
578 Extra_TruthCopy( pOut, pIn, pCell->
nVars );
600 Extra_TruthCopy( uTemp0, pCell->
uTruth, pCell->
nVars );
601 Extra_TruthCopy( uTemp1, pCell->
uTruth, pCell->
nVars );
638void Cut_CellTruthElem(
unsigned * InA,
unsigned * InB,
unsigned * InC,
unsigned * pOut,
int nVars,
int Type )
640 int nWords = Extra_TruthWordNum( nVars );
648 for ( i = 0; i <
nWords; i++ )
653 for ( i = 0; i <
nWords; i++ )
654 pOut[i] = 0xFFFFFFFF;
658 for ( i = 0; i <
nWords; i++ )
663 for ( i = 0; i <
nWords; i++ )
664 pOut[i] = InA[i] & InB[i];
668 for ( i = 0; i <
nWords; i++ )
669 pOut[i] = ~(InA[i] & InB[i]);
673 for ( i = 0; i <
nWords; i++ )
674 pOut[i] = InA[i] ^ InB[i];
678 for ( i = 0; i <
nWords; i++ )
679 pOut[i] = InA[i] & InB[i] & InC[i];
683 for ( i = 0; i <
nWords; i++ )
684 pOut[i] = ~(InA[i] & InB[i] & InC[i]);
688 for ( i = 0; i <
nWords; i++ )
689 pOut[i] = InA[i] & (InB[i] | InC[i]);
693 for ( i = 0; i <
nWords; i++ )
694 pOut[i] = ~(InA[i] & (InB[i] | InC[i]));
698 for ( i = 0; i <
nWords; i++ )
699 pOut[i] = InA[i] ^ InB[i] ^ InC[i];
703 for ( i = 0; i <
nWords; i++ )
704 pOut[i] = InA[i] ^ (InB[i] & InC[i]);
708 for ( i = 0; i <
nWords; i++ )
709 pOut[i] = InA[i] & (InB[i] ^ InC[i]);
713 for ( i = 0; i <
nWords; i++ )
714 pOut[i] = ~(InA[i] & (InB[i] ^ InC[i]));
718 for ( i = 0; i <
nWords; i++ )
719 pOut[i] = (InA[i] & InB[i]) | (InB[i] & InC[i]) | (InA[i] & InC[i]);
723 for ( i = 0; i <
nWords; i++ )
724 pOut[i] = (InA[i] & InB[i] & InC[i]) | (~InA[i] & ~InB[i] & ~InC[i]);
728 for ( i = 0; i <
nWords; i++ )
729 pOut[i] = ~((InA[i] & InB[i] & InC[i]) | (~InA[i] & ~InB[i] & ~InC[i]));
733 for ( i = 0; i <
nWords; i++ )
734 pOut[i] = (InA[i] & InB[i]) | (InB[i] & InC[i]) | (~InA[i] & InC[i]);
738 for ( i = 0; i <
nWords; i++ )
739 pOut[i] = (~InA[i] & InB[i] & InC[i]) | (InA[i] & ~InB[i] & InC[i]) | (InA[i] & InB[i] & ~InC[i]);
743 for ( i = 0; i <
nWords; i++ )
744 pOut[i] = ~((~InA[i] & InB[i] & InC[i]) | (InA[i] & ~InB[i] & InC[i]) | (InA[i] & InB[i] & ~InC[i]));
748 for ( i = 0; i <
nWords; i++ )
749 pOut[i] = (InA[i] & ~InB[i] & ~InC[i]) | (InB[i] & InC[i]);
753 for ( i = 0; i <
nWords; i++ )
754 pOut[i] = ~((InA[i] & ~InB[i] & ~InC[i]) | (InB[i] & InC[i]));
776 assert(
sizeof(
unsigned) == 4 );
786 p->uInputs[k][i>>5] |= (1 << (i&31));
821 return s_pCMan != NULL;
840 char * pFileName =
"celllib22.txt";
841 int NumUsed[10][5] = {{0}};
842 int BoxUsed[22][5] = {{0}};
848 printf(
"Cut_CellDumpToFile: Cell manager is not defined.\n" );
855 for ( pTemp =
p->pSameVar[k]; pTemp; pTemp = pTemp->
pNextVar )
857 if ( pTemp->
nUsed == 0 )
859 else if ( pTemp->
nUsed < 10 )
861 else if ( pTemp->
nUsed < 100 )
863 else if ( pTemp->
nUsed < 1000 )
868 for ( i = 0; i < 4; i++ )
869 if ( pTemp->
nUsed == 0 )
870 BoxUsed[ (int)pTemp->
Box[i] ][0]++;
871 else if ( pTemp->
nUsed < 10 )
872 BoxUsed[ (int)pTemp->
Box[i] ][1]++;
873 else if ( pTemp->
nUsed < 100 )
874 BoxUsed[ (int)pTemp->
Box[i] ][2]++;
875 else if ( pTemp->
nUsed < 1000 )
876 BoxUsed[ (int)pTemp->
Box[i] ][3]++;
878 BoxUsed[ (int)pTemp->
Box[i] ][4]++;
882 printf(
"Functions found = %10d. Functions not found = %10d.\n",
p->nCellFound,
p->nCellNotFound );
885 printf(
"%3d : ", k );
886 for ( i = 0; i < 5; i++ )
887 printf(
"%8d ", NumUsed[k][i] );
890 printf(
"Box usage:\n" );
891 for ( k = 0; k < 22; k++ )
893 printf(
"%3d : ", k );
894 for ( i = 0; i < 5; i++ )
895 printf(
"%8d ", BoxUsed[k][i] );
896 printf(
" %s", s_NP3Names[k] );
900 pFile = fopen( pFileName,
"w" );
903 printf(
"Cut_CellDumpToFile: Cannout open output file.\n" );
910 for ( pTemp =
p->pSameVar[k]; pTemp; pTemp = pTemp->
pNextVar )
911 if ( pTemp->
nUsed > 0 )
914 fprintf( pFile,
"\n" );
917 fprintf( pFile,
"\n" );
921 printf(
"Library composed of %d functions is written into file \"%s\". ", Counter, pFileName );
923 ABC_PRT(
"Time", Abc_Clock() - clk );
951 printf(
"Cut_CellTruthLookup: Cell manager is not defined.\n" );
957 pCell->
nVars = nVars;
958 Extra_TruthCopy( pCell->
uTruth, pTruth, nVars );
959 Cut_CellSuppMin( pCell );
961 for ( i = 0; i < (int)pCell->
nVars; i++ )
969 if (
st__lookup(
p->tTable, (
char *)(ABC_PTRUINT_T)Hash, (
char **)&pTemp ) )
971 for ( ; pTemp; pTemp = pTemp->
pNext )
#define ABC_ALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define CUT_CELL_MVAR
DECLARATIONS ///.
void Cut_CellPrecompute()
int Cut_CellTruthLookup(unsigned *pTruth, int nVars)
void Cut_CellLoad()
FUNCTION DEFINITIONS ///.
#define CUT_CELL_MVAR
DECLARATIONS ///.
void Cut_CellDumpToFile()
struct Cut_Cell_t_ Cut_Cell_t
struct Cut_CMan_t_ Cut_CMan_t
int st__ptrhash(const char *, int)
int st__find_or_add(st__table *table, char *key, char ***slot)
int st__ptrcmp(const char *, const char *)
int st__lookup(st__table *table, const char *key, char **value)
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
void st__free_table(st__table *table)
unsigned uTemp3[22][1<<(CUT_CELL_MVAR-5)]
int nSymGroups[CUT_CELL_MVAR+1]
Cut_Cell_t * pSameVar[CUT_CELL_MVAR+1]
unsigned puAux[1<<(CUT_CELL_MVAR-5)]
unsigned uTemp2[22][1<<(CUT_CELL_MVAR-5)]
unsigned uFinal[1<<(CUT_CELL_MVAR-5)]
int nVarCounts[CUT_CELL_MVAR+1]
unsigned uInputs[CUT_CELL_MVAR][1<<(CUT_CELL_MVAR-5)]
unsigned uTemp1[22][1<<(CUT_CELL_MVAR-5)]
int nSymGroupsE[CUT_CELL_MVAR+1]
short Store[2 *CUT_CELL_MVAR]
unsigned uTruth[1<<(CUT_CELL_MVAR-5)]
char CanonPerm[CUT_CELL_MVAR+3]