Skip to content

Commit 7691e2e

Browse files
committed
Fixing a bug in &mfs when black boxes are present.
1 parent ee89928 commit 7691e2e

File tree

3 files changed

+92
-37
lines changed

3 files changed

+92
-37
lines changed

src/aig/gia/giaMfs.c

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ Gia_Man_t * Gia_ManInsertMfs( Gia_Man_t * p, Sfm_Ntk_t * pNtk, int fAllBoxes )
300300
Vec_Int_t * vArray, * vLeaves;
301301
Vec_Int_t * vMapping, * vMapping2;
302302
Vec_Int_t * vCoDrivers;
303+
Vec_Int_t * vPiBoxes = NULL;
304+
Vec_Int_t * vBbCiMap = NULL;
305+
Vec_Int_t * vBbOutLit = NULL;
303306
int nBbIns = 0, nBbOuts = 0;
304307
if ( pManTime ) Tim_ManBlackBoxIoNum( pManTime, &nBbIns, &nBbOuts );
305308
nMfsNodes = 1 + Gia_ManCiNum(p) + Gia_ManLutNum(p) + Gia_ManCoNum(p) + nBbIns + nBbOuts;
@@ -341,8 +344,36 @@ Gia_Man_t * Gia_ManInsertMfs( Gia_Man_t * p, Sfm_Ntk_t * pNtk, int fAllBoxes )
341344
assert( curCo == Gia_ManCoNum(p) );
342345

