Commit 4aa33e7d by Alan Mishchenko

Structural reparametrization.

parent b71d4425
...@@ -888,6 +888,7 @@ extern word Gia_ObjComputeTruthTable6( Gia_Man_t * p, Gia_Obj_t * ...@@ -888,6 +888,7 @@ extern word Gia_ObjComputeTruthTable6( Gia_Man_t * p, Gia_Obj_t *
extern void Gia_ObjCollectInternal( Gia_Man_t * p, Gia_Obj_t * pObj ); extern void Gia_ObjCollectInternal( Gia_Man_t * p, Gia_Obj_t * pObj );
extern unsigned * Gia_ObjComputeTruthTable( Gia_Man_t * p, Gia_Obj_t * pObj ); extern unsigned * Gia_ObjComputeTruthTable( Gia_Man_t * p, Gia_Obj_t * pObj );
extern void Gia_ObjComputeTruthTableStart( Gia_Man_t * p, int nVarsMax ); extern void Gia_ObjComputeTruthTableStart( Gia_Man_t * p, int nVarsMax );
extern void Gia_ObjComputeTruthTableStop( Gia_Man_t * p );
extern unsigned * Gia_ObjComputeTruthTableCut( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vLeaves ); extern unsigned * Gia_ObjComputeTruthTableCut( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vLeaves );
/*=== giaTsim.c ============================================================*/ /*=== giaTsim.c ============================================================*/
extern Gia_Man_t * Gia_ManReduceConst( Gia_Man_t * pAig, int fVerbose ); extern Gia_Man_t * Gia_ManReduceConst( Gia_Man_t * pAig, int fVerbose );
......
...@@ -285,6 +285,15 @@ void Gia_ObjComputeTruthTableStart( Gia_Man_t * p, int nVarsMax ) ...@@ -285,6 +285,15 @@ void Gia_ObjComputeTruthTableStart( Gia_Man_t * p, int nVarsMax )
p->vTtInputs = Vec_PtrAllocTruthTables( p->nTtVars ); p->vTtInputs = Vec_PtrAllocTruthTables( p->nTtVars );
p->vTtMemory = Vec_WrdStart( p->nTtWords * 256 ); p->vTtMemory = Vec_WrdStart( p->nTtWords * 256 );
} }
void Gia_ObjComputeTruthTableStop( Gia_Man_t * p )
{
p->nTtVars = 0;
p->nTtWords = 0;
Vec_StrFreeP( &p->vTtNums );
Vec_IntFreeP( &p->vTtNodes );
Vec_PtrFreeP( &p->vTtInputs );
Vec_WrdFreeP( &p->vTtMemory );
}
/**Function************************************************************* /**Function*************************************************************
...@@ -303,7 +312,7 @@ unsigned * Gia_ObjComputeTruthTableCut( Gia_Man_t * p, Gia_Obj_t * pRoot, Vec_In ...@@ -303,7 +312,7 @@ unsigned * Gia_ObjComputeTruthTableCut( Gia_Man_t * p, Gia_Obj_t * pRoot, Vec_In
word * pTruth, * pTruthL, * pTruth0, * pTruth1; word * pTruth, * pTruthL, * pTruth0, * pTruth1;
int i; int i;
assert( p->vTtMemory != NULL ); assert( p->vTtMemory != NULL );
assert( p->nTtVars <= Vec_IntSize(vLeaves) ); assert( Vec_IntSize(vLeaves) <= p->nTtVars );
// collect internal nodes // collect internal nodes
Gia_ObjCollectInternalCut( p, pRoot, vLeaves ); Gia_ObjCollectInternalCut( p, pRoot, vLeaves );
// compute the truth table for internal nodes // compute the truth table for internal nodes
......
...@@ -26784,18 +26784,33 @@ usage: ...@@ -26784,18 +26784,33 @@ usage:
***********************************************************************/ ***********************************************************************/
int Abc_CommandAbc9Rpm( Abc_Frame_t * pAbc, int argc, char ** argv ) int Abc_CommandAbc9Rpm( Abc_Frame_t * pAbc, int argc, char ** argv )
{ {
extern Gia_Man_t * Abs_RpmPerform( Gia_Man_t * p, int nCutMax, int fVerbose ); extern Gia_Man_t * Abs_RpmPerform( Gia_Man_t * p, int nCutMax, int fVerbose, int fVeryVerbose );
Gia_Man_t * pTemp; Gia_Man_t * pTemp;
int nCutMax = 6; int c, nCutMax = 6;
int c, fVerbose = 0; int fVerbose = 0;
int fVeryVerbose = 0;
Extra_UtilGetoptReset(); Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF ) while ( ( c = Extra_UtilGetopt( argc, argv, "Cvwh" ) ) != EOF )
{ {
switch ( c ) switch ( c )
{ {
case 'C':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
goto usage;
}
nCutMax = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nCutMax < 0 )
goto usage;
break;
case 'v': case 'v':
fVerbose ^= 1; fVerbose ^= 1;
break; break;
case 'w':
fVeryVerbose ^= 1;
break;
case 'h': case 'h':
goto usage; goto usage;
default: default:
...@@ -26807,16 +26822,17 @@ int Abc_CommandAbc9Rpm( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -26807,16 +26822,17 @@ int Abc_CommandAbc9Rpm( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Print( -1, "Abc_CommandAbc9Rpm(): There is no AIG.\n" ); Abc_Print( -1, "Abc_CommandAbc9Rpm(): There is no AIG.\n" );
return 0; return 0;
} }
pTemp = Abs_RpmPerform( pAbc->pGia, nCutMax, fVerbose ); pTemp = Abs_RpmPerform( pAbc->pGia, nCutMax, fVerbose, fVeryVerbose );
if ( pTemp ) if ( pTemp )
Abc_CommandUpdate9( pAbc, pTemp ); Abc_CommandUpdate9( pAbc, pTemp );
return 0; return 0;
usage: usage:
Abc_Print( -2, "usage: &rpm [-K num] [-vh]\n" ); Abc_Print( -2, "usage: &rpm [-C num] [-vwh]\n" );
Abc_Print( -2, "\t performs structural reparametrization\n" ); Abc_Print( -2, "\t performs structural reparametrization\n" );
Abc_Print( -2, "\t-K num : the max cut size used for testing [default = %d]\n", nCutMax ); Abc_Print( -2, "\t-C num : max cut size for testing range equivalence [default = %d]\n", nCutMax );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-w : toggle printing more verbose information [default = %s]\n", fVeryVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n"); Abc_Print( -2, "\t-h : print the command usage\n");
return 1; return 1;
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
***********************************************************************/ ***********************************************************************/
#include "abs.h" #include "abs.h"
#include "misc/extra/extra.h"
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
...@@ -39,44 +40,6 @@ static int Abs_GiaObjRef_rec( Gia_Man_t * p, Gia_Obj_t * pNode ); ...@@ -39,44 +40,6 @@ static int Abs_GiaObjRef_rec( Gia_Man_t * p, Gia_Obj_t * pNode );
/**Function************************************************************* /**Function*************************************************************
Synopsis [Collects non-trivial internal dominators of the PIs.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Int_t * Gia_ManCollectDoms( Gia_Man_t * p )
{
Vec_Int_t * vNodes;
Gia_Obj_t * pObj;
int Lev, LevMax = 2;
int i, iDom, iDomNext;
vNodes = Vec_IntAlloc( 100 );
Gia_ManForEachObj( p, pObj, i )
{
if ( !pObj->fMark0 )
continue;
iDom = Gia_ObjDom(p, pObj);
if ( iDom == i )
continue;
for ( Lev = 0; Lev < LevMax && Gia_ObjIsAnd( Gia_ManObj(p, iDom) ); Lev++ )
{
Vec_IntPush( vNodes, iDom );
iDomNext = Gia_ObjDom( p, Gia_ManObj(p, iDom) );
if ( iDomNext == iDom )
break;
iDom = iDomNext;
}
}
Vec_IntUniqify( vNodes );
return vNodes;
}
/**Function*************************************************************
Synopsis [Computes one-node dominators.] Synopsis [Computes one-node dominators.]
Description [For each node, computes the closest one-node dominator, Description [For each node, computes the closest one-node dominator,
...@@ -131,7 +94,7 @@ void Gia_ManComputeDoms( Gia_Man_t * p ) ...@@ -131,7 +94,7 @@ void Gia_ManComputeDoms( Gia_Man_t * p )
{ {
if ( i == 0 || Gia_ObjIsCi(pObj) ) if ( i == 0 || Gia_ObjIsCi(pObj) )
continue; continue;
if ( pObj->fMark0 || (p->pRefs && Gia_ObjRefs(p, pObj) == 0) ) if ( pObj->fMark1 || (p->pRefs && Gia_ObjIsAnd(pObj) && Gia_ObjRefs(p, pObj) == 0) )
continue; continue;
if ( Gia_ObjIsCo(pObj) ) if ( Gia_ObjIsCo(pObj) )
{ {
...@@ -159,9 +122,9 @@ void Gia_ManTestDoms2( Gia_Man_t * p ) ...@@ -159,9 +122,9 @@ void Gia_ManTestDoms2( Gia_Man_t * p )
*/ */
Abc_PrintTime( 1, "Time", clock() - clk ); Abc_PrintTime( 1, "Time", clock() - clk );
// for each dominated PI, when if the PIs is in a leaf of the MFFC of the dominator // for each dominated PI, when if the PIs is in a leaf of the MFFC of the dominator
Gia_ManCleanMark0( p ); Gia_ManCleanMark1( p );
Gia_ManForEachPi( p, pObj, i ) Gia_ManForEachPi( p, pObj, i )
pObj->fMark0 = 1; pObj->fMark1 = 1;
vNodes = Vec_IntAlloc( 100 ); vNodes = Vec_IntAlloc( 100 );
Gia_ManCreateRefs( p ); Gia_ManCreateRefs( p );
Gia_ManForEachPi( p, pObj, i ) Gia_ManForEachPi( p, pObj, i )
...@@ -186,47 +149,76 @@ void Gia_ManTestDoms2( Gia_Man_t * p ) ...@@ -186,47 +149,76 @@ void Gia_ManTestDoms2( Gia_Man_t * p )
// printf( "Success.\n" ); // printf( "Success.\n" );
} }
Vec_IntFree( vNodes ); Vec_IntFree( vNodes );
Gia_ManCleanMark0( p ); Gia_ManCleanMark1( p );
} }
/**Function************************************************************* /**Function*************************************************************
Synopsis [Collect PI doms.] Synopsis [Collect PI doms.]
Description [Assumes that some PIs and ANDs are marked with fMark0.] Description [Assumes that some PIs and ANDs are marked with fMark1.]
SideEffects [] SideEffects []
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
Vec_Int_t * Gia_ManCollectDoms( Gia_Man_t * p )
{
Vec_Int_t * vNodes;
Gia_Obj_t * pObj;
int Lev, LevMax = ABC_INFINITY;
int i, iDom, iDomNext;
vNodes = Vec_IntAlloc( 100 );
Gia_ManForEachObj( p, pObj, i )
{
if ( !pObj->fMark1 )
continue;
iDom = Gia_ObjDom(p, pObj);
if ( iDom == -1 )
continue;
if ( iDom == i )
continue;
for ( Lev = 0; Lev < LevMax && Gia_ObjIsAnd( Gia_ManObj(p, iDom) ); Lev++ )
{
Vec_IntPush( vNodes, iDom );
iDomNext = Gia_ObjDom( p, Gia_ManObj(p, iDom) );
if ( iDomNext == iDom )
break;
iDom = iDomNext;
}
}
Vec_IntUniqify( vNodes );
return vNodes;
}
Vec_Int_t * Gia_ManComputePiDoms( Gia_Man_t * p ) Vec_Int_t * Gia_ManComputePiDoms( Gia_Man_t * p )
{ {
Vec_Int_t * vNodes; Vec_Int_t * vNodes;
Gia_ManComputeDoms( p ); Gia_ManComputeDoms( p );
vNodes = Gia_ManCollectDoms( p ); vNodes = Gia_ManCollectDoms( p );
// Vec_IntPrint( vNodes ); // Vec_IntPrint( vNodes );
printf( "Nodes = %d. Doms = %d.\n", Gia_ManAndNum(p), Vec_IntSize(vNodes) );
return vNodes; return vNodes;
} }
void Gia_ManTestDoms( Gia_Man_t * p ) void Gia_ManTestDoms( Gia_Man_t * p )
{ {
Vec_Int_t * vNodes; Vec_Int_t * vNodes;
Gia_Obj_t * pObj; Gia_Obj_t * pObj;
int i; int i;
assert( p->vDoms == NULL );
// mark PIs // mark PIs
Gia_ManCleanMark0( p ); // Gia_ManCreateRefs( p );
Gia_ManCleanMark1( p );
Gia_ManForEachPi( p, pObj, i ) Gia_ManForEachPi( p, pObj, i )
pObj->fMark0 = 1; pObj->fMark1 = 1;
// compute dominators // compute dominators
assert( p->vDoms == NULL );
vNodes = Gia_ManComputePiDoms( p ); vNodes = Gia_ManComputePiDoms( p );
// printf( "Nodes = %d. Doms = %d.\n", Gia_ManAndNum(p), Vec_IntSize(vNodes) );
Vec_IntFree( vNodes ); Vec_IntFree( vNodes );
// unmark PIs // unmark PIs
Gia_ManCleanMark0( p ); Gia_ManCleanMark1( p );
} }
/**Function************************************************************* /**Function*************************************************************
Synopsis [] Synopsis []
...@@ -243,7 +235,7 @@ void Gia_ManCountPisNodes_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vPis ...@@ -243,7 +235,7 @@ void Gia_ManCountPisNodes_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vPis
if ( Gia_ObjIsTravIdCurrent(p, pObj) ) if ( Gia_ObjIsTravIdCurrent(p, pObj) )
return; return;
Gia_ObjSetTravIdCurrent(p, pObj); Gia_ObjSetTravIdCurrent(p, pObj);
if ( pObj->fMark0 ) if ( pObj->fMark1 )
{ {
Vec_IntPush( vPis, Gia_ObjId(p, pObj) ); Vec_IntPush( vPis, Gia_ObjId(p, pObj) );
return; return;
...@@ -271,7 +263,7 @@ void Gia_ManCountPisNodes( Gia_Man_t * p, Vec_Int_t * vPis, Vec_Int_t * vAnds ) ...@@ -271,7 +263,7 @@ void Gia_ManCountPisNodes( Gia_Man_t * p, Vec_Int_t * vPis, Vec_Int_t * vAnds )
/**Function************************************************************* /**Function*************************************************************
Synopsis [] Synopsis [Computes support in terms of PIs and flops.]
Description [] Description []
...@@ -285,7 +277,7 @@ void Abs_ManSupport2_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vSupp ) ...@@ -285,7 +277,7 @@ void Abs_ManSupport2_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vSupp )
if ( Gia_ObjIsTravIdCurrent(p, pObj) ) if ( Gia_ObjIsTravIdCurrent(p, pObj) )
return; return;
Gia_ObjSetTravIdCurrent(p, pObj); Gia_ObjSetTravIdCurrent(p, pObj);
if ( pObj->fMark0 || Gia_ObjIsRo(p, pObj) ) if ( pObj->fMark1 || Gia_ObjIsRo(p, pObj) )
{ {
Vec_IntPush( vSupp, Gia_ObjId(p, pObj) ); Vec_IntPush( vSupp, Gia_ObjId(p, pObj) );
return; return;
...@@ -305,9 +297,9 @@ int Abs_ManSupport2( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vSupp ) ...@@ -305,9 +297,9 @@ int Abs_ManSupport2( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vSupp )
/**Function************************************************************* /**Function*************************************************************
Synopsis [] Synopsis [Computes support of the MFFC.]
Description [] Description [Should be called when pObj's cone is dereferenced.]
SideEffects [] SideEffects []
...@@ -319,7 +311,7 @@ void Abs_ManSupport_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vSupp ) ...@@ -319,7 +311,7 @@ void Abs_ManSupport_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vSupp )
if ( Gia_ObjIsTravIdCurrent(p, pObj) ) if ( Gia_ObjIsTravIdCurrent(p, pObj) )
return; return;
Gia_ObjSetTravIdCurrent(p, pObj); Gia_ObjSetTravIdCurrent(p, pObj);
if ( pObj->fMark0 || Gia_ObjIsRo(p, pObj) || Gia_ObjRefs(p, pObj) > 0 ) if ( pObj->fMark1 || Gia_ObjIsRo(p, pObj) || Gia_ObjRefs(p, pObj) > 0 )
{ {
Vec_IntPush( vSupp, Gia_ObjId(p, pObj) ); Vec_IntPush( vSupp, Gia_ObjId(p, pObj) );
return; return;
...@@ -335,6 +327,7 @@ int Abs_ManSupport( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vSupp ) ...@@ -335,6 +327,7 @@ int Abs_ManSupport( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vSupp )
Gia_ManIncrementTravId( p ); Gia_ManIncrementTravId( p );
Abs_ManSupport_rec( p, Gia_ObjFanin0(pObj), vSupp ); Abs_ManSupport_rec( p, Gia_ObjFanin0(pObj), vSupp );
Abs_ManSupport_rec( p, Gia_ObjFanin1(pObj), vSupp ); Abs_ManSupport_rec( p, Gia_ObjFanin1(pObj), vSupp );
Gia_ObjSetTravIdCurrent(p, pObj);
return Vec_IntSize(vSupp); return Vec_IntSize(vSupp);
} }
...@@ -353,7 +346,7 @@ int Abs_GiaObjDeref_rec( Gia_Man_t * p, Gia_Obj_t * pNode ) ...@@ -353,7 +346,7 @@ int Abs_GiaObjDeref_rec( Gia_Man_t * p, Gia_Obj_t * pNode )
{ {
Gia_Obj_t * pFanin; Gia_Obj_t * pFanin;
int Counter = 0; int Counter = 0;
if ( pNode->fMark0 || Gia_ObjIsRo(p, pNode) ) if ( pNode->fMark1 || Gia_ObjIsRo(p, pNode) )
return 0; return 0;
assert( Gia_ObjIsAnd(pNode) ); assert( Gia_ObjIsAnd(pNode) );
pFanin = Gia_ObjFanin0(pNode); pFanin = Gia_ObjFanin0(pNode);
...@@ -370,7 +363,7 @@ int Abs_GiaObjRef_rec( Gia_Man_t * p, Gia_Obj_t * pNode ) ...@@ -370,7 +363,7 @@ int Abs_GiaObjRef_rec( Gia_Man_t * p, Gia_Obj_t * pNode )
{ {
Gia_Obj_t * pFanin; Gia_Obj_t * pFanin;
int Counter = 0; int Counter = 0;
if ( pNode->fMark0 || Gia_ObjIsRo(p, pNode) ) if ( pNode->fMark1 || Gia_ObjIsRo(p, pNode) )
return 0; return 0;
assert( Gia_ObjIsAnd(pNode) ); assert( Gia_ObjIsAnd(pNode) );
pFanin = Gia_ObjFanin0(pNode); pFanin = Gia_ObjFanin0(pNode);
...@@ -401,7 +394,7 @@ int Abs_GiaSortNodes( Gia_Man_t * p, Vec_Int_t * vSupp ) ...@@ -401,7 +394,7 @@ int Abs_GiaSortNodes( Gia_Man_t * p, Vec_Int_t * vSupp )
Gia_ManForEachObjVec( vSupp, p, pObj, i ) Gia_ManForEachObjVec( vSupp, p, pObj, i )
if ( i < nSize && Gia_ObjRefs(p, pObj) == 0 && !Gia_ObjIsRo(p, pObj) ) // add removable leaves if ( i < nSize && Gia_ObjRefs(p, pObj) == 0 && !Gia_ObjIsRo(p, pObj) ) // add removable leaves
{ {
assert( pObj->fMark0 ); assert( pObj->fMark1 );
Vec_IntPush( vSupp, Gia_ObjId(p, pObj) ); Vec_IntPush( vSupp, Gia_ObjId(p, pObj) );
} }
RetValue = Vec_IntSize(vSupp) - nSize; RetValue = Vec_IntSize(vSupp) - nSize;
...@@ -418,7 +411,8 @@ int Abs_GiaSortNodes( Gia_Man_t * p, Vec_Int_t * vSupp ) ...@@ -418,7 +411,8 @@ int Abs_GiaSortNodes( Gia_Man_t * p, Vec_Int_t * vSupp )
Synopsis [Returns 1 if truth table has no const cofactors.] Synopsis [Returns 1 if truth table has no const cofactors.]
Description [] Description [The cofactoring variables are the (nSize-nSize0)
most significant vars. Each factors depends on nSize0 vars.]
SideEffects [] SideEffects []
...@@ -428,7 +422,8 @@ int Abs_GiaSortNodes( Gia_Man_t * p, Vec_Int_t * vSupp ) ...@@ -428,7 +422,8 @@ int Abs_GiaSortNodes( Gia_Man_t * p, Vec_Int_t * vSupp )
int Abs_GiaCheckTruth( word * pTruth, int nSize, int nSize0 ) int Abs_GiaCheckTruth( word * pTruth, int nSize, int nSize0 )
{ {
char * pStr = (char *)pTruth; char * pStr = (char *)pTruth;
int i, k, nSteps, nStr = (nSize >= 3 ? (1 << (nSize - 3)) : 1); int nStr = (nSize >= 3 ? (1 << (nSize - 3)) : 1);
int i, k, nSteps;
assert( nSize0 > 0 && nSize0 <= nSize ); assert( nSize0 > 0 && nSize0 <= nSize );
if ( nSize0 == 1 ) if ( nSize0 == 1 )
{ {
...@@ -440,8 +435,8 @@ int Abs_GiaCheckTruth( word * pTruth, int nSize, int nSize0 ) ...@@ -440,8 +435,8 @@ int Abs_GiaCheckTruth( word * pTruth, int nSize, int nSize0 )
if ( nSize0 == 2 ) if ( nSize0 == 2 )
{ {
for ( i = 0; i < nStr; i++ ) for ( i = 0; i < nStr; i++ )
if ( ((unsigned)pStr[i] & 0xF) == 0xF || (((unsigned)pStr[i] >> 4) & 0xF) == 0xF || if ( ((unsigned)pStr[i] & 0xF) == 0x0 || (((unsigned)pStr[i] >> 4) & 0xF) == 0x0 ||
((unsigned)pStr[i] & 0xF) == 0x0 || (((unsigned)pStr[i] >> 4) & 0xF) == 0x0 ) ((unsigned)pStr[i] & 0xF) == 0xF || (((unsigned)pStr[i] >> 4) & 0xF) == 0xF )
return 0; return 0;
return 1; return 1;
} }
...@@ -460,6 +455,7 @@ int Abs_GiaCheckTruth( word * pTruth, int nSize, int nSize0 ) ...@@ -460,6 +455,7 @@ int Abs_GiaCheckTruth( word * pTruth, int nSize, int nSize0 )
if ( k == nSteps ) if ( k == nSteps )
break; break;
} }
assert( i <= nStr );
return (int)( i == nStr ); return (int)( i == nStr );
} }
...@@ -474,108 +470,90 @@ int Abs_GiaCheckTruth( word * pTruth, int nSize, int nSize0 ) ...@@ -474,108 +470,90 @@ int Abs_GiaCheckTruth( word * pTruth, int nSize, int nSize0 )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Abs_RpmPerformMark( Gia_Man_t * p, int nCutMax, int fVerbose ) void Abs_RpmPerformMark( Gia_Man_t * p, int nCutMax, int fVerbose, int fVeryVerbose )
{ {
Vec_Int_t * vSupp, * vPis, * vAnds; Vec_Int_t * vSupp, * vPis, * vAnds, * vDoms;
Vec_Wrd_t * vTruths;
Gia_Obj_t * pObj; Gia_Obj_t * pObj;
word uTruth; word * pTruth;
int Iter, i, nSize0; int Iter, i, nSize0;
int fChanges = 1; int fHasConst, fChanges = 1;
Gia_ManCreateRefs( p ); Gia_ManCreateRefs( p );
Gia_ManCleanMark0( p ); Gia_ManCleanMark1( p );
Gia_ManForEachPi( p, pObj, i ) Gia_ManForEachPi( p, pObj, i )
pObj->fMark0 = 1; pObj->fMark1 = 1;
vPis = Vec_IntAlloc( 100 ); vPis = Vec_IntAlloc( 100 );
vAnds = Vec_IntAlloc( 100 ); vAnds = Vec_IntAlloc( 100 );
vSupp = Vec_IntAlloc( 100 ); vSupp = Vec_IntAlloc( 100 );
vTruths = Vec_WrdAlloc( 100 );
for ( Iter = 0; fChanges; Iter++ ) for ( Iter = 0; fChanges; Iter++ )
{ {
fChanges = 0;
vDoms = Gia_ManComputePiDoms( p );
// count the number of PIs and internal nodes // count the number of PIs and internal nodes
if ( fVerbose ) if ( fVerbose || fVeryVerbose )
{ {
Gia_ManCountPisNodes( p, vPis, vAnds ); Gia_ManCountPisNodes( p, vPis, vAnds );
printf( "Iter %3d : ", Iter ); printf( "Iter %3d : ", Iter );
printf( "PI = %5d ", Vec_IntSize(vPis) ); printf( "Dom = %5d (%6.2f %%) ", Vec_IntSize(vDoms), 100.0 * Vec_IntSize(vDoms) / Gia_ManAndNum(p) );
printf( "And = %6d ", Vec_IntSize(vAnds) ); printf( "PI = %5d (%6.2f %%) ", Vec_IntSize(vPis), 100.0 * Vec_IntSize(vPis) / Gia_ManPiNum(p) );
printf( "And = %6d (%6.2f %%) ", Vec_IntSize(vAnds), 100.0 * Vec_IntSize(vAnds) / Gia_ManAndNum(p) );
printf( "\n" ); printf( "\n" );
} }
fChanges = 0;
Gia_ManCleanMark1( p );
// pObj = Gia_ObjFanin0( Gia_ManPo(p, 1) ); // pObj = Gia_ObjFanin0( Gia_ManPo(p, 1) );
Gia_ManForEachAnd( p, pObj, i ) Gia_ManForEachObjVec( vDoms, p, pObj, i )
{ {
if ( pObj->fMark0 ) assert( !pObj->fMark1 );
continue; assert( Gia_ObjRefs( p, pObj ) > 0 );
if ( Gia_ObjRefs( p, pObj ) == 0 ) // dereference root node
continue;
if ( Gia_ObjFanin0(pObj)->fMark1 || Gia_ObjFanin1(pObj)->fMark1 )
{
pObj->fMark1 = 1;
continue;
}
// dereference nodes
Abs_GiaObjDeref_rec( p, pObj ); Abs_GiaObjDeref_rec( p, pObj );
// compute support
Abs_ManSupport( p, pObj, vSupp );
// check support size // check support size
if ( Vec_IntSize(vSupp) > nCutMax ) if ( Abs_ManSupport(p, pObj, vSupp) > nCutMax )
{ {
Abs_GiaObjRef_rec( p, pObj ); Abs_GiaObjRef_rec( p, pObj );
pObj->fMark1 = 1;
continue; continue;
} }
// order nodes by their ref counts // order nodes by their ref counts
nSize0 = Abs_GiaSortNodes( p, vSupp ); nSize0 = Abs_GiaSortNodes( p, vSupp );
// quit if there is no removable or too many assert( nSize0 > 0 && nSize0 <= nCutMax );
if ( nSize0 == 0 || nSize0 > nCutMax ) // check if truth table has const cofs
pTruth = (word *)Gia_ObjComputeTruthTableCut( p, pObj, vSupp );
fHasConst = !Abs_GiaCheckTruth( pTruth, Vec_IntSize(vSupp), nSize0 );
if ( fVeryVerbose )
{ {
Abs_GiaObjRef_rec( p, pObj ); printf( "Node = %8d Supp = %2d Supp0 = %2d Res = %4s ", Gia_ObjId(p, pObj), Vec_IntSize(vSupp), nSize0, fHasConst? "no":"yes" );
continue; Extra_PrintHex( stdout, (unsigned *)pTruth, Vec_IntSize(vSupp) ); printf( "\n" );
} }
if ( fHasConst )
// compute truth table
uTruth = Gia_ObjComputeTruthTable6( p, pObj, vSupp, vTruths );
// check if truth table has const cofs
if ( !Abs_GiaCheckTruth( &uTruth, Vec_IntSize(vSupp), nSize0 ) ) // has const
{ {
Abs_GiaObjRef_rec( p, pObj ); Abs_GiaObjRef_rec( p, pObj );
/*
if ( Iter == 1 )
{
printf( "Node = %8d Supp = %2d Supp0 = %2d ", Gia_ObjId(p, pObj), Vec_IntSize(vSupp), nSize0 );
Extra_PrintHex( stdout, &uTruth, Vec_IntSize(vSupp) );
printf( " no\n" );
}
*/
continue; continue;
} }
/*
printf( "Node = %8d Supp = %2d Supp0 = %2d ", Gia_ObjId(p, pObj), Vec_IntSize(vSupp), nSize0 );
Extra_PrintHex( stdout, &uTruth, Vec_IntSize(vSupp) );
printf( " yes\n" );
*/
// pObj can be reparamed // pObj can be reparamed
pObj->fMark0 = 1; pObj->fMark1 = 1;
fChanges = 1; fChanges = 1;
} }
Vec_IntFree( vDoms );
// break;
}
// count the number of PIs and internal nodes
if ( fVeryVerbose )
{
Gia_ManCountPisNodes( p, vPis, vAnds );
printf( "Iter %3d : ", Iter );
printf( "Dom = %5d (%6.2f %%) ", Vec_IntSize(vDoms), 100.0 * Vec_IntSize(vDoms) / Gia_ManAndNum(p) );
printf( "PI = %5d (%6.2f %%) ", Vec_IntSize(vPis), 100.0 * Vec_IntSize(vPis) / Gia_ManPiNum(p) );
printf( "And = %6d (%6.2f %%) ", Vec_IntSize(vAnds), 100.0 * Vec_IntSize(vAnds) / Gia_ManAndNum(p) );
printf( "\n" );
} }
Vec_IntFree( vPis ); Vec_IntFree( vPis );
Vec_IntFree( vAnds ); Vec_IntFree( vAnds );
Vec_IntFree( vSupp ); Vec_IntFree( vSupp );
Vec_WrdFree( vTruths );
ABC_FREE( p->pRefs ); ABC_FREE( p->pRefs );
// Gia_ManCleanMark0( p ); // temp // Gia_ManCleanMark1( p ); // temp
Gia_ManCleanMark1( p );
} }
/**Function************************************************************* /**Function*************************************************************
Synopsis [Assumed that fMark0 marks the internal PIs.] Synopsis [Assumed that fMark1 marks the internal PIs.]
Description [] Description []
...@@ -590,10 +568,12 @@ Gia_Man_t * Gia_ManDupRpm( Gia_Man_t * p ) ...@@ -590,10 +568,12 @@ Gia_Man_t * Gia_ManDupRpm( Gia_Man_t * p )
Gia_Man_t * pNew; Gia_Man_t * pNew;
Gia_Obj_t * pObj; Gia_Obj_t * pObj;
int i; int i;
// derive PIs and internal nodes
vPis = Vec_IntAlloc( 100 ); vPis = Vec_IntAlloc( 100 );
vAnds = Vec_IntAlloc( 100 ); vAnds = Vec_IntAlloc( 100 );
Gia_ManCountPisNodes( p, vPis, vAnds ); Gia_ManCountPisNodes( p, vPis, vAnds );
// duplicate AIG
Gia_ManFillValue( p ); Gia_ManFillValue( p );
pNew = Gia_ManStart( Gia_ManObjNum(p) ); pNew = Gia_ManStart( Gia_ManObjNum(p) );
pNew->pName = Abc_UtilStrsav( p->pName ); pNew->pName = Abc_UtilStrsav( p->pName );
...@@ -613,20 +593,35 @@ Gia_Man_t * Gia_ManDupRpm( Gia_Man_t * p ) ...@@ -613,20 +593,35 @@ Gia_Man_t * Gia_ManDupRpm( Gia_Man_t * p )
Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) ); Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
// cleanup
Vec_IntFree( vPis ); Vec_IntFree( vPis );
Vec_IntFree( vAnds ); Vec_IntFree( vAnds );
return pNew; return pNew;
} }
Gia_Man_t * Abs_RpmPerform( Gia_Man_t * p, int nCutMax, int fVerbose ) /**Function*************************************************************
Synopsis [Performs structural reparametrization.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Gia_Man_t * Abs_RpmPerform( Gia_Man_t * p, int nCutMax, int fVerbose, int fVeryVerbose )
{ {
Gia_Man_t * pNew; Gia_Man_t * pNew;
Gia_ObjComputeTruthTableStart( p, nCutMax );
// Gia_ManTestDoms( p ); // Gia_ManTestDoms( p );
// return NULL; // return NULL;
Abs_RpmPerformMark( p, nCutMax, 1 ); // perform structural analysis
Gia_ObjComputeTruthTableStart( p, nCutMax );
Abs_RpmPerformMark( p, nCutMax, fVerbose, fVeryVerbose );
Gia_ObjComputeTruthTableStop( p );
// derive new AIG
pNew = Gia_ManDupRpm( p ); pNew = Gia_ManDupRpm( p );
Gia_ManCleanMark0( p ); Gia_ManCleanMark1( p );
return pNew; return pNew;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment