summaryrefslogtreecommitdiffstats
path: root/src/map/if/ifPrepro.c
blob: 797e8727b258b1ba6f59f94b985fbcb669a935b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
165
166
167
168
169
170
171
172
173
174
175
/**CFile****************************************************************

  FileName    [ifPrepro.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [FPGA mapping based on priority cuts.]

  Synopsis    [Selects the starting mapping.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "if.h"

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

static void If_ManPerformMappingMoveBestCut( If_Man_t * p, int iPosNew, int iPosOld );
static void If_ManPerformMappingAdjust( If_Man_t * p, int nCuts );

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

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

  Synopsis    [Merges the results of delay, relaxed delay and area-based mapping.]

  Description [Delay target may be different from minimum delay!!!]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void If_ManPerformMappingPreprocess( If_Man_t * p )
{
    float delayArea, delayDelay, delayPure;
    int clk = clock();
    assert( p->pPars->nCutsMax >= 4 );

    // perform min-area mapping and move the cut to the end
    p->pPars->fArea = 1;
    If_ManPerformMappingRound( p, p->pPars->nCutsMax, 0, 0 );
    p->pPars->fArea = 0;
    delayArea = If_ManDelayMax( p );
    if ( p->pPars->DelayTarget != -1 && delayArea < p->pPars->DelayTarget - p->fEpsilon )
        delayArea = p->pPars->DelayTarget;
    If_ManPerformMappingMoveBestCut( p, p->pPars->nCutsMax - 1, 1 );

    // perfrom min-delay mapping and move the cut to the end
    p->pPars->fFancy = 1;
    If_ManPerformMappingRound( p, p->pPars->nCutsMax - 1, 0, 0 );
    p->pPars->fFancy = 0;
    delayDelay = If_ManDelayMax( p );
    if ( p->pPars->DelayTarget != -1 && delayDelay < p->pPars->DelayTarget - p->fEpsilon )
        delayDelay = p->pPars->DelayTarget;
    If_ManPerformMappingMoveBestCut( p, p->pPars->nCutsMax - 2, 1 );

    // perform min-area mapping 
    If_ManPerformMappingRound( p, p->pPars->nCutsMax - 2, 0, 0 );
    delayPure = If_ManDelayMax( p );
    if ( p->pPars->DelayTarget != -1 && delayPure < p->pPars->DelayTarget - p->fEpsilon )
        delayPure = p->pPars->DelayTarget;

    // decide what to do
    if ( delayPure < delayDelay - p->fEpsilon && delayPure < delayArea - p->fEpsilon )
    {
        // copy the remaining two cuts
        if ( p->pPars->nCutsMax > 4 )
        {
            If_ManPerformMappingMoveBestCut( p, 2, p->pPars->nCutsMax - 2 );
            If_ManPerformMappingMoveBestCut( p, 3, p->pPars->nCutsMax - 1 );
        }
        If_ManComputeRequired( p, 1 );
        If_ManPerformMappingAdjust( p, 4 );
    }
    else if ( delayDelay < delayArea - p->fEpsilon )
    {
        If_ManPerformMappingMoveBestCut( p, 1, p->pPars->nCutsMax - 2 );
        If_ManPerformMappingMoveBestCut( p, 2, p->pPars->nCutsMax - 1 );
        If_ManComputeRequired( p, 1 );
        If_ManPerformMappingAdjust( p, 3 );
    }
    else
    {
        If_ManPerformMappingMoveBestCut( p, 1, p->pPars->nCutsMax - 1 );
        If_ManComputeRequired( p, 1 );
        If_ManPerformMappingAdjust( p, 2 );
    }
    If_ManComputeRequired( p, 1 );
    if ( p->pPars->fVerbose )
    {
        printf( "S:  Del = %6.2f. Area = %8.2f. Cuts = %6d. Lim = %2d. Ave = %5.2f. ", 
            p->RequiredGlo, p->AreaGlo, p->nCutsMerged, p->nCutsUsed, 1.0 * p->nCutsMerged / If_ManAndNum(p) );
        PRT( "T", clock() - clk );
    }
}

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

  Synopsis    [Moves the best cut to the given position.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void If_ManPerformMappingMoveBestCut( If_Man_t * p, int iPosNew, int iPosOld )
{
    If_Obj_t * pObj;
    int i;
    assert( iPosOld != iPosNew );
    assert( iPosOld > 0 && iPosOld < p->pPars->nCutsMax );
    assert( iPosNew > 0 && iPosNew < p->pPars->nCutsMax );
    If_ManForEachNode( p, pObj, i )
        If_CutCopy( pObj->Cuts + iPosNew, pObj->Cuts + iPosOld );
}

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

  Synopsis    [Adjusts mapping for the given cuts.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void If_ManPerformMappingAdjust( If_Man_t * p, int nCuts )
{
    If_Cut_t * pCut, * pCutBest;
    If_Obj_t * pObj;
    int i, c;
    assert( nCuts >= 2 && nCuts <= 4 );
    If_ManForEachNode( p, pObj, i )
    {
        pCutBest = NULL;
        for ( c = 1; c < nCuts; c++ )
        {
            pCut = pObj->Cuts + c;
            pCut->Delay = If_CutDelay( p, pCut );
            pCut->Area  = If_CutFlow( p, pCut );
            assert( pCutBest || pCut->Delay < pObj->Required + p->fEpsilon );
            if ( pCutBest == NULL || 
                (pCut->Delay < pObj->Required + p->fEpsilon && 
                 pCut->Area < pCutBest->Area - p->fEpsilon) )
                pCutBest = pCut;
        }
        assert( pCutBest != NULL );
        // check if we need to move
        if ( pCutBest != pObj->Cuts + 1 )
            If_CutCopy( pObj->Cuts + 1, pCutBest );
        // set the number of cuts
        pObj->nCuts = 2;
    }
}

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