abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
simSwitch.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [simSwitch.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Computes switching activity of nodes in the ABC network.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: simSwitch.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "sim.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 static void Sim_NodeSimulate( Abc_Obj_t * pNode, Vec_Ptr_t * vSimInfo, int nSimWords );
32 static float Sim_ComputeSwitching( unsigned * pSimInfo, int nSimWords );
33 
34 ////////////////////////////////////////////////////////////////////////
35 /// FUNCTION DEFINITIONS ///
36 ////////////////////////////////////////////////////////////////////////
37 
38 /**Function*************************************************************
39 
40  Synopsis [Computes switching activity using simulation.]
41 
42  Description [Computes switching activity, which is understood as the
43  probability of switching under random simulation. Assigns the
44  random simulation information at the CI and propagates it through
45  the internal nodes of the AIG.]
46 
47  SideEffects []
48 
49  SeeAlso []
50 
51 ***********************************************************************/
52 Vec_Int_t * Sim_NtkComputeSwitching( Abc_Ntk_t * pNtk, int nPatterns )
53 {
54  Vec_Int_t * vSwitching;
55  float * pSwitching;
56  Vec_Ptr_t * vNodes;
57  Vec_Ptr_t * vSimInfo;
58  Abc_Obj_t * pNode;
59  unsigned * pSimInfo;
60  int nSimWords, i;
61 
62  // allocate space for simulation info of all nodes
63  nSimWords = SIM_NUM_WORDS(nPatterns);
64  vSimInfo = Sim_UtilInfoAlloc( Abc_NtkObjNumMax(pNtk), nSimWords, 0 );
65  // assign the random simulation to the CIs
66  vSwitching = Vec_IntStart( Abc_NtkObjNumMax(pNtk) );
67  pSwitching = (float *)vSwitching->pArray;
68  Abc_NtkForEachCi( pNtk, pNode, i )
69  {
70  pSimInfo = (unsigned *)Vec_PtrEntry(vSimInfo, pNode->Id);
71  Sim_UtilSetRandom( pSimInfo, nSimWords );
72  pSwitching[pNode->Id] = Sim_ComputeSwitching( pSimInfo, nSimWords );
73  }
74  // simulate the internal nodes
75  vNodes = Abc_AigDfs( pNtk, 1, 0 );
76  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
77  {
78  pSimInfo = (unsigned *)Vec_PtrEntry(vSimInfo, pNode->Id);
79  Sim_UtilSimulateNodeOne( pNode, vSimInfo, nSimWords, 0 );
80  pSwitching[pNode->Id] = Sim_ComputeSwitching( pSimInfo, nSimWords );
81  }
82  Vec_PtrFree( vNodes );
83  Sim_UtilInfoFree( vSimInfo );
84  return vSwitching;
85 }
86 
87 /**Function*************************************************************
88 
89  Synopsis [Computes switching activity of one node.]
90 
91  Description [Uses the formula: Switching = 2 * nOnes * nZeros / (nTotal ^ 2) ]
92 
93  SideEffects []
94 
95  SeeAlso []
96 
97 ***********************************************************************/
98 float Sim_ComputeSwitching( unsigned * pSimInfo, int nSimWords )
99 {
100  int nOnes, nTotal;
101  nTotal = 32 * nSimWords;
102  nOnes = Sim_UtilCountOnes( pSimInfo, nSimWords );
103  return (float)2.0 * nOnes / nTotal * (nTotal - nOnes) / nTotal;
104 }
105 
106 ////////////////////////////////////////////////////////////////////////
107 /// END OF FILE ///
108 ////////////////////////////////////////////////////////////////////////
109 
110 
112 
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
void Sim_UtilSetRandom(unsigned *pPatRand, int nSimWords)
Definition: simUtils.c:447
int Sim_UtilCountOnes(unsigned *pSimInfo, int nSimWords)
Definition: simUtils.c:402
static ABC_NAMESPACE_IMPL_START void Sim_NodeSimulate(Abc_Obj_t *pNode, Vec_Ptr_t *vSimInfo, int nSimWords)
DECLARATIONS ///.
void Sim_UtilInfoFree(Vec_Ptr_t *p)
Definition: simUtils.c:83
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
Vec_Ptr_t * Sim_UtilInfoAlloc(int nSize, int nWords, int fClean)
FUNCTION DEFINITIONS ///.
Definition: simUtils.c:57
void Sim_UtilSimulateNodeOne(Abc_Obj_t *pNode, Vec_Ptr_t *vSimInfo, int nSimWords, int nOffset)
Definition: simUtils.c:302
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static float Sim_ComputeSwitching(unsigned *pSimInfo, int nSimWords)
Definition: simSwitch.c:98
#define SIM_NUM_WORDS(n)
MACRO DEFINITIONS ///.
Definition: sim.h:148
Vec_Int_t * Sim_NtkComputeSwitching(Abc_Ntk_t *pNtk, int nPatterns)
FUNCTION DEFINITIONS ///.
Definition: simSwitch.c:52
ABC_DLL Vec_Ptr_t * Abc_AigDfs(Abc_Ntk_t *pNtk, int fCollectAll, int fCollectCos)
Definition: abcDfs.c:1014
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition: abc.h:515
int Id
Definition: abc.h:132
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
int nTotal
DECLARATIONS ///.
Definition: cutTruth.c:37
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223