58         word Cof1 = (pTruth[0] >> (1 << iVar)) & s_Truths6Neg[iVar];
 
   60             return Cof0 < Cof1 ? -1 : 1;
 
   66         int w, shift = (1 << iVar);
 
   67         for ( w = 0; w < 
nWords; w++ )
 
   70             Cof1 = (pTruth[w] >> shift) & s_Truths6Neg[iVar];
 
   72                 return Cof0 < Cof1 ? -1 : 1;
 
   81         for ( ; pTruth < pLimit; pTruth += 2*iStep )
 
   82             for ( i = 0; i < iStep; i++ )
 
   83                 if ( pTruth[i] != pTruth[i + iStep] )
 
   84                     return pTruth[i] < pTruth[i + iStep] ? -1 : 1;
 
   93         word Cof1 = (pTruth[0] >> (1 << iVar)) & s_Truths6Neg[iVar];
 
   95             return Cof0 < Cof1 ? -1 : 1;
 
  101         int w, shift = (1 << iVar);
 
  102         for ( w = nWords - 1; w >= 0; w-- )
 
  105             Cof1 = (pTruth[w] >> shift) & s_Truths6Neg[iVar];
 
  107                 return Cof0 < Cof1 ? -1 : 1;
 
  116         for ( pLimit -= 2*iStep; pLimit >= pTruth; pLimit -= 2*iStep )
 
  117             for ( i = iStep - 1; i >= 0; i-- )
 
  118                 if ( pLimit[i] != pLimit[i + iStep] )
 
  119                     return pLimit[i] < pLimit[i + iStep] ? -1 : 1;
 
  137     assert( Num1 < Num2 && Num2 < 4 );
 
  139         return ((pTruth[0] >> (Num2 * (1 << iVar))) & 
s_CMasks6[iVar]) == ((pTruth[0] >> (Num1 * (1 << iVar))) & 
s_CMasks6[iVar]);
 
  142         int w, shift = (1 << iVar);
 
  143         for ( w = 0; w < 
nWords; w++ )
 
  144             if ( ((pTruth[w] >> Num2 * shift) & 
s_CMasks6[iVar]) != ((pTruth[w] >> Num1 * shift) & 
s_CMasks6[iVar]) )
 
  150         unsigned * pTruthU = (
unsigned *)pTruth;
 
  151         unsigned * pLimitU = (
unsigned *)(pTruth + nWords);
 
  153         for ( ; pTruthU < pLimitU; pTruthU += 4 )
 
  154             if ( pTruthU[Num2] != pTruthU[Num1] )
 
  163         for ( ; pTruth < pLimit; pTruth += 4*iStep )
 
  164             for ( i = 0; i < iStep; i++ )
 
  165                 if ( pTruth[i+Num2*iStep] != pTruth[i+Num1*iStep] )
 
  184     assert( Num1 < Num2 && Num2 < 4 );
 
  187         word Cof1 = (pTruth[0] >> (Num1 * (1 << iVar))) & 
s_CMasks6[iVar];
 
  188         word Cof2 = (pTruth[0] >> (Num2 * (1 << iVar))) & 
s_CMasks6[iVar];
 
  190             return Cof1 < Cof2 ? -1 : 1;
 
  196         int w, shift = (1 << iVar);
 
  197         for ( w = 0; w < 
nWords; w++ )
 
  199             Cof1 = (pTruth[w] >> Num1 * shift) & 
s_CMasks6[iVar];
 
  200             Cof2 = (pTruth[w] >> Num2 * shift) & 
s_CMasks6[iVar];
 
  202                 return Cof1 < Cof2 ? -1 : 1;
 
  208         unsigned * pTruthU = (
unsigned *)pTruth;
 
  209         unsigned * pLimitU = (
unsigned *)(pTruth + nWords);
 
  211         for ( ; pTruthU < pLimitU; pTruthU += 4 )
 
  212             if ( pTruthU[Num1] != pTruthU[Num2] )
 
  213                 return pTruthU[Num1] < pTruthU[Num2] ? -1 : 1;
 
  220         int Offset1 = Num1*iStep;
 
  221         int Offset2 = Num2*iStep;
 
  223         for ( ; pTruth < pLimit; pTruth += 4*iStep )
 
  224             for ( i = 0; i < iStep; i++ )
 
  225                 if ( pTruth[i + Offset1] != pTruth[i + Offset2] )
 
  226                     return pTruth[i + Offset1] < pTruth[i + Offset2] ? -1 : 1;
 
  232     assert( Num1 < Num2 && Num2 < 4 );
 
  235         word Cof1 = (pTruth[0] >> (Num1 * (1 << iVar))) & 
