abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
aigFanout.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [aigFanout.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [AIG package.]
8 
9  Synopsis [Fanout manipulation.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - April 28, 2007.]
16 
17  Revision [$Id: aigFanout.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "aig.h"
22 
24 
25 
26 // 0: first iFan
27 // 1: prev iFan0
28 // 2: prev iFan1
29 // 3: next iFan0
30 // 4: next iFan1
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// DECLARATIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 static inline int Aig_FanoutCreate( int FanId, int Num ) { assert( Num < 2 ); return (FanId << 1) | Num; }
37 static inline int * Aig_FanoutObj( int * pData, int ObjId ) { return pData + 5*ObjId; }
38 static inline int * Aig_FanoutPrev( int * pData, int iFan ) { return pData + 5*(iFan >> 1) + 1 + (iFan & 1); }
39 static inline int * Aig_FanoutNext( int * pData, int iFan ) { return pData + 5*(iFan >> 1) + 3 + (iFan & 1); }
40 
41 ////////////////////////////////////////////////////////////////////////
42 /// FUNCTION DEFINITIONS ///
43 ////////////////////////////////////////////////////////////////////////
44 
45 /**Function*************************************************************
46 
47  Synopsis [Create fanout for all objects in the manager.]
48 
49  Description []
50 
51  SideEffects []
52 
53  SeeAlso []
54 
55 ***********************************************************************/
57 {
58  Aig_Obj_t * pObj;
59  int i;
60  assert( Aig_ManBufNum(p) == 0 );
61  // allocate fanout datastructure
62  assert( p->pFanData == NULL );
63  p->nFansAlloc = 2 * Aig_ManObjNumMax(p);
64  if ( p->nFansAlloc < (1<<12) )
65  p->nFansAlloc = (1<<12);
66  p->pFanData = ABC_ALLOC( int, 5 * p->nFansAlloc );
67  memset( p->pFanData, 0, sizeof(int) * 5 * p->nFansAlloc );
68  // add fanouts for all objects
69  Aig_ManForEachObj( p, pObj, i )
70  {
71  if ( Aig_ObjChild0(pObj) )
72  Aig_ObjAddFanout( p, Aig_ObjFanin0(pObj), pObj );
73  if ( Aig_ObjChild1(pObj) )
74  Aig_ObjAddFanout( p, Aig_ObjFanin1(pObj), pObj );
75  }
76 }
77 
78 /**Function*************************************************************
79 
80  Synopsis [Deletes fanout for all objects in the manager.]
81 
82  Description []
83 
84  SideEffects []
85 
86  SeeAlso []
87 
88 ***********************************************************************/
90 {
91  assert( p->pFanData != NULL );
92  ABC_FREE( p->pFanData );
93  p->nFansAlloc = 0;
94 }
95 
96 /**Function*************************************************************
97 
98  Synopsis [Adds fanout (pFanout) of node (pObj).]
99 
100  Description []
101 
102  SideEffects []
103 
104  SeeAlso []
105 
106 ***********************************************************************/
107 void Aig_ObjAddFanout( Aig_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pFanout )
108 {
109  int iFan, * pFirst, * pPrevC, * pNextC, * pPrev, * pNext;
110  assert( p->pFanData );
111  assert( !Aig_IsComplement(pObj) && !Aig_IsComplement(pFanout) );
112  assert( pFanout->Id > 0 );
113  if ( pObj->Id >= p->nFansAlloc || pFanout->Id >= p->nFansAlloc )
114  {
115  int nFansAlloc = 2 * Abc_MaxInt( pObj->Id, pFanout->Id );
116  p->pFanData = ABC_REALLOC( int, p->pFanData, 5 * nFansAlloc );
117  memset( p->pFanData + 5 * p->nFansAlloc, 0, sizeof(int) * 5 * (nFansAlloc - p->nFansAlloc) );
118  p->nFansAlloc = nFansAlloc;
119  }
120  assert( pObj->Id < p->nFansAlloc && pFanout->Id < p->nFansAlloc );
121  iFan = Aig_FanoutCreate( pFanout->Id, Aig_ObjWhatFanin(pFanout, pObj) );
122  pPrevC = Aig_FanoutPrev( p->pFanData, iFan );
123  pNextC = Aig_FanoutNext( p->pFanData, iFan );
124  pFirst = Aig_FanoutObj( p->pFanData, pObj->Id );
125  if ( *pFirst == 0 )
126  {
127  *pFirst = iFan;
128  *pPrevC = iFan;
129  *pNextC = iFan;
130  }
131  else
132  {
133  pPrev = Aig_FanoutPrev( p->pFanData, *pFirst );
134  pNext = Aig_FanoutNext( p->pFanData, *pPrev );
135  assert( *pNext == *pFirst );
136  *pPrevC = *pPrev;
137  *pNextC = *pFirst;
138  *pPrev = iFan;
139  *pNext = iFan;
140  }
141 }
142 
143 /**Function*************************************************************
144 
145  Synopsis [Removes fanout (pFanout) of node (pObj).]
146 
147  Description []
148 
149  SideEffects []
150 
151  SeeAlso []
152 
153 ***********************************************************************/
154 void Aig_ObjRemoveFanout( Aig_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pFanout )
155 {
156  int iFan, * pFirst, * pPrevC, * pNextC, * pPrev, * pNext;
157  assert( p->pFanData && pObj->Id < p->nFansAlloc && pFanout->Id < p->nFansAlloc );
158  assert( !Aig_IsComplement(pObj) && !Aig_IsComplement(pFanout) );
159  assert( pFanout->Id > 0 );
160  iFan = Aig_FanoutCreate( pFanout->Id, Aig_ObjWhatFanin(pFanout, pObj) );
161  pPrevC = Aig_FanoutPrev( p->pFanData, iFan );
162  pNextC = Aig_FanoutNext( p->pFanData, iFan );
163  pPrev = Aig_FanoutPrev( p->pFanData, *pNextC );
164  pNext = Aig_FanoutNext( p->pFanData, *pPrevC );
165  assert( *pPrev == iFan );
166  assert( *pNext == iFan );
167  pFirst = Aig_FanoutObj( p->pFanData, pObj->Id );
168  assert( *pFirst > 0 );
169  if ( *pFirst == iFan )
170  {
171  if ( *pNextC == iFan )
172  {
173  *pFirst = 0;
174  *pPrev = 0;
175  *pNext = 0;
176  *pPrevC = 0;
177  *pNextC = 0;
178  return;
179  }
180  *pFirst = *pNextC;
181  }
182  *pPrev = *pPrevC;
183  *pNext = *pNextC;
184  *pPrevC = 0;
185  *pNextC = 0;
186 }
187 
188 ////////////////////////////////////////////////////////////////////////
189 /// END OF FILE ///
190 ////////////////////////////////////////////////////////////////////////
191 
192 
194 
char * memset()
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static Aig_Obj_t * Aig_ObjChild0(Aig_Obj_t *pObj)
Definition: aig.h:310
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
void Aig_ManFanoutStop(Aig_Man_t *p)
Definition: aigFanout.c:89
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
static int Aig_IsComplement(Aig_Obj_t *p)
Definition: aig.h:249
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static Aig_Obj_t * Aig_ObjFanin1(Aig_Obj_t *pObj)
Definition: aig.h:309
static int Aig_ManBufNum(Aig_Man_t *p)
Definition: aig.h:253
static int Aig_ObjWhatFanin(Aig_Obj_t *pObj, Aig_Obj_t *pFanin)
Definition: aig.h:332
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
void Aig_ObjAddFanout(Aig_Man_t *p, Aig_Obj_t *pObj, Aig_Obj_t *pFanout)
Definition: aigFanout.c:107
static Aig_Obj_t * Aig_ObjChild1(Aig_Obj_t *pObj)
Definition: aig.h:311
static int * Aig_FanoutObj(int *pData, int ObjId)
Definition: aigFanout.c:37
Definition: aig.h:69
static int * Aig_FanoutPrev(int *pData, int iFan)
Definition: aigFanout.c:38
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int * Aig_FanoutNext(int *pData, int iFan)
Definition: aigFanout.c:39
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Aig_ObjRemoveFanout(Aig_Man_t *p, Aig_Obj_t *pObj, Aig_Obj_t *pFanout)
Definition: aigFanout.c:154
static ABC_NAMESPACE_IMPL_START int Aig_FanoutCreate(int FanId, int Num)
DECLARATIONS ///.
Definition: aigFanout.c:36
#define assert(ex)
Definition: util_old.h:213
void Aig_ManFanoutStart(Aig_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: aigFanout.c:56
int Id
Definition: aig.h:85