abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
aigPack.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [aigPack.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [AIG package.]
8 
9  Synopsis [Bit-packing code.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - April 28, 2007.]
16 
17  Revision [$Id: aigPack.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "aig.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 // resubstitution manager
33 {
34  Aig_Man_t * pAig; // working manager
35  Vec_Wrd_t * vSigns; // object signatures
36  Vec_Wrd_t * vPiPats; // PI assignments
37  Vec_Wrd_t * vPiCare; // PI care set
38  int iPatCur; // current pattern
39  int fVerbose; // verbosiness flag
40  // statistics
41  int nPatTotal; // number of all patterns
42  int nPatSkip; // number of skipped patterns
43  int nPatRepeat; // number of repeated patterns
44 };
45 
46 static inline int Aig_Word6CountOnes( word t ) { return Aig_WordCountOnes( (unsigned)(t >> 32) ) + Aig_WordCountOnes( (unsigned)(t & 0xFFFFFFFF) ); }
47 static inline int Aig_Word6HasOneBit( word t ) { return (t & (t-1)) == 0; }
48 
49 
50 ////////////////////////////////////////////////////////////////////////
51 /// FUNCTION DEFINITIONS ///
52 ////////////////////////////////////////////////////////////////////////
53 
54 /**Function*************************************************************
55 
56  Synopsis []
57 
58  Description []
59 
60  SideEffects []
61 
62  SeeAlso []
63 
64 ***********************************************************************/
66 {
67  Aig_ManPack_t * p;
68  p = ABC_CALLOC( Aig_ManPack_t, 1 );
69  p->pAig = pAig;
70  p->vSigns = Vec_WrdStart( Aig_ManObjNumMax(pAig) );
71  p->vPiPats = Vec_WrdStart( Aig_ManCiNum(pAig) );
72  p->vPiCare = Vec_WrdStart( Aig_ManCiNum(pAig) );
73  p->iPatCur = 1;
74  return p;
75 }
76 
77 /**Function*************************************************************
78 
79  Synopsis []
80 
81  Description []
82 
83  SideEffects []
84 
85  SeeAlso []
86 
87 ***********************************************************************/
89 {
90  Aig_Obj_t * pObj;
91  int i, Total = 0;
92  Aig_ManForEachCi( p->pAig, pObj, i )
93  Total += Aig_Word6CountOnes( Vec_WrdEntry(p->vPiCare, i) );
94  return Total;
95 }
96 
97 /**Function*************************************************************
98 
99  Synopsis []
100 
101  Description []
102 
103  SideEffects []
104 
105  SeeAlso []
106 
107 ***********************************************************************/
109 {
110  Aig_Obj_t * pObj;
111  word Sign;
112  int i;
113  Aig_ManForEachCi( p->pAig, pObj, i )
114  {
115  Sign = Vec_WrdEntry( p->vPiCare, i );
116 // Extra_PrintBinary( stdout, (unsigned *)&Sign, 64 );
117 // printf( "\n" );
118  }
119 // printf( "\n" );
120 }
121 
122 
123 /**Function*************************************************************
124 
125  Synopsis []
126 
127  Description []
128 
129  SideEffects []
130 
131  SeeAlso []
132 
133 ***********************************************************************/
135 {
136 // Aig_ManPackPrintCare( p );
137  printf( "Patterns: " );
138  printf( "Total = %6d. ", p->nPatTotal );
139  printf( "Skipped = %6d. ", p->nPatSkip );
140  printf( "Cares = %6.2f %% ", 100.0*Aig_ManPackCountCares(p)/Aig_ManCiNum(p->pAig)/64 );
141  printf( "\n" );
142  Vec_WrdFree( p->vSigns );
143  Vec_WrdFree( p->vPiPats );
144  Vec_WrdFree( p->vPiCare );
145  ABC_FREE( p );
146 }
147 
148 /**Function*************************************************************
149 
150  Synopsis []
151 
152  Description []
153 
154  SideEffects []
155 
156  SeeAlso []
157 
158 ***********************************************************************/
160 {
161  Aig_Obj_t * pObj;
162  word Sign;
163  int i;
164  Aig_ManForEachCi( p->pAig, pObj, i )
165  {
166  Sign = (((word)Aig_ManRandom(0)) << 32) | ((word)Aig_ManRandom(0));
167  Vec_WrdWriteEntry( p->vPiPats, i, Sign << 1 );
168  }
169 }
170 
171 /**Function*************************************************************
172 
173  Synopsis []
174 
175  Description []
176 
177  SideEffects []
178 
179  SeeAlso []
180 
181 ***********************************************************************/
183 {
184  Aig_Obj_t * pObj;
185  word Sign, Sign0, Sign1;
186  int i;
187  // set the constant
188  Vec_WrdWriteEntry( p->vSigns, 0, ~(word)0 );
189  // transfer into the array
190  Aig_ManForEachCi( p->pAig, pObj, i )
192  // simulate internal nodes
193  Aig_ManForEachNode( p->pAig, pObj, i )
194  {
195  Sign0 = Vec_WrdEntry( p->vSigns, Aig_ObjFaninId0(pObj) );
196  Sign1 = Vec_WrdEntry( p->vSigns, Aig_ObjFaninId1(pObj) );
197  if ( Aig_ObjFaninC0(pObj) && Aig_ObjFaninC1(pObj) )
198  Sign = ~(Sign0 | Sign1);
199  else if ( Aig_ObjFaninC0(pObj) )
200  Sign = ~Sign0 & Sign1;
201  else if ( Aig_ObjFaninC1(pObj) )
202  Sign = Sign0 & ~Sign1;
203  else
204  Sign = Sign0 & Sign1;
205  Vec_WrdWriteEntry( p->vSigns, Aig_ObjId(pObj), Sign );
206  }
207  // set the outputs
208  Aig_ManForEachCo( p->pAig, pObj, i )
209  {
210  Sign0 = Vec_WrdEntry( p->vSigns, Aig_ObjFaninId0(pObj) );
211  Sign = Aig_ObjFaninC0(pObj) ? ~Sign0 : Sign0;
212  Vec_WrdWriteEntry( p->vSigns, Aig_ObjId(pObj), Sign );
213  }
214 }
215 
216 /**Function*************************************************************
217 
218  Synopsis []
219 
220  Description []
221 
222  SideEffects []
223 
224  SeeAlso []
225 
226 ***********************************************************************/
228 {
229  word Sign;
230  Aig_Obj_t * pObj;
231  int i, Total, Count, Counts[33] = {0}; // the number of nodes having that many patterns
232  Aig_ManForEachNode( p->pAig, pObj, i )
233  {
234  Sign = Vec_WrdEntry( p->vSigns, Aig_ObjId(pObj) );
235  Count = Aig_Word6CountOnes( Sign );
236  if ( Count > 32 )
237  Count = 64 - Count;
238  Counts[Count]++;
239  }
240  // print statistics
241  Total = 0;
242  for ( i = 0; i <= 32; i++ )
243  {
244  Total += Counts[i];
245  printf( "%2d : ", i );
246  printf( "%6d ", Counts[i] );
247  printf( "%6.1f %%", 100.0*Counts[i]/Aig_ManNodeNum(p->pAig) );
248  printf( "%6.1f %%", 100.0*Total/Aig_ManNodeNum(p->pAig) );
249  printf( "\n" );
250  }
251 }
252 
253 /**Function*************************************************************
254 
255  Synopsis []
256 
257  Description []
258 
259  SideEffects []
260 
261  SeeAlso []
262 
263 ***********************************************************************/
265 {
266  Vec_Int_t * vNodes;
267  Aig_Obj_t * pObj;
268  word Sign;
269  int i;
270  vNodes = Vec_IntAlloc( 1000 );
271  Aig_ManForEachNode( p->pAig, pObj, i )
272  {
273  Sign = Vec_WrdEntry( p->vSigns, Aig_ObjId(pObj) );
274  if ( Sign == 0 || ~Sign == 0 || Aig_Word6HasOneBit(Sign) || Aig_Word6HasOneBit(~Sign) )
275  Vec_IntPush( vNodes, Aig_ObjId(pObj) );
276  }
277  return vNodes;
278 }
279 
280 
281 /**Function*************************************************************
282 
283  Synopsis [Packs patterns into array of simulation info.]
284 
285  Description []
286 
287  SideEffects []
288 
289  SeeAlso []
290 
291 *************************************`**********************************/
293 {
294  word * pInfo, * pPres;
295  int i, Lit;
296  Vec_IntForEachEntry( vLits, Lit, i )
297  {
298  pInfo = Vec_WrdEntryP( p->vPiPats, Abc_Lit2Var(Lit) );
299  pPres = Vec_WrdEntryP( p->vPiCare, Abc_Lit2Var(Lit) );
300  if ( Abc_InfoHasBit( (unsigned *)pPres, iBit ) &&
301  Abc_InfoHasBit( (unsigned *)pInfo, iBit ) == Abc_LitIsCompl(Lit) )
302  return 0;
303  }
304  Vec_IntForEachEntry( vLits, Lit, i )
305  {
306  pInfo = Vec_WrdEntryP( p->vPiPats, Abc_Lit2Var(Lit) );
307  pPres = Vec_WrdEntryP( p->vPiCare, Abc_Lit2Var(Lit) );
308  Abc_InfoSetBit( (unsigned *)pPres, iBit );
309  if ( Abc_InfoHasBit( (unsigned *)pInfo, iBit ) == Abc_LitIsCompl(Lit) )
310  Abc_InfoXorBit( (unsigned *)pInfo, iBit );
311  }
312  return 1;
313 }
314 
315 /**Function*************************************************************
316 
317  Synopsis []
318 
319  Description []
320 
321  SideEffects []
322 
323  SeeAlso []
324 
325 ***********************************************************************/
327 {
328  int k;
329  for ( k = 1; k < 64; k++ )
330  if ( Aig_ManPackAddPatternTry( p, k, vLits ) )
331  break;
332  if ( k == 64 )
333  {
334 /*
335  word * pInfo, * pPres;
336  int i, Lit;
337  Vec_IntForEachEntry( vLits, Lit, i )
338  printf( "%d", Abc_LitIsCompl(Lit) );
339  printf( "\n\n" );
340  for ( k = 1; k < 64; k++ )
341  {
342  Vec_IntForEachEntry( vLits, Lit, i )
343  {
344  pInfo = Vec_WrdEntryP( p->vPiPats, Abc_Lit2Var(Lit) );
345  pPres = Vec_WrdEntryP( p->vPiCare, Abc_Lit2Var(Lit) );
346  if ( Abc_InfoHasBit( (unsigned *)pPres, k ) )
347  printf( "%d", Abc_InfoHasBit( (unsigned *)pInfo, k ) );
348  else
349  printf( "-" );
350  }
351  printf( "\n" );
352  }
353 */
354  p->nPatSkip++;
355  }
356  p->nPatTotal++;
357 }
358 
359 /**Function*************************************************************
360 
361  Synopsis []
362 
363  Description []
364 
365  SideEffects []
366 
367  SeeAlso []
368 
369 ***********************************************************************/
371 {
372  Aig_ManPack_t * p;
373  p = Aig_ManPackAlloc( pAig );
375  Aig_ManPackSimulate( p );
377  return p;
378 }
379 
380 /**Function*************************************************************
381 
382  Synopsis []
383 
384  Description []
385 
386  SideEffects []
387 
388  SeeAlso []
389 
390 ***********************************************************************/
392 {
393  Aig_ManPackSimulate( p );
395  Aig_ManPackFree( p );
396 }
397 
398 ////////////////////////////////////////////////////////////////////////
399 /// END OF FILE ///
400 ////////////////////////////////////////////////////////////////////////
401 
402 
404 
Aig_ManPack_t * Aig_ManPackAlloc(Aig_Man_t *pAig)
FUNCTION DEFINITIONS ///.
Definition: aigPack.c:65
static int Aig_ObjFaninId0(Aig_Obj_t *pObj)
Definition: aig.h:304
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
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
int Aig_ManPackCountCares(Aig_ManPack_t *p)
Definition: aigPack.c:88
static int Abc_InfoHasBit(unsigned *p, int i)
Definition: abc_global.h:258
int fVerbose
Definition: aigPack.c:39
static void Abc_InfoXorBit(unsigned *p, int i)
Definition: abc_global.h:260
int nPatTotal
Definition: aigPack.c:41
static int Aig_Word6CountOnes(word t)
Definition: aigPack.c:46
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: aig.h:393
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
Vec_Wrd_t * vPiCare
Definition: aigPack.c:37
unsigned Aig_ManRandom(int fReset)
Definition: aigUtil.c:1157
static int Aig_ObjFaninId1(Aig_Obj_t *pObj)
Definition: aig.h:305
static int Aig_ManNodeNum(Aig_Man_t *p)
Definition: aig.h:256
Aig_Man_t * pAig
Definition: aigPack.c:34
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
static int Aig_WordCountOnes(unsigned uWord)
Definition: aig.h:229
#define Aig_ManForEachNode(p, pObj, i)
Definition: aig.h:413
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
int nPatSkip
Definition: aigPack.c:42
static void Vec_WrdWriteEntry(Vec_Wrd_t *p, int i, word Entry)
Definition: vecWrd.h:418
Vec_Wrd_t * vSigns
Definition: aigPack.c:35
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static int Aig_ManCiNum(Aig_Man_t *p)
Definition: aig.h:251
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static void Vec_WrdFree(Vec_Wrd_t *p)
Definition: vecWrd.h:260
void Aig_ManPackAddPattern(Aig_ManPack_t *p, Vec_Int_t *vLits)
Definition: aigPack.c:326
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
void Aig_ManPackPrintStats(Aig_ManPack_t *p)
Definition: aigPack.c:227
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void Abc_InfoSetBit(unsigned *p, int i)
Definition: abc_global.h:259
static Vec_Wrd_t * Vec_WrdStart(int nSize)
Definition: vecWrd.h:103
int nPatRepeat
Definition: aigPack.c:43
#define ABC_FREE(obj)
Definition: abc_global.h:232
static word Vec_WrdEntry(Vec_Wrd_t *p, int i)
Definition: vecWrd.h:384
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
Aig_ManPack_t * Aig_ManPackStart(Aig_Man_t *pAig)
Definition: aigPack.c:370
static int Aig_ObjFaninC1(Aig_Obj_t *pObj)
Definition: aig.h:307
static int Aig_Word6HasOneBit(word t)
Definition: aigPack.c:47
static int Aig_ObjId(Aig_Obj_t *pObj)
Definition: aig.h:286
void Aig_ManPackStop(Aig_ManPack_t *p)
Definition: aigPack.c:391
void Aig_ManPackFree(Aig_ManPack_t *p)
Definition: aigPack.c:134
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
void Aig_ManPackPrintCare(Aig_ManPack_t *p)
Definition: aigPack.c:108
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition: vecWrd.h:42
Vec_Int_t * Aig_ManPackConstNodes(Aig_ManPack_t *p)
Definition: aigPack.c:264
Vec_Wrd_t * vPiPats
Definition: aigPack.c:36
void Aig_ManPackSetRandom(Aig_ManPack_t *p)
Definition: aigPack.c:159
void Aig_ManPackSimulate(Aig_ManPack_t *p)
Definition: aigPack.c:182
static word * Vec_WrdEntryP(Vec_Wrd_t *p, int i)
Definition: vecWrd.h:401
int Aig_ManPackAddPatternTry(Aig_ManPack_t *p, int iBit, Vec_Int_t *vLits)
Definition: aigPack.c:292