ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaShrink6.c File Reference
#include "gia.h"
#include "bool/bdc/bdc.h"
#include "bool/rsb/rsb.h"
Include dependency graph for giaShrink6.c:

Go to the source code of this file.

Classes

struct  Shr_Fan_t_
 
struct  Shr_Man_t_
 

Macros

#define Shr_ObjForEachFanout(p, iNode, iFan)
 

Typedefs

typedef struct Shr_Fan_t_ Shr_Fan_t
 
typedef struct Shr_Man_t_ Shr_Man_t
 

Functions

Shr_Man_tShr_ManAlloc (Gia_Man_t *pGia)
 FUNCTION DEFINITIONS ///.
 
Gia_Man_tShr_ManFree (Shr_Man_t *p)
 
int Shr_ObjPerformBidec (Shr_Man_t *p, Bdc_Man_t *pManDec, Gia_Man_t *pNew, Vec_Int_t *vLeafLits, word uTruth1, word uTruthC)
 
word Shr_ManComputeTruth6_rec (Gia_Man_t *p, int iNode, Vec_Wrd_t *vTruths)
 
word Shr_ManComputeTruth6 (Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vLeaves, Vec_Wrd_t *vTruths)
 
void Shr_ManComputeTruths (Gia_Man_t *p, int nVars, Vec_Int_t *vDivs, Vec_Wrd_t *vDivTruths, Vec_Wrd_t *vTruths)
 
Gia_Man_tGia_ManMapShrink6 (Gia_Man_t *p, int nFanoutMax, int fKeepLevel, int fVerbose)
 

Macro Definition Documentation

◆ Shr_ObjForEachFanout

#define Shr_ObjForEachFanout ( p,
iNode,
iFan )
Value:
for ( iFan = Shr_ManFanIterStart(p, iNode); iFan; iFan = Shr_ManFanIterNext(p) )
Cube * p
Definition exorList.c:222

Definition at line 78 of file giaShrink6.c.

78#define Shr_ObjForEachFanout( p, iNode, iFan ) \
79 for ( iFan = Shr_ManFanIterStart(p, iNode); iFan; iFan = Shr_ManFanIterNext(p) )

Typedef Documentation

◆ Shr_Fan_t

typedef struct Shr_Fan_t_ Shr_Fan_t

Definition at line 44 of file giaShrink6.c.

◆ Shr_Man_t

typedef struct Shr_Man_t_ Shr_Man_t

Definition at line 52 of file giaShrink6.c.

Function Documentation

◆ Gia_ManMapShrink6()

Gia_Man_t * Gia_ManMapShrink6 ( Gia_Man_t * p,
int nFanoutMax,
int fKeepLevel,
int fVerbose )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 401 of file giaShrink6.c.

