ifCore.c 5.88 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    [ifCore.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [FPGA mapping based on priority cuts.]

  Synopsis    [The central part of the mapper.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "if.h"

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

30
extern abctime s_MappingTime;
Alan Mishchenko committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

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

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
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
void If_ManSetDefaultPars( If_Par_t * pPars )
{
    memset( pPars, 0, sizeof(If_Par_t) );
    pPars->nLutSize    = -1;
    pPars->nCutsMax    =  8;
    pPars->nFlowIters  =  1;
    pPars->nAreaIters  =  2;
    pPars->DelayTarget = -1;
    pPars->Epsilon     =  (float)0.005;
    pPars->fPreprocess =  1;
    pPars->fArea       =  0;
    pPars->fFancy      =  0;
    pPars->fExpRed     =  1;
    pPars->fLatchPaths =  0;
    pPars->fEdge       =  1;
    pPars->fPower      =  0;
    pPars->fCutMin     =  0;
    pPars->fBidec      =  0;
    pPars->fVerbose    =  0;
}


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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
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
int If_ManPerformMapping( If_Man_t * p )
{
    p->pPars->fAreaOnly = p->pPars->fArea; // temporary
    // create the CI cutsets
    If_ManSetupCiCutSets( p );
    // allocate memory for other cutsets
    If_ManSetupSetAll( p, If_ManCrossCut(p) );
    // derive reverse top order
    p->vObjsRev = If_ManReverseOrder( p );
    return If_ManPerformMappingComb( p );
}


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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int If_ManPerformMappingComb( If_Man_t * p )
{
    If_Obj_t * pObj;
107
    abctime clkTotal = Abc_Clock();
Alan Mishchenko committed
108
    int i;
109 110
    //p->vVisited2 = Vec_IntAlloc( 100 );
    //p->vMarks = Vec_StrStart( If_ManObjNum(p) );
Alan Mishchenko committed
111 112 113 114

    // set arrival times and fanout estimates
    If_ManForEachCi( p, pObj, i )
    {
115
        If_ObjSetArrTime( pObj, p->pPars->pTimesArr ? p->pPars->pTimesArr[i] : (float)0.0 );
Alan Mishchenko committed
116 117 118 119 120 121 122
        pObj->EstRefs = (float)1.0;
    }

    // delay oriented mapping
    if ( p->pPars->fPreprocess && !p->pPars->fArea )
    {
        // map for delay
123
        If_ManPerformMappingRound( p, p->pPars->nCutsMax, 0, 1, 1, "Delay" );
Alan Mishchenko committed
124 125 126
        // map for delay second option
        p->pPars->fFancy = 1;
        If_ManResetOriginalRefs( p );
127
        If_ManPerformMappingRound( p, p->pPars->nCutsMax, 0, 1, 0, "Delay-2" );
Alan Mishchenko committed
128 129 130 131
        p->pPars->fFancy = 0;
        // map for area
        p->pPars->fArea = 1;
        If_ManResetOriginalRefs( p );
132
        If_ManPerformMappingRound( p, p->pPars->nCutsMax, 0, 1, 0, "Area" );
Alan Mishchenko committed
133 134 135
        p->pPars->fArea = 0;
    }
    else
136
        If_ManPerformMappingRound( p, p->pPars->nCutsMax, 0, 0, 1, "Delay" );
Alan Mishchenko committed
137 138

    // try to improve area by expanding and reducing the cuts
Alan Mishchenko committed
139
    if ( p->pPars->fExpRed )
Alan Mishchenko committed
140 141 142 143 144
        If_ManImproveMapping( p );

    // area flow oriented mapping
    for ( i = 0; i < p->pPars->nFlowIters; i++ )
    {
145
        If_ManPerformMappingRound( p, p->pPars->nCutsMax, 1, 0, 0, "Flow" );
Alan Mishchenko committed
146
        if ( p->pPars->fExpRed )
Alan Mishchenko committed
147 148 149 150 151 152
            If_ManImproveMapping( p );
    }

    // area oriented mapping
    for ( i = 0; i < p->pPars->nAreaIters; i++ )
    {
153
        If_ManPerformMappingRound( p, p->pPars->nCutsMax, 2, 0, 0, "Area" );
Alan Mishchenko committed
154
        if ( p->pPars->fExpRed )
Alan Mishchenko committed
155 156 157 158 159
            If_ManImproveMapping( p );
    }

    if ( p->pPars->fVerbose )
    {
160
//        Abc_Print( 1, "Total memory = %7.2f MB. Peak cut memory = %7.2f MB.  ", 
Alan Mishchenko committed
161 162
//            1.0 * (p->nObjBytes + 2*sizeof(void *)) * If_ManObjNum(p) / (1<<20), 
//            1.0 * p->nSetBytes * Mem_FixedReadMaxEntriesUsed(p->pMemSet) / (1<<20) );
163
        Abc_PrintTime( 1, "Total time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
164
    }
165
//    Abc_Print( 1, "Cross cut memory = %d.\n", Mem_FixedReadMaxEntriesUsed(p->pMemSet) );
166
    s_MappingTime = Abc_Clock() - clkTotal;
167
//    Abc_Print( 1, "Special POs = %d.\n", If_ManCountSpecialPos(p) );
168 169

/*
Alan Mishchenko committed
170
    {
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
        static char * pLastName = NULL;
        FILE * pTable = fopen( "fpga/ucsb/stats.txt", "a+" );
        if ( pLastName == NULL || strcmp(pLastName, p->pName) )
        {
            fprintf( pTable, "\n" );
            fprintf( pTable, "%s ", p->pName );

            fprintf( pTable, "%d ", If_ManCiNum(p) );
            fprintf( pTable, "%d ", If_ManCoNum(p) );
            fprintf( pTable, "%d ", If_ManAndNum(p) );

            ABC_FREE( pLastName );
            pLastName = Abc_UtilStrsav( p->pName );
        }

        fprintf( pTable, "%d ", (int)p->AreaGlo );
        fprintf( pTable, "%d ", (int)p->RequiredGlo );
        fclose( pTable );
Alan Mishchenko committed
189
    }
190
*/
191
    p->pPars->FinalDelay = p->RequiredGlo;
192
    p->pPars->FinalArea  = p->AreaGlo;
Alan Mishchenko committed
193 194 195 196 197 198 199 200
    return 1;
}

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


201 202
ABC_NAMESPACE_IMPL_END