Skip to content

Commit 7f64516

Browse files
committed
Fix to maintain correct order of boxes after "&mfs".
1 parent ba85259 commit 7f64516

File tree

1 file changed

+44
-26
lines changed

1 file changed

+44
-26
lines changed

src/aig/gia/giaMfs.c

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,16 @@ Gia_Man_t * Gia_ManInsertMfs( Gia_Man_t * p, Sfm_Ntk_t * pNtk, int fAllBoxes )
290290
int nBoxes = Gia_ManBoxNum(p);
291291
int nRealPis = nBoxes ? Tim_ManPiNum(pManTime) : Gia_ManPiNum(p);
292292
int nRealPos = nBoxes ? Tim_ManPoNum(pManTime) : Gia_ManPoNum(p);
293-
int i, k, Id, curCi, curCo, nBoxIns, nBoxOuts, iLitNew, iMfsId, iGroup, Fanin;
293+
int i, k, curCi, curCo, nBoxIns, nBoxOuts, iLitNew, iMfsId, iGroup, Fanin, iBox;
294294
int nMfsNodes;
295295
word * pTruth, uTruthVar = ABC_CONST(0xAAAAAAAAAAAAAAAA);
296296
Vec_Wec_t * vGroups = Vec_WecStart( nBoxes );
297297
Vec_Int_t * vMfs2Gia, * vMfs2Old;
298298
Vec_Int_t * vGroupMap;
299-
Vec_Int_t * vMfsTopo, * vCover, * vBoxesLeft;
299+
Vec_Int_t * vMfsTopo, * vCover, * vBoxesLeft, * vBoxKeep;
300300
Vec_Int_t * vArray, * vLeaves;
301301
Vec_Int_t * vMapping, * vMapping2;
302+
Vec_Int_t * vCoDrivers;
302303
int nBbIns = 0, nBbOuts = 0;
303304
if ( pManTime ) Tim_ManBlackBoxIoNum( pManTime, &nBbIns, &nBbOuts );
304305
nMfsNodes = 1 + Gia_ManCiNum(p) + Gia_ManLutNum(p) + Gia_ManCoNum(p) + nBbIns + nBbOuts;
@@ -342,6 +343,10 @@ Gia_Man_t * Gia_ManInsertMfs( Gia_Man_t * p, Sfm_Ntk_t * pNtk, int fAllBoxes )
342343
// collect nodes in the given order
343344
vBoxesLeft = Vec_IntAlloc( nBoxes );
344345
vMfsTopo = Sfm_NtkDfs( pNtk, vGroups, vGroupMap, vBoxesLeft, fAllBoxes );
346+
Vec_IntUniqify( vBoxesLeft ); // reduce to sorted unique indices expected by the timing manager
347+
vBoxKeep = Vec_IntStart( nBoxes );
348+
Vec_IntForEachEntry( vBoxesLeft, iBox, i )
349+
Vec_IntWriteEntry( vBoxKeep, iBox, 1 );
345350
assert( Vec_IntSize(vBoxesLeft) <= nBoxes );
346351
assert( Vec_IntSize(vMfsTopo) > 0 );
347352

@@ -360,24 +365,36 @@ Gia_Man_t * Gia_ManInsertMfs( Gia_Man_t * p, Sfm_Ntk_t * pNtk, int fAllBoxes )
360365

