21#ifndef ABC__map__if__if_Count_h
22#define ABC__map__if__if_Count_h
57static inline int If_LogCreateAnd(
Vec_Int_t * vAig,
int iLit0,
int iLit1,
int nSuppAll )
59 int iObjId = Vec_IntSize(vAig)/2 + nSuppAll;
60 assert( Abc_Lit2Var(iLit0) != Abc_Lit2Var(iLit1) );
61 Vec_IntPush( vAig, iLit0 );
62 Vec_IntPush( vAig, iLit1 );
63 return Abc_Var2Lit( iObjId, 0 );
65static inline int If_LogCreateMux(
Vec_Int_t * vAig,
int iLitC,
int iLit1,
int iLit0,
int nSuppAll )
67 int iFanLit0 = If_LogCreateAnd( vAig, iLitC, iLit1, nSuppAll );
68 int iFanLit1 = If_LogCreateAnd( vAig, Abc_LitNot(iLitC), iLit0, nSuppAll );
69 int iResLit = If_LogCreateAnd( vAig, Abc_LitNot(iFanLit0), Abc_LitNot(iFanLit1), nSuppAll );
70 return Abc_LitNot(iResLit);
72static inline int If_LogCreateXor(
Vec_Int_t * vAig,
int iLit0,
int iLit1,
int nSuppAll )
74 return If_LogCreateMux( vAig, iLit0, Abc_LitNot(iLit1), iLit1, nSuppAll );
76static inline int If_LogCreateAndXor(
Vec_Int_t * vAig,
int iLit0,
int iLit1,
int nSuppAll,
int fXor )
78 return fXor ? If_LogCreateXor(vAig, iLit0, iLit1, nSuppAll) : If_LogCreateAnd(vAig, iLit0, iLit1, nSuppAll);
80static inline int If_LogCreateAndXorMulti(
Vec_Int_t * vAig,
int * pFaninLits,
int nFanins,
int nSuppAll,
int fXor )
84 for ( i = nFanins - 1; i > 0; i-- )
85 pFaninLits[i-1] = If_LogCreateAndXor( vAig, pFaninLits[i], pFaninLits[i-1], nSuppAll, fXor );
88static inline int If_LogCounterAddAig(
int * pTimes,
int * pnTimes,
int * pFaninLits,
int Num,
int iLit,
Vec_Int_t * vAig,
int nSuppAll,
int fXor,
int fXorFunc )
90 int nTimes = *pnTimes;
92 pFaninLits[nTimes] = iLit;
93 pTimes[nTimes++] = Num;
97 for ( k = nTimes-1; k > 0; k-- )
99 if ( pTimes[k] < pTimes[k-1] )
101 if ( pTimes[k] > pTimes[k-1] )
103 ABC_SWAP(
int, pTimes[k], pTimes[k-1] );
105 ABC_SWAP(
int, pFaninLits[k], pFaninLits[k-1] );
108 pTimes[k-1] += 1 + fXor;
110 pFaninLits[k-1] = If_LogCreateAndXor( vAig, pFaninLits[k], pFaninLits[k-1], nSuppAll, fXorFunc );
111 for ( nTimes--, i = k; i < nTimes; i++ )
113 pTimes[i] = pTimes[i+1];
115 pFaninLits[i] = pFaninLits[i+1];
121 return pTimes[0] + (nTimes > 1 ? 1 + fXor : 0);
123static inline int If_LogCounterDelayXor(
int * pTimes,
int nTimes )
127 for ( i = nTimes - 1; i > 0; i-- )
128 pTimes[i-1] = 2 + Abc_MaxInt( pTimes[i], pTimes[i-1] );
144static inline int If_CutPinDelayGet(
word D,
int v ) {
assert(v >= 0 && v < 16);
return (
int)((D >> (v << 2)) & 0xF); }
145static inline void If_CutPinDelaySet(
word * pD,
int v,
int d ) {
assert(v >= 0 && v < 16);
assert(d >= 0 && d < 16); *pD |= ((
word)d << (v << 2)); }
146static inline word If_CutPinDelayInit(
int v ) {
assert(v >= 0 && v < 16);
return (
word)1 << (v << 2); }
147static inline word If_CutPinDelayMax(
word D1,
word D2,
int nVars,
int AddOn )
151 for ( v = 0; v < nVars; v++ )
152 if ( (Max = Abc_MaxInt(If_CutPinDelayGet(D1, v), If_CutPinDelayGet(D2, v))) )
153 If_CutPinDelaySet( &D, v, Abc_MinInt(Max + AddOn, 15) );
156static inline word If_CutPinDelayDecrement(
word D1,
int nVars )
160 for ( v = 0; v < nVars; v++ )
161 if ( If_CutPinDelayGet(D1, v) )
162 If_CutPinDelaySet( &D, v, If_CutPinDelayGet(D1, v) - 1 );
165static inline int If_CutPinDelayEqual(
word D1,
word D2,
int nVars )
168 for ( v = 0; v < nVars; v++ )
169 if ( If_CutPinDelayGet(D1, v) != If_CutPinDelayGet(D2, v) )
173static inline int If_CutPinDelayDom(
word D1,
word D2,
int nVars )
176 for ( v = 0; v < nVars; v++ )
177 if ( If_CutPinDelayGet(D1, v) > If_CutPinDelayGet(D2, v) )
181static inline void If_CutPinDelayTranslate(
word D,
int nVars,
char * pPerm )
184 for ( v = 0; v < nVars; v++ )
186 Delay = If_CutPinDelayGet(D, v);
188 pPerm[v] = Delay - 1;
191static inline void If_CutPinDelayPrint(
word D,
int nVars )
194 printf(
"Delay profile = {" );
195 for ( v = 0; v < nVars; v++ )
196 printf(
" %d", If_CutPinDelayGet(D, v) );
199static inline int If_LogCounterPinDelays(
int * pTimes,
int * pnTimes,
word * pPinDels,
int Num,
word PinDel,
int nSuppAll,
int fXor )
201 int nTimes = *pnTimes;
202 pPinDels[nTimes] = PinDel;
203 pTimes[nTimes++] = Num;
207 for ( k = nTimes-1; k > 0; k-- )
209 if ( pTimes[k] < pTimes[k-1] )
211 if ( pTimes[k] > pTimes[k-1] )
213 ABC_SWAP(
int, pTimes[k], pTimes[k-1] );
217 pTimes[k-1] += 1 + fXor;
218 pPinDels[k-1] = If_CutPinDelayMax( pPinDels[k], pPinDels[k-1], nSuppAll, 1 + fXor );
219 for ( nTimes--, i = k; i < nTimes; i++ )
221 pTimes[i] = pTimes[i+1];
222 pPinDels[i] = pPinDels[i+1];
228 return pTimes[0] + (nTimes > 1 ? 1 + fXor : 0);
230static inline word If_LogPinDelaysMulti(
word * pPinDels,
int nFanins,
int nSuppAll,
int fXor )
234 for ( i = nFanins - 1; i > 0; i-- )
235 pPinDels[i-1] = If_CutPinDelayMax( pPinDels[i], pPinDels[i-1], nSuppAll, 1 + fXor );
251static inline word If_AigVerifyArray(
Vec_Int_t * vAig,
int nLeaves )
253 assert( Vec_IntSize(vAig) > 0 );
254 assert( Vec_IntEntryLast(vAig) < 2 );
255 if ( Vec_IntSize(vAig) == 1 )
256 return Vec_IntEntry(vAig, 0) ? ~((
word)0) : 0;
257 if ( Vec_IntSize(vAig) == 2 )
259 assert( Vec_IntEntry(vAig, 0) == 0 );
260 return Vec_IntEntry(vAig, 1) ? ~s_Truths6[0] : s_Truths6[0];
264 word Truth0 = 0, Truth1 = 0, TruthR;
265 int i, iVar0, iVar1, iLit0, iLit1;
266 assert( Vec_IntSize(vAig) & 1 );
269 iVar0 = Abc_Lit2Var( iLit0 );
270 iVar1 = Abc_Lit2Var( iLit1 );
271 Truth0 = iVar0 < nLeaves ? s_Truths6[iVar0] : Vec_WrdEntry( (
Vec_Wrd_t *)vAig, iVar0 - nLeaves );
272 Truth1 = iVar1 < nLeaves ? s_Truths6[iVar1] : Vec_WrdEntry( (
Vec_Wrd_t *)vAig, iVar1 - nLeaves );
273 if ( Abc_LitIsCompl(iLit0) )
275 if ( Abc_LitIsCompl(iLit1) )
278 Vec_WrdWriteEntry( (
Vec_Wrd_t *)vAig, Abc_Lit2Var(i), Truth0 & Truth1 );
280 assert( i == Vec_IntSize(vAig) - 1 );
281 TruthR = Truth0 & Truth1;
282 if ( Vec_IntEntry(vAig, i) )
284 Vec_IntClear( vAig );
300static inline void If_AigPrintArray(
Vec_Int_t * vAig,
int nLeaves )
302 assert( Vec_IntSize(vAig) > 0 );
303 assert( Vec_IntEntryLast(vAig) < 2 );
304 if ( Vec_IntSize(vAig) == 1 )
305 printf(
"Const %d\n", Vec_IntEntry(vAig, 0) );
306 else if ( Vec_IntSize(vAig) == 2 )
307 printf(
"Variable %s\n", Vec_IntEntry(vAig, 1) ?
"Compl" :
"" );
311 assert( Vec_IntSize(vAig) & 1 );
313 printf(
"%d %d\n", iLit0, iLit1 );
314 assert( i == Vec_IntSize(vAig) - 1 );
315 printf(
"%s\n", Vec_IntEntry(vAig, i) ?
"Compl" :
"" );
331static inline int If_LogCounter64Eval(
word Count )
333 int n = ((Count & (Count - 1)) > 0) ? -1 : 0;
335 if ( (Count &
ABC_CONST(0xFFFFFFFF00000000)) == 0 ) { n += 32; Count <<= 32; }
336 if ( (Count &
ABC_CONST(0xFFFF000000000000)) == 0 ) { n += 16; Count <<= 16; }
337 if ( (Count &
ABC_CONST(0xFF00000000000000)) == 0 ) { n += 8; Count <<= 8; }
338 if ( (Count &
ABC_CONST(0xF000000000000000)) == 0 ) { n += 4; Count <<= 4; }
339 if ( (Count &
ABC_CONST(0xC000000000000000)) == 0 ) { n += 2; Count <<= 2; }
340 if ( (Count &
ABC_CONST(0x8000000000000000)) == 0 ) { n++; }
343static word If_LogCounter64Add(
word Count,
int Num )
346 return Count + (((
word)1) << Num);
361static int If_LogCounter32Eval(
unsigned Count,
int Start )
363 int n = (Abc_LitIsCompl(Start) || (Count & (Count - 1)) > 0) ? -1 : 0;
365 if ( (Count & 0xFFFF0000) == 0 ) { n += 16; Count <<= 16; }
366 if ( (Count & 0xFF000000) == 0 ) { n += 8; Count <<= 8; }
367 if ( (Count & 0xF0000000) == 0 ) { n += 4; Count <<= 4; }
368 if ( (Count & 0xC0000000) == 0 ) { n += 2; Count <<= 2; }
369 if ( (Count & 0x80000000) == 0 ) { n++; }
370 return Abc_Lit2Var(Start) + 31 - n;
372static unsigned If_LogCounter32Add(
unsigned Count,
int * pStart,
int Num )
374 int Start = Abc_Lit2Var(*pStart);
380 if ( Num > Start + 16 )
382 int Shift = Num - (Start + 16);
383 if ( !Abc_LitIsCompl(*pStart) && (Shift >= 32 ? Count : Count & ~(~0 << Shift)) > 0 )
387 *pStart = Abc_Var2Lit( Start, Abc_LitIsCompl(*pStart) );
388 assert( Num <= Start + 16 );
390 return Count + (1 << (Num-Start));
454static inline int If_LogCounterAdd(
int * pTimes,
int * pnTimes,
int Num,
int fXor )
456 int nTimes = *pnTimes;
457 pTimes[nTimes++] = Num;
461 for ( k = nTimes-1; k > 0; k-- )
463 if ( pTimes[k] < pTimes[k-1] )
465 if ( pTimes[k] > pTimes[k-1] )
467 ABC_SWAP(
int, pTimes[k], pTimes[k-1] );
470 pTimes[k-1] += 1 + fXor;
471 for ( nTimes--, i = k; i < nTimes; i++ )
472 pTimes[i] = pTimes[i+1];
477 return pTimes[0] + (nTimes > 1 ? 1 + fXor : 0);
#define ABC_SWAP(Type, a, b)
#define ABC_CONST(number)
PARAMETERS ///.
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
unsigned __int64 word
DECLARATIONS ///.
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.