abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sclLibScl.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [sclLibScl.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Standard-cell library representation.]
8 
9  Synopsis [Liberty abstraction for delay-oriented mapping.]
10 
11  Author [Alan Mishchenko, Niklas Een]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - August 24, 2012.]
16 
17  Revision [$Id: sclLibScl.c,v 1.0 2012/08/24 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "sclLib.h"
22 #include "misc/st/st.h"
23 #include "map/mio/mio.h"
24 #include "bool/kit/kit.h"
25 
27 
28 
29 ////////////////////////////////////////////////////////////////////////
30 /// DECLARATIONS ///
31 ////////////////////////////////////////////////////////////////////////
32 
33 ////////////////////////////////////////////////////////////////////////
34 /// FUNCTION DEFINITIONS ///
35 ////////////////////////////////////////////////////////////////////////
36 
37 /**Function*************************************************************
38 
39  Synopsis [Reading library from file.]
40 
41  Description []
42 
43  SideEffects []
44 
45  SeeAlso []
46 
47 ***********************************************************************/
48 static void Abc_SclReadSurface( Vec_Str_t * vOut, int * pPos, SC_Surface * p )
49 {
50  Vec_Flt_t * vVec;
51  int i, j;
52 
53  for ( i = Vec_StrGetI(vOut, pPos); i != 0; i-- )
54  Vec_FltPush( p->vIndex0, Vec_StrGetF(vOut, pPos) );
55 
56  for ( i = Vec_StrGetI(vOut, pPos); i != 0; i-- )
57  Vec_FltPush( p->vIndex1, Vec_StrGetF(vOut, pPos) );
58 
59  for ( i = 0; i < Vec_FltSize(p->vIndex0); i++ )
60  {
61  vVec = Vec_FltAlloc( Vec_FltSize(p->vIndex1) );
62  Vec_PtrPush( p->vData, vVec );
63  for ( j = 0; j < Vec_FltSize(p->vIndex1); j++ )
64  Vec_FltPush( vVec, Vec_StrGetF(vOut, pPos) );
65  }
66 
67  for ( i = 0; i < 3; i++ )
68  p->approx[0][i] = Vec_StrGetF( vOut, pPos );
69  for ( i = 0; i < 4; i++ )
70  p->approx[1][i] = Vec_StrGetF( vOut, pPos );
71  for ( i = 0; i < 6; i++ )
72  p->approx[2][i] = Vec_StrGetF( vOut, pPos );
73 }
74 static int Abc_SclReadLibrary( Vec_Str_t * vOut, int * pPos, SC_Lib * p )
75 {
76  int i, j, k, n;
77  int version = Vec_StrGetI( vOut, pPos );
78  if ( version != ABC_SCL_CUR_VERSION )
79  {
80  Abc_Print( -1, "Wrong version of the SCL file.\n" );
81  return 0;
82  }
83  assert( version == ABC_SCL_CUR_VERSION ); // wrong version of the file
84 
85  // Read non-composite fields:
86  p->pName = Vec_StrGetS(vOut, pPos);
87  p->default_wire_load = Vec_StrGetS(vOut, pPos);
88  p->default_wire_load_sel = Vec_StrGetS(vOut, pPos);
89  p->default_max_out_slew = Vec_StrGetF(vOut, pPos);
90 
91  p->unit_time = Vec_StrGetI(vOut, pPos);
92  p->unit_cap_fst = Vec_StrGetF(vOut, pPos);
93  p->unit_cap_snd = Vec_StrGetI(vOut, pPos);
94 
95  // Read 'wire_load' vector:
96  for ( i = Vec_StrGetI(vOut, pPos); i != 0; i-- )
97  {
99  Vec_PtrPush( p->vWireLoads, pWL );
100 
101  pWL->pName = Vec_StrGetS(vOut, pPos);
102  pWL->cap = Vec_StrGetF(vOut, pPos);
103  pWL->slope = Vec_StrGetF(vOut, pPos);
104 
105  for ( j = Vec_StrGetI(vOut, pPos); j != 0; j-- )
106  {
107  Vec_IntPush( pWL->vFanout, Vec_StrGetI(vOut, pPos) );
108  Vec_FltPush( pWL->vLen, Vec_StrGetF(vOut, pPos) );
109  }
110  }
111 
112  // Read 'wire_load_sel' vector:
113  for ( i = Vec_StrGetI(vOut, pPos); i != 0; i-- )
114  {
116  Vec_PtrPush( p->vWireLoadSels, pWLS );
117 
118  pWLS->pName = Vec_StrGetS(vOut, pPos);
119  for ( j = Vec_StrGetI(vOut, pPos); j != 0; j-- )
120  {
121  Vec_FltPush( pWLS->vAreaFrom, Vec_StrGetF(vOut, pPos) );
122  Vec_FltPush( pWLS->vAreaTo, Vec_StrGetF(vOut, pPos) );
123  Vec_PtrPush( pWLS->vWireLoadModel, Vec_StrGetS(vOut, pPos) );
124  }
125  }
126 
127  for ( i = Vec_StrGetI(vOut, pPos); i != 0; i-- )
128  {
129  SC_Cell * pCell = Abc_SclCellAlloc();
130  pCell->Id = SC_LibCellNum(p);
131  Vec_PtrPush( p->vCells, pCell );
132 
133  pCell->pName = Vec_StrGetS(vOut, pPos);
134  pCell->area = Vec_StrGetF(vOut, pPos);
135  pCell->leakage = Vec_StrGetF(vOut, pPos);
136  pCell->drive_strength = Vec_StrGetI(vOut, pPos);
137 
138  pCell->n_inputs = Vec_StrGetI(vOut, pPos);
139  pCell->n_outputs = Vec_StrGetI(vOut, pPos);
140 /*
141  printf( "%s\n", pCell->pName );
142  if ( !strcmp( "XOR3_X4M_A9TL", pCell->pName ) )
143  {
144  int s = 0;
145  }
146 */
147  for ( j = 0; j < pCell->n_inputs; j++ )
148  {
149  SC_Pin * pPin = Abc_SclPinAlloc();
150  Vec_PtrPush( pCell->vPins, pPin );
151 
152  pPin->dir = sc_dir_Input;
153  pPin->pName = Vec_StrGetS(vOut, pPos);
154  pPin->rise_cap = Vec_StrGetF(vOut, pPos);
155  pPin->fall_cap = Vec_StrGetF(vOut, pPos);
156  }
157 
158  for ( j = 0; j < pCell->n_outputs; j++ )
159  {
160  SC_Pin * pPin = Abc_SclPinAlloc();
161  Vec_PtrPush( pCell->vPins, pPin );
162 
163  pPin->dir = sc_dir_Output;
164  pPin->pName = Vec_StrGetS(vOut, pPos);
165  pPin->max_out_cap = Vec_StrGetF(vOut, pPos);
166  pPin->max_out_slew = Vec_StrGetF(vOut, pPos);
167 
168  k = Vec_StrGetI(vOut, pPos);
169  assert( k == pCell->n_inputs );
170 
171  // read function
172  // (possibly empty) formula is always given
173  assert( version == ABC_SCL_CUR_VERSION );
174  assert( pPin->func_text == NULL );
175  pPin->func_text = Vec_StrGetS(vOut, pPos);
176  if ( pPin->func_text[0] == 0 )
177  {
178  // formula is not given - read truth table
179  ABC_FREE( pPin->func_text );
180  assert( Vec_WrdSize(pPin->vFunc) == 0 );
181  Vec_WrdGrow( pPin->vFunc, Abc_Truth6WordNum(pCell->n_inputs) );
182  for ( k = 0; k < Vec_WrdCap(pPin->vFunc); k++ )
183  Vec_WrdPush( pPin->vFunc, Vec_StrGetW(vOut, pPos) );
184  }
185  else
186  {
187  // formula is given - derive truth table
188  SC_Pin * pPin2;
189  Vec_Ptr_t * vNames;
190  // collect input names
191  vNames = Vec_PtrAlloc( pCell->n_inputs );
192  SC_CellForEachPinIn( pCell, pPin2, n )
193  Vec_PtrPush( vNames, pPin2->pName );
194  // derive truth table
195  assert( Vec_WrdSize(pPin->vFunc) == 0 );
196  Vec_WrdFree( pPin->vFunc );
197  pPin->vFunc = Mio_ParseFormulaTruth( pPin->func_text, (char **)Vec_PtrArray(vNames), pCell->n_inputs );
198  Vec_PtrFree( vNames );
199  // skip truth table
200  assert( Vec_WrdSize(pPin->vFunc) == Abc_Truth6WordNum(pCell->n_inputs) );
201  for ( k = 0; k < Vec_WrdSize(pPin->vFunc); k++ )
202  {
203  word Value = Vec_StrGetW(vOut, pPos);
204  assert( Value == Vec_WrdEntry(pPin->vFunc, k) );
205  }
206  }
207 
208  // Read 'rtiming': (pin-to-pin timing tables for this particular output)
209  for ( k = 0; k < pCell->n_inputs; k++ )
210  {
211  SC_Timings * pRTime = Abc_SclTimingsAlloc();
212  Vec_PtrPush( pPin->vRTimings, pRTime );
213 
214  pRTime->pName = Vec_StrGetS(vOut, pPos);
215  n = Vec_StrGetI(vOut, pPos); assert( n <= 1 );
216  if ( n == 1 )
217  {
218  SC_Timing * pTime = Abc_SclTimingAlloc();
219  Vec_PtrPush( pRTime->vTimings, pTime );
220 
221  pTime->tsense = (SC_TSense)Vec_StrGetI(vOut, pPos);
222  Abc_SclReadSurface( vOut, pPos, pTime->pCellRise );
223  Abc_SclReadSurface( vOut, pPos, pTime->pCellFall );
224  Abc_SclReadSurface( vOut, pPos, pTime->pRiseTrans );
225  Abc_SclReadSurface( vOut, pPos, pTime->pFallTrans );
226  }
227  else
228  assert( Vec_PtrSize(pRTime->vTimings) == 0 );
229  }
230  }
231  }
232  return 1;
233 }
235 {
236  SC_Lib * p;
237  int Pos = 0;
238  // read the library
239  p = Abc_SclLibAlloc();
240  if ( !Abc_SclReadLibrary( vOut, &Pos, p ) )
241  return NULL;
242  assert( Pos == Vec_StrSize(vOut) );
243  // hash gates by name
244  Abc_SclHashCells( p );
245  Abc_SclLinkCells( p );
246  return p;
247 }
248 SC_Lib * Abc_SclReadFromFile( char * pFileName )
249 {
250  SC_Lib * p;
251  FILE * pFile;
252  Vec_Str_t * vOut;
253  int nFileSize;
254  pFile = fopen( pFileName, "rb" );
255  if ( pFile == NULL )
256  {
257  printf( "Cannot open file \"%s\" for reading.\n", pFileName );
258  return NULL;
259  }
260  // get the file size, in bytes
261  fseek( pFile, 0, SEEK_END );
262  nFileSize = ftell( pFile );
263  rewind( pFile );
264  // load the contents
265  vOut = Vec_StrAlloc( nFileSize );
266  vOut->nSize = vOut->nCap;
267  assert( nFileSize == Vec_StrSize(vOut) );
268  nFileSize = fread( Vec_StrArray(vOut), 1, Vec_StrSize(vOut), pFile );
269  assert( nFileSize == Vec_StrSize(vOut) );
270  fclose( pFile );
271  // read the library
272  p = Abc_SclReadFromStr( vOut );
273  if ( p != NULL )
274  p->pFileName = Abc_UtilStrsav( pFileName );
275  if ( p != NULL )
276  Abc_SclLibNormalize( p );
277  Vec_StrFree( vOut );
278  return p;
279 }
280 
281 /**Function*************************************************************
282 
283  Synopsis [Writing library into file.]
284 
285  Description []
286 
287  SideEffects []
288 
289  SeeAlso []
290 
291 ***********************************************************************/
292 static void Abc_SclWriteSurface( Vec_Str_t * vOut, SC_Surface * p )
293 {
294  Vec_Flt_t * vVec;
295  float Entry;
296  int i, k;
297 
298  Vec_StrPutI( vOut, Vec_FltSize(p->vIndex0) );
299  Vec_FltForEachEntry( p->vIndex0, Entry, i )
300  Vec_StrPutF( vOut, Entry );
301 
302  Vec_StrPutI( vOut, Vec_FltSize(p->vIndex1) );
303  Vec_FltForEachEntry( p->vIndex1, Entry, i )
304  Vec_StrPutF( vOut, Entry );
305 
306  Vec_PtrForEachEntry( Vec_Flt_t *, p->vData, vVec, i )
307  Vec_FltForEachEntry( vVec, Entry, k )
308  Vec_StrPutF( vOut, Entry );
309 
310  for ( i = 0; i < 3; i++ )
311  Vec_StrPutF( vOut, p->approx[0][i] );
312  for ( i = 0; i < 4; i++ )
313  Vec_StrPutF( vOut, p->approx[1][i] );
314  for ( i = 0; i < 6; i++ )
315  Vec_StrPutF( vOut, p->approx[2][i] );
316 }
317 static void Abc_SclWriteLibrary( Vec_Str_t * vOut, SC_Lib * p )
318 {
319  SC_WireLoad * pWL;
320  SC_WireLoadSel * pWLS;
321  SC_Cell * pCell;
322  SC_Pin * pPin;
323  int n_valid_cells;
324  int i, j, k;
325 
327 
328  // Write non-composite fields:
329  Vec_StrPutS( vOut, p->pName );
330  Vec_StrPutS( vOut, p->default_wire_load );
332  Vec_StrPutF( vOut, p->default_max_out_slew );
333 
334  assert( p->unit_time >= 0 );
335  assert( p->unit_cap_snd >= 0 );
336  Vec_StrPutI( vOut, p->unit_time );
337  Vec_StrPutF( vOut, p->unit_cap_fst );
338  Vec_StrPutI( vOut, p->unit_cap_snd );
339 
340  // Write 'wire_load' vector:
341  Vec_StrPutI( vOut, Vec_PtrSize(p->vWireLoads) );
342  SC_LibForEachWireLoad( p, pWL, i )
343  {
344  Vec_StrPutS( vOut, pWL->pName );
345  Vec_StrPutF( vOut, pWL->cap );
346  Vec_StrPutF( vOut, pWL->slope );
347 
348  Vec_StrPutI( vOut, Vec_IntSize(pWL->vFanout) );
349  for ( j = 0; j < Vec_IntSize(pWL->vFanout); j++ )
350  {
351  Vec_StrPutI( vOut, Vec_IntEntry(pWL->vFanout, j) );
352  Vec_StrPutF( vOut, Vec_FltEntry(pWL->vLen, j) );
353  }
354  }
355 
356  // Write 'wire_load_sel' vector:
358  SC_LibForEachWireLoadSel( p, pWLS, i )
359  {
360  Vec_StrPutS( vOut, pWLS->pName );
361  Vec_StrPutI( vOut, Vec_FltSize(pWLS->vAreaFrom) );
362  for ( j = 0; j < Vec_FltSize(pWLS->vAreaFrom); j++)
363  {
364  Vec_StrPutF( vOut, Vec_FltEntry(pWLS->vAreaFrom, j) );
365  Vec_StrPutF( vOut, Vec_FltEntry(pWLS->vAreaTo, j) );
366  Vec_StrPutS( vOut, (char *)Vec_PtrEntry(pWLS->vWireLoadModel, j) );
367  }
368  }
369 
370  // Write 'cells' vector:
371  n_valid_cells = 0;
372  SC_LibForEachCell( p, pCell, i )
373  if ( !(pCell->seq || pCell->unsupp) )
374  n_valid_cells++;
375 
376  Vec_StrPutI( vOut, n_valid_cells );
377  SC_LibForEachCell( p, pCell, i )
378  {
379  if ( pCell->seq || pCell->unsupp )
380  continue;
381 
382  Vec_StrPutS( vOut, pCell->pName );
383  Vec_StrPutF( vOut, pCell->area );
384  Vec_StrPutF( vOut, pCell->leakage );
385  Vec_StrPutI( vOut, pCell->drive_strength );
386 
387  // Write 'pins': (sorted at this point; first inputs, then outputs)
388  Vec_StrPutI( vOut, pCell->n_inputs);
389  Vec_StrPutI( vOut, pCell->n_outputs);
390 
391  SC_CellForEachPinIn( pCell, pPin, j )
392  {
393  assert(pPin->dir == sc_dir_Input);
394  Vec_StrPutS( vOut, pPin->pName );
395  Vec_StrPutF( vOut, pPin->rise_cap );
396  Vec_StrPutF( vOut, pPin->fall_cap );
397  }
398 
399  SC_CellForEachPinOut( pCell, pPin, j )
400  {
401  SC_Timings * pRTime;
402  word uWord;
403 
404  assert(pPin->dir == sc_dir_Output);
405  Vec_StrPutS( vOut, pPin->pName );
406  Vec_StrPutF( vOut, pPin->max_out_cap );
407  Vec_StrPutF( vOut, pPin->max_out_slew );
408  Vec_StrPutI( vOut, pCell->n_inputs );
409 
410  // write function
411  Vec_StrPutS( vOut, pPin->func_text ? pPin->func_text : (char *)"" );
412 
413  // write truth table
414  assert( Vec_WrdSize(pPin->vFunc) == Abc_Truth6WordNum(pCell->n_inputs) );
415  Vec_WrdForEachEntry( pPin->vFunc, uWord, k ) // -- 'size = 1u << (n_vars - 6)'
416  Vec_StrPutW( vOut, uWord ); // -- 64-bit number, written uncompressed (low-byte first)
417 
418  // Write 'rtiming': (pin-to-pin timing tables for this particular output)
419  assert( Vec_PtrSize(pPin->vRTimings) == pCell->n_inputs );
420  SC_PinForEachRTiming( pPin, pRTime, k )
421  {
422  Vec_StrPutS( vOut, pRTime->pName );
423  Vec_StrPutI( vOut, Vec_PtrSize(pRTime->vTimings) );
424  // -- NOTE! After post-processing, the size of the 'rtiming[k]' vector is either
425  // 0 or 1 (in static timing, we have merged all tables to get the worst case).
426  // The case with size 0 should only occur for multi-output gates.
427  if ( Vec_PtrSize(pRTime->vTimings) == 1 )
428  {
429  SC_Timing * pTime = (SC_Timing *)Vec_PtrEntry( pRTime->vTimings, 0 );
430  // -- NOTE! We don't need to save 'related_pin' string because we have sorted
431  // the elements on input pins.
432  Vec_StrPutI( vOut, (int)pTime->tsense);
433  Abc_SclWriteSurface( vOut, pTime->pCellRise );
434  Abc_SclWriteSurface( vOut, pTime->pCellFall );
435  Abc_SclWriteSurface( vOut, pTime->pRiseTrans );
436  Abc_SclWriteSurface( vOut, pTime->pFallTrans );
437  }
438  else
439  assert( Vec_PtrSize(pRTime->vTimings) == 0 );
440  }
441  }
442  }
443 }
444 void Abc_SclWriteScl( char * pFileName, SC_Lib * p )
445 {
446  Vec_Str_t * vOut;
447  vOut = Vec_StrAlloc( 10000 );
448  Abc_SclWriteLibrary( vOut, p );
449  if ( Vec_StrSize(vOut) > 0 )
450  {
451  FILE * pFile = fopen( pFileName, "wb" );
452  if ( pFile == NULL )
453  printf( "Cannot open file \"%s\" for writing.\n", pFileName );
454  else
455  {
456  fwrite( Vec_StrArray(vOut), 1, Vec_StrSize(vOut), pFile );
457  fclose( pFile );
458  }
459  }
460  Vec_StrFree( vOut );
461 }
462 
463 
464 /**Function*************************************************************
465 
466  Synopsis [Writing library into text file.]
467 
468  Description []
469 
470  SideEffects []
471 
472  SeeAlso []
473 
474 ***********************************************************************/
475 static void Abc_SclWriteSurfaceText( FILE * s, SC_Surface * p )
476 {
477  Vec_Flt_t * vVec;
478  float Entry;
479  int i, k;
480 
481  fprintf( s, " index_1(\"" );
482  Vec_FltForEachEntry( p->vIndex0, Entry, i )
483  fprintf( s, "%f%s", Entry, i == Vec_FltSize(p->vIndex0)-1 ? "":", " );
484  fprintf( s, "\");\n" );
485 
486  fprintf( s, " index_2(\"" );
487  Vec_FltForEachEntry( p->vIndex1, Entry, i )
488  fprintf( s, "%f%s", Entry, i == Vec_FltSize(p->vIndex1)-1 ? "":", " );
489  fprintf( s, "\");\n" );
490 
491  fprintf( s, " values (\"" );
492  Vec_PtrForEachEntry( Vec_Flt_t *, p->vData, vVec, i )
493  {
494  Vec_FltForEachEntry( vVec, Entry, k )
495  fprintf( s, "%f%s", Entry, i == Vec_PtrSize(p->vData)-1 && k == Vec_FltSize(vVec)-1 ? "\");":", " );
496  if ( i == Vec_PtrSize(p->vData)-1 )
497  fprintf( s, "\n" );
498  else
499  {
500  fprintf( s, "\\\n" );
501  fprintf( s, " " );
502  }
503  }
504 /*
505  fprintf( s, " approximations: \n" );
506  fprintf( s, " " );
507  for ( i = 0; i < 3; i++ )
508  fprintf( s, "%f ", p->approx[0][i] );
509  fprintf( s, "\n" );
510  fprintf( s, " " );
511  for ( i = 0; i < 4; i++ )
512  fprintf( s, "%f ", p->approx[1][i] );
513  fprintf( s, "\n" );
514  fprintf( s, " " );
515  for ( i = 0; i < 6; i++ )
516  fprintf( s, "%f ", p->approx[2][i] );
517  fprintf( s, "\n" );
518  fprintf( s, " \n" );
519 */
520 }
521 static void Abc_SclWriteLibraryText( FILE * s, SC_Lib * p )
522 {
523  SC_WireLoad * pWL;
524  SC_WireLoadSel * pWLS;
525  SC_Cell * pCell;
526  SC_Pin * pPin;
527  int n_valid_cells;
528  int i, j, k;
529  fprintf( s, "/* This Liberty file was generated by ABC on %s */\n", Extra_TimeStamp() );
530  fprintf( s, "/* The original unabridged library came from file \"%s\".*/\n\n", p->pFileName );
531 
532 // fprintf( s, "%d", ABC_SCL_CUR_VERSION );
533  fprintf( s, "library(%s) {\n\n", p->pName );
535  fprintf( s, " default_wire_load : \"%s\";\n", p->default_wire_load );
537  fprintf( s, " default_wire_load_selection : \"%s\";\n", p->default_wire_load_sel );
538  if ( p->default_max_out_slew != -1 )
539  fprintf( s, " default_max_transition : %f;\n", p->default_max_out_slew );
540  if ( p->unit_time == 9 )
541  fprintf( s, " time_unit : \"1ns\";\n" );
542  else if ( p->unit_time == 10 )
543  fprintf( s, " time_unit : \"100ps\";\n" );
544  else if ( p->unit_time == 11 )
545  fprintf( s, " time_unit : \"10ps\";\n" );
546  else if ( p->unit_time == 12 )
547  fprintf( s, " time_unit : \"1ps\";\n" );
548  else assert( 0 );
549  fprintf( s, " capacitive_load_unit(%.1f,%s);\n", p->unit_cap_fst, p->unit_cap_snd == 12 ? "pf" : "ff" );
550  fprintf( s, "\n" );
551 
552  // Write 'wire_load' vector:
553  SC_LibForEachWireLoad( p, pWL, i )
554  {
555  fprintf( s, " wire_load(\"%s\") {\n", pWL->pName );
556  fprintf( s, " capacitance : %f;\n", pWL->cap );
557  fprintf( s, " slope : %f;\n", pWL->slope );
558  for ( j = 0; j < Vec_IntSize(pWL->vFanout); j++ )
559  fprintf( s, " fanout_length( %d, %f );\n", Vec_IntEntry(pWL->vFanout, j), Vec_FltEntry(pWL->vLen, j) );
560  fprintf( s, " }\n\n" );
561  }
562 
563  // Write 'wire_load_sel' vector:
564  SC_LibForEachWireLoadSel( p, pWLS, i )
565  {
566  fprintf( s, " wire_load_selection(\"%s\") {\n", pWLS->pName );
567  for ( j = 0; j < Vec_FltSize(pWLS->vAreaFrom); j++)
568  fprintf( s, " wire_load_from_area( %f, %f, %s );\n",
569  Vec_FltEntry(pWLS->vAreaFrom, j),
570  Vec_FltEntry(pWLS->vAreaTo, j),
571  (char *)Vec_PtrEntry(pWLS->vWireLoadModel, j) );
572  fprintf( s, " }\n\n" );
573  }
574 
575  // Write 'cells' vector:
576  n_valid_cells = 0;
577  SC_LibForEachCell( p, pCell, i )
578  if ( !(pCell->seq || pCell->unsupp) )
579  n_valid_cells++;
580 
581  SC_LibForEachCell( p, pCell, i )
582  {
583  if ( pCell->seq || pCell->unsupp )
584  continue;
585 
586  fprintf( s, "\n" );
587  fprintf( s, " cell(%s) {\n", pCell->pName );
588  fprintf( s, " /* n_inputs = %d n_outputs = %d */\n", pCell->n_inputs, pCell->n_outputs );
589  fprintf( s, " area : %f;\n", pCell->area );
590  fprintf( s, " cell_leakage_power : %f;\n", pCell->leakage );
591  fprintf( s, " drive_strength : %d;\n", pCell->drive_strength );
592 
593  SC_CellForEachPinIn( pCell, pPin, j )
594  {
595  assert(pPin->dir == sc_dir_Input);
596  fprintf( s, " pin(%s) {\n", pPin->pName );
597  fprintf( s, " direction : %s;\n", "input" );
598  fprintf( s, " fall_capacitance : %f;\n", pPin->fall_cap );
599  fprintf( s, " rise_capacitance : %f;\n", pPin->rise_cap );
600  fprintf( s, " }\n" );
601  }
602 
603  SC_CellForEachPinOut( pCell, pPin, j )
604  {
605  SC_Timings * pRTime;
606 // word uWord;
607  assert(pPin->dir == sc_dir_Output);
608  fprintf( s, " pin(%s) {\n", pPin->pName );
609  fprintf( s, " direction : %s;\n", "output" );
610  fprintf( s, " max_capacitance : %f;\n", pPin->max_out_cap );
611  fprintf( s, " max_transition : %f;\n", pPin->max_out_slew );
612  fprintf( s, " function : \"%s\";\n", pPin->func_text ? pPin->func_text : "?" );
613  fprintf( s, " /* truth table = " );
614  Extra_PrintHex( s, (unsigned *)Vec_WrdArray(pPin->vFunc), pCell->n_inputs );
615  fprintf( s, " */\n" );
616 
617  // Write 'rtiming': (pin-to-pin timing tables for this particular output)
618  assert( Vec_PtrSize(pPin->vRTimings) == pCell->n_inputs );
619  SC_PinForEachRTiming( pPin, pRTime, k )
620  {
621  if ( Vec_PtrSize(pRTime->vTimings) == 1 )
622  {
623  SC_Timing * pTime = (SC_Timing *)Vec_PtrEntry( pRTime->vTimings, 0 );
624  fprintf( s, " timing() {\n" );
625  fprintf( s, " related_pin : \"%s\"\n", pRTime->pName );
626  if ( pTime->tsense == sc_ts_Pos )
627  fprintf( s, " timing_sense : positive_unate;\n" );
628  else if ( pTime->tsense == sc_ts_Neg )
629  fprintf( s, " timing_sense : negative_unate;\n" );
630  else if ( pTime->tsense == sc_ts_Non )
631  fprintf( s, " timing_sense : non_unate;\n" );
632  else assert( 0 );
633 
634  fprintf( s, " cell_rise() {\n" );
635  Abc_SclWriteSurfaceText( s, pTime->pCellRise );
636  fprintf( s, " }\n" );
637 
638  fprintf( s, " cell_fall() {\n" );
639  Abc_SclWriteSurfaceText( s, pTime->pCellFall );
640  fprintf( s, " }\n" );
641 
642  fprintf( s, " rise_transition() {\n" );
643  Abc_SclWriteSurfaceText( s, pTime->pRiseTrans );
644  fprintf( s, " }\n" );
645 
646  fprintf( s, " fall_transition() {\n" );
647  Abc_SclWriteSurfaceText( s, pTime->pFallTrans );
648  fprintf( s, " }\n" );
649  fprintf( s, " }\n" );
650  }
651  else
652  assert( Vec_PtrSize(pRTime->vTimings) == 0 );
653  }
654  fprintf( s, " }\n" );
655  }
656  fprintf( s, " }\n" );
657  }
658  fprintf( s, "}\n\n" );
659 }
660 void Abc_SclWriteLiberty( char * pFileName, SC_Lib * p )
661 {
662  FILE * pFile = fopen( pFileName, "wb" );
663  if ( pFile == NULL )
664  printf( "Cannot open text file \"%s\" for writing.\n", pFileName );
665  else
666  {
667  Abc_SclWriteLibraryText( pFile, p );
668  fclose( pFile );
669  printf( "Dumped internal library into Liberty file \"%s\".\n", pFileName );
670  }
671 }
672 
673 ////////////////////////////////////////////////////////////////////////
674 /// END OF FILE ///
675 ////////////////////////////////////////////////////////////////////////
676 
677 
679 
int unit_time
Definition: sclLib.h:209
int unsupp
Definition: sclLib.h:187
static void Vec_WrdGrow(Vec_Wrd_t *p, int nCapMin)
Definition: vecWrd.h:469
Vec_Ptr_t * vPins
Definition: sclLib.h:191
SC_Surface * pCellRise
Definition: sclLib.h:155
static int SC_LibCellNum(SC_Lib *p)
Definition: sclLib.h:239
#define Vec_FltForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecFlt.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
float unit_cap_fst
Definition: sclLib.h:210
static word Vec_StrGetW(Vec_Str_t *vOut, int *pPos)
Definition: vecStr.h:852
static SC_WireLoad * Abc_SclWireLoadAlloc()
FUNCTION DEFINITIONS ///.
Definition: sclLib.h:276
char * pFileName
Definition: sclLib.h:205
char * pName
Definition: sclLib.h:163
#define SC_CellForEachPinIn(p, pPin, i)
Definition: sclLib.h:254
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_StrPutW(Vec_Str_t *vOut, word Val)
Definition: vecStr.h:846
static char * Vec_StrArray(Vec_Str_t *p)
Definition: vecStr.h:272
float fall_cap
Definition: sclLib.h:173
float slope
Definition: sclLib.h:121
ush Pos
Definition: deflate.h:88
static int Abc_Truth6WordNum(int nVars)
Definition: abc_global.h:257
static void Vec_WrdPush(Vec_Wrd_t *p, word Entry)
Definition: vecWrd.h:618
char * default_wire_load
Definition: sclLib.h:206
#define SEEK_END
Definition: zconf.h:392
static float Vec_StrGetF(Vec_Str_t *vOut, int *pPos)
Definition: vecStr.h:870
Vec_Ptr_t * vRTimings
Definition: sclLib.h:178
static int Vec_WrdCap(Vec_Wrd_t *p)
Definition: vecWrd.h:352
Vec_Flt_t * vAreaTo
Definition: sclLib.h:130
Vec_Wrd_t * Mio_ParseFormulaTruth(char *pFormInit, char **ppVarNames, int nVars)
Definition: mioParse.c:396
float approx[3][6]
Definition: sclLib.h:147
Vec_Ptr_t * vData
Definition: sclLib.h:146
static int Abc_SclReadLibrary(Vec_Str_t *vOut, int *pPos, SC_Lib *p)
Definition: sclLibScl.c:74
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static Vec_Flt_t * Vec_FltAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecFlt.h:78
Vec_Ptr_t * vWireLoadModel
Definition: sclLib.h:131
char * pName
Definition: sclLib.h:128
float leakage
Definition: sclLib.h:189
Vec_Ptr_t * vWireLoads
Definition: sclLib.h:212
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
Vec_Flt_t * vLen
Definition: sclLib.h:123
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static int Vec_WrdSize(Vec_Wrd_t *p)
Definition: vecWrd.h:336
#define Vec_WrdForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecWrd.h:54
static void Vec_FltPush(Vec_Flt_t *p, float Entry)
Definition: vecFlt.h:528
static SC_Timings * Abc_SclTimingsAlloc()
Definition: sclLib.h:320
static ABC_NAMESPACE_IMPL_START void Abc_SclReadSurface(Vec_Str_t *vOut, int *pPos, SC_Surface *p)
DECLARATIONS ///.
Definition: sclLibScl.c:48
char * func_text
Definition: sclLib.h:176
SC_Dir dir
Definition: sclLib.h:170
static SC_Lib * Abc_SclLibAlloc()
Definition: sclLib.h:343
Vec_Wrd_t * vFunc
Definition: sclLib.h:177
#define SC_LibForEachWireLoadSel(p, pWLS, i)
Definition: sclLib.h:251
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
static SC_Pin * Abc_SclPinAlloc()
Definition: sclLib.h:327
Vec_Flt_t * vIndex1
Definition: sclLib.h:145
float area
Definition: sclLib.h:188
static SC_Cell * Abc_SclCellAlloc()
Definition: sclLib.h:336
int unit_cap_snd
Definition: sclLib.h:211
string version
Definition: setup.py:63
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
SC_TSense tsense
Definition: sclLib.h:153
static void Abc_SclWriteSurfaceText(FILE *s, SC_Surface *p)
Definition: sclLibScl.c:475
static SC_WireLoadSel * Abc_SclWireLoadSelAlloc()
Definition: sclLib.h:284
float cap
Definition: sclLib.h:120
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
float default_max_out_slew
Definition: sclLib.h:208
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Vec_Flt_t * vIndex0
Definition: sclLib.h:144
static void Vec_WrdFree(Vec_Wrd_t *p)
Definition: vecWrd.h:260
static SC_Timing * Abc_SclTimingAlloc()
Definition: sclLib.h:310
char * pName
Definition: sclLib.h:119
int Id
Definition: sclLib.h:184
static void Vec_StrPutS(Vec_Str_t *vOut, char *pStr)
Definition: vecStr.h:897
static void Abc_SclWriteLibrary(Vec_Str_t *vOut, SC_Lib *p)
Definition: sclLibScl.c:317
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
char * pName
Definition: sclLib.h:183
static char * Vec_StrGetS(Vec_Str_t *vOut, int *pPos)
Definition: vecStr.h:903
int seq
Definition: sclLib.h:186
void Abc_SclWriteLiberty(char *pFileName, SC_Lib *p)
Definition: sclLibScl.c:660
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
SC_Surface * pFallTrans
Definition: sclLib.h:158
SC_Lib * Abc_SclReadFromStr(Vec_Str_t *vOut)
Definition: sclLibScl.c:234
static void Vec_StrPutF(Vec_Str_t *vOut, float Val)
Definition: vecStr.h:861
Vec_Ptr_t * vTimings
Definition: sclLib.h:164
static void Abc_SclWriteLibraryText(FILE *s, SC_Lib *p)
Definition: sclLibScl.c:521
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int drive_strength
Definition: sclLib.h:190
#define ABC_SCL_CUR_VERSION
INCLUDES ///.
Definition: sclLib.h:43
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int n_outputs
Definition: sclLib.h:193
static int Vec_StrSize(Vec_Str_t *p)
Definition: bblif.c:600
void Abc_SclWriteScl(char *pFileName, SC_Lib *p)
Definition: sclLibScl.c:444
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
static word * Vec_WrdArray(Vec_Wrd_t *p)
Definition: vecWrd.h:316
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
float max_out_slew
Definition: sclLib.h:175
SC_Surface * pRiseTrans
Definition: sclLib.h:157
Vec_Int_t * vFanout
Definition: sclLib.h:122
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define SC_CellForEachPinOut(p, pPin, i)
Definition: sclLib.h:255
int nSize
Definition: bblif.c:50
void Abc_SclLinkCells(SC_Lib *p)
Definition: sclLibUtil.c:129
char * Extra_TimeStamp()
static word Vec_WrdEntry(Vec_Wrd_t *p, int i)
Definition: vecWrd.h:384
static void Vec_StrPutI(Vec_Str_t *vOut, int Val)
Definition: vecStr.h:831
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
Definition: vecFlt.h:42
int n_inputs
Definition: sclLib.h:192
#define SC_LibForEachWireLoad(p, pWL, i)
Definition: sclLib.h:250
#define assert(ex)
Definition: util_old.h:213
SC_Lib * Abc_SclReadFromFile(char *pFileName)
Definition: sclLibScl.c:248
int strlen()
void Abc_SclHashCells(SC_Lib *p)
Definition: sclLibUtil.c:65
char * pName
Definition: sclLib.h:169
static float Vec_FltEntry(Vec_Flt_t *p, int i)
Definition: vecFlt.h:342
Vec_Ptr_t * vWireLoadSels
Definition: sclLib.h:213
Vec_Flt_t * vAreaFrom
Definition: sclLib.h:129
#define SC_PinForEachRTiming(p, pRTime, i)
Definition: sclLib.h:258
SC_Surface * pCellFall
Definition: sclLib.h:156
float rise_cap
Definition: sclLib.h:172
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
float max_out_cap
Definition: sclLib.h:174
Vec_Ptr_t * vCells
Definition: sclLib.h:215
int nCap
Definition: bblif.c:49
void Abc_SclLibNormalize(SC_Lib *p)
Definition: sclLibUtil.c:615
static int Vec_FltSize(Vec_Flt_t *p)
Definition: vecFlt.h:294
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
static void Abc_SclWriteSurface(Vec_Str_t *vOut, SC_Surface *p)
Definition: sclLibScl.c:292
static int Vec_StrGetI(Vec_Str_t *vOut, int *pPos)
Definition: vecStr.h:837
static void ** Vec_PtrArray(Vec_Ptr_t *p)
Definition: vecPtr.h:279
VOID_HACK rewind()
char * default_wire_load_sel
Definition: sclLib.h:207
char * pName
Definition: sclLib.h:204
SC_TSense
Definition: sclLib.h:54
#define SC_LibForEachCell(p, pCell, i)
Definition: sclLib.h:248
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223