ntlTime.c 7.32 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/**CFile****************************************************************

  FileName    [ntlTime.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Netlist representation.]

  Synopsis    [Creates timing manager.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "ntl.h"

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

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

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
float * Ntl_ManCreateDelayTable( Vec_Int_t * vDelays, int nIns, int nOuts )
{
    float * pDelayTable, Delay;
    int iIn, iOut, i, k;
    assert( Vec_IntSize(vDelays) % 3 == 0 );
Alan Mishchenko committed
50
    pDelayTable = ABC_ALLOC( float, nIns * nOuts );
Alan Mishchenko committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    memset( pDelayTable, 0, sizeof(float) * nIns * nOuts );
    Vec_IntForEachEntry( vDelays, iIn, i )
    {
        iOut = Vec_IntEntry(vDelays, ++i);
        Delay = Aig_Int2Float( Vec_IntEntry(vDelays, ++i) );
        if ( iIn == -1 && iOut == -1 )
            for ( k = 0; k < nIns * nOuts; k++ )
                pDelayTable[k] = Delay;
        else if ( iIn == -1 )
            for ( k = 0; k < nIns; k++ )
                pDelayTable[iOut * nIns + k] = Delay;
        else if ( iOut == -1 )
            for ( k = 0; k < nOuts; k++ )
                pDelayTable[k * nIns + iIn] = Delay;
        else 
            pDelayTable[iOut * nIns + iIn] = Delay;
    }
    return pDelayTable;
}

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

Alan Mishchenko committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
  Synopsis    [Records the arrival times for the map leaves.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Ntl_ManUnpackLeafTiming( Ntl_Man_t * p, Tim_Man_t * pMan )
{
    Vec_Int_t * vTimes;
    Ntl_Mod_t * pRoot;
    Ntl_Obj_t * pObj;
    Ntl_Net_t * pNet;
    float dTime;
    int i, k, v, Entry, Counter;
    // clean the place
    pRoot = Ntl_ManRootModel( p );
    Ntl_ModelForEachMapLeaf( pRoot, pObj, i )
        Ntl_ObjForEachFanout( pObj, pNet, k )
            pNet->dTemp = 0;
    // store the PI timing
    vTimes = pRoot->vTimeInputs;
Alan Mishchenko committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    if ( vTimes ) {
      Vec_IntForEachEntry( vTimes, Entry, i )
      {
          dTime = Aig_Int2Float( Vec_IntEntry(vTimes,++i) );
          if ( Entry == -1 )
          {
              Ntl_ModelForEachPi( pRoot, pObj, v )
                  Ntl_ObjFanout0(pObj)->dTemp = dTime;
          }
          else
          {
              pObj = Ntl_ModelPi( pRoot, Entry );
              Ntl_ObjFanout0(pObj)->dTemp = dTime;
          }
      }
Alan Mishchenko committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 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
    }
    // store box timing
    Ntl_ModelForEachMapLeaf( pRoot, pObj, k )
    {
        if ( !(Ntl_ObjIsBox(pObj) && Ntl_BoxIsSeq(pObj)) )
            continue;
        vTimes = pObj->pImplem->vTimeOutputs;
        if ( vTimes == NULL )
            continue;
        Vec_IntForEachEntry( vTimes, Entry, i )
        {
            dTime = Aig_Int2Float( Vec_IntEntry(vTimes,++i) );
            if ( Entry == -1 )
            {
                Ntl_ObjForEachFanout( pObj, pNet, v )
                    pNet->dTemp = dTime;
            }
            else
            {
                pNet = Ntl_ObjFanout( pObj, Entry );
                pNet->dTemp = dTime;
            }
        }
    }
    // load them into the timing manager
    Counter = 0;
    Ntl_ModelForEachMapLeaf( pRoot, pObj, i )
        Ntl_ObjForEachFanout( pObj, pNet, k )
        {
            if ( pNet->dTemp == TIM_ETERNITY )
                pNet->dTemp = -TIM_ETERNITY;
            Tim_ManInitCiArrival( pMan, Counter++, pNet->dTemp );
        }
    assert( Counter == p->iLastCi );
}

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

  Synopsis    [Records the required times for the map leaves.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Ntl_ManUnpackRootTiming( Ntl_Man_t * p, Tim_Man_t * pMan )
{
}

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

Alan Mishchenko committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Tim_Man_t * Ntl_ManCreateTiming( Ntl_Man_t * p )
{
    Tim_Man_t * pMan;
    Vec_Ptr_t * vDelayTables;
    Ntl_Mod_t * pRoot, * pModel;
    Ntl_Obj_t * pObj;
Alan Mishchenko committed
180
    int i, curPi, iBox;//, Entry;
Alan Mishchenko committed
181
    assert( p->pAig != NULL );
Alan Mishchenko committed
182
    pRoot = Ntl_ManRootModel( p );
Alan Mishchenko committed
183 184
    // start the timing manager
    pMan = Tim_ManStart( Aig_ManPiNum(p->pAig), Aig_ManPoNum(p->pAig) );
Alan Mishchenko committed
185 186 187 188
    // unpack the timing data
    Ntl_ManUnpackLeafTiming( p, pMan );
//    Ntl_ManUnpackRootTiming( p, pMan );
/*
Alan Mishchenko committed
189 190 191 192 193 194 195 196 197 198
    if ( pRoot->vTimeInputs )
    {
        Vec_IntForEachEntry( pRoot->vTimeInputs, Entry, i )
        {
            if ( Entry == -1 )
                Tim_ManSetCiArrivalAll( pMan, Aig_Int2Float(Vec_IntEntry(pRoot->vTimeInputs,++i)) );
            else
                Tim_ManInitCiArrival( pMan, Entry, Aig_Int2Float(Vec_IntEntry(pRoot->vTimeInputs,++i)) );
        }
    }
Alan Mishchenko committed
199
    // unpack the data in the required times
Alan Mishchenko committed
200 201 202 203 204 205 206 207 208 209
    if ( pRoot->vTimeOutputs )
    {
        Vec_IntForEachEntry( pRoot->vTimeOutputs, Entry, i )
        {
            if ( Entry == -1 )
                Tim_ManSetCoRequiredAll( pMan, Aig_Int2Float(Vec_IntEntry(pRoot->vTimeOutputs,++i)) );
            else
                Tim_ManInitCoRequired( pMan, Entry, Aig_Int2Float(Vec_IntEntry(pRoot->vTimeOutputs,++i)) );
        }
    }
Alan Mishchenko committed
210 211
*/
    // derive timing tables for the whilte comb boxes
