abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaSwitch.c File Reference
#include "giaAig.h"
#include "base/main/main.h"

Go to the source code of this file.

Data Structures

struct  Gia_ParSwi_t_
 
struct  Gia_ManSwi_t_
 

Typedefs

typedef
typedefABC_NAMESPACE_IMPL_START
struct Gia_ParSwi_t_ 
Gia_ParSwi_t
 DECLARATIONS ///. More...
 
typedef struct Gia_ManSwi_t_ Gia_ManSwi_t
 

Functions

static unsigned * Gia_SwiData (Gia_ManSwi_t *p, int i)
 
static unsigned * Gia_SwiDataCi (Gia_ManSwi_t *p, int i)
 
static unsigned * Gia_SwiDataCo (Gia_ManSwi_t *p, int i)
 
void Gia_ManSetDefaultParamsSwi (Gia_ParSwi_t *p)
 FUNCTION DEFINITIONS ///. More...
 
Gia_ManSwi_tGia_ManSwiCreate (Gia_Man_t *pAig, Gia_ParSwi_t *pPars)
 
void Gia_ManSwiDelete (Gia_ManSwi_t *p)
 
static void Gia_ManSwiSimInfoRandom (Gia_ManSwi_t *p, unsigned *pInfo, int nProbNum)
 
static void Gia_ManSwiSimInfoRandomShift (Gia_ManSwi_t *p, unsigned *pInfo, int nProbNum)
 
static void Gia_ManSwiSimInfoZero (Gia_ManSwi_t *p, unsigned *pInfo)
 
static void Gia_ManSwiSimInfoOne (Gia_ManSwi_t *p, unsigned *pInfo)
 
static void Gia_ManSwiSimInfoCopy (Gia_ManSwi_t *p, unsigned *pInfo, unsigned *pInfo0)
 
static void Gia_ManSwiSimInfoCopyShift (Gia_ManSwi_t *p, unsigned *pInfo, unsigned *pInfo0)
 
static void Gia_ManSwiSimulateCi (Gia_ManSwi_t *p, Gia_Obj_t *pObj, int iCi)
 
static void Gia_ManSwiSimulateCo (Gia_ManSwi_t *p, int iCo, Gia_Obj_t *pObj)
 
static void Gia_ManSwiSimulateNode (Gia_ManSwi_t *p, Gia_Obj_t *pObj)
 
static void Gia_ManSwiSimInfoInit (Gia_ManSwi_t *p)
 
static void Gia_ManSwiSimInfoTransfer (Gia_ManSwi_t *p, int nProbNum)
 
static void Gia_ManSwiSimInfoTransferShift (Gia_ManSwi_t *p, int nProbNum)
 
static int Gia_ManSwiSimInfoCountOnes (Gia_ManSwi_t *p, int iPlace)
 
static int Gia_ManSwiSimInfoCountTrans (Gia_ManSwi_t *p, int iPlace)
 
static void Gia_ManSwiSimulateRound (Gia_ManSwi_t *p, int fCount)
 
float Gia_ManSwiComputeSwitching (int nOnes, int nSimWords)
 
float Gia_ManSwiComputeProbOne (int nOnes, int nSimWords)
 
Vec_Int_tGia_ManSwiSimulate (Gia_Man_t *pAig, Gia_ParSwi_t *pPars)
 
Vec_Int_tGia_ManComputeSwitchProbs (Gia_Man_t *pGia, int nFrames, int nPref, int fProbOne)
 
Vec_Int_tSaig_ManComputeSwitchProbs (Aig_Man_t *pAig, int nFrames, int nPref, int fProbOne)
 
float Gia_ManEvaluateSwitching (Gia_Man_t *p)
 
float Gia_ManComputeSwitching (Gia_Man_t *p, int nFrames, int nPref, int fProbOne)
 
Vec_Flt_tGia_ManPrintOutputProb (Gia_Man_t *p)
 

Typedef Documentation

typedef struct Gia_ManSwi_t_ Gia_ManSwi_t

Definition at line 45 of file giaSwitch.c.

typedef typedefABC_NAMESPACE_IMPL_START struct Gia_ParSwi_t_ Gia_ParSwi_t

DECLARATIONS ///.

CFile****************************************************************

FileName [giaSwitch.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Scalable AIG package.]