343346
// collect nodes in the given order
347+
if ( nBbOuts > 0 )
348+
{
349+
int iBbOut = 0;
350+
vPiBoxes = Vec_IntStartFull( nBbOuts + nRealPis );
351+
vBbCiMap = Vec_IntStartFull( Gia_ManCiNum(p) );
352+
vBbOutLit = Vec_IntStartFull( nBbOuts );
353+
curCi = nRealPis;
354+
curCo = 0;
355+
for ( i = 0; i < nBoxes; i++ )
356+
{
357+
nBoxIns = Tim_ManBoxInputNum( pManTime, i );
358+
nBoxOuts = Tim_ManBoxOutputNum( pManTime, i );
359+
if ( Tim_ManBoxIsBlack(pManTime, i) )
360+
for ( k = 0; k < nBoxOuts; k++ )
361+
{
362+
assert( iBbOut < nBbOuts );
363+
Vec_IntWriteEntry( vPiBoxes, iBbOut, i );
364+
Vec_IntWriteEntry( vBbCiMap, curCi + k, iBbOut );
365+
iBbOut++;
366+
}
367+
curCo += nBoxIns;
368+
curCi += nBoxOuts;
369+
}
370+
curCo += nRealPos;
371+
assert( curCi == Gia_ManCiNum(p) );
372+
assert( curCo == Gia_ManCoNum(p) );
373+
assert( iBbOut == nBbOuts );
374+
}
344375
vBoxesLeft = Vec_IntAlloc( nBoxes );
345-
vMfsTopo = Sfm_NtkDfs( pNtk, vGroups, vGroupMap, vBoxesLeft, fAllBoxes );
376+
vMfsTopo = Sfm_NtkDfs( pNtk, vGroups, vGroupMap, vBoxesLeft, fAllBoxes, vPiBoxes );
346377
Vec_IntUniqify( vBoxesLeft ); // reduce to sorted unique indices expected by the timing manager
347378
vBoxKeep = Vec_IntStart( nBoxes );
348379
Vec_IntForEachEntry( vBoxesLeft, iBox, i )
@@ -370,12 +401,18 @@ Gia_Man_t * Gia_ManInsertMfs( Gia_Man_t * p, Sfm_Ntk_t * pNtk, int fAllBoxes )
370401
{
371402
int iCiId = Gia_ObjId( p, pObj );
372403
int iBox = pManTime ? Tim_ManBoxForCi( pManTime, Gia_ObjCioId(pObj) ) : -1;
404+
int iBbOut = vBbCiMap ? Vec_IntEntry(vBbCiMap, i) : -1;
373405
if ( iBox >= 0 && !Vec_IntEntry(vBoxKeep, iBox) )
374406
{
375407
Vec_IntWriteEntry( vMfs2Gia, Gia_ObjCopyArray(p, iCiId), -1 );
408+
if ( iBbOut >= 0 && vBbOutLit )
409+
Vec_IntWriteEntry( vBbOutLit, iBbOut, -1 );
376410
continue;
377411
}
378-
Vec_IntWriteEntry( vMfs2Gia, Gia_ObjCopyArray(p, iCiId), Gia_ManAppendCi(pNew) );
412+
iLitNew = Gia_ManAppendCi(pNew);
413+
Vec_IntWriteEntry( vMfs2Gia, Gia_ObjCopyArray(p, iCiId), iLitNew );
414+
if ( iBbOut >= 0 && vBbOutLit )
415+
Vec_IntWriteEntry( vBbOutLit, iBbOut, iLitNew );
379416
}
380417
// map internal nodes
381418
vLeaves = Vec_IntAlloc( 6 );
@@ -389,18 +426,20 @@ Gia_Man_t * Gia_ManInsertMfs( Gia_Man_t * p, Sfm_Ntk_t * pNtk, int fAllBoxes )
389426
if ( Vec_IntSize(vArray) == 1 && Vec_IntEntry(vArray,0) < nBbOuts ) // skip unreal inputs
390427
{
391428
assert( Abc_LitIsCompl(iGroup) );
392-
iLitNew = Vec_IntEntry( vMfs2Gia, iMfsId );
393-
if ( iLitNew == -1 )
394-
{
395-
iLitNew = Gia_ManAppendCi( pNew );
396-
Vec_IntWriteEntry( vMfs2Gia, iMfsId, iLitNew );
397-
}
429+
assert( vBbOutLit != NULL );
430+
iLitNew = Vec_IntEntry( vBbOutLit, Vec_IntEntry(vArray,0) );
431+
assert( iLitNew >= 0 );
432+
Vec_IntWriteEntry( vMfs2Gia, iMfsId, iLitNew );
398433
continue;
399434
}
400435
Vec_IntClear( vLeaves );
401436
Vec_IntForEachEntry( vArray, Fanin, k )
402437
{
403-
iLitNew = Vec_IntEntry( vMfs2Gia, Fanin ); assert( iLitNew >= 0 );
438+
if ( Fanin < nBbOuts )
439+
iLitNew = Vec_IntEntry( vBbOutLit, Fanin );
440+
else
441+
iLitNew = Vec_IntEntry( vMfs2Gia, Fanin );
442+
assert( iLitNew >= 0 );
404443
Vec_IntPush( vLeaves, iLitNew );
405444
}
406445
if ( iGroup == -1 ) // internal node
@@ -502,6 +541,9 @@ Gia_Man_t * Gia_ManInsertMfs( Gia_Man_t * p, Sfm_Ntk_t * pNtk, int fAllBoxes )
502541
Vec_IntFree( vBoxesLeft );
503542
Vec_IntFree( vBoxKeep );
504543
Vec_IntFree( vCoDrivers );
544+
Vec_IntFreeP( &vPiBoxes );
545+
Vec_IntFreeP( &vBbCiMap );
546+
Vec_IntFreeP( &vBbOutLit );
505547
return pNew;
506548
}
507549

src/opt/sfm/sfm.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ extern word * Sfm_NodeReadTruth( Sfm_Ntk_t * p, int i );
9595
extern int Sfm_NodeReadFixed( Sfm_Ntk_t * p, int i );
9696
extern int Sfm_NodeReadUsed( Sfm_Ntk_t * p, int i );
9797
/*=== sfmWin.c ==========================================================*/
98-
extern Vec_Int_t * Sfm_NtkDfs( Sfm_Ntk_t * p, Vec_Wec_t * vGroups, Vec_Int_t * vGroupMap, Vec_Int_t * vBoxesLeft, int fAllBoxes );
98+
extern Vec_Int_t * Sfm_NtkDfs( Sfm_Ntk_t * p, Vec_Wec_t * vGroups, Vec_Int_t * vGroupMap, Vec_Int_t * vBoxesLeft, int fAllBoxes, Vec_Int_t * vPiBoxes );
9999

