79 Res = log(Num)/log(2.0);
103 return (
double)(01<<Degree);
104 for ( Res = 1.0; Degree; Res *= 2.0, Degree-- );
125 for ( i = 0; i < Num; i++ )
144 for ( i = 1; i <= k; i++ )
145 Res = Res * (n-i+1) / i;
162 static int Code[100];
165 for ( i = 0; i < nDigits; i++ )
167 Code[i] = Number % Radix;
168 Number = Number / Radix;
188 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
189 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
190 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
191 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
192 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
193 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
194 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
195 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
200 for ( i = 0; i < nBytes; i++ )
201 Counter += bit_count[ *(pBytes+i) ];
219 for ( i = 1; i <= n; i++ )
247 for ( i = 0; i < n; i++ )
281 int iTemp, iCur, iLast, k;
285 pRes[0][0] = Array[0];
290 nFactNext = nFact / n;
294 for ( iCur = 0; iCur < n; iCur++ )
298 Array[iCur] = Array[iLast];
299 Array[iLast] = iTemp;
302 pNext = pRes + (n - 1 - iCur) * nFactNext;
305 for ( k = 0; k < nFactNext; k++ )
306 pNext[k][iLast] = Array[iLast];
313 Array[iCur] = Array[iLast];
314 Array[iLast] = iTemp;
333 memset( pMintsP, 0,
sizeof(
int) * nMints );
335 for ( m = 0; m < nMints; m++ )
336 for ( v = 0; v < nVars; v++ )
337 if ( pMints[m] & (1 << v) )
338 pMintsP[m] |= (1 << pPerm[v]);
361 nMints = (1 << nVars);
364 for ( i = 0; i < nMints; i++ )
372 for ( m = 0; m < nMints; m++ )
373 if ( Truth & (1 << pMintsP[m]) )
378 for ( m = 0; m < nMints; m++ )
379 if ( Truth & (1 << m) )
380 Result |= (1 << pMintsP[m]);
403 static unsigned Signs[5] = {
410 unsigned uTruthRes, uCof0, uCof1;
411 int nMints, Shift, v;
413 nMints = (1 << nVars);
415 for ( v = 0; v < nVars; v++ )
416 if ( Polarity & (1 << v) )
418 uCof0 = uTruth & ~Signs[v];
419 uCof1 = uTruth & Signs[v];
423 uTruth = uCof0 | uCof1;
441 unsigned uTruthMin, uPhase;
443 nMints = (1 << nVars);
444 uTruthMin = 0xFFFFFFFF;
445 for ( i = 0; i < nMints; i++ )
448 if ( uTruthMin > uPhase )
467 unsigned uTruthMin, uTruthC, uPhase;
469 nMints = (1 << nVars);
470 uTruthC = (unsigned)( (~uTruth) & ((~((unsigned)0)) >> (32-nMints)) );
471 uTruthMin = 0xFFFFFFFF;
472 for ( i = 0; i < nMints; i++ )
475 if ( uTruthMin > uPhase )
478 if ( uTruthMin > uPhase )
497 static int nVarsOld, nPerms;
498 static char ** pPerms = NULL;
500 unsigned uTruthMin, uPerm;
503 if ( pPerms == NULL )
509 else if ( nVarsOld != nVars )
517 uTruthMin = 0xFFFFFFFF;
518 for ( k = 0; k < nPerms; k++ )
521 if ( uTruthMin > uPerm )
540 static int nVarsOld, nPerms;
541 static char ** pPerms = NULL;
543 unsigned uTruthMin, uPhase, uPerm;
546 if ( pPerms == NULL )
552 else if ( nVarsOld != nVars )
560 nMints = (1 << nVars);
561 uTruthMin = 0xFFFFFFFF;
562 for ( i = 0; i < nMints; i++ )
565 for ( k = 0; k < nPerms; k++ )
568 if ( uTruthMin > uPerm )
588 static int nVarsOld, nPerms;
589 static char ** pPerms = NULL;
591 unsigned uTruthMin, uTruthC, uPhase, uPerm;
594 if ( pPerms == NULL )
600 else if ( nVarsOld != nVars )
608 nMints = (1 << nVars);
609 uTruthC = (unsigned)( (~uTruth) & ((~((unsigned)0)) >> (32-nMints)) );
610 uTruthMin = 0xFFFFFFFF;
611 for ( i = 0; i < nMints; i++ )
614 for ( k = 0; k < nPerms; k++ )
617 if ( uTruthMin > uPerm )
621 for ( k = 0; k < nPerms; k++ )
624 if ( uTruthMin > uPerm )
642 void Extra_Truth4VarNPN(
unsigned short ** puCanons,
char ** puPhases,
char ** puPerms,
unsigned char ** puMap )
644 unsigned short * uCanons;
645 unsigned char * uMap;
646 unsigned uTruth, uPhase, uPerm;
647 char ** pPerms4, * uPhases, * uPerms;
648 int nFuncs, nClasses;
652 uCanons =
ABC_ALLOC(
unsigned short, nFuncs );
655 uMap =
ABC_ALLOC(
unsigned char, nFuncs );
656 memset( uCanons, 0,
sizeof(
unsigned short) * nFuncs );
657 memset( uPhases, 0,
sizeof(
char) * nFuncs );
658 memset( uPerms, 0,
sizeof(
char) * nFuncs );
659 memset( uMap, 0,
sizeof(
unsigned char) * nFuncs );
664 for ( uTruth = 1; uTruth < (unsigned)nFuncs; uTruth++ )
667 if ( uCanons[uTruth] )
669 assert( uTruth > uCanons[uTruth] );
670 uMap[~uTruth & 0xFFFF] = uMap[uTruth] = uMap[uCanons[uTruth]];
673 uMap[uTruth] = nClasses++;
674 for ( i = 0; i < 16; i++ )
677 for ( k = 0; k < 24; k++ )
680 if ( uCanons[uPerm] == 0 )
682 uCanons[uPerm] = uTruth;
686 uPerm = ~uPerm & 0xFFFF;
687 uCanons[uPerm] = uTruth;
688 uPhases[uPerm] = i | 16;
692 assert( uCanons[uPerm] == uTruth );
695 for ( k = 0; k < 24; k++ )
698 if ( uCanons[uPerm] == 0 )
700 uCanons[uPerm] = uTruth;
704 uPerm = ~uPerm & 0xFFFF;
705 uCanons[uPerm] = uTruth;
706 uPhases[uPerm] = i | 16;
710 assert( uCanons[uPerm] == uTruth );
714 uPhases[(1<<16)-1] = 16;
715 assert( nClasses == 222 );
750 unsigned uTruth, uPhase, uTruth32;
751 char ** uPhases, * pCounters;
752 int nFuncs, nClasses, i;
756 memset( uCanons, 0,
sizeof(
unsigned) * nFuncs );
758 memset( pCounters, 0,
sizeof(
char) * nFuncs );
761 for ( uTruth = 0; uTruth < (unsigned)nFuncs; uTruth++ )
764 uTruth32 = ((uTruth << 24) | (uTruth << 16) | (uTruth << 8) | uTruth);
765 if ( uCanons[uTruth] )
767 assert( uTruth32 > uCanons[uTruth] );
771 for ( i = 0; i < 8; i++ )
774 if ( uCanons[uPhase] == 0 && (uTruth || i==0) )
776 uCanons[uPhase] = uTruth32;
777 uPhases[uPhase][0] = i;
778 pCounters[uPhase] = 1;
782 assert( uCanons[uPhase] == uTruth32 );
783 if ( pCounters[uPhase] < nPhasesMax )
784 uPhases[uPhase][ (int)pCounters[uPhase]++ ] = i;
797 *ppCounters = pCounters;
814 void Extra_Truth4VarN(
unsigned short ** puCanons,
char *** puPhases,
char ** ppCounters,
int nPhasesMax )
816 unsigned short * uCanons;
817 unsigned uTruth, uPhase;
818 char ** uPhases, * pCounters;
819 int nFuncs, nClasses, i;
822 uCanons =
ABC_ALLOC(
unsigned short, nFuncs );
823 memset( uCanons, 0,
sizeof(
unsigned short) * nFuncs );
825 memset( pCounters, 0,
sizeof(
char) * nFuncs );
828 for ( uTruth = 0; uTruth < (unsigned)nFuncs; uTruth++ )
831 if ( uCanons[uTruth] )
833 assert( uTruth > uCanons[uTruth] );
837 for ( i = 0; i < 16; i++ )
840 if ( uCanons[uPhase] == 0 && (uTruth || i==0) )
842 uCanons[uPhase] = uTruth;
843 uPhases[uPhase][0] = i;
844 pCounters[uPhase] = 1;
848 assert( uCanons[uPhase] == uTruth );
849 if ( pCounters[uPhase] < nPhasesMax )
850 uPhases[uPhase][ (int)pCounters[uPhase]++ ] = i;
863 *ppCounters = pCounters;
885 assert( nCols > 0 && nRows > 0 && Size > 0 );
886 pBuffer =
ABC_ALLOC(
char, nCols * (
sizeof(
void *) + nRows * Size) );
887 pRes = (
void **)pBuffer;
888 pRes[0] = pBuffer + nCols *
sizeof(
void *);
889 for ( i = 1; i < nCols; i++ )
890 pRes[i] = (
void *)((
char *)pRes[0] + i * nRows * Size);
908 static unsigned short Cases[16] = {
927 static int Perms[16][4] = {
947 assert( Phase >= 0 && Phase < 16 );
948 if ( Cases[Phase] == 0 )
950 if ( Cases[Phase] > 1 )
953 for ( i = 0; i < 16; i++ )
954 if ( uTruth & (1 << i) )
956 for ( iRes = 0, k = 0; k < 4; k++ )
957 if ( i & (1 << Perms[Phase][k]) )
959 uTruthRes |= (1 << iRes);
978 static unsigned Cases[32] = {
1013 static int Perms[32][5] = {
1049 assert( Phase >= 0 && Phase < 32 );
1050 if ( Cases[Phase] == 0 )
1052 if ( Cases[Phase] > 1 )
1053 return Cases[Phase];
1055 for ( i = 0; i < 32; i++ )
1056 if ( uTruth & (1 << i) )
1058 for ( iRes = 0, k = 0; k < 5; k++ )
1059 if ( i & (1 << Perms[Phase][k]) )
1061 uTruthRes |= (1 << iRes);
1080 static unsigned Cases[64] = {
1147 static int Perms[64][6] = {
1148 { 0, 0, 0, 0, 0, 0 },
1149 { 0, 0, 0, 0, 0, 0 },
1150 { 0, 0, 0, 0, 0, 0 },
1151 { 0, 0, 0, 0, 0, 0 },
1152 { 0, 0, 0, 0, 0, 0 },
1153 { 0, 2, 1, 3, 4, 5 },
1154 { 2, 0, 1, 3, 4, 5 },
1155 { 0, 0, 0, 0, 0, 0 },
1156 { 0, 0, 0, 0, 0, 0 },
1157 { 0, 2, 3, 1, 4, 5 },
1158 { 2, 0, 3, 1, 4, 5 },
1159 { 0, 1, 3, 2, 4, 5 },
1160 { 2, 3, 0, 1, 4, 5 },
1161 { 0, 3, 1, 2, 4, 5 },
1162 { 3, 0, 1, 2, 4, 5 },
1163 { 0, 0, 0, 0, 0, 0 },
1164 { 0, 0, 0, 0, 0, 0 },
1165 { 0, 4, 2, 3, 1, 5 },
1166 { 4, 0, 2, 3, 1, 5 },
1167 { 0, 1, 3, 4, 2, 5 },
1168 { 2, 3, 0, 4, 1, 5 },
1169 { 0, 3, 1, 4, 2, 5 },
1170 { 3, 0, 1, 4, 2, 5 },
1171 { 0, 1, 2, 4, 3, 5 },
1172 { 2, 3, 4, 0, 1, 5 },
1173 { 0, 3, 4, 1, 2, 5 },
1174 { 3, 0, 4, 1, 2, 5 },
1175 { 0, 1, 4, 2, 3, 5 },
1176 { 3, 4, 0, 1, 2, 5 },
1177 { 0, 4, 1, 2, 3, 5 },
1178 { 4, 0, 1, 2, 3, 5 },
1179 { 0, 0, 0, 0, 0, 0 },
1180 { 0, 0, 0, 0, 0, 0 },
1181 { 0, 2, 3, 4, 5, 1 },
1182 { 2, 0, 3, 4, 5, 1 },
1183 { 0, 1, 3, 4, 5, 2 },
1184 { 2, 3, 0, 4, 5, 1 },
1185 { 0, 3, 1, 4, 5, 2 },
1186 { 3, 0, 1, 4, 5, 2 },
1187 { 0, 1, 2, 4, 5, 3 },
1188 { 2, 3, 4, 0, 5, 1 },
1189 { 0, 3, 4, 1, 5, 2 },
1190 { 3, 0, 4, 1, 5, 2 },
1191 { 0, 1, 4, 2, 5, 3 },
1192 { 3, 4, 0, 1, 5, 2 },
1193 { 0, 4, 1, 2, 5, 3 },
1194 { 4, 0, 1, 2, 5, 3 },
1195 { 0, 1, 2, 3, 5, 4 },
1196 { 2, 3, 4, 5, 0, 1 },
1197 { 0, 3, 4, 5, 1, 2 },
1198 { 3, 0, 4, 5, 1, 2 },
1199 { 0, 1, 4, 5, 2, 3 },
1200 { 3, 4, 0, 5, 1, 2 },
1201 { 0, 4, 1, 5, 2, 3 },
1202 { 4, 0, 1, 5, 2, 3 },
1203 { 0, 1, 2, 5, 3, 4 },
1204 { 3, 4, 5, 0, 1, 2 },
1205 { 0, 4, 5, 1, 2, 3 },
1206 { 4, 0, 5, 1, 2, 3 },
1207 { 0, 1, 5, 2, 3, 4 },
1208 { 4, 5, 0, 1, 2, 3 },
1209 { 0, 5, 1, 2, 3, 4 },
1210 { 5, 0, 1, 2, 3, 4 },
1211 { 0, 0, 0, 0, 0, 0 }
1214 assert( Phase >= 0 && Phase < 64 );
1215 if ( Cases[Phase] == 0 )
1217 uTruthRes[0] = uTruth[0];
1218 uTruthRes[1] = uTruth[1];
1221 if ( Cases[Phase] > 1 )
1225 uTruthRes[0] = 0x00000000;
1226 uTruthRes[1] = 0xFFFFFFFF;
1230 uTruthRes[0] = Cases[Phase];
1231 uTruthRes[1] = Cases[Phase];
1237 for ( i = 0; i < 64; i++ )
1241 if ( uTruth[0] & (1 << i) )
1243 for ( iRes = 0, k = 0; k < 6; k++ )
1244 if ( i & (1 << Perms[Phase][k]) )
1247 uTruthRes[0] |= (1 << iRes);
1249 uTruthRes[1] |= (1 << (iRes-32));
1254 if ( uTruth[1] & (1 << (i-32)) )
1256 for ( iRes = 0, k = 0; k < 6; k++ )
1257 if ( i & (1 << Perms[Phase][k]) )
1260 uTruthRes[0] |= (1 << iRes);
1262 uTruthRes[1] |= (1 << (iRes-32));
1282 static unsigned uTruths[8][8] = {
1283 { 0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA },
1284 { 0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC },
1285 { 0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0 },
1286 { 0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00 },
1287 { 0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000 },
1288 { 0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF },
1289 { 0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF },
1290 { 0x00000000,0x00000000,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF }
1292 static char Cases[256] = {
1550 static char Perms[256][8] = {
1551 { 0, 1, 2, 3, 4, 5, 6, 7 },
1552 { 0, 1, 2, 3, 4, 5, 6, 7 },
1553 { 1, 0, 2, 3, 4, 5, 6, 7 },
1554 { 0, 1, 2, 3, 4, 5, 6, 7 },
1555 { 1, 2, 0, 3, 4, 5, 6, 7 },
1556 { 0, 2, 1, 3, 4, 5, 6, 7 },
1557 { 2, 0, 1, 3, 4, 5, 6, 7 },
1558 { 0, 1, 2, 3, 4, 5, 6, 7 },
1559 { 1, 2, 3, 0, 4, 5, 6, 7 },
1560 { 0, 2, 3, 1, 4, 5, 6, 7 },
1561 { 2, 0, 3, 1, 4, 5, 6, 7 },
1562 { 0, 1, 3, 2, 4, 5, 6, 7 },
1563 { 2, 3, 0, 1, 4, 5, 6, 7 },
1564 { 0, 3, 1, 2, 4, 5, 6, 7 },
1565 { 3, 0, 1, 2, 4, 5, 6, 7 },
1566 { 0, 1, 2, 3, 4, 5, 6, 7 },
1567 { 1, 2, 3, 4, 0, 5, 6, 7 },
1568 { 0, 2, 3, 4, 1, 5, 6, 7 },
1569 { 2, 0, 3, 4, 1, 5, 6, 7 },
1570 { 0, 1, 3, 4, 2, 5, 6, 7 },
1571 { 2, 3, 0, 4, 1, 5, 6, 7 },
1572 { 0, 3, 1, 4, 2, 5, 6, 7 },
1573 { 3, 0, 1, 4, 2, 5, 6, 7 },
1574 { 0, 1, 2, 4, 3, 5, 6, 7 },
1575 { 2, 3, 4, 0, 1,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 },
1644 { 0, 5, 1, 2, 3, 6, 4, 7 },
1645 { 5, 0, 1, 2, 3, 6, 4, 7 },
1646 { 0, 1, 2, 3, 4, 6, 5, 7 },
1647 { 2, 3, 4, 5, 6, 0, 1, 7 },
1648 { 0, 3, 4, 5, 6, 1, 2, 7 },
1649 { 3, 0, 4, 5, 6, 1, 2, 7 },
1650 { 0, 1, 4, 5, 6, 2, 3, 7 },
1651 { 3, 4, 0, 5, 6, 1, 2, 7 },
1652 { 0, 4, 1, 5, 6, 2, 3, 7 },
1653 { 4, 0, 1, 5, 6, 2, 3, 7 },
1654 { 0, 1, 2, 5, 6, 3, 4, 7 },
1655 { 3, 4, 5, 0, 6, 1, 2, 7 },
1656 { 0, 4, 5, 1, 6, 2, 3, 7 },
1657 { 4, 0, 5, 1, 6, 2, 3, 7 },
1658 { 0, 1, 5, 2, 6, 3, 4, 7 },
1659 { 4, 5, 0, 1, 6, 2, 3, 7 },
1660 { 0, 5, 1, 2, 6, 3, 4, 7 },
1661 { 5, 0, 1, 2, 6, 3, 4, 7 },
1662 { 0, 1, 2, 3, 6, 4, 5, 7 },
1663 { 3, 4, 5, 6, 0, 1, 2, 7 },
1664 { 0, 4, 5, 6, 1, 2, 3, 7 },
1665 { 4, 0, 5, 6, 1, 2, 3, 7 },
1666 { 0, 1, 5, 6, 2, 3, 4, 7 },
1667 { 4, 5, 0, 6, 1, 2, 3, 7 },
1668 { 0, 5, 1, 6, 2, 3, 4, 7 },
1669 { 5, 0, 1, 6, 2, 3, 4, 7 },
1670 { 0, 1, 2, 6, 3, 4, 5, 7 },
1671 { 4, 5, 6, 0, 1, 2, 3, 7 },
1672 { 0, 5, 6, 1, 2, 3, 4, 7 },
1673 { 5, 0, 6, 1, 2, 3, 4, 7 },
1674 { 0, 1, 6, 2, 3, 4, 5, 7 },
1675 { 5, 6, 0, 1, 2, 3, 4, 7 },
1676 { 0, 6, 1, 2, 3, 4, 5, 7 },
1677 { 6, 0, 1, 2, 3, 4, 5, 7 },
1678 { 0, 1, 2, 3, 4, 5, 6, 7 },
1679 { 1, 2, 3, 4, 5, 6, 7, 0 },
1680 { 0, 2, 3, 4, 5, 6, 7, 1 },
1681 { 2, 0, 3, 4, 5, 6, 7, 1 },
1682 { 0, 1, 3, 4, 5, 6, 7, 2 },
1683 { 2, 3, 0, 4, 5, 6, 7, 1 },
1684 { 0, 3, 1, 4, 5, 6, 7, 2 },
1685 { 3, 0, 1, 4, 5, 6, 7, 2 },
1686 { 0, 1, 2, 4, 5, 6, 7, 3 },
1687 { 2, 3, 4, 0, 5, 6, 7, 1 },
1688 { 0, 3, 4, 1, 5, 6, 7, 2 },
1689 { 3, 0, 4, 1, 5, 6, 7, 2 },
1690 { 0, 1, 4, 2, 5, 6, 7, 3 },
1691 { 3, 4, 0, 1, 5, 6, 7, 2 },
1692 { 0, 4, 1, 2, 5, 6, 7, 3 },
1693 { 4, 0, 1, 2, 5, 6, 7, 3 },
1694 { 0, 1, 2, 3, 5, 6, 7, 4 },
1695 { 2, 3, 4, 5, 0, 6, 7, 1 },
1696 { 0, 3, 4, 5, 1, 6, 7, 2 },
1697 { 3, 0, 4, 5, 1, 6, 7, 2 },
1698 { 0, 1, 4, 5, 2, 6, 7, 3 },
1699 { 3, 4, 0, 5, 1, 6, 7, 2 },
1700 { 0, 4, 1, 5, 2, 6, 7, 3 },
1701 { 4, 0, 1, 5, 2, 6, 7, 3 },
1702 { 0, 1, 2, 5, 3, 6, 7, 4 },
1703 { 3, 4, 5, 0, 1, 6, 7, 2 },
1704 { 0, 4, 5, 1, 2, 6, 7, 3 },
1705 { 4, 0, 5, 1, 2, 6, 7, 3 },
1706 { 0, 1, 5, 2, 3, 6, 7, 4 },
1707 { 4, 5, 0, 1, 2, 6, 7, 3 },
1708 { 0, 5, 1, 2, 3, 6, 7, 4 },
1709 { 5, 0, 1, 2, 3, 6, 7, 4 },
1710 { 0, 1, 2, 3, 4, 6, 7, 5 },
1711 { 2, 3, 4, 5, 6, 0, 7, 1 },
1712 { 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 6, 7, 2, 3, 4 },
1781 { 5, 0, 1, 6, 7, 2, 3, 4 },
1782 { 0, 1, 2, 6, 7, 3, 4, 5 },
1783 { 4, 5, 6, 0, 7, 1, 2, 3 },
1784 { 0, 5, 6, 1, 7, 2, 3, 4 },
1785 { 5, 0, 6, 1, 7, 2, 3, 4 },
1786 { 0, 1, 6, 2, 7, 3, 4, 5 },
1787 { 5, 6, 0, 1, 7, 2, 3, 4 },
1788 { 0, 6, 1, 2, 7, 3, 4, 5 },
1789 { 6, 0, 1, 2, 7, 3, 4, 5 },
1790 { 0, 1, 2, 3, 7, 4, 5, 6 },
1791 { 4, 5, 6, 7, 0, 1, 2, 3 },
1792 { 0, 5, 6, 7, 1, 2, 3, 4 },
1793 { 5, 0, 6, 7, 1, 2, 3, 4 },
1794 { 0, 1, 6, 7, 2, 3, 4, 5 },
1795 { 5, 6, 0, 7, 1, 2, 3, 4 },
1796 { 0, 6, 1, 7, 2, 3, 4, 5 },
1797 { 6, 0, 1, 7, 2, 3, 4, 5 },
1798 { 0, 1, 2, 7, 3, 4, 5, 6 },
1799 { 5, 6, 7, 0, 1, 2, 3, 4 },
1800 { 0, 6, 7, 1, 2, 3, 4, 5 },
1801 { 6, 0, 7, 1, 2, 3, 4, 5 },
1802 { 0, 1, 7, 2, 3, 4, 5, 6 },
1803 { 6, 7, 0, 1, 2, 3, 4, 5 },
1804 { 0, 7, 1, 2, 3, 4, 5, 6 },
1805 { 7, 0, 1, 2, 3, 4, 5, 6 },
1806 { 0, 1, 2, 3, 4, 5, 6, 7 }
1809 assert( uPhase > 0 && uPhase < (
unsigned)(1 << nVars) );
1812 if ( Cases[uPhase] == 0 )
1815 for ( i = 0; i <
nWords; i++ )
1816 puTruthR[i] = puTruth[i];
1821 if ( Cases[uPhase] > 0 )
1824 for ( i = 0; i <
nWords; i++ )
1825 puTruthR[i] = uTruths[(
int)Cases[uPhase]][i];
1832 int i, k, nMints, iRes;
1833 char *
pPerm = Perms[uPhase];
1835 nMints = (1 << nVars);
1836 for ( i = 0; i < nMints; i++ )
1837 if ( puTruth[0] & (1 << i) )
1839 for ( iRes = 0, k = 0; k < nVars; k++ )
1840 if ( i & (1 << pPerm[k]) )
1842 puTruthR[0] |= (1 << iRes);
1846 else if ( nWords == 2 )
1849 char *
pPerm = Perms[uPhase];
1850 puTruthR[0] = puTruthR[1] = 0;
1851 for ( i = 0; i < 32; i++ )
1853 if ( puTruth[0] & (1 << i) )
1855 for ( iRes = 0, k = 0; k < 6; k++ )
1856 if ( i & (1 << pPerm[k]) )
1859 puTruthR[0] |= (1 << iRes);
1861 puTruthR[1] |= (1 << (iRes-32));
1864 for ( ; i < 64; i++ )
1866 if ( puTruth[1] & (1 << (i-32)) )
1868 for ( iRes = 0, k = 0; k < 6; k++ )
1869 if ( i & (1 << pPerm[k]) )
1872 puTruthR[0] |= (1 << iRes);
1874 puTruthR[1] |= (1 << (iRes-32));
1881 int i, k, nMints, iRes;
1882 char *
pPerm = Perms[uPhase];
1883 for ( i = 0; i <
nWords; i++ )
1885 nMints = (1 << nVars);
1886 for ( i = 0; i < nMints; i++ )
1887 if ( puTruth[i>>5] & (1 << (i&31)) )
1889 for ( iRes = 0, k = 0; k < 5; k++ )
1890 if ( i & (1 << pPerm[k]) )
1892 puTruthR[iRes>>5] |= (1 << (iRes&31));
1910 unsigned short ** pTable;
1914 for ( i = 0; i < 256; i++ )
1916 uTruth = (i << 8) | i;
1917 for ( k = 0; k < 16; k++ )
1940 for ( i = 0; i < 256; i++ )
1942 uTruth = (i << 24) | (i << 16) | (i << 8) | i;
1943 for ( k = 0; k < 32; k++ )
1966 for ( i = 0; i < 256*256; i++ )
1968 uTruth = (i << 16) | i;
1994 for ( i = 0; i < 256; i++ )
1996 uTruth[0] = (i << 24) | (i << 16) | (i << 8) | i;
1997 uTruth[1] = uTruth[0];
1998 for ( k = 0; k < 64; k++ )
2017 static unsigned uTruths[8][8] = {
2018 { 0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA },
2019 { 0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC },
2020 { 0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0 },
2021 { 0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00 },
2022 { 0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000 },
2023 { 0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF },
2024 { 0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF },
2025 { 0x00000000,0x00000000,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF }
2027 static unsigned * puResult[8] = {
2028 uTruths[0], uTruths[1], uTruths[2], uTruths[3], uTruths[4], uTruths[5], uTruths[6], uTruths[7]
2030 return (
unsigned **)puResult;
2046 int i, Temp, fChanges;
2048 for ( i = 0; i < nSize; i++ )
2054 for ( i = 0; i < nSize - 1; i++ )
2056 if ( Costs[Order[i]] <= Costs[Order[i+1]] )
2059 Order[i] = Order[i+1];
2063 }
while ( fChanges );
2069 for ( i = 0; i < nSize - 1; i++ )
2071 if ( Costs[Order[i]] >= Costs[Order[i+1]] )
2074 Order[i] = Order[i+1];
2078 }
while ( fChanges );
2105 int i, k, nOnes, Last1, First0;
2108 printf(
"\nstatic char Cases[256] = {\n" );
2109 for ( i = 0; i < 256; i++ )
2112 Last1 = First0 = -1;
2113 for ( k = 0; k < 8; k++ )
2120 else if ( First0 == -1 )
2123 if ( Last1 + 1 == First0 || i == 255 )
2124 printf(
" %d%s", 0, (i==255?
" ":
",") );
2125 else if ( nOnes == 1 )
2126 printf(
" %d,", Last1 );
2128 printf(
" -%d,", 1 );
2135 printf(
"\nstatic char Perms[256][8] = {\n" );
2136 for ( i = 0; i < 256; i++ )
2140 for ( k = 0; k < 8; k++ )
2145 for ( k = 0; k < 8; k++ )
2147 printf(
"%s %d", (k==0?
"":
","), iOne++ );
2149 printf(
"%s %d", (k==0?
"":
","), iZero++ );
2150 assert( iOne + iZero == 8 );
2151 printf(
" }%s // ", (i==255?
" ":
",") );
2174 for ( k = 0; k < n; k++ )
2175 for ( pRes[b++] = k, i = 1; i < (1<<k); i++ )
2176 pRes[b++] = pRes[i-1];
2183 for ( b = 0; b < (1<<n); b++ )
2185 uSign ^= (1 << pRes[b]);
2186 printf(
"%3d %3d ", b, pRes[b] );
2208 int nGroups = nFact / n / 2;
2210 int * pRes0, i, k, b = 0;
2214 pRes[0] = pRes[1] = 0;
2218 for ( k = 0; k < nGroups; k++ )
2220 for ( i = n-1; i > 0; i-- )
2222 pRes[b++] = pRes0[2*k]+1;
2223 for ( i = 0; i < n-1; i++ )
2225 pRes[b++] = pRes0[2*k+1];
2233 for ( i = 0; i < n; i++ )
2235 for ( b = 0; b < nFact; b++ )
2237 ABC_SWAP(
int, Perm[pRes[b]], Perm[pRes[b]+1] );
2238 printf(
"%3d %3d ", b, pRes[b] );
2239 for ( i = 0; i < n; i++ )
2240 printf(
"%d", Perm[i] );
2270 return (t & PMasks[v][0]) | ((t & PMasks[v][1]) << (1 << v)) | ((t & PMasks[v][2]) >> (1 << v));
2284 return ((t & ~Truth6[v]) << (1 << v)) | ((t & Truth6[v]) >> (1 << v));
2289 word tCur, tTemp1, tTemp2;
2291 for ( i = 0; i < 2; i++ )
2295 for ( p = 0; p < 720; p++ )
2300 for ( c = 0; c < 64; c++ )
2305 assert( tTemp2 == tCur );
2308 assert( tTemp1 == tCur );
2331 return (t &
ABC_CONST(0x00000000FFFFFFFF)) + (t>>32);
2335 word tCur, tMin = t;
2336 assert( v >= 0 && v < 5 );
2359 int i, k, Limit = 10;
2360 word tCur, tMin = t;
2361 for ( i = 0; i < Limit; i++ )
2364 for ( k = 4; k >= 0; k-- )
2369 if ( tMin0 == tMin )
2412 pFile = fopen( pFileName,
"rb" );
2413 while ( fgets( pBuffer, 100, pFile ) )
2414 Extra_ReadHex( (
unsigned *)(pFuncs + i++), (pBuffer[1] ==
'x' ? pBuffer+2 : pBuffer), 16 );
2417 for ( i = 0; i <
Abc_MinInt(nFuncs, 10); i++ )
2419 printf(
"Line %d : ", i );
2420 Extra_PrintHex( stdout, (
unsigned *)(pFuncs + i), 6 ), printf(
"\n" );
2440 if ( Word1 < Word2 )
2442 if ( Word1 > Word2 )
2467 int * pComp, *
pPerm;
2485 int * pComp, *
pPerm;
2502 pFuncs =
Extra_NpnRead(
"C:\\_projects\\abc\\_TEST\\allan\\test.txt", nFuncs );
2506 for ( i = 0; i < nFuncs; i++ )
2509 if ( i % 10000 == 0 )
2510 printf(
"%d\n", i );
2512 printf(
"Finished deriving minimum form\n" );
2523 for ( i = 0; i <
Abc_MinInt(nFuncs, 10); i++ )
2525 printf(
"Line %d : ", i );
2526 Extra_PrintHex( stdout, (
unsigned *)(pFuncs + i), 6 ), printf(
"\n" );
static word Abc_MinWord(word a, word b)
#define ABC_ALLOC(type, num)
static abctime Abc_Clock()
static int bit_count[256]
#define ABC_SWAP(Type, a, b)
static void Abc_PrintTime(int level, const char *pStr, abctime time)
static int Abc_MinInt(int a, int b)
unsigned __int64 word
DECLARATIONS ///.
#define ABC_NAMESPACE_IMPL_END
#define ABC_NAMESPACE_IMPL_START
static ABC_NAMESPACE_IMPL_START word Truth[8]
DECLARATIONS ///.
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
#define ABC_CONST(number)
PARAMETERS ///.
#define ABC_CALLOC(type, num)