Synopsis [Computing switching activity.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
giaSwitch.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 32 of file giaSwitch.c.

Function Documentation

float Gia_ManComputeSwitching ( Gia_Man_t p,
int  nFrames,
int  nPref,
int  fProbOne 
)

Function*************************************************************

Synopsis [Computes probability of switching (or of being 1).]

Description []

SideEffects []

SeeAlso []

Definition at line 781 of file giaSwitch.c.

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 }
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
Definition: gia.h:75
#define Gia_ManForEachLut(p, i)
Definition: gia.h:968
Vec_Int_t * Gia_ManComputeSwitchProbs(Gia_Man_t *pGia, int nFrames, int nPref, int fProbOne)
Definition: giaSwitch.c:658
else
Definition: sparse_int.h:55
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
static int Gia_ManHasMapping(Gia_Man_t *p)
Definition: gia.h:951
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
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
static int Gia_ObjFaninId0(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:460
Vec_Int_t* Gia_ManComputeSwitchProbs ( Gia_Man_t pGia,
int  nFrames,
int  nPref,
int  fProbOne 
)

Function*************************************************************

Synopsis [Computes probability of switching (or of being 1).]

Description []

SideEffects []

SeeAlso []

Definition at line 658 of file giaSwitch.c.

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 }
Vec_Int_t * Gia_ManSwiSimulate(Gia_Man_t *pAig, Gia_ParSwi_t *pPars)
Definition: giaSwitch.c:556
typedefABC_NAMESPACE_IMPL_START struct Gia_ParSwi_t_ Gia_ParSwi_t
DECLARATIONS ///.
Definition: giaSwitch.c:32
void Gia_ManSetDefaultParamsSwi(Gia_ParSwi_t *p)
FUNCTION DEFINITIONS ///.
Definition: giaSwitch.c:77
ABC_DLL char * Abc_FrameReadFlag(char *pFlag)
Definition: mainFrame.c:64
float Gia_ManEvaluateSwitching ( Gia_Man_t p)

Function*************************************************************

Synopsis [Computes probability of switching (or of being 1).]

Description []

SideEffects []

SeeAlso []

Definition at line 719 of file giaSwitch.c.

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 }
void Gia_ManCreateRefs(Gia_Man_t *p)
Definition: giaUtil.c:715
static int Gia_ObjRefNum(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:521
int * pRefs
Definition: gia.h:114
Definition: gia.h:75
unsigned char * pSwitching
Definition: gia.h:147
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition: gia.h:984
#define assert(ex)
Definition: util_old.h:213
Vec_Flt_t* Gia_ManPrintOutputProb ( Gia_Man_t p)

Function*************************************************************

Synopsis [Determine probability of being 1 at the outputs.]

Description []

SideEffects []

SeeAlso []

Definition at line 813 of file giaSwitch.c.

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 }
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition: giaDup.c:552
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
Vec_Int_t * Gia_ManComputeSwitchProbs(Gia_Man_t *pGia, int nFrames, int nPref, int fProbOne)
Definition: giaSwitch.c:658
Definition: gia.h:95
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
Definition: vecFlt.h:42
#define assert(ex)
Definition: util_old.h:213
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387
void Gia_ManSetDefaultParamsSwi ( Gia_ParSwi_t p)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [This procedure sets default parameters.]

Description []

SideEffects []

SeeAlso []

Definition at line 77 of file giaSwitch.c.

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 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Gia_ParSwi_t_ Gia_ParSwi_t
DECLARATIONS ///.
Definition: giaSwitch.c:32
float Gia_ManSwiComputeProbOne ( int  nOnes,
int  nSimWords 
)

Function*************************************************************

Synopsis [Computes switching activity of one node.]

Description [Uses the formula: Switching = 2 * nOnes * nZeros / (nTotal ^ 2) ]

SideEffects []

SeeAlso []

Definition at line 539 of file giaSwitch.c.

540 {
541  int nTotal = 32 * nSimWords;
542  return (float)nOnes / nTotal;
543 }
int nTotal
DECLARATIONS ///.
Definition: cutTruth.c:37
float Gia_ManSwiComputeSwitching ( int  nOnes,
int  nSimWords 
)

Function*************************************************************

Synopsis [Computes switching activity of one node.]

Description [Uses the formula: Switching = 2 * nOnes * nZeros / (nTotal ^ 2) ]

SideEffects []

SeeAlso []

Definition at line 522 of file giaSwitch.c.

