abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fraigFanout.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [fraigFanout.c]
4 
5  PackageName [FRAIG: Functionally reduced AND-INV graphs.]
6 
7  Synopsis [Procedures to manipulate fanouts of the FRAIG nodes.]
8 
9  Author [Alan Mishchenko <alanmi@eecs.berkeley.edu>]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 2.0. Started - October 1, 2004]
14 
15  Revision [$Id: fraigFanout.c,v 1.5 2005/07/08 01:01:31 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "fraigInt.h"
20 
22 
23 
24 #ifdef FRAIG_ENABLE_FANOUTS
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Add the fanout to the node.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
46 {
47  Fraig_Node_t * pPivot;
48 
49  // pFanins is a fanin of pFanout
50  assert( !Fraig_IsComplement(pFanin) );
51  assert( !Fraig_IsComplement(pFanout) );
52  assert( Fraig_Regular(pFanout->p1) == pFanin || Fraig_Regular(pFanout->p2) == pFanin );
53 
54  pPivot = pFanin->pFanPivot;
55  if ( pPivot == NULL )
56  {
57  pFanin->pFanPivot = pFanout;
58  return;
59  }
60 
61  if ( Fraig_Regular(pPivot->p1) == pFanin )
62  {
63  if ( Fraig_Regular(pFanout->p1) == pFanin )
64  {
65  pFanout->pFanFanin1 = pPivot->pFanFanin1;
66  pPivot->pFanFanin1 = pFanout;
67  }
68  else // if ( Fraig_Regular(pFanout->p2) == pFanin )
69  {
70  pFanout->pFanFanin2 = pPivot->pFanFanin1;
71  pPivot->pFanFanin1 = pFanout;
72  }
73  }
74  else // if ( Fraig_Regular(pPivot->p2) == pFanin )
75  {
76  assert( Fraig_Regular(pPivot->p2) == pFanin );
77  if ( Fraig_Regular(pFanout->p1) == pFanin )
78  {
79  pFanout->pFanFanin1 = pPivot->pFanFanin2;
80  pPivot->pFanFanin2 = pFanout;
81  }
82  else // if ( Fraig_Regular(pFanout->p2) == pFanin )
83  {
84  pFanout->pFanFanin2 = pPivot->pFanFanin2;
85  pPivot->pFanFanin2 = pFanout;
86  }
87  }
88 }
89 
90 /**Function*************************************************************
91 
92  Synopsis [Add the fanout to the node.]
93 
94  Description []
95 
96  SideEffects []
97 
98  SeeAlso []
99 
100 ***********************************************************************/
101 void Fraig_NodeRemoveFaninFanout( Fraig_Node_t * pFanin, Fraig_Node_t * pFanoutToRemove )
102 {
103  Fraig_Node_t * pFanout, * pFanout2, ** ppFanList;
104  // start the linked list of fanouts
105  ppFanList = &pFanin->pFanPivot;
106  // go through the fanouts
107  Fraig_NodeForEachFanoutSafe( pFanin, pFanout, pFanout2 )
108  {
109  // skip the fanout-to-remove
110  if ( pFanout == pFanoutToRemove )
111  continue;
112  // add useful fanouts to the list
113  *ppFanList = pFanout;
114  ppFanList = Fraig_NodeReadNextFanoutPlace( pFanin, pFanout );
115  }
116  *ppFanList = NULL;
117 }
118 
119 /**Function*************************************************************
120 
121  Synopsis [Transfers fanout to a different node.]
122 
123  Description [Assumes that the other node currently has no fanouts.]
124 
125  SideEffects []
126 
127  SeeAlso []
128 
129 ***********************************************************************/
130 void Fraig_NodeTransferFanout( Fraig_Node_t * pNodeFrom, Fraig_Node_t * pNodeTo )
131 {
132  Fraig_Node_t * pFanout;
133  assert( pNodeTo->pFanPivot == NULL );
134  assert( pNodeTo->pFanFanin1 == NULL );
135  assert( pNodeTo->pFanFanin2 == NULL );
136  // go through the fanouts and update their fanins
137  Fraig_NodeForEachFanout( pNodeFrom, pFanout )
138  {
139  if ( Fraig_Regular(pFanout->p1) == pNodeFrom )
140  pFanout->p1 = Fraig_NotCond( pNodeTo, Fraig_IsComplement(pFanout->p1) );
141  else if ( Fraig_Regular(pFanout->p2) == pNodeFrom )
142  pFanout->p2 = Fraig_NotCond( pNodeTo, Fraig_IsComplement(pFanout->p2) );
143  }
144  // move the pointers
145  pNodeTo->pFanPivot = pNodeFrom->pFanPivot;
146  pNodeTo->pFanFanin1 = pNodeFrom->pFanFanin1;
147  pNodeTo->pFanFanin2 = pNodeFrom->pFanFanin2;
148  pNodeFrom->pFanPivot = NULL;
149  pNodeFrom->pFanFanin1 = NULL;
150  pNodeFrom->pFanFanin2 = NULL;
151 }
152 
153 /**Function*************************************************************
154 
155  Synopsis [Returns the number of fanouts of a node.]
156 
157  Description []
158 
159  SideEffects []
160 
161  SeeAlso []
162 
163 ***********************************************************************/
165 {
166  Fraig_Node_t * pFanout;
167  int Counter = 0;
168  Fraig_NodeForEachFanout( pNode, pFanout )
169  Counter++;
170  return Counter;
171 }
172 
173 ////////////////////////////////////////////////////////////////////////
174 /// END OF FILE ///
175 ////////////////////////////////////////////////////////////////////////
176 
177 #endif
178 
180 
Fraig_Node_t * pFanFanin1
Definition: fraigInt.h:257
ABC_NAMESPACE_IMPL_START void Fraig_NodeAddFaninFanout(Fraig_Node_t *pFanin, Fraig_Node_t *pFanout)
DECLARATIONS ///.
Definition: fraigFanout.c:45
Fraig_Node_t * p2
Definition: fraigInt.h:233
#define Fraig_NodeForEachFanout(pNode, pFanout)
Definition: fraigInt.h:288
int Fraig_NodeGetFanoutNum(Fraig_Node_t *pNode)
Definition: fraigFanout.c:164
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Fraig_Node_t * p1
Definition: fraigInt.h:232
void Fraig_NodeRemoveFaninFanout(Fraig_Node_t *pFanin, Fraig_Node_t *pFanoutToRemove)
Definition: fraigFanout.c:101
static int Counter
Fraig_Node_t * pFanFanin2
Definition: fraigInt.h:258
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define Fraig_NodeReadNextFanoutPlace(pNode, pFanout)
Definition: fraigInt.h:284
#define Fraig_Regular(p)
Definition: fraig.h:108
void Fraig_NodeTransferFanout(Fraig_Node_t *pNodeFrom, Fraig_Node_t *pNodeTo)
Definition: fraigFanout.c:130
#define Fraig_NodeForEachFanoutSafe(pNode, pFanout, pFanout2)
Definition: fraigInt.h:292
#define Fraig_NotCond(p, c)
Definition: fraig.h:110
Fraig_Node_t * pFanPivot
Definition: fraigInt.h:256
#define assert(ex)
Definition: util_old.h:213