Adding API to compute switching activity

This commit is contained in:
Alan Mishchenko 2026-06-16 04:52:40 -07:00
parent 8783dcfd73
commit a4b7912895
2 changed files with 77 additions and 0 deletions

View File

@ -645,6 +645,7 @@ extern void Abc_SclTransferGates( Abc_Ntk_t * pOld, Abc_Ntk_t * pNew );
extern void Abc_SclPrintGateSizes( SC_Lib * pLib, Abc_Ntk_t * p );
extern void Abc_SclMinsizePerform( SC_Lib * pLib, Abc_Ntk_t * p, int fUseMax, int fVerbose );
extern int Abc_SclCountMinSize( SC_Lib * pLib, Abc_Ntk_t * p, int fUseMax );
extern Vec_Flt_t * Abc_SclComputeSwitching( Abc_Ntk_t * pNtk, int nFrames, int nPref );
extern Vec_Int_t * Abc_SclExtractBarBufs( Abc_Ntk_t * pNtk );
extern void Abc_SclInsertBarBufs( Abc_Ntk_t * pNtk, Vec_Int_t * vBufs );

View File

@ -21,6 +21,7 @@
#include "sclSize.h"
#include "map/mio/mio.h"
#include "base/main/main.h"
#include "aig/aig/aig.h"
ABC_NAMESPACE_IMPL_START
@ -275,6 +276,81 @@ void Abc_SclReadTimingConstr( Abc_Frame_t * pAbc, char * pFileName, int fVerbose
fclose( pFile );
}
/**Function*************************************************************
Synopsis [Computes switching activity for each object.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Flt_t * Abc_SclComputeSwitching( Abc_Ntk_t * pNtk, int nFrames, int nPref )
{
extern Aig_Man_t * Abc_NtkToDar( Abc_Ntk_t * pNtk, int fExors, int fRegisters );
extern Vec_Int_t * Saig_ManComputeSwitchProbs( Aig_Man_t * p, int nFrames, int nPref, int fProbOne );
Vec_Int_t * vSwitching = NULL;
Vec_Flt_t * vResult;
float * pSwitching, * pResult;
Abc_Ntk_t * pNtkDup = NULL, * pNtkStr = NULL;
Aig_Man_t * pAig = NULL;
Aig_Obj_t * pObjAig;
Abc_Obj_t * pObj, * pObjDup, * pObjStr;
int i;
vResult = Vec_FltStart( Abc_NtkObjNumMax(pNtk) );
pResult = Vec_FltArray(vResult);
pNtkDup = Abc_NtkDup( pNtk );
if ( pNtkDup == NULL )
goto cleanup;
// strash the duplicated network
pNtkStr = Abc_NtkStrash( pNtkDup, 0, 1, 0 );
if ( pNtkStr == NULL )
goto cleanup;
Abc_NtkForEachObj( pNtkDup, pObj, i )
if ( (pObj->pTemp && Abc_ObjRegular((Abc_Obj_t *)pObj->pTemp)->Type == ABC_FUNC_NONE) || (!Abc_ObjIsCi(pObj) && !Abc_ObjIsNode(pObj)) )
pObj->pTemp = NULL;
// map network into an AIG
pAig = Abc_NtkToDar( pNtkStr, 0, (int)(Abc_NtkLatchNum(pNtkDup) > 0) );
if ( pAig == NULL )
goto cleanup;
vSwitching = Saig_ManComputeSwitchProbs( pAig, nFrames, nPref, 0 );
if ( vSwitching == NULL )
goto cleanup;
pSwitching = (float *)Vec_IntArray(vSwitching);
Abc_NtkForEachObj( pNtk, pObj, i )
{
pObjDup = (Abc_Obj_t *)pObj->pCopy;
if ( pObjDup == NULL )
continue;
if ( pObjDup->pTemp == NULL )
continue;
pObjStr = Abc_ObjRegular((Abc_Obj_t *)pObjDup->pTemp);
if ( pObjStr == NULL )
continue;
if ( pObjStr->pTemp == NULL )
continue;
pObjAig = Aig_Regular((Aig_Obj_t *)pObjStr->pTemp);
if ( pObjAig == NULL )
continue;
pResult[pObj->Id] = pSwitching[pObjAig->Id];
}
cleanup:
Abc_NtkForEachObj( pNtk, pObj, i )
pObj->pCopy = NULL;
pNtk->pCopy = NULL;
if ( vSwitching )
Vec_IntFree( vSwitching );
if ( pAig )
Aig_ManStop( pAig );
if ( pNtkStr )
Abc_NtkDelete( pNtkStr );
if ( pNtkDup )
Abc_NtkDelete( pNtkDup );
return vResult;
}
/**Function*************************************************************
Synopsis []