79 if ( Gia_ObjIsCi(pObj) )
80 pObj->
Value = Gia_ManAppendCi(pNew);
81 else if ( Gia_ObjIsCo(pObj) )
84 pObj->
Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
86 else if ( Gia_ObjIsAnd(pObj) )
90 pObj->
Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
93 Gia_ManObj(pNew, Abc_Lit2Var(pObj->
Value))->Value = Id;
112 assert( Vec_IntSize(vLimit) == 0 );
114 pNew->
pName = Abc_UtilStrsav(
p->pName );
115 pNew->
pSpec = Abc_UtilStrsav(
p->pSpec );
119 Gia_ManConst0(
p)->Value = 0;
120 Vec_IntPush( vLimit, Gia_ManObjNum(pNew) );
125 Vec_IntPush( vLimit, Gia_ManObjNum(pNew) );
128 for ( i = 1; i < Gia_ManObjNum(pNew); i++ )
130 if ( i == Vec_IntEntryLast(vLimit) )
131 Vec_IntPush( vLimit, Gia_ManObjNum(pNew) );
132 pObj = Gia_ManObj(
p, Gia_ManObj(pNew, i)->Value );
133 if ( Gia_ObjIsRo(
p, pObj) )
135 pObj = Gia_ObjRoToRi(
p, pObj);
162 int nObjBits, nObjMask;
163 int f, fMax, k, Entry, Prev, iStart, iStop, Size;
165 nObjBits = Abc_Base2Log( Gia_ManObjNum(
p) );
166 nObjMask = (1 << nObjBits) - 1;
167 assert( Gia_ManObjNum(
p) <= nObjMask );
169 vLimit = Vec_IntAlloc( 1000 );
177 printf(
"%d=%d ", k, Entry-Prev ), Prev = Entry;
178 printf(
" Unused=%d", Gia_ManObjNum(
p) - Gia_ManObjNum(pNew) );
182 vFrames = Vec_PtrAlloc( Vec_IntSize(vLimit) );
183 for ( fMax = 0; fMax < nFrames; fMax++ )
185 Size = (fMax+1 < Vec_IntSize(vLimit)) ? Vec_IntEntry(vLimit, fMax+1) : Gia_ManObjNum(pNew);
186 vOne = Vec_IntAlloc( Size );
187 for ( f = 0; f <= fMax; f++ )
189 iStart = (f < Vec_IntSize(vLimit)) ? Vec_IntEntry(vLimit, f ) : 0;
190 iStop = (f+1 < Vec_IntSize(vLimit)) ? Vec_IntEntry(vLimit, f+1) : 0;
191 for ( k = iStop - 1; k >= iStart; k-- )
193 assert( Gia_ManObj(pNew, k)->Value > 0 );
194 pObj = Gia_ManObj(
p, Gia_ManObj(pNew, k)->Value);
195 if ( Gia_ObjIsCo(pObj) || Gia_ObjIsPi(
p, pObj) )
197 assert( Gia_ObjIsRo(
p, pObj) || Gia_ObjIsAnd(pObj) );
198 Entry = ((fMax-f) << nObjBits) | Gia_ObjId(
p, pObj);
199 Vec_IntPush( vOne, Entry );
205 Vec_IntSort( vOne, 1 );
206 Vec_PtrPush( vFrames, vOne );
207 assert( Vec_IntSize(vOne) <= Size - 1 );
209 Vec_IntFree( vLimit );
229 int i, k, iRank, iFanin, Degree, Shift;
236 p->vLimit = Vec_IntAlloc( 0 );
244 p->vRank = Vec_IntAlloc( Gia_ManObjNum(
p->pOrder) );
245 for ( iRank = i = 0; i < Gia_ManObjNum(
p->pOrder); Vec_IntPush(
p->vRank, iRank), i++ )
246 if ( Vec_IntEntry(
p->vLimit, iRank) == i )
248 assert( iRank == Vec_IntSize(
p->vLimit)-1 );
249 assert( Vec_IntSize(
p->vRank) == Gia_ManObjNum(
p->pOrder) );
251 p->vDegree = Vec_IntStart( Gia_ManObjNum(
p->pOrder) );
252 p->vDegDiff= Vec_IntStart( 2* Gia_ManObjNum(
p->pOrder) );
255 for ( k = 0; k < 2; k++ )
257 iFanin = k ? Gia_ObjFaninId1(pObj, i) : Gia_ObjFaninId0(pObj, i);
258 Degree = Vec_IntEntry(
p->vRank, i) - Vec_IntEntry(
p->vRank, iFanin);
259 Vec_IntWriteEntry(
p->vDegDiff, 2*i + k, Degree );
260 if ( Vec_IntEntry(
p->vDegree, iFanin) < Degree )
261 Vec_IntWriteEntry(
p->vDegree, iFanin, Degree );
266 i = Gia_ObjId(
p->pOrder, pObj );
267 iFanin = Gia_ObjFaninId0(pObj, i);
268 Degree = Vec_IntEntry(
p->vRank, i) - Vec_IntEntry(
p->vRank, iFanin);
269 Vec_IntWriteEntry(
p->vDegDiff, 2*i, Degree );
270 if ( Vec_IntEntry(
p->vDegree, iFanin) < Degree )
271 Vec_IntWriteEntry(
p->vDegree, iFanin, Degree );
274 p->vFirst = Vec_IntAlloc( Gia_ManObjNum(
p->pOrder) );
275 p->vStore = Vec_IntStartFull( 2* Gia_ManObjNum(
p->pOrder) + Vec_IntSum(
p->vDegree) );
276 for ( Shift = i = 0; i < Gia_ManObjNum(
p->pOrder); i++ )
278 Vec_IntPush(
p->vFirst, Shift );
279 Vec_IntWriteEntry(
p->vStore, Shift, 1 + Vec_IntEntry(
p->vDegree, i) );
280 Shift += 2 + Vec_IntEntry(
p->vDegree, i);
282 assert( Shift == Vec_IntSize(
p->vStore) );
284 Vec_IntFreeP( &
p->vRank );
285 Vec_IntFreeP( &
p->vDegree );
290 printf(
"Convergence = %d. Dangling objects = %d. Average degree = %.3f ",
291 Vec_IntSize(
p->vLimit) - 1,
292 Gia_ManObjNum(pAig) - Gia_ManObjNum(
p->pOrder),
293 1.0*Vec_IntSize(
p->vStore)/Gia_ManObjNum(
p->pOrder) - 1.0 );
294 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
314 Vec_IntFreeP( &
p->vLimit );
315 Vec_IntFreeP( &
p->vRank );
316 Vec_IntFreeP( &
p->vDegree );
317 Vec_IntFreeP( &
p->vDegDiff );
318 Vec_IntFreeP( &
p->vFirst );
319 Vec_IntFreeP( &
p->vStore );
335static inline void Gia_ObjUnrWrite(
Gia_ManUnr_t *
p,
int Id,
int Entry )
337 int i, * pArray = Vec_IntEntryP(
p->vStore, Vec_IntEntry(
p->vFirst, Id) );
338 for ( i = pArray[0]; i > 1; i-- )
339 pArray[i] = pArray[i-1];
342static inline int Gia_ObjUnrRead(
Gia_ManUnr_t *
p,
int Id,
int Degree )
344 int * pArray = Vec_IntEntryP(
p->vStore, Vec_IntEntry(
p->vFirst, Id) );
347 assert( Degree >= 0 && Degree < pArray[0] );
350 return pArray[Degree + 1];
354 int Lit = Gia_ObjUnrRead(
p, Gia_ObjFaninId0(pObj, Id), Vec_IntEntry(
p->vDegDiff, 2*Id));
355 return Abc_LitNotCond( Lit, Gia_ObjFaninC0(pObj) );
359 int Lit = Gia_ObjUnrRead(
p, Gia_ObjFaninId1(pObj, Id), Vec_IntEntry(
p->vDegDiff, 2*Id+1));
360 return Abc_LitNotCond( Lit, Gia_ObjFaninC1(pObj) );
364 Gia_Obj_t * pObj = Gia_ManObj(
p->pOrder, Id );
366 assert( Gia_ObjIsCi(pObjReal) );
367 if ( Gia_ObjIsPi(
p->pAig, pObjReal) )
369 if ( !
p->pPars->fSaveLastLit )
370 pObj = Gia_ManPi( pNew, Gia_ManPiNum(
p->pAig) * f + Gia_ObjCioId(pObjReal) );
372 pObj = Gia_ManPi( pNew, Gia_ManRegNum(
p->pAig) + Gia_ManPiNum(
p->pAig) * f + Gia_ObjCioId(pObjReal) );
373 return Abc_Var2Lit( Gia_ObjId(pNew, pObj), 0 );
377 if (
p->pPars->fInit )
379 assert( Gia_ObjCioId(pObjReal) >= Gia_ManPiNum(
p->pAig) );
380 if ( !
p->pPars->fSaveLastLit )
381 pObj = Gia_ManPi( pNew, Gia_ManPiNum(
p->pAig) *
p->pPars->nFrames + Gia_ObjCioId(pObjReal)-Gia_ManPiNum(
p->pAig) );
383 pObj = Gia_ManPi( pNew, Gia_ObjCioId(pObjReal)-Gia_ManPiNum(
p->pAig) );
384 return Abc_Var2Lit( Gia_ObjId(pNew, pObj), 0 );
386 pObj = Gia_ManObj(
p->pOrder, Abc_Lit2Var(Gia_ObjRoToRi(
p->pAig, pObjReal)->Value) );
387 assert( Gia_ObjIsCo(pObj) );
388 return Gia_ObjUnrRead(
p, Gia_ObjId(
p->pOrder, pObj), 0 );
411 p->pNew->pName = Abc_UtilStrsav(
p->pAig->pName );
412 p->pNew->pSpec = Abc_UtilStrsav(
p->pAig->pSpec );
415 if ( !
p->pPars->fSaveLastLit )
416 for ( f = 0; f <
p->pPars->nFrames; f++ )
417 for ( i = 0; i < Gia_ManPiNum(
p->pAig); i++ )
418 Gia_ManAppendCi(
p->pNew);
420 if ( !
p->pPars->fInit )
421 for ( i = 0; i < Gia_ManRegNum(
p->pAig); i++ )
422 Gia_ManAppendCi(
p->pNew);
441 int f, i, Lit = 0, Beg, End;
443 if (
p->pPars->fSaveLastLit )
444 for ( i = 0; i < Gia_ManPiNum(
p->pAig); i++ )
445 Gia_ManAppendCi(
p->pNew);
447 for ( f = 0; f < fMax; f++ )
449 if ( Vec_IntSize(
p->vLimit) <= fMax-f )
451 Beg = Vec_IntEntry(
p->vLimit, fMax-f-1 );
452 End = Vec_IntEntry(
p->vLimit, fMax-f );
453 for ( i = Beg; i < End; i++ )
455 pObj = Gia_ManObj(
p->pOrder, i );
456 if ( Gia_ObjIsAnd(pObj) )
457 Lit =
Gia_ManHashAnd(
p->pNew, Gia_ObjUnrReadCopy0(
p, pObj, i), Gia_ObjUnrReadCopy1(
p, pObj, i) );
458 else if ( Gia_ObjIsCo(pObj) )
460 Lit = Gia_ObjUnrReadCopy0(
p, pObj, i);
463 if (
p->pPars->fSaveLastLit )
466 Gia_ManAppendCo(
p->pNew, Lit );
469 else if ( Gia_ObjIsCi(pObj) )
470 Lit = Gia_ObjUnrReadCi(
p, i, f,
p->pNew );
473 Gia_ObjUnrWrite(
p, i, Lit );
513 for ( fMax = 1; fMax <=
p->pPars->nFrames; fMax++ )
515 assert( Gia_ManPoNum(
p->pNew) ==
p->pPars->nFrames * Gia_ManPoNum(
p->pAig) );
523 pNew =
p->pNew;
p->pNew = NULL;
614 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
692 Vec_Int_t * vIns = NULL, * vAnds, * vOuts;
695 p->vIns = Vec_PtrStart(
p->pPars->nFrames );
696 p->vAnds = Vec_PtrStart(
p->pPars->nFrames );
697 p->vOuts = Vec_PtrStart(
p->pPars->nFrames );
699 for ( f =
p->pPars->nFrames - 1; f >= 0; f-- )
704 if ( Gia_ObjIsRo(
p->pAig, pObj) )
705 Vec_IntPush( vOuts, Gia_ObjId(
p->pAig, Gia_ObjRoToRi(
p->pAig, pObj) ) );
706 vIns = Vec_IntAlloc( 100 );
708 vAnds = Vec_IntAlloc( 100 );
710 Vec_PtrWriteEntry(
p->vIns, f, vIns );
711 Vec_PtrWriteEntry(
p->vAnds, f, vAnds );
712 Vec_PtrWriteEntry(
p->vOuts, f, vOuts );
739 pFrames->
pName = Abc_UtilStrsav( pAig->
pName );
740 pFrames->
pSpec = Abc_UtilStrsav( pAig->
pSpec );
742 Gia_ManConst0(pAig)->Value = 0;
743 for ( f = 0; f < pPars->
nFrames; f++ )
745 vIns = (
Vec_Int_t *)Vec_PtrEntry(
p->vIns, f );
746 vAnds = (
Vec_Int_t *)Vec_PtrEntry(
p->vAnds, f );
747 vOuts = (
Vec_Int_t *)Vec_PtrEntry(
p->vOuts, f );
749 printf(
"Frame %3d : CI = %6d. AND = %6d. CO = %6d.\n",
750 f, Vec_IntSize(vIns), Vec_IntSize(vAnds), Vec_IntSize(vOuts) );
754 pObj->
Value = Gia_ManAppendCi( pFrames );
759 assert( Gia_ObjIsCi(pObj) );
760 if ( !Gia_ObjIsPi(pAig, pObj) )
768 assert( Gia_ObjIsCi(pObj) );
769 if ( !Gia_ObjIsPi(pAig, pObj) )
770 pObj->
Value = Gia_ObjRoToRi(pAig, pObj)->Value;
780 assert( Gia_ObjIsCi(pObj) );
781 if ( Gia_ObjIsPi(pAig, pObj) )
782 pObj->
Value = Gia_ManAppendCi( pFrames );
791 assert( Gia_ObjIsCi(pObj) );
792 if ( Gia_ObjIsPi(pAig, pObj) )
793 pObj->
Value = Gia_ManAppendCi( pFrames );
795 pObj->
Value = Gia_ObjRoToRi(pAig, pObj)->Value;
801 assert( Gia_ObjIsAnd(pObj) );
806 assert( Gia_ObjIsCo(pObj) );
807 if ( Gia_ObjIsPo(pAig, pObj) )
808 pObj->
Value = Gia_ManAppendCo( pFrames, Gia_ObjFanin0Copy(pObj) );
810 pObj->
Value = Gia_ObjFanin0Copy(pObj);
819 printf(
"Before cleanup = %d nodes. After cleanup = %d nodes.\n",
820 Gia_ManAndNum(pTemp), Gia_ManAndNum(pFrames) );
824 printf(
"Before cleanup = %d nodes. After cleanup = %d nodes.\n",
825 Gia_ManAndNum(pFrames), Gia_ManAndNum(pFrames) );
846 assert( Gia_ManRegNum(pAig) > 0 );
851 vPoLits = Vec_IntStart( Gia_ManPoNum(pAig) );
853 pFrames->
pName = Abc_UtilStrsav( pAig->
pName );
854 pFrames->
pSpec = Abc_UtilStrsav( pAig->
pSpec );
857 Gia_ManConst0(pAig)->Value = 0;
859 for ( f = 0; f < pPars->
nFrames; f++ )
861 pObj->
Value = Gia_ManAppendCi( pFrames );
863 for ( f = 0; f < pPars->
nFrames; f++ )
868 pObj->
Value = Gia_ManAppendCi( pFrames );
873 pObj->
Value = Gia_ObjRoToRi( pAig, pObj )->Value;
876 pObj->
Value = Gia_Obj2Lit( pFrames, Gia_ManPi(pFrames, f * Gia_ManPiNum(pAig) + i) );
882 pObj->
Value = Gia_ManAppendAnd2( pFrames, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
887 Vec_IntWriteEntry( vPoLits, i,
Gia_ManHashOr(pFrames, Vec_IntEntry(vPoLits, i), Gia_ObjFanin0Copy(pObj)) );
890 Vec_IntWriteEntry( vPoLits, i, Abc_LitNot(Gia_ManAppendAnd2(pFrames, Abc_LitNot(Vec_IntEntry(vPoLits, i)), Abc_LitNot(Gia_ObjFanin0Copy(pObj)))) );
895 pObj->
Value = Gia_ManAppendCo( pFrames, Gia_ObjFanin0Copy(pObj) );
901 pObj->
Value = Gia_ManAppendCo( pFrames, Vec_IntEntry(vPoLits, i) );
903 pObj->
Value = Gia_ManAppendCo( pFrames, Gia_ObjFanin0Copy(pObj) );
908 pObj->
Value = Gia_ObjFanin0Copy(pObj);
911 Vec_IntFreeP( &vPoLits );
919 printf(
"Before cleanup = %d nodes. After cleanup = %d nodes.\n",
920 Gia_ManAndNum(pTemp), Gia_ManAndNum(pFrames) );
924 printf(
"Before cleanup = %d nodes. After cleanup = %d nodes.\n",
925 Gia_ManAndNum(pFrames), Gia_ManAndNum(pFrames) );
946 assert( Gia_ManRegNum(pAig) > 0 );
948 printf(
"Computing specialized unrolling with %d frames...\n", nFrames );
950 pFrames->
pName = Abc_UtilStrsav( pAig->
pName );
951 pFrames->
pSpec = Abc_UtilStrsav( pAig->
pSpec );
953 Gia_ManConst0(pAig)->Value = 0;
954 for ( f = 0; nFrames == 0 || f < nFrames; f++ )
956 if ( fVerbose && (f % 100 == 0) )
958 printf(
"%6d : ", f );
962 pObj->
Value = f ? Gia_ObjRoToRi( pAig, pObj )->Value : 0;
964 pObj->
Value = Gia_ManAppendCi( pFrames );
968 if ( Gia_ObjFanin0Copy(pObj) != 0 )
970 if ( i < Gia_ManPoNum(pAig) )
973 pObj->
Value = Gia_ObjFanin0Copy(pObj);
976 printf(
"Computed prefix of %d frames.\n", f );
978 Gia_ManAppendCo( pFrames, pObj->
Value );
982 printf(
"Before cleanup = %d nodes. After cleanup = %d nodes.\n",
983 Gia_ManAndNum(pTemp), Gia_ManAndNum(pFrames) );
#define ABC_ALLOC(type, num)
#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 ///.
void Gia_ManUnrollStop(void *pMan)
void Gia_ManFraSetDefaultParams(Gia_ParFra_t *p)
void Gia_ManUnrollDup_rec(Gia_Man_t *pNew, Gia_Obj_t *pObj, int Id)
FUNCTION DEFINITIONS ///.
Gia_Man_t * Gia_ManUnroll(Gia_Man_t *pAig, Gia_ParFra_t *pPars)
Vec_Ptr_t * Gia_ManUnrollAbs(Gia_Man_t *p, int nFrames)
Gia_ManUnr_t * Gia_ManUnrStart(Gia_Man_t *pAig, Gia_ParFra_t *pPars)
void * Gia_ManUnrollAdd(void *pMan, int fMax)
void Gia_ManFraSupports(Gia_ManFra_t *p)
void * Gia_ManUnrollStart(Gia_Man_t *pAig, Gia_ParFra_t *pPars)
Gia_Man_t * Gia_ManFrames2(Gia_Man_t *pAig, Gia_ParFra_t *pPars)
int Gia_ManUnrollLastLit(void *pMan)
Gia_Man_t * Gia_ManFrames(Gia_Man_t *pAig, Gia_ParFra_t *pPars)
void Gia_ManFraStop(Gia_ManFra_t *p)
Gia_ManFra_t * Gia_ManFraStart(Gia_Man_t *pAig, Gia_ParFra_t *pPars)
Gia_Man_t * Gia_ManFramesInit(Gia_Man_t *pAig, Gia_ParFra_t *pPars)
Gia_Man_t * Gia_ManUnrollDup(Gia_Man_t *p, Vec_Int_t *vLimit)
struct Gia_ManUnr_t_ Gia_ManUnr_t
Gia_Man_t * Gia_ManFramesInitSpecial(Gia_Man_t *pAig, int nFrames, int fVerbose)
typedefABC_NAMESPACE_IMPL_START struct Gia_ManFra_t_ Gia_ManFra_t
DECLARATIONS ///.
void Gia_ManStop(Gia_Man_t *p)
int Gia_ManCombMarkUsed(Gia_Man_t *p)
#define Gia_ManForEachRo(p, pObj, i)
#define Gia_ManForEachPo(p, pObj, i)
#define Gia_ManForEachAnd(p, pObj, i)
Vec_Int_t * Gia_ManCollectPoIds(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)
struct Gia_ParFra_t_ Gia_ParFra_t
#define Gia_ManForEachPi(p, pObj, i)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
int Gia_ManHashOr(Gia_Man_t *p, int iLit0, int iLit1)
struct Gia_Obj_t_ Gia_Obj_t
Gia_Man_t * Gia_ManDupMarked(Gia_Man_t *p)
void Gia_ManFillValue(Gia_Man_t *p)
struct Gia_Man_t_ Gia_Man_t
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
void Gia_ManIncrementTravId(Gia_Man_t *p)
#define Gia_ManForEachCo(p, pObj, i)
void Gia_ManHashStop(Gia_Man_t *p)
void Gia_ManPrintStats(Gia_Man_t *p, Gps_Par_t *pPars)
void Gia_ManCollectCis(Gia_Man_t *p, int *pNodes, int nNodes, Vec_Int_t *vSupp)
#define Gia_ManForEachRi(p, pObj, i)
void Gia_ManCollectAnds(Gia_Man_t *p, int *pNodes, int nNodes, Vec_Int_t *vNodes, Vec_Int_t *vLeaves)
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.