66 { 0x55555555, 0xAAAAAAAA },
67 { 0x33333333, 0xCCCCCCCC },
68 { 0x0F0F0F0F, 0xF0F0F0F0 },
69 { 0x00FF00FF, 0xFF00FF00 },
70 { 0x0000FFFF, 0xFFFF0000 },
71 { 0x00000000, 0xFFFFFFFF }
76 uWord = (uWord & 0x55555555) + ((uWord>>1) & 0x55555555);
77 uWord = (uWord & 0x33333333) + ((uWord>>2) & 0x33333333);
78 uWord = (uWord & 0x0F0F0F0F) + ((uWord>>4) & 0x0F0F0F0F);
79 uWord = (uWord & 0x00FF00FF) + ((uWord>>8) & 0x00FF00FF);
80 return (uWord & 0x0000FFFF) + (uWord>>16);
86 return (uTruth &
s_Masks[Var][Cof]) == 0;
93 return (uTruth &
s_Masks[Var][0]) == 0;
98 unsigned uCofactor = uTruth &
s_Masks[Var >> 1][(Var & 1) == 0];
99 int Shift = (1 << (Var >> 1));
101 return uCofactor | (uCofactor << Shift);
102 return uCofactor | (uCofactor >> Shift);
118 assert( iNum >= 0 && iNum <= 5 );
121 case 0: pNode->
Fan0 =
Var;
break;
122 case 1: pNode->
Fan1 =
Var;
break;
123 case 2: pNode->
Fan2 =
Var;
break;
124 case 3: pNode->
Fan3 =
Var;
break;
125 case 4: pNode->
Fan4 =
Var;
break;
126 case 5: pNode->
Fan5 =
Var;
break;
132 assert( iNum >= 0 && iNum <= 5 );
135 case 0:
return pNode->
Fan0;
136 case 1:
return pNode->
Fan1;
137 case 2:
return pNode->
Fan2;
138 case 3:
return pNode->
Fan3;
139 case 4:
return pNode->
Fan4;
140 case 5:
return pNode->
Fan5;
172 for ( i = 0; i < 5; i++ )
175 if ( uTruth == 0 || ~uTruth == 0 )
179 Node.
fCompl = (uTruth == 0);
185 if ( RetValue == -1 )
188 if ( (RetValue >> 1) < 5 )
192 Node.
fCompl = (RetValue & 1);
193 Node.
Fan0 = ((RetValue >> 1) << 1);
196 else if ( RetValue & 1 )
200 Node.
fCompl = (RetValue & 1);
204 printf(
"Verification failed.\n" );
222 int Supp[5], Vars0[5], Vars1[5], Vars2[5], * pVars;
223 int nSupp, Count0, Count1, Count2, nVars, RetValue, fCompl, i;
224 unsigned uTruthCof, uCof0, uCof1;
227 Count0 = Count1 = Count2 = nSupp = 0;
228 for ( i = 0; i < 5; i++ )
231 Vars0[Count0++] = (i << 1) | 0;
233 Vars0[Count0++] = (i << 1) | 1;
235 Vars1[Count1++] = (i << 1) | 0;
237 Vars1[Count1++] = (i << 1) | 1;
242 if ( uCof0 == ~uCof1 )
243 Vars2[Count2++] = (i << 1) | 0;
244 else if ( uCof0 != uCof1 )
248 assert( Count0 == 0 || Count1 == 0 );
249 assert( Count0 == 0 || Count2 == 0 );
250 assert( Count1 == 0 || Count2 == 0 );
253 if ( Count0 == 1 && nSupp == 0 )
257 if ( Count0 == 0 && Count1 == 0 && Count2 == 0 )
264 else if ( Count1 > 0 )
265 nVars = Count1, pVars = Vars1, Node.
Type =
IVY_DEC_AND, fCompl = 1, uTruth = ~uTruth;
266 else if ( Count2 > 0 )
270 Node.
nFans = nVars+(nSupp>0);
274 for ( i = 0; i < nVars; i++ )
281 fCompl ^= ((Node.
nFans & 1) == 0);
285 assert( uTruthCof != 0 && ~uTruthCof != 0 );
289 if ( RetValue == -1 )
301 fCompl ^= (uTruthCof == 0);
322 int i, k, RetValue0, RetValue1;
323 unsigned uCof0, uCof1, Num;
331 for ( i = 0; i < nSupp; i++ )
338 for ( k = 0; k < nSupp; k++ )
349 if ( RetValue0 == -1 )
352 if ( RetValue1 == -1 )
368 Count[0] = Count[1] = Count[2] = 0;
369 for ( i = 0; i < 8; i++ )
372 for ( k = 0; k < 3; k++ )
374 Num |= (1 << pSupp[k]);
376 if ( (uTruth & (1 << Num)) == 0 )
378 for ( k = 0; k < 3; k++ )
382 assert( Count[0] == 1 || Count[0] == 3 );
383 assert( Count[1] == 1 || Count[1] == 3 );
384 assert( Count[2] == 1 || Count[2] == 3 );
406 unsigned uTruthChild, uTruthTotal;
418 return Node.
fCompl? ~uTruthTotal : uTruthTotal;
423 for ( i = 0; i < (int)Node.
nFans; i++ )
427 uTruthTotal = (Var & 1)? uTruthTotal & ~uTruthChild : uTruthTotal & uTruthChild;
429 return Node.
fCompl? ~uTruthTotal : uTruthTotal;
434 for ( i = 0; i < (int)Node.
nFans; i++ )
440 return Node.
fCompl? ~uTruthTotal : uTruthTotal;
445 unsigned uTruthChildC, uTruthChild1, uTruthChild0;
446 int VarC, Var1, Var0;
454 uTruthChildC = (VarC & 1)? ~uTruthChildC : uTruthChildC;
455 uTruthChild1 = (Var1 & 1)? ~uTruthChild1 : uTruthChild1;
456 uTruthChild0 = (Var0 & 1)? ~uTruthChild0 : uTruthChild0;
458 return (uTruthChildC & uTruthChild1) | (~uTruthChildC & uTruthChild0);
460 return (uTruthChildC & uTruthChild1) | (uTruthChildC & uTruthChild0) | (uTruthChild1 & uTruthChild0);
501 fprintf( pFile,
"Const1%s", (Node.
fCompl?
"\'" :
"") );
503 fprintf( pFile,
"%c%s",
'a' + iNode, (Node.
fCompl?
"\'" :
"") );
507 fprintf( pFile,
"%s", (Node.
fCompl?
"\'" :
"") );
511 fprintf( pFile,
"AND(" );
512 for ( i = 0; i < (int)Node.
nFans; i++ )
516 fprintf( pFile,
"%s", (Var & 1)?
"\'" :
"" );
517 if ( i != (
int)Node.
nFans-1 )
518 fprintf( pFile,
"," );
520 fprintf( pFile,
")%s", (Node.
fCompl?
"\'" :
"") );
524 fprintf( pFile,
"EXOR(" );
525 for ( i = 0; i < (int)Node.
nFans; i++ )
529 if ( i != (
int)Node.
nFans-1 )
530 fprintf( pFile,
"," );
533 fprintf( pFile,
")%s", (Node.
fCompl?
"\'" :
"") );
537 int VarC, Var1, Var0;
544 fprintf( pFile,
"%s", (VarC & 1)?
"\'" :
"" );
545 fprintf( pFile,
"," );
547 fprintf( pFile,
"%s", (Var1 & 1)?
"\'" :
"" );
548 fprintf( pFile,
"," );
550 fprintf( pFile,
"%s", (Var0 & 1)?
"\'" :
"" );
551 fprintf( pFile,
")" );
570 fprintf( pFile,
"F = " );
572 fprintf( pFile,
"\n" );
588 Ivy_Obj_t * pResult, * pChild, * pNodes[16];
607 for ( i = 0; i < (int)Node.
nFans; i++ )
624 int VarC, Var1, Var0;
636 return Ivy_Mux( p, pNodes[0], pNodes[1], pNodes[2] );
638 return Ivy_Maj( p, pNodes[0], pNodes[1], pNodes[2] );
686 printf(
"Undecomposable\n" );
715 printf(
"%5d : ", Counter++ );
720 printf(
"Verification failed.\n" );
745 pFile = fopen(
"npn4.txt",
"r" );
746 for ( i = 0; i < 222; i++ )
750 fscanf( pFile,
"%s", Buffer );
753 uTruth |= (uTruth << 16);
771 void Ivy_TruthTest3()
778 pFile = fopen(
"npn3.txt",
"r" );
779 for ( i = 0; i < 14; i++ )
781 fscanf( pFile,
"%s", Buffer );
783 uTruth = uTruth | (uTruth << 8) | (uTruth << 16) | (uTruth << 24);
800 void Ivy_TruthTest5()
809 pFile = fopen(
"npn5.txt",
"r" );
810 for ( i = 0; i < 616126; i++ )
812 fscanf( pFile,
"%s", Buffer );
void Ivy_TruthDsdPrint(FILE *pFile, Vec_Int_t *vTree)
int Ivy_TruthDsd(unsigned uTruth, Vec_Int_t *vTree)
FUNCTION DEFINITIONS ///.
static Ivy_Obj_t * Ivy_ManConst1(Ivy_Man_t *p)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Ivy_Obj_t * Ivy_Mux(Ivy_Man_t *p, Ivy_Obj_t *pC, Ivy_Obj_t *p1, Ivy_Obj_t *p0)
void Ivy_TruthDsdPrint_rec(FILE *pFile, int iNode, Vec_Int_t *vTree)
static unsigned Ivy_DecGetVar(Ivy_Dec_t *pNode, int iNum)
void Ivy_TruthDsdComputePrint(unsigned uTruth)
static int Ivy_TruthRecognizeMuxMaj(unsigned uTruth, int *pSupp, int nSupp, Vec_Int_t *vTree)
static int Ivy_LeafId(int Leaf)
void Ivy_TruthTestOne(unsigned uTruth)
static Ivy_Dec_t Ivy_IntToDec(int m)
static int Ivy_TruthCofactorIsOne(unsigned uTruth, int Var)
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
static unsigned Ivy_TruthCofactor2(unsigned uTruth, int Var0, int Var1)
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
static Ivy_Obj_t * Ivy_ManObj(Ivy_Man_t *p, int i)
unsigned Ivy_TruthDsdCompute_rec(int iNode, Vec_Int_t *vTree)
static int Vec_IntEntry(Vec_Int_t *p, int i)
#define ABC_NAMESPACE_IMPL_END
Ivy_Obj_t * Ivy_ManDsdConstruct_rec(Ivy_Man_t *p, Vec_Int_t *vFront, int iNode, Vec_Int_t *vTree)
Ivy_Obj_t * Ivy_Multi(Ivy_Man_t *p, Ivy_Obj_t **pArgs, int nArgs, Ivy_Type_t Type)
static int Ivy_DecToInt(Ivy_Dec_t m)
static void Vec_IntPush(Vec_Int_t *p, int Entry)
static int Ivy_TruthCofactorIsConst(unsigned uTruth, int Var, int Cof, int Const)
static void Ivy_DecSetVar(Ivy_Dec_t *pNode, int iNum, unsigned Var)
static int Ivy_TruthDepends(unsigned uTruth, int Var)
unsigned Ivy_TruthDsdCompute(Vec_Int_t *vTree)
typedefABC_NAMESPACE_HEADER_START struct Ivy_Man_t_ Ivy_Man_t
INCLUDES ///.
#define ABC_NAMESPACE_IMPL_START
Ivy_DecType_t
DECLARATIONS ///.
static int Ivy_TruthDecompose_rec(unsigned uTruth, Vec_Int_t *vTree)
static unsigned Ivy_TruthCofactor(unsigned uTruth, int Var)
static int Vec_IntSize(Vec_Int_t *p)
static void Ivy_DecClear(Ivy_Dec_t *pNode)
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
static Ivy_Obj_t * Ivy_NotCond(Ivy_Obj_t *p, int c)
static int Ivy_TruthWordCountOnes(unsigned uWord)
Ivy_Obj_t * Ivy_Maj(Ivy_Man_t *p, Ivy_Obj_t *pA, Ivy_Obj_t *pB, Ivy_Obj_t *pC)
Ivy_Obj_t * Ivy_ManDsdConstruct(Ivy_Man_t *p, Vec_Int_t *vFront, Vec_Int_t *vTree)
static unsigned s_Masks[6][2]
static void Vec_IntClear(Vec_Int_t *p)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.