47 return Vec_WrdEntryP(
p->vSims,
p->nSimWords * iObj );
49static inline void Wlc_ObjSimPi(
Gia_Man_t *
p,
int iObj )
52 word * pSim = Wlc_ObjSim(
p, iObj );
53 for ( w = 0; w <
p->nSimWords; w++ )
57static inline void Wlc_ObjSimRo(
Gia_Man_t *
p,
int iObj )
60 word * pSimRo = Wlc_ObjSim(
p, iObj );
61 word * pSimRi = Wlc_ObjSim(
p, Gia_ObjRoToRiId(
p, iObj) );
62 for ( w = 0; w <
p->nSimWords; w++ )
63 pSimRo[w] = pSimRi[w];
65static inline void Wlc_ObjSimCo(
Gia_Man_t *
p,
int iObj )
69 word * pSimCo = Wlc_ObjSim(
p, iObj );
70 word * pSimDri = Wlc_ObjSim(
p, Gia_ObjFaninId0(pObj, iObj) );
71 if ( Gia_ObjFaninC0(pObj) )
72 for ( w = 0; w <
p->nSimWords; w++ )
73 pSimCo[w] = ~pSimDri[w];
75 for ( w = 0; w <
p->nSimWords; w++ )
76 pSimCo[w] = pSimDri[w];
78static inline void Wlc_ObjSimAnd(
Gia_Man_t *
p,
int iObj )
82 word * pSim = Wlc_ObjSim(
p, iObj );
83 word * pSim0 = Wlc_ObjSim(
p, Gia_ObjFaninId0(pObj, iObj) );
84 word * pSim1 = Wlc_ObjSim(
p, Gia_ObjFaninId1(pObj, iObj) );
85 if ( Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
86 for ( w = 0; w <
p->nSimWords; w++ )
87 pSim[w] = ~pSim0[w] & ~pSim1[w];
88 else if ( Gia_ObjFaninC0(pObj) && !Gia_ObjFaninC1(pObj) )
89 for ( w = 0; w <
p->nSimWords; w++ )
90 pSim[w] = ~pSim0[w] & pSim1[w];
91 else if ( !Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
92 for ( w = 0; w <
p->nSimWords; w++ )
93 pSim[w] = pSim0[w] & ~pSim1[w];
95 for ( w = 0; w <
p->nSimWords; w++ )
96 pSim[w] = pSim0[w] & pSim1[w];
112 int i, iFanin, Count = 0;
113 if ( Wlc_ObjIsCi(pObj) )
120 Vec_IntPush( vObjs, Wlc_ObjId(
p, pObj) );
130 if ( (i & 1) == fEven )
152 int nWords = Vec_MemEntrySize(vTtMem);
153 int nBits = Wlc_ObjRange(pWlcObj);
154 int iFirst = Vec_IntEntry( &
p->vCopies, Wlc_ObjId(
p, pWlcObj) );
155 for ( k = 0; k < nBits; k++ )
157 int iLit = Vec_IntEntry( &
p->vBits, iFirst + k );
158 word * pInfoObj = Wlc_ObjSim( pGia, Abc_Lit2Var(iLit) );
159 int fCompl = pInfoObj[0] & 1;
160 if ( fCompl ) Abc_TtNot( pInfoObj,
nWords );
161 Entry = Vec_MemHashInsert( vTtMem, pInfoObj );
162 if ( fCompl ) Abc_TtNot( pInfoObj,
nWords );
163 printf(
"%2d(%d) ", Entry, fCompl ^ Abc_LitIsCompl(iLit) );
172 int nWords = Vec_MemEntrySize(vTtMem);
173 int nBits = Wlc_ObjRange(pWlcObj);
174 int iFirst = Vec_IntEntry( &
p->vCopies, Wlc_ObjId(
p, pWlcObj) );
175 for ( k = 0; k < nBits; k++ )
177 int iLit = Vec_IntEntry( &
p->vBits, iFirst + k );
178 word * pInfoObj = Wlc_ObjSim( pGia, Abc_Lit2Var(iLit) );
179 int fCompl = pInfoObj[0] & 1;
180 if ( fCompl ) Abc_TtNot( pInfoObj,
nWords );
181 Entry = *Vec_MemHashLookup( vTtMem, pInfoObj );
183 printf(
"Obj %4d. Range = %2d. Bit %2d. Entry %d(%d). %s\n", Wlc_ObjId(
p, pWlcObj), Wlc_ObjRange(pWlcObj), k, Entry, fCompl ^ Abc_LitIsCompl(iLit),
Wlc_ObjName(
p, Wlc_ObjId(
p, pWlcObj)) );
184 if ( fCompl ) Abc_TtNot( pInfoObj,
nWords );
206 int i, nMultiLHS, nMultiRHS;
215 Vec_MemHashAlloc( vTtMem, 10000 );
218 if ( nMultiLHS == 0 && nMultiRHS == 0 )
220 printf(
"No multipliers are present.\n" );
224 if ( nMultiLHS > 0 && nMultiRHS > 0 )
226 printf(
"Multipliers are present in both sides of the miter.\n" );
233 ABC_SWAP(
int, nMultiLHS, nMultiRHS );
239 Vec_WrdFreeP( &pGia->
vSims );
240 pGia->
vSims = Vec_WrdStart( Gia_ManObjNum(pGia) *
nWords );
246 if ( Gia_ObjIsAnd(pObj) )
247 Wlc_ObjSimAnd( pGia, i );
248 else if ( Gia_ObjIsCo(pObj) )
249 Wlc_ObjSimCo( pGia, i );
250 else if ( Gia_ObjIsCi(pObj) )
251 Wlc_ObjSimPi( pGia, i );
256 pInfoObj = Wlc_ObjSim( pGia, 0 );
257 Vec_MemHashInsert( vTtMem, pInfoObj );
275 Vec_MemHashFree( vTtMem );
276 Vec_MemFreeP( &vTtMem );
279 Vec_WrdFreeP( &pGia->
vSims );
282 Vec_IntFree( vObjsLHS );
283 Vec_IntFree( vObjsRHS );
305 word Msk = 0xFFFFFFFF;
306 word pL = (a & Msk) * (b & Msk);
307 word pM1 = (a & Msk) * (b >> 32);
308 word pM2 = (a >> 32) * (b & Msk);
309 word pH = (a >> 32) * (b >> 32);
310 word Car = (pM1 & Msk) + (pM2 & Msk) + (pL >> 32);
312 r[1] = pH + (pM1 >> 32) + (pM2 >> 32) + (Car >> 32);
316 word a, b, r[2], Mask = Abc_Tt6Mask(nIns);
int i, k;
317 for ( i = 0; i < 64; i++ )
318 A[i] = B[i] = R[i] = R[i+64] = 0;
320 for ( i = 0; i < 64; i++ )
325 for ( k = 0; k < 64; k++ )
327 if ( (a >> k) & 1 ) A[k] |= ((
word)1 << i);
328 if ( (b >> k) & 1 ) B[k] |= ((
word)1 << i);
329 if ( (r[0] >> k) & 1 ) R[k] |= ((
word)1 << i);
330 if ( (r[1] >> k) & 1 ) R[k+64] |= ((
word)1 << i);
352 Vec_Int_t * vGia2Out = Vec_IntStartFull( Gia_ManObjNum(
p) );
353 Gia_Obj_t * pObj;
int i, Entry, nIns = Vec_IntSize(vIns)/2;
354 word A[64], B[64], R[128], * pInfoObj;
word Temp;
358 Vec_MemHashAlloc( vTtMem, 1000 );
360 for ( i = 0; i < 2*nIns; i++ )
362 Vec_MemHashInsert( vTtMem, R+i );
366 assert( Vec_MemEntryNum(vTtMem) == 2*nIns );
369 Vec_WrdFreeP( &
p->vSims );
370 p->vSims = Vec_WrdStart( Gia_ManObjNum(
p) *
nWords );
375 Gia_ObjSetTravIdCurrentId(
p, 0 );
378 Gia_ObjSetTravIdCurrent(
p, pObj );
383 assert( Vec_IntSize(vIns) % 2 == 0 );
386 Gia_ObjSetTravIdCurrent(
p, pObj );
387 pInfoObj = Wlc_ObjSim(
p, Gia_ObjId(
p, pObj) );
388 *pInfoObj = i < nIns ? A[i] : B[i - nIns];
394 if ( Gia_ObjIsTravIdCurrent(
p, pObj) )
397 if ( Gia_ObjIsAnd(pObj) )
398 Wlc_ObjSimAnd(
p, i );
399 else if ( Gia_ObjIsCo(pObj) )
400 Wlc_ObjSimCo(
p, i );
404 pInfoObj = Wlc_ObjSim(
p, i );
405 Entry = *Vec_MemHashLookup( vTtMem, pInfoObj );
408 Vec_IntWriteEntry( vGia2Out, i, Abc_Var2Lit(Entry, 0) );
414 Abc_TtNot( pInfoObj,
nWords );
415 Entry = *Vec_MemHashLookup( vTtMem, pInfoObj );
416 Abc_TtNot( pInfoObj,
nWords );
417 assert( Temp == *pInfoObj );
420 Vec_IntWriteEntry( vGia2Out, i, Abc_Var2Lit(Entry, 1) );
427 pInfoObj = Wlc_ObjSim(
p, Gia_ObjId(
p, pObj) );
433 Vec_MemHashFree( vTtMem );
434 Vec_MemFreeP( &vTtMem );
441 Wlc_Obj_t * pObj;
int i, k, iGiaLit, iFirst, nBits;
443 Vec_Int_t * vMap = Vec_IntStartFull( Gia_ManObjNum(
p) );
446 Vec_IntWriteEntry( vMap, Abc_Lit2Var(iGiaLit), Abc_Var2Lit(i, Abc_LitIsCompl(iGiaLit)) );
449 iFirst = Vec_IntEntry( &pNtk->
vCopies, i );
450 nBits = Wlc_ObjRange(pObj);
451 for ( k = 0; k < nBits; k++ )
453 int iLitGia = Vec_IntEntry( &pNtk->
vBits, iFirst + k );
454 int iLitOut = Vec_IntEntry( vMap, Abc_Lit2Var(iLitGia) );
457 Vec_IntWriteEntry( vMap, Abc_Lit2Var(iLitGia), -1 );
458 iLitOut = Abc_LitNotCond( iLitOut, Abc_LitIsCompl(iLitGia) );
459 printf(
"Matched out %d in phase %d with object %d (%s) bit %d (out of %d).\n", Abc_Lit2Var(iLitOut), Abc_LitIsCompl(iLitOut), i,
Wlc_ObjName(pNtk, Wlc_ObjId(pNtk, pObj)), k, nBits );
460 Vec_IntPushUnique( vRes, i );
464 Vec_IntSort( vRes, 0 );
466 pObj = Wlc_NtkObj( pNtk, Vec_IntEntryLast(vRes) );
467 iFirst = Vec_IntEntry( &pNtk->
vCopies, Wlc_ObjId(pNtk, pObj) );
468 nBits = Wlc_ObjRange(pObj);
469 printf(
"Considering object %d (%s):\n", Wlc_ObjId(pNtk, pObj),
Wlc_ObjName(pNtk, Wlc_ObjId(pNtk, pObj)) );
470 for ( k = 0; k < nBits; k++ )
472 int iLitGia = Vec_IntEntry( &pNtk->
vBits, iFirst + k );
473 int iLitOutP = Vec_IntFind( vGiaLits, iLitGia );
474 int iLitOutN = Vec_IntFind( vGiaLits, Abc_LitNot(iLitGia) );
475 printf(
"Matching bit %d with output %d / %d.\n", k, iLitOutP, iLitOutN );
478 word * pInfoObj = Wlc_ObjSim(
p, Abc_Lit2Var(iLitGia) );
479 Extra_PrintHex( stdout, (
unsigned *)pInfoObj, 6 ); printf(
"\n" );
487 int i, k, iLitGia, iLitOut, iFirst, nBits, iObjFound = -1;
488 Vec_Int_t * vMatched = Vec_IntAlloc( 100 );
491 iFirst = Vec_IntEntry( &pNtk->
vCopies, i );
492 nBits = Wlc_ObjRange(pObj);
493 Vec_IntClear( vMatched );
494 for ( k = 0; k < nBits; k++ )
496 iLitGia = Vec_IntEntry( &pNtk->
vBits, iFirst + k );
497 iLitOut = Vec_IntEntry( vGia2Out, Abc_Lit2Var(iLitGia) );
500 iLitOut = Abc_LitNotCond( iLitOut, Abc_LitIsCompl(iLitGia) );
501 printf(
"Matched node %5d (%10s) bit %3d (out of %3d) with output %3d(%d).\n",
502 i,
Wlc_ObjName(pNtk, Wlc_ObjId(pNtk, pObj)), k, nBits, Abc_Lit2Var(iLitOut), Abc_LitIsCompl(iLitOut) );
503 Vec_IntPushOrder( vMatched, Abc_Lit2Var(iLitOut) );
505 if ( Vec_IntSize(vMatched) > 0 )
507 if ( Vec_IntSize(vMatched) == nOuts )
509 if ( iObjFound == -1 )
511 printf(
"Found object %d with all bits matched.\n", i );
525 Vec_IntFree( vMatched );
551 if ( vIns == NULL || Vec_IntSize(vIns) == 0 || (Vec_IntSize(vIns) % 2) != 0 )
553 printf(
"Input identification did not work out.\n" );
561 Vec_IntFree( vGia2Out );
#define ABC_SWAP(Type, a, b)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Vec_Int_t * Sdb_StoComputeCutsDetect(Gia_Man_t *pGia)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
void Gia_ManStop(Gia_Man_t *p)
word Gia_ManRandomW(int fReset)
struct Gia_Obj_t_ Gia_Obj_t
struct Gia_Man_t_ Gia_Man_t
#define Gia_ManForEachObj1(p, pObj, i)
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
void Gia_ManIncrementTravId(Gia_Man_t *p)
#define Gia_ManForEachCo(p, pObj, i)
#define Gia_ManForEachCi(p, pObj, i)
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
unsigned __int64 word
DECLARATIONS ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Wlc_Ntk_t * Wlc_NtkGraftMulti(Wlc_Ntk_t *p, int fVerbose)
void Sbc_ManDetectMultTest(Wlc_Ntk_t *pNtk, int fVerbose)
void Wlc_NtkFindOneNode(Wlc_Ntk_t *p, Wlc_Obj_t *pWlcObj, Gia_Man_t *pGia, Vec_Mem_t *vTtMem)
Vec_Int_t * Sbc_ManDetectMult(Gia_Man_t *p, Vec_Int_t *vIns)
Vec_Int_t * Wlc_NtkCollectObjs(Wlc_Ntk_t *p, int fEven, int *pCount)
void Wlc_NtkSaveOneNode(Wlc_Ntk_t *p, Wlc_Obj_t *pWlcObj, Gia_Man_t *pGia, Vec_Mem_t *vTtMem)
void Sbc_Mult(word a, word b, word r[2])
int Sbc_ManWlcNodes(Wlc_Ntk_t *pNtk, Gia_Man_t *p, Vec_Int_t *vGia2Out, int nOuts)
int Wlc_NtkCollectObjs_rec(Wlc_Ntk_t *p, Wlc_Obj_t *pObj, Vec_Int_t *vObjs)
void Sbc_SimMult(word A[64], word B[64], word R[128], int nIns)
Vec_Int_t * Sbc_ManWlcNodes2(Wlc_Ntk_t *pNtk, Gia_Man_t *p, Vec_Int_t *vGiaLits)
Gia_Man_t * Wlc_NtkBitBlast(Wlc_Ntk_t *p, Wlc_BstPar_t *pPars)
void Wlc_NtkCleanMarks(Wlc_Ntk_t *p)
#define Wlc_NtkForEachObjVec(vVec, p, pObj, i)
struct Wlc_Ntk_t_ Wlc_Ntk_t
#define Wlc_NtkForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
#define Wlc_ObjForEachFanin(pObj, iFanin, i)
char * Wlc_ObjName(Wlc_Ntk_t *p, int iObj)
struct Wlc_Obj_t_ Wlc_Obj_t
BASIC TYPES ///.
#define Wlc_NtkForEachCo(p, pCo, i)