ifTime.c 7.38 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
/**CFile****************************************************************

  FileName    [ifTime.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [FPGA mapping based on priority cuts.]

  Synopsis    [Computation of delay paramters depending on the library.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - November 21, 2006.]

  Revision    [$Id: ifTime.c,v 1.00 2006/11/21 00:00:00 alanmi Exp $]

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

#include "if.h"
22 23 24

ABC_NAMESPACE_IMPL_START

Alan Mishchenko committed
25 26 27 28 29 30 31 32 33 34
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

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

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

35
  Synopsis    [Sorts the pins in the decreasing order of delays.]
36 37 38 39 40 41 42 43

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
44
void If_CutSortInputPins( If_Man_t * p, If_Cut_t * pCut, int * pPinPerm, float * pPinDelays )
45 46
{
    If_Obj_t * pLeaf;
47 48 49
    int i, j, best_i, temp;
    // start the trivial permutation and collect pin delays
    If_CutForEachLeaf( p, pCut, pLeaf, i )
50
    {
51 52
        pPinPerm[i] = i;
        pPinDelays[i] = If_ObjCutBest(pLeaf)->Delay;
53
    }
54 55 56
    // selection sort the pins in the decreasible order of delays
    // this order will match the increasing order of LUT input pins
    for ( i = 0; i < (int)pCut->nLeaves-1; i++ )
57
    {
58 59 60 61 62 63 64 65 66
        best_i = i;
        for ( j = i+1; j < (int)pCut->nLeaves; j++ )
            if ( pPinDelays[pPinPerm[j]] > pPinDelays[pPinPerm[best_i]] )
                best_i = j;
        if ( best_i == i )
            continue;
        temp = pPinPerm[i]; 
        pPinPerm[i] = pPinPerm[best_i]; 
        pPinPerm[best_i] = temp;
67
    }
68
/*
69 70 71
    // verify
    assert( pPinPerm[0] < (int)pCut->nLeaves );
    for ( i = 1; i < (int)pCut->nLeaves; i++ )
72
    {
73 74
        assert( pPinPerm[i] < (int)pCut->nLeaves );
        assert( pPinDelays[pPinPerm[i-1]] >= pPinDelays[pPinPerm[i]] );
75 76
    }
*/
77
}
78 79


