abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mapperRefs.c File Reference
#include "mapperInt.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START int Map_NodeReadRefPhaseAct (Map_Node_t *pNode, int fPhase)
 DECLARATIONS ///. More...
 
float Map_NodeReadRefPhaseEst (Map_Node_t *pNode, int fPhase)
 
int Map_NodeIncRefPhaseAct (Map_Node_t *pNode, int fPhase)
 
int Map_NodeDecRefPhaseAct (Map_Node_t *pNode, int fPhase)
 
void Map_MappingEstimateRefsInit (Map_Man_t *p)
 
void Map_MappingEstimateRefs (Map_Man_t *p)
 
float Map_CutGetAreaFlow (Map_Cut_t *pCut, int fPhase)
 
float Map_CutRefDeref (Map_Cut_t *pCut, int fPhase, int fReference)
 
float Map_CutGetAreaRefed (Map_Cut_t *pCut, int fPhase)
 
float Map_CutGetAreaDerefed (Map_Cut_t *pCut, int fPhase)
 
float Map_CutRef (Map_Cut_t *pCut, int fPhase)
 
float Map_CutDeref (Map_Cut_t *pCut, int fPhase)
 
void Map_MappingSetRefs_rec (Map_Man_t *pMan, Map_Node_t *pNode)
 
void Map_MappingSetRefs (Map_Man_t *pMan)
 
float Map_MappingGetArea (Map_Man_t *pMan)
 

Function Documentation

float Map_CutDeref ( Map_Cut_t pCut,
int  fPhase 
)

function*************************************************************

synopsis [Dereferences the cut.]

description []

sideeffects []

seealso []

Definition at line 384 of file mapperRefs.c.

385 {
386  return Map_CutRefDeref( pCut, fPhase, 0 ); // dereference
387 }
float Map_CutRefDeref(Map_Cut_t *pCut, int fPhase, int fReference)
Definition: mapperRefs.c:229
float Map_CutGetAreaDerefed ( Map_Cut_t pCut,
int  fPhase 
)

function*************************************************************

synopsis [Computes the exact area associated with the cut.]

description []

sideeffects []

seealso []

Definition at line 348 of file mapperRefs.c.

349 {
350  float aResult, aResult2;
351  aResult2 = Map_CutRefDeref( pCut, fPhase, 1 ); // reference
352  aResult = Map_CutRefDeref( pCut, fPhase, 0 ); // dereference
353 // assert( aResult == aResult2 );
354  return aResult;
355 }
float Map_CutRefDeref(Map_Cut_t *pCut, int fPhase, int fReference)
Definition: mapperRefs.c:229
float Map_CutGetAreaFlow ( Map_Cut_t pCut,
int  fPhase 
)

function*************************************************************

synopsis [Computes the area flow of the cut.]

description [Computes the area flow of the cut if it is implemented using the best supergate with the best phase.]

sideeffects []

seealso []

Definition at line 179 of file mapperRefs.c.

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 }
Map_Cut_t * pCutBest[2]
Definition: mapperInt.h:239
unsigned uPhaseBest
Definition: mapperInt.h:252
float Map_NodeReadRefPhaseEst(Map_Node_t *pNode, int fPhase)
Definition: mapperRefs.c:63
Map_Super_t * pSuperBest
Definition: mapperInt.h:253
Map_Match_t M[2]
Definition: mapperInt.h:271
Map_Node_t * ppLeaves[6]
Definition: mapperInt.h:265
float Map_CutGetAreaRefed ( Map_Cut_t pCut,
int  fPhase 
)

function*************************************************************

synopsis [Computes the exact area associated with the cut.]

description [Assumes that the cut is referenced.]

sideeffects []

seealso []

Definition at line 328 of file mapperRefs.c.

329 {
330  float aResult, aResult2;
331  aResult2 = Map_CutRefDeref( pCut, fPhase, 0 ); // dereference
332  aResult = Map_CutRefDeref( pCut, fPhase, 1 ); // reference
333 // assert( aResult == aResult2 );
334  return aResult;
335 }
float Map_CutRefDeref(Map_Cut_t *pCut, int fPhase, int fReference)
Definition: mapperRefs.c:229
float Map_CutRef ( Map_Cut_t pCut,
int  fPhase 
)

function*************************************************************

synopsis [References the cut.]

description []

sideeffects []

seealso []

Definition at line 368 of file mapperRefs.c.

369 {
370  return Map_CutRefDeref( pCut, fPhase, 1 ); // reference
371 }
float Map_CutRefDeref(Map_Cut_t *pCut, int fPhase, int fReference)
Definition: mapperRefs.c:229
float Map_CutRefDeref ( Map_Cut_t pCut,
int  fPhase,
int  fReference 
)

