sbdPath.c 6.27 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/**CFile****************************************************************

  FileName    [sbdPath.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [SAT-based optimization using internal don't-cares.]

  Synopsis    [Critical path.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 20, 2005.]

  Revision    [$Id: sbdPath.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

***********************************************************************/

#include "sbdInt.h"
22
#include "misc/tim/tim.h"
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

ABC_NAMESPACE_IMPL_START


////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Sbc_ManAddInternalToPath_rec( Gia_Man_t * p, int iObj, Vec_Bit_t * vPath )
{
    Gia_Obj_t * pObj; 
    int k, iFan, Value = 0;
    if ( Gia_ObjIsTravIdCurrentId(p, iObj) )
        return Vec_BitEntry(vPath, iObj);
    Gia_ObjSetTravIdCurrentId(p, iObj);
    pObj = Gia_ManObj( p, iObj );
    if ( Gia_ObjIsCi(pObj) )
55
        return Vec_BitEntry(vPath, iObj);
56 57 58 59 60 61 62 63 64
    assert( Gia_ObjIsAnd(pObj) );
    Gia_LutForEachFanin( p, iObj, iFan, k )
        Value |= Sbc_ManAddInternalToPath_rec( p, iFan, vPath );
    if ( Value )
        Vec_BitWriteEntry( vPath, iObj, 1 );
    return Value;
}
void Sbc_ManAddInternalToPath( Gia_Man_t * p, Vec_Bit_t * vPath )
{
65
    int k, iFan, iObj;
66 67 68 69 70
    Gia_ManForEachLut( p, iObj )
    {
        if ( !Vec_BitEntry(vPath, iObj) )
            continue;
        Gia_ManIncrementTravId( p );
71 72
        Gia_LutForEachFanin( p, iObj, iFan, k )
            Gia_ObjSetTravIdCurrentId(p, iFan);
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
        Sbc_ManAddInternalToPath_rec( p, iObj, vPath );
    }
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
88
void Sbc_ManCriticalPath_rec( Gia_Man_t * p, int * pLevels, int iObj, int LevelFan, Vec_Bit_t * vPath, int Slack )
89 90 91 92 93 94
{
    Gia_Obj_t * pObj; int k, iFan;
    if ( Gia_ObjIsTravIdCurrentId(p, iObj) )
        return;
    Gia_ObjSetTravIdCurrentId(p, iObj);
    pObj = Gia_ManObj( p, iObj );
95
    Vec_BitWriteEntry( vPath, iObj, 1 );
96
    if ( Gia_ObjIsCi(pObj) )
97 98 99 100 101 102 103 104 105 106 107
    {
        Tim_Man_t * pManTime = (Tim_Man_t *)p->pManTime;
        int iBox = pManTime ? Tim_ManBoxForCi( pManTime, Gia_ObjCioId(pObj) ) : -1;
        if ( iBox >= 0 )
        {
            int curCo = Tim_ManBoxInputFirst( pManTime, iBox );
            int nBoxInputs = Tim_ManBoxInputNum( pManTime, iBox );
            for ( k = 0; k < nBoxInputs; k++ )
            {
                Gia_Obj_t * pCo = Gia_ManCo( p, curCo + k );
                int iDriver = Gia_ObjFaninId0p( p, pCo );
108 109
                if ( (pLevels[iDriver]+Slack >= LevelFan-1) && iDriver )
                    Sbc_ManCriticalPath_rec( p, pLevels, iDriver, pLevels[iDriver], vPath, Abc_MaxInt(0, pLevels[iDriver]+Slack-(LevelFan-1)) );
110 111
            }
        }
112
        return;
113
    }
114 115
    assert( Gia_ObjIsAnd(pObj) );
    Gia_LutForEachFanin( p, iObj, iFan, k )
116 117
        if ( pLevels[iFan]+Slack >= LevelFan-1 )
            Sbc_ManCriticalPath_rec( p, pLevels, iFan, pLevels[iFan], vPath, Abc_MaxInt(0, pLevels[iFan]+Slack-(LevelFan-1)) );
118 119 120
}
Vec_Bit_t * Sbc_ManCriticalPath( Gia_Man_t * p )
{
121
    int * pLevels = NULL, k, iDriver, Slack = 1;
122 123 124 125 126 127
    int nLevels = p->pManTime ? Gia_ManLutLevelWithBoxes(p) : Gia_ManLutLevel(p, &pLevels);
    Vec_Bit_t * vPath = Vec_BitStart( Gia_ManObjNum(p) );
    if ( p->pManTime )
        pLevels = Vec_IntArray( p->vLevels );
    Gia_ManIncrementTravId( p );
    Gia_ManForEachCoDriverId( p, iDriver, k )
128
        if ( (pLevels[iDriver] == nLevels) && iDriver )
129
            Sbc_ManCriticalPath_rec( p, pLevels, iDriver, pLevels[iDriver], vPath, Slack );
130 131 132 133 134 135 136
    if ( !p->pManTime )
        ABC_FREE( pLevels );
    Sbc_ManAddInternalToPath( p, vPath );
    return vPath;
}


137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Sbc_ManDelayTrace( Gia_Man_t * p )
{
    Vec_Bit_t * vPath = Vec_BitStart( Gia_ManObjNum(p) );
    int i, k, iFan, nLevels, * pLevels;
    int nLuts = 0, nNodes = 0, nEdges = 0, nEdgesAll = 0;
    if ( !Gia_ManHasMapping(p) )
    {
        printf( "No mapping is available.\n" );
        return;
    }
    assert( Gia_ManHasMapping(p) );
    // set critical CO drivers
    nLevels = Gia_ManLutLevel( p, &pLevels );
    Gia_ManForEachCoDriverId( p, iFan, i )
        if ( pLevels[iFan] == nLevels )
            Vec_BitWriteEntry( vPath, iFan, 1 );
    // set critical internal nodes
    Gia_ManForEachLutReverse( p, i )
    { 
        nLuts++;
        if ( !Vec_BitEntry(vPath, i) )
            continue;
        nNodes++;
        Gia_LutForEachFanin( p, i, iFan, k )
        {
            if ( pLevels[iFan] +1 < pLevels[i] )
                continue;
            assert( pLevels[iFan] + 1 == pLevels[i] );
            Vec_BitWriteEntry( vPath, iFan, 1 );
            nEdges++;
            //printf( "%d -> %d\n", i, iFan );
        }
    }
    Gia_ManForEachLut( p, i )
        Gia_LutForEachFanin( p, i, iFan, k )
            nEdgesAll += (Vec_BitEntry(vPath, i) && Vec_BitEntry(vPath, iFan));

    ABC_FREE( pLevels );
    Vec_BitFree( vPath );
    printf( "AIG = %d. LUT = %d. Lev = %d.   Path nodes = %d.  Path edges = %d. (%d.)\n", 
        Gia_ManAndNum(p), nLuts, nLevels, nNodes, nEdges, nEdgesAll );
}

191 192 193 194 195 196 197
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


ABC_NAMESPACE_IMPL_END