summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2020-05-10 19:44:59 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2020-05-10 19:44:59 -0700
commita3ada00d8648a53bb43676d89d1ac2fa7cead948 (patch)
treef5922eaf00a69402a2112fcdbd5c3e0a71ae5145
parenta7871d24cdcd08c782a3165203ce3e4e76042344 (diff)
downloadabc-a3ada00d8648a53bb43676d89d1ac2fa7cead948.tar.gz
abc-a3ada00d8648a53bb43676d89d1ac2fa7cead948.tar.bz2
abc-a3ada00d8648a53bb43676d89d1ac2fa7cead948.zip
Adding new utility procedures.
-rw-r--r--src/base/acb/acb.h6
-rw-r--r--src/base/acb/acbFunc.c42
-rw-r--r--src/base/acb/acbUtil.c133
3 files changed, 172 insertions, 9 deletions
diff --git a/src/base/acb/acb.h b/src/base/acb/acb.h
index 9aed414c..cfe090bb 100644
--- a/src/base/acb/acb.h
+++ b/src/base/acb/acb.h
@@ -1019,6 +1019,12 @@ static inline void Acb_ManPrintStats( Acb_Man_t * p, int nModules, int fVerbose
extern Vec_Int_t * Acb_ObjCollectTfi( Acb_Ntk_t * p, int iObj, int fTerm );
extern Vec_Int_t * Acb_ObjCollectTfo( Acb_Ntk_t * p, int iObj, int fTerm );
+extern Vec_Int_t * Acb_ObjCollectTfiVec( Acb_Ntk_t * p, Vec_Int_t * vObjs );
+extern Vec_Int_t * Acb_ObjCollectTfoVec( Acb_Ntk_t * p, Vec_Int_t * vObjs );
+extern int Acb_NtkCountPiBuffers( Acb_Ntk_t * p, Vec_Int_t * vObjs );
+extern int Acb_NtkCountPoDrivers( Acb_Ntk_t * p, Vec_Int_t * vObjs );
+extern int Acb_NtkFindMffcSize( Acb_Ntk_t * p, Vec_Int_t * vObjs, int nGates[5] );
+
extern int Acb_ObjComputeLevelD( Acb_Ntk_t * p, int iObj );
extern int Acb_NtkComputeLevelD( Acb_Ntk_t * p, Vec_Int_t * vTfo );
extern void Acb_NtkUpdateLevelD( Acb_Ntk_t * p, int iObj );
diff --git a/src/base/acb/acbFunc.c b/src/base/acb/acbFunc.c
index 485a5e4e..4af33903 100644
--- a/src/base/acb/acbFunc.c
+++ b/src/base/acb/acbFunc.c
@@ -1897,6 +1897,14 @@ Vec_Ptr_t * Acb_GenerateSignalNames( Acb_Ntk_t * p, Vec_Int_t * vDivs, Vec_Int_t
Vec_StrFree( vStr );
return vRes;
}
+Vec_Int_t * Acb_GetUsedDivs( Vec_Int_t * vDivs, Vec_Int_t * vUsed )
+{
+ int i, iObj;
+ Vec_Int_t * vRes = Vec_IntAlloc( Vec_IntSize(vUsed) );
+ Vec_IntForEachEntryInVec( vDivs, vUsed, iObj, i )
+ Vec_IntPush( vRes, iObj );
+ return vRes;
+}
Vec_Str_t * Acb_GeneratePatch( Acb_Ntk_t * p, Vec_Int_t * vDivs, Vec_Int_t * vUsed, Vec_Ptr_t * vSops, Vec_Ptr_t * vGias, Vec_Int_t * vTars )
{
extern Vec_Wec_t * Abc_SopSynthesize( Vec_Ptr_t * vSops );
@@ -1904,10 +1912,16 @@ Vec_Str_t * Acb_GeneratePatch( Acb_Ntk_t * p, Vec_Int_t * vDivs, Vec_Int_t * vUs
Vec_Wec_t * vGates = vGias ? Abc_GiaSynthesize(vGias, NULL) : Abc_SopSynthesize(vSops); Vec_Int_t * vGate;
int nOuts = vGias ? Vec_PtrSize(vGias) : Vec_PtrSize(vSops);
int i, k, iObj, nWires = Vec_WecSize(vGates) - Vec_IntSize(vUsed) - nOuts, fFirst = 1;
+ int nGates[5] = {0}, nInvs = 0, nBufs = 0, nNodes = 0, nConst[2] = {0};
Vec_Ptr_t * vNames = Acb_GenerateSignalNames( p, vDivs, vUsed, nWires, vTars, vGates );
Vec_Str_t * vStr = Vec_StrAlloc( 100 );
-
- int nInvs = 0, nBufs = 0, nNodes = 0, nConst = 0;
+ Vec_Int_t * vSup = Acb_GetUsedDivs( vDivs, vUsed );
+ Vec_Int_t * vTfi = Acb_ObjCollectTfiVec( p, vSup );
+ Vec_Int_t * vTfo = Acb_ObjCollectTfoVec( p, vTars );
+ int nPiCount = Acb_NtkCountPiBuffers( p, vSup );
+ int nPoCount = Acb_NtkCountPoDrivers( p, vTars );
+ int nMffc = Acb_NtkFindMffcSize( p, vSup, nGates );
+ Vec_IntFree( vSup );
Vec_WecForEachLevelStartStop( vGates, vGate, i, Vec_IntSize(vUsed), Vec_IntSize(vUsed)+nWires )
{
if ( Vec_IntSize(vGate) > 2 )
@@ -1918,13 +1932,17 @@ Vec_Str_t * Acb_GeneratePatch( Acb_Ntk_t * p, Vec_Int_t * vDivs, Vec_Int_t * vUs
else if ( !strcmp(pName, "not") )
nInvs++;
else
- nNodes++;
+ nNodes += Vec_IntSize(vGate) - 3;
}
else
- nConst++;
+ nConst[Vec_IntEntry(vGate, 0) == ABC_OPER_CONST_T]++;
}
- Vec_StrPrintF( vStr, "// Patch statistics: in = %d out = %d gate = %d (const = %d buf = %d inv = %d other = %d)\n\n",
- Vec_IntSize(vUsed), nOuts, nWires, nConst, nBufs, nInvs, nNodes );
+
+ Vec_StrPrintF( vStr, "// Patch : in = %d out = %d : pi_in = %d po_out = %d : tfi = %d tfo = %d\n", Vec_IntSize(vUsed), nOuts, nPiCount, nPoCount, Vec_IntSize(vTfi), Vec_IntSize(vTfo) );
+ Vec_StrPrintF( vStr, "// Added : gate =%4d : c0 =%2d c1 =%2d buf =%3d inv =%3d two-input =%4d\n", nWires, nConst[0], nConst[1], nBufs, nInvs, nNodes );
+ Vec_StrPrintF( vStr, "// Removed : gate =%4d : c0 =%2d c1 =%2d buf =%3d inv =%3d two-input =%4d\n", nMffc, nGates[0], nGates[1], nGates[2], nGates[3], nGates[4] );
+ Vec_StrPrintF( vStr, "// TOTAL : gate =%4d : c0 =%2d c1 =%2d buf =%3d inv =%3d two-input =%4d\n\n", nWires-nMffc, nConst[0]-nGates[0], nConst[1]-nGates[1], nBufs-nGates[2], nInvs-nGates[3], nNodes-nGates[4] );
+
Vec_StrAppend( vStr, "module patch (" );
assert( Vec_IntSize(vTars) == nOuts );
@@ -1980,8 +1998,14 @@ Vec_Str_t * Acb_GeneratePatch( Acb_Ntk_t * p, Vec_Int_t * vDivs, Vec_Int_t * vUs
Vec_PtrFreeFree( vNames );
Vec_WecFree( vGates );
- printf( "Synthesized patch with %d inputs, %d outputs and %d gates (const = %d buf = %d inv = %d other = %d).\n",
- Vec_IntSize(vUsed), nOuts, nWires, nConst, nBufs, nInvs, nNodes );
+// printf( "Synthesized patch with %d inputs, %d outputs and %d gates (const = %d buf = %d inv = %d other = %d).\n",
+// Vec_IntSize(vUsed), nOuts, nWires, nConst, nBufs, nInvs, nNodes );
+// printf( "Summary of the results\n" );
+ printf( "\n" );
+ printf( "Patch : in = %d out = %d : pi_in = %d po_out = %d : tfi = %d tfo = %d\n", Vec_IntSize(vUsed), nOuts, nPiCount, nPoCount, Vec_IntSize(vTfi), Vec_IntSize(vTfo) );
+ printf( "Added : gate =%4d : c0 =%2d c1 =%2d buf =%3d inv =%3d two-input =%4d\n", nWires, nConst[0], nConst[1], nBufs, nInvs, nNodes );
+ printf( "Removed : gate =%4d : c0 =%2d c1 =%2d buf =%3d inv =%3d two-input =%4d\n", nMffc, nGates[0], nGates[1], nGates[2], nGates[3], nGates[4] );
+ printf( "TOTAL : gate =%4d : c0 =%2d c1 =%2d buf =%3d inv =%3d two-input =%4d\n", nWires-nMffc, nConst[0]-nGates[0], nConst[1]-nGates[1], nBufs-nGates[2], nInvs-nGates[3], nNodes-nGates[4] );
return vStr;
}
@@ -2479,7 +2503,7 @@ Vec_Ptr_t * Acb_TransformPatchFunctions( Vec_Ptr_t * vSops, Vec_Wec_t * vSupps,
Vec_IntWriteEntry( vMap, iVar, Vec_IntSize(vUsed) );
Vec_IntPush( vUsed, iVar );
}
- printf( "The number of used variables %d (out of %d).\n", Vec_IntSum(vPres), Vec_IntSize(vPres) );
+ //printf( "The number of used variables %d (out of %d).\n", Vec_IntSum(vPres), Vec_IntSize(vPres) );
// remap SOPs
Vec_WecForEachLevel( vSupps, vLevel, i )
{
diff --git a/src/base/acb/acbUtil.c b/src/base/acb/acbUtil.c
index 8a51bd3e..680dca12 100644
--- a/src/base/acb/acbUtil.c
+++ b/src/base/acb/acbUtil.c
@@ -71,6 +71,15 @@ Vec_Int_t * Acb_ObjCollectTfi( Acb_Ntk_t * p, int iObj, int fTerm )
Acb_ObjCollectTfi_rec( p, iObj, fTerm );
return &p->vArray0;
}
+Vec_Int_t * Acb_ObjCollectTfiVec( Acb_Ntk_t * p, Vec_Int_t * vObjs )
+{
+ int i, iObj;
+ Vec_IntClear( &p->vArray0 );
+ Acb_NtkIncTravId( p );
+ Vec_IntForEachEntry( vObjs, iObj, i )
+ Acb_ObjCollectTfi_rec( p, iObj, 0 );
+ return &p->vArray0;
+}
void Acb_ObjCollectTfo_rec( Acb_Ntk_t * p, int iObj, int fTerm )
{
@@ -95,6 +104,130 @@ Vec_Int_t * Acb_ObjCollectTfo( Acb_Ntk_t * p, int iObj, int fTerm )
Acb_ObjCollectTfo_rec( p, iObj, fTerm );
return &p->vArray1;
}
+Vec_Int_t * Acb_ObjCollectTfoVec( Acb_Ntk_t * p, Vec_Int_t * vObjs )
+{
+ int i, iObj;
+ if ( !Acb_NtkHasObjFanout(p) )
+ Acb_NtkCreateFanout( p );
+ Vec_IntClear( &p->vArray1 );
+ Acb_NtkIncTravId( p );
+ Vec_IntForEachEntry( vObjs, iObj, i )
+ Acb_ObjCollectTfo_rec( p, iObj, 0 );
+ return &p->vArray1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Count the number of nodes driving the POs.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Acb_NtkIsPiBuffers( Acb_Ntk_t * p, int iObj )
+{
+ if ( Acb_ObjIsCi(p, iObj) )
+ return 1;
+ if ( Acb_ObjFaninNum(p, iObj) != 1 )
+ return 0;
+ return Acb_NtkIsPiBuffers( p, Acb_ObjFanin(p, iObj, 0) );
+}
+int Acb_NtkCountPiBuffers( Acb_Ntk_t * p, Vec_Int_t * vObjs )
+{
+ int i, iObj, Count = 0;
+ Vec_IntForEachEntry( vObjs, iObj, i )
+ Count += Acb_NtkIsPiBuffers( p, iObj );
+ return Count;
+}
+int Acb_NtkCountPoDrivers( Acb_Ntk_t * p, Vec_Int_t * vObjs )
+{
+ int i, iObj, Count = 0;
+ Acb_NtkIncTravId( p );
+ Acb_NtkForEachCo( p, iObj, i )
+ Acb_ObjSetTravIdCur( p, iObj );
+ Acb_NtkForEachCo( p, iObj, i )
+ Acb_ObjSetTravIdCur( p, Acb_ObjFanin(p, iObj, 0) );
+ Vec_IntForEachEntry( vObjs, iObj, i )
+ Count += Acb_ObjIsTravIdCur(p, iObj);
+ return Count;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Compute MFFC size.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Acb_NtkNodeDeref_rec( Vec_Int_t * vRefs, Acb_Ntk_t * p, int iObj, int nGates[5] )
+{
+ int i, Fanin, * pFanins, Counter = 1;
+ if ( Acb_ObjIsCi(p, iObj) )
+ return 0;
+ if ( nGates )
+ {
+ int Type = Acb_ObjType( p, iObj );
+ if ( Type == ABC_OPER_CONST_F )
+ nGates[0]++;
+ if ( Type == ABC_OPER_CONST_T )
+ nGates[1]++;
+ if ( Type == ABC_OPER_BIT_BUF )
+ nGates[2]++;
+ if ( Type == ABC_OPER_BIT_INV )
+ nGates[3]++;
+ else
+ nGates[4] += Acb_ObjFaninNum(p, iObj)-1;
+ }
+ Acb_ObjForEachFaninFast( p, iObj, pFanins, Fanin, i )
+ {
+ assert( Vec_IntEntry(vRefs, Fanin) > 0 );
+ Vec_IntAddToEntry( vRefs, Fanin, -1 );
+ if ( Vec_IntEntry(vRefs, Fanin) == 0 )
+ Counter += Acb_NtkNodeDeref_rec( vRefs, p, Fanin, nGates );
+ }
+ return Counter;
+}
+int Acb_NtkNodeRef_rec( Vec_Int_t * vRefs, Acb_Ntk_t * p, int iObj )
+{
+ int i, Fanin, * pFanins, Counter = 1;
+ if ( Acb_ObjIsCi(p, iObj) )
+ return 0;
+ Acb_ObjForEachFaninFast( p, iObj, pFanins, Fanin, i )
+ {
+ if ( Vec_IntEntry(vRefs, Fanin) == 0 )
+ Counter += Acb_NtkNodeRef_rec( vRefs, p, Fanin );
+ Vec_IntAddToEntry( vRefs, Fanin, 1 );
+ }
+ return Counter;
+}
+int Acb_NtkFindMffcSize( Acb_Ntk_t * p, Vec_Int_t * vObjs, int nGates[5] )
+{
+ Vec_Int_t * vRefs = Vec_IntStart( Acb_NtkObjNumMax(p) );
+ int i, iObj, Fanin, * pFanins, Count1 = 0, Count2 = 0;
+ Acb_NtkForEachObj( p, iObj )
+ Acb_ObjForEachFaninFast( p, iObj, pFanins, Fanin, i )
+ Vec_IntAddToEntry( vRefs, Fanin, 1 );
+ //Vec_IntForEachEntry( vObjs, iObj, i )
+ // assert( Vec_IntEntry(vRefs, iObj) > 0 );
+ Vec_IntForEachEntry( vObjs, iObj, i )
+ Vec_IntAddToEntry( vRefs, iObj, 1 );
+ Vec_IntForEachEntry( vObjs, iObj, i )
+ Count1 += Acb_NtkNodeDeref_rec( vRefs, p, iObj, nGates );
+ Vec_IntForEachEntry( vObjs, iObj, i )
+ Count2 += Acb_NtkNodeRef_rec( vRefs, p, iObj );
+ Vec_IntForEachEntry( vObjs, iObj, i )
+ Vec_IntAddToEntry( vRefs, iObj, -1 );
+ assert( Count1 == Count2 );
+ Vec_IntFree( vRefs );
+ return Count1;
+}
/**Function*************************************************************