super.c 11.3 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
/**CFile****************************************************************

  FileName    [super.c]

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

  Synopsis    [Pre-computation of supergates.]

  Author      [MVSIS Group]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - August 18, 2003.]

  Revision    [$Id: super.c,v 1.6 2004/10/30 20:51:11 satrajit Exp $]

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

#include "superInt.h"
20 21
#include "base/main/mainInt.h"
#include "map/mio/mio.h"
Alan Mishchenko committed
22

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29 30 31 32 33
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

static int Super_CommandSupergates   ( Abc_Frame_t * pAbc, int argc, char **argv );
static int Super_CommandSupergatesAnd( Abc_Frame_t * pAbc, int argc, char **argv );

////////////////////////////////////////////////////////////////////////
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 56 57 58 59 60 61 62 63 64
////////////////////////////////////////////////////////////////////////

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Super_Init( Abc_Frame_t * pAbc )
{
    Cmd_CommandAdd( pAbc, "SC mapping",  "super",   Super_CommandSupergates,    0 ); 
    Cmd_CommandAdd( pAbc, "SC mapping",  "super2",  Super_CommandSupergatesAnd, 0 ); 
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
65
void Super_End( Abc_Frame_t * pAbc )
Alan Mishchenko committed
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
{
}



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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Super_CommandSupergatesAnd( Abc_Frame_t * pAbc, int argc, char **argv )
{
    FILE * pOut, * pErr;
    int nVarsMax, nLevels;
    int fVerbose;
    int c;

    pOut = Abc_FrameReadOut(pAbc);
    pErr = Abc_FrameReadErr(pAbc);

    // set the defaults
    nVarsMax = 4;
    nLevels  = 3;
    fVerbose = 0;
Alan Mishchenko committed
96
    Extra_UtilGetoptReset();
97
    while ( (c = Extra_UtilGetopt(argc, argv, "ILvh")) != EOF ) 
Alan Mishchenko committed
98 99 100
    {
        switch (c) 
        {
101
            case 'I':
Alan Mishchenko committed
102 103
                nVarsMax = atoi(argv[globalUtilOptind]);
                globalUtilOptind++;
Alan Mishchenko committed
104 105 106
                if ( nVarsMax < 0 ) 
                    goto usage;
                break;
107
            case 'L':
Alan Mishchenko committed
108 109
                nLevels = atoi(argv[globalUtilOptind]);
                globalUtilOptind++;
Alan Mishchenko committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
                if ( nLevels < 0 ) 
                    goto usage;
                break;
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
        }
    }

    Super2_Precompute( nVarsMax, nLevels, fVerbose );

    return 0;

usage:
129
    fprintf( pErr, "usage: super2 [-IL num] [-vh]\n");
Alan Mishchenko committed
130
    fprintf( pErr, "\t         precomputes the supergates composed of AND2s and INVs\n" );  
131 132
    fprintf( pErr, "\t-I num : the max number of inputs to the supergate [default = %d]\n", nVarsMax );
    fprintf( pErr, "\t-L num : the max number of logic levels of gates [default = %d]\n", nLevels );
Alan Mishchenko committed
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
    fprintf( pErr, "\t-v     : enable verbose output\n");
    fprintf( pErr, "\t-h     : print the help message\n");
    return 1;       /* error exit */
}


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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Super_CommandSupergates( Abc_Frame_t * pAbc, int argc, char **argv )
{
    FILE * pFile;
    FILE * pOut, * pErr;
    Mio_Library_t * pLib;
    char * FileName, * ExcludeFile;
    float DelayLimit;
    float AreaLimit;
158 159
    int fSkipInvs;
    int fWriteOldFormat; 
160
    int nVarsMax, nLevels, nGatesMax, TimeLimit;
Alan Mishchenko committed
161 162 163 164 165 166 167 168 169 170 171
    int fVerbose;
    int c;

    pOut = Abc_FrameReadOut(pAbc);
    pErr = Abc_FrameReadErr(pAbc);

    // set the defaults
    nVarsMax   = 5;
    nLevels    = 3;
    DelayLimit = 3.5;
    AreaLimit  = 9;
172
    nGatesMax  = 1000000;
Alan Mishchenko committed
173 174 175 176 177 178
    TimeLimit  = 10;
    fSkipInvs  = 1;
    fVerbose   = 0;
    fWriteOldFormat = 0;
    ExcludeFile = 0;

Alan Mishchenko committed
179
    Extra_UtilGetoptReset();
180
    while ( (c = Extra_UtilGetopt(argc, argv, "ILNTDAEsovh")) != EOF ) 
Alan Mishchenko committed
181 182 183
    {
        switch (c) 
        {
184
            case 'I':
Alan Mishchenko committed
185 186
                nVarsMax = atoi(argv[globalUtilOptind]);
                globalUtilOptind++;
Alan Mishchenko committed
187 188 189
                if ( nVarsMax < 0 ) 
                    goto usage;
                break;
190
            case 'L':
Alan Mishchenko committed
191 192
                nLevels = atoi(argv[globalUtilOptind]);
                globalUtilOptind++;
Alan Mishchenko committed
193 194 195
                if ( nLevels < 0 ) 
                    goto usage;
                break;
196 197 198 199 200 201 202
            case 'N':
                nGatesMax = atoi(argv[globalUtilOptind]);
                globalUtilOptind++;
                if ( nGatesMax < 0 ) 
                    goto usage;
                break;
            case 'T':
Alan Mishchenko committed
203 204
                TimeLimit = atoi(argv[globalUtilOptind]);
                globalUtilOptind++;
Alan Mishchenko committed
205 206 207
                if ( TimeLimit < 0 ) 
                    goto usage;
                break;
208
            case 'D':
Alan Mishchenko committed
209 210
                DelayLimit = (float)atof(argv[globalUtilOptind]);
                globalUtilOptind++;
Alan Mishchenko committed
211 212 213
                if ( DelayLimit <= 0.0 ) 
                    goto usage;
                break;
214
            case 'A':
Alan Mishchenko committed
215 216
                AreaLimit = (float)atof(argv[globalUtilOptind]);
                globalUtilOptind++;
Alan Mishchenko committed
217 218 219
                if ( AreaLimit <= 0.0 ) 
                    goto usage;
                break;
220 221 222 223 224 225
            case 'E':
                ExcludeFile = argv[globalUtilOptind];
                if ( ExcludeFile == 0 )
                    goto usage;
                globalUtilOptind++;
                break;
Alan Mishchenko committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
            case 's':
                fSkipInvs ^= 1;
                break;
            case 'o':
                fWriteOldFormat ^= 1;
                break;
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
        }
    }


Alan Mishchenko committed
244
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
245 246 247 248 249 250 251 252 253 254 255 256
    {
        fprintf( pErr, "The GENLIB library file should be given on the command line.\n" );
        goto usage;
    }

    if ( nVarsMax < 2 || nVarsMax > 6 )
    {
        fprintf( pErr, "The max number of variables (%d) should be more than 1 and less than 7.\n", nVarsMax );
        goto usage;
    }

    // get the input file name
Alan Mishchenko committed
257 258 259
    FileName = argv[globalUtilOptind];
    if ( (pFile = Io_FileOpen( FileName, "open_path", "r", 0 )) == NULL )
//    if ( (pFile = fopen( FileName, "r" )) == NULL )
Alan Mishchenko committed
260 261 262 263 264 265 266 267 268 269
    {
        fprintf( pErr, "Cannot open input file \"%s\". ", FileName );
        if (( FileName = Extra_FileGetSimilarName( FileName, ".genlib", ".lib", ".gen", ".g", NULL ) ))
            fprintf( pErr, "Did you mean \"%s\"?", FileName );
        fprintf( pErr, "\n" );
        return 1;
    }
    fclose( pFile );

    // set the new network
270
    pLib = Mio_LibraryRead( FileName, ExcludeFile, fVerbose );
Alan Mishchenko committed
271 272 273 274 275 276 277
    if ( pLib == NULL )
    {
        fprintf( pErr, "Reading library has failed.\n" );
        goto usage;
    }

    // compute the gates
278
    Super_Precompute( pLib, nVarsMax, nLevels, nGatesMax, DelayLimit, AreaLimit, TimeLimit, fSkipInvs, fWriteOldFormat, fVerbose );
Alan Mishchenko committed
279 280 281 282 283 284

    // delete the library
    Mio_LibraryDelete( pLib );
    return 0;

usage:
285
    fprintf( pErr, "usage: super [-ILNT num] [-DA float] [-E file] [-sovh] <genlib_file>\n");
Alan Mishchenko committed
286
    fprintf( pErr, "\t         precomputes the supergates for the given GENLIB library\n" );  
287 288 289 290 291 292 293
    fprintf( pErr, "\t-I num   : the max number of supergate inputs [default = %d]\n", nVarsMax );
    fprintf( pErr, "\t-L num   : the max number of levels of gates [default = %d]\n", nLevels );
    fprintf( pErr, "\t-N num   : the limit on the number of considered supergates [default = %d]\n", nGatesMax );
    fprintf( pErr, "\t-T num   : the approximate runtime limit in seconds [default = %d]\n", TimeLimit );
    fprintf( pErr, "\t-D float : the max delay of the supergates [default = %.2f]\n", DelayLimit );
    fprintf( pErr, "\t-A float : the max area of the supergates [default = %.2f]\n", AreaLimit );
    fprintf( pErr, "\t-E file  : file contains list of genlib gates to exclude\n" );
Alan Mishchenko committed
294 295 296 297 298 299 300
    fprintf( pErr, "\t-s       : toggle the use of inverters at the inputs [default = %s]\n", (fSkipInvs? "no": "yes") );
    fprintf( pErr, "\t-o       : toggle dumping the supergate library in old format [default = %s]\n", (fWriteOldFormat? "yes": "no") );
    fprintf( pErr, "\t-v       : enable verbose output [default = %s]\n", (fVerbose? "yes" : "no") );
    fprintf( pErr, "\t-h       : print the help message\n");
    fprintf( pErr, "\n");
    fprintf( pErr, "\tHere is a piece of advice on precomputing supergate libraries:\n");
    fprintf( pErr, "\t\n");
301 302 303 304
    fprintf( pErr, "\tStart with the number of inputs equal to 5 (-I 5), the number of \n");
    fprintf( pErr, "\tlevels equal to 2 (-L 2), the delay equal to 2-3 delays of inverter, \n");
    fprintf( pErr, "\tthe area equal to 2-3 areas of two input NAND, and runtime limit equal \n");
    fprintf( pErr, "\tto 10 seconds (-T 10). Run precomputation and learn from the result.\n");
Alan Mishchenko committed
305 306 307
    fprintf( pErr, "\tDetermine what parameter is most constraining and try to increase \n");
    fprintf( pErr, "\tthe value of that parameter. The goal is to have a well-balanced\n");
    fprintf( pErr, "\tset of constraints and the resulting supergate library containing\n");
308
    fprintf( pErr, "\tapproximately 5K-20K supergates. Typically, it is better to increase\n");
Alan Mishchenko committed
309 310 311 312
    fprintf( pErr, "\tdelay limit rather than area limit, because having large-area supergates\n");
    fprintf( pErr, "\tmay result in a considerable increase in area.\n");
    fprintf( pErr, "\t\n");
    fprintf( pErr, "\tNote that a good supergate library for experiments typically can be \n");
313
    fprintf( pErr, "\tprecomputed in 30 sec or less. Increasing runtime limit makes sense when\n");
Alan Mishchenko committed
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
    fprintf( pErr, "\tother parameters are well-balanced and it is needed to enumerate more\n");
    fprintf( pErr, "\tchoices to have a good result. In the end, to compute the final library\n");
    fprintf( pErr, "\tthe runtime can be set to 300 sec to ensure the ultimate quality.\n");
    fprintf( pErr, "\tIn some cases, the runtime has to be reduced if the supergate library\n");
    fprintf( pErr, "\tcontains too many supergates (> 500K).\n");
    fprintf( pErr, "\t\n");
    fprintf( pErr, "\tWhen precomputing libraries of 6 inputs (-i 6), start with even more \n");
    fprintf( pErr, "\trestricted parameters and gradually increase them until the goal is met.\n");
    fprintf( pErr, "\t\n");
    return 1;       /* error exit */
}

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


331 332
ABC_NAMESPACE_IMPL_END