31 #define CLU_VAR_MAX 16
32 #define CLU_WRD_MAX (1 << ((CLU_VAR_MAX)-6))
33 #define CLU_MEM_MAX 1000 // 1 GB
34 #define CLU_UNUSED 0xff
88 char * pChar = (
char *)pG;
91 for ( i = 0; i < 8; i++ )
92 Res |= ((pChar[i] & 15) << (i << 2));
98 char * pChar = (
char *)pG;
100 for ( i = 0; i < 8; i++ )
101 pChar[i] = ((Group >> (i << 2)) & 15);
114 while ((
unsigned) (i * i) <= p) {
132 return nVars <= 6 ? 1 : 1 << (nVars-6);
141 return (t &
ABC_CONST(0x00000000FFFFFFFF)) + (t>>32);
148 int i, RetValue, Status;
153 Status = ((pEntry->
Group & 15) > 0);
155 if ( RetValue != Status )
159 printf(
"Hash table problem!!!\n" );
177 printf(
"%d=%d ", i, Counter );
184 int i, Max = 0, Total = 0, Half = 0;
190 if ( Max < (
int)pEntry->
Counter )
199 for ( i = Max; i > 0; i-- )
202 if ( Half > Total/2 )
216 static unsigned BigPrimes[8] = {12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741};
221 unsigned char * s = (
unsigned char *)pTruth;
222 for ( i = 0; i < 8 *
nWords; i++ )
223 Value ^= BigPrimes[i % 7] * s[i];
227 unsigned * s = (
unsigned *)pTruth;
228 for ( i = 0; i < 2 *
nWords; i++ )
229 Value ^= BigPrimes[i % 7] * s[i];
258 return &pEntry->
Group;
271 if ( (
int)pEntry->Counter > Median )
274 pEntry = pEntry->pNext;
278 pPrev = pEntry->
pNext;
292 pEntry->
pNext = pPrev;
298 pPrev = pPrev->
pNext;
300 pPrev->
pNext = pEntry;
316 pEntry->
pNext = NULL;
321 pPrev->
pNext = pEntry;
322 return &pEntry->
Group;
329 for ( w = 0; w <
nWords; w++ )
335 for ( w = 0; w <
nWords; w++ )
341 for ( w = 0; w <
nWords; w++ )
347 for ( w = 0; w <
nWords; w++ )
348 if ( pOut[w] != pIn[w] )
355 for ( w = 0; w <
nWords; w++ )
356 pRes[w] = pIn1[w] & pIn2[w];
361 for ( w = 0; w <
nWords; w++ )
362 pRes[w] = pIn1[w] & ~pIn2[w];
367 for ( w = 0; w <
nWords; w++ )
368 pRes[w] = pIn1[w] | pIn2[w];
372 assert( nVars >= 0 && nVars <= 6 );
375 t &= (((
word)1) << (1 << nVars)) - 1;
377 t |= t << (1<<nVars++);
379 t |= t << (1<<nVars++);
381 t |= t << (1<<nVars++);
383 t |= t << (1<<nVars++);
385 t |= t << (1<<nVars++);
387 t |= t << (1<<nVars++);
393 if ( nVarsCur == nVarsMax )
395 assert( nVarsCur < nVarsMax );
396 for ( v =
Abc_MaxInt( nVarsCur, 6 ); v < nVarsMax; v++ )
405 assert( iVar < nVars - 1 );
408 int Shift = (1 << iVar);
409 for ( i = 0; i <
nWords; i++ )
410 pOut[i] = (pIn[i] &
PMasks[iVar][0]) | ((pIn[i] &
PMasks[iVar][1]) << Shift) | ((pIn[i] &
PMasks[iVar][2]) >> Shift);
414 int Step = (1 << (iVar - 6));
415 for ( k = 0; k <
nWords; k += 4*Step )
417 for ( i = 0; i < Step; i++ )
419 for ( i = 0; i < Step; i++ )
420 pOut[Step+i] = pIn[2*Step+i];
421 for ( i = 0; i < Step; i++ )
422 pOut[2*Step+i] = pIn[Step+i];
423 for ( i = 0; i < Step; i++ )
424 pOut[3*Step+i] = pIn[3*Step+i];
431 for ( i = 0; i <
nWords; i += 2 )
433 pOut[i] = (pIn[i] &
ABC_CONST(0x00000000FFFFFFFF)) | ((pIn[i+1] &
ABC_CONST(0x00000000FFFFFFFF)) << 32);
434 pOut[i+1] = (pIn[i+1] &
ABC_CONST(0xFFFFFFFF00000000)) | ((pIn[i] &
ABC_CONST(0xFFFFFFFF00000000)) >> 32);
445 int i, Shift = (1 << iVar);
446 for ( i = 0; i <
nWords; i++ )
447 pF[i] = ((pF[i] & ~
Truth6[iVar]) << Shift) | ((pF[i] &
Truth6[iVar]) >> Shift);
452 int i, k, Step = (1 << (iVar - 6));
453 for ( k = 0; k <
nWords; k += 2*Step )
455 for ( i = 0; i < Step; i++ )
468 int i, k, nOnes = 0, Limit =
Abc_MinInt( nVars, 6 );
469 memset( pStore, 0,
sizeof(
int) * 2 * nVars );
471 for ( k = 0; k <
nWords; k++ )
472 for ( i = 0; i < Limit; i++ )
475 for ( k = 0; k <
nWords; k++ )
476 for ( i = 6; i < nVars; i++ )
477 if ( k & (1 << (i-6)) )
480 for ( k = 0; k <
nWords; k++ )
482 for ( i = 0; i < nVars; i++ )
483 pStore[2*i] = nOnes - pStore[2*i+1];
489 unsigned uCanonPhase = 0;
490 int i, Temp, fChange,
Counter = 0;
496 for ( i = 0; i < nVars; i++ )
498 if ( pStore[2*i+0] <= pStore[2*i+1] )
500 uCanonPhase |= (1 << i);
501 Temp = pStore[2*i+0];
502 pStore[2*i+0] = pStore[2*i+1];
503 pStore[2*i+1] = Temp;
507 for ( i = 0; i < nVars; i++ )
511 for ( i = 0; i < nVars-1; i++ )
513 if ( pStore[2*i] <= pStore[2*(i+1)] )
518 Temp = pCanonPerm[i];
519 pCanonPerm[i] = pCanonPerm[i+1];
520 pCanonPerm[i+1] = Temp;
523 pStore[2*i] = pStore[2*(i+1)];
524 pStore[2*(i+1)] = Temp;
526 Temp = pStore[2*i+1];
527 pStore[2*i+1] = pStore[2*(i+1)+1];
528 pStore[2*(i+1)+1] = Temp;
531 pTemp = pIn; pIn = pOut; pOut = pTemp;
542 int i, Temp, fChange,
Counter = 0;
547 for ( i = 0; i < nVars-1; i++ )
549 if ( pCanonPerm[i] < pCanonPerm[i+1] )
555 Temp = pCanonPerm[i];
556 pCanonPerm[i] = pCanonPerm[i+1];
557 pCanonPerm[i+1] = Temp;
560 pTemp = pIn; pIn = pOut; pOut = pTemp;
566 for ( i = 0; i < nVars; i++ )
567 if ( (uCanonPhase >> i) & 1 )
575 printf(
"SemiCanonical verification FAILED!\n" );
583 printf(
"Vars = %d ", g->
nVars );
584 printf(
"Myu = %d {", g->
nMyu );
585 for ( i = 0; i < g->
nVars; i++ )
586 printf(
" %c",
'a' + g->
pVars[i] );
610 for ( i = 0; i < 6; i++ )
628 for ( m = 0; m < (1<<g->
nVars); m++ )
630 if ( !((t[m >> 6] >> (m & 63)) & 1) )
633 for ( v = 0; v < g->
nVars; v++ )
650 for ( i = 0; i < g->
nVars; i++ )
654 for ( i = 0; i < r->
nVars; i++ )
655 if ( r->
pVars[i] == nVars )
668 printf(
"Verification FAILED!\n" );
683 for ( i = 0; i < g->
nVars; i++ )
687 for ( i = 0; i < g2->
nVars; i++ )
691 for ( i = 0; i < r->
nVars; i++ )
692 if ( r->
pVars[i] == nVars )
694 else if ( r->
pVars[i] == nVars + 1 )
702 printf(
"%d\n", nVars );
715 printf(
"Verification FAILED!\n" );
725 word low2High, high2Low, temp;
727 int shift, step, iStep, jStep;
728 int w = 0, i = 0, j = 0;
729 static word PPMasks[6][6] = {
745 if ( iVar <= 5 && jVar <= 5 )
747 shift = (1 << jVar) - (1 << iVar);
748 for ( w = 0; w <
nWords; w++ )
750 low2High = (pTruth[w] & PPMasks[iVar][jVar - 1] ) << shift;
751 pTruth[w] &= ~PPMasks[iVar][jVar - 1];
752 high2Low = (pTruth[w] & (PPMasks[iVar][jVar - 1] << shift )) >> shift;
753 pTruth[w] &= ~ (PPMasks[iVar][jVar - 1] << shift);
754 pTruth[w] = pTruth[w] | low2High | high2Low;
757 else if( iVar <= 5 && jVar > 5 )
761 for ( w = 0; w <
nWords; w += 2*step )
763 for (j = 0; j < step; j++)
765 low2High = (pTruth[w + j] & PPMasks[iVar][5]) >> shift;
766 pTruth[w + j] &= ~PPMasks[iVar][5];
767 high2Low = (pTruth[w + step + j] & (PPMasks[iVar][5] >> shift)) << shift;
768 pTruth[w + step + j] &= ~(PPMasks[iVar][5] >> shift);
769 pTruth[w + j] |= high2Low;
770 pTruth[w + step + j] |= low2High;
778 for (w = 0; w <
nWords; w += 2*jStep)
780 for (i = 0; i < jStep; i += 2*iStep)
782 for (j = 0; j < iStep; j++)
784 temp = pTruth[w + iStep + i + j];
785 pTruth[w + iStep + i + j] = pTruth[w + jStep + i + j];
786 pTruth[w + jStep + i + j] = temp;
793 V2P[P2V[iVar]] = jVar;
794 V2P[P2V[jVar]] = iVar;
795 P2V[iVar] ^= P2V[jVar];
796 P2V[jVar] ^= P2V[iVar];
797 P2V[iVar] ^= P2V[jVar];
803 for ( k = 0; k < (nVars-iVarStart)/2 ; k++ )
821 int iPlace0, iPlace1, Count = 0;
822 assert( v >= 0 && v < nVars );
823 while ( Var2Pla[v] < p )
825 iPlace0 = Var2Pla[v];
826 iPlace1 = Var2Pla[v]+1;
828 pTemp = pIn; pIn = pOut, pOut = pTemp;
829 Var2Pla[Pla2Var[iPlace0]]++;
830 Var2Pla[Pla2Var[iPlace1]]--;
831 Pla2Var[iPlace0] ^= Pla2Var[iPlace1];
832 Pla2Var[iPlace1] ^= Pla2Var[iPlace0];
833 Pla2Var[iPlace0] ^= Pla2Var[iPlace1];
836 while ( Var2Pla[v] > p )
838 iPlace0 = Var2Pla[v]-1;
839 iPlace1 = Var2Pla[v];
841 pTemp = pIn; pIn = pOut, pOut = pTemp;
842 Var2Pla[Pla2Var[iPlace0]]++;
843 Var2Pla[Pla2Var[iPlace1]]--;
844 Pla2Var[iPlace0] ^= Pla2Var[iPlace1];
845 Pla2Var[iPlace1] ^= Pla2Var[iPlace0];
846 Pla2Var[iPlace0] ^= Pla2Var[iPlace1];
851 assert( Pla2Var[p] == v );
858 for ( v = 0; v < g->
nVars; v++ )
875 for ( v = iVarStart; v < nVars; v++ )
876 If_CluMoveVar( pF, nVars, V2P, P2V, P2V[iVarStart], nVars - 1 - (v - iVarStart) );
898 printf(
"%d ", nVars );
905 word iCofs[128], iCof, Result = 0;
906 word * pCofA, * pCofB;
907 int nMints = (1 << nBSsize);
909 assert( nBSsize >= 2 && nBSsize <= 7 && nBSsize < nVars );
910 if ( nVars - nBSsize < 6 )
912 int nShift = (1 << (nVars - nBSsize));
913 word Mask = ((((
word)1) << nShift) - 1);
914 for ( nCofs = i = 0; i < nMints; i++ )
916 iCof = (pF[(iShift + i * nShift) / 64] >> ((iShift + i * nShift) & 63)) & Mask;
917 for ( c = 0; c < nCofs; c++ )
918 if ( iCof == iCofs[c] )
921 iCofs[nCofs++] = iCof;
922 if ( pCofs && iCof != iCofs[0] )
923 Result |= (((
word)1) << i);
927 if ( nCofs <= 2 && pCofs )
930 pCofs[0][0] = iCofs[0];
931 pCofs[1][0] = (nCofs == 2) ? iCofs[1] : iCofs[0];
932 pCofs[2][0] = Result;
939 for ( nCofs = i = 0; i < nMints; i++ )
942 for ( c = 0; c < nCofs; c++ )
944 pCofB = pF + iCofs[c] *
nWords;
945 for ( w = 0; w <
nWords; w++ )
946 if ( pCofA[w] != pCofB[w] )
956 pCofB = pF + iCofs[0] *
nWords;
957 for ( w = 0; w <
nWords; w++ )
958 if ( pCofA[w] != pCofB[w] )
961 Result |= (((
word)1) << i);
966 if ( nCofs <= 2 && pCofs )
968 If_CluCopy( pCofs[0], pF + iCofs[0] * nWords, nVars - nBSsize );
969 If_CluCopy( pCofs[1], pF + ((nCofs == 2) ? iCofs[1] : iCofs[0]) * nWords, nVars - nBSsize );
970 pCofs[2][0] = Result;
973 assert( nCofs >= 1 && nCofs <= 5 );
980 word iCofs[128], iCof, Result0 = 0, Result1 = 0;
981 int nMints = (1 << nBSsize);
984 assert( nBSsize >= 2 && nBSsize <= 6 && nBSsize < nVars );
985 if ( nVars - nBSsize < 6 )
987 int nShift = (1 << (nVars - nBSsize));
988 word Mask = ((((
word)1) << nShift) - 1);
989 for ( nCofs = i = 0; i < nMints; i++ )
991 iCof = (pF[(i * nShift) / 64] >> ((i * nShift) & 63)) & Mask;
992 for ( c = 0; c < nCofs; c++ )
993 if ( iCof == iCofs[c] )
996 iCofs[nCofs++] = iCof;
997 if ( c == 1 || c == 3 )
998 Result0 |= (((
word)1) << i);
999 if ( c == 2 || c == 3 )
1000 Result1 |= (((
word)1) << i);
1002 assert( nCofs >= 3 && nCofs <= 4 );
1003 pCofs[0][0] = iCofs[0];
1004 pCofs[1][0] = iCofs[1];
1005 pCofs[2][0] = iCofs[2];
1006 pCofs[3][0] = (nCofs == 4) ? iCofs[3] : iCofs[2];
1007 pCofs[4][0] = Result0;
1008 pCofs[5][0] = Result1;
1021 int i, Shift = (1 << iVar);
1022 for ( i = 0; i <
nWords; i++ )
1024 pCof0[i] = (pF[i] & ~
Truth6[iVar]) | ((pF[i] & ~
Truth6[iVar]) << Shift);
1025 pCof1[i] = (pF[i] &
Truth6[iVar]) | ((pF[i] &
Truth6[iVar]) >> Shift);
1030 int i, k, Step = (1 << (iVar - 6));
1031 for ( k = 0; k <
nWords; k += 2*Step )
1033 for ( i = 0; i < Step; i++ )
1035 pCof0[i] = pCof0[Step+i] = pF[i];
1036 pCof1[i] = pCof1[Step+i] = pF[Step+i];
1054 int Shift = (1 << iVar);
1055 for ( i = 0; i <
nWords; i++ )
1057 Cof0 = (pF[i] & ~
Truth6[iVar]);
1058 Cof1 = ((pF[i] &
Truth6[iVar]) >> Shift);
1062 else if ( Cof0 == ~
Truth6[iVar] )
1064 else if ( Cof1 == 0 )
1066 else if ( Cof1 == ~
Truth6[iVar] )
1068 else if ( Cof0 == ~Cof1 )
1070 else if ( Cof0 == Cof1 )
1076 int k, Step = (1 << (iVar - 6));
1077 for ( k = 0; k <
nWords; k += 2*Step )
1079 for ( i = 0; i < Step; i++ )
1086 else if ( Cof0 == ~(
word)0 )
1088 else if ( Cof1 == 0 )
1090 else if ( Cof1 == ~(
word)0 )
1092 else if ( Cof0 == ~Cof1 )
1094 else if ( Cof0 == Cof1 )
1101 assert( State[5] != nWords );
1102 for ( i = 0; i < 5; i++ )
1104 assert( State[i] <= nWords );
1105 if ( State[i] == nWords )
1118 int nVarsNeeded = nVars - nLutLeaf;
1119 int v, i, k, iVar, State;
1123 for ( k = 0; k < nVars; k++ )
1124 Var2Pla[k] = Pla2Var[k] = k;
1126 for ( i = 0; i < nVarsNeeded; i++ )
1128 for ( v = nVars - 1; v >= 0; v-- )
1135 while ( Var2Pla[iVar] < nVars - 1 )
1137 int iPlace0 = Var2Pla[iVar];
1138 int iPlace1 = Var2Pla[iVar]+1;
1139 Var2Pla[Pla2Var[iPlace0]]++;
1140 Var2Pla[Pla2Var[iPlace1]]--;
1141 Pla2Var[iPlace0] ^= Pla2Var[iPlace1];
1142 Pla2Var[iPlace1] ^= Pla2Var[iPlace0];
1143 Pla2Var[iPlace0] ^= Pla2Var[iPlace1];
1146 for ( k = 0; k < nVars; k++ )
1147 V2P[k] = P2V[k] = k;
1153 if ( State == 0 || State == 1 )
1156 pF[0] = (pF[0] &
Truth6[iVar]) | ((pF[0] &
Truth6[iVar]) >> (1 << iVar));
1163 pF[0] = (pF[0] & ~
Truth6[iVar]) | ((pF[0] & ~
Truth6[iVar]) << (1 << iVar));
1175 for ( v = 0; v < G.
nVars; v++ )
1176 G.
pVars[v] = Pla2Var[v];
1186 int i, RetValue, nFSset = nVars - g->
nVars;
1191 pF[0] = (pCofs[1][0] << (1 << nFSset)) | pCofs[0][0];
1200 r->
nVars = nFSset + 1;
1202 for ( i = 0; i < nFSset; i++ )
1203 r->
pVars[i] = P2V[i];
1204 r->
pVars[nFSset] = nVars;
1212 int i, RetValue, nFSset = nVars - g->
nVars;
1217 if ( RetValue != 3 && RetValue != 4 )
1218 printf(
"If_CluDeriveDisjoint4(): Error!!!\n" );
1220 Cof0 = (pCofs[1][0] << (1 << nFSset)) | pCofs[0][0];
1221 Cof1 = (pCofs[3][0] << (1 << nFSset)) | pCofs[2][0];
1222 pF[0] = (Cof1 << (1 << (nFSset+1))) | Cof0;
1226 r->
nVars = nFSset + 2;
1228 for ( i = 0; i < nFSset; i++ )
1229 r->
pVars[i] = P2V[i];
1230 r->
pVars[nFSset] = nVars;
1231 r->
pVars[nFSset+1] = nVars+1;
1241 int i, nFSset = nVars - g->
nVars, nFSset1 = nFSset + 1;
1250 Truth = (Truth1 << (1 << g->
nVars)) | Truth0;
1253 pF[0] = (pCofs[1][0] << (1 << nFSset1)) | pCofs[0][0];
1268 r->
nVars = nFSset + 2;
1270 for ( i = 0; i < nFSset; i++ )
1271 r->
pVars[i] = P2V[i];
1272 r->
pVars[nFSset] = nVars;
1280 int v, i, nCofsBest2;
1281 if ( (g->
nMyu == 3 || g->
nMyu == 4) )
1285 for ( v = 0; v < g->
nVars; v++ )
1289 if ( nCofsBest2 > 2 )
1292 if ( nCofsBest2 > 2 )
1296 for ( i = 0; i < g->
nVars; i++ )
1311 int i, r, v, nCofs, VarBest, nCofsBest2;
1312 assert( nVars > nBSsize && nVars >= nBSsize + iVarStart && nVars <=
CLU_VAR_MAX );
1313 assert( nBSsize >= 2 && nBSsize <= 6 );
1314 assert( !iVarStart || !iVarStop );
1318 for ( i = 0; i < nBSsize; i++ )
1319 g->pVars[i] = P2V[nVars-nBSsize+i];
1328 if ( nVars == nBSsize + iVarStart )
1336 printf(
"Iter %2d ", -1 );
1341 for ( r = 0; r < nRounds; r++ )
1343 if ( nBSsize < nVars-1 )
1346 VarBest = P2V[nVars-1-nBSsize];
1348 for ( v = nVars-2-nBSsize; v >= iVarStart; v-- )
1353 if ( nCofsBest2 >= nCofs )
1356 VarBest = P2V[nVars-1-nBSsize];
1364 assert( nCofs == nCofsBest2 );
1368 VarBest = P2V[nVars-1-nBSsize];
1370 for ( v = nVars-nBSsize; v < nVars-iVarStop; v++ )
1375 if ( nCofsBest2 >= nCofs )
1378 VarBest = P2V[nVars-1-nBSsize];
1387 assert( nCofs == nCofsBest2 );
1388 if ( g->nMyu >= nCofs )
1392 for ( i = 0; i < nBSsize; i++ )
1393 g->pVars[i] = P2V[nVars-nBSsize+i];
1398 printf(
"Iter %2d ", r );
1427 for ( v = 0; v < nVars; v++ )
1428 V2P[v] = P2V[v] = v;
1435 if ( nCofs != g->
nMyu )
1436 printf(
"Group check 0 has failed.\n" );
1442 printf(
"Group check 1 has failed.\n" );
1445 printf(
"Group check 2 has failed.\n" );
1454 for ( i = 0; i < nVars; i++ )
1458 printf(
"Permutation FAILED.\n" );
1468 return (Supp & (Supp+1)) == 0;
1476 int i, Shift = (1 << iVar);
1477 for ( i = 0; i <
nWords; i++ )
1478 if ( (t[i] & ~
Truth6[iVar]) != ((t[i] &
Truth6[iVar]) >> Shift) )
1484 int i, k, Step = (1 << (iVar - 6));
1485 for ( k = 0; k <
nWords; k += 2*Step )
1487 for ( i = 0; i < Step; i++ )
1488 if ( t[i] != t[Step+i] )
1498 for ( v = 0; v < nVars; v++ )
1505 int v, SuppSize = 0;
1506 for ( v = 0; v < nVars; v++ )
1515 assert( nVarsAll <= 16 );
1516 for ( i = 0; i < nVarsAll; i++ )
1517 if ( Phase & (1 << i) )
1519 for ( k = i-1; k >=
Var; k-- )
1522 pTemp = pIn; pIn = pOut, pOut = pTemp;
1534 int v, iVar = 0, uSupp = 0;
1535 assert( nVarsAll <= 16 );
1536 for ( v = 0; v < nVarsAll; v++ )
1541 pSupp[iVar] = pSupp[v];
1558 unsigned * pHashed = NULL;
1561 int i, nSupp, uCanonPhase;
1564 assert( nVars <= nLutLeaf + nLutRoot - 1 );
1598 for ( i = 0; i < nVars; i++ )
1599 V2P[i] = P2V[i] = i;
1610 if ( p && fHashing )
1621 if ( G1.
nVars == 0 )
1626 if ( iVarStart == 0 )
1628 if ( G1.
nVars == 0 )
1631 G1 =
If_CluFindGroup( pF, nVars, iVarStart, iVarStop, V2P, P2V, nLutLeaf, nLutLeaf + nLutRoot == nVars + 1 );
1633 if ( G1.
nVars == 0 )
1636 if ( nVars < nLutLeaf + nLutRoot - 2 )
1639 G1 =
If_CluFindGroup( pF, nVars, iVarStart, iVarStop, V2P, P2V, nLutLeaf, nLutLeaf + nLutRoot == nVars + 1 );
1643 if ( nLutLeaf > 4 && nVars < nLutLeaf + nLutRoot - 3 )
1647 G1 =
If_CluFindGroup( pF, nVars, iVarStart, iVarStop, V2P, P2V, nLutLeaf, nLutLeaf + nLutRoot == nVars + 1 );
1651 if ( G1.
nVars == 0 )
1655 G1 =
If_CluFindGroup( pF, nVars, iVarStart, iVarStop, V2P, P2V, nLutLeaf, nLutLeaf + nLutRoot == nVars + 1 );
1659 if ( G1.
nVars == 0 )
1694 iNewPos = R.nVars - 1;
1699 iNewPos = R.nVars - 2;
1701 assert( R.pVars[iNewPos] == nVars );
1715 assert( iNewPos >= iVarStart );
1716 for ( k = 0; k < R.nVars; k++ )
1717 V2P2[k] = P2V2[k] = k;
1718 If_CluMoveVar( pF, R.nVars, V2P2, P2V2, iNewPos, iVarStart );
1719 for ( k = iNewPos; k > iVarStart; k-- )
1720 R.pVars[k] = R.pVars[k-1];
1721 R.pVars[iVarStart] = nVars;
1769 int v, u, Cof2[2], Cof4[4];
1770 for ( v = 0; v < nVars; v++ )
1774 for ( u = v+1; u < nVars; u++ )
1780 if ( Cof4[0] == Cof4[1] && Cof4[0] == Cof4[2] )
1782 if ( Cof4[0] == Cof4[2] && Cof4[0] == Cof4[3] )
1784 if ( Cof4[0] == Cof4[1] && Cof4[0] == Cof4[3] )
1786 if ( Cof4[1] == Cof4[2] && Cof4[1] == Cof4[3] )
1794 int v, u, Cof2[2], Cof4[4];
1796 for ( v = 0; v < 1; v++ )
1800 for ( u = v+1; u < nVars; u++ )
1806 if ( Cof4[0] == Cof4[1] && Cof4[0] == Cof4[2] )
1808 if ( Cof4[0] == Cof4[2] && Cof4[0] == Cof4[3] )
1810 if ( Cof4[0] == Cof4[1] && Cof4[0] == Cof4[3] )
1812 if ( Cof4[1] == Cof4[2] && Cof4[1] == Cof4[3] )
1820 int v, u, Cof2[2], Cof4[4];
1822 for ( v = 0; v < 1; v++ )
1826 for ( u = v+1; u < nVars; u++ )
1832 if ( Cof4[0] == Cof4[1] && Cof4[0] == Cof4[2] )
1834 if ( Cof4[0] == Cof4[2] && Cof4[0] == Cof4[3] )
1843 for ( v = 0; v < nVars; v++ )
1856 for ( v = 0; v < nVars; v++ )
1870 G =
If_CluCheck( p, (
word *)pTruth, nLeaves, 0, 0, 5, 4, &R, &Func0, &Func1, NULL, 0 );
1891 G =
If_CluCheck( p, (
word *)pTruth, nLeaves, 0, 0, 4, 5, &R, &Func0, &Func1, NULL, 0 );
1912 int fEnableHashing = 0;
1914 unsigned * pHashed = NULL;
1916 If_Grp_t G1 = {0}, G2 = {0}, R = {0}, R2 = {0};
1925 if ( p && fEnableHashing )
1937 G1 =
If_CluCheck( p, pTruth0, nVars, 0, 0, nLutLeaf, nLutRoot + nLutLeaf2 - 1, &R2, &Func0, &Func1, pLeftOver, 0 );
1939 if ( G1.
nVars == 0 )
1942 if ( (G1.
nMyu == 3 || G1.
nMyu == 4) && nLutLeaf == nLutLeaf2 && nVars - nLutLeaf + 2 <= nLutRoot )
1945 word Func0, Func1, Func2;
1948 G1.
nVars = nLutLeaf;
1950 for ( i = 0; i < nVars; i++ )
1951 V2P[i] = P2V[i] = i;
1957 for ( i = 0; i < R.nVars; i++ )
1958 V2P[i] = P2V[i] = i;
1959 If_CluMoveVar( pLeftOver, R.nVars, V2P, P2V, R.nVars-2, 0 );
1960 If_CluMoveVar( pLeftOver, R.nVars, V2P, P2V, R.nVars-1, 1 );
1961 iVar0 = R.pVars[R.nVars-2];
1962 iVar1 = R.pVars[R.nVars-1];
1963 for ( i = R.nVars-1; i > 1; i-- )
1964 R.pVars[i] = R.pVars[i-2];
1968 Func0 = pLeftOver[0];
1969 If_CluVerify3( pTruth0, nVars, &G1, &G1, &R, Func1, Func2, Func0 );
1970 if ( pFunc1 && pFunc2 )
2000 if ( R2.nVars <= nLutRoot )
2002 if ( pG2 ) *pG2 = G2;
2004 if ( pFunc0 ) *pFunc0 = Func0;
2005 if ( pFunc1 ) *pFunc1 = Func1;
2006 if ( pFunc2 ) *pFunc2 = 0;
2023 G2 =
If_CluCheck( p, pLeftOver, R2.nVars, 0, 0, nLutLeaf2, nLutRoot, &R, &Func0, &Func2, NULL, 0 );
2025 G2 =
If_CluCheck( p, pLeftOver, R2.nVars, 1, 0, nLutLeaf2, nLutRoot, &R, &Func0, &Func2, NULL, 0 );
2027 G2 =
If_CluCheck( p, pLeftOver, R2.nVars, 0, 1, nLutLeaf2, nLutRoot, &R, &Func0, &Func2, NULL, 0 );
2030 if ( G2.nVars == 0 )
2037 for ( i = 0; i < G2.nVars; i++ )
2039 assert( G2.pVars[i] < R2.nVars );
2040 G2.pVars[i] = R2.pVars[ (int)G2.pVars[i] ];
2043 for ( i = 0; i < R.nVars; i++ )
2045 if ( R.pVars[i] == R2.nVars )
2046 R.pVars[i] = nVars + 1;
2048 R.pVars[i] = R2.pVars[ (int)R.pVars[i] ];
2052 if ( pG2 ) *pG2 = G2;
2054 if ( pFunc0 ) *pFunc0 = Func0;
2055 if ( pFunc1 ) *pFunc1 = Func1;
2056 if ( pFunc2 ) *pFunc2 = Func2;
2067 char * pLut0,
char * pLut1,
word * pFunc0,
word * pFunc1 )
2071 G =
If_CluCheck( p, pTruth, nVars, 0, 0, nLutLeaf, nLutRoot, &R, pFunc0, pFunc1, NULL, 0 );
2075 return (G.
nVars > 0);
2080 char * pLut0,
char * pLut1,
char * pLut2,
word * pFunc0,
word * pFunc1,
word * pFunc2 )
2084 G =
If_CluCheck3( p, pTruth, nVars, nLutLeaf, nLutLeaf2, nLutRoot, &R, &G2, pFunc0, pFunc1, pFunc2 );
2088 return (G.
nVars > 0);
2097 for ( i = 0; i < g->
nVars; i++ )
2108 If_Grp_t G1 = {0}, G2 = {0}, G3 = {0};
2110 int i, nLutLeaf, nLutRoot;
2116 printf(
"Wrong LUT struct (%s)\n", pStr );
2119 nLutLeaf = pStr[0] -
'0';
2120 if ( nLutLeaf < 3 || nLutLeaf > 6 )
2122 printf(
"Leaf size (%d) should belong to {3,4,5,6}.\n", nLutLeaf );
2125 nLutRoot = pStr[1] -
'0';
2126 if ( nLutRoot < 3 || nLutRoot > 6 )
2128 printf(
"Root size (%d) should belong to {3,4,5,6}.\n", nLutRoot );
2131 if ( nLeaves > nLutLeaf + nLutRoot - 1 )
2133 printf(
"The cut size (%d) is too large for the LUT structure %d%d.\n",
If_CutLeaveNum(pCut), nLutLeaf, nLutRoot );
2142 if ( nLeaves <=
Abc_MaxInt( nLutLeaf, nLutRoot ) )
2146 for ( i = 0; i < nLeaves; i++ )
2156 G1 =
If_CluCheck( p,
If_CutTruthW(p, pCut), nLeaves, 0, 0, nLutLeaf, nLutRoot, NULL, NULL, NULL, NULL, 1 );
2157 if ( G1.
nVars == 0 )
2161 Delays[nLeaves] =
If_CluDelayMax( &G1, Delays ) + ((WireDelay == 0.0)?1.0:WireDelay);
2163 Delays[nLeaves+1] =
If_CluDelayMax( &G2, Delays ) + ((WireDelay == 0.0)?1.0:WireDelay);
2166 for ( i = 0; i < G1.
nVars; i++ )
2167 fUsed[(
int)G1.
pVars[i]] = 1;
2168 for ( i = 0; i < G2.nVars; i++ )
2169 fUsed[(
int)G2.pVars[i]] = 1;
2174 assert( !G2.nVars || (G2.nMyu >= 2 && G2.nMyu <= 4) );
2176 fUsed[(int)G2.pVars[G2.nVars-1]] = 0;
2180 for ( i = 0; i < nLeaves; i++ )
2182 G3.pVars[(int)G3.nVars++] = i;
2183 G3.pVars[(
int)G3.nVars++] = nLeaves;
2185 G3.pVars[(int)G3.nVars++] = nLeaves+1;
2186 assert( G1.
nVars + G2.nVars + G3.nVars == nLeaves +
2187 (G1.
nVars > 0) + (G2.nVars > 0) + (G1.
nMyu > 2) + (G2.nMyu > 2) );
2190 pCut->
Cost = 2 + (G2.nVars > 0);
2220 int i, nLutLeaf, nLutLeaf2, nLutRoot, Length;
2236 if ( s_vTtMem2 == NULL )
2243 for ( i = 0; i <
nWords; i++ )
2244 pCopy[i] = ~pCopy[i];
2249 char pCanonPermC[16];
2263 if ( Length != 2 && Length != 3 )
2265 printf(
"Wrong LUT struct (%s)\n", pStr );
2268 for ( i = 0; i < Length; i++ )
2269 if ( pStr[i] -
'0' < 3 || pStr[i] -
'0' > 6 )
2271 printf(
"The LUT size (%d) should belong to {3,4,5,6}.\n", pStr[i] -
'0' );
2275 nLutLeaf = pStr[0] -
'0';
2276 nLutLeaf2 = ( Length == 3 ) ? pStr[1] -
'0' : 0;
2277 nLutRoot = pStr[Length-1] -
'0';
2278 if ( nLeaves > nLutLeaf - 1 + (nLutLeaf2 ? nLutLeaf2 - 1 : 0) + nLutRoot )
2280 printf(
"The cut size (%d) is too large for the LUT structure %s.\n", nLeaves, pStr );
2289 G1 =
If_CluCheck( p, (
word *)pTruth, nLeaves, 0, 0, nLutLeaf, nLutRoot, NULL, NULL, NULL, NULL, 1 );
2291 G1 =
If_CluCheck3( p, (
word *)pTruth, nLeaves, nLutLeaf, nLutLeaf2, nLutRoot, NULL, NULL, NULL, NULL, NULL );
2296 return (
int)(G1.nVars > 0);
2331 word Func0, Func1, Func2;
2348 G =
If_CluCheck3( NULL, &t, nVars, nLutLeaf, nLutLeaf2, nLutRoot, &R, &G2, &Func0, &Func1, &Func2 );
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
static int If_CluEqual(word *pOut, word *pIn, int nVars)
void If_CluVerify3(word *pF, int nVars, If_Grp_t *g, If_Grp_t *g2, If_Grp_t *r, word BStruth, word BStruth2, word FStruth)
static int Abc_TtMinBase(word *pTruth, int *pVars, int nVars, int nVarsAll)
int If_CutPerformCheck16(If_Man_t *p, unsigned *pTruth0, int nVars, int nLeaves, char *pStr)
int If_CluCheckDecInU(word t, int nVars)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
int If_CluCheckDecOut(word t, int nVars)
static void If_CluAdjustBig(word *pF, int nVarsCur, int nVarsMax)
static void If_CluSwapAdjacent(word *pOut, word *pIn, int iVar, int nVars)
void If_CluHashPrintStats(If_Man_t *p, int t)
If_Grp_t If_CluCheck(If_Man_t *p, word *pTruth0, int nVars, int iVarStart, int iVarStop, int nLutLeaf, int nLutRoot, If_Grp_t *pR, word *pFunc0, word *pFunc1, word *pLeftOver, int fHashing)
static void Vec_MemHashAlloc(Vec_Mem_t *p, int nTableSize)
static int Abc_Truth6WordNum(int nVars)
#define If_CutForEachLeaf(p, pCut, pLeaf, i)
static int If_CutLeaveNum(If_Cut_t *pCut)
static char * If_CutPerm(If_Cut_t *pCut)
void If_CluHashTableCheck(If_Man_t *p)
void If_CluReverseOrder(word *pTruth, int nVars, int *V2P, int *P2V, int iVarStart)
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
static int Vec_MemEntryNum(Vec_Mem_t *p)
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
static void Vec_IntSetEntry(Vec_Int_t *p, int i, int Entry)
void If_CluSemiCanonicizeVerify(word *pTruth, word *pTruth0, int nVars, int *pCanonPerm, unsigned uCanonPhase)
static If_Cut_t * If_ObjCutBest(If_Obj_t *pObj)
If_Grp_t If_CluCheck3(If_Man_t *p, word *pTruth0, int nVars, int nLutLeaf, int nLutLeaf2, int nLutRoot, If_Grp_t *pR, If_Grp_t *pG2, word *pFunc0, word *pFunc1, word *pFunc2)
unsigned * If_CluHashLookup(If_Man_t *p, word *pTruth, int t)
static int Abc_TruthWordNum(int nVars)
static word Abc_Tt6Cofactor0(word t, int iVar)
static int Abc_MaxInt(int a, int b)
int If_CluCountCofs4(word *pF, int nVars, int nBSsize, word pCofs[6][CLU_WRD_MAX/4])
void If_CluReverseOrder_old(word *pF, int nVars, int *V2P, int *P2V, int iVarStart)
static int Vec_PtrSize(Vec_Ptr_t *p)
int If_CluCheckExt(void *pMan, word *pTruth, int nVars, int nLutLeaf, int nLutRoot, char *pLut0, char *pLut1, word *pFunc0, word *pFunc1)
static void If_CluClear(word *pIn, int nVars)
int If_CluCheckDecOutU(word t, int nVars)
int If_CluHashFindMedian(If_Man_t *p, int t)
static float Abc_MaxFloat(float a, float b)
void Kit_DsdPrintFromTruth(unsigned *pTruth, int nVars)
unsigned If_CluSemiCanonicize(word *pTruth, int nVars, int *pCanonPerm)
static int If_CluWordNum(int nVars)
static void If_CluAnd(word *pRes, word *pIn1, word *pIn2, int nVars)
Mem_Fixed_t * Mem_FixedStart(int nEntrySize)
FUNCTION DEFINITIONS ///.
static word * If_CutTruthW(If_Man_t *p, If_Cut_t *pCut)
static Vec_Mem_t * Vec_MemAlloc(int nCap)
FUNCTION DEFINITIONS ///.
static int Abc_MinInt(int a, int b)
static int If_CluSuppIsMinBase(int Supp)
static Vec_Int_t * Vec_IntStart(int nSize)
static void If_CluComposeLut(int nVars, If_Grp_t *g, word *t, word f[6][CLU_WRD_MAX], word *r)
int If_CluMinimumBase(word *t, int *pSupp, int nVarsAll, int *pnVars)
static void If_CluCopy(word *pOut, word *pIn, int nVars)
static void If_CluOr(word *pRes, word *pIn1, word *pIn2, int nVars)
static void If_CluTruthShrink(word *pF, int nVars, int nVarsAll, unsigned Phase)
static word Abc_Tt6Cofactor1(word t, int iVar)
If_Grp_t If_CluDecUsingCofs(word *pTruth, int nVars, int nLutLeaf)
static void Vec_IntAddToEntry(Vec_Int_t *p, int i, int Addition)
static void If_CluSharp(word *pRes, word *pIn1, word *pIn2, int nVars)
unsigned int If_CluPrimeCudd(unsigned int p)
int If_CluSupportSize(word *t, int nVars)
static word TruthAll[CLU_VAR_MAX][CLU_WRD_MAX]
void If_CluPrintConfig(int nVars, If_Grp_t *g, If_Grp_t *r, word BStruth, word *pFStruth)
float If_CutDelayLutStruct(If_Man_t *p, If_Cut_t *pCut, char *pStr, float WireDelay)
static int Vec_IntEntry(Vec_Int_t *p, int i)
void If_CluPrintGroup(If_Grp_t *g)
unsigned __int64 word
DECLARATIONS ///.
#define ABC_NAMESPACE_IMPL_END
#define CLU_VAR_MAX
DECLARATIONS ///.
static void Abc_TtStretch6(word *pInOut, int nVarS, int nVarB)
static int If_CluHasVar(word *t, int nVars, int iVar)
#define IF_MAX_FUNC_LUTSIZE
int If_CluCheckDecInAny(word t, int nVars)
float If_CluDelayMax(If_Grp_t *g, float *pDelays)
void Mem_FixedEntryRecycle(Mem_Fixed_t *p, char *pEntry)
static void If_CluFill(word *pIn, int nVars)
Mem_Fixed_t * pMemEntries
void If_CluCofactors(word *pF, int nVars, int iVar, word *pCof0, word *pCof1)
int If_CluCheckExt3(void *pMan, word *pTruth, int nVars, int nLutLeaf, int nLutLeaf2, int nLutRoot, char *pLut0, char *pLut1, char *pLut2, word *pFunc0, word *pFunc1, word *pFunc2)
#define ABC_NAMESPACE_IMPL_START
void If_CluCheckPerm(word *pTruth, word *pF, int nVars, int *V2P, int *P2V)
void If_CluCountOnesInCofs(word *pTruth, int nVars, int *pStore)
word If_CluDeriveNonDisjoint(word *pF, int nVars, int *V2P, int *P2V, If_Grp_t *g, If_Grp_t *r)
static ABC_NAMESPACE_IMPL_START word Truth[8]
DECLARATIONS ///.
int If_CutPerformCheck45(If_Man_t *p, unsigned *pTruth, int nVars, int nLeaves, char *pStr)
void If_CluMoveGroupToMsb(word *pF, int nVars, int *V2P, int *P2V, If_Grp_t *g)
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
static int Abc_TtWordNum(int nVars)
void If_CluChangePhase(word *pF, int nVars, int iVar)
void If_CluDeriveDisjoint4(word *pF, int nVars, int *V2P, int *P2V, If_Grp_t *g, If_Grp_t *r, word *pTruth0, word *pTruth1)
#define ABC_CONST(number)
PARAMETERS ///.
int If_CluDetectSpecialCaseCofs(word *pF, int nVars, int iVar)
int If_CutPerformCheck54(If_Man_t *p, unsigned *pTruth, int nVars, int nLeaves, char *pStr)
void If_CluInitTruthTables()
static word If_CluAdjust(word t, int nVars)
#define ABC_CALLOC(type, num)
word If_CluDeriveDisjoint(word *pF, int nVars, int *V2P, int *P2V, If_Grp_t *g, If_Grp_t *r)
unsigned Abc_TtCanonicize(word *pTruth, int nVars, char *pCanonPerm)
FUNCTION DECLARATIONS ///.
static int If_CluSupport(word *t, int nVars)
static int If_CluCountOnes(word t)
static void If_CluUns2Grp(unsigned Group, If_Grp_t *pG)
void If_CluVerify(word *pF, int nVars, If_Grp_t *g, If_Grp_t *r, word BStruth, word *pFStruth)
int If_CluHashKey(word *pTruth, int nWords, int Size)
If_Grp_t If_CluFindGroup(word *pF, int nVars, int iVarStart, int iVarStop, int *V2P, int *P2V, int nBSsize, int fDisjoint)
static int Vec_MemHashInsert(Vec_Mem_t *p, word *pEntry)
void If_CluMoveVar2(word *pF, int nVars, int *Var2Pla, int *Pla2Var, int v, int p)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
void If_CluMoveVar(word *pF, int nVars, int *Var2Pla, int *Pla2Var, int v, int p)
static Vec_Mem_t * s_vTtMem
void If_CluCheckGroup(word *pTruth, int nVars, If_Grp_t *g)
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
int If_CluCheckNonDisjointGroup(word *pF, int nVars, int *V2P, int *P2V, If_Grp_t *g)
static void Vec_IntFree(Vec_Int_t *p)
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
static unsigned If_CluGrp2Uns(If_Grp_t *pG)
FUNCTION DEFINITIONS ///.
char * Mem_FixedEntryFetch(Mem_Fixed_t *p)
int If_CluCountCofs(word *pF, int nVars, int nBSsize, int iShift, word pCofs[3][CLU_WRD_MAX/4])
void If_CluSwapVars(word *pTruth, int nVars, int *V2P, int *P2V, int iVar, int jVar)
int If_CluCheckDecIn(word t, int nVars)
static void Vec_PtrFree(Vec_Ptr_t *p)