fpgaCore.c 5.86 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
/**CFile****************************************************************

  FileName    [fpgaCore.c]

  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]

  Synopsis    [Technology mapping for variable-size-LUT FPGAs.]

  Author      [MVSIS Group]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 2.0. Started - August 18, 2004.]

  Revision    [$Id: fpgaCore.c,v 1.7 2004/10/01 23:41:04 satrajit Exp $]

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

#include "fpgaInt.h"

21 22 23
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
24 25 26 27
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

Alan Mishchenko committed
28
static int  Fpga_MappingPostProcess( Fpga_Man_t * p );
Alan Mishchenko committed
29

30
extern clock_t s_MappingTime;
31
extern int s_MappingMem;
Alan Mishchenko committed
32 33


Alan Mishchenko committed
34
////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
35
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
////////////////////////////////////////////////////////////////////////

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

  Synopsis    [Performs technology mapping for the given object graph.]

  Description [The object graph is stored in the mapping manager.
  First, all the AND-nodes, which fanout into the POs, are collected
  in the DFS fashion. Next, three steps are performed: the k-feasible
  cuts are computed for each node, the truth tables are computed for
  each cut, and the delay-optimal matches are assigned for each node.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Fpga_Mapping( Fpga_Man_t * p )
{
55
    clock_t clk, clkTotal = clock();
Alan Mishchenko committed
56
 
Alan Mishchenko committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    // collect the nodes reachable from POs in the DFS order (including the choices)
    p->vAnds = Fpga_MappingDfs( p, 1 );
    Fpga_ManReportChoices( p ); // recomputes levels
    Fpga_MappingSetChoiceLevels( p );

    // compute the cuts of nodes in the DFS order
    clk = clock();
    Fpga_MappingCuts( p );
    p->timeCuts = clock() - clk;

    // match the truth tables to the supergates
    clk = clock();
    if ( !Fpga_MappingMatches( p, 1 ) )
        return 0;
    p->timeMatch = clock() - clk;

    // perform area recovery
Alan Mishchenko committed
74 75 76 77
    clk = clock();
    if ( !Fpga_MappingPostProcess( p ) )
        return 0;
    p->timeRecover = clock() - clk;
Alan Mishchenko committed
78
//ABC_PRT( "Total mapping time", clock() - clkTotal );
Alan Mishchenko committed
79

Alan Mishchenko committed
80 81 82
    s_MappingTime = clock() - clkTotal;
    s_MappingMem = Fpga_CutCountAll(p) * (sizeof(Fpga_Cut_t) - sizeof(int) * (FPGA_MAX_LEAVES - p->nVarsMax));

Alan Mishchenko committed
83 84
    // print the AI-graph used for mapping
    //Fpga_ManShow( p, "test" );
Alan Mishchenko committed
85 86
//    if ( p->fVerbose )
//        Fpga_MappingPrintOutputArrivals( p );
Alan Mishchenko committed
87
    if ( p->fVerbose )
Alan Mishchenko committed
88
    {
Alan Mishchenko committed
89
        ABC_PRT( "Total time", clock() - clkTotal );
Alan Mishchenko committed
90
    }
Alan Mishchenko committed
91 92 93 94 95 96 97 98 99 100 101
    return 1;
}

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

  Synopsis    [Postprocesses the mapped network for area recovery.]

  Description [This procedure assumes that the mapping is assigned.
  It iterates the loop, in which the required times are computed and
  the mapping is updated. It is conceptually similar to the paper: 
  V. Manohararajah, S. D. Brown, Z. G. Vranesic, Heuristics for area 
Alan Mishchenko committed
102
  minimization in LUT-based FPGA technology mapping. Proc. IWLS '04.]
Alan Mishchenko committed
103 104 105 106 107 108 109 110
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Fpga_MappingPostProcess( Fpga_Man_t * p )
{
Alan Mishchenko committed
111
    int fShowSwitching    = 0;
Alan Mishchenko committed
112 113 114
    int fRecoverAreaFlow  = 1;
    int fRecoverArea      = 1;
    float aAreaTotalCur, aAreaTotalCur2;
115 116
    int Iter;
    clock_t clk;
Alan Mishchenko committed
117

Alan Mishchenko committed
118 119 120
//if ( p->fVerbose )
//    printf( "Best clock period = %5.2f\n", Fpga_TimeComputeArrivalMax(p) );

Alan Mishchenko committed
121
    // compute area, set references, and collect nodes used in the mapping
Alan Mishchenko committed
122
    Iter = 1;
Alan Mishchenko committed
123
    aAreaTotalCur = Fpga_MappingSetRefsAndArea( p );
Alan Mishchenko committed
124 125
if ( p->fVerbose )
{
Alan Mishchenko committed
126 127 128
printf( "Iteration %dD :  Area = %8.1f  ", Iter++, aAreaTotalCur );
if ( fShowSwitching )
printf( "Switch = %8.1f  ", Fpga_MappingGetSwitching(p,p->vMapping) );
Alan Mishchenko committed
129 130 131
else
printf( "Delay = %5.2f  ", Fpga_TimeComputeArrivalMax(p) );

Alan Mishchenko committed
132
ABC_PRT( "Time", p->timeMatch );
Alan Mishchenko committed
133 134
}

Alan Mishchenko committed
135 136 137
    if ( !p->fAreaRecovery )
        return 1;

Alan Mishchenko committed
138 139
    if ( fRecoverAreaFlow )
    {
Alan Mishchenko committed
140 141
clk = clock();
        // compute the required times and the fanouts
Alan Mishchenko committed
142
        Fpga_TimeComputeRequiredGlobal( p, 1 );
Alan Mishchenko committed
143 144 145
        // remap topologically
        Fpga_MappingMatches( p, 0 );
        // get the resulting area
Alan Mishchenko committed
146 147 148 149
//        aAreaTotalCur = Fpga_MappingSetRefsAndArea( p );
        aAreaTotalCur = Fpga_MappingAreaTrav( p );
        // note that here we do not update the reference counter
        // for some reason, this works better on benchmarks
Alan Mishchenko committed
150 151
if ( p->fVerbose )
{
Alan Mishchenko committed
152 153 154
printf( "Iteration %dF :  Area = %8.1f  ", Iter++, aAreaTotalCur );
if ( fShowSwitching )
printf( "Switch = %8.1f  ", Fpga_MappingGetSwitching(p,p->vMapping) );
Alan Mishchenko committed
155 156
else
printf( "Delay = %5.2f  ", Fpga_TimeComputeArrivalMax(p) );
Alan Mishchenko committed
157
ABC_PRT( "Time", clock() - clk );
Alan Mishchenko committed
158
}
Alan Mishchenko committed
159
    }
Alan Mishchenko committed
160

Alan Mishchenko committed
161 162
    // update reference counters
    aAreaTotalCur2 = Fpga_MappingSetRefsAndArea( p );
Alan Mishchenko committed
163 164
    assert( aAreaTotalCur == aAreaTotalCur2 );

Alan Mishchenko committed
165 166
    if ( fRecoverArea )
    {
Alan Mishchenko committed
167 168
clk = clock();
        // compute the required times and the fanouts
Alan Mishchenko committed
169
        Fpga_TimeComputeRequiredGlobal( p, 0 );
Alan Mishchenko committed
170
        // remap topologically
Alan Mishchenko committed
171 172 173 174
        if ( p->fSwitching )
            Fpga_MappingMatchesSwitch( p );
        else
            Fpga_MappingMatchesArea( p );
Alan Mishchenko committed
175
        // get the resulting area
Alan Mishchenko committed
176
        aAreaTotalCur = Fpga_MappingSetRefsAndArea( p );
Alan Mishchenko committed
177 178
if ( p->fVerbose )
{
Alan Mishchenko committed
179 180 181
printf( "Iteration %d%s :  Area = %8.1f  ", Iter++, (p->fSwitching?"S":"A"), aAreaTotalCur );
if ( fShowSwitching )
printf( "Switch = %8.1f  ", Fpga_MappingGetSwitching(p,p->vMapping) );
Alan Mishchenko committed
182 183
else
printf( "Delay = %5.2f  ", Fpga_TimeComputeArrivalMax(p) );
Alan Mishchenko committed
184
ABC_PRT( "Time", clock() - clk );
Alan Mishchenko committed
185
}
Alan Mishchenko committed
186 187
    }

Alan Mishchenko committed
188 189 190 191 192
    p->fAreaGlo = aAreaTotalCur;
    return 1;
}


193 194
ABC_NAMESPACE_IMPL_END