abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sclLibUtil.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [sclLibUtil.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Standard-cell library representation.]
8 
9  Synopsis [Various library utilities.]
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: sclLibUtil.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 unsigned Abc_SclHashString( char * pName, int TableSize )
49 {
50  static int s_Primes[10] = { 1291, 1699, 2357, 4177, 5147, 5647, 6343, 7103, 7873, 8147 };
51  unsigned i, Key = 0;
52  for ( i = 0; pName[i] != '\0'; i++ )
53  Key += s_Primes[i%10]*pName[i]*pName[i];
54  return Key % TableSize;
55 }
56 int * Abc_SclHashLookup( SC_Lib * p, char * pName )
57 {
58  int i;
59  for ( i = Abc_SclHashString(pName, p->nBins); i < p->nBins; i = (i + 1) % p->nBins )
60  if ( p->pBins[i] == -1 || !strcmp(pName, SC_LibCell(p, p->pBins[i])->pName) )
61  return p->pBins + i;
62  assert( 0 );
63  return NULL;
64 }
66 {
67  SC_Cell * pCell;
68  int i, * pPlace;
69  assert( p->nBins == 0 );
70  p->nBins = Abc_PrimeCudd( 5 * SC_LibCellNum(p) );
71  p->pBins = ABC_FALLOC( int, p->nBins );
72  SC_LibForEachCell( p, pCell, i )
73  {
74  pPlace = Abc_SclHashLookup( p, pCell->pName );
75  assert( *pPlace == -1 );
76  *pPlace = i;
77  }
78 }
79 int Abc_SclCellFind( SC_Lib * p, char * pName )
80 {
81  int *pPlace = Abc_SclHashLookup( p, pName );
82  return pPlace ? *pPlace : -1;
83 }
85 {
86  SC_Cell * pCell;
87  int i, Count = 0;
88  SC_RingForEachCell( pClass, pCell, i )
89  if ( !pCell->fSkip )
90  Count++;
91  return Count;
92 }
94 {
95  SC_Cell * pRepr;
96  int i, Count = 0;
97  SC_LibForEachCellClass( pLib, pRepr, i )
98  Count++;
99  return Count;
100 }
101 
102 /**Function*************************************************************
103 
104  Synopsis [Links equal gates into rings while sorting them by area.]
105 
106  Description []
107 
108  SideEffects []
109 
110  SeeAlso []
111 
112 ***********************************************************************/
113 static int Abc_SclCompareCells( SC_Cell ** pp1, SC_Cell ** pp2 )
114 {
115  if ( (*pp1)->n_inputs < (*pp2)->n_inputs )
116  return -1;
117  if ( (*pp1)->n_inputs > (*pp2)->n_inputs )
118  return 1;
119 // if ( (*pp1)->area < (*pp2)->area )
120 // return -1;
121 // if ( (*pp1)->area > (*pp2)->area )
122 // return 1;
123  if ( SC_CellPinCapAve(*pp1) < SC_CellPinCapAve(*pp2) )
124  return -1;
125  if ( SC_CellPinCapAve(*pp1) > SC_CellPinCapAve(*pp2) )
126  return 1;
127  return strcmp( (*pp1)->pName, (*pp2)->pName );
128 }
130 {
131  Vec_Ptr_t * vList;
132  SC_Cell * pCell, * pRepr = NULL;
133  int i, k;
134  assert( Vec_PtrSize(p->vCellClasses) == 0 );
135  SC_LibForEachCell( p, pCell, i )
136  {
137  // find gate with the same function
138  SC_LibForEachCellClass( p, pRepr, k )
139  if ( pCell->n_inputs == pRepr->n_inputs &&
140  pCell->n_outputs == pRepr->n_outputs &&
141  Vec_WrdEqual(SC_CellFunc(pCell), SC_CellFunc(pRepr)) )
142  break;
143  if ( k == Vec_PtrSize(p->vCellClasses) )
144  {
145  Vec_PtrPush( p->vCellClasses, pCell );
146  pCell->pNext = pCell->pPrev = pCell;
147  continue;
148  }
149  // add it to the list before the cell
150  pRepr->pPrev->pNext = pCell; pCell->pNext = pRepr;
151  pCell->pPrev = pRepr->pPrev; pRepr->pPrev = pCell;
152  }
153  // sort cells by size then by name
154  qsort( (void *)Vec_PtrArray(p->vCellClasses), Vec_PtrSize(p->vCellClasses), sizeof(void *), (int(*)(const void *,const void *))Abc_SclCompareCells );
155  // sort cell lists
156  vList = Vec_PtrAlloc( 100 );
157  SC_LibForEachCellClass( p, pRepr, k )
158  {
159  Vec_PtrClear( vList );
160  SC_RingForEachCell( pRepr, pCell, i )
161  Vec_PtrPush( vList, pCell );
162  qsort( (void *)Vec_PtrArray(vList), Vec_PtrSize(vList), sizeof(void *), (int(*)(const void *,const void *))Abc_SclCompareCells );
163  // create new representative
164  pRepr = (SC_Cell *)Vec_PtrEntry( vList, 0 );
165  pRepr->pNext = pRepr->pPrev = pRepr;
166  pRepr->pRepr = pRepr;
167  pRepr->pAve = (SC_Cell *)Vec_PtrEntry( vList, Vec_PtrSize(vList)/2 );
168  pRepr->Order = 0;
169  pRepr->nGates = Vec_PtrSize(vList);
170  // relink cells
171  Vec_PtrForEachEntryStart( SC_Cell *, vList, pCell, i, 1 )
172  {
173  pRepr->pPrev->pNext = pCell; pCell->pNext = pRepr;
174  pCell->pPrev = pRepr->pPrev; pRepr->pPrev = pCell;
175  pCell->pRepr = pRepr;
176  pCell->pAve = (SC_Cell *)Vec_PtrEntry( vList, Vec_PtrSize(vList)/2 );
177  pCell->Order = i;
178  pCell->nGates = Vec_PtrSize(vList);
179  }
180  // update list
181  Vec_PtrWriteEntry( p->vCellClasses, k, pRepr );
182  }
183  Vec_PtrFree( vList );
184 }
185 
186 /**Function*************************************************************
187 
188  Synopsis [Returns the largest inverter.]
189 
190  Description []
191 
192  SideEffects []
193 
194  SeeAlso []
195 
196 ***********************************************************************/
197 SC_Cell * Abc_SclFindInvertor( SC_Lib * p, int fFindBuff )
198 {
199  SC_Cell * pCell = NULL;
200  word Truth = fFindBuff ? ABC_CONST(0xAAAAAAAAAAAAAAAA) : ABC_CONST(0x5555555555555555);
201  int k;
202  SC_LibForEachCellClass( p, pCell, k )
203  if ( pCell->n_inputs == 1 && Vec_WrdEntry(SC_CellPin(pCell, 1)->vFunc, 0) == Truth )
204  break;
205  // take representative
206  return pCell ? pCell->pRepr : NULL;
207 }
209 {
210  SC_Cell * pRes = NULL;
211  int i;
212  SC_RingForEachCell( p->pRepr, pRes, i )
213  if ( SC_CellPinCapAve(pRes) > CinMin )
214  return pRes;
215  // take the largest gate
216  return p->pRepr->pPrev;
217 }
218 
219 /**Function*************************************************************
220 
221  Synopsis [Returns the wireload model for the given area.]
222 
223  Description []
224 
225  SideEffects []
226 
227  SeeAlso []
228 
229 ***********************************************************************/
231 {
232  SC_WireLoad * pWL = NULL;
233  int i;
234  // Get the actual table and reformat it for 'wire_cap' output:
235  assert( pWLoadUsed != NULL );
236  SC_LibForEachWireLoad( p, pWL, i )
237  if ( !strcmp(pWL->pName, pWLoadUsed) )
238  break;
239  if ( i == Vec_PtrSize(p->vWireLoads) )
240  {
241  Abc_Print( -1, "Cannot find wire load model \"%s\".\n", pWLoadUsed );
242  exit(1);
243  }
244 // printf( "Using wireload model \"%s\".\n", pWL->pName );
245  return pWL;
246 }
248 {
249  char * pWLoadUsed = NULL;
250  int i;
252  {
253  SC_WireLoadSel * pWLS = NULL;
254  SC_LibForEachWireLoadSel( p, pWLS, i )
255  if ( !strcmp(pWLS->pName, p->default_wire_load_sel) )
256  break;
257  if ( i == Vec_PtrSize(p->vWireLoadSels) )
258  {
259  Abc_Print( -1, "Cannot find wire load selection model \"%s\".\n", p->default_wire_load_sel );
260  exit(1);
261  }
262  for ( i = 0; i < Vec_FltSize(pWLS->vAreaFrom); i++)
263  if ( Area >= Vec_FltEntry(pWLS->vAreaFrom, i) && Area < Vec_FltEntry(pWLS->vAreaTo, i) )
264  {
265  pWLoadUsed = (char *)Vec_PtrEntry(pWLS->vWireLoadModel, i);
266  break;
267  }
268  if ( i == Vec_FltSize(pWLS->vAreaFrom) )
269  pWLoadUsed = (char *)Vec_PtrEntryLast(pWLS->vWireLoadModel);
270  }
271  else if ( p->default_wire_load && strlen(p->default_wire_load) )
272  pWLoadUsed = p->default_wire_load;
273  else
274  {
275 // Abc_Print( 0, "No wire model given.\n" );
276  return NULL;
277  }
278  return Abc_SclFetchWireLoadModel( p, pWLoadUsed );
279 }
280 
281 /**Function*************************************************************
282 
283  Synopsis [Returns 1 if the library has delay info.]
284 
285  Description []
286 
287  SideEffects []
288 
289  SeeAlso []
290 
291 ***********************************************************************/
292 int Abc_SclHasDelayInfo( void * pScl )
293 {
294  SC_Lib * p = (SC_Lib *)pScl;
295  SC_Cell * pCell;
296  SC_Timing * pTime;
297  pCell = Abc_SclFindInvertor(p, 0);
298  if ( pCell == NULL )
299  return 0;
300  pTime = Scl_CellPinTime( pCell, 0 );
301  if ( pTime == NULL )
302  return 0;
303  return 1;
304 }
305 
306 /**Function*************************************************************
307 
308  Synopsis [Returns "average" slew.]
309 
310  Description []
311 
312  SideEffects []
313 
314  SeeAlso []
315 
316 ***********************************************************************/
318 {
319  SC_Cell * pCell;
320  SC_Timing * pTime;
321  Vec_Flt_t * vIndex;
322  pCell = Abc_SclFindInvertor(p, 0);
323  if ( pCell == NULL )
324  return 0;
325  pTime = Scl_CellPinTime( pCell, 0 );
326  if ( pTime == NULL )
327  return 0;
328  vIndex = pTime->pCellRise->vIndex0; // slew
329  return Vec_FltEntry( vIndex, Vec_FltSize(vIndex)/3 );
330 }
331 
332 /**Function*************************************************************
333 
334  Synopsis [Compute delay parameters of pin/cell/class.]
335 
336  Description []
337 
338  SideEffects []
339 
340  SeeAlso []
341 
342 ***********************************************************************/
343 int Abc_SclComputeParametersPin( SC_Lib * p, SC_Cell * pCell, int iPin, float Slew, float * pLD, float * pPD )
344 {
345  SC_Pair Load0, Load1, Load2;
346  SC_Pair ArrIn = { 0.0, 0.0 };
347  SC_Pair SlewIn = { Slew, Slew };
348  SC_Pair ArrOut0 = { 0.0, 0.0 };
349  SC_Pair ArrOut1 = { 0.0, 0.0 };
350  SC_Pair ArrOut2 = { 0.0, 0.0 };
351  SC_Pair SlewOut = { 0.0, 0.0 };
352  SC_Timing * pTime = Scl_CellPinTime( pCell, iPin );
353  Vec_Flt_t * vIndex = pTime ? pTime->pCellRise->vIndex1 : NULL; // capacitance
354  if ( vIndex == NULL )
355  return 0;
356  // handle constant table
357  if ( Vec_FltSize(vIndex) == 1 )
358  {
359  *pLD = 0;
360  *pPD = Vec_FltEntry( (Vec_Flt_t *)Vec_PtrEntry(pTime->pCellRise->vData, 0), 0 );
361  return 1;
362  }
363  // get load points
364  Load0.rise = Load0.fall = 0.0;
365  Load1.rise = Load1.fall = Vec_FltEntry( vIndex, 0 );
366  Load2.rise = Load2.fall = Vec_FltEntry( vIndex, Vec_FltSize(vIndex) - 2 );
367  // compute delay
368  Scl_LibPinArrival( pTime, &ArrIn, &SlewIn, &Load0, &ArrOut0, &SlewOut );
369  Scl_LibPinArrival( pTime, &ArrIn, &SlewIn, &Load1, &ArrOut1, &SlewOut );
370  Scl_LibPinArrival( pTime, &ArrIn, &SlewIn, &Load2, &ArrOut2, &SlewOut );
371  ArrOut0.rise = 0.5 * ArrOut0.rise + 0.5 * ArrOut0.fall;
372  ArrOut1.rise = 0.5 * ArrOut1.rise + 0.5 * ArrOut1.fall;
373  ArrOut2.rise = 0.5 * ArrOut2.rise + 0.5 * ArrOut2.fall;
374  // get tangent
375  *pLD = (ArrOut2.rise - ArrOut1.rise) / ((Load2.rise - Load1.rise) / SC_CellPinCap(pCell, iPin));
376  // get constant
377  *pPD = ArrOut0.rise;
378  return 1;
379 }
380 int Abc_SclComputeParametersCell( SC_Lib * p, SC_Cell * pCell, float Slew, float * pLD, float * pPD )
381 {
382  SC_Pin * pPin;
383  float LD, PD, ld, pd;
384  int i;
385  LD = PD = ld = pd = 0;
386  SC_CellForEachPinIn( pCell, pPin, i )
387  {
388  if ( !Abc_SclComputeParametersPin( p, pCell, i, Slew, &ld, &pd ) )
389  return 0;
390  LD += ld; PD += pd;
391  }
392  *pLD = LD / Abc_MaxInt(1, pCell->n_inputs);
393  *pPD = PD / Abc_MaxInt(1, pCell->n_inputs);
394  return 1;
395 }
396 void Abc_SclComputeParametersClass( SC_Lib * p, SC_Cell * pRepr, float Slew, float * pLD, float * pPD )
397 {
398  SC_Cell * pCell;
399  float LD, PD, ld, pd;
400  int i, Count = 0;
401  LD = PD = ld = pd = 0;
402  SC_RingForEachCell( pRepr, pCell, i )
403  {
404  Abc_SclComputeParametersCell( p, pCell, Slew, &ld, &pd );
405  LD += ld; PD += pd;
406  Count++;
407  }
408  *pLD = LD / Abc_MaxInt(1, Count);
409  *pPD = PD / Abc_MaxInt(1, Count);
410 }
411 void Abc_SclComputeParametersClassPin( SC_Lib * p, SC_Cell * pRepr, int iPin, float Slew, float * pLD, float * pPD )
412 {
413  SC_Cell * pCell;
414  float LD, PD, ld, pd;
415  int i, Count = 0;
416  LD = PD = ld = pd = 0;
417  SC_RingForEachCell( pRepr, pCell, i )
418  {
419  Abc_SclComputeParametersPin( p, pCell, iPin, Slew, &ld, &pd );
420  LD += ld; PD += pd;
421  Count++;
422  }
423  *pLD = LD / Abc_MaxInt(1, Count);
424  *pPD = PD / Abc_MaxInt(1, Count);
425 }
426 float Abc_SclComputeDelayCellPin( SC_Lib * p, SC_Cell * pCell, int iPin, float Slew, float Gain )
427 {
428  float LD = 0, PD = 0;
429  Abc_SclComputeParametersPin( p, pCell, iPin, Slew, &LD, &PD );
430  return 0.01 * LD * Gain + PD;
431 }
432 float Abc_SclComputeDelayClassPin( SC_Lib * p, SC_Cell * pRepr, int iPin, float Slew, float Gain )
433 {
434  SC_Cell * pCell;
435  float Delay = 0;
436  int i, Count = 0;
437  SC_RingForEachCell( pRepr, pCell, i )
438  {
439  if ( pCell->fSkip )
440  continue;
441 // if ( pRepr == pCell ) // skip the first gate
442 // continue;
443  Delay += Abc_SclComputeDelayCellPin( p, pCell, iPin, Slew, Gain );
444  Count++;
445  }
446  return Delay / Abc_MaxInt(1, Count);
447 }
449 {
450  SC_Cell * pCell;
451  float Area = 0;
452  int i, Count = 0;
453  SC_RingForEachCell( pRepr, pCell, i )
454  {
455  if ( pCell->fSkip )
456  continue;
457  Area += pCell->area;
458  Count++;
459  }
460  return Area / Abc_MaxInt(1, Count);
461 }
462 
463 /**Function*************************************************************
464 
465  Synopsis [Print cells]
466 
467  Description []
468 
469  SideEffects []
470 
471  SeeAlso []
472 
473 ***********************************************************************/
475 {
476  char FileName[1000];
477  char Buffer[1000], * pName;
478  SC_Cell * pCell;
479  FILE * pFile;
480  int CellId, nSkipped = 0;
481  sprintf( FileName, "%s.skip", p->pName );
482  pFile = fopen( FileName, "rb" );
483  if ( pFile == NULL )
484  return;
485  while ( fgets( Buffer, 999, pFile ) != NULL )
486  {
487  pName = strtok( Buffer, "\r\n\t " );
488  if ( pName == NULL )
489  continue;
490  CellId = Abc_SclCellFind( p, pName );
491  if ( CellId == -1 )
492  {
493  printf( "Cannot find cell \"%s\" in the library \"%s\".\n", pName, p->pName );
494  continue;
495  }
496  pCell = SC_LibCell( p, CellId );
497  pCell->fSkip = 1;
498  nSkipped++;
499  }
500  fclose( pFile );
501  printf( "Marked %d cells for skipping in the library \"%s\".\n", nSkipped, p->pName );
502 }
503 void Abc_SclPrintCells( SC_Lib * p, float SlewInit, float Gain, int fInvOnly, int fShort )
504 {
505  SC_Cell * pCell, * pRepr;
506  SC_Pin * pPin;
507  int i, j, k, nLength = 0;
508  float Slew = (SlewInit == 0) ? Abc_SclComputeAverageSlew(p) : SlewInit;
509  float LD = 0, PD = 0;
510  assert( Vec_PtrSize(p->vCellClasses) > 0 );
511  printf( "Library \"%s\" ", p->pName );
512  printf( "has %d cells in %d classes. ",
514  if ( !fShort )
515  printf( "Delay estimate is based on slew %.2f ps and gain %.2f.", Slew, Gain );
516  printf( "\n" );
518  // find the longest name
519  SC_LibForEachCellClass( p, pRepr, k )
520  SC_RingForEachCell( pRepr, pCell, i )
521  nLength = Abc_MaxInt( nLength, strlen(pRepr->pName) );
522  // print cells
523  SC_LibForEachCellClass( p, pRepr, k )
524  {
525  if ( fInvOnly && pRepr->n_inputs != 1 )
526  continue;
527  SC_CellForEachPinOut( pRepr, pPin, i )
528  {
529  if ( i == pRepr->n_inputs )
530  {
531  printf( "Class%4d : ", k );
532  printf( "Cells =%3d ", Abc_SclClassCellNum(pRepr) );
533  printf( "Ins =%2d ", pRepr->n_inputs );
534  printf( "Outs =%2d ", pRepr->n_outputs );
535  }
536  else
537  printf( " " );
538  if ( pPin->func_text )
539  printf( "%-30s", pPin->func_text );
540  printf( " " );
541  Kit_DsdPrintFromTruth( (unsigned *)Vec_WrdArray(pPin->vFunc), pRepr->n_inputs );
542  printf( "\n" );
543  if ( fShort )
544  continue;
545  SC_RingForEachCell( pRepr, pCell, j )
546  {
547  printf( " %3d ", j+1 );
548  printf( "%s", pCell->fSkip ? "s" : " " );
549  printf( " : " );
550  printf( "%-*s ", nLength, pCell->pName );
551  printf( "%2d ", pCell->drive_strength );
552  printf( "A =%8.2f ", pCell->area );
553  printf( "L =%8.2f ", pCell->leakage );
554  if ( pCell->n_outputs == 1 )
555  {
556  if ( Abc_SclComputeParametersCell( p, pCell, Slew, &LD, &PD ) )
557  {
558  printf( "D =%6.1f ps ", 0.01 * Gain * LD + PD );
559  printf( "LD =%6.1f ps ", LD );
560  printf( "PD =%6.1f ps ", PD );
561  printf( "C =%5.1f ff ", SC_CellPinCapAve(pCell) );
562  printf( "Cm =%5.0f ff ", SC_CellPin(pCell, pCell->n_inputs)->max_out_cap );
563  printf( "Sm =%5.1f ps ", SC_CellPin(pCell, pCell->n_inputs)->max_out_slew );
564  }
565  }
566  printf( "\n" );
567  }
568  break;
569  }
570  }
571 }
572 
573 /**Function*************************************************************
574 
575  Synopsis []
576 
577  Description []
578 
579  SideEffects []
580 
581  SeeAlso []
582 
583 ***********************************************************************/
584 void Abc_SclConvertLeakageIntoArea( SC_Lib * p, float A, float B )
585 {
586  SC_Cell * pCell; int i;
587  SC_LibForEachCell( p, pCell, i )
588  pCell->area = A * pCell->area + B * pCell->leakage;
589 }
590 
591 
592 /**Function*************************************************************
593 
594  Synopsis [Print cells]
595 
596  Description []
597 
598  SideEffects []
599 
600  SeeAlso []
601 
602 ***********************************************************************/
603 void Abc_SclLibNormalizeSurface( SC_Surface * p, float Time, float Load )
604 {
605  Vec_Flt_t * vArray;
606  int i, k; float Entry;
607  Vec_FltForEachEntry( p->vIndex0, Entry, i ) // slew
608  Vec_FltWriteEntry( p->vIndex0, i, Time * Entry );
609  Vec_FltForEachEntry( p->vIndex1, Entry, i ) // load
610  Vec_FltWriteEntry( p->vIndex1, i, Load * Entry );
611  Vec_PtrForEachEntry( Vec_Flt_t *, p->vData, vArray, k )
612  Vec_FltForEachEntry( vArray, Entry, i ) // delay/slew
613  Vec_FltWriteEntry( vArray, i, Time * Entry );
614 }
616 {
617  SC_WireLoad * pWL;
618  SC_Cell * pCell;
619  SC_Pin * pPin;
620  SC_Timings * pTimings;
621  SC_Timing * pTiming;
622  int i, k, m, n;
623  float Time = 1.0 * pow(10.0, 12 - p->unit_time);
624  float Load = p->unit_cap_fst * pow(10.0, 15 - p->unit_cap_snd);
625  if ( Time == 1 && Load == 1 )
626  return;
627  p->unit_time = 12;
628  p->unit_cap_fst = 1;
629  p->unit_cap_snd = 15;
630  p->default_max_out_slew *= Time;
631  SC_LibForEachWireLoad( p, pWL, i )
632  pWL->cap *= Load;
633  SC_LibForEachCell( p, pCell, i )
634  SC_CellForEachPin( pCell, pPin, k )
635  {
636  pPin->cap *= Load;
637  pPin->rise_cap *= Load;
638  pPin->fall_cap *= Load;
639  pPin->max_out_cap *= Load;
640  pPin->max_out_slew *= Time;
641  SC_PinForEachRTiming( pPin, pTimings, m )
642  Vec_PtrForEachEntry( SC_Timing *, pTimings->vTimings, pTiming, n )
643  {
644  Abc_SclLibNormalizeSurface( pTiming->pCellRise, Time, Load );
645  Abc_SclLibNormalizeSurface( pTiming->pCellFall, Time, Load );
646  Abc_SclLibNormalizeSurface( pTiming->pRiseTrans, Time, Load );
647  Abc_SclLibNormalizeSurface( pTiming->pFallTrans, Time, Load );
648  }
649  }
650 }
651 
652 /**Function*************************************************************
653 
654  Synopsis [Derives simple GENLIB library.]
655 
656  Description []
657 
658  SideEffects []
659 
660  SeeAlso []
661 
662 ***********************************************************************/
664 {
665  char Buffer[200];
666  Vec_Str_t * vStr;
667  SC_Cell * pCell;
668  SC_Pin * pPin, * pPinOut;
669  int i, j, k, Count = 2;
670  // mark skipped cells
671 // Abc_SclMarkSkippedCells( p );
672  vStr = Vec_StrAlloc( 1000 );
673  Vec_StrPrintStr( vStr, "GATE _const0_ 0.00 z=CONST0;\n" );
674  Vec_StrPrintStr( vStr, "GATE _const1_ 0.00 z=CONST1;\n" );
675  SC_LibForEachCell( p, pCell, i )
676  {
677  if ( pCell->n_inputs == 0 )
678  continue;
679  assert( strlen(pCell->pName) < 200 );
680  SC_CellForEachPinOut( pCell, pPinOut, j )
681  {
682  Vec_StrPrintStr( vStr, "GATE " );
683  sprintf( Buffer, "%-16s", pCell->pName );
684  Vec_StrPrintStr( vStr, Buffer );
685  Vec_StrPrintStr( vStr, " " );
686  sprintf( Buffer, "%7.2f", pCell->area );
687  Vec_StrPrintStr( vStr, Buffer );
688  Vec_StrPrintStr( vStr, " " );
689  Vec_StrPrintStr( vStr, pPinOut->pName );
690  Vec_StrPrintStr( vStr, "=" );
691  Vec_StrPrintStr( vStr, pPinOut->func_text ? pPinOut->func_text : "?" );
692  Vec_StrPrintStr( vStr, ";\n" );
693  SC_CellForEachPinIn( pCell, pPin, k )
694  {
695  Vec_StrPrintStr( vStr, " PIN " );
696  sprintf( Buffer, "%-4s", pPin->pName );
697  Vec_StrPrintStr( vStr, Buffer );
698  sprintf( Buffer, " UNKNOWN 1 999 1.00 0.00 1.00 0.00\n" );
699  Vec_StrPrintStr( vStr, Buffer );
700  }
701  Count++;
702  }
703  }
704  Vec_StrPrintStr( vStr, "\n.end\n" );
705  Vec_StrPush( vStr, '\0' );
706 // printf( "GENLIB library with %d gates is produced:\n", Count );
707 // printf( "%s", Vec_StrArray(vStr) );
708  return vStr;
709 }
711 {
712  SC_Lib * p = (SC_Lib *)pScl;
714  Mio_Library_t * pLib = Mio_LibraryRead( p->pFileName, Vec_StrArray(vStr), NULL, 0 );
715  Vec_StrFree( vStr );
716  if ( pLib )
717  printf( "Derived GENLIB library \"%s\" with %d gates.\n", p->pName, SC_LibCellNum(p) );
718  else
719  printf( "Reading library has filed.\n" );
720  return pLib;
721 }
722 
723 
724 /**Function*************************************************************
725 
726  Synopsis [Derive GENLIB library.]
727 
728  Description []
729 
730  SideEffects []
731 
732  SeeAlso []
733 
734 ***********************************************************************/
735 Vec_Str_t * Abc_SclProduceGenlibStr( SC_Lib * p, float Slew, float Gain, int nGatesMin, int * pnCellCount )
736 {
737  char Buffer[200];
738  Vec_Str_t * vStr;
739  SC_Cell * pRepr;
740  SC_Pin * pPin;
741  int i, k, Count = 2, nClassMax = 0;
742  // find the largest number of cells in a class
743  SC_LibForEachCellClass( p, pRepr, i )
744  if ( pRepr->n_outputs == 1 )
745  nClassMax = Abc_MaxInt( nClassMax, Abc_SclClassCellNum(pRepr) );
746  // update the number
747  if ( nGatesMin && nGatesMin >= nClassMax )
748  nGatesMin = 0;
749  // mark skipped cells
751  vStr = Vec_StrAlloc( 1000 );
752  Vec_StrPrintStr( vStr, "GATE _const0_ 0.00 z=CONST0;\n" );
753  Vec_StrPrintStr( vStr, "GATE _const1_ 0.00 z=CONST1;\n" );
754  SC_LibForEachCellClass( p, pRepr, i )
755  {
756  if ( pRepr->n_inputs == 0 )
757  continue;
758  if ( pRepr->n_outputs > 1 )
759  continue;
760  if ( nGatesMin && pRepr->n_inputs > 2 && Abc_SclClassCellNum(pRepr) < nGatesMin )
761  continue;
762  assert( strlen(pRepr->pName) < 200 );
763  Vec_StrPrintStr( vStr, "GATE " );
764  sprintf( Buffer, "%-16s", pRepr->pName );
765  Vec_StrPrintStr( vStr, Buffer );
766  Vec_StrPrintStr( vStr, " " );
767 // sprintf( Buffer, "%7.2f", Abc_SclComputeAreaClass(pRepr) );
768  sprintf( Buffer, "%7.2f", pRepr->area );
769  Vec_StrPrintStr( vStr, Buffer );
770  Vec_StrPrintStr( vStr, " " );
771  Vec_StrPrintStr( vStr, SC_CellPinName(pRepr, pRepr->n_inputs) );
772  Vec_StrPrintStr( vStr, "=" );
773  Vec_StrPrintStr( vStr, SC_CellPinOutFunc(pRepr, 0) ? SC_CellPinOutFunc(pRepr, 0) : "?" );
774  Vec_StrPrintStr( vStr, ";\n" );
775  SC_CellForEachPinIn( pRepr, pPin, k )
776  {
777  float Delay = Abc_SclComputeDelayClassPin( p, pRepr, k, Slew, Gain );
778  assert( Delay > 0 );
779  Vec_StrPrintStr( vStr, " PIN " );
780  sprintf( Buffer, "%-4s", pPin->pName );
781  Vec_StrPrintStr( vStr, Buffer );
782  sprintf( Buffer, " UNKNOWN 1 999 %7.2f 0.00 %7.2f 0.00\n", Delay, Delay );
783  Vec_StrPrintStr( vStr, Buffer );
784  }
785  Count++;
786  }
787  Vec_StrPrintStr( vStr, "\n.end\n" );
788  Vec_StrPush( vStr, '\0' );
789 // printf( "GENLIB library with %d gates is produced:\n", Count );
790 // printf( "%s", Vec_StrArray(vStr) );
791  if ( pnCellCount )
792  *pnCellCount = Count;
793  return vStr;
794 }
795 void Abc_SclDumpGenlib( char * pFileName, SC_Lib * p, float SlewInit, float Gain, int nGatesMin )
796 {
797  int nCellCount = 0;
798  char FileName[1000];
799  float Slew = (SlewInit == 0) ? Abc_SclComputeAverageSlew(p) : SlewInit;
800  Vec_Str_t * vStr;
801  FILE * pFile;
802  if ( pFileName == NULL )
803  sprintf( FileName, "%s_s%03d_g%03d_m%d.genlib", p->pName, (int)Slew, (int)Gain, nGatesMin );
804  else
805  sprintf( FileName, "%s", pFileName );
806  pFile = fopen( FileName, "wb" );
807  if ( pFile == NULL )
808  {
809  printf( "Cannot open file \"%s\" for writing.\n", FileName );
810  return;
811  }
812  vStr = Abc_SclProduceGenlibStr( p, Slew, Gain, nGatesMin, &nCellCount );
813  fprintf( pFile, "%s", Vec_StrArray(vStr) );
814  Vec_StrFree( vStr );
815  fclose( pFile );
816  printf( "Written GENLIB library with %d gates into file \"%s\".\n", nCellCount, FileName );
817 }
818 Mio_Library_t * Abc_SclDeriveGenlib( void * pScl, float SlewInit, float Gain, int nGatesMin, int fVerbose )
819 {
820  int nCellCount = 0;
821  SC_Lib * p = (SC_Lib *)pScl;
822  float Slew = (SlewInit == 0) ? Abc_SclComputeAverageSlew(p) : SlewInit;
823  Vec_Str_t * vStr = Abc_SclProduceGenlibStr( p, Slew, Gain, nGatesMin, &nCellCount );
824  Mio_Library_t * pLib = Mio_LibraryRead( p->pFileName, Vec_StrArray(vStr), NULL, 0 );
825  Vec_StrFree( vStr );
826  if ( !pLib )
827  printf( "Reading library has filed.\n" );
828  else if ( fVerbose )
829  printf( "Derived GENLIB library \"%s\" with %d gates using slew %.2f ps and gain %.2f.\n", p->pName, nCellCount, Slew, Gain );
830  return pLib;
831 }
832 
833 /**Function*************************************************************
834 
835  Synopsis [Install library.]
836 
837  Description []
838 
839  SideEffects []
840 
841  SeeAlso []
842 
843 ***********************************************************************/
844 void Abc_SclInstallGenlib( void * pScl, float SlewInit, float Gain, int nGatesMin )
845 {
846  SC_Lib * p = (SC_Lib *)pScl;
847  Vec_Str_t * vStr, * vStr2;
848  float Slew = (SlewInit == 0) ? Abc_SclComputeAverageSlew(p) : SlewInit;
849  int RetValue, nGateCount = SC_LibCellNum(p);
850  if ( Gain == 0 )
852  else
853  vStr = Abc_SclProduceGenlibStr( p, Slew, Gain, nGatesMin, &nGateCount );
854  vStr2 = Vec_StrDup( vStr );
855  RetValue = Mio_UpdateGenlib2( vStr, vStr2, p->pName, 0 );
856  Vec_StrFree( vStr );
857  Vec_StrFree( vStr2 );
858  if ( !RetValue )
859  printf( "Reading library has filed.\n" );
860  else if ( Gain != 0 )
861  printf( "Derived GENLIB library \"%s\" with %d gates using slew %.2f ps and gain %.2f.\n", p->pName, nGateCount, Slew, Gain );
862 // else
863 // printf( "Derived unit-delay GENLIB library \"%s\" with %d gates.\n", p->pName, nGateCount );
864 }
865 
866 ////////////////////////////////////////////////////////////////////////
867 /// END OF FILE ///
868 ////////////////////////////////////////////////////////////////////////
869 
870 
872 
int unit_time
Definition: sclLib.h:209
SC_Cell * pRepr
Definition: sclLib.h:196
VOID_HACK exit()
SC_Surface * pCellRise
Definition: sclLib.h:155
static SC_Timing * Scl_CellPinTime(SC_Cell *pCell, int iPin)
Definition: sclLib.h:565
static int SC_LibCellNum(SC_Lib *p)
Definition: sclLib.h:239
void Abc_SclLinkCells(SC_Lib *p)
Definition: sclLibUtil.c:129
#define Vec_FltForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecFlt.h:54
void Abc_SclPrintCells(SC_Lib *p, float SlewInit, float Gain, int fInvOnly, int fShort)
Definition: sclLibUtil.c:503
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Abc_PrimeCudd(unsigned int p)
Definition: abc_global.h:383
int nGates
Definition: sclLib.h:199
#define SC_CellForEachPin(p, pPin, i)
Definition: sclLib.h:253
float unit_cap_fst
Definition: sclLib.h:210
int Abc_SclCellFind(SC_Lib *p, char *pName)
Definition: sclLibUtil.c:79
Mio_Library_t * Mio_LibraryRead(char *FileName, char *pBuffer, char *ExcludeFile, int fVerbose)
Definition: mioRead.c:54
SC_WireLoad * Abc_SclFindWireLoadModel(SC_Lib *p, float Area)
Definition: sclLibUtil.c:247
static int Vec_WrdEqual(Vec_Wrd_t *p1, Vec_Wrd_t *p2)
Definition: vecWrd.h:963
static void Vec_FltWriteEntry(Vec_Flt_t *p, int i, float Entry)
Definition: vecFlt.h:364
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition: vecPtr.h:57
char * pFileName
Definition: sclLib.h:205
Mio_Library_t * Abc_SclDeriveGenlib(void *pScl, float SlewInit, float Gain, int nGatesMin, int fVerbose)
Definition: sclLibUtil.c:818
int Abc_SclComputeParametersPin(SC_Lib *p, SC_Cell *pCell, int iPin, float Slew, float *pLD, float *pPD)
Definition: sclLibUtil.c:343
#define SC_CellForEachPinIn(p, pPin, i)
Definition: sclLib.h:254
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static char * Vec_StrArray(Vec_Str_t *p)
Definition: vecStr.h:272
float fall_cap
Definition: sclLib.h:173
SC_Cell * Abc_SclFindInvertor(SC_Lib *p, int fFindBuff)
Definition: sclLibUtil.c:197
int Order
Definition: sclLib.h:198
void Abc_SclDumpGenlib(char *pFileName, SC_Lib *p, float SlewInit, float Gain, int nGatesMin)
Definition: sclLibUtil.c:795
char * default_wire_load
Definition: sclLib.h:206
Vec_Flt_t * vAreaTo
Definition: sclLib.h:130
char * strtok()
Vec_Ptr_t * vData
Definition: sclLib.h:146
Vec_Ptr_t * vCellClasses
Definition: sclLib.h:216
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
Vec_Ptr_t * vWireLoadModel
Definition: sclLib.h:131
char * pName
Definition: sclLib.h:128
#define SC_LibForEachCellClass(p, pCell, i)
Definition: sclLib.h:249
float leakage
Definition: sclLib.h:189
static float SC_CellPinCapAve(SC_Cell *p)
Definition: sclLib.h:244
Vec_Ptr_t * vWireLoads
Definition: sclLib.h:212
#define SC_RingForEachCell(pRing, pCell, i)
Definition: sclLib.h:256
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
void Kit_DsdPrintFromTruth(unsigned *pTruth, int nVars)
Definition: kitDsd.c:490
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static void Vec_StrPush(Vec_Str_t *p, char Entry)
Definition: vecStr.h:535
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
int nBins
Definition: sclLib.h:218
SC_WireLoad * Abc_SclFetchWireLoadModel(SC_Lib *p, char *pWLoadUsed)
Definition: sclLibUtil.c:230
void Abc_SclLibNormalizeSurface(SC_Surface *p, float Time, float Load)
Definition: sclLibUtil.c:603
int * pBins
Definition: sclLib.h:217
void Abc_SclComputeParametersClassPin(SC_Lib *p, SC_Cell *pRepr, int iPin, float Slew, float *pLD, float *pPD)
Definition: sclLibUtil.c:411
char * func_text
Definition: sclLib.h:176
int strcmp()
Vec_Wrd_t * vFunc
Definition: sclLib.h:177
#define SC_LibForEachWireLoadSel(p, pWLS, i)
Definition: sclLib.h:251
Vec_Str_t * Abc_SclProduceGenlibStrSimple(SC_Lib *p)
Definition: sclLibUtil.c:663
static int s_Primes[MAX_PRIMES]
Definition: fxuPair.c:30
Vec_Flt_t * vIndex1
Definition: sclLib.h:145
float area
Definition: sclLib.h:188
int unit_cap_snd
Definition: sclLib.h:211
static void * Vec_PtrEntryLast(Vec_Ptr_t *p)
Definition: vecPtr.h:413
float rise
Definition: sclLib.h:65
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
float Abc_SclComputeDelayCellPin(SC_Lib *p, SC_Cell *pCell, int iPin, float Slew, float Gain)
Definition: sclLibUtil.c:426
float cap
Definition: sclLib.h:120
float fall
Definition: sclLib.h:66
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
int * Abc_SclHashLookup(SC_Lib *p, char *pName)
Definition: sclLibUtil.c:56
Vec_Flt_t * vIndex0
Definition: sclLib.h:144
SC_Cell * pAve
Definition: sclLib.h:197
char * pName
Definition: sclLib.h:119
int Mio_UpdateGenlib2(Vec_Str_t *vStr, Vec_Str_t *vStr2, char *pFileName, int fVerbose)
Definition: mio.c:141
STRUCTURE DEFINITIONS ///.
Definition: mioInt.h:61
void Abc_SclInstallGenlib(void *pScl, float SlewInit, float Gain, int nGatesMin)
Definition: sclLibUtil.c:844
char * pName
Definition: sclLib.h:183
char * sprintf()
static char * SC_CellPinName(SC_Cell *p, int i)
Definition: sclLib.h:246
static SC_Pin * SC_CellPin(SC_Cell *p, int i)
Definition: sclLib.h:241
void Abc_SclLibNormalize(SC_Lib *p)
Definition: sclLibUtil.c:615
static SC_Cell * SC_LibCell(SC_Lib *p, int i)
Definition: sclLib.h:240
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
static int Abc_SclCompareCells(SC_Cell **pp1, SC_Cell **pp2)
Definition: sclLibUtil.c:113
SC_Surface * pFallTrans
Definition: sclLib.h:158
int Abc_SclLibClassNum(SC_Lib *pLib)
Definition: sclLibUtil.c:93
Vec_Ptr_t * vTimings
Definition: sclLib.h:164
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
float Abc_SclComputeAverageSlew(SC_Lib *p)
Definition: sclLibUtil.c:317
int Abc_SclComputeParametersCell(SC_Lib *p, SC_Cell *pCell, float Slew, float *pLD, float *pPD)
Definition: sclLibUtil.c:380
static Vec_Wrd_t * SC_CellFunc(SC_Cell *p)
Definition: sclLib.h:242
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int drive_strength
Definition: sclLib.h:190
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int n_outputs
Definition: sclLib.h:193
void Abc_SclConvertLeakageIntoArea(SC_Lib *p, float A, float B)
Definition: sclLibUtil.c:584
static ABC_NAMESPACE_IMPL_START word Truth[8]
DECLARATIONS ///.
Definition: giaShrink6.c:32
int Abc_SclHasDelayInfo(void *pScl)
Definition: sclLibUtil.c:292
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
float Abc_SclComputeAreaClass(SC_Cell *pRepr)
Definition: sclLibUtil.c:448
static float SC_CellPinCap(SC_Cell *p, int i)
Definition: sclLib.h:243
#define ABC_CONST(number)
PARAMETERS ///.
Definition: abc_global.h:206
#define SC_CellForEachPinOut(p, pPin, i)
Definition: sclLib.h:255
void Abc_SclHashCells(SC_Lib *p)
Definition: sclLibUtil.c:65
static void Scl_LibPinArrival(SC_Timing *pTime, SC_Pair *pArrIn, SC_Pair *pSlewIn, SC_Pair *pLoad, SC_Pair *pArrOut, SC_Pair *pSlewOut)
Definition: sclLib.h:523
Vec_Str_t * Abc_SclProduceGenlibStr(SC_Lib *p, float Slew, float Gain, int nGatesMin, int *pnCellCount)
Definition: sclLibUtil.c:735
static word Vec_WrdEntry(Vec_Wrd_t *p, int i)
Definition: vecWrd.h:384
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
Definition: vecFlt.h:42
void Abc_SclComputeParametersClass(SC_Lib *p, SC_Cell *pRepr, float Slew, float *pLD, float *pPD)
Definition: sclLibUtil.c:396
SC_Cell * Abc_SclFindSmallestGate(SC_Cell *p, float CinMin)
Definition: sclLibUtil.c:208
int n_inputs
Definition: sclLib.h:192
#define SC_LibForEachWireLoad(p, pWL, i)
Definition: sclLib.h:250
Mio_Library_t * Abc_SclDeriveGenlibSimple(void *pScl)
Definition: sclLibUtil.c:710
void Abc_SclMarkSkippedCells(SC_Lib *p)
Definition: sclLibUtil.c:474
static char * SC_CellPinOutFunc(SC_Cell *p, int i)
Definition: sclLib.h:245
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
static ABC_NAMESPACE_IMPL_START unsigned Abc_SclHashString(char *pName, int TableSize)
DECLARATIONS ///.
Definition: sclLibUtil.c:48
int strlen()
SC_Cell * pPrev
Definition: sclLib.h:195
char * pName
Definition: sclLib.h:169
float cap
Definition: sclLib.h:171
static void Vec_StrPrintStr(Vec_Str_t *p, const char *pStr)
Definition: vecStr.h:627
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 fSkip
Definition: sclLib.h:185
static int Vec_FltSize(Vec_Flt_t *p)
Definition: vecFlt.h:294
SC_Cell * pNext
Definition: sclLib.h:194
float Abc_SclComputeDelayClassPin(SC_Lib *p, SC_Cell *pRepr, int iPin, float Slew, float Gain)
Definition: sclLibUtil.c:432
static void ** Vec_PtrArray(Vec_Ptr_t *p)
Definition: vecPtr.h:279
static Vec_Str_t * Vec_StrDup(Vec_Str_t *pVec)
Definition: vecStr.h:158
int Abc_SclClassCellNum(SC_Cell *pClass)
Definition: sclLibUtil.c:84
char * default_wire_load_sel
Definition: sclLib.h:207
char * pName
Definition: sclLib.h:204
#define ABC_FALLOC(type, num)
Definition: abc_global.h:231
#define SC_LibForEachCell(p, pCell, i)
Definition: sclLib.h:248
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223