function*************************************************************

synopsis [References or dereferences the cut.]

description [This reference part is similar to Cudd_NodeReclaim(). The dereference part is similar to Cudd_RecursiveDeref().]

sideeffects []

seealso []

Definition at line 229 of file mapperRefs.c.

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  // go through the children
243  for ( i = 0; i < pCut->nLeaves; i++ )
244  {
245  pNodeChild = pCut->ppLeaves[i];
246  fPhaseChild = Map_CutGetLeafPhase( pCut, fPhase, i );
247  // get the reference counter of the child
248 /*
249  // this code does not take inverters into account
250  // the quality of area recovery seems to always be a little worse
251  if ( fReference )
252  nRefs = Map_NodeIncRefPhaseAct( pNodeChild, fPhaseChild );
253  else
254  nRefs = Map_NodeDecRefPhaseAct( pNodeChild, fPhaseChild );
255  assert( nRefs >= 0 );
256  // skip if the child was already reference before
257  if ( nRefs > 0 )
258  continue;
259 */
260 
261  if ( fReference )
262  {
263  if ( pNodeChild->pCutBest[0] && pNodeChild->pCutBest[1] ) // both phases are present
264  {
265  // if this phase of the node is referenced, there is no recursive call
266  pNodeChild->nRefAct[2]++;
267  if ( pNodeChild->nRefAct[fPhaseChild]++ > 0 )
268  continue;
269  }
270  else // only one phase is present
271  {
272  // inverter should be added if the phase
273  // (a) has no reference and (b) is implemented using other phase
274  if ( pNodeChild->nRefAct[fPhaseChild]++ == 0 && pNodeChild->pCutBest[fPhaseChild] == NULL )
275  aArea += pNodeChild->p->pSuperLib->AreaInv;
276  // if the node is referenced, there is no recursive call
277  if ( pNodeChild->nRefAct[2]++ > 0 )
278  continue;
279  }
280  }
281  else
282  {
283  if ( pNodeChild->pCutBest[0] && pNodeChild->pCutBest[1] ) // both phases are present
284  {
285  // if this phase of the node is referenced, there is no recursive call
286  --pNodeChild->nRefAct[2];
287  if ( --pNodeChild->nRefAct[fPhaseChild] > 0 )
288  continue;
289  }
290  else // only one phase is present
291  {
292  // inverter should be added if the phase
293  // (a) has no reference and (b) is implemented using other phase
294  if ( --pNodeChild->nRefAct[fPhaseChild] == 0 && pNodeChild->pCutBest[fPhaseChild] == NULL )
295  aArea += pNodeChild->p->pSuperLib->AreaInv;
296  // if the node is referenced, there is no recursive call
297  if ( --pNodeChild->nRefAct[2] > 0 )
298  continue;
299  }
300  assert( pNodeChild->nRefAct[fPhaseChild] >= 0 );
301  }
302 
303  // get the child cut
304  pCutChild = pNodeChild->pCutBest[fPhaseChild];
305  // if the child does not have this phase mapped, take the opposite phase
306  if ( pCutChild == NULL )
307  {
308  fPhaseChild = !fPhaseChild;
309  pCutChild = pNodeChild->pCutBest[fPhaseChild];
310  }
311  // reference and compute area recursively
312  aArea += Map_CutRefDeref( pCutChild, fPhaseChild, fReference );
313  }
314  return aArea;
315 }
Map_Man_t * p
Definition: mapperInt.h:204
Map_Cut_t * pCutBest[2]
Definition: mapperInt.h:239
float Map_CutGetRootArea(Map_Cut_t *pCut, int fPhase)
int Map_CutGetLeafPhase(Map_Cut_t *pCut, int fPhase, int iLeaf)
#define assert(ex)
Definition: util_old.h:213
float Map_CutRefDeref(Map_Cut_t *pCut, int fPhase, int fReference)
Definition: mapperRefs.c:229
Map_Node_t * ppLeaves[6]
Definition: mapperInt.h:265
void Map_MappingEstimateRefs ( Map_Man_t p)

Function*************************************************************

Synopsis [Sets the estimated reference counter.]

Description [When this procedure is called for the first time, the reference counter is estimated from the AIG. Otherwise, it is a linear combination of reference counters in the last two iterations.]

SideEffects []

SeeAlso []

Definition at line 151 of file mapperRefs.c.

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 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
float nRefEst[3]
Definition: mapperInt.h:217
void Map_MappingEstimateRefsInit ( Map_Man_t p)

Function*************************************************************

Synopsis [Sets the estimated reference counter for the PIs.]

Description []

