32static word Truth[8] = {
78#define Shr_ObjForEachFanout( p, iNode, iFan ) \
79 for ( iFan = Shr_ManFanIterStart(p, iNode); iFan; iFan = Shr_ManFanIterNext(p) )
101 p->nNewSize = 2 * Gia_ManObjNum(pGia);
103 p->vFanMem = Vec_WrdAlloc( 1000 ); Vec_WrdPush(
p->vFanMem, -1);
104 p->vObj2Fan = Vec_IntStart(
p->nNewSize );
105 p->vDivs = Vec_IntAlloc( 1000 );
106 p->vPrio = Vec_IntAlloc( 1000 );
107 p->vTruths = Vec_WrdStart(
p->nNewSize );
108 p->vDivTruths = Vec_WrdAlloc( 100 );
109 p->vDivResub = Vec_IntAlloc( 6 );
110 p->vLeaves = Vec_IntAlloc( 6 );
113 p->pNew->pName = Abc_UtilStrsav( pGia->
pName );
114 p->pNew->pSpec = Abc_UtilStrsav( pGia->
pSpec );
118 p->pNew->nObjs =
p->nNewSize;
122 p->Pars.nVarsMax = 6;
123 p->Pars.fVerbose = 0;
133 Vec_IntFreeP( &
p->pNew->vLevels );
137 if ( Gia_ManAndNum(
p->pNew) != Gia_ManAndNum(pTemp) )
138 printf(
"Node reduction after sweep %6d -> %6d.\n", Gia_ManAndNum(pTemp), Gia_ManAndNum(
p->pNew) );
142 pTemp =
p->pNew;
p->pNew = NULL;
147 Vec_WrdFree(
p->vFanMem );
148 Vec_IntFree(
p->vObj2Fan );
149 Vec_IntFree(
p->vDivs );
150 Vec_IntFree(
p->vPrio );
151 Vec_WrdFree(
p->vTruths );
152 Vec_WrdFree(
p->vDivTruths );
153 Vec_IntFree(
p->vDivResub );
154 Vec_IntFree(
p->vLeaves );
171static inline void Shr_ManAddFanout(
Shr_Man_t *
p,
int iFanin,
int iFanout )
177 FanStr.sFan.iFan = iFanout;
178 FanStr.sFan.Next = Vec_IntEntry(
p->vObj2Fan, iFanin);
179 Vec_IntWriteEntry(
p->vObj2Fan, iFanin, Vec_WrdSize(
p->vFanMem) );
180 Vec_WrdPush(
p->vFanMem, FanStr.sWord );
182static inline int Shr_ManFanIterStart(
Shr_Man_t *
p,
int iNode )
184 if ( Vec_IntEntry(
p->vObj2Fan, iNode) == 0 )
186 p->pFanTemp = (
Shr_Fan_t *)Vec_WrdEntryP(
p->vFanMem, Vec_IntEntry(
p->vObj2Fan, iNode) );
187 return p->pFanTemp->iFan;
189static inline int Shr_ManFanIterNext(
Shr_Man_t *
p )
191 if (
p->pFanTemp->Next == 0 )
193 p->pFanTemp = (
Shr_Fan_t *)Vec_WrdEntryP(
p->vFanMem,
p->pFanTemp->Next );
194 return p->pFanTemp->iFan;
208static inline int Shr_ManDivPushOrderByLevel(
Shr_Man_t *
p,
int iDiv )
210 int iPlace, * pArray;
211 Vec_IntPush(
p->vPrio, iDiv );
212 if ( Vec_IntSize(
p->vPrio) == 1 )
214 pArray = Vec_IntArray(
p->vPrio);
215 for ( iPlace = Vec_IntSize(
p->vPrio) - 1; iPlace > 0; iPlace-- )
216 if ( Gia_ObjLevel(
p->pNew, Gia_ManObj(
p->pNew, pArray[iPlace-1])) >
217 Gia_ObjLevel(
p->pNew, Gia_ManObj(
p->pNew, pArray[iPlace])) )
218 ABC_SWAP(
int, pArray[iPlace-1], pArray[iPlace] )
223static inline int Shr_ManCollectDivisors(
Shr_Man_t *
p,
Vec_Int_t * vLeaves,
int Limit,
int nFanoutMax )
226 int i, c, iDiv, iFan, iPlace;
228 Vec_IntClear(
p->vDivs );
229 Vec_IntClear(
p->vPrio );
233 Vec_IntPush(
p->vDivs, iDiv );
234 Shr_ManDivPushOrderByLevel(
p, iDiv );
235 Gia_ObjSetTravIdCurrentId(
p->pNew, iDiv );
240 assert( Gia_ObjIsTravIdCurrentId(
p->pNew, iDiv) );
243 if ( c++ == nFanoutMax )
245 if ( Gia_ObjIsTravIdCurrentId(
p->pNew, iFan) )
247 pFan = Gia_ManObj(
p->pNew, iFan );
248 assert( Gia_ObjIsAnd(pFan) );
249 assert( Gia_ObjLevel(
p->pNew, Gia_ManObj(
p->pNew, iDiv)) < Gia_ObjLevel(
p->pNew, pFan) );
250 if ( !Gia_ObjIsTravIdCurrentId(
p->pNew, Gia_ObjFaninId0(pFan, iFan)) ||
251 !Gia_ObjIsTravIdCurrentId(
p->pNew, Gia_ObjFaninId1(pFan, iFan)) )
253 Vec_IntPush(
p->vDivs, iFan );
254 Gia_ObjSetTravIdCurrentId(
p->pNew, iFan );
255 iPlace = Shr_ManDivPushOrderByLevel(
p, iFan );
257 if ( Vec_IntSize(
p->vDivs) == Limit )
258 return Vec_IntSize(
p->vDivs);
261 return Vec_IntSize(
p->vDivs);
279 int i, iVar, iLit, nNodes, iLast;
280 int nVars = Vec_IntSize(vLeafLits);
281 assert( uTruth1 != 0 && uTruthC != 0 );
282 Bdc_ManDecompose( pManDec, (
unsigned *)&uTruth1, (
unsigned *)&uTruthC, nVars, NULL, 1000 );
287 for ( i = nVars + 1; i < nNodes; i++ )
290 iLast = Gia_ManObjNum(pNew);
291 iLit =
Gia_ManHashAnd( pNew, Bdc_FunFanin0Copy(pFunc), Bdc_FunFanin1Copy(pFunc) );
293 if ( iLast == Gia_ManObjNum(pNew) )
295 assert( iLast + 1 == Gia_ManObjNum(pNew) );
296 pObj = Gia_ManObj(pNew, Abc_Lit2Var(iLit));
297 Gia_ObjSetAndLevel( pNew, pObj );
298 Shr_ManAddFanout(
p, Gia_ObjFaninId0p(pNew, pObj), Gia_ObjId(pNew, pObj) );
299 Shr_ManAddFanout(
p, Gia_ObjFaninId1p(pNew, pObj), Gia_ObjId(pNew, pObj) );
300 assert( Gia_ManObjNum(pNew) <
p->nNewSize );
321 if ( Gia_ObjIsTravIdCurrentId(
p, iNode) )
322 return Vec_WrdEntry(vTruths, iNode);
323 Gia_ObjSetTravIdCurrentId(
p, iNode);
324 pObj = Gia_ManObj(
p, iNode );
325 assert( Gia_ObjIsAnd(pObj) );
328 if ( Gia_ObjFaninC0(pObj) )
330 if ( Gia_ObjFaninC1(pObj) )
332 Vec_WrdWriteEntry( vTruths, iNode, Truth0 & Truth1 );
333 return Truth0 & Truth1;
338 assert( Gia_ObjIsAnd(pObj) );
342 Gia_ObjSetTravIdCurrentId(
p, iLeaf );
343 Vec_WrdWriteEntry( vTruths, iLeaf, Truth[i] );
364 Vec_WrdClear( vDivTruths );
367 Vec_WrdWriteEntry( vTruths, iDiv, Truth[i] );
368 Vec_WrdPush( vDivTruths, Truth[i] );
372 pObj = Gia_ManObj(
p, iDiv );
373 Truth0 = Vec_WrdEntry( vTruths, Gia_ObjFaninId0(pObj, iDiv) );
374 Truth1 = Vec_WrdEntry( vTruths, Gia_ObjFaninId1(pObj, iDiv) );
375 if ( Gia_ObjFaninC0(pObj) )
377 if ( Gia_ObjFaninC1(pObj) )
379 Vec_WrdWriteEntry( vTruths, iDiv, Truth0 & Truth1 );
380 Vec_WrdPush( vDivTruths, Truth0 & Truth1 );
405 word uTruth, uTruth0, uTruth1;
406 int i, k, nDivs, iNode;
407 int RetValue, Counter1 = 0, Counter2 = 0;
408 abctime clk2, clk = Abc_Clock();
410 assert( Gia_ManHasMapping(
p) );
413 Gia_ManConst0(
p)->Value = 0;
416 if ( Gia_ObjIsCi(pObj) )
418 pObj->
Value = Gia_ManAppendCi( pMan->
pNew );
420 Gia_ObjSetLevel( pMan->
pNew, Gia_ObjFromLit(pMan->
pNew, Gia_ObjValue(pObj)), Gia_ObjLevel(
p, pObj) );
422 else if ( Gia_ObjIsCo(pObj) )
424 pObj->
Value = Gia_ManAppendCo( pMan->
pNew, Gia_ObjFanin0Copy(pObj) );
426 else if ( Gia_ObjIsLut(
p, i) )
431 Vec_IntPush( pMan->
vLeaves, iNode );
436 if ( uTruth == 0 || ~uTruth == 0 )
437 pObj->
Value = Abc_LitNotCond( 0, ~uTruth == 0 );
440 if ( uTruth == Truth[k] || ~uTruth == Truth[k] )
441 pObj->
Value = Abc_LitNotCond( pFanin->
Value, ~uTruth == Truth[k] );
442 if ( pObj->
Value != ~0 )
447 if ( Abc_LitIsCompl(pFanin->
Value) )
448 uTruth = ((uTruth & Truth[k]) >> (1 << k)) | ((uTruth & ~Truth[k]) << (1 << k));
449 Vec_IntWriteEntry( pMan->
vLeaves, k, Abc_Lit2Var(pFanin->
Value) );
453 nDivs = Shr_ManCollectDivisors( pMan, pMan->
vLeaves, pMan->
nDivMax, nFanoutMax );
454 assert( nDivs <= pMan->nDivMax );
455 timeFanout += Abc_Clock() - clk2;
478 printf(
"Performed %d resubs and %d decomps. ", Counter1, Counter2 );
479 printf(
"Gain in AIG nodes = %d. ", Gia_ManObjNum(
p)-Gia_ManObjNum(pMan->
pNew) );
480 ABC_PRT(
"Runtime", Abc_Clock() - clk );
#define ABC_SWAP(Type, a, b)
#define ABC_CALLOC(type, num)
#define ABC_CONST(number)
PARAMETERS ///.
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
int Bdc_ManNodeNum(Bdc_Man_t *p)
void Bdc_FuncSetCopyInt(Bdc_Fun_t *p, int iCopy)
Bdc_Fun_t * Bdc_ManRoot(Bdc_Man_t *p)
typedefABC_NAMESPACE_HEADER_START struct Bdc_Fun_t_ Bdc_Fun_t
INCLUDES ///.
struct Bdc_Par_t_ Bdc_Par_t
struct Bdc_Man_t_ Bdc_Man_t
void Bdc_ManFree(Bdc_Man_t *p)
int Bdc_ManDecompose(Bdc_Man_t *p, unsigned *puFunc, unsigned *puCare, int nVars, Vec_Ptr_t *vDivs, int nNodesMax)
Bdc_Fun_t * Bdc_ManFunc(Bdc_Man_t *p, int i)
DECLARATIONS ///.
Bdc_Man_t * Bdc_ManAlloc(Bdc_Par_t *pPars)
MACRO DEFINITIONS ///.
word Shr_ManComputeTruth6_rec(Gia_Man_t *p, int iNode, Vec_Wrd_t *vTruths)
#define Shr_ObjForEachFanout(p, iNode, iFan)
struct Shr_Fan_t_ Shr_Fan_t
void Shr_ManComputeTruths(Gia_Man_t *p, int nVars, Vec_Int_t *vDivs, Vec_Wrd_t *vDivTruths, Vec_Wrd_t *vTruths)
word Shr_ManComputeTruth6(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vLeaves, Vec_Wrd_t *vTruths)
Gia_Man_t * Shr_ManFree(Shr_Man_t *p)
Shr_Man_t * Shr_ManAlloc(Gia_Man_t *pGia)
FUNCTION DEFINITIONS ///.
int Shr_ObjPerformBidec(Shr_Man_t *p, Bdc_Man_t *pManDec, Gia_Man_t *pNew, Vec_Int_t *vLeafLits, word uTruth1, word uTruthC)
struct Shr_Man_t_ Shr_Man_t
Gia_Man_t * Gia_ManMapShrink6(Gia_Man_t *p, int nFanoutMax, int fKeepLevel, int fVerbose)
void Gia_ManStop(Gia_Man_t *p)
int Gia_ManHasDangling(Gia_Man_t *p)
void Gia_ManStopP(Gia_Man_t **p)
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
void Gia_ManHashAlloc(Gia_Man_t *p)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
struct Gia_Obj_t_ Gia_Obj_t
#define Gia_LutForEachFanin(p, i, iFan, k)
void Gia_ManFillValue(Gia_Man_t *p)
struct Gia_Man_t_ Gia_Man_t
#define Gia_ManForEachObj1(p, pObj, i)
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
void Gia_ManCleanLevels(Gia_Man_t *p, int Size)
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
void Gia_ManIncrementTravId(Gia_Man_t *p)
void Gia_ManHashStop(Gia_Man_t *p)
unsigned __int64 word
DECLARATIONS ///.
Rsb_Man_t * Rsb_ManAlloc(int nLeafMax, int nDivMax, int nDecMax, int fVerbose)
MACRO DEFINITIONS ///.
void Rsb_ManFree(Rsb_Man_t *p)
int Rsb_ManPerformResub6(Rsb_Man_t *p, int nVars, word uTruth, Vec_Wrd_t *vDivTruths, word *puTruth0, word *puTruth1, int fVerbose)
Vec_Int_t * Rsb_ManGetFanins(Rsb_Man_t *p)
typedefABC_NAMESPACE_HEADER_START struct Rsb_Man_t_ Rsb_Man_t
INCLUDES ///.
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryStop(vVec, Entry, i, Stop)
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.