523 {
524  int nTotal = 32 * nSimWords;
525  return (float)2.0 * nOnes / nTotal * (nTotal - nOnes) / nTotal;
526 }
int nTotal
DECLARATIONS ///.
Definition: cutTruth.c:37
Gia_ManSwi_t* Gia_ManSwiCreate ( Gia_Man_t pAig,
Gia_ParSwi_t pPars 
)

Function*************************************************************

Synopsis [Creates fast simulation manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 100 of file giaSwitch.c.

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 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned * pDataSimCos
Definition: giaSwitch.c:54
int nFront
Definition: gia.h:119
Gia_ParSwi_t * pPars
Definition: giaSwitch.c:49
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Gia_Man_t * Gia_ManFront(Gia_Man_t *p)
Definition: giaFront.c:147
static int Gia_ManCiNum(Gia_Man_t *p)
Definition: gia.h:383
Gia_Man_t * pAig
Definition: giaSwitch.c:48
unsigned * pDataSimCis
Definition: giaSwitch.c:53
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
int * pData1
Definition: giaSwitch.c:55
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
static int Gia_ManCoNum(Gia_Man_t *p)
Definition: gia.h:384
unsigned * pDataSim
Definition: giaSwitch.c:52
void Gia_ManSwiDelete ( Gia_ManSwi_t p)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 126 of file giaSwitch.c.

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 }
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
unsigned * pDataSimCos
Definition: giaSwitch.c:54
Gia_Man_t * pAig
Definition: giaSwitch.c:48
unsigned * pDataSimCis
Definition: giaSwitch.c:53
#define ABC_FREE(obj)
Definition: abc_global.h:232
int * pData1
Definition: giaSwitch.c:55
unsigned * pDataSim
Definition: giaSwitch.c:52
static void Gia_ManSwiSimInfoCopy ( Gia_ManSwi_t p,
unsigned *  pInfo,
unsigned *  pInfo0 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 254 of file giaSwitch.c.

255 {
256  int w;
257  for ( w = p->nWords-1; w >= 0; w-- )
258  pInfo[w] = pInfo0[w];
259 }
static void Gia_ManSwiSimInfoCopyShift ( Gia_ManSwi_t p,
unsigned *  pInfo,
unsigned *  pInfo0 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 272 of file giaSwitch.c.

273 {
274  int w;
275  for ( w = p->nWords-1; w >= 0; w-- )
276  pInfo[w] = (pInfo[w] << 16) | (pInfo0[w] & 0xffff);
277 }
static int Gia_ManSwiSimInfoCountOnes ( Gia_ManSwi_t p,
int  iPlace 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 431 of file giaSwitch.c.

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 }
static int Gia_WordCountOnes(unsigned uWord)
Definition: gia.h:313
static int Counter
static unsigned * Gia_SwiData(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:58
static int Gia_ManSwiSimInfoCountTrans ( Gia_ManSwi_t p,
int  iPlace 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 452 of file giaSwitch.c.

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 }
static int Gia_WordCountOnes(unsigned uWord)
Definition: gia.h:313
static int Counter
static unsigned * Gia_SwiData(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:58
static void Gia_ManSwiSimInfoInit ( Gia_ManSwi_t p)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 371 of file giaSwitch.c.

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 }
static void Gia_ManSwiSimInfoZero(Gia_ManSwi_t *p, unsigned *pInfo)
Definition: giaSwitch.c:218
static void Gia_ManSwiSimInfoRandom(Gia_ManSwi_t *p, unsigned *pInfo, int nProbNum)
Definition: giaSwitch.c:147
static int Gia_ManCiNum(Gia_Man_t *p)
Definition: gia.h:383
Gia_Man_t * pAig
Definition: giaSwitch.c:48
static int Gia_ManPiNum(Gia_Man_t *p)
Definition: gia.h:385
static unsigned * Gia_SwiDataCi(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:59
static void Gia_ManSwiSimInfoOne ( Gia_ManSwi_t p,
unsigned *  pInfo 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 236 of file giaSwitch.c.

237 {
238  int w;
239  for ( w = p->nWords-1; w >= 0; w-- )
240  pInfo[w] = ~0;
241 }
static void Gia_ManSwiSimInfoRandom ( Gia_ManSwi_t p,
unsigned *  pInfo,
int  nProbNum 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 147 of file giaSwitch.c.

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 }
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
Definition: giaUtil.c:49
#define assert(ex)
Definition: util_old.h:213
static void Gia_ManSwiSimInfoRandomShift ( Gia_ManSwi_t p,
unsigned *  pInfo,
int  nProbNum 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 186 of file giaSwitch.c.

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 }
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
Definition: giaUtil.c:49
#define assert(ex)
Definition: util_old.h:213
static void Gia_ManSwiSimInfoTransfer ( Gia_ManSwi_t p,
int  nProbNum 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 391 of file giaSwitch.c.

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 }
static int Gia_ManPoNum(Gia_Man_t *p)
Definition: gia.h:386
static void Gia_ManSwiSimInfoRandom(Gia_ManSwi_t *p, unsigned *pInfo, int nProbNum)
Definition: giaSwitch.c:147
static void Gia_ManSwiSimInfoCopy(Gia_ManSwi_t *p, unsigned *pInfo, unsigned *pInfo0)
Definition: giaSwitch.c:254
static int Gia_ManCiNum(Gia_Man_t *p)
Definition: gia.h:383
Gia_Man_t * pAig
Definition: giaSwitch.c:48
static unsigned * Gia_SwiDataCo(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:60
static int Gia_ManPiNum(Gia_Man_t *p)
Definition: gia.h:385
static unsigned * Gia_SwiDataCi(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:59
static void Gia_ManSwiSimInfoTransferShift ( Gia_ManSwi_t p,
int  nProbNum 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 411 of file giaSwitch.c.

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 }
static int Gia_ManPoNum(Gia_Man_t *p)
Definition: gia.h:386
static void Gia_ManSwiSimInfoCopyShift(Gia_ManSwi_t *p, unsigned *pInfo, unsigned *pInfo0)
Definition: giaSwitch.c:272
static void Gia_ManSwiSimInfoRandomShift(Gia_ManSwi_t *p, unsigned *pInfo, int nProbNum)
Definition: giaSwitch.c:186
static int Gia_ManCiNum(Gia_Man_t *p)
Definition: gia.h:383
Gia_Man_t * pAig
Definition: giaSwitch.c:48
static unsigned * Gia_SwiDataCo(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:60
static int Gia_ManPiNum(Gia_Man_t *p)
Definition: gia.h:385
static unsigned * Gia_SwiDataCi(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:59
static void Gia_ManSwiSimInfoZero ( Gia_ManSwi_t p,
unsigned *  pInfo 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 218 of file giaSwitch.c.

219 {
220  int w;
221  for ( w = p->nWords-1; w >= 0; w-- )
222  pInfo[w] = 0;
223 }
Vec_Int_t* Gia_ManSwiSimulate ( Gia_Man_t pAig,
Gia_ParSwi_t pPars 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 556 of file giaSwitch.c.

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 }
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
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 nFront
Definition: gia.h:119
static abctime Abc_Clock()
Definition: abc_global.h:279
int nObjs
Definition: gia.h:101
int nWords
Definition: abcNpn.c:127
Definition: gia.h:75
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
Definition: giaUtil.c:49
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 Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
static void Gia_ManSwiSimInfoInit(Gia_ManSwi_t *p)
Definition: giaSwitch.c:371
static void Gia_ManSwiSimInfoTransferShift(Gia_ManSwi_t *p, int nProbNum)
Definition: giaSwitch.c:411
static void Gia_ManSwiSimulateRound(Gia_ManSwi_t *p, int fCount)
Definition: giaSwitch.c:473
if(last==0)
Definition: sparse_int.h:34
else
Definition: sparse_int.h:55
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
float Gia_ManSwiComputeSwitching(int nOnes, int nSimWords)
Definition: giaSwitch.c:522
static int Gia_ManCiNum(Gia_Man_t *p)
Definition: gia.h:383
Gia_Man_t * pAig
Definition: giaSwitch.c:48
#define ABC_PRT(a, t)
Definition: abc_global.h:220
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition: gia.h:984
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
Gia_ManSwi_t * Gia_ManSwiCreate(Gia_Man_t *pAig, Gia_ParSwi_t *pPars)
Definition: giaSwitch.c:100
static void Gia_ManSwiSimInfoTransfer(Gia_ManSwi_t *p, int nProbNum)
Definition: giaSwitch.c:391
ABC_INT64_T abctime
Definition: abc_global.h:278
void Gia_ManSwiDelete(Gia_ManSwi_t *p)
Definition: giaSwitch.c:126
float Gia_ManSwiComputeProbOne(int nOnes, int nSimWords)
Definition: giaSwitch.c:539
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
static int Gia_ManCoNum(Gia_Man_t *p)
Definition: gia.h:384
static void Gia_ManSwiSimulateCi ( Gia_ManSwi_t p,
Gia_Obj_t pObj,
int  iCi 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 290 of file giaSwitch.c.

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 }
static int Gia_ObjValue(Gia_Obj_t *pObj)
Definition: gia.h:413
static unsigned * Gia_SwiData(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:58
static unsigned * Gia_SwiDataCi(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:59
static void Gia_ManSwiSimulateCo ( Gia_ManSwi_t p,
int  iCo,
Gia_Obj_t pObj 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 310 of file giaSwitch.c.

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 }
static int Gia_ObjDiff0(Gia_Obj_t *pObj)
Definition: gia.h:449
static unsigned * Gia_SwiData(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:58
static unsigned * Gia_SwiDataCo(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:60
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
static void Gia_ManSwiSimulateNode ( Gia_ManSwi_t p,
Gia_Obj_t pObj 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 334 of file giaSwitch.c.

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 }
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
static int Gia_ObjDiff1(Gia_Obj_t *pObj)
Definition: gia.h:450
static int Gia_ObjValue(Gia_Obj_t *pObj)
Definition: gia.h:413
static int Gia_ObjDiff0(Gia_Obj_t *pObj)
Definition: gia.h:449
static unsigned * Gia_SwiData(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:58
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
static void Gia_ManSwiSimulateRound ( Gia_ManSwi_t p,
int  fCount 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 473 of file giaSwitch.c.

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 }
static void Gia_ManSwiSimInfoZero(Gia_ManSwi_t *p, unsigned *pInfo)
Definition: giaSwitch.c:218
int nFront
Definition: gia.h:119
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 void Gia_ManSwiSimulateCo(Gia_ManSwi_t *p, int iCo, Gia_Obj_t *pObj)
Definition: giaSwitch.c:310
static void Gia_ManSwiSimulateCi(Gia_ManSwi_t *p, Gia_Obj_t *pObj, int iCi)
Definition: giaSwitch.c:290
Definition: gia.h:75
static int Gia_ManSwiSimInfoCountTrans(Gia_ManSwi_t *p, int iPlace)
Definition: giaSwitch.c:452
static int Gia_ObjIsAndOrConst0(Gia_Obj_t *pObj)
Definition: gia.h:419
static void Gia_ManSwiSimulateNode(Gia_ManSwi_t *p, Gia_Obj_t *pObj)
Definition: giaSwitch.c:334
static int Gia_ObjIsCo(Gia_Obj_t *pObj)
Definition: gia.h:421
Gia_Man_t * pAig
Definition: giaSwitch.c:48
static unsigned * Gia_SwiData(Gia_ManSwi_t *p, int i)
Definition: giaSwitch.c:58
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
#define GIA_NONE
INCLUDES ///.
Definition: gia.h:44
int * pData1
Definition: giaSwitch.c:55
#define assert(ex)
Definition: util_old.h:213
unsigned Value
Definition: gia.h:87
#define Gia_ManForEachObj1(p, pObj, i)
Definition: gia.h:986
static int Gia_ObjCioId(Gia_Obj_t *pObj)
Definition: gia.h:411
static unsigned* Gia_SwiData ( Gia_ManSwi_t p,
int  i 
)
inlinestatic

Definition at line 58 of file giaSwitch.c.

58 { return p->pDataSim + i * p->nWords; }
unsigned * pDataSim
Definition: giaSwitch.c:52
static unsigned* Gia_SwiDataCi ( Gia_ManSwi_t p,
int  i 
)
inlinestatic

Definition at line 59 of file giaSwitch.c.

59 { return p->pDataSimCis + i * p->nWords; }
unsigned * pDataSimCis
Definition: giaSwitch.c:53
static unsigned* Gia_SwiDataCo ( Gia_ManSwi_t p,
int  i 
)
inlinestatic

Definition at line 60 of file giaSwitch.c.

60 { return p->pDataSimCos + i * p->nWords; }
unsigned * pDataSimCos
Definition: giaSwitch.c:54
Vec_Int_t* Saig_ManComputeSwitchProbs ( Aig_Man_t pAig,
int  nFrames,
int  nPref,
int  fProbOne 
)

Definition at line 684 of file giaSwitch.c.

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 }
Gia_Man_t * Gia_ManFromAigSwitch(Aig_Man_t *p)
Definition: giaAig.c:211
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
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
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 Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
Definition: aig.h:69
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
int iData
Definition: aig.h:88
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
Definition: gia.h:95
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235