Alan Mishchenko committed
212 213 214 215 216 217 218 219 220 221
    vDelayTables = Vec_PtrAlloc( Vec_PtrSize(p->vModels) );
    Ntl_ManForEachModel( p, pModel, i )
    {
        if ( pModel->vDelays )
            pModel->pDelayTable = Ntl_ManCreateDelayTable( pModel->vDelays, Ntl_ModelPiNum(pModel), Ntl_ModelPoNum(pModel) );
        Vec_PtrPush( vDelayTables, pModel->pDelayTable );
    }
    Tim_ManSetDelayTables( pMan, vDelayTables );
    // set up the boxes
    iBox = 0;
Alan Mishchenko committed
222
    curPi = p->iLastCi;
223
    Vec_PtrForEachEntry( Ntl_Obj_t *, p->vVisNodes, pObj, i )
Alan Mishchenko committed
224
    {
Alan Mishchenko committed
225 226 227
        if ( !Ntl_ObjIsBox(pObj) )
            continue;
        Tim_ManCreateBoxFirst( pMan, Vec_IntEntry(p->vBox1Cios, iBox), Ntl_ObjFaninNum(pObj), curPi, Ntl_ObjFanoutNum(pObj), pObj->pImplem->pDelayTable );
Alan Mishchenko committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
        curPi += Ntl_ObjFanoutNum(pObj);
        iBox++;
    }
    // forget refs to the delay tables in the network
    Ntl_ManForEachModel( p, pModel, i )
        pModel->pDelayTable = NULL;
//    Tim_ManPrint( pMan );
    return pMan;
}


////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


244 245
ABC_NAMESPACE_IMPL_END