30#include DSD_MAX_VAR 12
31#include DSD_MAX_WRD ((DSD_MAX_VAR > 6) ? (1 << (DSD_MAX_VAR-6)) : 1)
69static inline word Abc_Tt6HalfUnShuffleVars(
word t,
int iVar,
int fCof1 )
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];
86static inline void Abc_TtHalfUnShuffleVars(
word * pTruth,
int nVars,
int iVar,
int jVar,
int fCof1 )
88 int w,
nWords = Abc_TtWordNum( nVars );
94 for ( w = 0; w <
nWords; w++ )
95 pTruth[w] = Abc_Tt6HalfUnShuffleVars( pTruth[w], iVar, fCof1 );
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];
113 int i, iStep = Abc_TtWordNum(iVar);
114 int j, jStep = Abc_TtWordNum(jVar);
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];
140 pRes->
nWords = Abc_TtWordNum( nVars );
142 pRes->
iRoot = Abc_Var2Lit( 0, 0 );
143 pRes->
pObjs[0].Type = 5;
144 pRes->
pObjs[0].nFans = nVars;
145 for ( i = 0; i < nVars; i++ )
146 pRes->
pObjs[0].pFans[i] = (
char)Abc_Var2Lit( i, 0 );
164 if ( !(pTruth[0] & 1) )
166 Abc_TtNot( pTruth, Abc_TtWordNum(nVars) );
171 int nWordsI = Abc_TtWordNum(iVar);
172 word c0 = (iVar < 6) ? Abc_Tt6Cofactor0( pTruth[0], iVar ) : pTruth[0];
173 word c1 = (iVar < 6) ? Abc_Tt6Cofactor1( pTruth[0], iVar ) : pTruth[
nWords];
176 if ( c1 < c0 && c1 < ~c1 )
178 Abc_TtFlip( pTruth,
nWords, iVar );
181 if ( ~c1 < c0 && ~c1 < c1 )
183 Abc_TtFlipNot( pTruth,
nWords, iVar );
190 for ( pTruth++; pTruth < pLimit; pTruth++ )
192 c0 = Abc_Tt6Cofactor0( pTruth[0], iVar );
193 c1 = Abc_Tt6Cofactor1( pTruth[0], iVar );
198 for ( ; pTruth < pLimit; pTruth++ )
199 pTruth[0] = Abc_Tt6Flip( pTruth[0], iVar );
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++ )
226 return (pTruth[0] & s_Truths6Neg[iVar]) == 0;
230 for ( w = 0; w <
nWords; w++ )
231 if ( (pTruth[w] & s_Truths6Neg[iVar]) )
238 int i, iStep = Abc_TtWordNum(iVar);
239 for ( ; pTruth < pLimit; pTruth += (iStep << 1) )
240 for ( i = 0; i < iStep; i++ )
249 return (pTruth[0] & s_Truths6Neg[iVar]) == ((~pTruth[0] & s_Truths6[iVar]) >> (1 << iVar));
252 int w, shift = (1 << iVar);
253 for ( w = 0; w <
nWords; w++ )
254 if ( (pTruth[w] & s_Truths6Neg[iVar]) != ((~pTruth[w] & s_Truths6[iVar]) >> shift) )
261 int i, iStep = Abc_TtWordNum(iVar);
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++ )
307 static word s_PMasks[5][3] = {
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] );
350 int i, iStep = Abc_TtWordNum(iVar);
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++ )
370 static word s_PMasks[5][4] = {
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 )
409 int i, iStep = Abc_TtWordNum(iVar);
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 );
518 int nWordsF = Abc_TtWordNum(iVar);
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, (
size_t)nBytes) )
528 pCof0 = pTruth + iWord;
529 else if ( !pCof1 || !
memcmp(pCof1, pTruth + iWord, (
size_t)nBytes) )
531 pCof1 = pTruth + iWord;
532 MaskOne |= ((
word)1) << Mint;
539 else if ( MaskAll != MaskOne )
544 memcpy( pTruth + (2 * Part + 0) * nWordsF, pCof0, (
size_t)nBytes );
545 memcpy( pTruth + (2 * Part + 1) * nWordsF, pCof1, (
size_t)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++ )
606 if ( Abc_TtGetBit(pTruth, i) ^ (pTruthP[i] != Dfunc) )
607 Abc_TtXorBit(pTruth, i);
609 else if ( iVar == 4 )
611 unsigned short * pTruthP = (
unsigned short *)pTruth, Dfunc = pTruthP[0];
612 for ( i = 0; i < nParts; i++ )
613 if ( Abc_TtGetBit(pTruth, i) ^ (pTruthP[i] != Dfunc) )
614 Abc_TtXorBit(pTruth, i);
616 else if ( iVar == 5 )
618 unsigned int * pTruthP = (
unsigned int *)pTruth, Dfunc = pTruthP[0];
619 for ( i = 0; i < nParts; i++ )
620 if ( Abc_TtGetBit(pTruth, i) ^ (pTruthP[i] != Dfunc) )
621 Abc_TtXorBit(pTruth, i);
625 word Dfunc = pTruth[0];
627 for ( i = 0; i < nParts; i++ )
628 if ( Abc_TtGetBit(pTruth, i) ^ (pTruth[i] != Dfunc) )
629 Abc_TtXorBit(pTruth, i);
632 if ( nVars - iVar + 1 < 6 )
633 pTruth[0] = Abc_Tt6Stretch( pTruth[0], nVars - iVar + 1 < 6 );
#define ABC_SWAP(Type, a, b)
#define ABC_CONST(number)
PARAMETERS ///.
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
int Dua_DsdTryVar(word *pTruth, int nWords, int iVar)
word Dua_DsdRangeVars(word *pTruth, int nVars, int iVar, int jVar, int fPerform)
int Dua_DsdTwoVars(Dua_Dsd_t *pRes)
int Dua_DsdCheckCofsEqualNot(word *pTruth, int nWords, int iVar)
struct Dua_Dsd_t_ Dua_Dsd_t
void Dua_DsdInit(Dua_Dsd_t *pRes, word *pTruth, int nVars)
typedefABC_NAMESPACE_IMPL_START struct Dua_Obj_t_ Dua_Obj_t
DECLARATIONS ///.
int Dua_DsdOneVar(Dua_Dsd_t *pRes)
int Dua_DsdTrySwap(word *pTruth, int nWords, int iVar)
void Dua_DsdRangeVars0Derive(word *pTruth, int nVars, int iVar)
int Dua_DsdCheckDecomp(word *pTruth, int nWords, int iVar)
void Dua_DsdTest(word *pTruth, int nVar)
int Dua_DsdRangeVars0(word *pTruth, int nVars, int iVar, int fPerform)
int Dua_DsdTryConst(word *pTruth, int nVars)
int Dua_DsdCheckCof0Const0(word *pTruth, int nWords, int iVar)
unsigned __int64 word
DECLARATIONS ///.
Dua_Obj_t pObjs[DSD_MAX_VAR]