abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaBalMap.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [giaSopb.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Scalable AIG package.]
8 
9  Synopsis [SOP balancing for a window.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: giaSopb.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "gia.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis []
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
45 void Gia_ManHighlight_rec( Gia_Man_t * p, int iObj )
46 {
47  Gia_Obj_t * pObj;
48  if ( Gia_ObjIsTravIdCurrentId(p, iObj) )
49  return;
51  pObj = Gia_ManObj( p, iObj );
52  if ( Gia_ObjIsAnd(pObj) )
53  Gia_ManHighlight_rec( p, Gia_ObjFaninId0(pObj, iObj) );
54  if ( Gia_ObjIsAnd(pObj) )
55  Gia_ManHighlight_rec( p, Gia_ObjFaninId1(pObj, iObj) );
56 }
57 void Gia_ManPrepareWin( Gia_Man_t * p, Vec_Int_t * vOuts, Vec_Int_t ** pvPis, Vec_Int_t ** pvPos, Vec_Int_t ** pvAnds, int fPoOnly )
58 {
59  Gia_Obj_t * pObj;
60  int i;
61  // mark the section
63  Gia_ManForEachCoVec( vOuts, p, pObj, i )
65  // mark fanins of the outside area
66  Gia_ManCleanMark0( p );
67  if ( fPoOnly )
68  {
69  Gia_ManForEachCoVec( vOuts, p, pObj, i )
70  Gia_ObjFanin0(pObj)->fMark0 = 1;
71  }
72  else
73  {
74  Gia_ManForEachObj1( p, pObj, i )
75  {
76  if ( Gia_ObjIsCi(pObj) )
77  continue;
78  if ( Gia_ObjIsAnd(pObj) && !Gia_ObjIsTravIdCurrentId(p, i) )
79  continue;
80  Gia_ObjFanin0(pObj)->fMark0 = 1;
81  if ( Gia_ObjIsAnd(pObj) )
82  Gia_ObjFanin1(pObj)->fMark0 = 1;
83  }
84  }
85  // collect pointed nodes
86  *pvPis = Vec_IntAlloc( 1000 );
87  *pvPos = Vec_IntAlloc( 1000 );
88  *pvAnds = Vec_IntAlloc( 1000 );
89  Gia_ManForEachObj1( p, pObj, i )
90  {
91  if ( !Gia_ObjIsTravIdCurrentId(p, i) )
92  continue;
93  if ( Gia_ObjIsCi(pObj) )
94  Vec_IntPush( *pvPis, i );
95  else if ( pObj->fMark0 )
96  Vec_IntPush( *pvPos, i );
97  if ( Gia_ObjIsAnd(pObj) )
98  Vec_IntPush( *pvAnds, i );
99  }
100  Gia_ManCleanMark0( p );
101 }
102 
103 /**Function*************************************************************
104 
105  Synopsis []
106 
107  Description []
108 
109  SideEffects []
110 
111  SeeAlso []
112 
113 ***********************************************************************/
114 Gia_Man_t * Gia_ManExtractWin( Gia_Man_t * p, Vec_Int_t * vOuts, int fPoOnly )
115 {
116  Vec_Int_t * vPis, * vPos, * vAnds;
117  Gia_Man_t * pNew;
118  Gia_Obj_t * pObj;
119  int i;
120  Gia_ManPrepareWin( p, vOuts, &vPis, &vPos, &vAnds, fPoOnly );
121  // create AIG
122  pNew = Gia_ManStart( Vec_IntSize(vPis) + Vec_IntSize(vPos) + Vec_IntSize(vAnds) + 1 );
123  pNew->pName = Abc_UtilStrsav( p->pName );
124  Gia_ManConst0(p)->Value = 0;
125  Gia_ManForEachObjVec( vPis, p, pObj, i )
126  pObj->Value = Gia_ManAppendCi( pNew );
127  Gia_ManForEachObjVec( vAnds, p, pObj, i )
128  pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
129  Gia_ManForEachObjVec( vPos, p, pObj, i )
130  Gia_ManAppendCo( pNew, pObj->Value );
131  Vec_IntFree( vPis );
132  Vec_IntFree( vPos );
133  Vec_IntFree( vAnds );
134  return pNew;
135 }
137 {
138  Vec_Int_t * vPos, * vPis, * vAnds;
139  Gia_Man_t * pNew, * pTemp;
140  Gia_Obj_t * pObj;
141  int i;
142  Gia_ManPrepareWin( p, vOuts, &vPis, &vPos, &vAnds, 0 );
143  // create AIG
144  pNew = Gia_ManStart( Gia_ManObjNum(p) - Vec_IntSize(vAnds) + Gia_ManAndNum(pWin) );
145  pNew->pName = Abc_UtilStrsav( p->pName );
146  pNew->pSpec = Abc_UtilStrsav( p->pSpec );
147  // inputs
148  Gia_ManConst0(p)->Value = 0;
149  Gia_ManForEachCi( p, pObj, i )
150  pObj->Value = Gia_ManAppendCi( pNew );
151  Gia_ManConst0(pWin)->Value = 0;
152  Gia_ManForEachCi( pWin, pObj, i )
153  pObj->Value = Gia_ManObj(p, Vec_IntEntry(vPis, i))->Value;
154  // internal nodes
155  Gia_ManHashAlloc( pNew );
156  Gia_ManForEachAnd( pWin, pObj, i )
157  pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
158  Gia_ManForEachCo( pWin, pObj, i )
159  Gia_ManObj( p, Vec_IntEntry(vPos, i) )->Value = Gia_ObjFanin0Copy(pObj);
160  Gia_ManForEachAnd( p, pObj, i )
161  if ( !Gia_ObjIsTravIdCurrentId(p, i) )
162  pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
163  Gia_ManForEachCo( p, pObj, i )
164  Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
165  Gia_ManHashStop( pNew );
166  // cleanup
167  Vec_IntFree( vPis );
168  Vec_IntFree( vPos );
169  Vec_IntFree( vAnds );
170  pNew = Gia_ManCleanup( pTemp = pNew );
171  Gia_ManStop( pTemp );
172  return pNew;
173 }
174 
175 /**Function*************************************************************
176 
177  Synopsis []
178 
179  Description []
180 
181  SideEffects []
182 
183  SeeAlso []
184 
185 ***********************************************************************/
186 Vec_Int_t * Gia_ManFindLatest( Gia_Man_t * p, int LevelMax, int nTimeWindow )
187 {
188  Gia_Obj_t * pObj;
189  Vec_Int_t * vOuts;
190  vOuts = Vec_IntAlloc( 1000 );
191  if ( Gia_ManHasMapping(p) )
192  {
193  int i, k, iFan, nLevels = 0;
194  int * pLevels = ABC_CALLOC( int, Gia_ManObjNum(p) );
195  Gia_ManForEachLut( p, i )
196  {
197  Gia_LutForEachFanin( p, i, iFan, k )
198  pLevels[i] = Abc_MaxInt( pLevels[i], pLevels[iFan] );
199  pLevels[i]++;
200  nLevels = Abc_MaxInt( nLevels, pLevels[i] );
201  }
202  if ( nTimeWindow )
203  LevelMax = (int)((1.0 - 0.01 * nTimeWindow) * nLevels);
204  if ( nLevels < LevelMax )
205  printf( "The maximum mapped level (%d) is less than the target level (%d).\n", nLevels, LevelMax );
206  Gia_ManForEachCo( p, pObj, i )
207  if ( pLevels[Gia_ObjFaninId0p(p, pObj)] >= LevelMax )
208  Vec_IntPush( vOuts, i );
209  ABC_FREE( pLevels );
210  }
211  else
212  {
213  int i, nLevels = Gia_ManLevelNum( p );
214  if ( nTimeWindow )
215  LevelMax = (int)((1.0 - 0.01 * nTimeWindow) * nLevels);
216  if ( nLevels < LevelMax )
217  printf( "The maximum AIG level (%d) is less than the target level (%d).\n", nLevels, LevelMax );
218  Gia_ManForEachCo( p, pObj, i )
219  if ( Gia_ObjLevel(p, pObj) >= LevelMax )
220  Vec_IntPush( vOuts, i );
221  }
222  return vOuts;
223 }
224 
225 /**Function*************************************************************
226 
227  Synopsis []
228 
229  Description []
230 
231  SideEffects []
232 
233  SeeAlso []
234 
235 ***********************************************************************/
236 Gia_Man_t * Gia_ManExtractWindow( Gia_Man_t * p, int LevelMax, int nTimeWindow, int fVerbose )
237 {
238  Vec_Int_t * vOuts;
239  Gia_Man_t * pWin;
240  assert( !LevelMax != !nTimeWindow );
241  vOuts = Gia_ManFindLatest( p, LevelMax, nTimeWindow );
242  if ( fVerbose )
243  printf( "Collected %d outputs to extract.\n", Vec_IntSize(vOuts) );
244  if ( Vec_IntSize(vOuts) == 0 )
245  {
246  Vec_IntFree( vOuts );
247  return Gia_ManDup( p );
248  }
249  pWin = Gia_ManExtractWin( p, vOuts, 1 );
250  Vec_IntFree( vOuts );
251  return pWin;
252 }
253 
254 /**Function*************************************************************
255 
256  Synopsis []
257 
258  Description []
259 
260  SideEffects []
261 
262  SeeAlso []
263 
264 ***********************************************************************/
265 Gia_Man_t * Gia_ManPerformSopBalanceWin( Gia_Man_t * p, int LevelMax, int nTimeWindow, int nCutNum, int nRelaxRatio, int fVerbose )
266 {
267  Vec_Int_t * vOuts;
268  Gia_Man_t * pNew, * pWin, * pWinNew;
269  assert( !LevelMax != !nTimeWindow );
270  vOuts = Gia_ManFindLatest( p, LevelMax, nTimeWindow );
271  if ( fVerbose )
272  printf( "Collected %d outputs to extract.\n", Vec_IntSize(vOuts) );
273  if ( Vec_IntSize(vOuts) == 0 )
274  {
275  Vec_IntFree( vOuts );
276  return Gia_ManDup( p );
277  }
278  pWin = Gia_ManExtractWin( p, vOuts, 0 );
279  pWinNew = Gia_ManPerformSopBalance( pWin, nCutNum, nRelaxRatio, fVerbose );
280  Gia_ManStop( pWin );
281  pNew = Gia_ManInsertWin( p, vOuts, pWinNew );
282  Gia_ManStop( pWinNew );
283  Vec_IntFree( vOuts );
284  return pNew;
285 }
286 
287 /**Function*************************************************************
288 
289  Synopsis []
290 
291  Description []
292 
293  SideEffects []
294 
295  SeeAlso []
296 
297 ***********************************************************************/
298 Gia_Man_t * Gia_ManPerformDsdBalanceWin( Gia_Man_t * p, int LevelMax, int nTimeWindow, int nLutSize, int nCutNum, int nRelaxRatio, int fVerbose )
299 {
300  Vec_Int_t * vOuts;
301  Gia_Man_t * pNew, * pWin, * pWinNew;
302  assert( !LevelMax != !nTimeWindow );
303  vOuts = Gia_ManFindLatest( p, LevelMax, nTimeWindow );
304  if ( fVerbose )
305  printf( "Collected %d outputs to extract.\n", Vec_IntSize(vOuts) );
306  if ( Vec_IntSize(vOuts) == 0 )
307  {
308  Vec_IntFree( vOuts );
309  return Gia_ManDup( p );
310  }
311  pWin = Gia_ManExtractWin( p, vOuts, 0 );
312  pWinNew = Gia_ManPerformDsdBalance( pWin, nLutSize, nCutNum, nRelaxRatio, fVerbose );
313  Gia_ManStop( pWin );
314  pNew = Gia_ManInsertWin( p, vOuts, pWinNew );
315  Gia_ManStop( pWinNew );
316  Vec_IntFree( vOuts );
317  return pNew;
318 }
319 
320 ////////////////////////////////////////////////////////////////////////
321 /// END OF FILE ///
322 ////////////////////////////////////////////////////////////////////////
323 
324 
326 
static int Gia_ManAppendAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition: gia.h:592
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition: giaDup.c:552
Gia_Man_t * Gia_ManInsertWin(Gia_Man_t *p, Vec_Int_t *vOuts, Gia_Man_t *pWin)
Definition: giaBalMap.c:136
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
static int Gia_ManAppendCo(Gia_Man_t *p, int iLit0)
Definition: gia.h:703
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
ABC_NAMESPACE_IMPL_START void Gia_ManHighlight_rec(Gia_Man_t *p, int iObj)
DECLARATIONS ///.
Definition: giaBalMap.c:45
static int Gia_ManAppendCi(Gia_Man_t *p)
Definition: gia.h:583
void Gia_ManCleanMark0(Gia_Man_t *p)
Definition: giaUtil.c:215
void Gia_ManPrepareWin(Gia_Man_t *p, Vec_Int_t *vOuts, Vec_Int_t **pvPis, Vec_Int_t **pvPos, Vec_Int_t **pvAnds, int fPoOnly)
Definition: giaBalMap.c:57
Gia_Man_t * Gia_ManExtractWindow(Gia_Man_t *p, int LevelMax, int nTimeWindow, int fVerbose)
Definition: giaBalMap.c:236
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
#define Gia_ManForEachCoVec(vVec, p, pObj, i)
Definition: gia.h:1024
static Gia_Obj_t * Gia_ManObj(Gia_Man_t *p, int v)
Definition: gia.h:402
Gia_Man_t * Gia_ManPerformDsdBalance(Gia_Man_t *p, int nLutSize, int nCutNum, int nRelaxRatio, int fVerbose)
Definition: giaIf.c:2058
Definition: gia.h:75
#define Gia_ManForEachLut(p, i)
Definition: gia.h:968
#define Gia_ManForEachCi(p, pObj, i)
Definition: gia.h:1016
Gia_Man_t * Gia_ManPerformSopBalanceWin(Gia_Man_t *p, int LevelMax, int nTimeWindow, int nCutNum, int nRelaxRatio, int fVerbose)
Definition: giaBalMap.c:265
static int Gia_ManAndNum(Gia_Man_t *p)
Definition: gia.h:389
static int Gia_ObjLevel(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:501
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
char * pName
Definition: gia.h:97
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Gia_ObjFanin1Copy(Gia_Obj_t *pObj)
Definition: gia.h:482
Gia_Man_t * Gia_ManPerformDsdBalanceWin(Gia_Man_t *p, int LevelMax, int nTimeWindow, int nLutSize, int nCutNum, int nRelaxRatio, int fVerbose)
Definition: giaBalMap.c:298
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
char * pSpec
Definition: gia.h:98
Gia_Man_t * Gia_ManStart(int nObjsMax)
DECLARATIONS ///.
Definition: giaMan.c:52
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
Gia_Man_t * Gia_ManExtractWin(Gia_Man_t *p, Vec_Int_t *vOuts, int fPoOnly)
Definition: giaBalMap.c:114
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Gia_ObjFanin0Copy(Gia_Obj_t *pObj)
Definition: gia.h:481
static int Gia_ObjIsTravIdCurrentId(Gia_Man_t *p, int Id)
Definition: gia.h:536
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Definition: gia.h:988
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
static int Gia_ManHasMapping(Gia_Man_t *p)
Definition: gia.h:951
unsigned fMark0
Definition: gia.h:79
Vec_Int_t * Gia_ManFindLatest(Gia_Man_t *p, int LevelMax, int nTimeWindow)
Definition: giaBalMap.c:186
Gia_Man_t * Gia_ManPerformSopBalance(Gia_Man_t *p, int nCutNum, int nRelaxRatio, int fVerbose)
Definition: giaIf.c:2031
#define ABC_FREE(obj)
Definition: abc_global.h:232
Definition: gia.h:95
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
static int Gia_ObjFaninId0p(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:463
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
#define assert(ex)
Definition: util_old.h:213
int Gia_ManLevelNum(Gia_Man_t *p)
Definition: giaUtil.c:505
unsigned Value
Definition: gia.h:87
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition: giaHash.c:99
#define Gia_ManForEachObj1(p, pObj, i)
Definition: gia.h:986
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition: giaUtil.c:149
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static int Gia_ObjIsCi(Gia_Obj_t *pObj)
Definition: gia.h:420
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition: giaScl.c:84
static void Gia_ObjSetTravIdCurrentId(Gia_Man_t *p, int Id)
Definition: gia.h:535
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
static int Gia_ObjFaninId1(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:461
#define Gia_LutForEachFanin(p, i, iFan, k)
Definition: gia.h:970
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:572
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
void Gia_ManHashStop(Gia_Man_t *p)
Definition: giaHash.c:142
static int Gia_ObjFaninId0(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:460