31 void swapAndFlip(
word* pAfter,
int nVars,
int iVarInPosition,
int jVar,
char * pCanonPerm,
unsigned* pUCanonPhase)
34 swap_ij(pAfter, nVars, iVarInPosition, jVar);
36 Temp = pCanonPerm[iVarInPosition];
37 pCanonPerm[iVarInPosition] = pCanonPerm[jVar];
38 pCanonPerm[jVar] = Temp;
40 if ( ((*pUCanonPhase & (1 << iVarInPosition)) > 0) != ((*pUCanonPhase & (1 << jVar)) > 0) )
42 *pUCanonPhase ^= (1 << iVarInPosition);
43 *pUCanonPhase ^= (1 << jVar);
45 if((*pUCanonPhase>>iVarInPosition) & 1)
58 if(tempChar != pCanonPerm[i])
60 swapAndFlip(pAfter , nVars, j, i, pCanonPerm, &uCanonPhase);
64 if((uCanonPhase>>nVars) & 1)
76 void updataInfo(
int iQ,
int jQ,
int iVar,
char * pCanonPerm,
unsigned* pCanonPhase)
78 *pCanonPhase =
adjustInfoAfterSwap(pCanonPerm, *pCanonPhase, iVar, ((abs(iQ-jQ)-1)<<2) + iQ );
87 if(blockSize == 16){
return 0;}
88 if (x >=
ABC_CONST(0x0000000100000000)) {n = n + 32; x = x >> 32;}
89 if(blockSize == 8){
return (64-n)/32;}
90 if (x >=
ABC_CONST(0x0000000000010000)) {n = n + 16; x = x >> 16;}
91 if(blockSize == 4){
return (64-n)/16;}
92 if (x >=
ABC_CONST(0x0000000000000100)) {n = n + 8; x = x >> 8;}
93 if(blockSize == 2){
return (64-n)/8;}
94 if (x >=
ABC_CONST(0x0000000000000010)) {n = n + 4; x = x >> 4;}
103 int i, blockSize = 1<<iVar;
106 for(i=start;i>=0;i--)
108 assert( iQ*blockSize < 64 );
109 assert( jQ*blockSize < 64 );
110 assert( kQ*blockSize < 64 );
111 assert( lQ*blockSize < 64 );
112 assert( 3*blockSize < 64 );
113 pInOut[i] = (pInOut[i] &
SFmask[iVar][iQ])<<(iQ*blockSize) |
114 (((pInOut[i] &
SFmask[iVar][jQ])<<(jQ*blockSize))>>blockSize) |
115 (((pInOut[i] &
SFmask[iVar][kQ])<<(kQ*blockSize))>>2*blockSize) |
116 (((pInOut[i] &
SFmask[iVar][lQ])<<(lQ*blockSize))>>3*blockSize);
118 updataInfo(iQ, jQ, iVar, pCanonPerm, pCanonPhase);
133 int i, blockSize = 1<<iVar;
135 for(i=nWords - 1; i>=0; i--)
137 assert( 3*blockSize < 64 );
138 temp = ((pInOut[i] &
SFmask[iVar][0])) ^ ((pInOut[i] &
SFmask[iVar][3])<<(3*blockSize));
144 if( ((pInOut[i] &
SFmask[iVar][0])) < ((pInOut[i] &
SFmask[iVar][3])<<(3*blockSize)) )
159 int i, blockSize = 1<<iVar;
161 for(i=nWords - 1; i>=0; i--)
163 assert( 2*blockSize < 64 );
164 temp = ((pInOut[i] &
SFmask[iVar][1])<<(blockSize)) ^ ((pInOut[i] &
SFmask[iVar][2])<<(2*blockSize));
170 if( ((pInOut[i] &
SFmask[iVar][1])<<(blockSize)) < ((pInOut[i] &
SFmask[iVar][2])<<(2*blockSize)) )
184 int i, blockSize = 1<<iVar;
186 for(i=nWords - 1; i>=0; i--)
188 assert( jQ*blockSize < 64 );
189 temp = ((pInOut[i] &
SFmask[iVar][iQ])<<(iQ*blockSize)) ^ ((pInOut[i] &
SFmask[iVar][jQ])<<(jQ*blockSize));
195 if( ((pInOut[i] &
SFmask[iVar][iQ])<<(iQ*blockSize)) <= ((pInOut[i] &
SFmask[iVar][jQ])<<(jQ*blockSize)) )
205 int minTemp3_fast(
word* pInOut,
int iVar,
int start,
int finish,
int iQ,
int jQ,
int* pDifStart)
207 int i, blockSize = 1<<iVar;
209 for(i=start; i>=finish; i--)
211 assert( jQ*blockSize < 64 );
212 temp = ((pInOut[i] &
SFmask[iVar][iQ])<<(iQ*blockSize)) ^ ((pInOut[i] &
SFmask[iVar][jQ])<<(jQ*blockSize));
218 if( ((pInOut[i] &
SFmask[iVar][iQ])<<(iQ*blockSize)) <= ((pInOut[i] &
SFmask[iVar][jQ])<<(jQ*blockSize)) )
231 int min1, min2, DifStart0, DifStart1, DifStartMin, DifStart4=0;
235 min1 =
minTemp2_fast(pInOut, iVar, M[0], M[1], nWords, &DifStartMin);
238 if(DifStart0 != DifStart1)
241 if( DifStartMin>=DifStart1 && DifStartMin>=DifStart0 )
243 else if( DifStart0 > DifStart1)
244 arrangeQuoters_superFast_lessThen5(pInOut,
luckyMax(DifStartMin/100, DifStart0/100), M[0], M[1], 3 - M[1], 3 - M[0], iVar, nWords, pCanonPerm, pCanonPhase);
246 arrangeQuoters_superFast_lessThen5(pInOut,
luckyMax(DifStartMin/100, DifStart1/100), M[1], M[0], 3 - M[0], 3 - M[1], iVar, nWords, pCanonPerm, pCanonPhase);
251 if(DifStartMin>=DifStart0)
255 min2 =
minTemp3_fast(pInOut, iVar, DifStart0/100, DifStartMin/100, 3-M[0], 3-M[1], &DifStart4);
257 if(DifStart4>DifStartMin)
277 int i,blockSize,shiftSize;
278 unsigned* tempPtr = temp+start;
281 if(iQ == 0 && jQ == 1)
283 blockSize =
sizeof(unsigned);
285 for(i=start-1;i>0;i-=shiftSize)
288 memcpy(tempPtr, pInOut+i-iQ, blockSize);
290 memcpy(tempPtr, pInOut+i-jQ, blockSize);
292 memcpy(tempPtr, pInOut+i-kQ, blockSize);
294 memcpy(tempPtr, pInOut+i-lQ, blockSize);
296 memcpy(pInOut, temp, start*
sizeof(
unsigned));
297 updataInfo(iQ, jQ, 5, pCanonPerm, pCanonPhase);
306 for(i=(nWords)*2 - 1; i>=0; i-=4)
332 for(i=(nWords)*2 - 2; i>=0; i-=4)
359 for(i=(nWords)*2 - 1; i>=0; i-=4)
385 for(i=start-1; i>=finish; i-=4)
408 int min1, min2, DifStart0, DifStart1, DifStartMin;
415 if(DifStart0 != DifStart1)
417 if( DifStartMin>=DifStart1 && DifStartMin>=DifStart0 )
419 else if( DifStart0 > DifStart1)
426 if(DifStartMin>=DifStart0)
431 if(DifStart1>DifStartMin)
453 int i,wordBlock,blockSize,shiftSize;
454 word* tempPtr = temp+start;
457 if(iQ == 0 && jQ == 1)
459 wordBlock = (1<<(iVar-6));
460 blockSize = wordBlock*
sizeof(
word);
461 shiftSize = wordBlock*4;
462 for(i=start-wordBlock;i>0;i-=shiftSize)
464 tempPtr -= wordBlock;
465 memcpy(tempPtr, pInOut+i-iQ*wordBlock, blockSize);
466 tempPtr -= wordBlock;
467 memcpy(tempPtr, pInOut+i-jQ*wordBlock, blockSize);
468 tempPtr -= wordBlock;
469 memcpy(tempPtr, pInOut+i-kQ*wordBlock, blockSize);
470 tempPtr -= wordBlock;
471 memcpy(tempPtr, pInOut+i-lQ*wordBlock, blockSize);
474 updataInfo(iQ, jQ, iVar, pCanonPerm, pCanonPhase);
484 int wordBlock = 1<<(iVar-6);
485 int wordDif = 3*wordBlock;
486 int shiftBlock = wordBlock*4;
489 for(i=nWords - 1; i>=0; i-=shiftBlock)
490 for(j=0;j<wordBlock;j++)
517 int wordBlock = 1<<(iVar-6);
518 int shiftBlock = wordBlock*4;
521 for(i=nWords - wordBlock - 1; i>=0; i-=shiftBlock)
522 for(j=0;j<wordBlock;j++)
529 *pDifStart = i+wordBlock+1;
534 *pDifStart = i+wordBlock+1;
549 int wordBlock = 1<<(iVar-6);
550 int shiftBlock = wordBlock*4;
553 for(i=nWords - 1; i>=0; i-=shiftBlock)
554 for(j=0;j<wordBlock;j++)
556 temp =
CompareWords(pInOut[i-j-iQ*wordBlock],pInOut[i-j-jQ*wordBlock]);
580 int wordBlock = 1<<(iVar-6);
581 int shiftBlock = wordBlock*4;
584 for(i=start-1; i>=finish; i-=shiftBlock)
585 for(j=0;j<wordBlock;j++)
587 temp =
CompareWords(pInOut[i-j-iQ*wordBlock],pInOut[i-j-jQ*wordBlock]);
610 int min1, min2, DifStart0, DifStart1, DifStartMin;
617 if(DifStart0 != DifStart1)
619 if( DifStartMin>=DifStart1 && DifStartMin>=DifStart0 )
621 else if( DifStart0 > DifStart1)
622 arrangeQuoters_superFast_moreThen5(pInOut, temp,
luckyMax(DifStartMin,DifStart0), M[0], M[1], 3 - M[1], 3 - M[0], iVar, pCanonPerm, pCanonPhase);
624 arrangeQuoters_superFast_moreThen5(pInOut, temp,
luckyMax(DifStartMin,DifStart1), M[1], M[0], 3 - M[0], 3 - M[1], iVar, pCanonPerm, pCanonPhase);
628 if(DifStartMin>=DifStart0)
633 if(DifStart1>DifStartMin)
658 (* pCanonPhase) ^=(1<<nVars);
668 word pDuplicate[1024];
669 int bitInfoTemp = pStore[0];
670 memcpy(pDuplicate,pInOut,nWords*
sizeof(
word));
674 if(bitInfoTemp == pStore[i+1])
678 bitInfoTemp = pStore[i+1];
682 if(bitInfoTemp == pStore[i+1])
685 bitInfoTemp = pStore[i+1];
687 for(i=6;i<nVars-1;i++)
689 if(bitInfoTemp == pStore[i+1])
693 bitInfoTemp = pStore[i+1];
699 if(
memcmp(pInOut,pDuplicate , nWords*
sizeof(
word)) == 0)
708 word pDuplicate[1024];
709 int bitInfoTemp = pStore[0];
710 memcpy(pDuplicate,pInOut,nWords*
sizeof(
word));
713 if(bitInfoTemp == pStore[i+1])
717 bitInfoTemp = pStore[i+1];
721 if(bitInfoTemp == pStore[i+1])
724 bitInfoTemp = pStore[i+1];
726 for(i=6;i<nVars-1;i++)
728 if(bitInfoTemp == pStore[i+1])
732 bitInfoTemp = pStore[i+1];
736 if(
memcmp(pInOut,pDuplicate , nWords*
sizeof(
word)) == 0)
752 if(((* pCanonPhase) >> (nVars+1)) & 1)
762 word duplicate[1024];
763 char pCanonPerm1[16];
764 unsigned uCanonPhase1;
766 if((* pCanonPhase) >> (nVars+2) )
768 memcpy(duplicate, pInOut,
sizeof(
word)*nWords);
770 uCanonPhase1 = *pCanonPhase;
771 uCanonPhase1 ^= (1 << nVars);
772 memcpy(pCanonPerm1,pCanonPerm,
sizeof(
char)*16);
777 *pCanonPhase = uCanonPhase1;
778 memcpy(pCanonPerm,pCanonPerm1,
sizeof(
char)*16);
779 memcpy(pInOut, duplicate,
sizeof(
word)*nWords);
790 assert( nVars > 6 && nVars <= 16 );
798 for(i= nVars-1;i>=0;i--)
805 assert( nVars > 6 && nVars <= 16 );
809 (*pCanonPhase) ^= (1<<nVars) -1;
822 unsigned uCanonPhase = 0;
824 word temp[1024] = {0};
825 word duplicate[1024] = {0};
830 else if ( nVars <= 16 )
832 nWords = (nVars <= 6) ? 1 : (1 << (nVars - 6));
847 unsigned uCanonPhase = 0;
849 word temp[1024] = {0};
850 word duplicate[1024] = {0};
855 else if ( nVars <= 16 )
857 nWords = 1 << (nVars - 6);
int minimalSwapAndFlipIVar_superFast_all(word *pInOut, int nVars, int nWords, int *pStore, char *pCanonPerm, unsigned *pCanonPhase)
int minTemp3_fast_iVar5(unsigned *pInOut, int start, int finish, int iQ, int jQ, int *pDifStart)
void Kit_TruthCopy_64bit(word *pOut, word *pIn, int nVars)
void luckyCanonicizerS_F_first_16Vars1(word *pInOut, int nVars, int nWords, int *pStore, char *pCanonPerm, unsigned *pCanonPhase)
unsigned luckyCanonicizer_final_fast(word *pInOut, int nVars, char *pCanonPerm)
void swapAndFlip(word *pAfter, int nVars, int iVarInPosition, int jVar, char *pCanonPerm, unsigned *pUCanonPhase)
static ABC_NAMESPACE_IMPL_START word SFmask[5][4]
void luckyCanonicizer_final_fast_16Vars(word *pInOut, int nVars, int nWords, int *pStore, char *pCanonPerm, unsigned *pCanonPhase)
void arrangeQuoters_superFast_lessThen5(word *pInOut, int start, int iQ, int jQ, int kQ, int lQ, int iVar, int nWords, char *pCanonPerm, unsigned *pCanonPhase)
int Kit_TruthWordNum_64bit(int nVars)
word luckyCanonicizer_final_fast_6Vars1(word InOut, int *pStore, char *pCanonPerm, unsigned *pCanonPhase)
void luckyCanonicizerS_F_first_16Vars11(word *pInOut, int nVars, int nWords, int *pStore, char *pCanonPerm, unsigned *pCanonPhase)
int minTemp2_fast_moreThen5(word *pInOut, int iVar, int iQ, int jQ, int nWords, int *pDifStart)
word M(word f1, word f2, int n)
void arrangeQuoters_superFast_moreThen5(word *pInOut, word *temp, int start, int iQ, int jQ, int kQ, int lQ, int iVar, char *pCanonPerm, unsigned *pCanonPhase)
void minimalSwapAndFlipIVar_superFast_lessThen5_noEBFC(word *pInOut, int iVar, int nWords, char *pCanonPerm, unsigned *pCanonPhase)
void swap_ij(word *f, int totalVars, int varI, int varJ)
int minTemp0_fast_moreThen5(word *pInOut, int iVar, int nWords, int *pDifStart)
int minTemp3_fast_moreThen5(word *pInOut, int iVar, int start, int finish, int iQ, int jQ, int *pDifStart)
void minimalSwapAndFlipIVar_superFast_iVar5(unsigned *pInOut, int nWords, char *pCanonPerm, unsigned *pCanonPhase)
int minTemp2_fast(word *pInOut, int iVar, int iQ, int jQ, int nWords, int *pDifStart)
unsigned adjustInfoAfterSwap(char *pCanonPerm, unsigned uCanonPhase, int iVar, unsigned info)
void minimalSwapAndFlipIVar_superFast_moreThen5(word *pInOut, int iVar, int nWords, char *pCanonPerm, unsigned *pCanonPhase)
unsigned __int64 word
DECLARATIONS ///.
void minimalSwapAndFlipIVar_superFast_moreThen5_noEBFC(word *pInOut, int iVar, int nWords, char *pCanonPerm, unsigned *pCanonPhase)
#define ABC_NAMESPACE_IMPL_END
void minimalSwapAndFlipIVar_superFast_lessThen5(word *pInOut, int iVar, int nWords, char *pCanonPerm, unsigned *pCanonPhase)
int luckyCheck(word *pAfter, word *pBefore, int nVars, char *pCanonPerm, unsigned uCanonPhase)
void bitReverceOrder(word *x, int nVars)
void minimalSwapAndFlipIVar_superFast_iVar5_noEBFC(unsigned *pInOut, int nWords, char *pCanonPerm, unsigned *pCanonPhase)
int minTemp1_fast_iVar5(unsigned *pInOut, int nWords, int *pDifStart)
int minTemp3_fast(word *pInOut, int iVar, int start, int finish, int iQ, int jQ, int *pDifStart)
void Kit_TruthNot_64bit(word *pIn, int nVars)
void updataInfo(int iQ, int jQ, int iVar, char *pCanonPerm, unsigned *pCanonPhase)
void arrangeQuoters_superFast_iVar5(unsigned *pInOut, unsigned *temp, int start, int iQ, int jQ, int kQ, int lQ, char *pCanonPerm, unsigned *pCanonPhase)
#define ABC_NAMESPACE_IMPL_START
unsigned Kit_TruthSemiCanonicize_Yasha1(word *pInOut, int nVars, char *pCanonPerm, int *pStore)
int minTemp1_fast(word *pInOut, int iVar, int nWords, int *pDifStart)
unsigned luckyCanonicizer_final_fast1(word *pInOut, int nVars, char *pCanonPerm)
void luckyCanonicizer_final_fast_16Vars1(word *pInOut, int nVars, int nWords, int *pStore, char *pCanonPerm, unsigned *pCanonPhase)
void minimalInitialFlip_fast_16Vars(word *pInOut, int nVars, unsigned *pCanonPhase)
#define ABC_CONST(number)
PARAMETERS ///.
int minTemp1_fast_moreThen5(word *pInOut, int iVar, int nWords, int *pDifStart)
int firstShiftWithOneBit(word x, int blockSize)
int minTemp0_fast(word *pInOut, int iVar, int nWords, int *pDifStart)
int minTemp0_fast_iVar5(unsigned *pInOut, int nWords, int *pDifStart)
int minTemp2_fast_iVar5(unsigned *pInOut, int iQ, int jQ, int nWords, int *pDifStart)
ABC_NAMESPACE_IMPL_START int memCompare(word *x, word *y, int nVars)
word luckyCanonicizer_final_fast_6Vars(word InOut, int *pStore, char *pCanonPerm, unsigned *pCanonPhase)
static int luckyMax(int x, int y)
void Kit_TruthChangePhase_64bit(word *pInOut, int nVars, int iVar)
int minimalSwapAndFlipIVar_superFast_all_noEBFC(word *pInOut, int nVars, int nWords, int *pStore, char *pCanonPerm, unsigned *pCanonPhase)