abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaSwitch.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [giaSwitch.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Scalable AIG package.]
8 
9  Synopsis [Computing switching activity.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: giaSwitch.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "giaAig.h"
22 #include "base/main/main.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 // switching estimation parameters
32 typedef struct Gia_ParSwi_t_ Gia_ParSwi_t;
34 {
35  // user-controlled parameters
36  int nWords; // the number of machine words
37  int nIters; // the number of timeframes
38  int nPref; // the number of first timeframes to skip
39  int nRandPiFactor; // PI trans prob (-1=3/8; 0=1/2; 1=1/4; 2=1/8, etc)
40  int fProbOne; // collect probability of one
41  int fProbTrans; // collect probatility of Swiing
42  int fVerbose; // enables verbose output
43 };
44 
45 typedef struct Gia_ManSwi_t_ Gia_ManSwi_t;
47 {
50  int nWords;
51  // simulation information
52  unsigned * pDataSim; // simulation data
53  unsigned * pDataSimCis; // simulation data for CIs
54  unsigned * pDataSimCos; // simulation data for COs
55  int * pData1; // switching data
56 };
57 
58 static inline unsigned * Gia_SwiData( Gia_ManSwi_t * p, int i ) { return p->pDataSim + i * p->nWords; }
59 static inline unsigned * Gia_SwiDataCi( Gia_ManSwi_t * p, int i ) { return p->pDataSimCis + i * p->nWords; }
60 static inline unsigned * Gia_SwiDataCo( Gia_ManSwi_t * p, int i ) { return p->pDataSimCos + i * p->nWords; }
61 
62 ////////////////////////////////////////////////////////////////////////
63 /// FUNCTION DEFINITIONS ///
64 ////////////////////////////////////////////////////////////////////////
65 
66 /**Function*************************************************************
67 
68  Synopsis [This procedure sets default parameters.]
69 
70  Description []
71 
72  SideEffects []
73 
74  SeeAlso []
75 
76 ***********************************************************************/
78 {
79  memset( p, 0, sizeof(Gia_ParSwi_t) );
80  p->nWords = 10; // the number of machine words of simulatation data
81  p->nIters = 48; // the number of all timeframes to simulate
82  p->nPref = 16; // the number of first timeframes to skip when computing switching
83  p->nRandPiFactor = 0; // primary input transition probability (-1=3/8; 0=1/2; 1=1/4; 2=1/8, etc)
84  p->fProbOne = 0; // compute probability of signal being one (if 0, compute probability of switching)
85  p->fProbTrans = 1; // compute signal transition probability (if 0, compute transition probability using probability of being one)
86  p->fVerbose = 0; // enables verbose output
87 }
88 
89 /**Function*************************************************************
90 
91  Synopsis [Creates fast simulation manager.]
92 
93  Description []
94 
95  SideEffects []
96 
97  SeeAlso []
98 
99 ***********************************************************************/
101 {
102  Gia_ManSwi_t * p;
103  p = ABC_ALLOC( Gia_ManSwi_t, 1 );
104  memset( p, 0, sizeof(Gia_ManSwi_t) );
105  p->pAig = Gia_ManFront( pAig );
106  p->pPars = pPars;
107  p->nWords = pPars->nWords;
108  p->pDataSim = ABC_ALLOC( unsigned, p->nWords * p->pAig->nFront );
109  p->pDataSimCis = ABC_ALLOC( unsigned, p->nWords * Gia_ManCiNum(p->pAig) );
110  p->pDataSimCos = ABC_ALLOC( unsigned, p->nWords * Gia_ManCoNum(p->pAig) );
111  p->pData1 = ABC_CALLOC( int, Gia_ManObjNum(pAig) );
112  return p;
113 }
114 
115 /**Function*************************************************************
116 
117  Synopsis []
118 
119  Description []
120 
121  SideEffects []
122 
123  SeeAlso []
124 
125 ***********************************************************************/
127 {
128  Gia_ManStop( p->pAig );
129  ABC_FREE( p->pData1 );
130  ABC_FREE( p->pDataSim );
131  ABC_FREE( p->pDataSimCis );
132  ABC_FREE( p->pDataSimCos );
133  ABC_FREE( p );
134 }
135 
136 /**Function*************************************************************
137 
138  Synopsis []
139 
140  Description []
141 
142  SideEffects []
143 
144  SeeAlso []
145 
146 ***********************************************************************/
147 static inline void Gia_ManSwiSimInfoRandom( Gia_ManSwi_t * p, unsigned * pInfo, int nProbNum )
148 {
149  unsigned Mask;
150  int w, i;
151  if ( nProbNum == -1 )
152  { // 3/8 = 1/4 + 1/8
153  Mask = (Gia_ManRandom( 0 ) & Gia_ManRandom( 0 )) |
154  (Gia_ManRandom( 0 ) & Gia_ManRandom( 0 ) & Gia_ManRandom( 0 ));
155  for ( w = p->nWords-1; w >= 0; w-- )
156  pInfo[w] ^= Mask;
157  }
158  else if ( nProbNum > 0 )
159  {
160  Mask = Gia_ManRandom( 0 );
161  for ( i = 0; i < nProbNum; i++ )
162  Mask &= Gia_ManRandom( 0 );
163  for ( w = p->nWords-1; w >= 0; w-- )
164  pInfo[w] ^= Mask;
165  }
166  else if ( nProbNum == 0 )
167  {
168  for ( w = p->nWords-1; w >= 0; w-- )
169  pInfo[w] = Gia_ManRandom( 0 );
170  }
171  else
172  assert( 0 );
173 }
174 
175 /**Function*************************************************************
176 
177  Synopsis []
178 
179  Description []
180 
181  SideEffects []
182 
183  SeeAlso []
184 
185 ***********************************************************************/
186 static inline void Gia_ManSwiSimInfoRandomShift( Gia_ManSwi_t * p, unsigned * pInfo, int nProbNum )
187 {
188  unsigned Mask;
189  int w, i;
190  if ( nProbNum == -1 )
191  { // 3/8 = 1/4 + 1/8
192  Mask = (Gia_ManRandom( 0 ) & Gia_ManRandom( 0 )) |
193  (Gia_ManRandom( 0 ) & Gia_ManRandom( 0 ) & Gia_ManRandom( 0 ));
194  }
195  else if ( nProbNum >= 0 )
196  {
197  Mask = Gia_ManRandom( 0 );
198  for ( i = 0; i < nProbNum; i++ )
199  Mask &= Gia_ManRandom( 0 );
200  }
201  else
202  assert( 0 );
203  for ( w = p->nWords-1; w >= 0; w-- )
204  pInfo[w] = (pInfo[w] << 16) | ((pInfo[w] ^ Mask) & 0xffff);
205 }
206 
207 /**Function*************************************************************
208 
209  Synopsis []
210 
211  Description []
212 
213  SideEffects []
214 
215  SeeAlso []
216 
217 ***********************************************************************/
218 static inline void Gia_ManSwiSimInfoZero( Gia_ManSwi_t * p, unsigned * pInfo )
219 {
220  int w;
221  for ( w = p->nWords-1; w >= 0; w-- )
222  pInfo[w] = 0;
223 }
224 
225 /**Function*************************************************************
226 
227  Synopsis []
228 
229  Description []
230 
231  SideEffects []
232 
233  SeeAlso []
234 
235 ***********************************************************************/
236 static inline void Gia_ManSwiSimInfoOne( Gia_ManSwi_t * p, unsigned * pInfo )
237 {
238  int w;
239  for ( w = p->nWords-1; w >= 0; w-- )
240  pInfo[w] = ~0;
241 }
242 
243 /**Function*************************************************************
244 
245  Synopsis []
246 
247  Description []
248 
249  SideEffects []
250 
251  SeeAlso []
252 
253 ***********************************************************************/
254 static inline void Gia_ManSwiSimInfoCopy( Gia_ManSwi_t * p, unsigned * pInfo, unsigned * pInfo0 )
255 {
256  int w;
257  for ( w = p->nWords-1; w >= 0; w-- )
258  pInfo[w] = pInfo0[w];
259 }
260 
261 /**Function*************************************************************
262 
263  Synopsis []
264 
265  Description []
266 
267  SideEffects []
268 
269  SeeAlso []
270 
271 ***********************************************************************/
272 static inline void Gia_ManSwiSimInfoCopyShift( Gia_ManSwi_t * p, unsigned * pInfo, unsigned * pInfo0 )
273 {
274  int w;
275  for ( w = p->nWords-1; w >= 0; w-- )
276  pInfo[w] = (pInfo[w] << 16) | (pInfo0[w] & 0xffff);
277 }
278 
279 /**Function*************************************************************
280 
281  Synopsis []
282 
283  Description []
284 
285  SideEffects []
286 
287  SeeAlso []
288 
289 ***********************************************************************/
290 static inline void Gia_ManSwiSimulateCi( Gia_ManSwi_t * p, Gia_Obj_t * pObj, int iCi )
291 {
292  unsigned * pInfo = Gia_SwiData( p, Gia_ObjValue(pObj) );
293  unsigned * pInfo0 = Gia_SwiDataCi( p, iCi );
294  int w;
295  for ( w = p->nWords-1; w >= 0; w-- )
296  pInfo[w] = pInfo0[w];
297 }
298 
299 /**Function*************************************************************
300 
301  Synopsis []
302 
303  Description []
304 
305  SideEffects []
306 
307  SeeAlso []
308 
309 ***********************************************************************/
310 static inline void Gia_ManSwiSimulateCo( Gia_ManSwi_t * p, int iCo, Gia_Obj_t * pObj )
311 {
312  unsigned * pInfo = Gia_SwiDataCo( p, iCo );
313  unsigned * pInfo0 = Gia_SwiData( p, Gia_ObjDiff0(pObj) );
314  int w;
315  if ( Gia_ObjFaninC0(pObj) )
316  for ( w = p->nWords-1; w >= 0; w-- )
317  pInfo[w] = ~pInfo0[w];
318  else
319  for ( w = p->nWords-1; w >= 0; w-- )
320  pInfo[w] = pInfo0[w];
321 }
322 
323 /**Function*************************************************************
324 
325  Synopsis []
326 
327  Description []
328 
329  SideEffects []
330 
331  SeeAlso []
332 
333 ***********************************************************************/
334 static inline void Gia_ManSwiSimulateNode( Gia_ManSwi_t * p, Gia_Obj_t * pObj )
335 {
336  unsigned * pInfo = Gia_SwiData( p, Gia_ObjValue(pObj) );
337  unsigned * pInfo0 = Gia_SwiData( p, Gia_ObjDiff0(pObj) );
338  unsigned * pInfo1 = Gia_SwiData( p, Gia_ObjDiff1(pObj) );
339  int w;
340  if ( Gia_ObjFaninC0(pObj) )
341  {
342  if ( Gia_ObjFaninC1(pObj) )
343  for ( w = p->nWords-1; w >= 0; w-- )
344  pInfo[w] = ~(pInfo0[w] | pInfo1[w]);
345  else
346  for ( w = p->nWords-1; w >= 0; w-- )
347  pInfo[w] = ~pInfo0[w] & pInfo1[w];
348  }
349  else
350  {
351  if ( Gia_ObjFaninC1(pObj) )
352  for ( w = p->nWords-1; w >= 0; w-- )
353  pInfo[w] = pInfo0[w] & ~pInfo1[w];
354  else
355  for ( w = p->nWords-1; w >= 0; w-- )
356  pInfo[w] = pInfo0[w] & pInfo1[w];
357  }
358 }
359 
360 /**Function*************************************************************
361 
362  Synopsis []
363 
364  Description []
365 
366  SideEffects []
367 
368  SeeAlso []
369 
370 ***********************************************************************/
371 static inline void Gia_ManSwiSimInfoInit( Gia_ManSwi_t * p )
372 {
373  int i = 0;
374  for ( ; i < Gia_ManPiNum(p->pAig); i++ )
375  Gia_ManSwiSimInfoRandom( p, Gia_SwiDataCi(p, i), 0 );
376  for ( ; i < Gia_ManCiNum(p->pAig); i++ )
378 }
379 
380 /**Function*************************************************************
381 
382  Synopsis []
383 
384  Description []
385 
386  SideEffects []
387 
388  SeeAlso []
389 
390 ***********************************************************************/
391 static inline void Gia_ManSwiSimInfoTransfer( Gia_ManSwi_t * p, int nProbNum )
392 {
393  int i = 0, nShift = Gia_ManPoNum(p->pAig)-Gia_ManPiNum(p->pAig);
394  for ( ; i < Gia_ManPiNum(p->pAig); i++ )
395  Gia_ManSwiSimInfoRandom( p, Gia_SwiDataCi(p, i), nProbNum );
396  for ( ; i < Gia_ManCiNum(p->pAig); i++ )
397  Gia_ManSwiSimInfoCopy( p, Gia_SwiDataCi(p, i), Gia_SwiDataCo(p, nShift+i) );
398 }
399 
400 /**Function*************************************************************
401 
402  Synopsis []
403 
404  Description []
405 
406  SideEffects []
407 
408  SeeAlso []
409 
410 ***********************************************************************/
411 static inline void Gia_ManSwiSimInfoTransferShift( Gia_ManSwi_t * p, int nProbNum )
412 {
413  int i = 0, nShift = Gia_ManPoNum(p->pAig)-Gia_ManPiNum(p->pAig);
414  for ( ; i < Gia_ManPiNum(p->pAig); i++ )
415  Gia_ManSwiSimInfoRandomShift( p, Gia_SwiDataCi(p, i), nProbNum );
416  for ( ; i < Gia_ManCiNum(p->pAig); i++ )
417  Gia_ManSwiSimInfoCopyShift( p, Gia_SwiDataCi(p, i), Gia_SwiDataCo(p, nShift+i) );
418 }
419 
420 /**Function*************************************************************
421 
422  Synopsis []
423 
424  Description []
425 
426  SideEffects []
427 
428  SeeAlso []
429 
430 ***********************************************************************/
431 static inline int Gia_ManSwiSimInfoCountOnes( Gia_ManSwi_t * p, int iPlace )
432 {
433  unsigned * pInfo;
434  int w, Counter = 0;
435  pInfo = Gia_SwiData( p, iPlace );
436  for ( w = p->nWords-1; w >= 0; w-- )
437  Counter += Gia_WordCountOnes( pInfo[w] );
438  return Counter;
439 }
440 
441 /**Function*************************************************************
442 
443  Synopsis []
444 
445  Description []
446 
447  SideEffects []
448 
449  SeeAlso []
450 
451 ***********************************************************************/
452 static inline int Gia_ManSwiSimInfoCountTrans( Gia_ManSwi_t * p, int iPlace )
453 {
454  unsigned * pInfo;
455  int w, Counter = 0;
456  pInfo = Gia_SwiData( p, iPlace );
457  for ( w = p->nWords-1; w >= 0; w-- )
458  Counter += 2*Gia_WordCountOnes( (pInfo[w] ^ (pInfo[w] >> 16)) & 0xffff );
459  return Counter;
460 }
461 
462 /**Function*************************************************************
463 
464  Synopsis []
465 
466  Description []
467 
468  SideEffects []
469 
470  SeeAlso []
471 
472 ***********************************************************************/
473 static inline void Gia_ManSwiSimulateRound( Gia_ManSwi_t * p, int fCount )
474 {
475  Gia_Obj_t * pObj;
476  int i;//, iCis = 0, iCos = 0;
477  assert( p->pAig->nFront > 0 );
478  assert( Gia_ManConst0(p->pAig)->Value == 0 );
480  Gia_ManForEachObj1( p->pAig, pObj, i )
481  {
482  if ( Gia_ObjIsAndOrConst0(pObj) )
483  {
484  assert( Gia_ObjValue(pObj) < p->pAig->nFront );
485  Gia_ManSwiSimulateNode( p, pObj );
486  }
487  else if ( Gia_ObjIsCo(pObj) )
488  {
489  assert( Gia_ObjValue(pObj) == GIA_NONE );
490 // Gia_ManSwiSimulateCo( p, iCos++, pObj );
491  Gia_ManSwiSimulateCo( p, Gia_ObjCioId(pObj), pObj );
492  }
493  else // if ( Gia_ObjIsCi(pObj) )
494  {
495  assert( Gia_ObjValue(pObj) < p->pAig->nFront );
496 // Gia_ManSwiSimulateCi( p, pObj, iCis++ );
497  Gia_ManSwiSimulateCi( p, pObj, Gia_ObjCioId(pObj) );
498  }
499  if ( fCount && !Gia_ObjIsCo(pObj) )
500  {
501  if ( p->pPars->fProbTrans )
502  p->pData1[i] += Gia_ManSwiSimInfoCountTrans( p, Gia_ObjValue(pObj) );
503  else
504  p->pData1[i] += Gia_ManSwiSimInfoCountOnes( p, Gia_ObjValue(pObj) );
505  }
506  }
507 // assert( Gia_ManCiNum(p->pAig) == iCis );
508 // assert( Gia_ManCoNum(p->pAig) == iCos );
509 }
510 
511 /**Function*************************************************************
512 
513  Synopsis [Computes switching activity of one node.]
514 
515  Description [Uses the formula: Switching = 2 * nOnes * nZeros / (nTotal ^ 2) ]
516 
517  SideEffects []
518 
519  SeeAlso []
520 
521 ***********************************************************************/
522 float Gia_ManSwiComputeSwitching( int nOnes, int nSimWords )
523 {
524  int nTotal = 32 * nSimWords;
525  return (float)2.0 * nOnes / nTotal * (nTotal - nOnes) / nTotal;
526 }
527 
528 /**Function*************************************************************
529 
530  Synopsis [Computes switching activity of one node.]
531 
532  Description [Uses the formula: Switching = 2 * nOnes * nZeros / (nTotal ^ 2) ]
533 
534  SideEffects []
535 
536  SeeAlso []
537 
538 ***********************************************************************/
539 float Gia_ManSwiComputeProbOne( int nOnes, int nSimWords )
540 {
541  int nTotal = 32 * nSimWords;
542  return (float)nOnes / nTotal;
543 }
544 
545 /**Function*************************************************************
546 
547  Synopsis []
548 
549  Description []
550 
551  SideEffects []
552 
553  SeeAlso []
554 
555 ***********************************************************************/
557 {
558  Gia_ManSwi_t * p;
559  Gia_Obj_t * pObj;
560  Vec_Int_t * vSwitching;
561  float * pSwitching;
562  int i;
563  abctime clk, clkTotal = Abc_Clock();
564  if ( pPars->fProbOne && pPars->fProbTrans )
565  printf( "Conflict of options: Can either compute probability of 1, or probability of switching by observing transitions.\n" );
566  // create manager
567  clk = Abc_Clock();
568  p = Gia_ManSwiCreate( pAig, pPars );
569  if ( pPars->fVerbose )
570  {
571  printf( "Obj = %8d (%8d). F = %6d. ",
572  pAig->nObjs, Gia_ManCiNum(pAig) + Gia_ManAndNum(pAig), p->pAig->nFront );
573  printf( "AIG = %7.2f MB. F-mem = %7.2f MB. Other = %7.2f MB. ",
574  12.0*Gia_ManObjNum(p->pAig)/(1<<20),
575  4.0*p->nWords*p->pAig->nFront/(1<<20),
576  4.0*p->nWords*(Gia_ManCiNum(p->pAig) + Gia_ManCoNum(p->pAig))/(1<<20) );
577  ABC_PRT( "Time", Abc_Clock() - clk );
578  }
579  // perform simulation
580  Gia_ManRandom( 1 );
582  for ( i = 0; i < pPars->nIters; i++ )
583  {
584  Gia_ManSwiSimulateRound( p, i >= pPars->nPref );
585  if ( i == pPars->nIters - 1 )
586  break;
587  if ( pPars->fProbTrans )
588  Gia_ManSwiSimInfoTransferShift( p, pPars->nRandPiFactor );
589  else
590  Gia_ManSwiSimInfoTransfer( p, pPars->nRandPiFactor );
591  }
592  if ( pPars->fVerbose )
593  {
594  printf( "Simulated %d frames with %d words. ", pPars->nIters, pPars->nWords );
595  ABC_PRT( "Simulation time", Abc_Clock() - clkTotal );
596  }
597  // derive the result
598  vSwitching = Vec_IntStart( Gia_ManObjNum(pAig) );
599  pSwitching = (float *)vSwitching->pArray;
600  if ( pPars->fProbOne )
601  {
602  Gia_ManForEachObj( pAig, pObj, i )
603  pSwitching[i] = Gia_ManSwiComputeProbOne( p->pData1[i], pPars->nWords*(pPars->nIters-pPars->nPref) );
604  Gia_ManForEachCo( pAig, pObj, i )
605  {
606  if ( Gia_ObjFaninC0(pObj) )
607  pSwitching[Gia_ObjId(pAig,pObj)] = (float)1.0-pSwitching[Gia_ObjId(pAig,Gia_ObjFanin0(pObj))];
608  else
609  pSwitching[Gia_ObjId(pAig,pObj)] = pSwitching[Gia_ObjId(pAig,Gia_ObjFanin0(pObj))];
610  }
611  }
612  else if ( pPars->fProbTrans )
613  {
614  Gia_ManForEachObj( pAig, pObj, i )
615  pSwitching[i] = Gia_ManSwiComputeProbOne( p->pData1[i], pPars->nWords*(pPars->nIters-pPars->nPref) );
616  }
617  else
618  {
619  Gia_ManForEachObj( pAig, pObj, i )
620  pSwitching[i] = Gia_ManSwiComputeSwitching( p->pData1[i], pPars->nWords*(pPars->nIters-pPars->nPref) );
621  }
622 /*
623  printf( "PI: " );
624  Gia_ManForEachPi( pAig, pObj, i )
625  printf( "%d=%d (%f) ", i, p->pData1[Gia_ObjId(pAig,pObj)], pSwitching[Gia_ObjId(pAig,pObj)] );
626  printf( "\n" );
627 
628  printf( "LO: " );
629  Gia_ManForEachRo( pAig, pObj, i )
630  printf( "%d=%d (%f) ", i, p->pData1[Gia_ObjId(pAig,pObj)], pSwitching[Gia_ObjId(pAig,pObj)] );
631  printf( "\n" );
632 
633  printf( "PO: " );
634  Gia_ManForEachPo( pAig, pObj, i )
635  printf( "%d=%d (%f) ", i, p->pData1[Gia_ObjId(pAig,pObj)], pSwitching[Gia_ObjId(pAig,pObj)] );
636  printf( "\n" );
637 
638  printf( "LI: " );
639  Gia_ManForEachRi( pAig, pObj, i )
640  printf( "%d=%d (%f) ", i, p->pData1[Gia_ObjId(pAig,pObj)], pSwitching[Gia_ObjId(pAig,pObj)] );
641  printf( "\n" );
642 */
643  Gia_ManSwiDelete( p );
644  return vSwitching;
645 
646 }
647 /**Function*************************************************************
648 
649  Synopsis [Computes probability of switching (or of being 1).]
650 
651  Description []
652 
653  SideEffects []
654 
655  SeeAlso []
656 
657 ***********************************************************************/
658 Vec_Int_t * Gia_ManComputeSwitchProbs( Gia_Man_t * pGia, int nFrames, int nPref, int fProbOne )
659 {
660  Gia_ParSwi_t Pars, * pPars = &Pars;
661  // set the default parameters
662  Gia_ManSetDefaultParamsSwi( pPars );
663  // override some of the defaults
664  pPars->nIters = nFrames; // set number of total timeframes
665  if ( Abc_FrameReadFlag("seqsimframes") )
666  pPars->nIters = atoi( Abc_FrameReadFlag("seqsimframes") );
667  pPars->nPref = nPref; // set number of first timeframes to skip
668  // decide what should be computed
669  if ( fProbOne )
670  {
671  // if the user asked to compute propability of 1, we do not need transition information
672  pPars->fProbOne = 1; // enable computing probabiblity of being one
673  pPars->fProbTrans = 0; // disable computing transition probability
674  }
675  else
676  {
677  // if the user asked for transition propabability, we do not need to compute probability of 1
678  pPars->fProbOne = 0; // disable computing probabiblity of being one
679  pPars->fProbTrans = 1; // enable computing transition probability
680  }
681  // perform the computation of switching activity
682  return Gia_ManSwiSimulate( pGia, pPars );
683 }
684 Vec_Int_t * Saig_ManComputeSwitchProbs( Aig_Man_t * pAig, int nFrames, int nPref, int fProbOne )
685 {
686  Vec_Int_t * vSwitching, * vResult;
687  Gia_Man_t * p;
688  Aig_Obj_t * pObj;
689  int i;
690  // translate AIG into the intermediate form (takes care of choices if present!)
691  p = Gia_ManFromAigSwitch( pAig );
692  // perform the computation of switching activity
693  vSwitching = Gia_ManComputeSwitchProbs( p, nFrames, nPref, fProbOne );
694  // transfer the computed result to the original AIG
695  vResult = Vec_IntStart( Aig_ManObjNumMax(pAig) );
696  Aig_ManForEachObj( pAig, pObj, i )
697  {
698 // if ( Aig_ObjIsCo(pObj) )
699 // printf( "%d=%f\n", i, Abc_Int2Float( Vec_IntEntry(vSwitching, Abc_Lit2Var(pObj->iData)) ) );
700  Vec_IntWriteEntry( vResult, i, Vec_IntEntry(vSwitching, Abc_Lit2Var(pObj->iData)) );
701  }
702  // delete intermediate results
703  Vec_IntFree( vSwitching );
704  Gia_ManStop( p );
705  return vResult;
706 }
707 
708 /**Function*************************************************************
709 
710  Synopsis [Computes probability of switching (or of being 1).]
711 
712  Description []
713 
714  SideEffects []
715 
716  SeeAlso []
717 
718 ***********************************************************************/
720 {
721  Gia_Obj_t * pObj;
722  float SwitchTotal = 0.0;
723  int i;
724  assert( p->pSwitching );
725  ABC_FREE( p->pRefs );
726  Gia_ManCreateRefs( p );
727  Gia_ManForEachObj( p, pObj, i )
728  SwitchTotal += (float)Gia_ObjRefNum(p, pObj) * p->pSwitching[i] / 255;
729  return SwitchTotal;
730 }
731 
732 /**Function*************************************************************
733 
734  Synopsis [Computes probability of switching (or of being 1).]
735 
736  Description []
737 
738  SideEffects []
739 
740  SeeAlso []
741 
742 ***********************************************************************/
743 /*
744 float Gia_ManComputeSwitching( Gia_Man_t * p, int nFrames, int nPref, int fProbOne )
745 {
746  Gia_Man_t * pDfs;
747  Gia_Obj_t * pObj, * pObjDfs;
748  Vec_Int_t * vSwitching;
749  float * pSwitching, Switch, SwitchTotal = 0.0;
750  int i;
751  // derives the DFS ordered AIG
752  if ( Gia_ManHasMapping(p) )
753  Gia_ManSetRefsMapped(p);
754  else
755  Gia_ManCreateRefs( p );
756 // pDfs = Gia_ManDupOrderDfs( p );
757  pDfs = Gia_ManDup( p );
758  assert( Gia_ManObjNum(pDfs) == Gia_ManObjNum(p) );
759  // perform the computation of switching activity
760  vSwitching = Gia_ManComputeSwitchProbs( pDfs, nFrames, nPref, fProbOne );
761  // transfer the computed result to the original AIG
762  ABC_FREE( p->pSwitching );
763  p->pSwitching = ABC_CALLOC( unsigned char, Gia_ManObjNum(p) );
764  pSwitching = (float *)vSwitching->pArray;
765  Gia_ManForEachObj( p, pObj, i )
766  {
767  pObjDfs = Gia_ObjFromLit( pDfs, pObj->Value );
768  Switch = pSwitching[ Gia_ObjId(pDfs, pObjDfs) ];
769  p->pSwitching[i] = (char)((Switch >= 1.0) ? 255 : (int)((0.002 + Switch) * 255)); // 0.00196 = (1/255)/2
770  if ( Gia_ObjIsCi(pObj) || (Gia_ObjIsAnd(pObj) && (!Gia_ManHasMapping(p) || Gia_ObjIsLut(p, i))) )
771  {
772  SwitchTotal += (float)Gia_ObjRefNum(p, pObj) * p->pSwitching[i] / 255;
773 // printf( "%d = %.2f\n", i, (float)Gia_ObjRefNum(p, pObj) * p->pSwitching[i] / 255 );
774  }
775  }
776  Vec_IntFree( vSwitching );
777  Gia_ManStop( pDfs );
778  return SwitchTotal;
779 }
780 */
781 float Gia_ManComputeSwitching( Gia_Man_t * p, int nFrames, int nPref, int fProbOne )
782 {
783  Vec_Int_t * vSwitching = Gia_ManComputeSwitchProbs( p, nFrames, nPref, fProbOne );
784  float * pSwi = (float *)Vec_IntArray(vSwitching), SwiTotal = 0;
785  Gia_Obj_t * pObj;
786  int i, k, iFan;
787  if ( Gia_ManHasMapping(p) )
788  {
789  Gia_ManForEachLut( p, i )
790  Gia_LutForEachFanin( p, i, iFan, k )
791  SwiTotal += pSwi[iFan];
792  }
793  else
794  {
795  Gia_ManForEachAnd( p, pObj, i )
796  SwiTotal += pSwi[Gia_ObjFaninId0(pObj, i)] + pSwi[Gia_ObjFaninId1(pObj, i)];
797  }
798  Vec_IntFree( vSwitching );
799  return SwiTotal;
800 }
801 
802 /**Function*************************************************************
803 
804  Synopsis [Determine probability of being 1 at the outputs.]
805 
806  Description []
807 
808  SideEffects []
809 
810  SeeAlso []
811 
812 ***********************************************************************/
814 {
815  Vec_Flt_t * vSimData;
816  Gia_Man_t * pDfs = Gia_ManDup( p );
817  assert( Gia_ManObjNum(pDfs) == Gia_ManObjNum(p) );
818  vSimData = (Vec_Flt_t *)Gia_ManComputeSwitchProbs( pDfs, (Gia_ManRegNum(p) ? 16 : 1), 0, 1 );
819  Gia_ManStop( pDfs );
820  return vSimData;
821 }
822 
823 ////////////////////////////////////////////////////////////////////////
824 /// END OF FILE ///
825 ////////////////////////////////////////////////////////////////////////
826 
827 
829 
char * memset()
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
static void Gia_ManSwiSimInfoZero(Gia_ManSwi_t *p, unsigned *pInfo)
Definition: giaSwitch.c:218
void Gia_ManCreateRefs(Gia_Man_t *p)
Definition: giaUtil.c:715
Gia_Man_t * Gia_ManFromAigSwitch(Aig_Man_t *p)
Definition: giaAig.c:211
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition: giaDup.c:552
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
static int Gia_ManPoNum(Gia_Man_t *p)
Definition: gia.h:386
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
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
float Gia_ManComputeSwitching(Gia_Man_t *p, int nFrames, int nPref, int fProbOne)
Definition: giaSwitch.c:781
unsigned * pDataSimCos
Definition: giaSwitch.c:54
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
int nFront
Definition: gia.h:119
static int Gia_ObjDiff1(Gia_Obj_t *pObj)
Definition: gia.h:450
int nRandPiFactor
Definition: giaSwitch.c:39
Gia_ParSwi_t * pPars
Definition: giaSwitch.c:49
static int Gia_ManSwiSimInfoCountOnes(Gia_ManSwi_t *p, int iPlace)
Definition: giaSwitch.c:431
static int Gia_ObjValue(Gia_Obj_t *pObj)
Definition: gia.h:413
static int Gia_ObjRefNum(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:521
static int Gia_WordCountOnes(unsigned uWord)
Definition: gia.h:313
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static void Gia_ManSwiSimulateCo(Gia_ManSwi_t *p, int iCo, Gia_Obj_t *pObj)
Definition: giaSwitch.c:310
static abctime Abc_Clock()
Definition: abc_global.h:279
int nObjs
Definition: gia.h:101
static void Gia_ManSwiSimInfoCopyShift(Gia_ManSwi_t *p, unsigned *pInfo, unsigned *pInfo0)
Definition: giaSwitch.c:272
static void Gia_ManSwiSimInfoRandom(Gia_ManSwi_t *p, unsigned *pInfo, int nProbNum)
Definition: giaSwitch.c:147
static void Gia_ManSwiSimInfoRandomShift(Gia_ManSwi_t *p, unsigned *pInfo, int nProbNum)
Definition: giaSwitch.c:186
int * pRefs
Definition: gia.h:114
static void Gia_ManSwiSimulateCi(Gia_ManSwi_t *p, Gia_Obj_t *pObj, int iCi)
Definition: giaSwitch.c:290
Definition: gia.h:75
#define Gia_ManForEachLut(p, i)
Definition: gia.h:968
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
Definition: giaUtil.c:49
Vec_Int_t * Gia_ManComputeSwitchProbs(Gia_Man_t *pGia, int nFrames, int nPref, int fProbOne)
Definition: giaSwitch.c:658
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static int Gia_ManAndNum(Gia_Man_t *p)
Definition: gia.h:389
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
static void Gia_ManSwiSimInfoCopy(Gia_ManSwi_t *p, unsigned *pInfo, unsigned *pInfo0)
Definition: giaSwitch.c:254
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
static int Gia_ManSwiSimInfoCountTrans(Gia_ManSwi_t *p, int iPlace)
Definition: giaSwitch.c:452
static void Gia_ManSwiSimInfoInit(Gia_ManSwi_t *p)
Definition: giaSwitch.c:371
Vec_Int_t * Gia_ManSwiSimulate(Gia_Man_t *pAig, Gia_ParSwi_t *pPars)
Definition: giaSwitch.c:556
Vec_Int_t * Saig_ManComputeSwitchProbs(Aig_Man_t *pAig, int nFrames, int nPref, int fProbOne)
Definition: giaSwitch.c:684
static void Gia_ManSwiSimInfoTransferShift(Gia_ManSwi_t *p, int nProbNum)
Definition: giaSwitch.c:411
Vec_Flt_t * Gia_ManPrintOutputProb(Gia_Man_t *p)
Definition: giaSwitch.c:813
static void Gia_ManSwiSimulateRound(Gia_ManSwi_t *p, int fCount)
Definition: giaSwitch.c:473
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
Gia_Man_t * Gia_ManFront(Gia_Man_t *p)
Definition: giaFront.c:147
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
if(last==0)
Definition: sparse_int.h:34
unsigned char * pSwitching
Definition: gia.h:147
static int Gia_ObjIsAndOrConst0(Gia_Obj_t *pObj)
Definition: gia.h:419
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
int fProbTrans
Definition: giaSwitch.c:41
Definition: aig.h:69
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
static int Counter
static void Gia_ManSwiSimulateNode(Gia_ManSwi_t *p, Gia_Obj_t *pObj)
Definition: giaSwitch.c:334
float Gia_ManSwiComputeSwitching(int nOnes, int nSimWords)
Definition: giaSwitch.c:522
static int Gia_ObjDiff0(Gia_Obj_t *pObj)
Definition: gia.h:449
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
static int Gia_ObjIsCo(Gia_Obj_t *pObj)
Definition: gia.h:421
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Gia_ManCiNum(Gia_Man_t *p)
Definition: gia.h:383
int iData
Definition: aig.h:88
Gia_Man_t * pAig
Definition: giaSwitch.c:48
typedefABC_NAMESPACE_IMPL_START struct Gia_ParSwi_t_ Gia_ParSwi_t
DECLARATIONS ///.
Definition: giaSwitch.c:32
static int Gia_ManHasMapping(Gia_Man_t *p)
Definition: gia.h:951
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
unsigned * pDataSimCis
Definition: giaSwitch.c:53
#define ABC_FREE(obj)
Definition: abc_global.h:232
Definition: gia.h:95
#define ABC_PRT(a, t)
Definition: abc_global.h:220
static unsigned * Gia_SwiData(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:58
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition: gia.h:984
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
#define GIA_NONE
INCLUDES ///.
Definition: gia.h:44
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
static unsigned * Gia_SwiDataCo(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:60
void Gia_ManSetDefaultParamsSwi(Gia_ParSwi_t *p)
FUNCTION DEFINITIONS ///.
Definition: giaSwitch.c:77
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
Definition: vecFlt.h:42
int * pData1
Definition: giaSwitch.c:55
#define assert(ex)
Definition: util_old.h:213
unsigned Value
Definition: gia.h:87
ABC_DLL char * Abc_FrameReadFlag(char *pFlag)
Definition: mainFrame.c:64
#define Gia_ManForEachObj1(p, pObj, i)
Definition: gia.h:986
static void Gia_ManSwiSimInfoOne(Gia_ManSwi_t *p, unsigned *pInfo)
Definition: giaSwitch.c:236
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
Gia_ManSwi_t * Gia_ManSwiCreate(Gia_Man_t *pAig, Gia_ParSwi_t *pPars)
Definition: giaSwitch.c:100
static int Gia_ManPiNum(Gia_Man_t *p)
Definition: gia.h:385
static void Gia_ManSwiSimInfoTransfer(Gia_ManSwi_t *p, int nProbNum)
Definition: giaSwitch.c:391
ABC_INT64_T abctime
Definition: abc_global.h:278
static int Gia_ObjFaninId1(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:461
void Gia_ManSwiDelete(Gia_ManSwi_t *p)
Definition: giaSwitch.c:126
float Gia_ManSwiComputeProbOne(int nOnes, int nSimWords)
Definition: giaSwitch.c:539
float Gia_ManEvaluateSwitching(Gia_Man_t *p)
Definition: giaSwitch.c:719
#define Gia_LutForEachFanin(p, i, iFan, k)
Definition: gia.h:970
static int Gia_ObjCioId(Gia_Obj_t *pObj)
Definition: gia.h:411
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
int nTotal
DECLARATIONS ///.
Definition: cutTruth.c:37
static unsigned * Gia_SwiDataCi(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:59
static int Gia_ObjFaninId0(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:460
static int Gia_ManCoNum(Gia_Man_t *p)
Definition: gia.h:384
unsigned * pDataSim
Definition: giaSwitch.c:52
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387