s_CMasks6[iVar];
 
  236         word Cof2 = (pTruth[0] >> (Num2 * (1 << iVar))) & 
s_CMasks6[iVar];
 
  238             return Cof1 < Cof2 ? -1 : 1;
 
  244         int w, shift = (1 << iVar);
 
  245         for ( w = nWords - 1; w >= 0; w-- )
 
  247             Cof1 = (pTruth[w] >> Num1 * shift) & 
s_CMasks6[iVar];
 
  248             Cof2 = (pTruth[w] >> Num2 * shift) & 
s_CMasks6[iVar];
 
  250                 return Cof1 < Cof2 ? -1 : 1;
 
  256         unsigned * pTruthU = (
unsigned *)pTruth;
 
  257         unsigned * pLimitU = (
unsigned *)(pTruth + nWords);
 
  259         for ( pLimitU -= 4; pLimitU >= pTruthU; pLimitU -= 4 )
 
  260             if ( pLimitU[Num1] != pLimitU[Num2] )
 
  261                 return pLimitU[Num1] < pLimitU[Num2] ? -1 : 1;
 
  268         int Offset1 = Num1*iStep;
 
  269         int Offset2 = Num2*iStep;
 
  271         for ( pLimit -= 4*iStep; pLimit >= pTruth; pLimit -= 4*iStep )
 
  272             for ( i = iStep - 1; i >= 0; i-- )
 
  273                 if ( pLimit[i + Offset1] != pLimit[i + Offset2] )
 
  274                     return pLimit[i + Offset1] < pLimit[i + Offset2] ? -1 : 1;
 
  294     for ( k = 0; k < 
nWords; k++ )
 
  305         for ( i = 0; i < nVars; i++ )
 
  311     memset( pStore, 0, 
sizeof(
int) * nVars );
 
  312     for ( k = 0; k < 
nWords; k++ )
 
  315         for ( i = 0; i < 6; i++ )
 
  322             for ( i = 6; i < nVars; i++ )
 
  323                 if ( (k & (1 << (i-6))) == 0 )
 
  331             for ( i = 6; i < nVars; i++ )
 
  332                 if ( (k & (1 << (i-6))) == 0 )
 
  352       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,
 
  353       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,
 
  354       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,
 
  355       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,
 
  356       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,
 
  357       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,
 
  358       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,
 
  359       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
 
  362     unsigned char * pTruthC = (
unsigned char *)pTruth;
 
  364     memset( pStore, 0, 
sizeof(
int) * nVars );
 
  365     for ( k = 0; k < nBytes; k++ )
 
  367         pStore[0] += bit_count[ pTruthC[k] & 0x55 ];
 
  368         pStore[1] += bit_count[ pTruthC[k] & 0x33 ];
 
  369         pStore[2] += bit_count[ pTruthC[k] & 0x0F ];
 
  370         for ( i = 3; i < nVars; i++ )
 
  371             if ( (k & (1 << (i-3))) == 0 )
 
  372                 pStore[i] += bit_count[pTruthC[k]];
 
  390       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,
 
  391       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,
 
  392       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,
 
  393       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,
 
  394       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,
 
  395       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,
 
  396       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,
 
  397       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
 
  399     int nMints0, nMints1;
 
  405         for ( i = 0; i <= iVar; i++ )
 
  406             pStore[i] += nBytes * 4;
 
  412         pStore[0] += bit_count[ Truth & 0x55 ];
 
  413         pStore[1] += bit_count[ Truth & 0x33 ];
 
  414         pStore[2] += bit_count[ Truth & 0x0F ];
 
  415         return bit_count[ Truth & 0xFF ];
 
  419     pStore[iVar] += nMints0;
 
  420     return nMints0 + nMints1;
 
  425     int nMints0, nMints1;
 
  438             for ( i = 0; i <= iVar; i++ )
 
  439                 pStore[i] += nWords * 32;
 
  450     pStore[iVar] += nMints0;
 
  451     return nMints0 + nMints1;
 
  455     memset( pStore, 0, 
sizeof(
int) * nVars );
 
  479     int * pStore = pStoreOut ? pStoreOut : pStoreIn;
 
  481     unsigned uCanonPhase = 0;
 
  483     for ( i = 0; i < nVars; i++ )
 
  487     if ( nOnes > nWords * 32 )
 
  490         nOnes = nWords*64 - nOnes;
 
  491         uCanonPhase |= (1 << nVars);
 
  495     pStore[nVars] = nOnes;
 
  496     for ( i = 0; i < nVars; i++ )
 
  498         if ( pStore[i] >= nOnes - pStore[i] )
 
  501         uCanonPhase |= (1 << i);
 
  502         pStore[i] = nOnes - pStore[i]; 
 
  510             for ( i = 0; i < nVars-1; i++ )
 
  512                 if ( pStore[i] <= pStore[i+1] )
 
  515                 ABC_SWAP( 
int, pCanonPerm[i], pCanonPerm[i+1] );
 
  516                 ABC_SWAP( 
int, pStore[i], pStore[i+1] );
 
  517                 if ( ((uCanonPhase >> i) & 1) != ((uCanonPhase >> (i+1)) & 1) )
 
  519                     uCanonPhase ^= (1 << i);
 
  520                     uCanonPhase ^= (1 << (i+1));
 
  532         for ( i = 0; i < nVars - 1; i++ )
 
  535             for ( k = i + 2; k < nVars; k++ )
 
  536                 if ( pStore[BestK] > pStore[k] )
 
  539             if ( pStore[i] <= pStore[BestK] )
 
  542             ABC_SWAP( 
int, pCanonPerm[i], pCanonPerm[BestK] );
 
  543             ABC_SWAP( 
int, pStore[i], pStore[BestK] );
 
  544             if ( ((uCanonPhase >> i) & 1) != ((uCanonPhase >> BestK) & 1) )
 
  546                 uCanonPhase ^= (1 << i);
 
  547                 uCanonPhase ^= (1 << BestK);
 
  571     static word pCopy1[1024];
 
  572     static word pCopy2[1024];
 
  575     for ( i = 0; i < nVars - 1; i++ )
 
  604         if ( pTruth[0] > Copy )
 
  612         word Copy = pTruth[0];
 
  613         word Best = pTruth[0];
 
  619             Best = Copy, Config = 1;
 
  624             Best = Copy, Config = 3;
 
  629             Best = Copy, Config = 2;
 
  634             Best = Copy, Config = 6;
 
  639             Best = Copy, Config = 7;
 
  644             Best = Copy, Config = 5;
 
  649             Best = Copy, Config = 4;
 
  653         assert( Copy == pTruth[0] );
 
  654         assert( Best <= pTruth[0] );
 
  663         static word pCopy[1024];
 
  674         static word pCopy[1024];
 
  675         static word pBest[1024];
 
  684             Abc_TtCopy( pBest, pCopy, nWords, 0 ), Config = 1;
 
  689             Abc_TtCopy( pBest, pCopy, nWords, 0 ), Config = 3;
 
  694             Abc_TtCopy( pBest, pCopy, nWords, 0 ), Config = 2;
 
  699             Abc_TtCopy( pBest, pCopy, nWords, 0 ), Config = 6;
 
  704             Abc_TtCopy( pBest, pCopy, nWords, 0 ), Config = 7;
 
  709             Abc_TtCopy( pBest, pCopy, nWords, 0 ), Config = 5;
 
  714             Abc_TtCopy( pBest, pCopy, nWords, 0 ), Config = 4;
 
  755         int fComp01, fComp02, fComp03, fComp12, fComp13, fComp23, Config = 0;
 
  764                     Abc_TtFlip( pTruth, nWords, i + 1 ), Config = 2;
 
  765                 else if ( fComp13 == 0 ) 
 
  769                         Abc_TtFlip( pTruth, nWords, i + 1 ), Config = 2;
 
  779                     Abc_TtFlip( pTruth, nWords, i + 1 ), Config = 3;
 
  795                 else if ( fComp12 == 0 ) 
 
  798                     Abc_TtFlip( pTruth, nWords, i + 1 ), Config = 3;
 
  802                     Abc_TtFlip( pTruth, nWords, i + 1 ), Config = 2;
 
  813                     Abc_TtFlip( pTruth, nWords, i + 1 ), Config = 3;
 
  815                 else if ( fComp02 == 0 ) 
 
  823                         Abc_TtFlip( pTruth, nWords, i + 1 ), Config = 3;
 
  844             if ( ((*puCanonPhase >> i) & 1) != ((*puCanonPhase >> (i+1)) & 1) )
 
  846                 *puCanonPhase ^= (1 << i);
 
  847                 *puCanonPhase ^= (1 << (i+1));
 
  849             ABC_SWAP( 
int, pCanonPerm[i], pCanonPerm[i+1] );
 
  854         static word pCopy1[1024];
 
  867             *puCanonPhase ^= (1 << i);
 
  869             *puCanonPhase ^= (1 << (i+1));
 
  872             if ( ((*puCanonPhase >> i) & 1) != ((*puCanonPhase >> (i+1)) & 1) )
 
  874                 *puCanonPhase ^= (1 << i);
 
  875                 *puCanonPhase ^= (1 << (i+1));
 
  877             ABC_SWAP( 
int, pCanonPerm[i], pCanonPerm[i+1] );
 
  898     unsigned uCanonPhase;
 
  903     char pCanonPermCopy[16];
 
  904     static word pCopy1[1024];
 
  905     static word pCopy2[1024];
 
  910     for ( k = 0; k < 5; k++ )
 
  913         for ( i = nVars - 2; i >= 0; i-- )
 
  914             if ( pStoreIn[i] == pStoreIn[i+1] )
 
  915                 fChanges |= 