SideEffects []

SeeAlso []

Definition at line 126 of file mapperRefs.c.

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 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
float nRefEst[3]
Definition: mapperInt.h:217
float Map_MappingGetArea ( Map_Man_t pMan)

Function*************************************************************

Synopsis [Computes the array of mapping.]

Description []

SideEffects []

SeeAlso []

Definition at line 474 of file mapperRefs.c.

475 {
476  Map_Node_t * pNode;
477  float Area = 0.0;
478  int i;
479  for ( i = 0; i < pMan->vMapObjs->nSize; i++ )
480  {
481  pNode = pMan->vMapObjs->pArray[i];
482  if ( pNode->nRefAct[2] == 0 )
483  continue;
484  if ( Map_NodeIsBuf(pNode) )
485  continue;
486  // at least one phase has the best cut assigned
487  assert( pNode->pCutBest[0] != NULL || pNode->pCutBest[1] != NULL );
488  // at least one phase is used in the mapping
489  assert( pNode->nRefAct[0] > 0 || pNode->nRefAct[1] > 0 );
490  // compute the array due to the supergate
491  if ( Map_NodeIsAnd(pNode) )
492  {
493  // count area of the negative phase
494  if ( pNode->pCutBest[0] && (pNode->nRefAct[0] > 0 || pNode->pCutBest[1] == NULL) )
495  Area += pNode->pCutBest[0]->M[0].pSuperBest->Area;
496  // count area of the positive phase
497  if ( pNode->pCutBest[1] && (pNode->nRefAct[1] > 0 || pNode->pCutBest[0] == NULL) )
498  Area += pNode->pCutBest[1]->M[1].pSuperBest->Area;
499  }
500  // count area of the interver if we need to implement one phase with another phase
501  if ( (pNode->pCutBest[0] == NULL && pNode->nRefAct[0] > 0) ||
502  (pNode->pCutBest[1] == NULL && pNode->nRefAct[1] > 0) )
503  Area += pMan->pSuperLib->AreaInv;
504  }
505  // add buffers for each CO driven by a CI
506  for ( i = 0; i < pMan->nOutputs; i++ )
507  if ( Map_NodeIsVar(pMan->pOutputs[i]) && !Map_IsComplement(pMan->pOutputs[i]) )
508  Area += pMan->pSuperLib->AreaBuf;
509  return Area;
510 }
int Map_NodeIsAnd(Map_Node_t *p)
Definition: mapperCreate.c:115
Map_Cut_t * pCutBest[2]
Definition: mapperInt.h:239
int Map_NodeIsBuf(Map_Node_t *p)
Definition: mapperCreate.c:114
#define Map_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: mapper.h:67
Map_Super_t * pSuperBest
Definition: mapperInt.h:253
int Map_NodeIsVar(Map_Node_t *p)
Definition: mapperCreate.c:113
#define assert(ex)
Definition: util_old.h:213
Map_Match_t M[2]
Definition: mapperInt.h:271
void Map_MappingSetRefs ( Map_Man_t pMan)

Definition at line 441 of file mapperRefs.c.

442 {
443  Map_Node_t * pNode;
444  int i;
445  // clean all references
446  for ( i = 0; i < pMan->vMapObjs->nSize; i++ )
447  {
448  pNode = pMan->vMapObjs->pArray[i];
449  pNode->nRefAct[0] = 0;
450  pNode->nRefAct[1] = 0;
451  pNode->nRefAct[2] = 0;
452  }
453  // visit nodes reachable from POs in the DFS order through the best cuts
454  for ( i = 0; i < pMan->nOutputs; i++ )
455  {
456  pNode = pMan->pOutputs[i];
457  if ( !Map_NodeIsConst(pNode) )
458  Map_MappingSetRefs_rec( pMan, pNode );
459  }
460 }
int Map_NodeIsConst(Map_Node_t *p)
Definition: mapperCreate.c:112
void Map_MappingSetRefs_rec(Map_Man_t *pMan, Map_Node_t *pNode)
Definition: mapperRefs.c:403
void Map_MappingSetRefs_rec ( Map_Man_t pMan,
Map_Node_t pNode 
)

Function*************************************************************

Synopsis [Computes actual reference counters.]

Description [Collects the nodes used in the mapping in array pMan->vMapping. Nodes are collected in reverse topological order to facilitate the computation of required times.]

SideEffects []

SeeAlso []

Definition at line 403 of file mapperRefs.c.

