abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mapperSwitch.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [mapperSwitch.c]
4 
5  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
6 
7  Synopsis [Generic technology mapping engine.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 1.0. Started - September 8, 2003.]
14 
15  Revision [$Id: mapperSwitch.h,v 1.0 2003/09/08 00:00:00 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "mapperInt.h"
20 
22 
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 static float Map_SwitchCutRefDeref( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase, int fReference );
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**function*************************************************************
35 
36  synopsis [Computes the exact area associated with the cut.]
37 
38  description []
39 
40  sideeffects []
41 
42  seealso []
43 
44 ***********************************************************************/
45 float Map_SwitchCutGetDerefed( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase )
46 {
47  float aResult, aResult2;
48 // assert( pNode->Switching > 0 );
49  aResult2 = Map_SwitchCutRefDeref( pNode, pCut, fPhase, 1 ); // reference
50  aResult = Map_SwitchCutRefDeref( pNode, pCut, fPhase, 0 ); // dereference
51 // assert( aResult == aResult2 );
52  return aResult;
53 }
54 
55 /**function*************************************************************
56 
57  synopsis [References the cut.]
58 
59  description []
60 
61  sideeffects []
62 
63  seealso []
64 
65 ***********************************************************************/
66 float Map_SwitchCutRef( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase )
67 {
68  return Map_SwitchCutRefDeref( pNode, pCut, fPhase, 1 ); // reference
69 }
70 
71 /**function*************************************************************
72 
73  synopsis [References the cut.]
74 
75  description []
76 
77  sideeffects []
78 
79  seealso []
80 
81 ***********************************************************************/
82 float Map_SwitchCutDeref( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase )
83 {
84  return Map_SwitchCutRefDeref( pNode, pCut, fPhase, 0 ); // dereference
85 }
86 
87 /**function*************************************************************
88 
89  synopsis [References or dereferences the cut.]
90 
91  description [This reference part is similar to Cudd_NodeReclaim().
92  The dereference part is similar to Cudd_RecursiveDeref().]
93 
94  sideeffects []
95 
96  seealso []
97 
98 ***********************************************************************/
99 float Map_SwitchCutRefDeref( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase, int fReference )
100 {
101  Map_Node_t * pNodeChild;
102  Map_Cut_t * pCutChild;
103  float aSwitchActivity;
104  int i, fPhaseChild;
105 
106  // start switching activity for the node
107  aSwitchActivity = pNode->Switching;
108  // consider the elementary variable
109  if ( pCut->nLeaves == 1 )
110  return aSwitchActivity;
111 
112  // go through the children
113  assert( pCut->M[fPhase].pSuperBest );
114  for ( i = 0; i < pCut->nLeaves; i++ )
115  {
116  pNodeChild = pCut->ppLeaves[i];
117  fPhaseChild = Map_CutGetLeafPhase( pCut, fPhase, i );
118  // get the reference counter of the child
119 
120  if ( fReference )
121  {
122  if ( pNodeChild->pCutBest[0] && pNodeChild->pCutBest[1] ) // both phases are present
123  {
124  // if this phase of the node is referenced, there is no recursive call
125  pNodeChild->nRefAct[2]++;
126  if ( pNodeChild->nRefAct[fPhaseChild]++ > 0 )
127  continue;
128  }
129  else // only one phase is present
130  {
131  // inverter should be added if the phase
132  // (a) has no reference and (b) is implemented using other phase
133  if ( pNodeChild->nRefAct[fPhaseChild]++ == 0 && pNodeChild->pCutBest[fPhaseChild] == NULL )
134  aSwitchActivity += pNodeChild->Switching; // inverter switches the same as the node
135  // if the node is referenced, there is no recursive call
136  if ( pNodeChild->nRefAct[2]++ > 0 )
137  continue;
138  }
139  }
140  else
141  {
142  if ( pNodeChild->pCutBest[0] && pNodeChild->pCutBest[1] ) // both phases are present
143  {
144  // if this phase of the node is referenced, there is no recursive call
145  --pNodeChild->nRefAct[2];
146  if ( --pNodeChild->nRefAct[fPhaseChild] > 0 )
147  continue;
148  }
149  else // only one phase is present
150  {
151  // inverter should be added if the phase
152  // (a) has no reference and (b) is implemented using other phase
153  if ( --pNodeChild->nRefAct[fPhaseChild] == 0 && pNodeChild->pCutBest[fPhaseChild] == NULL )
154  aSwitchActivity += pNodeChild->Switching; // inverter switches the same as the node
155  // if the node is referenced, there is no recursive call
156  if ( --pNodeChild->nRefAct[2] > 0 )
157  continue;
158  }
159  assert( pNodeChild->nRefAct[fPhaseChild] >= 0 );
160  }
161 
162  // get the child cut
163  pCutChild = pNodeChild->pCutBest[fPhaseChild];
164  // if the child does not have this phase mapped, take the opposite phase
165  if ( pCutChild == NULL )
166  {
167  fPhaseChild = !fPhaseChild;
168  pCutChild = pNodeChild->pCutBest[fPhaseChild];
169  }
170  // reference and compute area recursively
171  aSwitchActivity += Map_SwitchCutRefDeref( pNodeChild, pCutChild, fPhaseChild, fReference );
172  }
173  return aSwitchActivity;
174 }
175 
176 /**Function*************************************************************
177 
178  Synopsis [Computes the array of mapping.]
179 
180  Description []
181 
182  SideEffects []
183 
184  SeeAlso []
185 
186 ***********************************************************************/
188 {
189  Map_Node_t * pNode;
190  float Switch = 0.0;
191  int i;
192  for ( i = 0; i < pMan->vMapObjs->nSize; i++ )
193  {
194  pNode = pMan->vMapObjs->pArray[i];
195  if ( pNode->nRefAct[2] == 0 )
196  continue;
197  // at least one phase has the best cut assigned
198  assert( pNode->pCutBest[0] != NULL || pNode->pCutBest[1] != NULL );
199  // at least one phase is used in the mapping
200  assert( pNode->nRefAct[0] > 0 || pNode->nRefAct[1] > 0 );
201  // compute the array due to the supergate
202  if ( Map_NodeIsAnd(pNode) )
203  {
204  // count switching of the negative phase
205  if ( pNode->pCutBest[0] && (pNode->nRefAct[0] > 0 || pNode->pCutBest[1] == NULL) )
206  Switch += pNode->Switching;
207  // count switching of the positive phase
208  if ( pNode->pCutBest[1] && (pNode->nRefAct[1] > 0 || pNode->pCutBest[0] == NULL) )
209  Switch += pNode->Switching;
210  }
211  // count switching of the interver if we need to implement one phase with another phase
212  if ( (pNode->pCutBest[0] == NULL && pNode->nRefAct[0] > 0) ||
213  (pNode->pCutBest[1] == NULL && pNode->nRefAct[1] > 0) )
214  Switch += pNode->Switching; // inverter switches the same as the node
215  }
216  // add buffers for each CO driven by a CI
217  for ( i = 0; i < pMan->nOutputs; i++ )
218  if ( Map_NodeIsVar(pMan->pOutputs[i]) && !Map_IsComplement(pMan->pOutputs[i]) )
219  Switch += pMan->pOutputs[i]->Switching;
220  return Switch;
221 }
222 
223 ////////////////////////////////////////////////////////////////////////
224 /// END OF FILE ///
225 ////////////////////////////////////////////////////////////////////////
226 
227 
229 
int Map_NodeIsAnd(Map_Node_t *p)
Definition: mapperCreate.c:115
Map_Cut_t * pCutBest[2]
Definition: mapperInt.h:239
float Map_MappingGetSwitching(Map_Man_t *pMan)
Definition: mapperSwitch.c:187
#define Map_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: mapper.h:67
Map_Super_t * pSuperBest
Definition: mapperInt.h:253
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
int Map_NodeIsVar(Map_Node_t *p)
Definition: mapperCreate.c:113
float Map_SwitchCutDeref(Map_Node_t *pNode, Map_Cut_t *pCut, int fPhase)
Definition: mapperSwitch.c:82
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
typedefABC_NAMESPACE_HEADER_START struct Map_ManStruct_t_ Map_Man_t
INCLUDES ///.
Definition: mapper.h:40
int Map_CutGetLeafPhase(Map_Cut_t *pCut, int fPhase, int iLeaf)
static ABC_NAMESPACE_IMPL_START float Map_SwitchCutRefDeref(Map_Node_t *pNode, Map_Cut_t *pCut, int fPhase, int fReference)
DECLARATIONS ///.
Definition: mapperSwitch.c:99
#define assert(ex)
Definition: util_old.h:213
float Map_SwitchCutRef(Map_Node_t *pNode, Map_Cut_t *pCut, int fPhase)
Definition: mapperSwitch.c:66
Map_Match_t M[2]
Definition: mapperInt.h:271
Map_Node_t * ppLeaves[6]
Definition: mapperInt.h:265
float Map_SwitchCutGetDerefed(Map_Node_t *pNode, Map_Cut_t *pCut, int fPhase)
FUNCTION DEFINITIONS ///.
Definition: mapperSwitch.c:45