abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
super.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [super.c]
4 
5  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
6 
7  Synopsis [Pre-computation of supergates.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 1.0. Started - August 18, 2003.]
14 
15  Revision [$Id: super.c,v 1.6 2004/10/30 20:51:11 satrajit Exp $]
16 
17 ***********************************************************************/
18 
19 #include "superInt.h"
20 #include "base/main/mainInt.h"
21 #include "map/mio/mio.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 static int Super_CommandSupergates ( Abc_Frame_t * pAbc, int argc, char **argv );
31 static int Super_CommandSupergatesAnd( Abc_Frame_t * pAbc, int argc, char **argv );
32 
33 ////////////////////////////////////////////////////////////////////////
34 /// FUNCTION DEFINITIONS ///
35 ////////////////////////////////////////////////////////////////////////
36 
37 /**Function*************************************************************
38 
39  Synopsis []
40 
41  Description []
42 
43  SideEffects []
44 
45  SeeAlso []
46 
47 ***********************************************************************/
48 void Super_Init( Abc_Frame_t * pAbc )
49 {
50  Cmd_CommandAdd( pAbc, "SC mapping", "super", Super_CommandSupergates, 0 );
51  Cmd_CommandAdd( pAbc, "SC mapping", "super2", Super_CommandSupergatesAnd, 0 );
52 }
53 
54 /**Function*************************************************************
55 
56  Synopsis []
57 
58  Description []
59 
60  SideEffects []
61 
62  SeeAlso []
63 
64 ***********************************************************************/
65 void Super_End( Abc_Frame_t * pAbc )
66 {
67 }
68 
69 
70 
71 /**Function*************************************************************
72 
73  Synopsis []
74 
75  Description []
76 
77  SideEffects []
78 
79  SeeAlso []
80 
81 ***********************************************************************/
82 int Super_CommandSupergatesAnd( Abc_Frame_t * pAbc, int argc, char **argv )
83 {
84  FILE * pOut, * pErr;
85  int nVarsMax, nLevels;
86  int fVerbose;
87  int c;
88 
89  pOut = Abc_FrameReadOut(pAbc);
90  pErr = Abc_FrameReadErr(pAbc);
91 
92  // set the defaults
93  nVarsMax = 4;
94  nLevels = 3;
95  fVerbose = 0;
97  while ( (c = Extra_UtilGetopt(argc, argv, "ILvh")) != EOF )
98  {
99  switch (c)
100  {
101  case 'I':
102  nVarsMax = atoi(argv[globalUtilOptind]);
103  globalUtilOptind++;
104  if ( nVarsMax < 0 )
105  goto usage;
106  break;
107  case 'L':
108  nLevels = atoi(argv[globalUtilOptind]);
109  globalUtilOptind++;
110  if ( nLevels < 0 )
111  goto usage;
112  break;
113  case 'v':
114  fVerbose ^= 1;
115  break;
116  case 'h':
117  goto usage;
118  break;
119  default:
120  goto usage;
121  }
122  }
123 
124  Super2_Precompute( nVarsMax, nLevels, fVerbose );
125 
126  return 0;
127 
128 usage:
129  fprintf( pErr, "usage: super2 [-IL num] [-vh]\n");
130  fprintf( pErr, "\t precomputes the supergates composed of AND2s and INVs\n" );
131  fprintf( pErr, "\t-I num : the max number of inputs to the supergate [default = %d]\n", nVarsMax );
132  fprintf( pErr, "\t-L num : the max number of logic levels of gates [default = %d]\n", nLevels );
133  fprintf( pErr, "\t-v : enable verbose output\n");
134  fprintf( pErr, "\t-h : print the help message\n");
135  return 1; /* error exit */
136 }
137 
138 
139 /**Function*************************************************************
140 
141  Synopsis []
142 
143  Description []
144 
145  SideEffects []
146 
147  SeeAlso []
148 
149 ***********************************************************************/
150 int Super_CommandSupergates( Abc_Frame_t * pAbc, int argc, char **argv )
151 {
152  FILE * pFile;
153  FILE * pOut, * pErr;
154  Mio_Library_t * pLib;
155  char * FileName, * ExcludeFile;
156  float DelayLimit;
157  float AreaLimit;
158  int fSkipInvs;
159  int fWriteOldFormat;
160  int nVarsMax, nLevels, nGatesMax, TimeLimit;
161  int fVerbose;
162  int c;
163 
164  pOut = Abc_FrameReadOut(pAbc);
165  pErr = Abc_FrameReadErr(pAbc);
166 
167  // set the defaults
168  nVarsMax = 5;
169  nLevels = 2;
170  DelayLimit = 0;
171  AreaLimit = 0;
172  nGatesMax = 0;
173  TimeLimit = 0;
174  fSkipInvs = 1;
175  fVerbose = 0;
176  fWriteOldFormat = 0;
177  ExcludeFile = 0;
178 
180  while ( (c = Extra_UtilGetopt(argc, argv, "ILNTDAEsovh")) != EOF )
181  {
182  switch (c)
183  {
184  case 'I':
185  nVarsMax = atoi(argv[globalUtilOptind]);
186  globalUtilOptind++;
187  if ( nVarsMax < 0 )
188  goto usage;
189  break;
190  case 'L':
191  nLevels = atoi(argv[globalUtilOptind]);
192  globalUtilOptind++;
193  if ( nLevels < 0 )
194  goto usage;
195  break;
196  case 'N':
197  nGatesMax = atoi(argv[globalUtilOptind]);
198  globalUtilOptind++;
199  if ( nGatesMax < 0 )
200  goto usage;
201  break;
202  case 'T':
203  TimeLimit = atoi(argv[globalUtilOptind]);
204  globalUtilOptind++;
205  if ( TimeLimit < 0 )
206  goto usage;
207  break;
208  case 'D':
209  DelayLimit = (float)atof(argv[globalUtilOptind]);
210  globalUtilOptind++;
211  if ( DelayLimit <= 0.0 )
212  goto usage;
213  break;
214  case 'A':
215  AreaLimit = (float)atof(argv[globalUtilOptind]);
216  globalUtilOptind++;
217  if ( AreaLimit <= 0.0 )
218  goto usage;
219  break;
220  case 'E':
221  ExcludeFile = argv[globalUtilOptind];
222  if ( ExcludeFile == 0 )
223  goto usage;
224  globalUtilOptind++;
225  break;
226  case 's':
227  fSkipInvs ^= 1;
228  break;
229  case 'o':
230  fWriteOldFormat ^= 1;
231  break;
232  case 'v':
233  fVerbose ^= 1;
234  break;
235  case 'h':
236  goto usage;
237  break;
238  default:
239  goto usage;
240  }
241  }
242 
243 
244  if ( argc != globalUtilOptind + 1 )
245  {
246  fprintf( pErr, "The genlib library file should be given on the command line.\n" );
247  goto usage;
248  }
249 
250  if ( nVarsMax < 2 || nVarsMax > 6 )
251  {
252  fprintf( pErr, "The max number of variables (%d) should be more than 1 and less than 7.\n", nVarsMax );
253  goto usage;
254  }
255 
256  // get the input file name
257  FileName = argv[globalUtilOptind];
258  if ( (pFile = Io_FileOpen( FileName, "open_path", "r", 0 )) == NULL )
259 // if ( (pFile = fopen( FileName, "r" )) == NULL )
260  {
261  fprintf( pErr, "Cannot open input file \"%s\". ", FileName );
262  if (( FileName = Extra_FileGetSimilarName( FileName, ".genlib", ".lib", ".gen", ".g", NULL ) ))
263  fprintf( pErr, "Did you mean \"%s\"?", FileName );
264  fprintf( pErr, "\n" );
265  return 1;
266  }
267  fclose( pFile );
268 
269  // set the new network
270  pLib = Mio_LibraryRead( FileName, NULL, ExcludeFile, fVerbose );
271  if ( pLib == NULL )
272  {
273  fprintf( pErr, "Reading library has failed.\n" );
274  goto usage;
275  }
276 
277  // compute the gates
278  FileName = Extra_FileNameGenericAppend(Mio_LibraryReadName(pLib), ".super");
279  Super_Precompute( pLib, nVarsMax, nLevels, nGatesMax, DelayLimit, AreaLimit, TimeLimit, fSkipInvs, fVerbose, FileName );
280 
281  // delete the library
282  Mio_LibraryDelete( pLib );
283  return 0;
284 
285 usage:
286  fprintf( pErr, "usage: super [-ILNT num] [-DA float] [-E file] [-sovh] <genlib_file>\n");
287  fprintf( pErr, "\t precomputes the supergates for the given genlib library\n" );
288  fprintf( pErr, "\t-I num : the max number of supergate inputs [default = %d]\n", nVarsMax );
289  fprintf( pErr, "\t-L num : the max number of levels of gates [default = %d]\n", nLevels );
290  fprintf( pErr, "\t-N num : the limit on the number of considered supergates [default = %d]\n", nGatesMax );
291  fprintf( pErr, "\t-T num : the approximate runtime limit in seconds [default = %d]\n", TimeLimit );
292  fprintf( pErr, "\t-D float : the max delay of the supergates [default = %.2f]\n", DelayLimit );
293  fprintf( pErr, "\t-A float : the max area of the supergates [default = %.2f]\n", AreaLimit );
294  fprintf( pErr, "\t-E file : file contains list of genlib gates to exclude\n" );
295  fprintf( pErr, "\t-s : toggle the use of inverters at the inputs [default = %s]\n", (fSkipInvs? "no": "yes") );
296  fprintf( pErr, "\t-o : toggle dumping the supergate library in old format [default = %s]\n", (fWriteOldFormat? "yes": "no") );
297  fprintf( pErr, "\t-v : enable verbose output [default = %s]\n", (fVerbose? "yes" : "no") );
298  fprintf( pErr, "\t-h : print the help message\n");
299  fprintf( pErr, "\n");
300  fprintf( pErr, "\tHere is a piece of advice on precomputing supergate libraries:\n");
301  fprintf( pErr, "\t\n");
302  fprintf( pErr, "\tStart with the number of inputs equal to 5 (-I 5), the number of \n");
303  fprintf( pErr, "\tlevels equal to 2 (-L 2), the delay equal to 2-3 delays of inverter, \n");
304  fprintf( pErr, "\tthe area equal to 2-3 areas of two input NAND, and runtime limit equal \n");
305  fprintf( pErr, "\tto 10 seconds (-T 10). Run precomputation and learn from the result.\n");
306  fprintf( pErr, "\tDetermine what parameter is most constraining and try to increase \n");
307  fprintf( pErr, "\tthe value of that parameter. The goal is to have a well-balanced\n");
308  fprintf( pErr, "\tset of constraints and the resulting supergate library containing\n");
309  fprintf( pErr, "\tapproximately 5K-20K supergates. Typically, it is better to increase\n");
310  fprintf( pErr, "\tdelay limit rather than area limit, because having large-area supergates\n");
311  fprintf( pErr, "\tmay result in a considerable increase in area.\n");
312  fprintf( pErr, "\t\n");
313  fprintf( pErr, "\tNote that a good supergate library for experiments typically can be \n");
314  fprintf( pErr, "\tprecomputed in 30 sec or less. Increasing runtime limit makes sense when\n");
315  fprintf( pErr, "\tother parameters are well-balanced and it is needed to enumerate more\n");
316  fprintf( pErr, "\tchoices to have a good result. In the end, to compute the final library\n");
317  fprintf( pErr, "\tthe runtime can be set to 300 sec to ensure the ultimate quality.\n");
318  fprintf( pErr, "\tIn some cases, the runtime has to be reduced if the supergate library\n");
319  fprintf( pErr, "\tcontains too many supergates (> 500K).\n");
320  fprintf( pErr, "\t\n");
321  fprintf( pErr, "\tWhen precomputing libraries of 6 inputs (-i 6), start with even more \n");
322  fprintf( pErr, "\trestricted parameters and gradually increase them until the goal is met.\n");
323  fprintf( pErr, "\t\n");
324  return 1; /* error exit */
325 }
326 
327 ////////////////////////////////////////////////////////////////////////
328 /// END OF FILE ///
329 ////////////////////////////////////////////////////////////////////////
330 
331 
333 
ABC_NAMESPACE_HEADER_START void Super2_Precompute(int nInputs, int nLevels, int fVerbose)
INCLUDES ///.
Definition: superAnd.c:113
FILE * Io_FileOpen(const char *FileName, const char *PathVar, const char *Mode, int fVerbose)
Definition: ioUtil.c:819
Mio_Library_t * Mio_LibraryRead(char *FileName, char *pBuffer, char *ExcludeFile, int fVerbose)
Definition: mioRead.c:54
void Mio_LibraryDelete(Mio_Library_t *pLib)
DECLARATIONS ///.
Definition: mioUtils.c:48
char * Extra_FileGetSimilarName(char *pFileNameWrong, char *pS1, char *pS2, char *pS3, char *pS4, char *pS5)
Definition: extraUtilFile.c:71
void Super_Precompute(Mio_Library_t *pLibGen, int nVarsMax, int nLevels, int nGatesMax, float tDelayMax, float tAreaMax, int TimeLimit, int fSkipInv, int fVerbose, char *pFileName)
FUNCTION DEFINITIONS ///.
Definition: superGate.c:140
void Cmd_CommandAdd(Abc_Frame_t *pAbc, const char *sGroup, const char *sName, Cmd_CommandFuncType pFunc, int fChanges)
Definition: cmdApi.c:63
char * Mio_LibraryReadName(Mio_Library_t *pLib)
DECLARATIONS ///.
Definition: mioApi.c:43
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
ABC_DLL void Extra_UtilGetoptReset()
Definition: extraUtilUtil.c:80
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static ABC_NAMESPACE_IMPL_START int Super_CommandSupergates(Abc_Frame_t *pAbc, int argc, char **argv)
DECLARATIONS ///.
Definition: super.c:150
int globalUtilOptind
Definition: extraUtilUtil.c:45
STRUCTURE DEFINITIONS ///.
Definition: mioInt.h:61
double atof()
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Super_CommandSupergatesAnd(Abc_Frame_t *pAbc, int argc, char **argv)
Definition: super.c:82
int Extra_UtilGetopt(int argc, char *argv[], const char *optstring)
Definition: extraUtilUtil.c:98
ABC_DLL FILE * Abc_FrameReadErr(Abc_Frame_t *p)
Definition: mainFrame.c:330
char * Extra_FileNameGenericAppend(char *pBase, char *pSuffix)
ABC_DLL FILE * Abc_FrameReadOut(Abc_Frame_t *p)
Definition: mainFrame.c:314
void Super_End(Abc_Frame_t *pAbc)
Definition: super.c:65
void Super_Init(Abc_Frame_t *pAbc)
FUNCTION DEFINITIONS ///.
Definition: super.c:48