1 /**CFile****************************************************************
2
3 FileName [abcRenode.c]
4
5 SystemName [ABC: Logic synthesis and verification system.]
6
7 PackageName [Network and node package.]
8
9 Synopsis []
10
11 Author [Alan Mishchenko]
12
13 Affiliation [UC Berkeley]
14
15 Date [Ver. 1.0. Started - June 20, 2005.]
16
17 Revision [$Id: abcRenode.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18
19 ***********************************************************************/
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
30 ABC_NAMESPACE_IMPL_START
31
32
33 ////////////////////////////////////////////////////////////////////////
34 /// DECLARATIONS ///
35 ////////////////////////////////////////////////////////////////////////
36
37 #ifdef ABC_USE_CUDD
38
39 static int Abc_NtkRenodeEvalAig( If_Man_t * p, If_Cut_t * pCut );
40 static int Abc_NtkRenodeEvalBdd( If_Man_t * p, If_Cut_t * pCut );
41 static int Abc_NtkRenodeEvalSop( If_Man_t * p, If_Cut_t * pCut );
42 static int Abc_NtkRenodeEvalCnf( If_Man_t * p, If_Cut_t * pCut );
43 static int Abc_NtkRenodeEvalMv( If_Man_t * p, If_Cut_t * pCut );
44
45 static reo_man * s_pReo = NULL;
46 static DdManager * s_pDd = NULL;
47 static Vec_Int_t * s_vMemory = NULL;
48 static Vec_Int_t * s_vMemory2 = NULL;
49
50 static int nDsdCounter = 0;
51
52 ////////////////////////////////////////////////////////////////////////
53 /// FUNCTION DEFINITIONS ///
54 ////////////////////////////////////////////////////////////////////////
55
56 /**Function*************************************************************
57
58 Synopsis [Performs renoding as technology mapping.]
59
60 Description []
61
62 SideEffects []
63
64 SeeAlso []
65
66 ***********************************************************************/
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)67 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 )
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
158 /**Function*************************************************************
159
160 Synopsis [Computes the cost based on the factored form.]
161
162 Description []
163
164 SideEffects []
165
166 SeeAlso []
167
168 ***********************************************************************/
Abc_NtkRenodeEvalAig(If_Man_t * p,If_Cut_t * pCut)169 int 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
188 /**Function*************************************************************
189
190 Synopsis [Computes the cost based on the BDD size after reordering.]
191
192 Description []
193
194 SideEffects []
195
196 SeeAlso []
197
198 ***********************************************************************/
Abc_NtkRenodeEvalBdd(If_Man_t * p,If_Cut_t * pCut)199 int 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
218 /**Function*************************************************************
219
220 Synopsis [Computes the cost based on ISOP.]
221
222 Description []
223
224 SideEffects []
225
226 SeeAlso []
227
228 ***********************************************************************/
Abc_NtkRenodeEvalSop(If_Man_t * p,If_Cut_t * pCut)229 int 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
242 /**Function*************************************************************
243
244 Synopsis [Computes the cost based on two ISOPs.]
245
246 Description []
247
248 SideEffects []
249
250 SeeAlso []
251
252 ***********************************************************************/
Abc_NtkRenodeEvalCnf(If_Man_t * p,If_Cut_t * pCut)253 int 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
277 /**Function*************************************************************
278
279 Synopsis [Computes the cost of MV-SOP of the cut function.]
280
281 Description []
282
283 SideEffects []
284
285 SeeAlso []
286
287 ***********************************************************************/
Abc_NtkRenodeEvalMv(If_Man_t * p,If_Cut_t * pCut)288 int 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
316 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 ) { return NULL; }
317
318 #endif
319
320 ////////////////////////////////////////////////////////////////////////
321 /// END OF FILE ///
322 ////////////////////////////////////////////////////////////////////////
323
324
325 ABC_NAMESPACE_IMPL_END
326
327