mapperLib.c 8.02 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/**CFile****************************************************************

  FileName    [mapperLib.c]

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

  Synopsis    [Generic technology mapping engine.]

  Author      [MVSIS Group]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 2.0. Started - June 1, 2004.]

  Revision    [$Id: mapperLib.c,v 1.6 2005/01/23 06:59:44 alanmi Exp $]

***********************************************************************/
Alan Mishchenko committed
18 19 20 21 22
#define _BSD_SOURCE

#ifndef WIN32
#include <unistd.h>
#endif
Alan Mishchenko committed
23 24

#include "mapperInt.h"
25 26
#include "map/super/super.h"
#include "map/mapper/mapperInt.h"
Alan Mishchenko committed
27

28 29 30
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
31 32 33 34 35
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

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

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

  Synopsis    [Reads in the supergate library and prepares it for use.]

  Description [The supergates library comes in a .super file. This file
  contains descriptions of supergates along with some relevant information.
  This procedure reads the supergate file, canonicizes the supergates,
  and constructs an additional lookup table, which can be used to map
  truth tables of the cuts into the pair (phase, supergate). The phase
  indicates how the current truth table should be phase assigned to 
  match the canonical form of the supergate. The resulting phase is the
  bitwise EXOR of the phase needed to canonicize the supergate and the
  phase needed to transform the truth table into its canonical form.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
58
Map_SuperLib_t * Map_SuperLibCreate( Mio_Library_t * pGenlib, Vec_Str_t * vStr, char * pFileName, char * pExcludeFile, int fAlgorithm, int fVerbose )
Alan Mishchenko committed
59 60
{
    Map_SuperLib_t * p;
61
    abctime clk;
Alan Mishchenko committed
62 63

    // start the supergate library
Alan Mishchenko committed
64
    p = ABC_ALLOC( Map_SuperLib_t, 1 );
Alan Mishchenko committed
65
    memset( p, 0, sizeof(Map_SuperLib_t) );
66
    p->pName     = Abc_UtilStrsav(pFileName);
Alan Mishchenko committed
67 68 69 70 71 72 73 74 75 76 77
    p->fVerbose  = fVerbose;
    p->mmSupers  = Extra_MmFixedStart( sizeof(Map_Super_t) );
    p->mmEntries = Extra_MmFixedStart( sizeof(Map_HashEntry_t) );
    p->mmForms   = Extra_MmFlexStart();
    Map_MappingSetupTruthTables( p->uTruths );

    // start the hash table
    p->tTableC = Map_SuperTableCreate( p );
    p->tTable  = Map_SuperTableCreate( p );

    // read the supergate library from file
78
clk = Abc_Clock();
79 80 81
    if ( vStr != NULL )
    {
        // read the supergate library from file
82
        int Status = Map_LibraryReadFileTreeStr( p, pGenlib, vStr, pFileName );
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
        if ( Status == 0 )
        {
            Map_SuperLibFree( p );
            return NULL;
        }
        // prepare the info about the library
        Status = Map_LibraryDeriveGateInfo( p, NULL );
        if ( Status == 0 )
        {
            Map_SuperLibFree( p );
            return NULL;
        }
        assert( p->nVarsMax > 0 );
    }
    else if ( fAlgorithm )
Alan Mishchenko committed
98
    {
99
        if ( !Map_LibraryReadTree( p, pGenlib, pFileName, pExcludeFile ) )
Alan Mishchenko committed
100 101 102 103 104 105 106 107 108
        {
            Map_SuperLibFree( p );
            return NULL;
        }
    }
    else
    {
        if ( pExcludeFile != 0 )
        {
109
            Map_SuperLibFree( p );
Alan Mishchenko committed
110 111 112 113 114 115 116 117 118 119 120 121
            printf ("Error: Exclude file support not present for old format. Stop.\n");
            return NULL;
        }
        if ( !Map_LibraryRead( p, pFileName ) )
        {
            Map_SuperLibFree( p );
            return NULL;
        }
    }
    assert( p->nVarsMax > 0 );

    // report the stats
122 123 124 125
    if ( fVerbose ) 
    {
        printf( "Loaded %d unique %d-input supergates from \"%s\".  ", 
            p->nSupersReal, p->nVarsMax, pFileName );
126
        ABC_PRT( "Time", Abc_Clock() - clk );
127
    }
Alan Mishchenko committed
128 129 130 131 132 133 134

    // assign the interver parameters
    p->pGateInv        = Mio_LibraryReadInv( p->pGenlib );
    p->tDelayInv.Rise  = Mio_LibraryReadDelayInvRise( p->pGenlib );
    p->tDelayInv.Fall  = Mio_LibraryReadDelayInvFall( p->pGenlib );
    p->tDelayInv.Worst = MAP_MAX( p->tDelayInv.Rise, p->tDelayInv.Fall );
    p->AreaInv         = Mio_LibraryReadAreaInv( p->pGenlib );
Alan Mishchenko committed
135
    p->AreaBuf         = Mio_LibraryReadAreaBuf( p->pGenlib );
Alan Mishchenko committed
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

    // assign the interver supergate
    p->pSuperInv = (Map_Super_t *)Extra_MmFixedEntryFetch( p->mmSupers );
    memset( p->pSuperInv, 0, sizeof(Map_Super_t) );
    p->pSuperInv->Num         = -1;
    p->pSuperInv->nGates      =  1;
    p->pSuperInv->nFanins     =  1;
    p->pSuperInv->nFanLimit   = 10;
    p->pSuperInv->pFanins[0]  = p->ppSupers[0];
    p->pSuperInv->pRoot       = p->pGateInv;
    p->pSuperInv->Area        = p->AreaInv;
    p->pSuperInv->tDelayMax   = p->tDelayInv;
    p->pSuperInv->tDelaysR[0].Rise = MAP_NO_VAR;
    p->pSuperInv->tDelaysR[0].Fall = p->tDelayInv.Rise;
    p->pSuperInv->tDelaysF[0].Rise = p->tDelayInv.Fall;
    p->pSuperInv->tDelaysF[0].Fall = MAP_NO_VAR;
    return p;
}


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

  Synopsis    [Deallocates the supergate library.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Map_SuperLibFree( Map_SuperLib_t * p )
{
    if ( p == NULL ) return;
    if ( p->pGenlib )
    {
172 173
        if ( p->pGenlib != Abc_FrameReadLibGen() )
            Mio_LibraryDelete( p->pGenlib );
174
        p->pGenlib = NULL;
Alan Mishchenko committed
175 176 177 178 179
    }
    if ( p->tTableC )
        Map_SuperTableFree( p->tTableC );
    if ( p->tTable )
        Map_SuperTableFree( p->tTable );
Alan Mishchenko committed
180 181 182
    Extra_MmFixedStop( p->mmSupers );
    Extra_MmFixedStop( p->mmEntries );
    Extra_MmFlexStop( p->mmForms );
Alan Mishchenko committed
183
    ABC_FREE( p->ppSupers );
184
    ABC_FREE( p->pName );
Alan Mishchenko committed
185
    ABC_FREE( p );
Alan Mishchenko committed
186 187 188 189 190 191 192 193 194 195 196 197 198
}

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

  Synopsis    [Derives the library from the genlib library.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
199
int Map_SuperLibDeriveFromGenlib( Mio_Library_t * pLib, int fVerbose )
Alan Mishchenko committed
200
{
201 202 203 204 205
    Map_SuperLib_t * pLibSuper;
    Vec_Str_t * vStr;
    char * pFileName;
    if ( pLib == NULL )
        return 0;
206

207 208 209 210
    // compute supergates
    vStr = Super_PrecomputeStr( pLib, 5, 1, 100000000, 10000000, 10000000, 100, 1, 0 );
    if ( vStr == NULL )
        return 0;
211

212 213
    // create supergate library
    pFileName = Extra_FileNameGenericAppend( Mio_LibraryReadName(pLib), ".super" );
214
    pLibSuper = Map_SuperLibCreate( pLib, vStr, pFileName, NULL, 1, 0 );
215
    Vec_StrFree( vStr );
216

217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
    // replace the library
    Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() );
    Abc_FrameSetLibSuper( pLibSuper );
    return 1;
}

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

  Synopsis    [Derives the library from the genlib library.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Map_SuperLibDeriveFromGenlib2( Mio_Library_t * pLib, int fVerbose )
{
Alan Mishchenko committed
236
    Abc_Frame_t * pAbc = Abc_FrameGetGlobalFrame();
237
    char * pFileName;
Alan Mishchenko committed
238 239
    if ( pLib == NULL )
        return 0;
240 241
    // compute supergates
    pFileName = Extra_FileNameGenericAppend(Mio_LibraryReadName(pLib), ".super");
242 243
    Super_Precompute( pLib, 5, 1, 100000000, 10000000, 10000000, 100, 1, 0, pFileName );
    // assuming that it terminated successfully
244
    if ( Cmd_CommandExecute( pAbc, pFileName ) )
Alan Mishchenko committed
245
    {
246
        fprintf( stdout, "Cannot execute command \"read_super %s\".\n", pFileName );
Alan Mishchenko committed
247 248
        return 0;
    }
249
    return 1;
Alan Mishchenko committed
250 251 252 253 254 255 256
}

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


257 258
ABC_NAMESPACE_IMPL_END