80 81
/**Function*************************************************************

Alan Mishchenko committed
82 83 84 85 86 87 88 89 90
  Synopsis    [Computes delay.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
91
float If_CutDelay( If_Man_t * p, If_Obj_t * pObj, If_Cut_t * pCut )
Alan Mishchenko committed
92 93 94 95 96 97
{
    static int pPinPerm[IF_MAX_LUTSIZE];
    static float pPinDelays[IF_MAX_LUTSIZE];
    If_Obj_t * pLeaf;
    float Delay, DelayCur;
    float * pLutDelays;
98
    int i, Shift, Pin2PinDelay;//, iLeaf;
99
//    assert( p->pPars->fSeqMap || pCut->nLeaves > 1 );
Alan Mishchenko committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    Delay = -IF_FLOAT_LARGE;
    if ( p->pPars->pLutLib )
    {
        assert( !p->pPars->fLiftLeaves );
        pLutDelays = p->pPars->pLutLib->pLutDelays[pCut->nLeaves];
        if ( p->pPars->pLutLib->fVarPinDelays )
        {
            // compute the delay using sorted pins
            If_CutSortInputPins( p, pCut, pPinPerm, pPinDelays );
            for ( i = 0; i < (int)pCut->nLeaves; i++ )
            {
                DelayCur = pPinDelays[pPinPerm[i]] + pLutDelays[i];
                Delay = IF_MAX( Delay, DelayCur );
            }
        }
        else
        {
            If_CutForEachLeaf( p, pCut, pLeaf, i )
            {
119
                DelayCur = If_ObjCutBest(pLeaf)->Delay + pLutDelays[0];
Alan Mishchenko committed
120 121 122 123 124 125 126 127 128 129 130
                Delay = IF_MAX( Delay, DelayCur );
            }
        }
    }
    else
    {
        if ( pCut->fUser )
        {
            assert( !p->pPars->fLiftLeaves );
            If_CutForEachLeaf( p, pCut, pLeaf, i )
            {
131 132
                Pin2PinDelay = pCut->pPerm ? (pCut->pPerm[i] == IF_BIG_CHAR ? -IF_BIG_CHAR : pCut->pPerm[i]) : 1;
                DelayCur = If_ObjCutBest(pLeaf)->Delay + (float)Pin2PinDelay;
Alan Mishchenko committed
133 134 135 136 137 138 139 140 141 142
                Delay = IF_MAX( Delay, DelayCur );
            }
        }
        else
        {
            if ( p->pPars->fLiftLeaves )
            {
                If_CutForEachLeafSeq( p, pCut, pLeaf, Shift, i )
                {
                    DelayCur = If_ObjCutBest(pLeaf)->Delay - Shift * p->Period;
143
                    Delay = IF_MAX( Delay, DelayCur + 1.0 );
Alan Mishchenko committed
144 145 146 147 148 149
                }
            }
            else
            {
                If_CutForEachLeaf( p, pCut, pLeaf, i )
                {
150
                    DelayCur = If_ObjCutBest(pLeaf)->Delay + 1.0;
Alan Mishchenko committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
                    Delay = IF_MAX( Delay, DelayCur );
                }
            }
        }
    }
    return Delay;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
170
void If_CutPropagateRequired( If_Man_t * p, If_Obj_t * pObj, If_Cut_t * pCut, float ObjRequired )
Alan Mishchenko committed
171 172 173 174 175 176
{
    static int pPinPerm[IF_MAX_LUTSIZE];
    static float pPinDelays[IF_MAX_LUTSIZE];
    If_Obj_t * pLeaf;
    float * pLutDelays;
    float Required;
177
    int i, Pin2PinDelay;//, iLeaf;
Alan Mishchenko committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
    assert( !p->pPars->fLiftLeaves );
    // compute the pins
    if ( p->pPars->pLutLib )
    {
        pLutDelays = p->pPars->pLutLib->pLutDelays[pCut->nLeaves];
        if ( p->pPars->pLutLib->fVarPinDelays )
        {
            // compute the delay using sorted pins
            If_CutSortInputPins( p, pCut, pPinPerm, pPinDelays );
            for ( i = 0; i < (int)pCut->nLeaves; i++ )
            {
                Required = ObjRequired - pLutDelays[i];
                pLeaf = If_ManObj( p, pCut->pLeaves[pPinPerm[i]] );
                pLeaf->Required = IF_MIN( pLeaf->Required, Required );
            }
        }
        else
        {
196
            Required = ObjRequired;
Alan Mishchenko committed
197
            If_CutForEachLeaf( p, pCut, pLeaf, i )
198
                pLeaf->Required = IF_MIN( pLeaf->Required, Required - pLutDelays[0] );
Alan Mishchenko committed
199 200 201 202 203 204
        }
    }
    else
    {
        if ( pCut->fUser )
        {
205
            char Perm[IF_MAX_FUNC_LUTSIZE], * pPerm = Perm;
206
            if ( p->pPars->fDelayOpt )
207 208 209 210 211 212 213 214 215 216 217
            {
                int Delay = If_CutSopBalancePinDelays( p, pCut, pPerm );
                assert( Delay == pCut->Delay );
            }
            else if ( p->pPars->fDsdBalance )
            {
                int Delay = If_CutDsdBalancePinDelays( p, pCut, pPerm );
                assert( Delay == pCut->Delay );
            }
            else 
                pPerm = pCut->pPerm;
Alan Mishchenko committed
218 219
            If_CutForEachLeaf( p, pCut, pLeaf, i )
            {
220
                Pin2PinDelay = pPerm ? (pPerm[i] == IF_BIG_CHAR ? -IF_BIG_CHAR : pPerm[i]) : 1;
221
                Required = ObjRequired - (float)Pin2PinDelay;
Alan Mishchenko committed
222 223 224 225 226
                pLeaf->Required = IF_MIN( pLeaf->Required, Required );
            }
        }
        else
        {
227
            Required = ObjRequired;
Alan Mishchenko committed
228
            If_CutForEachLeaf( p, pCut, pLeaf, i )
229
                pLeaf->Required = IF_MIN( pLeaf->Required, Required - (float)1.0 );
Alan Mishchenko committed
230 231 232 233 234 235 236 237 238
        }
    }
}

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


239 240
ABC_NAMESPACE_IMPL_END