100100

101101
ABC_NAMESPACE_HEADER_END
@@ -105,4 +105,3 @@ ABC_NAMESPACE_HEADER_END
105105
////////////////////////////////////////////////////////////////////////
106106
/// END OF FILE ///
107107
////////////////////////////////////////////////////////////////////////
108-

src/opt/sfm/sfmWin.c

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -133,37 +133,52 @@ static inline int Sfm_ObjIsTravIdCurrent2( Sfm_Ntk_t * p, int Id ) { return
133133
SeeAlso []
134134
135135
***********************************************************************/
136-
void Sfm_NtkDfs_rec( Sfm_Ntk_t * p, int iNode, Vec_Int_t * vNodes, Vec_Wec_t * vGroups, Vec_Int_t * vGroupMap, Vec_Int_t * vBoxesLeft )
136+
static void Sfm_NtkDfs_rec( Sfm_Ntk_t * p, int iNode, Vec_Int_t * vNodes, Vec_Wec_t * vGroups, Vec_Int_t * vGroupMap, Vec_Int_t * vBoxesLeft, Vec_Int_t * vPiBoxes );
137+
static void Sfm_NtkDfsVisitGroup( Sfm_Ntk_t * p, int iGroup, Vec_Int_t * vNodes, Vec_Wec_t * vGroups, Vec_Int_t * vGroupMap, Vec_Int_t * vBoxesLeft, Vec_Int_t * vPiBoxes )
137138
{
138-
int i, iFanin;
139-
if ( Sfm_ObjIsPi(p, iNode) )
140-
return;
139+
int i, iFanin, k, Obj;
140+
Vec_Int_t * vGroup = Vec_WecEntry( vGroups, iGroup );
141+
Vec_IntForEachEntry( vGroup, Obj, i )
142+
assert( Sfm_ObjIsNode(p, Obj) );
143+
Vec_IntForEachEntry( vGroup, Obj, i )
144+
Sfm_ObjSetTravIdCurrent( p, Obj );
145+
Vec_IntForEachEntry( vGroup, Obj, i )
146+
Sfm_ObjForEachFanin( p, Obj, iFanin, k )
147+
Sfm_NtkDfs_rec( p, iFanin, vNodes, vGroups, vGroupMap, vBoxesLeft, vPiBoxes );
148+
Vec_IntForEachEntry( vGroup, Obj, i )
149+
Vec_IntPush( vNodes, Obj );
150+
Vec_IntPush( vBoxesLeft, iGroup );
151+
}
152+
static void Sfm_NtkDfs_rec( Sfm_Ntk_t * p, int iNode, Vec_Int_t * vNodes, Vec_Wec_t * vGroups, Vec_Int_t * vGroupMap, Vec_Int_t * vBoxesLeft, Vec_Int_t * vPiBoxes )
153+
{
154+
int i, iFanin, iGroup;
141155
if ( Sfm_ObjIsTravIdCurrent(p, iNode) )
142156
return;
143-
if ( Vec_IntEntry(vGroupMap, iNode) >= 0 )
157+
iGroup = Vec_IntEntry(vGroupMap, iNode);
158+
if ( iGroup >= 0 )
144159
{
145-
int k, iGroup = Abc_Lit2Var( Vec_IntEntry(vGroupMap, iNode) );
146-
Vec_Int_t * vGroup = Vec_WecEntry( vGroups, iGroup );
147-
Vec_IntForEachEntry( vGroup, iNode, i )
148-
assert( Sfm_ObjIsNode(p, iNode) );
149-
Vec_IntForEachEntry( vGroup, iNode, i )
150-
Sfm_ObjSetTravIdCurrent( p, iNode );
151-
Vec_IntForEachEntry( vGroup, iNode, i )
152-
Sfm_ObjForEachFanin( p, iNode, iFanin, k )
153-
Sfm_NtkDfs_rec( p, iFanin, vNodes, vGroups, vGroupMap, vBoxesLeft );
154-
Vec_IntForEachEntry( vGroup, iNode, i )
155-
Vec_IntPush( vNodes, iNode );
156-
Vec_IntPush( vBoxesLeft, iGroup );
160+
Sfm_NtkDfsVisitGroup( p, Abc_Lit2Var(iGroup), vNodes, vGroups, vGroupMap, vBoxesLeft, vPiBoxes );
161+
return;
157162
}
158-
else
163+
if ( Sfm_ObjIsPi(p, iNode) )
159164
{
160-
Sfm_ObjSetTravIdCurrent(p, iNode);
161-
Sfm_ObjForEachFanin( p, iNode, iFanin, i )
162-
Sfm_NtkDfs_rec( p, iFanin, vNodes, vGroups, vGroupMap, vBoxesLeft );
163-
Vec_IntPush( vNodes, iNode );
165+
if ( vPiBoxes && iNode < Vec_IntSize(vPiBoxes) )
166+
{
167+
int iBox = Vec_IntEntry( vPiBoxes, iNode );
168+
if ( iBox >= 0 )
169+
{
170+
Sfm_ObjSetTravIdCurrent( p, iNode );
171+
Sfm_NtkDfsVisitGroup( p, iBox, vNodes, vGroups, vGroupMap, vBoxesLeft, vPiBoxes );
172+
}
173+
}
174+
return;
164175
}
176+
Sfm_ObjSetTravIdCurrent(p, iNode);
177+
Sfm_ObjForEachFanin( p, iNode, iFanin, i )
178+
Sfm_NtkDfs_rec( p, iFanin, vNodes, vGroups, vGroupMap, vBoxesLeft, vPiBoxes );
179+
Vec_IntPush( vNodes, iNode );
165180
}
166-
Vec_Int_t * Sfm_NtkDfs( Sfm_Ntk_t * p, Vec_Wec_t * vGroups, Vec_Int_t * vGroupMap, Vec_Int_t * vBoxesLeft, int fAllBoxes )
181+
Vec_Int_t * Sfm_NtkDfs( Sfm_Ntk_t * p, Vec_Wec_t * vGroups, Vec_Int_t * vGroupMap, Vec_Int_t * vBoxesLeft, int fAllBoxes, Vec_Int_t * vPiBoxes )
167182
{
168183
Vec_Int_t * vNodes;
169184
int i;
@@ -174,10 +189,10 @@ Vec_Int_t * Sfm_NtkDfs( Sfm_Ntk_t * p, Vec_Wec_t * vGroups, Vec_Int_t * vGroupMa
174189
{
175190
Vec_Int_t * vGroup;
176191
Vec_WecForEachLevel( vGroups, vGroup, i )
177-
Sfm_NtkDfs_rec( p, Vec_IntEntry(vGroup, 0), vNodes, vGroups, vGroupMap, vBoxesLeft );
192+
Sfm_NtkDfs_rec( p, Vec_IntEntry(vGroup, 0), vNodes, vGroups, vGroupMap, vBoxesLeft, vPiBoxes );
178193
}
179194
Sfm_NtkForEachPo( p, i )
180-
Sfm_NtkDfs_rec( p, Sfm_ObjFanin(p, i, 0), vNodes, vGroups, vGroupMap, vBoxesLeft );
195+
Sfm_NtkDfs_rec( p, Sfm_ObjFanin(p, i, 0), vNodes, vGroups, vGroupMap, vBoxesLeft, vPiBoxes );
181196
return vNodes;
182197
}
183198

@@ -478,4 +493,3 @@ void Sfm_NtkWindowTest( Sfm_Ntk_t * p, int iNode )
478493

479494

480495
ABC_NAMESPACE_IMPL_END
481-

0 commit comments

Comments
 (0)