ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
nwkBidec.c
Go to the documentation of this file.
1
20
21#include "nwk.h"
22
24
25
29
30static inline int Extra_TruthWordNum( int nVars ) { return nVars <= 5 ? 1 : (1 << (nVars - 5)); }
31static inline void Extra_TruthNot( unsigned * pOut, unsigned * pIn, int nVars )
32{
33 int w;
34 for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
35 pOut[w] = ~pIn[w];
36}
37static inline void Extra_TruthOr( unsigned * pOut, unsigned * pIn0, unsigned * pIn1, int nVars )
38{
39 int w;
40 for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
41 pOut[w] = pIn0[w] | pIn1[w];
42}
43static inline void Extra_TruthSharp( unsigned * pOut, unsigned * pIn0, unsigned * pIn1, int nVars )
44{
45 int w;
46 for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
47 pOut[w] = pIn0[w] & ~pIn1[w];
48}
49
50static inline Hop_Obj_t * Bdc_FunCopyHop( Bdc_Fun_t * pObj ) { return Hop_NotCond( (Hop_Obj_t *)Bdc_FuncCopy(Bdc_Regular(pObj)), Bdc_IsComplement(pObj) ); }
51
55
67Hop_Obj_t * Nwk_NodeIfNodeResyn( Bdc_Man_t * p, Hop_Man_t * pHop, Hop_Obj_t * pRoot, int nVars, Vec_Int_t * vTruth, unsigned * puCare, float dProb )
68{
69 unsigned * pTruth;
70 Bdc_Fun_t * pFunc;
71 int nNodes, i;
72 assert( nVars <= 16 );
73 // derive truth table
74 pTruth = Hop_ManConvertAigToTruth( pHop, Hop_Regular(pRoot), nVars, vTruth, 0 );
75 if ( Hop_IsComplement(pRoot) )
76 for ( i = Abc_TruthWordNum(nVars)-1; i >= 0; i-- )
77 pTruth[i] = ~pTruth[i];
78 // perform power-aware decomposition
79 if ( dProb >= 0.0 )
80 {
81 float Prob = (float)2.0 * dProb * (1.0 - dProb);
82 assert( Prob >= 0.0 && Prob <= 0.5 );
83 if ( Prob >= 0.4 )
84 {
85 Extra_TruthNot( puCare, puCare, nVars );
86 if ( dProb > 0.5 ) // more 1s than 0s
87 Extra_TruthOr( pTruth, pTruth, puCare, nVars );
88 else
89 Extra_TruthSharp( pTruth, pTruth, puCare, nVars );
90 Extra_TruthNot( puCare, puCare, nVars );
91 // decompose truth table
92 Bdc_ManDecompose( p, pTruth, NULL, nVars, NULL, 1000 );
93 }
94 else
95 {
96 // decompose truth table
97 Bdc_ManDecompose( p, pTruth, puCare, nVars, NULL, 1000 );
98 }
99 }
100 else
101 {
102 // decompose truth table
103 Bdc_ManDecompose( p, pTruth, puCare, nVars, NULL, 1000 );
104 }
105 // convert back into HOP
106 Bdc_FuncSetCopy( Bdc_ManFunc( p, 0 ), Hop_ManConst1( pHop ) );
107 for ( i = 0; i < nVars; i++ )
108 Bdc_FuncSetCopy( Bdc_ManFunc( p, i+1 ), Hop_ManPi( pHop, i ) );
109 nNodes = Bdc_ManNodeNum(p);
110 for ( i = nVars + 1; i < nNodes; i++ )
111 {
112 pFunc = Bdc_ManFunc( p, i );
113 Bdc_FuncSetCopy( pFunc, Hop_And( pHop, Bdc_FunCopyHop(Bdc_FuncFanin0(pFunc)), Bdc_FunCopyHop(Bdc_FuncFanin1(pFunc)) ) );
114 }
115 return Bdc_FunCopyHop( Bdc_ManRoot(p) );
116}
117
129void Nwk_ManBidecResyn( Nwk_Man_t * pNtk, int fVerbose )
130{
131 Bdc_Par_t Pars = {0}, * pPars = &Pars;
132 Bdc_Man_t * p;
133 Nwk_Obj_t * pObj;
134 Vec_Int_t * vTruth;
135 int i, nGainTotal = 0, nNodes1, nNodes2;
136 abctime clk = Abc_Clock();
137 pPars->nVarsMax = Nwk_ManGetFaninMax( pNtk );
138 pPars->fVerbose = fVerbose;
139 if ( pPars->nVarsMax < 2 )
140 {
141 printf( "Resynthesis is not performed for networks whose nodes are less than 2 inputs.\n" );
142 return;
143 }
144 if ( pPars->nVarsMax > 15 )
145 {
146 if ( fVerbose )
147 printf( "Resynthesis is not performed for nodes with more than 15 inputs.\n" );
148 pPars->nVarsMax = 15;
149 }
150 vTruth = Vec_IntAlloc( 0 );
151 p = Bdc_ManAlloc( pPars );
152 Nwk_ManForEachNode( pNtk, pObj, i )
153 {
154 if ( Nwk_ObjFaninNum(pObj) > 15 )
155 continue;
156 nNodes1 = Hop_DagSize(pObj->pFunc);
157 pObj->pFunc = Nwk_NodeIfNodeResyn( p, pNtk->pManHop, pObj->pFunc, Nwk_ObjFaninNum(pObj), vTruth, NULL, -1.0 );
158 nNodes2 = Hop_DagSize(pObj->pFunc);
159 nGainTotal += nNodes1 - nNodes2;
160 }
161 Bdc_ManFree( p );
162 Vec_IntFree( vTruth );
163 if ( fVerbose )
164 {
165 printf( "Total gain in AIG nodes = %d. ", nGainTotal );
166 ABC_PRT( "Total runtime", Abc_Clock() - clk );
167 }
168}
169
170
174
175
177
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#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
int Bdc_ManNodeNum(Bdc_Man_t *p)
Definition bdcCore.c:48
Bdc_Fun_t * Bdc_FuncFanin0(Bdc_Fun_t *p)
Definition bdcCore.c:50
Bdc_Fun_t * Bdc_ManRoot(Bdc_Man_t *p)
Definition bdcCore.c:47
typedefABC_NAMESPACE_HEADER_START struct Bdc_Fun_t_ Bdc_Fun_t
INCLUDES ///.
Definition bdc.h:42
struct Bdc_Par_t_ Bdc_Par_t
Definition bdc.h:44
void Bdc_FuncSetCopy(Bdc_Fun_t *p, void *pCopy)
Definition bdcCore.c:54
struct Bdc_Man_t_ Bdc_Man_t
Definition bdc.h:43
Bdc_Fun_t * Bdc_FuncFanin1(Bdc_Fun_t *p)
Definition bdcCore.c:51
void * Bdc_FuncCopy(Bdc_Fun_t *p)
Definition bdcCore.c:52
void Bdc_ManFree(Bdc_Man_t *p)
Definition bdcCore.c:113
int Bdc_ManDecompose(Bdc_Man_t *p, unsigned *puFunc, unsigned *puCare, int nVars, Vec_Ptr_t *vDivs, int nNodesMax)
Definition bdcCore.c:291
Bdc_Fun_t * Bdc_ManFunc(Bdc_Man_t *p, int i)
DECLARATIONS ///.
Definition bdcCore.c:46
Bdc_Man_t * Bdc_ManAlloc(Bdc_Par_t *pPars)
MACRO DEFINITIONS ///.
Definition bdcCore.c:68
Cube * p
Definition exorList.c:222
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition hop.h:49
int Hop_DagSize(Hop_Obj_t *pObj)
Definition hopDfs.c:279
Hop_Obj_t * Hop_And(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition hopOper.c:104
unsigned * Hop_ManConvertAigToTruth(Hop_Man_t *p, Hop_Obj_t *pRoot, int nVars, Vec_Int_t *vTruth, int fMsbFirst)
Definition hopTruth.c:143
struct Hop_Obj_t_ Hop_Obj_t
Definition hop.h:50
struct Nwk_Man_t_ Nwk_Man_t
Definition ntlnwk.h:41
Hop_Obj_t * Nwk_NodeIfNodeResyn(Bdc_Man_t *p, Hop_Man_t *pHop, Hop_Obj_t *pRoot, int nVars, Vec_Int_t *vTruth, unsigned *puCare, float dProb)
FUNCTION DEFINITIONS ///.
Definition nwkBidec.c:67
void Nwk_ManBidecResyn(Nwk_Man_t *pNtk, int fVerbose)
Definition nwkBidec.c:129
#define Nwk_ManForEachNode(p, pObj, i)
Definition nwk.h:192
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition nwk.h:49
ABC_DLL int Nwk_ManGetFaninMax(Nwk_Man_t *pNtk)
Definition nwkUtil.c:71
Hop_Man_t * pManHop
Definition nwk.h:73
#define assert(ex)
Definition util_old.h:213