Commit 0f8b68ae by Alan Mishchenko

Performance bug fix in SOP balancing.

parent 360c705f
...@@ -404,7 +404,7 @@ Hop_Obj_t * Abc_NodeTruthToHop( Hop_Man_t * pMan, If_Man_t * p, If_Cut_t * pCut ...@@ -404,7 +404,7 @@ Hop_Obj_t * Abc_NodeTruthToHop( Hop_Man_t * pMan, If_Man_t * p, If_Cut_t * pCut
Vec_Wrd_t * vArray; Vec_Wrd_t * vArray;
vArray = If_CutDelaySopArray( p, pCut ); vArray = If_CutDelaySopArray( p, pCut );
pResult = Abc_NodeTruthToHopInt( pMan, vArray, If_CutLeaveNum(pCut) ); pResult = Abc_NodeTruthToHopInt( pMan, vArray, If_CutLeaveNum(pCut) );
Vec_WrdFree( vArray ); // Vec_WrdFree( vArray );
return pResult; return pResult;
} }
......
...@@ -165,6 +165,11 @@ struct If_Man_t_ ...@@ -165,6 +165,11 @@ struct If_Man_t_
int nChoices; // the number of choice nodes int nChoices; // the number of choice nodes
Vec_Int_t * vSwitching; // switching activity of each node Vec_Int_t * vSwitching; // switching activity of each node
Vec_Int_t ** pDriverCuts; // temporary driver cuts Vec_Int_t ** pDriverCuts; // temporary driver cuts
// SOP balancing
Vec_Int_t * vCover; // used to compute ISOP
Vec_Wrd_t * vAnds; // intermediate storage
Vec_Wrd_t * vOrGate; // intermediate storage
Vec_Wrd_t * vAndGate; // intermediate storage
// sequential mapping // sequential mapping
Vec_Ptr_t * vLatchOrder; // topological ordering of latches Vec_Ptr_t * vLatchOrder; // topological ordering of latches
Vec_Int_t * vLags; // sequentail lags of all nodes Vec_Int_t * vLags; // sequentail lags of all nodes
......
...@@ -149,6 +149,10 @@ void If_ManStop( If_Man_t * p ) ...@@ -149,6 +149,10 @@ void If_ManStop( If_Man_t * p )
Vec_PtrFree( p->vObjs ); Vec_PtrFree( p->vObjs );
// Vec_PtrFree( p->vMapped ); // Vec_PtrFree( p->vMapped );
Vec_PtrFree( p->vTemp ); Vec_PtrFree( p->vTemp );
Vec_IntFreeP( &p->vCover );
Vec_WrdFreeP( &p->vAnds );
Vec_WrdFreeP( &p->vAndGate );
Vec_WrdFreeP( &p->vOrGate );
if ( p->vObjsRev ) Vec_PtrFree( p->vObjsRev ); if ( p->vObjsRev ) Vec_PtrFree( p->vObjsRev );
if ( p->vLatchOrder ) Vec_PtrFree( p->vLatchOrder ); if ( p->vLatchOrder ) Vec_PtrFree( p->vLatchOrder );
if ( p->vLags ) Vec_IntFree( p->vLags ); if ( p->vLags ) Vec_IntFree( p->vLags );
......
...@@ -166,35 +166,34 @@ If_And_t If_CutDelaySopCube( Vec_Wrd_t * vCube, Vec_Wrd_t * vAnds, int fOrGate ) ...@@ -166,35 +166,34 @@ If_And_t If_CutDelaySopCube( Vec_Wrd_t * vCube, Vec_Wrd_t * vAnds, int fOrGate )
***********************************************************************/ ***********************************************************************/
Vec_Wrd_t * If_CutDelaySopAnds( If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vCover, int fCompl ) Vec_Wrd_t * If_CutDelaySopAnds( If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vCover, int fCompl )
{ {
Vec_Wrd_t * vAnds, * vAndGate, * vOrGate;
If_Obj_t * pLeaf; If_Obj_t * pLeaf;
If_And_t Leaf; If_And_t Leaf;
int i, k, Entry, Literal; int i, k, Entry, Literal;
vAnds = Vec_WrdAlloc( 32 ); Vec_WrdClear( p->vAnds );
if ( Vec_IntSize(vCover) == 0 ) // const 0 if ( Vec_IntSize(vCover) == 0 ) // const 0
{ {
assert( fCompl == 0 ); assert( fCompl == 0 );
return vAnds; return p->vAnds;
} }
if ( Vec_IntSize(vCover) == 1 && Vec_IntEntry(vCover, 0) == 0 ) // const 1 if ( Vec_IntSize(vCover) == 1 && Vec_IntEntry(vCover, 0) == 0 ) // const 1
{ {
assert( fCompl == 0 ); assert( fCompl == 0 );
Vec_WrdPush( vAnds, 0 ); Vec_WrdPush( p->vAnds, 0 );
return vAnds; return p->vAnds;
} }
If_CutForEachLeaf( p, pCut, pLeaf, k ) If_CutForEachLeaf( p, pCut, pLeaf, k )
{ {
If_AndClear( &Leaf ); If_AndClear( &Leaf );
Leaf.Id = k; Leaf.Id = k;
Leaf.Delay = (int)If_ObjCutBest(pLeaf)->Delay; Leaf.Delay = (int)If_ObjCutBest(pLeaf)->Delay;
Vec_WrdPush( vAnds, If_AndToWrd(Leaf) ); Vec_WrdPush( p->vAnds, If_AndToWrd(Leaf) );
} }
// iterate through the cubes // iterate through the cubes
vOrGate = Vec_WrdAlloc( 16 ); Vec_WrdClear( p->vOrGate );
vAndGate = Vec_WrdAlloc( 16 ); Vec_WrdClear( p->vAndGate );
Vec_IntForEachEntry( vCover, Entry, i ) Vec_IntForEachEntry( vCover, Entry, i )
{ {
Vec_WrdClear( vAndGate ); Vec_WrdClear( p->vAndGate );
If_CutForEachLeaf( p, pCut, pLeaf, k ) If_CutForEachLeaf( p, pCut, pLeaf, k )
{ {
Literal = 3 & (Entry >> (k << 1)); Literal = 3 & (Entry >> (k << 1));
...@@ -204,39 +203,37 @@ Vec_Wrd_t * If_CutDelaySopAnds( If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vCove ...@@ -204,39 +203,37 @@ Vec_Wrd_t * If_CutDelaySopAnds( If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vCove
Leaf.fCompl = 1; Leaf.fCompl = 1;
Leaf.Id = k; Leaf.Id = k;
Leaf.Delay = (int)If_ObjCutBest(pLeaf)->Delay; Leaf.Delay = (int)If_ObjCutBest(pLeaf)->Delay;
If_AndInsertSorted( vAndGate, Leaf ); If_AndInsertSorted( p->vAndGate, Leaf );
} }
else if ( Literal == 2 ) // pos literal else if ( Literal == 2 ) // pos literal
{ {
If_AndClear( &Leaf ); If_AndClear( &Leaf );
Leaf.Id = k; Leaf.Id = k;
Leaf.Delay = (int)If_ObjCutBest(pLeaf)->Delay; Leaf.Delay = (int)If_ObjCutBest(pLeaf)->Delay;
If_AndInsertSorted( vAndGate, Leaf ); If_AndInsertSorted( p->vAndGate, Leaf );
} }
else if ( Literal != 0 ) else if ( Literal != 0 )
assert( 0 ); assert( 0 );
} }
Leaf = If_CutDelaySopCube( vAndGate, vAnds, 0 ); Leaf = If_CutDelaySopCube( p->vAndGate, p->vAnds, 0 );
If_AndInsertSorted( vOrGate, Leaf ); If_AndInsertSorted( p->vOrGate, Leaf );
} }
Leaf = If_CutDelaySopCube( vOrGate, vAnds, 1 ); Leaf = If_CutDelaySopCube( p->vOrGate, p->vAnds, 1 );
Vec_WrdFree( vAndGate ); if ( Vec_WrdSize(p->vAnds) == (int)pCut->nLeaves )
Vec_WrdFree( vOrGate );
if ( Vec_WrdSize(vAnds) == (int)pCut->nLeaves )
{ {
// Extra_PrintBinary( stdout, If_CutTruth(pCut), 32 ); printf( "\n" ); // Extra_PrintBinary( stdout, If_CutTruth(pCut), 32 ); printf( "\n" );
assert( Leaf.Id < pCut->nLeaves ); assert( Leaf.Id < pCut->nLeaves );
Leaf.iFan0 = Leaf.iFan1 = Leaf.Id; Leaf.iFan0 = Leaf.iFan1 = Leaf.Id;
Leaf.Id = Vec_WrdSize(vAnds); Leaf.Id = Vec_WrdSize(p->vAnds);
Vec_WrdPush( vAnds, If_AndToWrd(Leaf) ); Vec_WrdPush( p->vAnds, If_AndToWrd(Leaf) );
} }
if ( fCompl ) if ( fCompl )
{ {
Leaf = If_WrdToAnd( Vec_WrdPop(vAnds) ); Leaf = If_WrdToAnd( Vec_WrdPop(p->vAnds) );
Leaf.fCompl ^= 1; Leaf.fCompl ^= 1;
Vec_WrdPush( vAnds, If_AndToWrd(Leaf) ); Vec_WrdPush( p->vAnds, If_AndToWrd(Leaf) );
} }
return vAnds; return p->vAnds;
} }
/**Function************************************************************* /**Function*************************************************************
...@@ -252,18 +249,21 @@ Vec_Wrd_t * If_CutDelaySopAnds( If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vCove ...@@ -252,18 +249,21 @@ Vec_Wrd_t * If_CutDelaySopAnds( If_Man_t * p, If_Cut_t * pCut, Vec_Int_t * vCove
***********************************************************************/ ***********************************************************************/
Vec_Wrd_t * If_CutDelaySopArray( If_Man_t * p, If_Cut_t * pCut ) Vec_Wrd_t * If_CutDelaySopArray( If_Man_t * p, If_Cut_t * pCut )
{ {
Vec_Int_t * vCover;
Vec_Wrd_t * vAnds; Vec_Wrd_t * vAnds;
int RetValue; int RetValue;
vCover = Vec_IntAlloc(0); if ( p->vCover == NULL )
RetValue = Kit_TruthIsop( If_CutTruth(pCut), If_CutLeaveNum(pCut), vCover, 1 );
if ( RetValue == -1 )
{ {
Vec_IntFree( vCover ); p->vCover = Vec_IntAlloc(0);
return NULL; p->vAnds = Vec_WrdAlloc(100);
p->vAndGate = Vec_WrdAlloc(100);
p->vOrGate = Vec_WrdAlloc(100);
} }
RetValue = Kit_TruthIsop( If_CutTruth(pCut), If_CutLeaveNum(pCut), p->vCover, 1 );
if ( RetValue == -1 )
return NULL;
assert( RetValue == 0 || RetValue == 1 ); assert( RetValue == 0 || RetValue == 1 );
vAnds = If_CutDelaySopAnds( p, pCut, vCover, RetValue ^ pCut->fCompl ); vAnds = If_CutDelaySopAnds( p, pCut, p->vCover, RetValue ^ pCut->fCompl );
/* /*
if ( pCut->nLeaves <= 5 ) if ( pCut->nLeaves <= 5 )
{ {
...@@ -289,7 +289,6 @@ Vec_Wrd_t * If_CutDelaySopArray( If_Man_t * p, If_Cut_t * pCut ) ...@@ -289,7 +289,6 @@ Vec_Wrd_t * If_CutDelaySopArray( If_Man_t * p, If_Cut_t * pCut )
// printf( "Verification passed for %d vars.\n", pCut->nLeaves ); // printf( "Verification passed for %d vars.\n", pCut->nLeaves );
} }
*/ */
Vec_IntFree( vCover );
return vAnds; return vAnds;
} }
...@@ -386,7 +385,6 @@ int If_CutDelaySopCost( If_Man_t * p, If_Cut_t * pCut ) ...@@ -386,7 +385,6 @@ int If_CutDelaySopCost( If_Man_t * p, If_Cut_t * pCut )
Delay = If_CutDelayLeafDepth( vAnds, i ); Delay = If_CutDelayLeafDepth( vAnds, i );
pCut->pPerm[i] = (char)(Delay == -IF_BIG_CHAR ? IF_BIG_CHAR : Delay); pCut->pPerm[i] = (char)(Delay == -IF_BIG_CHAR ? IF_BIG_CHAR : Delay);
} }
// Vec_WrdFree( vAnds );
// verify the delay // verify the delay
// Delay = If_CutDelay( p, pObj, pCut ); // Delay = If_CutDelay( p, pObj, pCut );
// assert( (int)Leaf.Delay == Delay ); // assert( (int)Leaf.Delay == Delay );
......
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