ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcRenode.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22#include "map/if/if.h"
23#include "bool/kit/kit.h"
24
25#ifdef ABC_USE_CUDD
26#include "bdd/extrab/extraBdd.h"
27#include "bdd/reo/reo.h"
28#endif
29
31
32
36
37#ifdef ABC_USE_CUDD
38
39static int Abc_NtkRenodeEvalAig( If_Man_t * p, If_Cut_t * pCut );
40static int Abc_NtkRenodeEvalBdd( If_Man_t * p, If_Cut_t * pCut );
41static int Abc_NtkRenodeEvalSop( If_Man_t * p, If_Cut_t * pCut );
42static int Abc_NtkRenodeEvalCnf( If_Man_t * p, If_Cut_t * pCut );
43static int Abc_NtkRenodeEvalMv( If_Man_t * p, If_Cut_t * pCut );
44
45static reo_man * s_pReo = NULL;
46static DdManager * s_pDd = NULL;
47static Vec_Int_t * s_vMemory = NULL;
48static Vec_Int_t * s_vMemory2 = NULL;
49
50static int nDsdCounter = 0;
51
55
67Abc_Ntk_t * Abc_NtkRenode( Abc_Ntk_t * pNtk, int nFaninMax, int nCubeMax, int nFlowIters, int nAreaIters, int fArea, int fUseBdds, int fUseSops, int fUseCnfs, int fUseMv, int fVerbose )
68{
69 extern Abc_Ntk_t * Abc_NtkIf( Abc_Ntk_t * pNtk, If_Par_t * pPars );
70 If_Par_t Pars, * pPars = &Pars;
71 Abc_Ntk_t * pNtkNew;
72
73 if ( Abc_NtkGetChoiceNum( pNtk ) )
74 printf( "Performing renoding with choices.\n" );
75
76 nDsdCounter = 0;
77
78 // set defaults
79 memset( pPars, 0, sizeof(If_Par_t) );
80 // user-controlable paramters
81 pPars->nLutSize = nFaninMax;
82 pPars->nCutsMax = nCubeMax;
83 pPars->nFlowIters = nFlowIters;
84 pPars->nAreaIters = nAreaIters;
85 pPars->DelayTarget = -1;
86 pPars->Epsilon = (float)0.005;
87 pPars->fPreprocess = 1;
88 pPars->fArea = fArea;
89 pPars->fFancy = 0;
90 pPars->fExpRed = 0; //
91 pPars->fLatchPaths = 0;
92 pPars->fVerbose = fVerbose;
93 // internal parameters
94 pPars->fTruth = 1;
95 pPars->fUsePerm = 1;
96 pPars->nLatchesCi = 0;
97 pPars->nLatchesCo = 0;
98 pPars->pLutLib = NULL; // Abc_FrameReadLibLut();
99 pPars->pTimesArr = NULL;
100 pPars->pTimesArr = NULL;
101 pPars->fUseBdds = fUseBdds;
102 pPars->fUseSops = fUseSops;
103 pPars->fUseCnfs = fUseCnfs;
104 pPars->fUseMv = fUseMv;
105 if ( fUseBdds )
106 pPars->pFuncCost = Abc_NtkRenodeEvalBdd;
107 else if ( fUseSops )
108 pPars->pFuncCost = Abc_NtkRenodeEvalSop;
109 else if ( fUseCnfs )
110 {
111 pPars->fArea = 1;
112 pPars->pFuncCost = Abc_NtkRenodeEvalCnf;
113 }
114 else if ( fUseMv )
115 pPars->pFuncCost = Abc_NtkRenodeEvalMv;
116 else
117 pPars->pFuncCost = Abc_NtkRenodeEvalAig;
118
119 // start the manager
120 if ( fUseBdds )
121 {
122 assert( s_pReo == NULL );
123 s_pDd = Cudd_Init( nFaninMax, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
124 s_pReo = Extra_ReorderInit( nFaninMax, 100 );
125 pPars->pReoMan = s_pReo;
126 }
127 else
128 {
129 assert( s_vMemory == NULL );
130 s_vMemory = Vec_IntAlloc( 1 << 16 );
131 s_vMemory2 = Vec_IntAlloc( 1 << 16 );
132 }
133
134 // perform mapping/renoding
135 pNtkNew = Abc_NtkIf( pNtk, pPars );
136
137 // start the manager
138 if ( fUseBdds )
139 {
140 Extra_StopManager( s_pDd );
141 Extra_ReorderQuit( s_pReo );
142 s_pReo = NULL;
143 s_pDd = NULL;
144 }
145 else
146 {
147 Vec_IntFree( s_vMemory );
148 Vec_IntFree( s_vMemory2 );
149 s_vMemory = NULL;
150 s_vMemory2 = NULL;
151 }
152
153// printf( "Decomposed %d functions.\n", nDsdCounter );
154
155 return pNtkNew;
156}
157
169int Abc_NtkRenodeEvalAig( If_Man_t * p, If_Cut_t * pCut )
170{
171 char * pPerm = If_CutPerm( pCut );
172 Kit_Graph_t * pGraph;
173 int i, nNodes;
174 pGraph = Kit_TruthToGraph( If_CutTruth(p, pCut), If_CutLeaveNum(pCut), s_vMemory );
175 if ( pGraph == NULL )
176 {
177 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
178 pPerm[i] = 100;
179 return IF_COST_MAX;
180 }
181 nNodes = Kit_GraphNodeNum( pGraph );
182 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
183 pPerm[i] = Kit_GraphLeafDepth_rec( pGraph, Kit_GraphNodeLast(pGraph), Kit_GraphNode(pGraph, i) );
184 Kit_GraphFree( pGraph );
185 return nNodes;
186}
187
199int Abc_NtkRenodeEvalBdd( If_Man_t * p, If_Cut_t * pCut )
200{
201 char * pPerm = If_CutPerm( pCut );
202 int pOrder[IF_MAX_LUTSIZE];
203 DdNode * bFunc, * bFuncNew;
204 int i, k, nNodes;
205 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
206 pPerm[i] = pOrder[i] = -100;
207 bFunc = Kit_TruthToBdd( s_pDd, If_CutTruth(p, pCut), If_CutLeaveNum(pCut), 0 ); Cudd_Ref( bFunc );
208 bFuncNew = Extra_Reorder( s_pReo, s_pDd, bFunc, pOrder ); Cudd_Ref( bFuncNew );
209 for ( i = k = 0; i < If_CutLeaveNum(pCut); i++ )
210 if ( pOrder[i] >= 0 )
211 pPerm[pOrder[i]] = ++k; // double-check this!
212 nNodes = -1 + Cudd_DagSize( bFuncNew );
213 Cudd_RecursiveDeref( s_pDd, bFuncNew );
214 Cudd_RecursiveDeref( s_pDd, bFunc );
215 return nNodes;
216}
217
229int Abc_NtkRenodeEvalSop( If_Man_t * p, If_Cut_t * pCut )
230{
231 char * pPerm = If_CutPerm( pCut );
232 int i, RetValue;
233 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
234 pPerm[i] = 1;
235 RetValue = Kit_TruthIsop( If_CutTruth(p, pCut), If_CutLeaveNum(pCut), s_vMemory, 1 );
236 if ( RetValue == -1 )
237 return IF_COST_MAX;
238 assert( RetValue == 0 || RetValue == 1 );
239 return Vec_IntSize( s_vMemory );
240}
241
253int Abc_NtkRenodeEvalCnf( If_Man_t * p, If_Cut_t * pCut )
254{
255 char * pPerm = If_CutPerm( pCut );
256 int i, RetValue, nClauses;
257 // set internal mapper parameters
258 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
259 pPerm[i] = 1;
260 // compute ISOP for the positive phase
261 RetValue = Kit_TruthIsop( If_CutTruth(p, pCut), If_CutLeaveNum(pCut), s_vMemory, 0 );
262 if ( RetValue == -1 )
263 return IF_COST_MAX;
264 assert( RetValue == 0 || RetValue == 1 );
265 nClauses = Vec_IntSize( s_vMemory );
266 // compute ISOP for the negative phase
267 Kit_TruthNot( If_CutTruth(p, pCut), If_CutTruth(p, pCut), If_CutLeaveNum(pCut) );
268 RetValue = Kit_TruthIsop( If_CutTruth(p, pCut), If_CutLeaveNum(pCut), s_vMemory, 0 );
269 Kit_TruthNot( If_CutTruth(p, pCut), If_CutTruth(p, pCut), If_CutLeaveNum(pCut) );
270 if ( RetValue == -1 )
271 return IF_COST_MAX;
272 assert( RetValue == 0 || RetValue == 1 );
273 nClauses += Vec_IntSize( s_vMemory );
274 return nClauses;
275}
276
288int Abc_NtkRenodeEvalMv( If_Man_t * p, If_Cut_t * pCut )
289{
290 char * pPerm = If_CutPerm( pCut );
291 int i, RetValue;
292 // set internal mapper parameters
293 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
294 pPerm[i] = 1;
295 // compute ISOP for the positive phase
296 RetValue = Kit_TruthIsop( If_CutTruth(p, pCut), If_CutLeaveNum(pCut), s_vMemory, 0 );
297 if ( RetValue == -1 )
298 return IF_COST_MAX;
299 assert( RetValue == 0 || RetValue == 1 );
300 // compute ISOP for the negative phase
301 Kit_TruthNot( If_CutTruth(p, pCut), If_CutTruth(p, pCut), If_CutLeaveNum(pCut) );
302 RetValue = Kit_TruthIsop( If_CutTruth(p, pCut), If_CutLeaveNum(pCut), s_vMemory2, 0 );
303 Kit_TruthNot( If_CutTruth(p, pCut), If_CutTruth(p, pCut), If_CutLeaveNum(pCut) );
304 if ( RetValue == -1 )
305 return IF_COST_MAX;
306 assert( RetValue == 0 || RetValue == 1 );
307 // return the cost of the cut
308 RetValue = Abc_NodeEvalMvCost( If_CutLeaveNum(pCut), s_vMemory, s_vMemory2 );
309 if ( RetValue >= IF_COST_MAX )
310 return IF_COST_MAX;
311 return RetValue;
312}
313
314#else
315
316Abc_Ntk_t * Abc_NtkRenode( Abc_Ntk_t * pNtk, int nFaninMax, int nCubeMax, int nFlowIters, int nAreaIters, int fArea, int fUseBdds, int fUseSops, int fUseCnfs, int fUseMv, int fVerbose ) { return NULL; }
317
318#endif
319
323
324
326
ABC_NAMESPACE_IMPL_START Abc_Ntk_t * Abc_NtkRenode(Abc_Ntk_t *pNtk, int nFaninMax, int nCubeMax, int nFlowIters, int nAreaIters, int fArea, int fUseBdds, int fUseSops, int fUseCnfs, int fUseMv, int fVerbose)
DECLARATIONS ///.
Definition abcRenode.c:316
ABC_DLL int Abc_NodeEvalMvCost(int nVars, Vec_Int_t *vSop0, Vec_Int_t *vSop1)
Definition abcBlifMv.c:1140
ABC_DLL int Abc_NtkGetChoiceNum(Abc_Ntk_t *pNtk)
Definition abcUtil.c:463
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
#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
Cube * p
Definition exorList.c:222
void Extra_StopManager(DdManager *dd)
Abc_Ntk_t * Abc_NtkIf(Abc_Ntk_t *pNtk, If_Par_t *pPars)
Definition abcIf.c:107
struct If_Par_t_ If_Par_t
Definition if.h:78
struct If_Cut_t_ If_Cut_t
Definition if.h:80
#define IF_COST_MAX
Definition if.h:59
#define IF_MAX_LUTSIZE
INCLUDES ///.
Definition if.h:53
struct If_Man_t_ If_Man_t
BASIC TYPES ///.
Definition if.h:77
struct Kit_Graph_t_ Kit_Graph_t
Definition kit.h:88
int Kit_TruthIsop(unsigned *puTruth, int nVars, Vec_Int_t *vMemory, int fTryBoth)
Definition kitIsop.c:134
int Kit_GraphLeafDepth_rec(Kit_Graph_t *pGraph, Kit_Node_t *pNode, Kit_Node_t *pLeaf)
Definition kitGraph.c:412
void Kit_GraphFree(Kit_Graph_t *pGraph)
Definition kitGraph.c:132
Kit_Graph_t * Kit_TruthToGraph(unsigned *pTruth, int nVars, Vec_Int_t *vMemory)
Definition kitGraph.c:356
struct _reo_man reo_man
Definition reo.h:63
void Extra_ReorderQuit(reo_man *p)
Definition reoApi.c:79
DdNode * Extra_Reorder(reo_man *p, DdManager *dd, DdNode *Func, int *pOrder)
Definition reoApi.c:262
reo_man * Extra_ReorderInit(int nDdVarsMax, int nNodesMax)
FUNCTION DECLARATIONS ///.
Definition reoApi.c:50
float * pTimesArr
Definition if.h:176
int fLatchPaths
Definition if.h:121
int fUseSops
Definition if.h:163
float Epsilon
Definition if.h:111
int fTruth
Definition if.h:160
int nLutSize
Definition if.h:104
int fUseCnfs
Definition if.h:164
int fExpRed
Definition if.h:120
int nLatchesCo
Definition if.h:167
int nFlowIters
Definition if.h:106
int nAreaIters
Definition if.h:107
int fUseBdds
Definition if.h:162
int fUseMv
Definition if.h:165
int nCutsMax
Definition if.h:105
int fVerbose
Definition if.h:152
float DelayTarget
Definition if.h:110
void * pReoMan
Definition if.h:183
int fPreprocess
Definition if.h:117
If_LibLut_t * pLutLib
Definition if.h:175
int nLatchesCi
Definition if.h:166
int fFancy
Definition if.h:119
int(* pFuncCost)(If_Man_t *, If_Cut_t *)
Definition if.h:178
int fUsePerm
Definition if.h:161
int fArea
Definition if.h:118
#define assert(ex)
Definition util_old.h:213
char * memset()