29#define UNR_DIFF_NULL 0x7FFF
69static inline int Unr_ObjSizeInt(
int Rank ) {
return 0xFFFFFFFE & (
sizeof(
Unr_Obj_t) /
sizeof(int) + Rank); }
70static inline int Unr_ObjSize(
Unr_Obj_t * pObj ) {
return Unr_ObjSizeInt(pObj->
RankMax); }
76 assert( pFanin->RankCur < pFanin->RankMax );
77 assert( pObj->uRDiff0 < pFanin->RankMax );
78 return Abc_LitNotCond( pFanin->Res[Index], pObj->fCompl0 );
84 assert( pFanin->RankCur < pFanin->RankMax );
85 assert( pObj->uRDiff1 < pFanin->RankMax );
86 return Abc_LitNotCond( pFanin->Res[Index], pObj->fCompl1 );
88static inline int Unr_ManObjReadValue(
Unr_Obj_t * pObj )
93static inline void Unr_ManObjSetValue(
Unr_Obj_t * pObj,
int Value )
97 pObj->Res[ pObj->RankCur ] = Value;
115static inline void Vec_IntWriteMaxEntry(
Vec_Int_t *
p,
int i,
int Entry )
117 assert( i >= 0 && i < p->nSize );
118 p->pArray[i] = Abc_MaxInt(
p->pArray[i], Entry );
134 int RankMax = Vec_IntFindMax( vRanks );
135 Vec_Int_t * vCounts = Vec_IntStart( RankMax+1 );
136 int i, Rank, Count, nExtras = 0;
138 Vec_IntAddToEntry( vCounts, Rank, 1 );
143 printf(
"%2d : %8d (%6.2f %%)\n", i, Count, 100.0 * Count / Vec_IntSize(vRanks) );
144 nExtras += Count * i;
146 printf(
"Extra space = %d (%6.2f %%) ", nExtras, 100.0 * nExtras / Vec_IntSize(vRanks) );
147 Vec_IntFree( vCounts );
165 if ( Vec_IntEntry(
p->vTents, iObj) >= 0 )
167 Vec_IntWriteEntry(
p->vTents, iObj, iTent);
168 pObj = Gia_ManObj(
p->pGia, iObj );
169 if ( Gia_ObjIsAnd(pObj) || Gia_ObjIsCo(pObj) )
172 Vec_IntWriteMaxEntry(
p->vRanks, iFanin, Abc_MaxInt(0, iTent - Vec_IntEntry(
p->vTents, iFanin) - 1) );
174 if ( Gia_ObjIsAnd(pObj) )
177 Vec_IntWriteMaxEntry(
p->vRanks, iFanin, Abc_MaxInt(0, iTent - Vec_IntEntry(
p->vTents, iFanin) - 1) );
179 else if ( Gia_ObjIsRo(
p->pGia, pObj) )
181 Vec_IntPush( vRoots, (iFanin = Gia_ObjId(
p->pGia, Gia_ObjRoToRi(
p->pGia, pObj))) );
182 Vec_IntWriteMaxEntry(
p->vRanks, iFanin, 0 );
184 Vec_IntPush(
p->vOrder, iObj );
191 int i, k, t, iObj, nInts, * pInts;
194 assert( Vec_IntSize(
p->vOrder) == 0 );
195 Vec_IntPush(
p->vOrder, 0 );
196 Vec_IntPush(
p->vOrderLim, Vec_IntSize(
p->vOrder) );
197 Vec_IntWriteEntry(
p->vTents, 0, 0 );
198 Vec_IntWriteEntry(
p->vRanks, 0, 0 );
200 vRoots = Vec_IntAlloc( 100 );
201 vRoots2 = Vec_IntAlloc( 100 );
205 while ( Vec_IntSize(vRoots) > 0 )
207 Vec_IntPush(
p->vOrderLim, Vec_IntSize(
p->vOrder) );
208 Vec_IntClear( vRoots2 );
213 Vec_IntPush(
p->vOrderLim, Vec_IntSize(
p->vOrder) );
214 Vec_IntFree( vRoots );
215 Vec_IntFree( vRoots2 );
219 nInts += Unr_ObjSizeInt( Vec_IntEntry(
p->vRanks, iObj) + 1 );
221 p->pEnd =
p->pObjs + nInts;
223 pUnrObj = Unr_ManObj(
p, pInts -
p->pObjs );
224 pUnrObj->
RankMax = Vec_IntEntry(
p->vRanks, 0) + 1;
228 vMap = Vec_IntStartFull(
p->nObjs );
229 Vec_IntWriteEntry( vMap, 0, pInts -
p->pObjs );
230 pInts += Unr_ObjSize(pUnrObj);
232 assert( Vec_IntSize(
p->vObjLim) == 0 );
233 for ( t = Vec_IntSize(
p->vOrderLim) - 2; t >= 0; t-- )
235 int Beg = Vec_IntEntry(
p->vOrderLim, t);
236 int End = Vec_IntEntry(
p->vOrderLim, t+1);
237 Vec_IntPush(
p->vObjLim, pInts -
p->pObjs );
240 pObj = Gia_ManObj(
p->pGia, iObj );
241 pUnrObj = Unr_ManObj(
p, pInts -
p->pObjs );
243 if ( Gia_ObjIsAnd(pObj) || Gia_ObjIsCo(pObj) )
244 pUnrObj->
uRDiff0 = Abc_MaxInt(0, Vec_IntEntry(
p->vTents, iObj) - Vec_IntEntry(
p->vTents, Gia_ObjFaninId0(pObj, iObj)) - 1);
245 if ( Gia_ObjIsAnd(pObj) )
246 pUnrObj->
uRDiff1 = Abc_MaxInt(0, Vec_IntEntry(
p->vTents, iObj) - Vec_IntEntry(
p->vTents, Gia_ObjFaninId1(pObj, iObj)) - 1);
247 else if ( Gia_ObjIsRo(
p->pGia, pObj) )
249 pUnrObj->
RankMax = Vec_IntEntry(
p->vRanks, iObj) + 1;
252 for ( k = 0; k < (int)pUnrObj->
RankMax; k++ )
253 pUnrObj->
Res[k] = -1;
254 assert( ((pInts -
p->pObjs) & 1) == 0 );
255 Vec_IntWriteEntry( vMap, iObj, pInts -
p->pObjs );
256 pInts += Unr_ObjSize( pUnrObj );
259 assert( pInts -
p->pObjs == nInts );
263 if ( Vec_IntEntry(vMap, i) == -1 )
265 pUnrObj = Unr_ManObj(
p, Vec_IntEntry(vMap, i) );
266 if ( Gia_ObjIsAnd(pObj) || Gia_ObjIsCo(pObj) )
268 pUnrObj->
hFan0 = Vec_IntEntry( vMap, Gia_ObjFaninId0(pObj, i) );
269 pUnrObj->
fCompl0 = Gia_ObjFaninC0(pObj);
270 pUnrObj->
fItIsPo = Gia_ObjIsPo(
p->pGia, pObj);
272 if ( Gia_ObjIsAnd(pObj) )
274 pUnrObj->
hFan1 = Vec_IntEntry( vMap, Gia_ObjFaninId1(pObj, i) );
275 pUnrObj->
fCompl1 = Gia_ObjFaninC1(pObj);
277 else if ( Gia_ObjIsRo(
p->pGia, pObj) )
279 pUnrObj->
hFan0 = Vec_IntEntry( vMap, Gia_ObjId(
p->pGia, Gia_ObjRoToRi(
p->pGia, pObj)) );
282 else if ( Gia_ObjIsPi(
p->pGia, pObj) )
284 pUnrObj->
hFan0 = Gia_ObjCioId(pObj);
285 pUnrObj->
hFan1 = Vec_IntEntry(
p->vTents, i);
291 Vec_IntPush(
p->vCiMap, Vec_IntEntry(vMap, Gia_ObjId(
p->pGia, pObj)) );
293 Vec_IntPush(
p->vCoMap, Vec_IntEntry(vMap, Gia_ObjId(
p->pGia, pObj)) );
294 Vec_IntFreeP( &vMap );
299 printf(
"Memory usage = %6.2f MB ", 4.0 * nInts / (1<<20) );
300 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
302 Vec_IntFreeP( &
p->vOrder );
303 Vec_IntFreeP( &
p->vOrderLim );
304 Vec_IntFreeP( &
p->vRanks );
305 Vec_IntFreeP( &
p->vTents );
326 p->nObjs = Gia_ManObjNum(pGia);
327 p->vOrder = Vec_IntAlloc(
p->nObjs );
328 p->vOrderLim = Vec_IntAlloc( 100 );
329 p->vTents = Vec_IntStartFull(
p->nObjs );
330 p->vRanks = Vec_IntStart(
p->nObjs );
331 p->vObjLim = Vec_IntAlloc( 100 );
332 p->vCiMap = Vec_IntAlloc( Gia_ManCiNum(pGia) );
333 p->vCoMap = Vec_IntAlloc( Gia_ManCoNum(pGia) );
334 p->vPiLits = Vec_IntAlloc( 10000 );
336 p->pFrames->pName = Abc_UtilStrsav( pGia->
pName );
344 Vec_IntFreeP( &
p->vOrder );
345 Vec_IntFreeP( &
p->vOrderLim );
346 Vec_IntFreeP( &
p->vTents );
347 Vec_IntFreeP( &
p->vRanks );
349 Vec_IntFreeP( &
p->vObjLim );
350 Vec_IntFreeP( &
p->vCiMap );
351 Vec_IntFreeP( &
p->vCoMap );
352 Vec_IntFreeP( &
p->vPiLits );
374 for ( i = 0; i < Gia_ManRegNum(
p->pGia); i++ )
375 if ( (iHandle = Vec_IntEntry(
p->vCoMap, Gia_ManPoNum(
p->pGia) + i)) != -1 )
376 Unr_ManObjSetValue( Unr_ManObj(
p, iHandle), 0 );
381 int i, iLit, iLit0, iLit1, hStart;
382 for ( i = 0; i < Gia_ManPiNum(
p->pGia); i++ )
383 Vec_IntPush(
p->vPiLits, Gia_ManAppendCi(
p->pFrames) );
384 hStart = Vec_IntEntry(
p->vObjLim, Abc_MaxInt(0, Vec_IntSize(
p->vObjLim)-1-f) );
385 while (
p->pObjs + hStart < p->pEnd )
387 Unr_Obj_t * pUnrObj = Unr_ManObj(
p, hStart );
390 iLit0 = Unr_ManFanin0Value(
p, pUnrObj );
391 iLit1 = Unr_ManFanin1Value(
p, pUnrObj );
393 Unr_ManObjSetValue( pUnrObj, iLit );
397 iLit = Unr_ManFanin0Value(
p, pUnrObj );
398 Unr_ManObjSetValue( pUnrObj, iLit );
400 Gia_ManAppendCo(
p->pFrames, iLit );
405 iLit = Vec_IntEntry(
p->vPiLits, Gia_ManPiNum(
p->pGia) * (f - pUnrObj->
hFan1) + pUnrObj->
hFan0 );
406 Unr_ManObjSetValue( pUnrObj, iLit );
408 hStart += Unr_ObjSize( pUnrObj );
410 assert(
p->pObjs + hStart ==
p->pEnd );
411 assert( Gia_ManPoNum(
p->pFrames) == (f + 1) * Gia_ManPoNum(
p->pGia) );
420 for ( f = 0; f < nFrames; f++ )
444 pFrames->
pName = Abc_UtilStrsav( pGia->
pName );
446 Gia_ManConst0(pGia)->Value = 0;
449 for ( f = 0; f < nFrames; f++ )
452 pObj->
Value = Gia_ManAppendCi(pFrames);
458 pObj->
Value = Gia_ObjFanin0Copy(pObj);
460 Gia_ManAppendCo( pFrames, pObj->
Value );
485 Abc_PrintTime( 1,
"Unroll ", Abc_Clock() - clk );
488 Abc_PrintTime( 1,
"UnrollS", Abc_Clock() - clk );
#define ABC_SWAP(Type, a, b)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Unr_Man_t * Unr_ManAlloc(Gia_Man_t *pGia)
#define UNR_DIFF_NULL
DECLARATIONS ///.
Gia_Man_t * Unr_ManUnrollFrame(Unr_Man_t *p, int f)
Unr_Man_t * Unr_ManUnrollStart(Gia_Man_t *pGia, int fVerbose)
void Unr_ManSetup(Unr_Man_t *p, int fVerbose)
Gia_Man_t * Unr_ManUnrollSimple(Gia_Man_t *pGia, int nFrames)
void Unr_ManFree(Unr_Man_t *p)
void Unr_ManSetup_rec(Unr_Man_t *p, int iObj, int iTent, Vec_Int_t *vRoots)
void Unr_ManProfileRanks(Vec_Int_t *vRanks)
struct Unr_Obj_t_ Unr_Obj_t
void Unr_ManTest(Gia_Man_t *pGia, int nFrames)
Gia_Man_t * Unr_ManUnroll(Gia_Man_t *pGia, int nFrames)
struct Unr_Man_t_ Unr_Man_t
void Gia_ManStop(Gia_Man_t *p)
void Gia_ManHashStart(Gia_Man_t *p)
#define Gia_ManForEachPo(p, pObj, i)
#define Gia_ManForEachAnd(p, pObj, i)
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
void Gia_ManHashAlloc(Gia_Man_t *p)
#define Gia_ManForEachPi(p, pObj, i)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
struct Gia_Obj_t_ Gia_Obj_t
struct Gia_Man_t_ Gia_Man_t
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
#define Gia_ManForEachCo(p, pObj, i)
#define Gia_ManForEachCi(p, pObj, i)
#define Gia_ManForEachRiRo(p, pObjRi, pObjRo, i)
void Gia_ManHashStop(Gia_Man_t *p)
void Gia_ManPrintStats(Gia_Man_t *p, Gps_Par_t *pPars)
#define Gia_ManForEachRi(p, pObj, i)
void Gia_AigerWrite(Gia_Man_t *p, char *pFileName, int fWriteSymbols, int fCompact, int fWriteNewLine)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryStartStop(vVec, Entry, i, Start, Stop)