Skip to content

Commit b50fd7a

Browse files
committed
Adding support for not merging some flops after &scorr.
1 parent 367b407 commit b50fd7a

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

src/aig/gia/giaIf.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,11 +2842,12 @@ void Gia_ManTransferTiming( Gia_Man_t * p, Gia_Man_t * pGia )
28422842
}
28432843
if ( pGia->pManTime == NULL )
28442844
return;
2845-
p->pManTime = pGia->pManTime; pGia->pManTime = NULL;
2846-
p->pAigExtra = pGia->pAigExtra; pGia->pAigExtra = NULL;
2847-
p->vRegClasses = pGia->vRegClasses; pGia->vRegClasses = NULL;
2848-
p->vRegInits = pGia->vRegInits; pGia->vRegInits = NULL;
2849-
p->nAnd2Delay = pGia->nAnd2Delay; pGia->nAnd2Delay = 0;
2845+
p->pManTime = pGia->pManTime; pGia->pManTime = NULL;
2846+
p->pAigExtra = pGia->pAigExtra; pGia->pAigExtra = NULL;
2847+
p->vRegClasses = pGia->vRegClasses; pGia->vRegClasses = NULL;
2848+
p->vRegInits = pGia->vRegInits; pGia->vRegInits = NULL;
2849+
p->vFlopClasses = pGia->vFlopClasses; pGia->vFlopClasses = NULL;
2850+
p->nAnd2Delay = pGia->nAnd2Delay; pGia->nAnd2Delay = 0;
28502851
}
28512852

28522853
/**Function*************************************************************

src/aig/gia/giaSweep.c

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ int * Gia_ManFraigSelectReprs( Gia_Man_t * p, Gia_Man_t * pClp, int fVerbose, in
483483
int * pReprs = ABC_FALLOC( int, Gia_ManObjNum(p) );
484484
int * pClp2Gia = ABC_FALLOC( int, Gia_ManObjNum(pClp) );
485485
int i, iLitClp, iLitClp2, iReprClp, fCompl;
486-
int nConsts = 0, nReprs = 0;
486+
int nConsts = 0, nReprs = 0, nSkipped = 0;
487487
assert( pManTime != NULL );
488488
// count the number of equivalent objects
489489
Gia_ManForEachObj1( pClp, pObj, i )
@@ -549,9 +549,53 @@ int * Gia_ManFraigSelectReprs( Gia_Man_t * p, Gia_Man_t * pClp, int fVerbose, in
549549
if ( pClp2Gia[iReprClp] == -1 )
550550
pClp2Gia[iReprClp] = i;
551551
else
552-
{
552+
{
553553
iLitClp2 = Gia_ObjValue( Gia_ManObj(p, pClp2Gia[iReprClp]) );
554554
assert( Gia_ObjReprSelf(pClp, Abc_Lit2Var(iLitClp)) == Gia_ObjReprSelf(pClp, Abc_Lit2Var(iLitClp2)) );
555+
556+
// Check vFlopClasses restrictions if both are flops
557+
// vFlopClasses specifies which flops can be merged:
558+
// - Class 0: unmergeable flops (never merge)
559+
// - Class N>0: flops in group N (can merge within same group)
560+
// - NULL: no restrictions (all flops can be merged)
561+
if ( p->vFlopClasses && Gia_ObjIsCi(pObj) )
562+
{
563+
// In unnormalized AIGs (used during &scorr with boxes):
564+
// CIs are ordered as: PIs + FlopOutputs
565+
// BoxOutputs are spread through the AIG as internal nodes
566+
int iFlopCur = -1, iFlopRepr = -1;
567+
int nPis = Gia_ManPiNum(p);
568+
int nFlops = Gia_ManRegBoxNum(p);
569+
570+
// Check if current object is a flop output
571+
// In unnormalized AIG: flop outputs are CIs from nPis to nPis+nFlops
572+
if ( i >= nPis && i < nPis + nFlops )
573+
iFlopCur = i - nPis;
574+
575+
// Check if representative is a flop output
576+
int iRepr = pClp2Gia[iReprClp];
577+
if ( iRepr >= nPis && iRepr < nPis + nFlops )
578+
iFlopRepr = iRepr - nPis;
579+
580+
// Apply merging restrictions
581+
if ( iFlopCur >= 0 && iFlopRepr >= 0 )
582+
{
583+
// Make sure indices are valid
584+
assert( iFlopCur < Vec_IntSize(p->vFlopClasses) );
585+
assert( iFlopRepr < Vec_IntSize(p->vFlopClasses) );
586+
587+
int ClassCur = Vec_IntEntry(p->vFlopClasses, iFlopCur);
588+
int ClassRepr = Vec_IntEntry(p->vFlopClasses, iFlopRepr);
589+
590+
// Skip merging if classes don't match or class is 0 (unmergeable)
591+
if ( ClassCur == 0 || ClassRepr == 0 || ClassCur != ClassRepr )
592+
{
593+
nSkipped++;
594+
continue; // Skip this merging
595+
}
596+
}
597+
}
598+
555599
fCompl = Abc_LitIsCompl(iLitClp) ^ Abc_LitIsCompl(iLitClp2);
556600
fCompl ^= Gia_ManObj(pClp, Abc_Lit2Var(iLitClp))->fPhase;
557601
fCompl ^= Gia_ManObj(pClp, Abc_Lit2Var(iLitClp2))->fPhase;
@@ -567,7 +611,11 @@ int * Gia_ManFraigSelectReprs( Gia_Man_t * p, Gia_Man_t * pClp, int fVerbose, in
567611
Gia_ManForEachCi( p, pObj, i )
568612
pObj->fMark0 = 0;
569613
if ( fVerbose )
614+
{
570615
printf( "Found %d const objects and %d other objects.\n", nConsts, nReprs );
616+
if ( p->vFlopClasses && nSkipped > 0 )
617+
printf( "Skipped %d flop mergings due to vFlopClasses restrictions.\n", nSkipped );
618+
}
571619
return pReprs;
572620
}
573621

0 commit comments

Comments
 (0)