83static inline Rtm_Init_t Rtm_InitNotCond(
Rtm_Init_t Val,
int c ) {
return c ? Rtm_InitNot(Val) : Val; }
86static inline int Rtm_InitWordsNum(
int nLats ) {
return (nLats >> 4) + ((nLats & 15) > 0); }
87static inline int Rtm_InitGetTwo(
unsigned *
p,
int i ) {
return (
p[i>>4] >> ((i & 15)<<1)) & 3; }
88static inline void Rtm_InitSetTwo(
unsigned *
p,
int i,
int val ) {
p[i>>4] |= (val << ((i & 15)<<1)); }
89static inline void Rtm_InitXorTwo(
unsigned *
p,
int i,
int val ) {
p[i>>4] ^= (val << ((i & 15)<<1)); }
116static void Rtm_ObjAddFirst(
Rtm_Man_t *
p,
Rtm_Edg_t * pEdge,
Rtm_Init_t Val ) {
if ( pEdge->
nLats == 10 ) Rtm_ObjTransferToBig(
p, pEdge);
else if ( (pEdge->
nLats & 15) == 15 ) Rtm_ObjTransferToBigger(
p, pEdge);
if ( pEdge->
nLats >= 10 ) Rtm_ObjAddFirst2(
p, pEdge, Val);
else Rtm_ObjAddFirst1(pEdge, Val); }
117static void Rtm_ObjAddLast(
Rtm_Man_t *
p,
Rtm_Edg_t * pEdge,
Rtm_Init_t Val ) {
if ( pEdge->
nLats == 10 ) Rtm_ObjTransferToBig(
p, pEdge);
else if ( (pEdge->
nLats & 15) == 15 ) Rtm_ObjTransferToBigger(
p, pEdge);
if ( pEdge->
nLats >= 10 ) Rtm_ObjAddLast2(
p, pEdge, Val);
else Rtm_ObjAddLast1(pEdge, Val); }
121#define Rtm_ManForEachPi( p, pObj, i ) \
122 Vec_PtrForEachEntry( Rtm_Obj_t *, p->vPis, pObj, i )
124#define Rtm_ManForEachPo( p, pObj, i ) \
125 Vec_PtrForEachEntry( Rtm_Obj_t *, p->vPos, pObj, i )
127#define Rtm_ManForEachObj( p, pObj, i ) \
128 Vec_PtrForEachEntry( Rtm_Obj_t *, p->vObjs, pObj, i )
130#define Rtm_ObjForEachFanin( pObj, pFanin, i ) \
131 for ( i = 0; i < (int)(pObj)->nFanins && ((pFanin = Rtm_ObjFanin(pObj, i)), 1); i++ )
133#define Rtm_ObjForEachFanout( pObj, pFanout, i ) \
134 for ( i = 0; i < (int)(pObj)->nFanouts && ((pFanout = Rtm_ObjFanout(pObj, i)), 1); i++ )
136#define Rtm_ObjForEachFaninEdge( pObj, pEdge, i ) \
137 for ( i = 0; i < (int)(pObj)->nFanins && ((pEdge = Rtm_ObjEdge(pObj, i)), 1); i++ )
139#define Rtm_ObjForEachFanoutEdge( pObj, pEdge, i ) \
140 for ( i = 0; i < (int)(pObj)->nFanouts && ((pEdge = Rtm_ObjFanoutEdge(pObj, i)), 1); i++ )
177 if (
p->nExtraCur + 1 >
p->nExtraAlloc )
179 int nExtraAllocNew = Abc_MaxInt( 2 *
p->nExtraAlloc, 1024 );
180 p->pExtra =
ABC_REALLOC(
unsigned,
p->pExtra, nExtraAllocNew );
181 p->nExtraAlloc = nExtraAllocNew;
183 p->pExtra[
p->nExtraCur] = pEdge->
LData;
184 pEdge->
LData =
p->nExtraCur++;
203 if (
p->nExtraCur +
nWords + 1 >
p->nExtraAlloc )
205 int nExtraAllocNew = Abc_MaxInt( 2 *
p->nExtraAlloc, 1024 );
206 p->pExtra =
ABC_REALLOC(
unsigned,
p->pExtra, nExtraAllocNew );
207 p->nExtraAlloc = nExtraAllocNew;
210 p->pExtra[
p->nExtraCur +
nWords] = 0;
211 pEdge->
LData =
p->nExtraCur;
229 unsigned * pB =
p->pExtra + pEdge->
LData, * pE = pB + Rtm_InitWordsNum( pEdge->
nLats-- ) - 1;
233 *pE = (*pE >> 2) | (Val << 30);
254 unsigned * pB =
p->pExtra + pEdge->
LData, * pE = pB + Rtm_InitWordsNum( ++pEdge->
nLats );
260 *pB = (*pB << 2) | Val;
280 printf(
"%d : ", (
int)pEdge->
nLats );
309 pRtm->
vObjs = Vec_PtrAlloc( Aig_ManObjNum(
p) );
310 pRtm->
vPis = Vec_PtrAlloc( Aig_ManCiNum(
p) );
311 pRtm->
vPos = Vec_PtrAlloc( Aig_ManCoNum(
p) );
329 Vec_PtrFree(
p->vObjs );
330 Vec_PtrFree(
p->vPis );
331 Vec_PtrFree(
p->vPos );
352 int nLatchMax = 0, i, k;
363 nLatchMax = Abc_MaxInt( nLatchMax, (
int)pEdge->
nLats );
385 pObj->
Type = (int)(nFanins == 1 && nFanouts == 0);
387 pObj->
Temp = nFanouts;
388 pObj->
Id = Vec_PtrSize(pRtm->
vObjs);
389 Vec_PtrPush( pRtm->
vObjs, pObj );
438 if ( pEdge->
nLats == 0 )
459 if ( pEdge->
nLats == 0 )
480 Degree = Abc_MaxInt( Degree, (
int)pFanin->
Num );
500 Degree = Abc_MaxInt( Degree, (
int)pFanout->
Num );
525 ValCur = Rtm_ObjRemFirst( pRtm, pEdge );
526 ValCur = Rtm_InitNotCond( ValCur, i? pObj->
fCompl1 : pObj->
fCompl0 );
527 ValTotal = Rtm_InitAnd( ValTotal, ValCur );
531 Rtm_ObjAddLast( pRtm, pEdge, ValTotal );
552 Rtm_ObjRemLast( pRtm, pEdge );
604 Counter += pObjRtm->
fAuto;
658 Counter += pObjRtm->
fAuto;
680 assert( Aig_ManRegNum(
p) > 0 );
681 assert( Aig_ManBufNum(
p) == 0 );
685 pObj = Aig_ManConst1(
p);
734 if ( pObjRtm->
pCopy )
737 pRes = Aig_ManConst1( pNew );
740 if ( pEdge->
nLats == 0 )
741 pFanin =
Rtm_ManToAig_rec( pNew, pRtm, Rtm_ObjFanin(pObjRtm, k), pLatches );
744 Val = Rtm_ObjGetFirst( pRtm, pEdge );
745 pFanin = Aig_ManCi( pNew, pLatches[2*pObjRtm->
Id + k] + pEdge->
nLats - 1 );
746 pFanin = Aig_NotCond( pFanin, Val ==
RTM_VAL_ONE );
748 pFanin = Aig_NotCond( pFanin, k ? pObjRtm->
fCompl1 : pObjRtm->
fCompl0 );
749 pRes =
Aig_And( pNew, pRes, pFanin );
771 int i, k, m, Val, nLatches, * pLatches;
778 pLatches[2*pObjRtm->
Id + k] = Vec_PtrSize(pRtm->
vPis) + nLatches;
779 nLatches += pEdge->
nLats;
785 pObjRtm->
pCopy = Aig_ManConst1(pNew);
788 for ( i = 0; i < nLatches; i++ )
800 if ( pEdge->
nLats == 0 )
802 pObjNew = (
Aig_Obj_t *)Rtm_ObjFanin( pObjRtm, k )->pCopy;
803 for ( m = 0; m < (int)pEdge->
nLats; m++ )
805 Val = Rtm_ObjGetOne( pRtm, pEdge, pEdge->
nLats - 1 - m );
807 pObjNew = Aig_NotCond( pObjNew, Val ==
RTM_VAL_ONE );
809 pObjNew = Aig_ManCi( pNew, pLatches[2*pObjRtm->
Id + k] + m );
810 pObjNew = Aig_NotCond( pObjNew, Val ==
RTM_VAL_ONE );
819 printf(
"Rtm_ManToAig: The network check has failed.\n" );
841 int i, k, nAutos, Degree, DegreeMax = 0;
857 printf(
"Detected %d autonomous objects. ", nAutos );
858 ABC_PRT(
"Time", Abc_Clock() - clk );
871 vQueue = Vec_PtrAlloc( 1000 );
880 Vec_PtrPush( vQueue, pObj );
891 Vec_PtrPush( vQueue, pObj );
913 DegreeMax = Abc_MaxInt( DegreeMax, Degree );
914 if ( Degree > nStepsMax )
918 Vec_PtrPush( vQueue, pNext );
934 DegreeMax = Abc_MaxInt( DegreeMax, Degree );
935 if ( Degree > nStepsMax )
939 Vec_PtrPush( vQueue, pNext );
946 printf(
"Performed %d %s latch moves of max depth %d and max latch count %d.\n",
947 Vec_PtrSize(vQueue), fForward?
"fwd":
"bwd", DegreeMax,
Rtm_ManLatchMax(pRtm) );
948 printf(
"Memory usage = %d. ", pRtm->
nExtraCur );
949 ABC_PRT(
"Time", Abc_Clock() - clk );
951 Vec_PtrFree( vQueue );
955 pNew->pName = Abc_UtilStrsav(
p->pName );
956 pNew->pSpec = Abc_UtilStrsav(
p->pSpec );
963 ABC_PRT(
"Register sharing time", Abc_Clock() - clk );
#define ABC_ALLOC(type, num)
#define ABC_REALLOC(type, obj, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
int Rtm_ObjCheckRetimeBwd(Rtm_Obj_t *pObj)
void Rtm_PrintEdge(Rtm_Man_t *p, Rtm_Edg_t *pEdge)
int Rtm_ObjGetDegreeFwd(Rtm_Obj_t *pObj)
int Rtm_ManMarkAutoFwd(Rtm_Man_t *pRtm)
void Rtm_ObjMarkAutoBwd_rec(Rtm_Obj_t *pObj)
Rtm_Man_t * Rtm_ManAlloc(Aig_Man_t *p)
void Rtm_ObjRetimeFwd(Rtm_Man_t *pRtm, Rtm_Obj_t *pObj)
Aig_Man_t * Rtm_ManToAig(Rtm_Man_t *pRtm)
Aig_Man_t * Rtm_ManRetime(Aig_Man_t *p, int fForward, int nStepsMax, int fVerbose)
#define Rtm_ObjForEachFanout(pObj, pFanout, i)
#define Rtm_ObjForEachFanoutEdge(pObj, pEdge, i)
Rtm_Init_t
DECLARATIONS ///.
struct Rtm_Obj_t_ Rtm_Obj_t
Aig_Obj_t * Rtm_ManToAig_rec(Aig_Man_t *pNew, Rtm_Man_t *pRtm, Rtm_Obj_t *pObjRtm, int *pLatches)
void Rtm_ObjRetimeBwd(Rtm_Man_t *pRtm, Rtm_Obj_t *pObj)
Rtm_Man_t * Rtm_ManFromAig(Aig_Man_t *p)
void Rtm_ObjAddFanin(Rtm_Obj_t *pObj, Rtm_Obj_t *pFanin, int fCompl)
int Rtm_ObjGetDegreeBwd(Rtm_Obj_t *pObj)
#define Rtm_ManForEachObj(p, pObj, i)
struct Rtm_Man_t_ Rtm_Man_t
struct Rtm_Edg_t_ Rtm_Edg_t
void Rtm_ManFree(Rtm_Man_t *p)
#define Rtm_ObjForEachFaninEdge(pObj, pEdge, i)
int Rtm_ManMarkAutoBwd(Rtm_Man_t *pRtm)
int Rtm_ManLatchMax(Rtm_Man_t *p)
int Rtm_ObjCheckRetimeFwd(Rtm_Obj_t *pObj)
Rtm_Obj_t * Rtm_ObjAlloc(Rtm_Man_t *pRtm, int nFanins, int nFanouts)
#define Rtm_ObjForEachFanin(pObj, pFanin, i)
void Rtm_ObjMarkAutoFwd_rec(Rtm_Obj_t *pObj)
#define Rtm_ManForEachPo(p, pObj, i)
#define Rtm_ManForEachPi(p, pObj, i)
void Aig_ManSetRegNum(Aig_Man_t *p, int nRegs)
void Aig_MmFlexStop(Aig_MmFlex_t *p, int fVerbose)
char * Aig_MmFlexEntryFetch(Aig_MmFlex_t *p, int nBytes)
Aig_Man_t * Aig_ManReduceLaches(Aig_Man_t *p, int fVerbose)
#define Aig_ManForEachLiSeq(p, pObj, i)
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Aig_Obj_t * Aig_ObjCreateCo(Aig_Man_t *p, Aig_Obj_t *pDriver)
struct Aig_Obj_t_ Aig_Obj_t
struct Aig_MmFlex_t_ Aig_MmFlex_t
Aig_Man_t * Aig_ManStart(int nNodesMax)
DECLARATIONS ///.
#define Aig_ManForEachNode(p, pObj, i)
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
int Aig_ManCleanup(Aig_Man_t *p)
#define Aig_ManForEachPiSeq(p, pObj, i)
SEQUENTIAL ITERATORS ///.
#define Aig_ManForEachPoSeq(p, pObj, i)
Aig_MmFlex_t * Aig_MmFlexStart()
Aig_Obj_t * Aig_ObjCreateCi(Aig_Man_t *p)
DECLARATIONS ///.
#define Aig_ManForEachLoSeq(p, pObj, i)
#define Aig_ManForEachLiLoSeq(p, pObjLi, pObjLo, k)
ABC_DLL int Aig_ManCheck(Aig_Man_t *p)
FUNCTION DECLARATIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.