404 {
405  Map_Cut_t * pCut;
406  Map_Node_t * pNodeR;
407  unsigned uPhase;
408  int i, fPhase, fInvPin;
409  // get the regular node and its phase
410  pNodeR = Map_Regular(pNode);
411  fPhase = !Map_IsComplement(pNode);
412  pNodeR->nRefAct[2]++;
413  // quit if the node was already visited in this phase
414  if ( pNodeR->nRefAct[fPhase]++ )
415  return;
416  // quit if this is a PI node
417  if ( Map_NodeIsVar(pNodeR) )
418  return;
419  // propagate through buffer
420  if ( Map_NodeIsBuf(pNodeR) )
421  {
422  Map_MappingSetRefs_rec( pMan, Map_NotCond(pNodeR->p1, Map_IsComplement(pNode)) );
423  return;
424  }
425  assert( Map_NodeIsAnd(pNode) );
426  // get the cut implementing this or opposite polarity
427  pCut = pNodeR->pCutBest[fPhase];
428  if ( pCut == NULL )
429  {
430  fPhase = !fPhase;
431  pCut = pNodeR->pCutBest[fPhase];
432  }
433  // visit the transitive fanin
434  uPhase = pCut->M[fPhase].uPhaseBest;
435  for ( i = 0; i < pCut->nLeaves; i++ )
436  {
437  fInvPin = ((uPhase & (1 << i)) > 0);
438  Map_MappingSetRefs_rec( pMan, Map_NotCond(pCut->ppLeaves[i], fInvPin) );
439  }
440 }
#define Map_NotCond(p, c)
Definition: mapper.h:70
int Map_NodeIsAnd(Map_Node_t *p)
Definition: mapperCreate.c:115
Map_Cut_t * pCutBest[2]
Definition: mapperInt.h:239
unsigned uPhaseBest
Definition: mapperInt.h:252
int Map_NodeIsBuf(Map_Node_t *p)
Definition: mapperCreate.c:114
#define Map_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: mapper.h:67
int Map_NodeIsVar(Map_Node_t *p)
Definition: mapperCreate.c:113
void Map_MappingSetRefs_rec(Map_Man_t *pMan, Map_Node_t *pNode)
Definition: mapperRefs.c:403
Map_Node_t * p1
Definition: mapperInt.h:221
#define Map_Regular(p)
Definition: mapper.h:68
#define assert(ex)
Definition: util_old.h:213
Map_Match_t M[2]
Definition: mapperInt.h:271
Map_Node_t * ppLeaves[6]
Definition: mapperInt.h:265
int Map_NodeDecRefPhaseAct ( Map_Node_t pNode,
int  fPhase 
)

Function*************************************************************

Synopsis [Decrements the actual reference counter of a phase.]

Description [Returns the new reference counter.]

SideEffects []

SeeAlso []

Definition at line 105 of file mapperRefs.c.

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 }
Map_Cut_t * pCutBest[2]
Definition: mapperInt.h:239
#define Map_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: mapper.h:67
#define assert(ex)
Definition: util_old.h:213
int Map_NodeIncRefPhaseAct ( Map_Node_t pNode,
int  fPhase 
)

Function*************************************************************

Synopsis [Increments the actual reference counter of a phase.]

Description [Returns the old reference counter.]

SideEffects []

SeeAlso []

Definition at line 85 of file mapperRefs.c.

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 }
Map_Cut_t * pCutBest[2]
Definition: mapperInt.h:239
#define Map_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: mapper.h:67
#define assert(ex)
Definition: util_old.h:213
ABC_NAMESPACE_IMPL_START int Map_NodeReadRefPhaseAct ( Map_Node_t pNode,
int  fPhase 
)

DECLARATIONS ///.

CFile****************************************************************

FileName [mapperRefs.c]

PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]

Synopsis [Generic technology mapping engine.]

Author [MVSIS Group]

Affiliation [UC Berkeley]

Date [Ver. 2.0. Started - June 1, 2004.]

Revision [

Id:
mapperRefs.h,v 1.0 2003/09/08 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Reads the actual reference counter of a phase.]

Description []

SideEffects []

SeeAlso []

Definition at line 43 of file mapperRefs.c.

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 }
Map_Cut_t * pCutBest[2]
Definition: mapperInt.h:239
#define Map_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: mapper.h:67
#define assert(ex)
Definition: util_old.h:213
float Map_NodeReadRefPhaseEst ( Map_Node_t pNode,
int  fPhase 
)

Function*************************************************************

Synopsis [Reads the estimated reference counter of a phase.]

Description []

SideEffects []

SeeAlso []

Definition at line 63 of file mapperRefs.c.

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 }
Map_Cut_t * pCutBest[2]
Definition: mapperInt.h:239
#define Map_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: mapper.h:67
float nRefEst[3]
Definition: mapperInt.h:217
#define assert(ex)
Definition: util_old.h:213