mapperLib.c 7.95 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 25

#include "mapperInt.h"

26 27 28
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
29 30 31 32 33
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

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

/**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     []

***********************************************************************/
56
Map_SuperLib_t * Map_SuperLibCreate( char * pFileName, char * pExcludeFile, int fAlgorithm, int fVerbose )
Alan Mishchenko committed
57 58
{
    Map_SuperLib_t * p;
59
    clock_t clk;
Alan Mishchenko committed
60 61

    // start the supergate library
Alan Mishchenko committed
62
    p = ABC_ALLOC( Map_SuperLib_t, 1 );
Alan Mishchenko committed
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
    memset( p, 0, sizeof(Map_SuperLib_t) );
    p->pName     = pFileName;
    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
clk = clock();
    if ( fAlgorithm )
    {
        if ( !Map_LibraryReadTree( p, pFileName, pExcludeFile ) )
        {
            Map_SuperLibFree( p );
            return NULL;
        }
    }
    else
    {
        if ( pExcludeFile != 0 )
        {
89
            Map_SuperLibFree( p );
Alan Mishchenko committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
            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
if ( fVerbose ) {
    printf( "Loaded %d unique %d-input supergates from \"%s\".  ", 
        p->nSupersReal, p->nVarsMax, pFileName );
Alan Mishchenko committed
105
    ABC_PRT( "Time", clock() - clk );
Alan Mishchenko committed
106 107 108 109 110 111 112 113
}

    // 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
114
    p->AreaBuf         = Mio_LibraryReadAreaBuf( p->pGenlib );
Alan Mishchenko committed
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

    // 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 )
    {
Alan Mishchenko committed
151
        assert( p->pGenlib == Abc_FrameReadLibGen() );
Alan Mishchenko committed
152
        Mio_LibraryDelete( p->pGenlib );
Alan Mishchenko committed
153
        Abc_FrameSetLibGen( NULL );
Alan Mishchenko committed
154 155 156 157 158
    }
    if ( p->tTableC )
        Map_SuperTableFree( p->tTableC );
    if ( p->tTable )
        Map_SuperTableFree( p->tTable );
Alan Mishchenko committed
159 160 161
    Extra_MmFixedStop( p->mmSupers );
    Extra_MmFixedStop( p->mmEntries );
    Extra_MmFlexStop( p->mmForms );
Alan Mishchenko committed
162 163
    ABC_FREE( p->ppSupers );
    ABC_FREE( p );
Alan Mishchenko committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
}

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

  Synopsis    [Derives the library from the genlib library.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Map_SuperLibDeriveFromGenlib( Mio_Library_t * pLib )
{
    Abc_Frame_t * pAbc = Abc_FrameGetGlobalFrame();
    char * pNameGeneric;
Alan Mishchenko committed
181 182 183 184
    char * FileNameGenlib;
    char * FileNameSuper;
    char * CommandSuper;
    char * CommandRead;
Alan Mishchenko committed
185 186 187 188 189
    FILE * pFile;

    if ( pLib == NULL )
        return 0;

Alan Mishchenko committed
190 191 192 193 194
    FileNameGenlib = ABC_ALLOC( char, 10000 );
    FileNameSuper = ABC_ALLOC( char, 10000 );
    CommandSuper = ABC_ALLOC( char, 10000 );
    CommandRead = ABC_ALLOC( char, 10000 );

Alan Mishchenko committed
195
    // write the current library into the file
Alan Mishchenko committed
196
    sprintf( FileNameGenlib, "%s_temp", Mio_LibraryReadName(pLib) );
Alan Mishchenko committed
197 198 199 200 201 202 203
    pFile = fopen( FileNameGenlib, "w" );
    Mio_WriteLibrary( pFile, pLib, 0 );
    fclose( pFile );

    // get the file name with the library
    pNameGeneric = Extra_FileNameGeneric( Mio_LibraryReadName(pLib) );
    sprintf( FileNameSuper, "%s.super", pNameGeneric );
Alan Mishchenko committed
204
    ABC_FREE( pNameGeneric );
205
 
206
    sprintf( CommandSuper,  "super -L 1 -I 5 -D 10000000 -A 10000000 -T 100 %s", FileNameGenlib ); 
Alan Mishchenko committed
207 208
    if ( Cmd_CommandExecute( pAbc, CommandSuper ) )
    {
Alan Mishchenko committed
209 210 211 212
        ABC_FREE( FileNameGenlib );
        ABC_FREE( FileNameSuper );
        ABC_FREE( CommandSuper );
        ABC_FREE( CommandRead );
Alan Mishchenko committed
213 214 215 216 217 218 219 220
        fprintf( stdout, "Cannot execute command \"%s\".\n", CommandSuper );
        return 0;
    }
//#ifdef WIN32
//        _unlink( FileNameGenlib );
//#else
//        unlink( FileNameGenlib );
//#endif
221 222
    printf( "A simple supergate library is derived from gate library \"%s\".\n", Mio_LibraryReadName(pLib) );
    fflush( stdout );
Alan Mishchenko committed
223 224 225 226

    sprintf( CommandRead,  "read_super %s", FileNameSuper ); 
    if ( Cmd_CommandExecute( pAbc, CommandRead ) )
    {
227 228 229 230 231
//#ifdef WIN32
//        _unlink( FileNameSuper );
//#else
//       unlink( FileNameSuper );
//#endif
Alan Mishchenko committed
232
        fprintf( stdout, "Cannot execute command \"%s\".\n", CommandRead );
Alan Mishchenko committed
233 234 235 236
        ABC_FREE( FileNameGenlib );
        ABC_FREE( FileNameSuper );
        ABC_FREE( CommandSuper );
        ABC_FREE( CommandRead );
Alan Mishchenko committed
237 238
        return 0;
    }
239 240 241 242 243
//#ifdef WIN32
//    _unlink( FileNameSuper );
//#else
//    unlink( FileNameSuper );
//#endif
Alan Mishchenko committed
244 245 246 247
    ABC_FREE( FileNameGenlib );
    ABC_FREE( FileNameSuper );
    ABC_FREE( CommandSuper );
    ABC_FREE( CommandRead );
248
    return 1;
Alan Mishchenko committed
249 250 251 252 253 254 255 256
}


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


257 258
ABC_NAMESPACE_IMPL_END