Abc_TtCofactorPerm( pTruth, i, nWords, pStoreIn[i] != pStoreIn[nVars]/2, pCanonPerm, &uCanonPhase, fNaive );
 
  919         for ( i = 1; i < nVars - 1; i++ )
 
  920             if ( pStoreIn[i] == pStoreIn[i+1] )
 
  921                 fChanges |= 
Abc_TtCofactorPerm( pTruth, i, nWords, pStoreIn[i] != pStoreIn[nVars]/2, pCanonPerm, &uCanonPhase, fNaive );
 
  928     memcpy( pCanonPermCopy, pCanonPerm, 
sizeof(
char) * nVars );
 
  931         printf( 
"Canonical form verification failed!\n" );
 
  958     int s, nStep = 1 << (v-6);
 
  960     for ( w = nWords - 1, s = nWords - nStep; w > 0; w-- )
 
  962         if ( pTruth[w-nStep] == pTruth[w] )
 
  964             if ( w == s ) { w = s - nStep; s = w - nStep; }
 
  967         if ( pTruth[w-nStep] > pTruth[w] )
 
  972             if ( w == s ) { w = s - nStep; s = w - nStep; }
 
  985     for ( w = nWords - 1; w >= 0; w-- )
 
  987         if ( ((pTruth[w] << Shift) & Mask) == (pTruth[w] & Mask) )
 
  989         if ( ((pTruth[w] << Shift) & Mask) > (pTruth[w] & Mask) )
 
  992         for ( ; w >= 0; w-- )
 
  993             pTruth[w] = ((pTruth[w] << Shift) & Mask) | ((pTruth[w] & Mask) >> Shift);
 
 1001     unsigned uCanonPhase = 0;
 
 1007     static word pCopy1[1024];
 
 1008     static word pCopy2[1024];
 
 1012     if ( (pTruth[nWords-1] >> 63) & 1 )
 
 1015         uCanonPhase ^= (1 << nVars);
 
 1021         for ( v = nVars - 1; v >= 6; v-- )
 
 1023                 uCanonPhase ^= 1 << v;
 
 1024         for ( ; v >= 0; v-- )
 
 1026                 uCanonPhase ^= 1 << v;
 
 1038         printf( 
"Canonical form verification failed!\n" );
 
