ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
mapperRefs.c
Go to the documentation of this file.
1
18
19#include "mapperInt.h"
20
22
23
27
31
43int Map_NodeReadRefPhaseAct( Map_Node_t * pNode, int fPhase )
44{
45 assert( !Map_IsComplement(pNode) );
46 if ( pNode->pCutBest[0] && pNode->pCutBest[1] ) // both assigned
47 return pNode->nRefAct[fPhase];
48 assert( pNode->pCutBest[0] || pNode->pCutBest[1] ); // at least one assigned
49 return pNode->nRefAct[2];
50}
51
63float Map_NodeReadRefPhaseEst( Map_Node_t * pNode, int fPhase )
64{
65 assert( !Map_IsComplement(pNode) );
66 if ( pNode->pCutBest[0] && pNode->pCutBest[1] ) // both assigned
67 return pNode->nRefEst[fPhase];
68 assert( pNode->pCutBest[0] || pNode->pCutBest[1] ); // at least one assigned
69// return pNode->nRefEst[0] + pNode->nRefEst[1];
70 return pNode->nRefEst[2];
71}
72
73
85int Map_NodeIncRefPhaseAct( Map_Node_t * pNode, int fPhase )
86{
87 assert( !Map_IsComplement(pNode) );
88 if ( pNode->pCutBest[0] && pNode->pCutBest[1] ) // both assigned
89 return pNode->nRefAct[fPhase]++;
90 assert( pNode->pCutBest[0] || pNode->pCutBest[1] ); // at least one assigned
91 return pNode->nRefAct[2]++;
92}
93
105int Map_NodeDecRefPhaseAct( Map_Node_t * pNode, int fPhase )
106{
107 assert( !Map_IsComplement(pNode) );
108 if ( pNode->pCutBest[0] && pNode->pCutBest[1] ) // both assigned
109 return --pNode->nRefAct[fPhase];
110 assert( pNode->pCutBest[0] || pNode->pCutBest[1] ); // at least one assigned
111 return --pNode->nRefAct[2];
112}
113
114
127{
128 Map_Node_t * pNode;
129 int i;
130 for ( i = 0; i < p->vMapObjs->nSize; i++ )
131 {
132 pNode = p->vMapObjs->pArray[i];
133// pNode->nRefEst[0] = pNode->nRefEst[1] = ((float)pNode->nRefs)*(float)2.0;
134 pNode->nRefEst[0] = pNode->nRefEst[1] = pNode->nRefEst[2] = ((float)pNode->nRefs);
135 }
136}
137
152{
153 Map_Node_t * pNode;
154 int i;
155 for ( i = 0; i < p->vMapObjs->nSize; i++ )
156 {
157 pNode = p->vMapObjs->pArray[i];
158// pNode->nRefEst[0] = (float)((2.0 * pNode->nRefEst[0] + 1.0 * pNode->nRefAct[0]) / 3.0);
159// pNode->nRefEst[1] = (float)((2.0 * pNode->nRefEst[1] + 1.0 * pNode->nRefAct[1]) / 3.0);
160// pNode->nRefEst[2] = (float)((2.0 * pNode->nRefEst[2] + 1.0 * pNode->nRefAct[2]) / 3.0);
161 pNode->nRefEst[0] = (float)((3.0 * pNode->nRefEst[0] + 1.0 * pNode->nRefAct[0]) / 4.0);
162 pNode->nRefEst[1] = (float)((3.0 * pNode->nRefEst[1] + 1.0 * pNode->nRefAct[1]) / 4.0);
163 pNode->nRefEst[2] = (float)((3.0 * pNode->nRefEst[2] + 1.0 * pNode->nRefAct[2]) / 4.0);
164 }
165}
166
179float Map_CutGetAreaFlow( Map_Cut_t * pCut, int fPhase )
180{
181 Map_Match_t * pM = pCut->M + fPhase;
182 Map_Super_t * pSuper = pM->pSuperBest;
183 unsigned uPhaseTot = pM->uPhaseBest;
184 Map_Cut_t * pCutFanin;
185 float aFlowRes, aFlowFanin, nRefs;
186 int i, fPinPhasePos;
187
188 // start the resulting area flow
189 aFlowRes = pSuper->Area;
190 // iterate through the leaves
191 for ( i = 0; i < pCut->nLeaves; i++ )
192 {
193 // get the phase of this fanin
194 fPinPhasePos = ((uPhaseTot & (1 << i)) == 0);
195 // get the cut implementing this phase of the fanin
196 pCutFanin = pCut->ppLeaves[i]->pCutBest[fPinPhasePos];
197 // if the cut is not available, we have to use the opposite phase
198 if ( pCutFanin == NULL )
199 {
200 fPinPhasePos = !fPinPhasePos;
201 pCutFanin = pCut->ppLeaves[i]->pCutBest[fPinPhasePos];
202 }
203 aFlowFanin = pCutFanin->M[fPinPhasePos].AreaFlow; // ignores the area of the interter
204 // get the fanout count of the cut in the given phase
205 nRefs = Map_NodeReadRefPhaseEst( pCut->ppLeaves[i], fPinPhasePos );
206 // if the node does no fanout, assume fanout count equal to 1
207 if ( nRefs == (float)0.0 )
208 nRefs = (float)1.0;
209 // add the area flow due to the fanin
210 aFlowRes += aFlowFanin / nRefs;
211 }
212 pM->AreaFlow = aFlowRes;
213 return aFlowRes;
214}
215
216
229float Map_CutRefDeref( Map_Cut_t * pCut, int fPhase, int fReference, int fUpdateProf )
230{
231 Map_Node_t * pNodeChild;
232 Map_Cut_t * pCutChild;
233 float aArea;
234 int i, fPhaseChild;
235// int nRefs;
236
237 // consider the elementary variable
238 if ( pCut->nLeaves == 1 )
239 return 0;
240 // start the area of this cut
241 aArea = Map_CutGetRootArea( pCut, fPhase );
242 if ( fUpdateProf )
243 {
244 if ( fReference )
245 Mio_GateIncProfile2( pCut->M[fPhase].pSuperBest->pRoot );
246 else
247 Mio_GateDecProfile2( pCut->M[fPhase].pSuperBest->pRoot );
248 }
249 // go through the children
250 for ( i = 0; i < pCut->nLeaves; i++ )
251 {
252 pNodeChild = pCut->ppLeaves[i];
253 fPhaseChild = Map_CutGetLeafPhase( pCut, fPhase, i );
254 // get the reference counter of the child
255/*
256 // this code does not take inverters into account
257 // the quality of area recovery seems to always be a little worse
258 if ( fReference )
259 nRefs = Map_NodeIncRefPhaseAct( pNodeChild, fPhaseChild );
260 else
261 nRefs = Map_NodeDecRefPhaseAct( pNodeChild, fPhaseChild );
262 assert( nRefs >= 0 );
263 // skip if the child was already reference before
264 if ( nRefs > 0 )
265 continue;
266*/
267
268 if ( fReference )
269 {
270 if ( pNodeChild->pCutBest[0] && pNodeChild->pCutBest[1] ) // both phases are present
271 {
272 // if this phase of the node is referenced, there is no recursive call
273 pNodeChild->nRefAct[2]++;
274 if ( pNodeChild->nRefAct[fPhaseChild]++ > 0 )
275 continue;
276 }
277 else // only one phase is present
278 {
279 // inverter should be added if the phase
280 // (a) has no reference and (b) is implemented using other phase
281 if ( pNodeChild->nRefAct[fPhaseChild]++ == 0 && pNodeChild->pCutBest[fPhaseChild] == NULL )
282 aArea += pNodeChild->p->pSuperLib->AreaInv;
283 // if the node is referenced, there is no recursive call
284 if ( pNodeChild->nRefAct[2]++ > 0 )
285 continue;
286 }
287 }
288 else
289 {
290 if ( pNodeChild->pCutBest[0] && pNodeChild->pCutBest[1] ) // both phases are present
291 {
292 // if this phase of the node is referenced, there is no recursive call
293 --pNodeChild->nRefAct[2];
294 if ( --pNodeChild->nRefAct[fPhaseChild] > 0 )
295 continue;
296 }
297 else // only one phase is present
298 {
299 // inverter should be added if the phase
300 // (a) has no reference and (b) is implemented using other phase
301 if ( --pNodeChild->nRefAct[fPhaseChild] == 0 && pNodeChild->pCutBest[fPhaseChild] == NULL )
302 aArea += pNodeChild->p->pSuperLib->AreaInv;
303 // if the node is referenced, there is no recursive call
304 if ( --pNodeChild->nRefAct[2] > 0 )
305 continue;
306 }
307 assert( pNodeChild->nRefAct[fPhaseChild] >= 0 );
308 }
309
310 // get the child cut
311 pCutChild = pNodeChild->pCutBest[fPhaseChild];
312 // if the child does not have this phase mapped, take the opposite phase
313 if ( pCutChild == NULL )
314 {
315 fPhaseChild = !fPhaseChild;
316 pCutChild = pNodeChild->pCutBest[fPhaseChild];
317 }
318 // reference and compute area recursively
319 aArea += Map_CutRefDeref( pCutChild, fPhaseChild, fReference, fUpdateProf );
320 }
321 return aArea;
322}
323
335float Map_CutGetAreaRefed( Map_Cut_t * pCut, int fPhase )
336{
337 float aResult, aResult2;
338 aResult2 = Map_CutRefDeref( pCut, fPhase, 0, 0 ); // dereference
339 aResult = Map_CutRefDeref( pCut, fPhase, 1, 0 ); // reference
340// assert( aResult == aResult2 );
341 return aResult;
342}
343
355float Map_CutGetAreaDerefed( Map_Cut_t * pCut, int fPhase )
356{
357 float aResult, aResult2;
358 aResult2 = Map_CutRefDeref( pCut, fPhase, 1, 0 ); // reference
359 aResult = Map_CutRefDeref( pCut, fPhase, 0, 0 ); // dereference
360// assert( aResult == aResult2 );
361 return aResult;
362}
363
375float Map_CutRef( Map_Cut_t * pCut, int fPhase, int fProfile )
376{
377 return Map_CutRefDeref( pCut, fPhase, 1, fProfile ); // reference
378}
379
391float Map_CutDeref( Map_Cut_t * pCut, int fPhase, int fProfile )
392{
393 return Map_CutRefDeref( pCut, fPhase, 0, fProfile ); // dereference
394}
395
396
411{
412 Map_Cut_t * pCut;
413 Map_Node_t * pNodeR;
414 unsigned uPhase;
415 int i, fPhase, fInvPin;
416 // get the regular node and its phase
417 pNodeR = Map_Regular(pNode);
418 fPhase = !Map_IsComplement(pNode);
419 pNodeR->nRefAct[2]++;
420 // quit if the node was already visited in this phase
421 if ( pNodeR->nRefAct[fPhase]++ )
422 return;
423 // quit if this is a PI node
424 if ( Map_NodeIsVar(pNodeR) )
425 return;
426 // propagate through buffer
427 if ( Map_NodeIsBuf(pNodeR) )
428 {
429 Map_MappingSetRefs_rec( pMan, Map_NotCond(pNodeR->p1, Map_IsComplement(pNode)) );
430 return;
431 }
432 assert( Map_NodeIsAnd(pNode) );
433 // get the cut implementing this or opposite polarity
434 pCut = pNodeR->pCutBest[fPhase];
435 if ( pCut == NULL )
436 {
437 fPhase = !fPhase;
438 pCut = pNodeR->pCutBest[fPhase];
439 }
440 if ( pMan->fUseProfile )
441 Mio_GateIncProfile2( pCut->M[fPhase].pSuperBest->pRoot );
442 // visit the transitive fanin
443 uPhase = pCut->M[fPhase].uPhaseBest;
444 for ( i = 0; i < pCut->nLeaves; i++ )
445 {
446 fInvPin = ((uPhase & (1 << i)) > 0);
447 Map_MappingSetRefs_rec( pMan, Map_NotCond(pCut->ppLeaves[i], fInvPin) );
448 }
449}
451{
452 Map_Node_t * pNode;
453 int i;
454 if ( pMan->fUseProfile )
455 Mio_LibraryCleanProfile2( pMan->pSuperLib->pGenlib );
456 // clean all references
457 for ( i = 0; i < pMan->vMapObjs->nSize; i++ )
458 {
459 pNode = pMan->vMapObjs->pArray[i];
460 pNode->nRefAct[0] = 0;
461 pNode->nRefAct[1] = 0;
462 pNode->nRefAct[2] = 0;
463 }
464 // visit nodes reachable from POs in the DFS order through the best cuts
465 for ( i = 0; i < pMan->nOutputs; i++ )
466 {
467 pNode = pMan->pOutputs[i];
468 if ( !Map_NodeIsConst(pNode) )
469 Map_MappingSetRefs_rec( pMan, pNode );
470 }
471}
472
473
486{
487 Map_Node_t * pNode;
488 float Area = 0.0;
489 int i;
490 if ( pMan->fUseProfile )
491 Mio_LibraryCleanProfile2( pMan->pSuperLib->pGenlib );
492 for ( i = 0; i < pMan->vMapObjs->nSize; i++ )
493 {
494 pNode = pMan->vMapObjs->pArray[i];
495 if ( pNode->nRefAct[2] == 0 )
496 continue;
497 if ( Map_NodeIsBuf(pNode) )
498 continue;
499 // at least one phase has the best cut assigned
500 assert( pNode->pCutBest[0] != NULL || pNode->pCutBest[1] != NULL );
501 // at least one phase is used in the mapping
502 assert( pNode->nRefAct[0] > 0 || pNode->nRefAct[1] > 0 );
503 // compute the array due to the supergate
504 if ( Map_NodeIsAnd(pNode) )
505 {
506 // count area of the negative phase
507 if ( pNode->pCutBest[0] && (pNode->nRefAct[0] > 0 || pNode->pCutBest[1] == NULL) )
508 {
509 Area += pNode->pCutBest[0]->M[0].pSuperBest->Area;
510 if ( pMan->fUseProfile )
512 }
513 // count area of the positive phase
514 if ( pNode->pCutBest[1] && (pNode->nRefAct[1] > 0 || pNode->pCutBest[0] == NULL) )
515 {
516 Area += pNode->pCutBest[1]->M[1].pSuperBest->Area;
517 if ( pMan->fUseProfile )
519 }
520 }
521 // count area of the interver if we need to implement one phase with another phase
522 if ( (pNode->pCutBest[0] == NULL && pNode->nRefAct[0] > 0) ||
523 (pNode->pCutBest[1] == NULL && pNode->nRefAct[1] > 0) )
524 Area += pMan->pSuperLib->AreaInv;
525 }
526 // add buffers for each CO driven by a CI
527 for ( i = 0; i < pMan->nOutputs; i++ )
528 if ( Map_NodeIsVar(pMan->pOutputs[i]) && !Map_IsComplement(pMan->pOutputs[i]) )
529 Area += pMan->pSuperLib->AreaBuf;
530 return Area;
531}
532
533
537
538
540
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Cube * p
Definition exorList.c:222
int Map_CutGetLeafPhase(Map_Cut_t *pCut, int fPhase, int iLeaf)
float Map_CutGetRootArea(Map_Cut_t *pCut, int fPhase)
float Map_CutGetAreaRefed(Map_Cut_t *pCut, int fPhase)
Definition mapperRefs.c:335
int Map_NodeDecRefPhaseAct(Map_Node_t *pNode, int fPhase)
Definition mapperRefs.c:105
int Map_NodeIncRefPhaseAct(Map_Node_t *pNode, int fPhase)
Definition mapperRefs.c:85
void Map_MappingSetRefs(Map_Man_t *pMan)
Definition mapperRefs.c:450
ABC_NAMESPACE_IMPL_START int Map_NodeReadRefPhaseAct(Map_Node_t *pNode, int fPhase)
DECLARATIONS ///.
Definition mapperRefs.c:43
float Map_CutGetAreaDerefed(Map_Cut_t *pCut, int fPhase)
Definition mapperRefs.c:355
void Map_MappingEstimateRefsInit(Map_Man_t *p)
Definition mapperRefs.c:126
void Map_MappingSetRefs_rec(Map_Man_t *pMan, Map_Node_t *pNode)
Definition mapperRefs.c:410
float Map_NodeReadRefPhaseEst(Map_Node_t *pNode, int fPhase)
Definition mapperRefs.c:63
float Map_CutDeref(Map_Cut_t *pCut, int fPhase, int fProfile)
Definition mapperRefs.c:391
float Map_CutRefDeref(Map_Cut_t *pCut, int fPhase, int fReference, int fUpdateProf)
Definition mapperRefs.c:229
void Map_MappingEstimateRefs(Map_Man_t *p)
Definition mapperRefs.c:151
float Map_CutRef(Map_Cut_t *pCut, int fPhase, int fProfile)
Definition mapperRefs.c:375
float Map_CutGetAreaFlow(Map_Cut_t *pCut, int fPhase)
Definition mapperRefs.c:179
float Map_MappingGetArea(Map_Man_t *pMan)
Definition mapperRefs.c:485
#define Map_NotCond(p, c)
Definition mapper.h:70
typedefABC_NAMESPACE_HEADER_START struct Map_ManStruct_t_ Map_Man_t
INCLUDES ///.
Definition mapper.h:40
int Map_NodeIsBuf(Map_Node_t *p)
int Map_NodeIsConst(Map_Node_t *p)
struct Map_MatchStruct_t_ Map_Match_t
Definition mapper.h:44
struct Map_CutStruct_t_ Map_Cut_t
Definition mapper.h:43
struct Map_SuperStruct_t_ Map_Super_t
Definition mapper.h:45
int Map_NodeIsVar(Map_Node_t *p)
#define Map_Regular(p)
Definition mapper.h:68
int Map_NodeIsAnd(Map_Node_t *p)
#define Map_IsComplement(p)
GLOBAL VARIABLES ///.
Definition mapper.h:67
struct Map_NodeStruct_t_ Map_Node_t
Definition mapper.h:41
void Mio_GateDecProfile2(Mio_Gate_t *pGate)
Definition mioApi.c:192
void Mio_LibraryCleanProfile2(Mio_Library_t *pLib)
Definition mioUtils.c:1616
void Mio_GateIncProfile2(Mio_Gate_t *pGate)
Definition mioApi.c:191
Map_Match_t M[2]
Definition mapperInt.h:275
Map_Node_t * ppLeaves[6]
Definition mapperInt.h:269
Map_Super_t * pSuperBest
Definition mapperInt.h:257
unsigned uPhaseBest
Definition mapperInt.h:256
Map_Cut_t * pCutBest[2]
Definition mapperInt.h:243
Map_Man_t * p
Definition mapperInt.h:208
Map_Node_t * p1
Definition mapperInt.h:225
Mio_Gate_t * pRoot
Definition mapperInt.h:292
#define assert(ex)
Definition util_old.h:213