abc/src/map/if/ifDsd.c
// checks if there is a way to package some fanins 
checks if there is a way to package some fanins
checks if there is a way to package some fanins
unsigned If_DsdManCheckPrime( If_DsdMan_t * p, int iFirst, unsigned uMaskNot, If_DsdObj_t * pObj, int nSuppAll, int LutSize, int fDerive, int fVerbose )
{
    int i, v, set, LimitOut, SizeIn, SizeOut, pSSizes[DAU_MAX_VAR], pFirsts[DAU_MAX_VAR];
    int truthId = If_DsdObjTruthId(p, pObj);
    int nFans = If_DsdObjFaninNum(pObj);
    Vec_Int_t * vSets = (Vec_Int_t *)Vec_PtrEntry(p->vTtDecs[pObj->nFans], truthId);
if ( fVerbose )
printf( "\n" );
if ( fVerbose )
Dau_DecPrintSets( vSets, nFans );
    assert( If_DsdObjFaninNum(pObj) > 2 );
    assert( If_DsdObjSuppSize(pObj) > LutSize );
    If_DsdManGetSuppSizes( p, pObj, pSSizes );
    LimitOut = LutSize - (nSuppAll - If_DsdObjSuppSize(pObj) + 1);
    assert( LimitOut < LutSize );
    Vec_IntForEachEntry( vSets, set, i )
    {
        SizeIn = SizeOut = 0;
        for ( v = 0; v < nFans; v++ )
        {
            int Value = ((set >> (v << 1)) & 3);
            if ( Value == 0 )
                SizeOut += pSSizes[v];
            else if ( Value == 1 )
                SizeIn += pSSizes[v];
            else if ( Value == 3 )
            {
                SizeIn += pSSizes[v];
                SizeOut += pSSizes[v];
            }
            else assert( 0 );
            if ( SizeIn > LutSize || SizeOut > LimitOut )
                break;
        }
        if ( v == nFans )
        {
            unsigned uRes = 0;
            if ( !fDerive )
                return ~0;
            If_DsdManComputeFirst( p, pObj, pFirsts );
            for ( v = 0; v < nFans; v++ )
            {
                int Value = ((set >> (v << 1)) & 3);
                if ( Value == 0 )
                {}
                else if ( Value == 1 )
                    uRes |= If_DsdSign(p, pObj, v, iFirst + pFirsts[v], 0);
                else if ( Value == 3 )
                    uRes |= If_DsdSign(p, pObj, v, iFirst + pFirsts[v], 1);
                else assert( 0 );
            }
            if ( uRes & uMaskNot )
                continue;
            return uRes;
        }
    }
    return 0;
}
unsigned If_DsdManCheckPrime ( If_DsdMan_t * p , int iFirst , unsigned uMaskNot , If_DsdObj_t * pObj , int nSuppAll , int LutSize , int fDerive , int fVerbose ) { int i , v , set , LimitOut , SizeIn , SizeOut , pSSizes [ DAU_MAX_VAR ] , pFirsts [ DAU_MAX_VAR ] ; int truthId = If_DsdObjTruthId ( p , pObj ) ; int nFans = If_DsdObjFaninNum ( pObj ) ; Vec_Int_t * vSets = ( Vec_Int_t * ) Vec_PtrEntry ( p -> vTtDecs [ pObj -> nFans ] , truthId ) ; if ( fVerbose ) printf ( " \n " ) ; if ( fVerbose ) Dau_DecPrintSets ( vSets , nFans ) ; assert ( If_DsdObjFaninNum ( pObj ) > 2 ) ; assert ( If_DsdObjSuppSize ( pObj ) > LutSize ) ; If_DsdManGetSuppSizes ( p , pObj , pSSizes ) ; LimitOut = LutSize - ( nSuppAll - If_DsdObjSuppSize ( pObj ) + 1 ) ; assert ( LimitOut < LutSize ) ; Vec_IntForEachEntry ( vSets , set , i ) { SizeIn = SizeOut = 0 ; for ( v = 0 ; v < nFans ; v ++ ) { int Value = ( ( set >> ( v << 1 ) ) & 3 ) ; if ( Value == 0 ) SizeOut += pSSizes [ v ] ; else if ( Value == 1 ) SizeIn += pSSizes [ v ] ; else if ( Value == 3 ) { SizeIn += pSSizes [ v ] ; SizeOut += pSSizes [ v ] ; } else assert ( 0 ) ; if ( SizeIn > LutSize || SizeOut > LimitOut ) break ; } if ( v == nFans ) { unsigned uRes = 0 ; if ( ! fDerive ) return ~ 0 ; If_DsdManComputeFirst ( p , pObj , pFirsts ) ; for ( v = 0 ; v < nFans ; v ++ ) { int Value = ( ( set >> ( v << 1 ) ) & 3 ) ; if ( Value == 0 ) { } else if ( Value == 1 ) uRes |= If_DsdSign ( p , pObj , v , iFirst + pFirsts [ v ] , 0 ) ; else if ( Value == 3 ) uRes |= If_DsdSign ( p , pObj , v , iFirst + pFirsts [ v ] , 1 ) ; else assert ( 0 ) ; } if ( uRes & uMaskNot ) continue ; return uRes ; } } return 0 ; }
checks if there is a way to package some fanins
checks if there is a way to package some fanins