int Abc_TtCountOnesInCofsFast6_rec(word Truth, int iVar, int nBytes, int *pStore)
int Abc_TtCofactorPerm(word *pTruth, int i, int nWords, int fSwapOnly, char *pCanonPerm, unsigned *puCanonPhase, int fNaive)
static int Abc_TtCompare1VarCofsRev(word *pTruth, int nWords, int iVar)
static int Abc_TtCanonicizePhaseVar5(word *pTruth, int nVars, int v)
int Abc_TtCofactorPermNaive(word *pTruth, int i, int nWords, int fSwapOnly)
static int Abc_TtIsConst0(word *pIn1, int nWords)
static int Abc_TtCompare2VarCofsRev(word *pTruth, int nWords, int iVar, int Num1, int Num2)
int Abc_Tt6CofactorPermNaive(word *pTruth, int i, int fSwapOnly)
static int Abc_TtCountOnes(word x)
static word Abc_Tt6Cofactor0(word t, int iVar)
static int Abc_TtCanonicizePhaseVar6(word *pTruth, int nVars, int v)
static int bit_count[256]
static int Abc_TtCompare1VarCofs(word *pTruth, int nWords, int iVar)
FUNCTION DEFINITIONS ///. 
static int Abc_TtIsConst1(word *pIn1, int nWords)
static int Abc_TtByteNum(int nVars)
#define ABC_SWAP(Type, a, b)
static word Abc_Tt6SwapAdjacent(word Truth, int iVar)
static void Abc_TtCopy(word *pOut, word *pIn, int nWords, int fCompl)
static word Abc_Tt6Cofactor1(word t, int iVar)
void Abc_TtCofactorTest10(word *pTruth, int nVars, int N)
static int Abc_TtCountOnesInTruth(word *pTruth, int nVars)
unsigned __int64 word
DECLARATIONS ///. 
#define ABC_NAMESPACE_IMPL_END
static int Abc_TtCompare2VarCofs(word *pTruth, int nWords, int iVar, int Num1, int Num2)
unsigned Abc_TtCanonicize(word *pTruth, int nVars, char *pCanonPerm)
FUNCTION DECLARATIONS ///. 
static void Abc_TtImplementNpnConfig(word *pTruth, int nVars, char *pCanonPerm, unsigned uCanonPhase)
static word s_Truths6Neg[6]
static word Abc_Tt6Flip(word Truth, int iVar)
static int Abc_TtCheckEqual2VarCofs(word *pTruth, int nWords, int iVar, int Num1, int Num2)
static void Abc_TtFlip(word *pTruth, int nWords, int iVar)
#define ABC_NAMESPACE_IMPL_START
static ABC_NAMESPACE_IMPL_START word Truth[8]
DECLARATIONS ///. 
static unsigned Abc_TtSemiCanonicize(word *pTruth, int nVars, char *pCanonPerm, int *pStoreOut)
unsigned Abc_TtCanonicizePhase(word *pTruth, int nVars)
static int Abc_TtWordNum(int nVars)
#define ABC_CONST(number)
PARAMETERS ///. 
static void Abc_TtCountOnesInCofsSlow(word *pTruth, int nVars, int *pStore)
static ABC_NAMESPACE_IMPL_START word s_CMasks6[5]
DECLARATIONS ///. 
static int Abc_TtEqual(word *pIn1, word *pIn2, int nWords)
static void Abc_TtCountOnesInCofs(word *pTruth, int nVars, int *pStore)
int Abc_TtCountOnesInCofsFast(word *pTruth, int nVars, int *pStore)
static void Abc_TtSwapVars(word *pTruth, int nVars, int iVar, int jVar)
static void Abc_TtNot(word *pOut, int nWords)
int Abc_TtCofactorPermConfig(word *pTruth, int i, int nWords, int fSwapOnly, int fNaive)
int Abc_TtCountOnesInCofsFast_rec(word *pTruth, int iVar, int nWords, int *pStore)
static void Abc_TtSwapAdjacent(word *pTruth, int nWords, int iVar)
static int Abc_TtCompareRev(word *pIn1, word *pIn2, int nWords)