402{
403 Shr_Man_t * pMan;
404 Gia_Obj_t * pObj, * pFanin;
405 word uTruth, uTruth0, uTruth1;
406 int i, k, nDivs, iNode;
407 int RetValue, Counter1 = 0, Counter2 = 0;
408 abctime clk2, clk = Abc_Clock();
409 abctime timeFanout = 0;
410 assert( Gia_ManHasMapping(p) );
411 pMan = Shr_ManAlloc( p );
413 Gia_ManConst0(p)->Value = 0;
414 Gia_ManForEachObj1( p, pObj, i )
415 {
416 if ( Gia_ObjIsCi(pObj) )
417 {
418 pObj->Value = Gia_ManAppendCi( pMan->pNew );
419 if ( p->vLevels )
420 Gia_ObjSetLevel( pMan->pNew, Gia_ObjFromLit(pMan->pNew, Gia_ObjValue(pObj)), Gia_ObjLevel(p, pObj) );
421 }
422 else if ( Gia_ObjIsCo(pObj) )
423 {
424 pObj->Value = Gia_ManAppendCo( pMan->pNew, Gia_ObjFanin0Copy(pObj) );
425 }
426 else if ( Gia_ObjIsLut(p, i) )
427 {
428 // collect leaves of this gate
429 Vec_IntClear( pMan->vLeaves );
430 Gia_LutForEachFanin( p, i, iNode, k )
431 Vec_IntPush( pMan->vLeaves, iNode );
432 assert( Vec_IntSize(pMan->vLeaves) <= 6 );
433 // compute truth table
434 uTruth = Shr_ManComputeTruth6( pMan->pGia, pObj, pMan->vLeaves, pMan->vTruths );
435 assert( pObj->Value == ~0 );
436 if ( uTruth == 0 || ~uTruth == 0 )
437 pObj->Value = Abc_LitNotCond( 0, ~uTruth == 0 );
438 else
439 Gia_ManForEachObjVec( pMan->vLeaves, p, pFanin, k )
440 if ( uTruth == Truth[k] || ~uTruth == Truth[k] )
441 pObj->Value = Abc_LitNotCond( pFanin->Value, ~uTruth == Truth[k] );
442 if ( pObj->Value != ~0 )
443 continue;
444 // translate into new nodes
445 Gia_ManForEachObjVec( pMan->vLeaves, p, pFanin, k )
446 {
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) );
450 }
451 // compute divisors
452 clk2 = Abc_Clock();
453 nDivs = Shr_ManCollectDivisors( pMan, pMan->vLeaves, pMan->nDivMax, nFanoutMax );
454 assert( nDivs <= pMan->nDivMax );
455 timeFanout += Abc_Clock() - clk2;
456 // compute truth tables
457 Shr_ManComputeTruths( pMan->pNew, Vec_IntSize(pMan->vLeaves), pMan->vDivs, pMan->vDivTruths, pMan->vTruths );
458 // perform resubstitution
459 RetValue = Rsb_ManPerformResub6( pMan->pManRsb, Vec_IntSize(pMan->vLeaves), uTruth, pMan->vDivTruths, &uTruth0, &uTruth1, 0 );
460 if ( RetValue ) // resub exists
461 {
462 Vec_Int_t * vResult = Rsb_ManGetFanins(pMan->pManRsb);
463 Vec_IntClear( pMan->vDivResub );
464 Vec_IntForEachEntry( vResult, iNode, k )
465 Vec_IntPush( pMan->vDivResub, Vec_IntEntry(pMan->vDivs, iNode) );
466 pObj->Value = Shr_ObjPerformBidec( pMan, pMan->pManDec, pMan->pNew, pMan->vDivResub, uTruth1, uTruth0 | uTruth1 );
467 Counter1++;
468 }
469 else
470 {
471 pObj->Value = Shr_ObjPerformBidec( pMan, pMan->pManDec, pMan->pNew, pMan->vLeaves, uTruth, ~(word)0 );
472 Counter2++;
473 }
474 }
475 }
476 if ( fVerbose )
477 {
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 );
481// ABC_PRT( "Divisors", timeFanout );
482 }
483 return Shr_ManFree( pMan );
484}
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
void Shr_ManComputeTruths(Gia_Man_t *p, int nVars, Vec_Int_t *vDivs, Vec_Wrd_t *vDivTruths, Vec_Wrd_t *vTruths)
Definition giaShrink6.c:359
word Shr_ManComputeTruth6(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vLeaves, Vec_Wrd_t *vTruths)
Definition giaShrink6.c:335
Gia_Man_t * Shr_ManFree(Shr_Man_t *p)
Definition giaShrink6.c:128
Shr_Man_t * Shr_ManAlloc(Gia_Man_t *pGia)
FUNCTION DEFINITIONS ///.
Definition giaShrink6.c:96
int Shr_ObjPerformBidec(Shr_Man_t *p, Bdc_Man_t *pManDec, Gia_Man_t *pNew, Vec_Int_t *vLeafLits, word uTruth1, word uTruthC)
Definition giaShrink6.c:275
struct Shr_Man_t_ Shr_Man_t
Definition giaShrink6.c:52
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
#define Gia_LutForEachFanin(p, i, iFan, k)
Definition gia.h:1161
void Gia_ManFillValue(Gia_Man_t *p)
Definition giaUtil.c:369
#define Gia_ManForEachObj1(p, pObj, i)
Definition gia.h:1192
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Definition gia.h:1194
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
int Rsb_ManPerformResub6(Rsb_Man_t *p, int nVars, word uTruth, Vec_Wrd_t *vDivTruths, word *puTruth0, word *puTruth1, int fVerbose)
Definition rsbDec6.c:694
Vec_Int_t * Rsb_ManGetFanins(Rsb_Man_t *p)
Definition rsbMan.c:84
unsigned Value
Definition gia.h:89
Gia_Man_t * pNew
Definition giaShrink6.c:56
Vec_Int_t * vDivs
Definition giaShrink6.c:64
Vec_Int_t * vLeaves
Definition giaShrink6.c:67
Rsb_Man_t * pManRsb
Definition giaShrink6.c:72
Vec_Int_t * vDivResub
Definition giaShrink6.c:66
Vec_Wrd_t * vDivTruths
Definition giaShrink6.c:70
Vec_Wrd_t * vTruths
Definition giaShrink6.c:69
Gia_Man_t * pGia
Definition giaShrink6.c:55
Bdc_Man_t * pManDec
Definition giaShrink6.c:73
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
Here is the call graph for this function:

◆ Shr_ManAlloc()

Shr_Man_t * Shr_ManAlloc ( Gia_Man_t * pGia)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 96 of file giaShrink6.c.