361366
// map constant
362367
Vec_IntWriteEntry( vMfs2Gia, Gia_ObjCopyArray(p, 0), 0 );
363-
// map primary inputs
364-
Gia_ManForEachCiId( p, Id, i )
365-
if ( i < nRealPis )
366-
Vec_IntWriteEntry( vMfs2Gia, Gia_ObjCopyArray(p, Id), Gia_ManAppendCi(pNew) );
368+
// map primary inputs (real ones and preserved box outputs)
369+
Gia_ManForEachCi( p, pObj, i )
370+
{
371+
int iCiId = Gia_ObjId( p, pObj );
372+
int iBox = pManTime ? Tim_ManBoxForCi( pManTime, Gia_ObjCioId(pObj) ) : -1;
373+
if ( iBox >= 0 && !Vec_IntEntry(vBoxKeep, iBox) )
374+
{
375+
Vec_IntWriteEntry( vMfs2Gia, Gia_ObjCopyArray(p, iCiId), -1 );
376+
continue;
377+
}
378+
Vec_IntWriteEntry( vMfs2Gia, Gia_ObjCopyArray(p, iCiId), Gia_ManAppendCi(pNew) );
379+
}
367380
// map internal nodes
368381
vLeaves = Vec_IntAlloc( 6 );
369382
vCover = Vec_IntAlloc( 1 << 16 );
383+
vCoDrivers = Vec_IntStartFull( Gia_ManCoNum(p) );
370384
Vec_IntForEachEntry( vMfsTopo, iMfsId, i )
371385
{
372386
pTruth = Sfm_NodeReadTruth( pNtk, iMfsId );
373387
iGroup = Vec_IntEntry( vGroupMap, iMfsId );
374388
vArray = Sfm_NodeReadFanins( pNtk, iMfsId ); // belongs to pNtk
375389
if ( Vec_IntSize(vArray) == 1 && Vec_IntEntry(vArray,0) < nBbOuts ) // skip unreal inputs
376390
{
377-
// create CI for the output of black box
378391
assert( Abc_LitIsCompl(iGroup) );
379-
iLitNew = Gia_ManAppendCi( pNew );
380-
Vec_IntWriteEntry( vMfs2Gia, iMfsId, iLitNew );
392+
iLitNew = Vec_IntEntry( vMfs2Gia, iMfsId );
393+
if ( iLitNew == -1 )
394+
{
395+
iLitNew = Gia_ManAppendCi( pNew );
396+
Vec_IntWriteEntry( vMfs2Gia, iMfsId, iLitNew );
397+
}
381398
continue;
382399
}
383400
Vec_IntClear( vLeaves );
@@ -411,36 +428,36 @@ Gia_Man_t * Gia_ManInsertMfs( Gia_Man_t * p, Sfm_Ntk_t * pNtk, int fAllBoxes )
411428
Abc_TtFlipVar5( pTruth, Vec_IntSize(vLeaves) );
412429
}
413430
}
414-
else if ( Abc_LitIsCompl(iGroup) ) // internal CI
431+
else if ( Abc_LitIsCompl(iGroup) ) // internal CI (box output)
415432
{
416-
//Dau_DsdPrintFromTruth( pTruth, Vec_IntSize(vLeaves) );
417-
iLitNew = Gia_ManAppendCi( pNew );
433+
iLitNew = Vec_IntEntry( vMfs2Gia, iMfsId );
434+
if ( iLitNew < 0 )
435+
continue;
418436
}
419437
else // internal CO
420438
{
439+
int iObjOld = Vec_IntEntry( vMfs2Old, iMfsId );
440+
int iCoIdx;
441+
assert( iObjOld >= 0 );
421442
assert( pTruth[0] == uTruthVar || pTruth[0] == ~uTruthVar );
422-
iLitNew = Gia_ManAppendCo( pNew, Abc_LitNotCond(Vec_IntEntry(vLeaves, 0), pTruth[0] == ~uTruthVar) );
423-
//printf("Group = %d. po = %d\n", iGroup>>1, iMfsId );
443+
iLitNew = Abc_LitNotCond( Vec_IntEntry(vLeaves, 0), pTruth[0] == ~uTruthVar );
444+
iCoIdx = Gia_ObjCioId( Gia_ManObj(p, iObjOld) );
445+
Vec_IntWriteEntry( vCoDrivers, iCoIdx, iLitNew );
424446
}
425447
Vec_IntWriteEntry( vMfs2Gia, iMfsId, iLitNew );
426448
}
427449
Vec_IntFree( vCover );
428450
Vec_IntFree( vLeaves );
429451

430-
// map primary outputs
452+
// map primary outputs (internal box inputs followed by real POs)
431453
Gia_ManForEachCo( p, pObj, i )
432454
{
433-
if ( i < Gia_ManCoNum(p) - nRealPos ) // internal COs
455+
if ( i < Gia_ManCoNum(p) - nRealPos )
434456
{
435-
iMfsId = Gia_ObjCopyArray( p, Gia_ObjId(p, pObj) );
436-
iGroup = Vec_IntEntry( vGroupMap, iMfsId );
437-
if ( Vec_IntFind(vMfsTopo, iGroup) >= 0 )
438-
{
439-
iLitNew = Vec_IntEntry( vMfs2Gia, iMfsId );
440-
if ( iLitNew < 0 )
441-
continue;
442-
assert( iLitNew >= 0 );
443-
}
457+
iLitNew = Vec_IntEntry( vCoDrivers, i );
458+
if ( iLitNew == -1 )
459+
continue;
460+
Gia_ManAppendCo( pNew, iLitNew );
444461
continue;
445462
}
446463
iLitNew = Vec_IntEntry( vMfs2Gia, Gia_ObjCopyArray(p, Gia_ObjFaninId0p(p, pObj)) );
@@ -483,6 +500,8 @@ Gia_Man_t * Gia_ManInsertMfs( Gia_Man_t * p, Sfm_Ntk_t * pNtk, int fAllBoxes )
483500
Vec_IntFree( vMfs2Gia );
484501
Vec_IntFree( vMfs2Old );
485502
Vec_IntFree( vBoxesLeft );
503+
Vec_IntFree( vBoxKeep );
504+
Vec_IntFree( vCoDrivers );
486505
return pNew;
487506
}
488507

@@ -550,4 +569,3 @@ Gia_Man_t * Gia_ManPerformMfs( Gia_Man_t * p, Sfm_Par_t * pPars )
550569
////////////////////////////////////////////////////////////////////////
551570

552571
ABC_NAMESPACE_IMPL_END
553-

0 commit comments

Comments
 (0)