30 #include DSD_MAX_VAR 12
31 #include DSD_MAX_WRD ((DSD_MAX_VAR > 6) ? (1 << (DSD_MAX_VAR-6)) : 1)
71 static word Masks[6] = {
79 int v, s = (1 << iVar);
80 t = (t >> (fCof1 ? 0 : s)) & Masks[iVar];
81 for ( v = iVar, s = (1 << v); v < 5; v++, s <<= 1 )
82 t = ((t >> s) | t) & Masks[v+1];
94 for ( w = 0; w <
nWords; w++ )
100 for ( w = 0; w <
nWords; w++ )
101 pTruth[w] = (pTruth[w] << 32) | pTruth[w];
106 unsigned * pTruthU = (
unsigned *)pTruth;
107 for ( w = 0; w <
nWords; w += 2 )
108 pTruthU[w] = pTruthU[w+1];
115 for ( ; pTruth < pLimit; pTruth += jStep )
116 for ( i = 0; i < jStep; i += iStep )
117 for ( j = 0; j < iStep; j++ )
118 pTruth[w++] = pTruth[iStep + i + j];
119 assert( w == (nWords >> 1) );
143 pRes->
pObjs[0].Type = 5;
144 pRes->
pObjs[0].nFans = nVars;
145 for ( i = 0; i < nVars; i++ )
164 if ( !(pTruth[0] & 1) )
176 if ( c1 < c0 && c1 < ~c1 )
181 if ( ~c1 < c0 && ~c1 < c1 )
183 Abc_TtFlipNot( pTruth, nWords, iVar );
190 for ( pTruth++; pTruth < pLimit; pTruth++ )
198 for ( ; pTruth < pLimit; pTruth++ )
205 for ( ; pTruth < pLimit; pTruth += (nWordsI << 1) )
206 for ( w = 0; w < nWordsI; w++ )
209 c1 = pTruth[nWordsI];
214 for ( ; pTruth < pLimit; pTruth += (nWordsI << 1) )
215 for ( ; w < nWordsI; w++ )
230 for ( w = 0; w <
nWords; w++ )
239 for ( ; pTruth < pLimit; pTruth += (iStep << 1) )
240 for ( i = 0; i < iStep; i++ )
252 int w, shift = (1 << iVar);
253 for ( w = 0; w <
nWords; w++ )
262 for ( ; pTruth < pLimit; pTruth += (iStep << 1) )
263 for ( i = 0; i < iStep; i++ )
264 if ( pTruth[i] != ~pTruth[i + iStep] )
271 int v, fCompl, fChange = 1;
273 while ( fChange && pRes->
nVars > 2 )
276 for ( v = 0; v < pRes->
nVars; v++ )
316 int Shift = (1 << iVar);
318 for ( ; pTruth < pLimit; pTruth++ )
320 c01 = (pTruth[0] & s_PMasks[iVar][1]);
321 c10 = (pTruth[0] & s_PMasks[iVar][2]) >> Shift;
326 pTruth[0] = (pTruth[0] & s_PMasks[iVar][0]) | ((pTruth[0] & s_PMasks[iVar][1]) << Shift) | ((pTruth[0] & s_PMasks[iVar][2]) >> Shift);
330 else if ( iVar == 5 )
332 unsigned * pTruthU = (
unsigned *)pTruth;
333 unsigned * pLimitU = (
unsigned *)(pTruth + nWords);
334 for ( ; pTruthU < pLimitU; pTruthU += 4 )
342 for ( ; pTruthU < pLimitU; pTruthU += 4 )
343 ABC_SWAP(
unsigned, pTruthU[1], pTruthU[2] );
351 for ( ; pTruth < pLimit; pTruth += 4*iStep )
352 for ( i = 0; i < iStep; i++ )
354 c01 = pTruth[i + iStep];
355 c10 = pTruth[i + 2*iStep];
360 for ( ; pTruth < pLimit; pTruth += 4*iStep )
361 for ( ; i < iStep; i++ )
377 int fC0eC1 = 1, fC0eC3 = 1;
380 int Shift = (1 << iVar);
382 for ( ; pTruth < pLimit; pTruth++ )
384 if ( fC0eC1 && (pTruth[0] & s_PMasks[iVar][0]) != ((pTruth[0] & s_PMasks[iVar][1]) >> Shift) )
386 if ( fC0eC3 && (pTruth[0] & s_PMasks[iVar][0]) != ((pTruth[0] & s_PMasks[iVar][3]) >> (3*Shift)) )
388 if ( !fC0eC1 && !fC0eC3 )
394 unsigned * pTruthU = (
unsigned *)pTruth;
395 unsigned * pLimitU = (
unsigned *)(pTruth + nWords);
396 for ( ; pTruthU < pLimitU; pTruthU += 4 )
398 if ( fC0eC1 && pTruthU[0] != pTruthU[1] )
400 if ( fC0eC3 && pTruthU[0] != pTruthU[3] )
402 if ( !fC0eC1 && !fC0eC3 )
410 for ( ; pTruth < pLimit; pTruth += 4*iStep )
411 for ( i = 0; i < iStep; i++ )
413 if ( fC0eC1 && pTruth[0] != pTruth[1] )
415 if ( fC0eC3 && pTruth[0] != pTruth[3] )
417 if ( !fC0eC1 && !fC0eC3 )
421 assert( fC0eC1 != fC0eC3 );
422 return fC0eC1 ? 1 : 2;
428 int v, RetValue, fChange = 1;
429 while ( fChange && pRes->
nVars > 2 )
432 for ( v = 0; v < pRes->
nVars - 1; v++ )
470 int Part, nParts = 1 << (nVars - jVar);
471 int Mint, nMints = 1 << (jVar - iVar);
472 word MaskOne, MaskAll = 0;
473 assert( jVar - iVar > 2 );
474 assert( jVar - iVar < 7 );
477 int Shift = 6 - iVar, MaskF = (1 << Shift) - 1, iMint = 0;
478 word MaskFF = (((
word)1) << (1 << iVar)) - 1;
479 word Cof0, Cof1, Value;
480 for ( Part = 0; Part < nParts; Part++ )
483 Cof0 = Cof1 = ~(
word)0;
484 for ( Mint = 0; Mint < nMints; Mint++, iMint++ )
486 Value = (pTruth[iMint>>Shift] >> ((iMint & MaskF)<<iVar)) & MaskFF;
487 if ( !~Cof0 || Cof0 == Value )
489 else if ( !~Cof1 || Cof1 == Value )
492 MaskOne |= ((
word)1) << Mint;
499 else if ( MaskAll != MaskOne )
505 Value = (pTruth[Mint>>Shift] >> ((Mint & MaskF)<<nVarsF)) & MaskFF;
506 pTruth[Mint>>Shift] ^= (Value ^ Cof0) << ((Mint & MaskF)<<nVarsF)
508 Value = (pTruth[Mint>>Shift] >> ((Mint & MaskF)<<nVarsF)) & MaskFF;
509 pTruth[Mint>>Shift] ^= (Value ^ Cof1) << ((Mint & MaskF)<<nVarsF)
513 if ( nVars - (jVar - iVar) + 1 < 6 )
514 pTruth[0] =
Abc_Tt6Stretch( pTruth[0], nVars - (jVar - iVar) + 1 );
519 int iWord = 0, nBytes =
sizeof(
word) * nWordsF;
520 word * pCof0, * pCof1;
521 for ( Part = 0; Part < nParts; Part++ )
524 pCof0 = pCof1 = NULL;
525 for ( Mint = 0; Mint < nMints; Mint++, iWord += nWordsF )
527 if ( !pCof0 || !
memcmp(pCof0, pTruth + iWord, nBytes) )
528 pCof0 = pTruth + iWord;
529 else if ( !pCof1 || !
memcmp(pCof1, pTruth + iWord, nBytes) )
531 pCof1 = pTruth + iWord;
532 MaskOne |= ((
word)1) << Mint;
539 else if ( MaskAll != MaskOne )
544 memcpy( pTruth + (2 * Part + 0) * nWordsF, pCof0, nBytes );
545 memcpy( pTruth + (2 * Part + 1) * nWordsF, pCof1, nBytes );
565 int i, nParts = 1 << (nVars - iVar);
566 assert( iVar > 2 && iVar < nVars );
569 unsigned char * pTruthP = (
unsigned char *)pTruth, Dfunc = pTruthP[0];
570 for ( i = 1; i < nParts; i++ )
571 if ( pTruthP[i] != Dfunc && pTruthP[i] != ~Dfunc )
574 else if ( iVar == 4 )
576 unsigned short * pTruthP = (
unsigned short *)pTruth, Dfunc = pTruthP[0];
577 for ( i = 1; i < nParts; i++ )
578 if ( pTruthP[i] != Dfunc && pTruthP[i] != ~Dfunc )
581 else if ( iVar == 5 )
583 unsigned int * pTruthP = (
unsigned int *)pTruth, Dfunc = pTruthP[0];
584 for ( i = 1; i < nParts; i++ )
585 if ( pTruthP[i] != Dfunc && pTruthP[i] != ~Dfunc )
590 int nStep = 1 << (6 - iVar);
592 for ( i = 1; i < nParts; i++ )
593 if ( !
Abc_TtEqual(pTruth, pTruth + i * nStep, nStep) && !Abc_TtEqualNot(pTruth, pTruth + i * nStep, nStep) )
600 int i, nParts = 1 << (nVars - iVar);
601 assert( iVar > 2 && iVar < nVars );
604 unsigned char * pTruthP = (
unsigned char *)pTruth, Dfunc = pTruthP[0];
605 for ( i = 0; i < nParts; i++ )
609 else if ( iVar == 4 )
611 unsigned short * pTruthP = (
unsigned short *)pTruth, Dfunc = pTruthP[0];
612 for ( i = 0; i < nParts; i++ )
616 else if ( iVar == 5 )
618 unsigned int * pTruthP = (
unsigned int *)pTruth, Dfunc = pTruthP[0];
619 for ( i = 0; i < nParts; i++ )
625 word Dfunc = pTruth[0];
627 for ( i = 0; i < nParts; i++ )
632 if ( nVars - iVar + 1 < 6 )
int Dua_DsdTwoVars(Dua_Dsd_t *pRes)
word Dua_DsdRangeVars(word *pTruth, int nVars, int iVar, int jVar, int fPerform)
int Dua_DsdTryVar(word *pTruth, int nWords, int iVar)
Dua_Obj_t pObjs[DSD_MAX_VAR]
static int Abc_Var2Lit(int Var, int fCompl)
static word Abc_Tt6Cofactor0(word t, int iVar)
static int Abc_TtGetBit(word *p, int i)
MACRO DEFINITIONS ///.
void Dua_DsdRangeVars0Derive(word *pTruth, int nVars, int iVar)
int Dua_DsdTryConst(word *pTruth, int nVars)
#define ABC_SWAP(Type, a, b)
int Dua_DsdRangeVars0(word *pTruth, int nVars, int iVar, int fPerform)
static void Abc_TtXorBit(word *p, int i)
static word Abc_Tt6Cofactor1(word t, int iVar)
unsigned __int64 word
DECLARATIONS ///.
#define ABC_NAMESPACE_IMPL_END
static word Abc_Tt6Stretch(word t, int nVars)
static word s_PMasks[5][3]
static word s_Truths6Neg[6]
static word Abc_Tt6Flip(word Truth, int iVar)
static word Abc_Tt6HalfUnShuffleVars(word t, int iVar, int fCof1)
FUNCTION DEFINITIONS ///.
static void Abc_TtFlip(word *pTruth, int nWords, int iVar)
#define ABC_NAMESPACE_IMPL_START
static int Abc_TtWordNum(int nVars)
#define ABC_CONST(number)
PARAMETERS ///.
static int Abc_TtEqual(word *pIn1, word *pIn2, int nWords)
typedefABC_NAMESPACE_IMPL_START struct Dua_Obj_t_ Dua_Obj_t
DECLARATIONS ///.
int Dua_DsdCheckCof0Const0(word *pTruth, int nWords, int iVar)
void Dua_DsdInit(Dua_Dsd_t *pRes, word *pTruth, int nVars)
int Dua_DsdCheckDecomp(word *pTruth, int nWords, int iVar)
int Dua_DsdCheckCofsEqualNot(word *pTruth, int nWords, int iVar)
void Dua_DsdTest(word *pTruth, int nVar)
static void Abc_TtHalfUnShuffleVars(word *pTruth, int nVars, int iVar, int jVar, int fCof1)
static void Abc_TtNot(word *pOut, int nWords)
int Dua_DsdTrySwap(word *pTruth, int nWords, int iVar)
int Dua_DsdOneVar(Dua_Dsd_t *pRes)