ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaShrink.c
Go to the documentation of this file.
1
20
21#include "gia.h"
22#include "aig/aig/aig.h"
23#include "opt/dar/dar.h"
24
26
27
31
32extern int Dar_LibEvalBuild( Gia_Man_t * p, Vec_Int_t * vCut, unsigned uTruth, int fKeepLevel, Vec_Int_t * vLeavesBest );
33
37
49Gia_Man_t * Gia_ManMapShrink4( Gia_Man_t * p, int fKeepLevel, int fVerbose )
50{
51 Vec_Int_t * vLeaves, * vTruth, * vVisited, * vLeavesBest;
52 Gia_Man_t * pNew, * pTemp;
53 Gia_Obj_t * pObj, * pFanin;
54 unsigned * pTruth;
55 int i, k, iFan;
56 abctime clk = Abc_Clock();
57// int ClassCounts[222] = {0};
58 int * pLutClass, Counter = 0;
59 assert( Gia_ManHasMapping(p) );
60 if ( Gia_ManLutSizeMax( p ) > 4 )
61 {
62 printf( "Resynthesis is not performed when nodes have more than 4 inputs.\n" );
63 return NULL;
64 }
65 pLutClass = ABC_CALLOC( int, Gia_ManObjNum(p) );
66 vLeaves = Vec_IntAlloc( 0 );
67 vTruth = Vec_IntAlloc( (1<<16) );
68 vVisited = Vec_IntAlloc( 0 );
69 vLeavesBest = Vec_IntAlloc( 4 );
70 // prepare the library
71 Dar_LibPrepare( 5 );
72 // clean the old manager
76 Gia_ManConst0(p)->Value = 0;
77 // start the new manager
78 pNew = Gia_ManStart( Gia_ManObjNum(p) );
79 pNew->pName = Abc_UtilStrsav( p->pName );
80 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
81 Gia_ManHashAlloc( pNew );
82 Gia_ManCleanLevels( pNew, Gia_ManObjNum(p) );
83 Gia_ManForEachObj1( p, pObj, i )
84 {
85 if ( Gia_ObjIsCi(pObj) )
86 {
87 pObj->Value = Gia_ManAppendCi( pNew );
88 if ( p->vLevels )
89 Gia_ObjSetLevel( pNew, Gia_ObjFromLit(pNew, Gia_ObjValue(pObj)), Gia_ObjLevel(p, pObj) );
90 }
91 else if ( Gia_ObjIsCo(pObj) )
92 {
93 pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
94 }
95 else if ( Gia_ObjIsLut(p, i) )
96 {
97 Counter++;
98 // collect leaves of this gate
99 Vec_IntClear( vLeaves );
100 Gia_LutForEachFanin( p, i, iFan, k )
101 Vec_IntPush( vLeaves, iFan );
102 for ( ; k < 4; k++ )
103 Vec_IntPush( vLeaves, 0 );
104 //.compute the truth table
105 pTruth = Gia_ManConvertAigToTruth( p, pObj, vLeaves, vTruth, vVisited );
106 // change from node IDs to their literals
107 Gia_ManForEachObjVec( vLeaves, p, pFanin, k )
108 {
109// assert( Gia_ObjValue(pFanin) != ~0 );
110 Vec_IntWriteEntry( vLeaves, k, Gia_ObjValue(pFanin) != ~0 ? Gia_ObjValue(pFanin) : 0 );
111 }
112 // derive new structre
113 if ( Gia_ManTruthIsConst0(pTruth, Vec_IntSize(vLeaves)) )
114 pObj->Value = 0;
115 else if ( Gia_ManTruthIsConst1(pTruth, Vec_IntSize(vLeaves)) )
116 pObj->Value = 1;
117 else
118 {
119 pObj->Value = Dar_LibEvalBuild( pNew, vLeaves, 0xffff & *pTruth, fKeepLevel, vLeavesBest );
120 pObj->Value = Abc_LitNotCond( pObj->Value, Gia_ObjPhaseRealLit(pNew, pObj->Value) ^ pObj->fPhase );
121 }
122 }
123 }
124 // cleanup the AIG
125 Gia_ManHashStop( pNew );
126 // check the presence of dangling nodes
127 if ( Gia_ManHasDangling(pNew) )
128 {
129 pNew = Gia_ManCleanup( pTemp = pNew );
130 if ( fVerbose && Gia_ManAndNum(pNew) != Gia_ManAndNum(pTemp) )
131 printf( "Gia_ManMapShrink4() node reduction after sweep %6d -> %6d.\n", Gia_ManAndNum(pTemp), Gia_ManAndNum(pNew) );
132 Gia_ManStop( pTemp );
133 }
134 Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
135 Vec_IntFree( vLeaves );
136 Vec_IntFree( vTruth );
137 Vec_IntFree( vVisited );
138 Vec_IntFree( vLeavesBest );
139 if ( fVerbose )
140 {
141 printf( "Total gain in AIG nodes = %d. ", Gia_ManObjNum(p)-Gia_ManObjNum(pNew) );
142 ABC_PRT( "Total runtime", Abc_Clock() - clk );
143 }
144 ABC_FREE( pLutClass );
145 return pNew;
146}
147
151
152
154
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
void Dar_LibPrepare(int nSubgraphs)
Definition darLib.c:478
Cube * p
Definition exorList.c:222
ABC_NAMESPACE_IMPL_START int Dar_LibEvalBuild(Gia_Man_t *p, Vec_Int_t *vCut, unsigned uTruth, int fKeepLevel, Vec_Int_t *vLeavesBest)
DECLARATIONS ///.
Definition darLib.c:1329
Gia_Man_t * Gia_ManMapShrink4(Gia_Man_t *p, int fKeepLevel, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition giaShrink.c:49
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
unsigned * Gia_ManConvertAigToTruth(Gia_Man_t *p, Gia_Obj_t *pRoot, Vec_Int_t *vLeaves, Vec_Int_t *vTruth, Vec_Int_t *vVisited)
Definition giaBidec.c:90
int Gia_ManHasDangling(Gia_Man_t *p)
Definition giaUtil.c:1353
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition giaMan.c:764
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition giaHash.c:105
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
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
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
#define Gia_ManForEachObj1(p, pObj, i)
Definition gia.h:1192
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Definition gia.h:1194
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition giaScl.c:84
void Gia_ManCleanTruth(Gia_Man_t *p)
Definition giaUtil.c:528
int Gia_ManLutSizeMax(Gia_Man_t *p)
Definition giaIf.c:127
void Gia_ManCleanLevels(Gia_Man_t *p, int Size)
Definition giaUtil.c:511
void Gia_ManSetPhase(Gia_Man_t *p)
Definition giaUtil.c:420
void Gia_ManHashStop(Gia_Man_t *p)
Definition giaHash.c:149
char * pSpec
Definition gia.h:100
char * pName
Definition gia.h:99
unsigned Value
Definition gia.h:89
unsigned fPhase
Definition gia.h:87
#define assert(ex)
Definition util_old.h:213