abc/src/opt/lpk/lpkAbcDec.c
/**Function*************************************************************

  Synopsis    [Decomposes the function using recursive MUX decomposition.]

  Description [Returns the ID of the top-most decomposition node 
  implementing this function, or 0 if there is no decomposition satisfying
  the constraints on area and delay.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Decomposes the function using recursive MUX decomposition.]

Description [Returns the ID of the top-most decomposition node
implementing this function, or 0 if there is no decomposition satisfying
the constraints on area and delay.]




Function Synopsis [ Decomposes the function using recursive MUX decomposition . ] Description [ Returns the ID of the top - most decomposition node implementing this function or 0 if there is no decomposition satisfying the constraints on area and delay . ]
int Lpk_Decompose_rec( Lpk_Man_t * pMan, Lpk_Fun_t * p )
{
    Lpk_Res_t * pResMux, * pResDsd;
    Lpk_Fun_t * p2;
    abctime clk;
    assert( p->nLutK >= 3 && p->nLutK <= 6 );
    assert( p->nVars > p->nLutK );
    if ( Lpk_LutNumLuts(p->nVars, p->nLutK) > (int)p->nAreaLim )
        return 0;
    if ( Lpk_SuppDelay(p->uSupp, p->pDelays) > (int)p->nDelayLim )
        return 0;
    if ( !p->fSupports )
        Lpk_FunComputeCofSupps( p );
clk = Abc_Clock();
    pResDsd = Lpk_DsdAnalize( pMan, p, pMan->pPars->nVarsShared );
pMan->timeEvalDsdAn += Abc_Clock() - clk;
    if ( pResDsd && (pResDsd->nBSVars == (int)p->nLutK || pResDsd->nBSVars == (int)p->nLutK - 1) && 
          pResDsd->AreaEst <= (int)p->nAreaLim && pResDsd->DelayEst <= (int)p->nDelayLim )
    {
clk = Abc_Clock();
        p2 = Lpk_DsdSplit( pMan, p, pResDsd->pCofVars, pResDsd->nCofVars, pResDsd->BSVars );
pMan->timeEvalDsdSp += Abc_Clock() - clk;
        assert( p2->nVars <= (int)p->nLutK );
        if ( p->nVars > p->nLutK && !Lpk_Decompose_rec( pMan, p ) )
            return 0;
        return 1;
    }
clk = Abc_Clock();
    pResMux = Lpk_MuxAnalize( pMan, p );
pMan->timeEvalMuxAn += Abc_Clock() - clk;
    assert( !pResMux || (pResMux->DelayEst <= (int)p->nDelayLim && pResMux->AreaEst <= (int)p->nAreaLim) );
    if ( pResMux && pResMux->nSuppSizeS <= (int)p->nLutK && pResMux->nSuppSizeL <= (int)p->nLutK )
        pResDsd = NULL;
    else if ( pResMux && pResDsd )
    {
        if ( pResMux->AreaEst < pResDsd->AreaEst || 
            (pResMux->AreaEst == pResDsd->AreaEst && pResMux->nSuppSizeL < pResDsd->nSuppSizeL) || 
            (pResMux->AreaEst == pResDsd->AreaEst && pResMux->nSuppSizeL == pResDsd->nSuppSizeL && pResMux->DelayEst < pResDsd->DelayEst) )
            pResDsd = NULL;
        else
            pResMux = NULL;
    }
    assert( pResMux == NULL || pResDsd == NULL );
    if ( pResMux )
    {
clk = Abc_Clock();
        p2 = Lpk_MuxSplit( pMan, p, pResMux->Variable, pResMux->Polarity );
pMan->timeEvalMuxSp += Abc_Clock() - clk;
        if ( p2->nVars > p->nLutK && !Lpk_Decompose_rec( pMan, p2 ) )
            return 0;
        if ( p->nVars > p->nLutK && !Lpk_Decompose_rec( pMan, p ) )
            return 0;
        return 1;
    }
    if ( pResDsd )
    {
clk = Abc_Clock();
        p2 = Lpk_DsdSplit( pMan, p, pResDsd->pCofVars, pResDsd->nCofVars, pResDsd->BSVars );
pMan->timeEvalDsdSp += Abc_Clock() - clk;
        assert( p2->nVars <= (int)p->nLutK );
        if ( p->nVars > p->nLutK && !Lpk_Decompose_rec( pMan, p ) )
            return 0;
        return 1;
    }
    return 0;
}
int Lpk_Decompose_rec ( Lpk_Man_t * pMan , Lpk_Fun_t * p ) { Lpk_Res_t * pResMux , * pResDsd ; Lpk_Fun_t * p2 ; abctime clk ; assert ( p -> nLutK >= 3 && p -> nLutK <= 6 ) ; assert ( p -> nVars > p -> nLutK ) ; if ( Lpk_LutNumLuts ( p -> nVars , p -> nLutK ) > ( int ) p -> nAreaLim ) return 0 ; if ( Lpk_SuppDelay ( p -> uSupp , p -> pDelays ) > ( int ) p -> nDelayLim ) return 0 ; if ( ! p -> fSupports ) Lpk_FunComputeCofSupps ( p ) ; clk = Abc_Clock ( ) ; pResDsd = Lpk_DsdAnalize ( pMan , p , pMan -> pPars -> nVarsShared ) ; pMan -> timeEvalDsdAn += Abc_Clock ( ) - clk ; if ( pResDsd && ( pResDsd -> nBSVars == ( int ) p -> nLutK || pResDsd -> nBSVars == ( int ) p -> nLutK - 1 ) && pResDsd -> AreaEst <= ( int ) p -> nAreaLim && pResDsd -> DelayEst <= ( int ) p -> nDelayLim ) { clk = Abc_Clock ( ) ; p2 = Lpk_DsdSplit ( pMan , p , pResDsd -> pCofVars , pResDsd -> nCofVars , pResDsd -> BSVars ) ; pMan -> timeEvalDsdSp += Abc_Clock ( ) - clk ; assert ( p2 -> nVars <= ( int ) p -> nLutK ) ; if ( p -> nVars > p -> nLutK && ! Lpk_Decompose_rec ( pMan , p ) ) return 0 ; return 1 ; } clk = Abc_Clock ( ) ; pResMux = Lpk_MuxAnalize ( pMan , p ) ; pMan -> timeEvalMuxAn += Abc_Clock ( ) - clk ; assert ( ! pResMux || ( pResMux -> DelayEst <= ( int ) p -> nDelayLim && pResMux -> AreaEst <= ( int ) p -> nAreaLim ) ) ; if ( pResMux && pResMux -> nSuppSizeS <= ( int ) p -> nLutK && pResMux -> nSuppSizeL <= ( int ) p -> nLutK ) pResDsd = NULL ; else if ( pResMux && pResDsd ) { if ( pResMux -> AreaEst < pResDsd -> AreaEst || ( pResMux -> AreaEst == pResDsd -> AreaEst && pResMux -> nSuppSizeL < pResDsd -> nSuppSizeL ) || ( pResMux -> AreaEst == pResDsd -> AreaEst && pResMux -> nSuppSizeL == pResDsd -> nSuppSizeL && pResMux -> DelayEst < pResDsd -> DelayEst ) ) pResDsd = NULL ; else pResMux = NULL ; } assert ( pResMux == NULL || pResDsd == NULL ) ; if ( pResMux ) { clk = Abc_Clock ( ) ; p2 = Lpk_MuxSplit ( pMan , p , pResMux -> Variable , pResMux -> Polarity ) ; pMan -> timeEvalMuxSp += Abc_Clock ( ) - clk ; if ( p2 -> nVars > p -> nLutK && ! Lpk_Decompose_rec ( pMan , p2 ) ) return 0 ; if ( p -> nVars > p -> nLutK && ! Lpk_Decompose_rec ( pMan , p ) ) return 0 ; return 1 ; } if ( pResDsd ) { clk = Abc_Clock ( ) ; p2 = Lpk_DsdSplit ( pMan , p , pResDsd -> pCofVars , pResDsd -> nCofVars , pResDsd -> BSVars ) ; pMan -> timeEvalDsdSp += Abc_Clock ( ) - clk ; assert ( p2 -> nVars <= ( int ) p -> nLutK ) ; if ( p -> nVars > p -> nLutK && ! Lpk_Decompose_rec ( pMan , p ) ) return 0 ; return 1 ; } return 0 ; }
Function
Synopsis    [Decomposes the function using recursive MUX decomposition.]
Function Synopsis [ Decomposes the function using recursive MUX decomposition . ]
// is only called for non-trivial blocks // skip if area bound is exceeded // skip if delay bound is exceeded // compute supports if needed // check DSD decomposition // check MUX decomposition //    pResMux = NULL; // accept MUX decomposition if it is "good" // compare two decompositions