54 word iBestArea, tCur, iThis;
55 int * pPerm[7], nPerms[7], Perm[7], * Perm1, * Perm2;
56 int iBestCell, iBestPerm, iBestDiff;
57 int i, k, n, v,
p, Count = 0;
58 int iGate1 = -1, iGate2 = -1;
60 for ( i = 1; i <= 6; i++ )
62 for ( i = 1; i <= 6; i++ )
65 for ( i = 2; i < nCells; i++ )
67 int nFanins = pCells[i].
nFanins;
68 for ( n = 0; n <= nFanins; n++ )
71 iThis = (n == nFanins) ? ~pCells[i].uTruth : Abc_Tt6Flip(pCells[i].uTruth, n);
73 iBestArea = ~((
word)0);
74 iBestCell = iBestPerm = iBestDiff = -1;
76 for ( k = 2; k < nCells; k++ )
78 if ( nFanins != (
int)pCells[k].nFanins )
80 if ( i != k && pCells[i].uTruth == pCells[k].uTruth )
88 for ( v = 0; v < nFanins; v++ )
92 for (
p = 0;
p < nPerms[nFanins];
p++ )
94 if ( iThis == tCur && iBestArea > pCells[k].AreaW )
96 iBestArea = pCells[k].
AreaW;
99 for ( v = 0; v < nFanins; v++ )
100 iBestPerm |= (v << (Perm[v] << 2));
101 iBestDiff = (pCells[i].
AreaW >= pCells[k].
AreaW) ? (
int)(pCells[i].
AreaW - pCells[k].
AreaW) : -(int)(pCells[k].AreaW - pCells[i].AreaW);
103 if ( nPerms[nFanins] == 1 )
106 tCur = Abc_Tt6SwapAdjacent( tCur, pPerm[nFanins][
p] );
107 Perm1 = Perm + pPerm[nFanins][
p];
111 assert( tCur == pCells[k].uTruth );
113 Vec_IntPushThree( vInfo, iBestCell, iBestPerm, iBestDiff );
117 for ( i = 1; i <= 6; i++ )
120 printf(
"In this library, %d cell pairs have equal functions (for example, %s and %s).\n", Count/2, pCells[iGate1].pName, pCells[iGate2].pName );
126 Vec_Int_t * vFirst = Vec_IntStartFull( 2 );
127 for ( i = 2; i < nCells; i++ )
129 Vec_IntPush( vFirst, Index );
130 Index += 3 * (pCells[i].
nFanins + 1);
132 assert( nCells == Vec_IntSize(vFirst) );
137 int i, n, v, Index = 0, nRecUsed = 0;
138 for ( i = 2; i < nCells; i++ )
140 int nFanins = pCells[i].
nFanins;
141 printf(
"%3d : %8s Fanins = %d ", i, pCells[i].pName, nFanins );
143 for ( n = 0; n <= nFanins; n++, Index += 3 )
145 int iCellA = Vec_IntEntry( vInfo, Index+0 );
146 int iPerm = Vec_IntEntry( vInfo, Index+1 );
147 int Diff = Vec_IntEntry( vInfo, Index+2 );
150 printf(
"%d : {", n );
151 for ( v = 0; v < nFanins; v++ )
152 printf(
" %d ", (iPerm >> (v << 2)) & 15 );
153 printf(
"} Index = %d ", Index );
155 printf(
"Gain = %6.2f ", Scl_Int2Flt(Diff) );
171 printf(
"Used records = %d. All records = %d.\n", nRecUsed, Vec_IntSize(vInfo)/3 - nRecUsed );
172 assert( nCells == Vec_IntSize(vFirst) );
173 Vec_IntFree( vFirst );
174 Vec_IntFree( vInfo );
201 int * pArray = pObj->
vFanins.pArray;
202 int i, k, Limit = Abc_ObjFaninNum(pObj);
203 for ( i = 0; i < Limit; i++ )
204 for ( k = i+1; k < Limit; k++ )
205 if ( pArray[i] == pArray[k] )
211 int * pArray = pObj->
vFanouts.pArray;
212 int i, k, Limit = Abc_ObjFanoutNum(pObj);
213 for ( i = 0; i < Limit; i++ )
214 for ( k = i+1; k < Limit; k++ )
215 if ( pArray[i] == pArray[k] )
224 int * pFanInfo, * pNodeInfo = Vec_IntEntryP( vInfo, Vec_IntEntry(vFirst, iNodeCell) );
225 int i, fNeedInv = 0, Gain = 0, iFanin = Abc_ObjFaninNum(pObj), fUseInv =
Abc_NodeIsInv(pObj);
228 if ( pNodeInfo[3*iFanin] == -1 )
233 Gain = pNodeInfo[3*iFanin+2];
253 pFanInfo = Vec_IntEntryP( vInfo, Vec_IntEntry(vFirst, iFanCell) );
255 if ( pFanInfo[3*iFanin] == -1 )
260 Gain += pFanInfo[3*iFanin+2];
264 *pfUseInv = fNeedInv;
269 int v, Perm, iNodeCell = pNodeInfo[3*iFanin];
274 Perm = pNodeInfo[3*iFanin+1];
275 Vec_IntClear( vTemp );
276 for ( v = 0; v < Abc_ObjFaninNum(pObj); v++ )
277 Vec_IntPush( vTemp, Abc_ObjFaninId(pObj, (Perm >> (v << 2)) & 15) );
278 Vec_IntClear( &pObj->
vFanins );
279 Vec_IntAppend( &pObj->
vFanins, vTemp );
283 Abc_Obj_t * pNext, * pNext2, * pNodeInv = NULL;
285 int * pFanInfo, * pNodeInfo = Vec_IntEntryP( vInfo, Vec_IntEntry(vFirst, iNodeCell) );
286 int i, k, iFanin = Abc_ObjFaninNum(pObj);
287 assert( iFanin > 0 && pNodeInfo[3*iFanin] != -1 );
292 Abc_Obj_t * pFanin = Abc_ObjFanin0(pObj);
295 assert( Abc_ObjFanoutNum(pObj) == 0 );
318 assert( Abc_ObjFanoutNum(pNext) == 0 );
324 pFanInfo = Vec_IntEntryP( vInfo, Vec_IntEntry(vFirst, iFanCell) );
325 if ( pFanInfo[3*iFanin] == -1 )
336 int i, fNeedInv, nCells, Gain, GainAll = 0, Count = 0, CountInv = 0;
341 Vec_Ptr_t * vFanout = Vec_PtrAlloc( 100 );
342 Vec_Ptr_t * vFanout2 = Vec_PtrAlloc( 100 );
351 Gain =
Abc_ObjChangeEval( pObj, vInfo, vFirst, (
int)pCells[3].AreaW, &fNeedInv );
360 Vec_PtrFree( vFanout2 );
361 Vec_PtrFree( vFanout );
362 Vec_IntFree( vTemp );
364 Vec_IntFree( vFirst );
365 Vec_IntFree( vInfo );
369 printf(
"Total gain in area = %6.2f after %d changes (including %d inverters). ", Scl_Int2Flt(GainAll), Count, CountInv );
371 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
struct Abc_Obj_t_ Abc_Obj_t
ABC_DLL void Abc_NtkDeleteObj(Abc_Obj_t *pObj)
ABC_DLL int Abc_NodeIsBuf(Abc_Obj_t *pNode)
#define Abc_ObjForEachFanout(pObj, pFanout, i)
ABC_DLL int Abc_NodeIsInv(Abc_Obj_t *pNode)
ABC_DLL void Abc_NodeCollectFanouts(Abc_Obj_t *pNode, Vec_Ptr_t *vNodes)
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeInv(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
ABC_DLL void Abc_ObjPatchFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFaninOld, Abc_Obj_t *pFaninNew)
ABC_DLL int Abc_NodeFindFanin(Abc_Obj_t *pNode, Abc_Obj_t *pFanin)
#define Abc_NtkForEachNode(pNtk, pNode, i)
#define ABC_SWAP(Type, a, b)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
void Dau_DsdPrintFromTruth(word *pTruth, int nVarsInit)
unsigned __int64 word
DECLARATIONS ///.
Mio_Cell2_t * Mio_CollectRootsNewDefault2(int nInputs, int *pnGates, int fVerbose)
struct Mio_Cell2_t_ Mio_Cell2_t
struct Mio_GateStruct_t_ Mio_Gate_t
int Mio_GateReadCell(Mio_Gate_t *pGate)
Vec_Int_t * Abc_NtkPrecomputeFirsts(Mio_Cell2_t *pCells, int nCells)
void Abc_NtkPrecomputeCellPairsTest()
int Abc_ObjHasDupFanouts(Abc_Obj_t *pObj)
void Abc_ObjChangeUpdate(Abc_Obj_t *pObj, int iFanin, Mio_Cell2_t *pCells, int *pNodeInfo, Vec_Int_t *vTemp)
void Abc_ObjChangePerform(Abc_Obj_t *pObj, Vec_Int_t *vInfo, Vec_Int_t *vFirst, int fUseInv, Vec_Int_t *vTemp, Vec_Ptr_t *vFanout, Vec_Ptr_t *vFanout2, Mio_Cell2_t *pCells)
int Abc_NtkPrecomputePrint(Mio_Cell2_t *pCells, int nCells, Vec_Int_t *vInfo)
int Abc_ObjChangeEval(Abc_Obj_t *pObj, Vec_Int_t *vInfo, Vec_Int_t *vFirst, int InvArea, int *pfUseInv)
int Abc_ObjHasDupFanins(Abc_Obj_t *pObj)
int Abc_NodeCheckFanoutHasFanin(Abc_Obj_t *pNode, Abc_Obj_t *pFanin)
ABC_NAMESPACE_IMPL_START Vec_Int_t * Abc_NtkPrecomputeCellPairs(Mio_Cell2_t *pCells, int nCells)
DECLARATIONS ///.
void Abc_NtkChangePerform(Abc_Ntk_t *pNtk, int fVerbose)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.