97{
98 Shr_Man_t * p;
99 p = ABC_CALLOC( Shr_Man_t, 1 );
100 p->nDivMax = 64;
101 p->nNewSize = 2 * Gia_ManObjNum(pGia);
102 p->pGia = 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 );
111 // start new manager
112 p->pNew = Gia_ManStart( p->nNewSize );
113 p->pNew->pName = Abc_UtilStrsav( pGia->pName );
114 p->pNew->pSpec = Abc_UtilStrsav( pGia->pSpec );
115 Gia_ManHashAlloc( p->pNew );
116 Gia_ManCleanLevels( p->pNew, p->nNewSize );
117 // allocate traversal IDs
118 p->pNew->nObjs = p->nNewSize;
119 Gia_ManIncrementTravId( p->pNew );
120 p->pNew->nObjs = 1;
121 // start decompostion
122 p->Pars.nVarsMax = 6;
123 p->Pars.fVerbose = 0;
124 p->pManDec = Bdc_ManAlloc( &p->Pars );
125 p->pManRsb = Rsb_ManAlloc( 6, p->nDivMax, 4, 1 );
126 return p;
127}
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
Bdc_Man_t * Bdc_ManAlloc(Bdc_Par_t *pPars)
MACRO DEFINITIONS ///.
Definition bdcCore.c:68
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition giaHash.c:105
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
void Gia_ManCleanLevels(Gia_Man_t *p, int Size)
Definition giaUtil.c:511
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition giaUtil.c:190
Rsb_Man_t * Rsb_ManAlloc(int nLeafMax, int nDivMax, int nDecMax, int fVerbose)
MACRO DEFINITIONS ///.
Definition rsbMan.c:45
char * pSpec
Definition gia.h:100
char * pName
Definition gia.h:99
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Shr_ManComputeTruth6()

word Shr_ManComputeTruth6 ( Gia_Man_t * p,
Gia_Obj_t * pObj,
Vec_Int_t * vLeaves,
Vec_Wrd_t * vTruths )

Definition at line 335 of file giaShrink6.c.

336{
337 int i, iLeaf;
338 assert( Gia_ObjIsAnd(pObj) );
340 Vec_IntForEachEntry( vLeaves, iLeaf, i )
341 {
342 Gia_ObjSetTravIdCurrentId( p, iLeaf );
343 Vec_WrdWriteEntry( vTruths, iLeaf, Truth[i] );
344 }
345 return Shr_ManComputeTruth6_rec( p, Gia_ObjId(p, pObj), vTruths );
346}
word Shr_ManComputeTruth6_rec(Gia_Man_t *p, int iNode, Vec_Wrd_t *vTruths)
Definition giaShrink6.c:317
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Shr_ManComputeTruth6_rec()

word Shr_ManComputeTruth6_rec ( Gia_Man_t * p,
int iNode,
Vec_Wrd_t * vTruths )

Function*************************************************************

Synopsis [Compute truth table.]

Description []

SideEffects []

SeeAlso []

Definition at line 317 of file giaShrink6.c.

318{
319 Gia_Obj_t * pObj;
320 word Truth0, Truth1;
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) );
326 Truth0 = Shr_ManComputeTruth6_rec( p, Gia_ObjFaninId0p(p, pObj), vTruths );
327 Truth1 = Shr_ManComputeTruth6_rec( p, Gia_ObjFaninId1p(p, pObj), vTruths );
328 if ( Gia_ObjFaninC0(pObj) )
329 Truth0 = ~Truth0;
330 if ( Gia_ObjFaninC1(pObj) )
331 Truth1 = ~Truth1;
332 Vec_WrdWriteEntry( vTruths, iNode, Truth0 & Truth1 );
333 return Truth0 & Truth1;
334}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Shr_ManComputeTruths()

void Shr_ManComputeTruths ( Gia_Man_t * p,
int nVars,
Vec_Int_t * vDivs,
Vec_Wrd_t * vDivTruths,
Vec_Wrd_t * vTruths )

Function*************************************************************

Synopsis [Compute truth table.]

Description []

SideEffects []

SeeAlso []

Definition at line 359 of file giaShrink6.c.

360{
361 Gia_Obj_t * pObj;
362 word Truth0, Truth1;//, Truthh;
363 int i, iDiv;
364 Vec_WrdClear( vDivTruths );
365 Vec_IntForEachEntryStop( vDivs, iDiv, i, nVars )
366 {
367 Vec_WrdWriteEntry( vTruths, iDiv, Truth[i] );
368 Vec_WrdPush( vDivTruths, Truth[i] );
369 }
370 Vec_IntForEachEntryStart( vDivs, iDiv, i, nVars )
371 {
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) )
376 Truth0 = ~Truth0;
377 if ( Gia_ObjFaninC1(pObj) )
378 Truth1 = ~Truth1;
379 Vec_WrdWriteEntry( vTruths, iDiv, Truth0 & Truth1 );
380 Vec_WrdPush( vDivTruths, Truth0 & Truth1 );
381
382// Truthh = Truth0 & Truth1;
383// Abc_TtPrintBinary( &Truthh, nVars ); //printf( "\n" );
384// Kit_DsdPrintFromTruth( &Truthh, nVars ); printf( "\n" );
385 }
386// printf( "\n" );
387}
#define Vec_IntForEachEntryStop(vVec, Entry, i, Stop)
Definition vecInt.h:58
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition vecInt.h:56
Here is the caller graph for this function:

◆ Shr_ManFree()

Gia_Man_t * Shr_ManFree ( Shr_Man_t * p)

Definition at line 128 of file giaShrink6.c.

129{
130 // prepare the manager
131 Gia_Man_t * pTemp;
132 Gia_ManHashStop( p->pNew );
133 Vec_IntFreeP( &p->pNew->vLevels );
134 if ( Gia_ManHasDangling(p->pNew) )
135 {
136 p->pNew = Gia_ManCleanup( pTemp = p->pNew );
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) );
139 Gia_ManStop( pTemp );
140 }
141 Gia_ManSetRegNum( p->pNew, Gia_ManRegNum(p->pGia) );
142 pTemp = p->pNew; p->pNew = NULL;
143 // free data structures
144 Rsb_ManFree( p->pManRsb );
145 Bdc_ManFree( p->pManDec );
146 Gia_ManStopP( &p->pNew );
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 );
155 ABC_FREE( p );
156 return pTemp;
157}
#define ABC_FREE(obj)
Definition abc_global.h:267
void Bdc_ManFree(Bdc_Man_t *p)
Definition bdcCore.c:113
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
int Gia_ManHasDangling(Gia_Man_t *p)
Definition giaUtil.c:1353
void Gia_ManStopP(Gia_Man_t **p)
Definition giaMan.c:224
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition giaMan.c:764
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition giaScl.c:84
void Gia_ManHashStop(Gia_Man_t *p)
Definition giaHash.c:149
void Rsb_ManFree(Rsb_Man_t *p)
Definition rsbMan.c:63
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Shr_ObjPerformBidec()

int Shr_ObjPerformBidec ( Shr_Man_t * p,
Bdc_Man_t * pManDec,
Gia_Man_t * pNew,
Vec_Int_t * vLeafLits,
word uTruth1,
word uTruthC )

Function*************************************************************

Synopsis [Resynthesizes nodes using bi-decomposition.]

Description []

SideEffects []

SeeAlso []

Definition at line 275 of file giaShrink6.c.

276{
277 Bdc_Fun_t * pFunc;
278 Gia_Obj_t * pObj;
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 );
283 Bdc_FuncSetCopyInt( Bdc_ManFunc(pManDec, 0), 1 );
284 Vec_IntForEachEntry( vLeafLits, iVar, i )
285 Bdc_FuncSetCopyInt( Bdc_ManFunc(pManDec, i+1), Abc_Var2Lit(iVar, 0) );
286 nNodes = Bdc_ManNodeNum( pManDec );
287 for ( i = nVars + 1; i < nNodes; i++ )
288 {
289 pFunc = Bdc_ManFunc( pManDec, i );
290 iLast = Gia_ManObjNum(pNew);
291 iLit = Gia_ManHashAnd( pNew, Bdc_FunFanin0Copy(pFunc), Bdc_FunFanin1Copy(pFunc) );
292 Bdc_FuncSetCopyInt( pFunc, iLit );
293 if ( iLast == Gia_ManObjNum(pNew) )
294 continue;
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 );
301 }
302 return Bdc_FunObjCopy( Bdc_ManRoot(pManDec) );
303}
int Bdc_ManNodeNum(Bdc_Man_t *p)
Definition bdcCore.c:48
void Bdc_FuncSetCopyInt(Bdc_Fun_t *p, int iCopy)
Definition bdcCore.c:55
Bdc_Fun_t * Bdc_ManRoot(Bdc_Man_t *p)
Definition bdcCore.c:47
typedefABC_NAMESPACE_HEADER_START struct Bdc_Fun_t_ Bdc_Fun_t
INCLUDES ///.
Definition bdc.h:42
int Bdc_ManDecompose(Bdc_Man_t *p, unsigned *puFunc, unsigned *puCare, int nVars, Vec_Ptr_t *vDivs, int nNodesMax)
Definition bdcCore.c:291
Bdc_Fun_t * Bdc_ManFunc(Bdc_Man_t *p, int i)
DECLARATIONS ///.
Definition bdcCore.c:46
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:576
Here is the call graph for this function:
Here is the caller graph for this function: