abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaGlitch.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [giaGlitch.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Scalable AIG package.]
8 
9  Synopsis [Glitch simulation.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: giaGlitch.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 typedef struct Gli_Obj_t_ Gli_Obj_t;
31 struct Gli_Obj_t_
32 {
33  unsigned fTerm : 1; // terminal node
34  unsigned fPhase : 1; // value under 000 pattern
35  unsigned fPhase2 : 1; // value under 000 pattern
36  unsigned fMark : 1; // user-controlled mark
37  unsigned nFanins : 3; // the number of fanins
38  unsigned nFanouts : 25; // total number of fanouts
39  unsigned Handle; // ID of the node
40  unsigned uTruth[2]; // truth table of the node
41  unsigned uSimInfo; // simulation info of the node
42  union
43  {
44  int iFanin; // the number of fanins added
45  int nSwitches; // the number of switches
46  };
47  union
48  {
49  int iFanout; // the number of fanouts added
50  int nGlitches; // the number of glitches ( nGlitches >= nSwitches )
51  };
52  int Fanios[0]; // the array of fanins/fanouts
53 };
54 
55 typedef struct Gli_Man_t_ Gli_Man_t;
56 struct Gli_Man_t_
57 {
58  Vec_Int_t * vCis; // the vector of CIs (PIs + LOs)
59  Vec_Int_t * vCos; // the vector of COs (POs + LIs)
60  Vec_Int_t * vCisChanged; // the changed CIs
61  Vec_Int_t * vAffected; // the affected nodes
62  Vec_Int_t * vFrontier; // the fanouts of these nodes
63  int nObjs; // the number of objects
64  int nRegs; // the number of registers
65  int nTravIds; // traversal ID of the network
66  int iObjData; // pointer to the current data
67  int nObjData; // the size of array to store the logic network
68  int * pObjData; // the internal nodes
69  unsigned * pSimInfoPrev; // previous values of the CIs
70 };
71 
72 
73 static inline int Gli_ManCiNum( Gli_Man_t * p ) { return Vec_IntSize(p->vCis); }
74 static inline int Gli_ManCoNum( Gli_Man_t * p ) { return Vec_IntSize(p->vCos); }
75 static inline int Gli_ManPiNum( Gli_Man_t * p ) { return Vec_IntSize(p->vCis) - p->nRegs; }
76 static inline int Gli_ManPoNum( Gli_Man_t * p ) { return Vec_IntSize(p->vCos) - p->nRegs; }
77 static inline int Gli_ManRegNum( Gli_Man_t * p ) { return p->nRegs; }
78 static inline int Gli_ManObjNum( Gli_Man_t * p ) { return p->nObjs; }
79 static inline int Gli_ManNodeNum( Gli_Man_t * p ) { return p->nObjs - Vec_IntSize(p->vCis) - Vec_IntSize(p->vCos); }
80 
81 static inline Gli_Obj_t * Gli_ManObj( Gli_Man_t * p, int v ) { return (Gli_Obj_t *)(p->pObjData + v); }
82 static inline Gli_Obj_t * Gli_ManCi( Gli_Man_t * p, int v ) { return Gli_ManObj( p, Vec_IntEntry(p->vCis,v) ); }
83 static inline Gli_Obj_t * Gli_ManCo( Gli_Man_t * p, int v ) { return Gli_ManObj( p, Vec_IntEntry(p->vCos,v) ); }
84 static inline Gli_Obj_t * Gli_ManPi( Gli_Man_t * p, int v ) { assert( v < Gli_ManPiNum(p) ); return Gli_ManCi( p, v ); }
85 static inline Gli_Obj_t * Gli_ManPo( Gli_Man_t * p, int v ) { assert( v < Gli_ManPoNum(p) ); return Gli_ManCo( p, v ); }
86 static inline Gli_Obj_t * Gli_ManRo( Gli_Man_t * p, int v ) { assert( v < Gli_ManRegNum(p) ); return Gli_ManCi( p, Gli_ManRegNum(p)+v ); }
87 static inline Gli_Obj_t * Gli_ManRi( Gli_Man_t * p, int v ) { assert( v < Gli_ManRegNum(p) ); return Gli_ManCo( p, Gli_ManRegNum(p)+v ); }
88 
89 static inline int Gli_ObjIsTerm( Gli_Obj_t * pObj ) { return pObj->fTerm; }
90 static inline int Gli_ObjIsCi( Gli_Obj_t * pObj ) { return pObj->fTerm && pObj->nFanins == 0; }
91 static inline int Gli_ObjIsCo( Gli_Obj_t * pObj ) { return pObj->fTerm && pObj->nFanins == 1; }
92 static inline int Gli_ObjIsNode( Gli_Obj_t * pObj ) { return!pObj->fTerm; }
93 
94 static inline int Gli_ObjFaninNum( Gli_Obj_t * pObj ) { return pObj->nFanins; }
95 static inline int Gli_ObjFanoutNum( Gli_Obj_t * pObj ) { return pObj->nFanouts; }
96 static inline int Gli_ObjSize( Gli_Obj_t * pObj ) { return sizeof(Gli_Obj_t) / 4 + pObj->nFanins + pObj->nFanouts; }
97 
98 static inline Gli_Obj_t * Gli_ObjFanin( Gli_Obj_t * pObj, int i ) { return (Gli_Obj_t *)(((int *)pObj) - pObj->Fanios[i]); }
99 static inline Gli_Obj_t * Gli_ObjFanout( Gli_Obj_t * pObj, int i ) { return (Gli_Obj_t *)(((int *)pObj) + pObj->Fanios[pObj->nFanins+i]); }
100 
101 #define Gli_ManForEachObj( p, pObj, i ) \
102  for ( i = 0; (i < p->nObjData) && (pObj = Gli_ManObj(p,i)); i += Gli_ObjSize(pObj) )
103 #define Gli_ManForEachNode( p, pObj, i ) \
104  for ( i = 0; (i < p->nObjData) && (pObj = Gli_ManObj(p,i)); i += Gli_ObjSize(pObj) ) if ( Gli_ObjIsTerm(pObj) ) {} else
105 
106 #define Gli_ManForEachEntry( vVec, p, pObj, i ) \
107  for ( i = 0; (i < Vec_IntSize(vVec)) && (pObj = Gli_ManObj(p,Vec_IntEntry(vVec,i))); i++ )
108 #define Gli_ManForEachCi( p, pObj, i ) \
109  for ( i = 0; (i < Vec_IntSize(p->vCis)) && (pObj = Gli_ManObj(p,Vec_IntEntry(p->vCis,i))); i++ )
110 #define Gli_ManForEachCo( p, pObj, i ) \
111  for ( i = 0; (i < Vec_IntSize(p->vCos)) && (pObj = Gli_ManObj(p,Vec_IntEntry(p->vCos,i))); i++ )
112 
113 #define Gli_ManForEachPi( p, pObj, i ) \
114  for ( i = 0; (i < Gli_ManPiNum(p)) && ((pObj) = Gli_ManCi(p, i)); i++ )
115 #define Gli_ManForEachPo( p, pObj, i ) \
116  for ( i = 0; (i < Gli_ManPoNum(p)) && ((pObj) = Gli_ManCo(p, i)); i++ )
117 #define Gli_ManForEachRo( p, pObj, i ) \
118  for ( i = 0; (i < Gli_ManRegNum(p)) && ((pObj) = Gli_ManCi(p, Gli_ManPiNum(p)+i)); i++ )
119 #define Gli_ManForEachRi( p, pObj, i ) \
120  for ( i = 0; (i < Gli_ManRegNum(p)) && ((pObj) = Gli_ManCo(p, Gli_ManPoNum(p)+i)); i++ )
121 #define Gli_ManForEachRiRo( p, pObjRi, pObjRo, i ) \
122  for ( i = 0; (i < Gli_ManRegNum(p)) && ((pObjRi) = Gli_ManCo(p, Gli_ManPoNum(p)+i)) && ((pObjRo) = Gli_ManCi(p, Gli_ManPiNum(p)+i)); i++ )
123 
124 #define Gli_ObjForEachFanin( pObj, pNext, i ) \
125  for ( i = 0; (i < (int)pObj->nFanins) && (pNext = Gli_ObjFanin(pObj,i)); i++ )
126 #define Gli_ObjForEachFanout( pObj, pNext, i ) \
127  for ( i = 0; (i < (int)pObj->nFanouts) && (pNext = Gli_ObjFanout(pObj,i)); i++ )
128 
129 ////////////////////////////////////////////////////////////////////////
130 /// FUNCTION DEFINITIONS ///
131 ////////////////////////////////////////////////////////////////////////
132 
133 /**Function*************************************************************
134 
135  Synopsis [Creates logic network.]
136 
137  Description []
138 
139  SideEffects []
140 
141  SeeAlso []
142 
143 ***********************************************************************/
144 Gli_Man_t * Gli_ManAlloc( int nObjs, int nRegs, int nFanioPairs )
145 {
146  Gli_Man_t * p;
147  p = (Gli_Man_t *)ABC_CALLOC( int, (sizeof(Gli_Man_t) / 4) + (sizeof(Gli_Obj_t) / 4) * nObjs + 2 * nFanioPairs );
148  p->nRegs = nRegs;
149  p->vCis = Vec_IntAlloc( 1000 );
150  p->vCos = Vec_IntAlloc( 1000 );
151  p->vCisChanged = Vec_IntAlloc( 1000 );
152  p->vAffected = Vec_IntAlloc( 1000 );
153  p->vFrontier = Vec_IntAlloc( 1000 );
154  p->nObjData = (sizeof(Gli_Obj_t) / 4) * nObjs + 2 * nFanioPairs;
155  p->pObjData = (int *)(p + 1);
156  return p;
157 }
158 
159 /**Function*************************************************************
160 
161  Synopsis [Deletes logic network.]
162 
163  Description []
164 
165  SideEffects []
166 
167  SeeAlso []
168 
169 ***********************************************************************/
171 {
172  Vec_IntFree( p->vCis );
173  Vec_IntFree( p->vCos );
174  Vec_IntFree( p->vCisChanged );
175  Vec_IntFree( p->vAffected );
176  Vec_IntFree( p->vFrontier );
177  ABC_FREE( p->pSimInfoPrev );
178  ABC_FREE( p );
179 }
180 
181 /**Function*************************************************************
182 
183  Synopsis [Checks logic network.]
184 
185  Description []
186 
187  SideEffects []
188 
189  SeeAlso []
190 
191 ***********************************************************************/
193 {
194  Gli_Obj_t * pObj, * pNext;
195  int i, k;
196  Gli_ManForEachObj( p, pObj, i )
197  {
198  printf( "Node %d \n", pObj->Handle );
199  printf( "Fanins: " );
200  Gli_ObjForEachFanin( pObj, pNext, k )
201  printf( "%d ", pNext->Handle );
202  printf( "\n" );
203  printf( "Fanouts: " );
204  Gli_ObjForEachFanout( pObj, pNext, k )
205  printf( "%d ", pNext->Handle );
206  printf( "\n" );
207  }
208 }
209 
210 /**Function*************************************************************
211 
212  Synopsis [Checks logic network.]
213 
214  Description []
215 
216  SideEffects []
217 
218  SeeAlso []
219 
220 ***********************************************************************/
222 {
223  Gli_Obj_t * pObj;
224  int i;
225  assert( p->iObjData == p->nObjData );
226  Gli_ManForEachObj( p, pObj, i )
227  {
228  assert( pObj->iFanin == (int)pObj->nFanins );
229  assert( pObj->iFanout == (int)pObj->nFanouts );
230  pObj->iFanin = 0;
231  pObj->iFanout = 0;
232  }
233 }
234 
235 /**Function*************************************************************
236 
237  Synopsis [Creates fanin/fanout pair.]
238 
239  Description []
240 
241  SideEffects []
242 
243  SeeAlso []
244 
245 ***********************************************************************/
246 void Gli_ObjAddFanin( Gli_Obj_t * pObj, Gli_Obj_t * pFanin )
247 {
248  assert( pObj->iFanin < (int)pObj->nFanins );
249  assert( pFanin->iFanout < (int)pFanin->nFanouts );
250  pFanin->Fanios[pFanin->nFanins + pFanin->iFanout++] =
251  pObj->Fanios[pObj->iFanin++] = pObj->Handle - pFanin->Handle;
252 }
253 
254 /**Function*************************************************************
255 
256  Synopsis [Allocates object.]
257 
258  Description []
259 
260  SideEffects []
261 
262  SeeAlso []
263 
264 ***********************************************************************/
265 Gli_Obj_t * Gli_ObjAlloc( Gli_Man_t * p, int nFanins, int nFanouts )
266 {
267  Gli_Obj_t * pObj;
268  pObj = Gli_ManObj( p, p->iObjData );
269  pObj->Handle = p->iObjData;
270  pObj->nFanins = nFanins;
271  pObj->nFanouts = nFanouts;
272  p->iObjData += Gli_ObjSize( pObj );
273  p->nObjs++;
274  return pObj;
275 }
276 
277 /**Function*************************************************************
278 
279  Synopsis [Creates CI.]
280 
281  Description []
282 
283  SideEffects []
284 
285  SeeAlso []
286 
287 ***********************************************************************/
288 int Gli_ManCreateCi( Gli_Man_t * p, int nFanouts )
289 {
290  Gli_Obj_t * pObj;
291  pObj = Gli_ObjAlloc( p, 0, nFanouts );
292  pObj->fTerm = 1;
293  Vec_IntPush( p->vCis, pObj->Handle );
294  return pObj->Handle;
295 }
296 
297 /**Function*************************************************************
298 
299  Synopsis [Creates CO.]
300 
301  Description []
302 
303  SideEffects []
304 
305  SeeAlso []
306 
307 ***********************************************************************/
308 int Gli_ManCreateCo( Gli_Man_t * p, int iFanin )
309 {
310  Gli_Obj_t * pObj, * pFanin;
311  pObj = Gli_ObjAlloc( p, 1, 0 );
312  pObj->fTerm = 1;
313  pFanin = Gli_ManObj( p, iFanin );
314  Gli_ObjAddFanin( pObj, pFanin );
315  pObj->fPhase = pObj->fPhase2 = pFanin->fPhase;
316  Vec_IntPush( p->vCos, pObj->Handle );
317  return pObj->Handle;
318 }
319 
320 /**Function*************************************************************
321 
322  Synopsis [Creates node.]
323 
324  Description []
325 
326  SideEffects []
327 
328  SeeAlso []
329 
330 ***********************************************************************/
331 static inline int Gli_NodeComputeValue( Gli_Obj_t * pNode )
332 {
333  int i, Phase = 0;
334  for ( i = 0; i < (int)pNode->nFanins; i++ )
335  Phase |= (Gli_ObjFanin(pNode, i)->fPhase << i);
336  return Abc_InfoHasBit( pNode->uTruth, Phase );
337 }
338 
339 /**Function*************************************************************
340 
341  Synopsis [Creates node.]
342 
343  Description []
344 
345  SideEffects []
346 
347  SeeAlso []
348 
349 ***********************************************************************/
350 static inline int Gli_NodeComputeValue2( Gli_Obj_t * pNode )
351 {
352  int i, Phase = 0;
353  for ( i = 0; i < (int)pNode->nFanins; i++ )
354  Phase |= (Gli_ObjFanin(pNode, i)->fPhase2 << i);
355  return Abc_InfoHasBit( pNode->uTruth, Phase );
356 }
357 
358 /**Function*************************************************************
359 
360  Synopsis [Creates node.]
361 
362  Description []
363 
364  SideEffects []
365 
366  SeeAlso []
367 
368 ***********************************************************************/
369 int Gli_ManCreateNode( Gli_Man_t * p, Vec_Int_t * vFanins, int nFanouts, unsigned * puTruth )
370 {
371  Gli_Obj_t * pObj, * pFanin;
372  int i;
373  assert( Vec_IntSize(vFanins) <= 6 );
374  pObj = Gli_ObjAlloc( p, Vec_IntSize(vFanins), nFanouts );
375  Gli_ManForEachEntry( vFanins, p, pFanin, i )
376  Gli_ObjAddFanin( pObj, pFanin );
377  pObj->uTruth[0] = puTruth[0];
378  pObj->uTruth[1] = puTruth[Vec_IntSize(vFanins) == 6];
379  pObj->fPhase = pObj->fPhase2 = Gli_NodeComputeValue( pObj );
380  return pObj->Handle;
381 }
382 
383 /**Function*************************************************************
384 
385  Synopsis [Returns the number of switches of the node.]
386 
387  Description []
388 
389  SideEffects []
390 
391  SeeAlso []
392 
393 ***********************************************************************/
394 int Gli_ObjNumSwitches( Gli_Man_t * p, int iNode )
395 {
396  return Gli_ManObj( p, iNode )->nSwitches;
397 }
398 
399 /**Function*************************************************************
400 
401  Synopsis [Returns the number of glitches of the node.]
402 
403  Description []
404 
405  SideEffects []
406 
407  SeeAlso []
408 
409 ***********************************************************************/
410 int Gli_ObjNumGlitches( Gli_Man_t * p, int iNode )
411 {
412  return Gli_ManObj( p, iNode )->nGlitches;
413 }
414 
415 
416 /**Function*************************************************************
417 
418  Synopsis [Sets random info at the PIs and collects changed PIs.]
419 
420  Description []
421 
422  SideEffects []
423 
424  SeeAlso []
425 
426 ***********************************************************************/
427 void Gli_ManSetPiRandom( Gli_Man_t * p, float PiTransProb )
428 {
429  Gli_Obj_t * pObj;
430  float Multi = 1.0 / (1 << 16);
431  int i;
432  assert( 0.0 < PiTransProb && PiTransProb < 1.0 );
434  Gli_ManForEachCi( p, pObj, i )
435  if ( Multi * (Gia_ManRandom(0) & 0xffff) < PiTransProb )
436  {
437  Vec_IntPush( p->vCisChanged, pObj->Handle );
438  pObj->fPhase ^= 1;
439  pObj->fPhase2 ^= 1;
440  pObj->nSwitches++;
441  pObj->nGlitches++;
442  }
443 }
444 
445 /**Function*************************************************************
446 
447  Synopsis [Sets random info at the PIs and collects changed PIs.]
448 
449  Description []
450 
451  SideEffects []
452 
453  SeeAlso []
454 
455 ***********************************************************************/
456 void Gli_ManSetPiFromSaved( Gli_Man_t * p, int iBit )
457 {
458  Gli_Obj_t * pObj;
459  int i;
461  Gli_ManForEachCi( p, pObj, i )
462  if ( (p->pSimInfoPrev[i] ^ pObj->uSimInfo) & (1 << iBit) )
463  {
464  Vec_IntPush( p->vCisChanged, pObj->Handle );
465  pObj->fPhase ^= 1;
466  pObj->fPhase2 ^= 1;
467  pObj->nSwitches++;
468  pObj->nGlitches++;
469  }
470 }
471 
472 /**Function*************************************************************
473 
474  Synopsis [Computes switching activity of each node.]
475 
476  Description []
477 
478  SideEffects []
479 
480  SeeAlso []
481 
482 ***********************************************************************/
484 {
485  Gli_Obj_t * pThis;
486  int i;
487  Gli_ManForEachNode( p, pThis, i )
488  {
489  if ( ((int)pThis->fPhase) == Gli_NodeComputeValue(pThis) )
490  continue;
491  pThis->fPhase ^= 1;
492  pThis->nSwitches++;
493  }
494 }
495 
496 /**Function*************************************************************
497 
498  Synopsis [Computes glitching activity of each node.]
499 
500  Description []
501 
502  SideEffects []
503 
504  SeeAlso []
505 
506 ***********************************************************************/
508 {
509  Gli_Obj_t * pThis, * pFanout;//, * pOther = Gli_ManObj(p, 41);
510  int i, k, Handle;
511 // Gli_ManForEachObj( p, pThis, i )
512 // assert( pThis->fMark == 0 );
513  // start the array of affected nodes
514  Vec_IntClear( p->vAffected );
515  Vec_IntForEachEntry( p->vCisChanged, Handle, i )
516  Vec_IntPush( p->vAffected, Handle );
517  // iteration propagation
518  while ( Vec_IntSize(p->vAffected) > 0 )
519  {
520  // compute the frontier
521  Vec_IntClear( p->vFrontier );
522  Gli_ManForEachEntry( p->vAffected, p, pThis, i )
523  {
524  Gli_ObjForEachFanout( pThis, pFanout, k )
525  {
526  if ( Gli_ObjIsCo(pFanout) )
527  continue;
528  if ( pFanout->fMark )
529  continue;
530  pFanout->fMark = 1;
531  Vec_IntPush( p->vFrontier, pFanout->Handle );
532  }
533  }
534  // compute the next set of affected nodes
535  Vec_IntClear( p->vAffected );
536  Gli_ManForEachEntry( p->vFrontier, p, pThis, i )
537  {
538  pThis->fMark = 0;
539  if ( ((int)pThis->fPhase2) == Gli_NodeComputeValue2(pThis) )
540  continue;
541  pThis->fPhase2 ^= 1;
542  pThis->nGlitches++;
543  Vec_IntPush( p->vAffected, pThis->Handle );
544  }
545  }
546 }
547 
548 /**Function*************************************************************
549 
550  Synopsis [Checks that the resulting values are the same.]
551 
552  Description []
553 
554  SideEffects []
555 
556  SeeAlso []
557 
558 ***********************************************************************/
560 {
561  Gli_Obj_t * pObj;
562  int i;
563  Gli_ManForEachObj( p, pObj, i )
564  {
565  assert( pObj->fPhase == pObj->fPhase2 );
566  assert( pObj->nGlitches >= pObj->nSwitches );
567  }
568 }
569 
570 /**Function*************************************************************
571 
572  Synopsis [Simulates one node.]
573 
574  Description []
575 
576  SideEffects []
577 
578  SeeAlso []
579 
580 ***********************************************************************/
582 {
583  unsigned pSimInfos[6], Result = 0;
584  int nFanins = Gli_ObjFaninNum(pNode);
585  int i, k, Phase;
586  Gli_Obj_t * pFanin;
587  assert( nFanins <= 6 );
588  Gli_ObjForEachFanin( pNode, pFanin, i )
589  pSimInfos[i] = pFanin->uSimInfo;
590  for ( i = 0; i < 32; i++ )
591  {
592  Phase = 0;
593  for ( k = 0; k < nFanins; k++ )
594  if ( (pSimInfos[k] >> i) & 1 )
595  Phase |= (1 << k);
596  if ( Abc_InfoHasBit( pNode->uTruth, Phase ) )
597  Result |= (1 << i);
598  }
599  return Result;
600 }
601 
602 /**Function*************************************************************
603 
604  Synopsis [Simulates one node.]
605 
606  Description []
607 
608  SideEffects []
609 
610  SeeAlso []
611 
612 ***********************************************************************/
613 static inline unsigned Gli_ManUpdateRandomInput( unsigned uInfo, float PiTransProb )
614 {
615  float Multi = 1.0 / (1 << 16);
616  int i;
617  if ( PiTransProb == 0.5 )
618  return Gia_ManRandom(0);
619  for ( i = 0; i < 32; i++ )
620  if ( Multi * (Gia_ManRandom(0) & 0xffff) < PiTransProb )
621  uInfo ^= (1 << i);
622  return uInfo;
623 }
624 
625 /**Function*************************************************************
626 
627  Synopsis [Simulates sequential network randomly for the given number of frames.]
628 
629  Description []
630 
631  SideEffects []
632 
633  SeeAlso []
634 
635 ***********************************************************************/
636 void Gli_ManSimulateSeqPref( Gli_Man_t * p, int nPref )
637 {
638  Gli_Obj_t * pObj, * pObjRi, * pObjRo;
639  int i, f;
640  // initialize simulation data
641  Gli_ManForEachPi( p, pObj, i )
642  pObj->uSimInfo = Gli_ManUpdateRandomInput( pObj->uSimInfo, 0.5 );
643  Gli_ManForEachRo( p, pObj, i )
644  pObj->uSimInfo = 0;
645  for ( f = 0; f < nPref; f++ )
646  {
647  // simulate one frame
648  Gli_ManForEachNode( p, pObj, i )
649  pObj->uSimInfo = Gli_ManSimulateSeqNode( p, pObj );
650  Gli_ManForEachRi( p, pObj, i )
651  pObj->uSimInfo = Gli_ObjFanin(pObj, 0)->uSimInfo;
652  // initialize the next frame
653  Gli_ManForEachPi( p, pObj, i )
654  pObj->uSimInfo = Gli_ManUpdateRandomInput( pObj->uSimInfo, 0.5 );
655  Gli_ManForEachRiRo( p, pObjRi, pObjRo, i )
656  pObjRo->uSimInfo = pObjRi->uSimInfo;
657  }
658  // save simulation data after nPref timeframes
659  if ( p->pSimInfoPrev == NULL )
660  p->pSimInfoPrev = ABC_ALLOC( unsigned, Gli_ManCiNum(p) );
661  Gli_ManForEachCi( p, pObj, i )
662  p->pSimInfoPrev[i] = pObj->uSimInfo;
663 }
664 
665 /**Function*************************************************************
666 
667  Synopsis [Initialized object values to be one pattern in the saved data.]
668 
669  Description []
670 
671  SideEffects []
672 
673  SeeAlso []
674 
675 ***********************************************************************/
676 void Gli_ManSetDataSaved( Gli_Man_t * p, int iBit )
677 {
678  Gli_Obj_t * pObj;
679  int i;
680  Gli_ManForEachCi( p, pObj, i )
681  pObj->fPhase = pObj->fPhase2 = ((p->pSimInfoPrev[i] >> iBit) & 1);
682  Gli_ManForEachNode( p, pObj, i )
683  pObj->fPhase = pObj->fPhase2 = Gli_NodeComputeValue( pObj );
684 }
685 
686 /**Function*************************************************************
687 
688  Synopsis [Sets random info at the PIs and collects changed PIs.]
689 
690  Description []
691 
692  SideEffects []
693 
694  SeeAlso []
695 
696 ***********************************************************************/
697 void Gli_ManSetPiRandomSeq( Gli_Man_t * p, float PiTransProb )
698 {
699  Gli_Obj_t * pObj, * pObjRi;
700  float Multi = 1.0 / (1 << 16);
701  int i;
702  assert( 0.0 < PiTransProb && PiTransProb < 1.0 );
703  // transfer data to the COs
704  Gli_ManForEachCo( p, pObj, i )
705  pObj->fPhase = pObj->fPhase2 = Gli_ObjFanin(pObj, 0)->fPhase;
706  // set changed PIs
708  Gli_ManForEachPi( p, pObj, i )
709  if ( Multi * (Gia_ManRandom(0) & 0xffff) < PiTransProb )
710  {
711  Vec_IntPush( p->vCisChanged, pObj->Handle );
712  pObj->fPhase ^= 1;
713  pObj->fPhase2 ^= 1;
714  pObj->nSwitches++;
715  pObj->nGlitches++;
716  }
717  // set changed ROs
718  Gli_ManForEachRiRo( p, pObjRi, pObj, i )
719  if ( pObjRi->fPhase != pObj->fPhase )
720  {
721  Vec_IntPush( p->vCisChanged, pObj->Handle );
722  pObj->fPhase ^= 1;
723  pObj->fPhase2 ^= 1;
724  pObj->nSwitches++;
725  pObj->nGlitches++;
726  }
727 
728 }
729 
730 /**Function*************************************************************
731 
732  Synopsis [Computes glitching activity of each node.]
733 
734  Description []
735 
736  SideEffects []
737 
738  SeeAlso []
739 
740 ***********************************************************************/
741 void Gli_ManSwitchesAndGlitches( Gli_Man_t * p, int nPatterns, float PiTransProb, int fVerbose )
742 {
743  int i, k;
744  abctime clk = Abc_Clock();
745  Gia_ManRandom( 1 );
746  Gli_ManFinalize( p );
747  if ( p->nRegs == 0 )
748  {
749  for ( i = 0; i < nPatterns; i++ )
750  {
751  Gli_ManSetPiRandom( p, PiTransProb );
752  Gli_ManSwitching( p );
753  Gli_ManGlitching( p );
754 // Gli_ManVerify( p );
755  }
756  }
757  else
758  {
759  int nIters = Abc_BitWordNum(nPatterns);
760  Gli_ManSimulateSeqPref( p, 16 );
761  for ( i = 0; i < 32; i++ )
762  {
763  Gli_ManSetDataSaved( p, i );
764  for ( k = 0; k < nIters; k++ )
765  {
766  Gli_ManSetPiRandomSeq( p, PiTransProb );
767  Gli_ManSwitching( p );
768  Gli_ManGlitching( p );
769 // Gli_ManVerify( p );
770  }
771  }
772  }
773  if ( fVerbose )
774  {
775  printf( "\nSimulated %d patterns. ", nPatterns );
776  ABC_PRMn( "Memory", 4*p->nObjData );
777  ABC_PRT( "Time", Abc_Clock() - clk );
778  }
779 }
780 
781 ////////////////////////////////////////////////////////////////////////
782 /// END OF FILE ///
783 ////////////////////////////////////////////////////////////////////////
784 
785 
787 
#define ABC_PRMn(a, f)
Definition: abc_global.h:226
int * pObjData
Definition: giaGlitch.c:68
unsigned fPhase
Definition: giaGlitch.c:34
int nTravIds
Definition: giaGlitch.c:65
static int Gli_ObjIsTerm(Gli_Obj_t *pObj)
Definition: giaGlitch.c:89
void Gli_ManPrintObjects(Gli_Man_t *p)
Definition: giaGlitch.c:192
unsigned Gli_ManSimulateSeqNode(Gli_Man_t *p, Gli_Obj_t *pNode)
Definition: giaGlitch.c:581
unsigned fTerm
Definition: giaGlitch.c:33
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned * pSimInfoPrev
Definition: giaGlitch.c:69
int Gli_ManCreateCi(Gli_Man_t *p, int nFanouts)
Definition: giaGlitch.c:288
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
Vec_Int_t * vFrontier
Definition: giaGlitch.c:62
static int Abc_InfoHasBit(unsigned *p, int i)
Definition: abc_global.h:258
unsigned nFanouts
Definition: giaGlitch.c:38
void Gli_ManGlitching(Gli_Man_t *p)
Definition: giaGlitch.c:507
static Gli_Obj_t * Gli_ManCi(Gli_Man_t *p, int v)
Definition: giaGlitch.c:82
int Gli_ObjNumGlitches(Gli_Man_t *p, int iNode)
Definition: giaGlitch.c:410
static Gli_Obj_t * Gli_ObjFanin(Gli_Obj_t *pObj, int i)
Definition: giaGlitch.c:98
void Gli_ManSwitching(Gli_Man_t *p)
Definition: giaGlitch.c:483
static Gli_Obj_t * Gli_ManCo(Gli_Man_t *p, int v)
Definition: giaGlitch.c:83
static Gli_Obj_t * Gli_ManPo(Gli_Man_t *p, int v)
Definition: giaGlitch.c:85
Vec_Int_t * vCis
Definition: giaGlitch.c:58
unsigned fPhase2
Definition: giaGlitch.c:35
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int Gli_ManCoNum(Gli_Man_t *p)
Definition: giaGlitch.c:74
int iObjData
Definition: giaGlitch.c:66
unsigned uTruth[2]
Definition: giaGlitch.c:40
static abctime Abc_Clock()
Definition: abc_global.h:279
Vec_Int_t * vAffected
Definition: giaGlitch.c:61
#define Gli_ObjForEachFanin(pObj, pNext, i)
Definition: giaGlitch.c:124
static Gli_Obj_t * Gli_ManObj(Gli_Man_t *p, int v)
Definition: giaGlitch.c:81
Vec_Int_t * vCos
Definition: giaGlitch.c:59
static int Gli_NodeComputeValue(Gli_Obj_t *pNode)
Definition: giaGlitch.c:331
int nRegs
Definition: giaGlitch.c:64
void Gli_ManFinalize(Gli_Man_t *p)
Definition: giaGlitch.c:221
static int Gli_ObjSize(Gli_Obj_t *pObj)
Definition: giaGlitch.c:96
#define Gli_ManForEachCo(p, pObj, i)
Definition: giaGlitch.c:110
typedefABC_NAMESPACE_IMPL_START struct Gli_Obj_t_ Gli_Obj_t
DECLARATIONS ///.
Definition: giaGlitch.c:30
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
Definition: giaUtil.c:49
void Gli_ManSimulateSeqPref(Gli_Man_t *p, int nPref)
Definition: giaGlitch.c:636
void Gli_ObjAddFanin(Gli_Obj_t *pObj, Gli_Obj_t *pFanin)
Definition: giaGlitch.c:246
int nGlitches
Definition: giaGlitch.c:50
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
int Fanios[0]
Definition: giaGlitch.c:52
void Gli_ManSetPiRandomSeq(Gli_Man_t *p, float PiTransProb)
Definition: giaGlitch.c:697
static int Gli_ManNodeNum(Gli_Man_t *p)
Definition: giaGlitch.c:79
unsigned nFanins
Definition: giaGlitch.c:37
#define Gli_ObjForEachFanout(pObj, pNext, i)
Definition: giaGlitch.c:126
unsigned Handle
Definition: giaGlitch.c:39
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
Gli_Obj_t * Gli_ObjAlloc(Gli_Man_t *p, int nFanins, int nFanouts)
Definition: giaGlitch.c:265
static Gli_Obj_t * Gli_ManRo(Gli_Man_t *p, int v)
Definition: giaGlitch.c:86
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static int Gli_ManCiNum(Gli_Man_t *p)
Definition: giaGlitch.c:73
int nSwitches
Definition: giaGlitch.c:45
static Gli_Obj_t * Gli_ObjFanout(Gli_Obj_t *pObj, int i)
Definition: giaGlitch.c:99
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
#define Gli_ManForEachObj(p, pObj, i)
Definition: giaGlitch.c:101
#define Gli_ManForEachCi(p, pObj, i)
Definition: giaGlitch.c:108
static unsigned Gli_ManUpdateRandomInput(unsigned uInfo, float PiTransProb)
Definition: giaGlitch.c:613
int Gli_ManCreateNode(Gli_Man_t *p, Vec_Int_t *vFanins, int nFanouts, unsigned *puTruth)
Definition: giaGlitch.c:369
int iFanout
Definition: giaGlitch.c:49
static int Gli_ManRegNum(Gli_Man_t *p)
Definition: giaGlitch.c:77
unsigned uSimInfo
Definition: giaGlitch.c:41
void Gli_ManSwitchesAndGlitches(Gli_Man_t *p, int nPatterns, float PiTransProb, int fVerbose)
Definition: giaGlitch.c:741
void Gli_ManSetDataSaved(Gli_Man_t *p, int iBit)
Definition: giaGlitch.c:676
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Gli_ManPoNum(Gli_Man_t *p)
Definition: giaGlitch.c:76
static int Gli_ManObjNum(Gli_Man_t *p)
Definition: giaGlitch.c:78
int nObjs
Definition: giaGlitch.c:63
static int Gli_NodeComputeValue2(Gli_Obj_t *pNode)
Definition: giaGlitch.c:350
Vec_Int_t * vCisChanged
Definition: giaGlitch.c:60
#define Gli_ManForEachEntry(vVec, p, pObj, i)
Definition: giaGlitch.c:106
int iFanin
Definition: giaGlitch.c:44
#define Gli_ManForEachRi(p, pObj, i)
Definition: giaGlitch.c:119
int Gli_ManCreateCo(Gli_Man_t *p, int iFanin)
Definition: giaGlitch.c:308
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
static int Gli_ObjIsNode(Gli_Obj_t *pObj)
Definition: giaGlitch.c:92
static int Gli_ObjIsCo(Gli_Obj_t *pObj)
Definition: giaGlitch.c:91
int nObjData
Definition: giaGlitch.c:67
unsigned fMark
Definition: giaGlitch.c:36
static int Gli_ObjIsCi(Gli_Obj_t *pObj)
Definition: giaGlitch.c:90
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_PRT(a, t)
Definition: abc_global.h:220
static Gli_Obj_t * Gli_ManPi(Gli_Man_t *p, int v)
Definition: giaGlitch.c:84
void Gli_ManStop(Gli_Man_t *p)
Definition: giaGlitch.c:170
static int Gli_ObjFaninNum(Gli_Obj_t *pObj)
Definition: giaGlitch.c:94
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
void Gli_ManVerify(Gli_Man_t *p)
Definition: giaGlitch.c:559
void Gli_ManSetPiRandom(Gli_Man_t *p, float PiTransProb)
Definition: giaGlitch.c:427
static Gli_Obj_t * Gli_ManRi(Gli_Man_t *p, int v)
Definition: giaGlitch.c:87
static int Abc_BitWordNum(int nBits)
Definition: abc_global.h:255
#define assert(ex)
Definition: util_old.h:213
static int Gli_ManPiNum(Gli_Man_t *p)
Definition: giaGlitch.c:75
#define Gli_ManForEachPi(p, pObj, i)
Definition: giaGlitch.c:113
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
int Gli_ObjNumSwitches(Gli_Man_t *p, int iNode)
Definition: giaGlitch.c:394
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
ABC_INT64_T abctime
Definition: abc_global.h:278
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
#define Gli_ManForEachRiRo(p, pObjRi, pObjRo, i)
Definition: giaGlitch.c:121
void Gli_ManSetPiFromSaved(Gli_Man_t *p, int iBit)
Definition: giaGlitch.c:456
Gli_Man_t * Gli_ManAlloc(int nObjs, int nRegs, int nFanioPairs)
FUNCTION DEFINITIONS ///.
Definition: giaGlitch.c:144
#define Gli_ManForEachRo(p, pObj, i)
Definition: giaGlitch.c:117
static int Gli_ObjFanoutNum(Gli_Obj_t *pObj)
Definition: giaGlitch.c:95
#define Gli_ManForEachNode(p, pObj, i)
Definition: giaGlitch.c:103