00001
00021 #include "abc.h"
00022 #include "sim.h"
00023
00027
00028 static void Sim_NodeSimulate( Abc_Obj_t * pNode, Vec_Ptr_t * vSimInfo, int nSimWords );
00029 static float Sim_ComputeSwitching( unsigned * pSimInfo, int nSimWords );
00030
00034
00049 Vec_Int_t * Sim_NtkComputeSwitching( Abc_Ntk_t * pNtk, int nPatterns )
00050 {
00051 Vec_Int_t * vSwitching;
00052 float * pSwitching;
00053 Vec_Ptr_t * vNodes;
00054 Vec_Ptr_t * vSimInfo;
00055 Abc_Obj_t * pNode;
00056 unsigned * pSimInfo;
00057 int nSimWords, i;
00058
00059
00060 nSimWords = SIM_NUM_WORDS(nPatterns);
00061 vSimInfo = Sim_UtilInfoAlloc( Abc_NtkObjNumMax(pNtk), nSimWords, 0 );
00062
00063 vSwitching = Vec_IntStart( Abc_NtkObjNumMax(pNtk) );
00064 pSwitching = (float *)vSwitching->pArray;
00065 Abc_NtkForEachCi( pNtk, pNode, i )
00066 {
00067 pSimInfo = Vec_PtrEntry(vSimInfo, pNode->Id);
00068 Sim_UtilSetRandom( pSimInfo, nSimWords );
00069 pSwitching[pNode->Id] = Sim_ComputeSwitching( pSimInfo, nSimWords );
00070 }
00071
00072 vNodes = Abc_AigDfs( pNtk, 1, 0 );
00073 Vec_PtrForEachEntry( vNodes, pNode, i )
00074 {
00075 pSimInfo = Vec_PtrEntry(vSimInfo, pNode->Id);
00076 Sim_UtilSimulateNodeOne( pNode, vSimInfo, nSimWords, 0 );
00077 pSwitching[pNode->Id] = Sim_ComputeSwitching( pSimInfo, nSimWords );
00078 }
00079 Vec_PtrFree( vNodes );
00080 Sim_UtilInfoFree( vSimInfo );
00081 return vSwitching;
00082 }
00083
00095 float Sim_ComputeSwitching( unsigned * pSimInfo, int nSimWords )
00096 {
00097 int nOnes, nTotal;
00098 nTotal = 32 * nSimWords;
00099 nOnes = Sim_UtilCountOnes( pSimInfo, nSimWords );
00100 return (float)2.0 * nOnes * (nTotal - nOnes) / nTotal / nTotal;
00101 }
00102
00106
00107