53static inline int Abc_BddIthVar(
int i ) {
return Abc_Var2Lit(i + 1, 0); }
54static inline unsigned Abc_BddHash(
int Arg0,
int Arg1,
int Arg2 ) {
return 12582917 * Arg0 + 4256249 * Arg1 + 741457 * Arg2; }
56static inline int Abc_BddVar(
Abc_BddMan *
p,
int i ) {
return (
int)
p->pVars[Abc_Lit2Var(i)]; }
57static inline int Abc_BddThen(
Abc_BddMan *
p,
int i ) {
return Abc_LitNotCond(
p->pObjs[Abc_LitRegular(i)], Abc_LitIsCompl(i)); }
58static inline int Abc_BddElse(
Abc_BddMan *
p,
int i ) {
return Abc_LitNotCond(
p->pObjs[Abc_LitRegular(i)+1], Abc_LitIsCompl(i)); }
60static inline int Abc_BddMark(
Abc_BddMan *
p,
int i ) {
return (
int)
p->pMark[Abc_Lit2Var(i)]; }
61static inline void Abc_BddSetMark(
Abc_BddMan *
p,
int i,
int m ){
p->pMark[Abc_Lit2Var(i)] = m; }
78static inline int Abc_BddUniqueCreateInt(
Abc_BddMan *
p,
int Var,
int Then,
int Else )
80 int *q =
p->pUnique + (Abc_BddHash(
Var, Then, Else) &
p->nUniqueMask);
81 for ( ; *q; q =
p->pNexts + *q )
82 if ( (
int)
p->pVars[*q] ==
Var &&
p->pObjs[*q+*q] == Then &&
p->pObjs[*q+*q+1] == Else )
83 return Abc_Var2Lit(*q, 0);
84 if (
p->nObjs ==
p->nObjsAlloc )
85 printf(
"Aborting because the number of nodes exceeded %d.\n",
p->nObjsAlloc ), fflush(stdout);
89 p->pObjs[*q+*q] = Then;
90 p->pObjs[*q+*q+1] = Else;
92 assert( !Abc_LitIsCompl(Else) );
93 return Abc_Var2Lit(*q, 0);
95static inline int Abc_BddUniqueCreate(
Abc_BddMan *
p,
int Var,
int Then,
int Else )
102 if ( !Abc_LitIsCompl(Else) )
103 return Abc_BddUniqueCreateInt(
p,
Var, Then, Else );
104 return Abc_LitNot( Abc_BddUniqueCreateInt(
p,
Var, Abc_LitNot(Then), Abc_LitNot(Else)) );
118static inline int Abc_BddCacheLookup(
Abc_BddMan *
p,
int Arg1,
int Arg2 )
120 int * pEnt =
p->pCache + 3*(Abc_BddHash(0, Arg1, Arg2) &
p->nCacheMask);
122 return (pEnt[0] == Arg1 && pEnt[1] == Arg2) ? pEnt[2] : -1;
124static inline int Abc_BddCacheInsert(
Abc_BddMan *
p,
int Arg1,
int Arg2,
int Res )
126 int * pEnt =
p->pCache + 3*(Abc_BddHash(0, Arg1, Arg2) &
p->nCacheMask);
127 pEnt[0] = Arg1; pEnt[1] = Arg2; pEnt[2] = Res;
150 p->nObjsAlloc = nObjs;
151 p->nUniqueMask = (1 << Abc_Base2Log(nObjs)) - 1;
152 p->nCacheMask = (1 << Abc_Base2Log(nObjs)) - 1;
161 for ( i = 0; i < nVars; i++ )
162 Abc_BddUniqueCreate(
p, i, 1, 0 );
163 assert(
p->nObjs == nVars + 1 );
165 p->nUniqueMask + 1 +
p->nObjsAlloc +
166 (
p->nCacheMask + 1) * 3 *
sizeof(int)/4 +
167 p->nObjsAlloc * 2 *
sizeof(
int)/4;
172 printf(
"BDD stats: Var = %d Obj = %d Alloc = %d Hit = %d Miss = %d ",
173 p->nVars,
p->nObjs,
p->nObjsAlloc,
p->nCacheLookups-
p->nCacheMisses,
p->nCacheMisses );
174 printf(
"Mem = %.2f MB\n", 4.0*(
int)(
p->nMemory/(1<<20)) );
197 if ( a == 0 )
return 0;
198 if ( b == 0 )
return 0;
199 if ( a == 1 )
return b;
200 if ( b == 1 )
return a;
201 if ( a == b )
return a;
203 if ( (r = Abc_BddCacheLookup(
p, a, b)) >= 0 )
205 if ( Abc_BddVar(
p, a) < Abc_BddVar(
p, b) )
208 else if ( Abc_BddVar(
p, a) > Abc_BddVar(
p, b) )
214 r = Abc_BddUniqueCreate(
p, Abc_MinInt(Abc_BddVar(
p, a), Abc_BddVar(
p, b)), r1, r0 );
215 return Abc_BddCacheInsert(
p, a, b, r );
219 return Abc_LitNot(
Abc_BddAnd(
p, Abc_LitNot(a), Abc_LitNot(b)) );
237 if ( Abc_BddMark(
p, i) )
239 Abc_BddSetMark(
p, i, 1 );
246 if ( !Abc_BddMark(
p, i) )
248 Abc_BddSetMark(
p, i, 0 );
298 for ( i = 0; i <
p->nVars; i++ )
299 if ( pPath[i] == 0 || pPath[i] == 1 )
300 printf(
"%c%d", pPath[i] ?
'+' :
'-', i );
304 pPath[Abc_BddVar(
p, a)] = 0;
306 pPath[Abc_BddVar(
p, a)] = 1;
308 pPath[Abc_BddVar(
p, a)] = -1;
313 printf(
"BDD %d = ", a );
320 int bVarA = Abc_BddIthVar(0);
321 int bVarB = Abc_BddIthVar(1);
322 int bVarC = Abc_BddIthVar(2);
323 int bVarD = Abc_BddIthVar(3);
357 Gia_ManConst0(pGia)->Value = 0;
359 pObj->
Value = Abc_BddIthVar( i );
360 vNodes = Vec_IntAlloc( Gia_ManAndNum(pGia) );
363 int Cof0 = Abc_LitNotCond(Gia_ObjFanin0(pObj)->Value, Gia_ObjFaninC0(pObj));
364 int Cof1 = Abc_LitNotCond(Gia_ObjFanin1(pObj)->Value, Gia_ObjFaninC1(pObj));
368 pObj->
Value = Abc_LitNotCond(Gia_ObjFanin0(pObj)->Value, Gia_ObjFaninC0(pObj));
373 Vec_IntPush( vNodes, pObj->
Value );
376 Vec_IntFree( vNodes );
#define ABC_FALLOC(type, num)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
#define Gia_ManForEachAnd(p, pObj, i)
struct Gia_Obj_t_ Gia_Obj_t
void Gia_ManFillValue(Gia_Man_t *p)
struct Gia_Man_t_ Gia_Man_t
#define Gia_ManForEachCo(p, pObj, i)
#define Gia_ManForEachCi(p, pObj, i)
unsigned __int64 word
DECLARATIONS ///.
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.