ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
sclLibScl.c
Go to the documentation of this file.
1
20
21#include "sclLib.h"
22#include "misc/st/st.h"
23#include "map/mio/mio.h"
24#include "bool/kit/kit.h"
25#include "misc/extra/extra.h"
26#include "misc/util/utilNam.h"
27#include "map/scl/sclCon.h"
28
30
31
35
39
40
52static void Abc_SclReadSurfaceGenlib( SC_Surface * p )
53{
54 Vec_Flt_t * vVec;
55 Vec_Int_t * vVecI;
56 int i, j;
57
58 Vec_FltPush( &p->vIndex0, 0 );
59 Vec_IntPush( &p->vIndex0I, Scl_Flt2Int(0) );
60
61 Vec_FltPush( &p->vIndex1, 0 );
62 Vec_IntPush( &p->vIndex1I, Scl_Flt2Int(0) );
63
64 for ( i = 0; i < Vec_FltSize(&p->vIndex0); i++ )
65 {
66 vVec = Vec_FltAlloc( Vec_FltSize(&p->vIndex1) );
67 Vec_PtrPush( &p->vData, vVec );
68 vVecI = Vec_IntAlloc( Vec_FltSize(&p->vIndex1) );
69 Vec_PtrPush( &p->vDataI, vVecI );
70 for ( j = 0; j < Vec_FltSize(&p->vIndex1); j++ )
71 {
72 Vec_FltPush( vVec, 1 );
73 Vec_IntPush( vVecI, Scl_Flt2Int(1) );
74 }
75 }
76}
77static int Abc_SclReadLibraryGenlib( SC_Lib * p, Mio_Library_t * pLib )
78{
79 Mio_Gate_t * pGate;
80 Mio_Pin_t * pGatePin;
81 int j, k;
82
83 // Read non-composite fields:
84 p->pName = Abc_UtilStrsav( Mio_LibraryReadName(pLib) );
85 p->default_wire_load = 0;
86 p->default_wire_load_sel = 0;
87 p->default_max_out_slew = 0;
88
89 p->unit_time = 12;
90 p->unit_cap_fst = 1.0;
91 p->unit_cap_snd = 15;
92
93 Mio_LibraryForEachGate( pLib, pGate )
94 {
95 SC_Cell * pCell = Abc_SclCellAlloc();
96 pCell->Id = SC_LibCellNum(p);
97 Vec_PtrPush( &p->vCells, pCell );
98
99 pCell->pName = Abc_UtilStrsav( Mio_GateReadName( pGate ) );
100 pCell->area = Mio_GateReadArea( pGate );
101 pCell->leakage = 0;
102 pCell->drive_strength = 0;
103
104 pCell->n_inputs = Mio_GateReadPinNum( pGate );
105 pCell->n_outputs = 1;
106
107 pCell->areaI = Scl_Flt2Int(pCell->area);
108 pCell->leakageI = Scl_Flt2Int(pCell->leakage);
109
110 Mio_GateForEachPin( pGate, pGatePin )
111 {
112 SC_Pin * pPin = Abc_SclPinAlloc();
113 Vec_PtrPush( &pCell->vPins, pPin );
114
115 pPin->dir = sc_dir_Input;
116 pPin->pName = Abc_UtilStrsav( Mio_PinReadName( pGatePin ) );
117 pPin->rise_cap = 0;
118 pPin->fall_cap = 0;
119
120 pPin->rise_capI = Scl_Flt2Int(pPin->rise_cap);
121 pPin->fall_capI = Scl_Flt2Int(pPin->fall_cap);
122 }
123
124 for ( j = 0; j < pCell->n_outputs; j++ )
125 {
126 word * pTruth = Mio_GateReadTruthP( pGate );
127 SC_Pin * pPin = Abc_SclPinAlloc();
128 Vec_PtrPush( &pCell->vPins, pPin );
129
130 pPin->dir = sc_dir_Output;
131 pPin->pName = Abc_UtilStrsav( Mio_GateReadOutName( pGate ) );
132 pPin->max_out_cap = 0;
133 pPin->max_out_slew = 0;
134
135 // read function
136 pPin->func_text = Abc_UtilStrsav( Mio_GateReadForm( pGate ) );
137 Vec_WrdGrow( &pPin->vFunc, Abc_Truth6WordNum(pCell->n_inputs) );
138 for ( k = 0; k < Vec_WrdCap(&pPin->vFunc); k++ )
139 Vec_WrdPush( &pPin->vFunc, pTruth[k] );
140
141 // read pins
142 Mio_GateForEachPin( pGate, pGatePin )
143 {
144 Mio_PinPhase_t Value = Mio_PinReadPhase( pGatePin );
145 SC_Timings * pRTime = Abc_SclTimingsAlloc();
146 Vec_PtrPush( &pPin->vRTimings, pRTime );
147 pRTime->pName = Abc_UtilStrsav( Mio_PinReadName( pGatePin ) );
148 if ( 1 )
149 {
150 SC_Timing * pTime = Abc_SclTimingAlloc();
151 Vec_PtrPush( &pRTime->vTimings, pTime );
152 if ( Value == MIO_PHASE_UNKNOWN )
153 pTime->tsense = (SC_TSense)sc_ts_Non;
154 else if ( Value == MIO_PHASE_INV )
155 pTime->tsense = (SC_TSense)sc_ts_Neg;
156 else if ( Value == MIO_PHASE_NONINV )
157 pTime->tsense = (SC_TSense)sc_ts_Pos;
158 else assert( 0 );
159 Abc_SclReadSurfaceGenlib( &pTime->pCellRise );
160 Abc_SclReadSurfaceGenlib( &pTime->pCellFall );
161 Abc_SclReadSurfaceGenlib( &pTime->pRiseTrans );
162 Abc_SclReadSurfaceGenlib( &pTime->pFallTrans );
163 }
164 }
165 }
166 }
167 return 1;
168}
170{
171 Mio_Library_t * pLib = (Mio_Library_t *)pLib0;
172 SC_Lib * p = Abc_SclLibAlloc();
173 if ( !Abc_SclReadLibraryGenlib( p, pLib ) )
174 return NULL;
175 // hash gates by name
178 return p;
179}
180
181
193static void Abc_SclReadSurface( Vec_Str_t * vOut, int * pPos, SC_Surface * p )
194{
195 Vec_Flt_t * vVec;
196 Vec_Int_t * vVecI;
197 int i, j;
198
199 for ( i = Vec_StrGetI(vOut, pPos); i != 0; i-- )
200 {
201 float Num = Vec_StrGetF(vOut, pPos);
202 Vec_FltPush( &p->vIndex0, Num );
203 Vec_IntPush( &p->vIndex0I, Scl_Flt2Int(Num) );
204 }
205
206 for ( i = Vec_StrGetI(vOut, pPos); i != 0; i-- )
207 {
208 float Num = Vec_StrGetF(vOut, pPos);
209 Vec_FltPush( &p->vIndex1, Num );
210 Vec_IntPush( &p->vIndex1I, Scl_Flt2Int(Num) );
211 }
212
213 for ( i = 0; i < Vec_FltSize(&p->vIndex0); i++ )
214 {
215 vVec = Vec_FltAlloc( Vec_FltSize(&p->vIndex1) );
216 Vec_PtrPush( &p->vData, vVec );
217 vVecI = Vec_IntAlloc( Vec_FltSize(&p->vIndex1) );
218 Vec_PtrPush( &p->vDataI, vVecI );
219 for ( j = 0; j < Vec_FltSize(&p->vIndex1); j++ )
220 {
221 float Num = Vec_StrGetF(vOut, pPos);
222 Vec_FltPush( vVec, Num );
223 Vec_IntPush( vVecI, Scl_Flt2Int(Num) );
224 }
225 }
226
227 for ( i = 0; i < 3; i++ )
228 p->approx[0][i] = Vec_StrGetF( vOut, pPos );
229 for ( i = 0; i < 4; i++ )
230 p->approx[1][i] = Vec_StrGetF( vOut, pPos );
231 for ( i = 0; i < 6; i++ )
232 p->approx[2][i] = Vec_StrGetF( vOut, pPos );
233}
234static int Abc_SclReadLibrary( Vec_Str_t * vOut, int * pPos, SC_Lib * p )
235{
236 int i, j, k, n;
237 int version = Vec_StrGetI( vOut, pPos );
238 if ( version != ABC_SCL_CUR_VERSION )
239 {
240 Abc_Print( -1, "Wrong version of the SCL file.\n" );
241 return 0;
242 }
243 assert( version == ABC_SCL_CUR_VERSION ); // wrong version of the file
244
245 // Read non-composite fields:
246 p->pName = Vec_StrGetS(vOut, pPos);
247 p->default_wire_load = Vec_StrGetS(vOut, pPos);
248 p->default_wire_load_sel = Vec_StrGetS(vOut, pPos);
249 p->default_max_out_slew = Vec_StrGetF(vOut, pPos);
250
251 p->unit_time = Vec_StrGetI(vOut, pPos);
252 p->unit_cap_fst = Vec_StrGetF(vOut, pPos);
253 p->unit_cap_snd = Vec_StrGetI(vOut, pPos);
254
255 // Read 'wire_load' vector:
256 for ( i = Vec_StrGetI(vOut, pPos); i != 0; i-- )
257 {
258 SC_WireLoad * pWL = Abc_SclWireLoadAlloc();
259 Vec_PtrPush( &p->vWireLoads, pWL );
260
261 pWL->pName = Vec_StrGetS(vOut, pPos);
262 pWL->cap = Vec_StrGetF(vOut, pPos);
263 pWL->slope = Vec_StrGetF(vOut, pPos);
264
265 for ( j = Vec_StrGetI(vOut, pPos); j != 0; j-- )
266 {
267 Vec_IntPush( &pWL->vFanout, Vec_StrGetI(vOut, pPos) );
268 Vec_FltPush( &pWL->vLen, Vec_StrGetF(vOut, pPos) );
269 }
270 }
271
272 // Read 'wire_load_sel' vector:
273 for ( i = Vec_StrGetI(vOut, pPos); i != 0; i-- )
274 {
275 SC_WireLoadSel * pWLS = Abc_SclWireLoadSelAlloc();
276 Vec_PtrPush( &p->vWireLoadSels, pWLS );
277
278 pWLS->pName = Vec_StrGetS(vOut, pPos);
279 for ( j = Vec_StrGetI(vOut, pPos); j != 0; j-- )
280 {
281 Vec_FltPush( &pWLS->vAreaFrom, Vec_StrGetF(vOut, pPos) );
282 Vec_FltPush( &pWLS->vAreaTo, Vec_StrGetF(vOut, pPos) );
283 Vec_PtrPush( &pWLS->vWireLoadModel, Vec_StrGetS(vOut, pPos) );
284 }
285 }
286
287 for ( i = Vec_StrGetI(vOut, pPos); i != 0; i-- )
288 {
289 SC_Cell * pCell = Abc_SclCellAlloc();
290 pCell->Id = SC_LibCellNum(p);
291 Vec_PtrPush( &p->vCells, pCell );
292
293 pCell->pName = Vec_StrGetS(vOut, pPos);
294 pCell->area = Vec_StrGetF(vOut, pPos);
295 pCell->leakage = Vec_StrGetF(vOut, pPos);
296 pCell->drive_strength = Vec_StrGetI(vOut, pPos);
297
298 pCell->n_inputs = Vec_StrGetI(vOut, pPos);
299 pCell->n_outputs = Vec_StrGetI(vOut, pPos);
300
301 pCell->areaI = Scl_Flt2Int(pCell->area);
302 pCell->leakageI = Scl_Flt2Int(pCell->leakage);
303/*
304 printf( "%s\n", pCell->pName );
305 if ( !strcmp( "XOR3_X4M_A9TL", pCell->pName ) )
306 {
307 int s = 0;
308 }
309*/
310 for ( j = 0; j < pCell->n_inputs; j++ )
311 {
312 SC_Pin * pPin = Abc_SclPinAlloc();
313 Vec_PtrPush( &pCell->vPins, pPin );
314
315 pPin->dir = sc_dir_Input;
316 pPin->pName = Vec_StrGetS(vOut, pPos);
317 pPin->rise_cap = Vec_StrGetF(vOut, pPos);
318 pPin->fall_cap = Vec_StrGetF(vOut, pPos);
319
320 pPin->rise_capI = Scl_Flt2Int(pPin->rise_cap);
321 pPin->fall_capI = Scl_Flt2Int(pPin->fall_cap);
322 }
323
324 for ( j = 0; j < pCell->n_outputs; j++ )
325 {
326 SC_Pin * pPin = Abc_SclPinAlloc();
327 Vec_PtrPush( &pCell->vPins, pPin );
328
329 pPin->dir = sc_dir_Output;
330 pPin->pName = Vec_StrGetS(vOut, pPos);
331 pPin->max_out_cap = Vec_StrGetF(vOut, pPos);
332 pPin->max_out_slew = Vec_StrGetF(vOut, pPos);
333
334 k = Vec_StrGetI(vOut, pPos);
335 assert( k == pCell->n_inputs );
336
337 // read function
338 // (possibly empty) formula is always given
339 assert( version == ABC_SCL_CUR_VERSION );
340 assert( pPin->func_text == NULL );
341 pPin->func_text = Vec_StrGetS(vOut, pPos);
342 if ( pPin->func_text[0] == 0 )
343 {
344 // formula is not given - read truth table
345 ABC_FREE( pPin->func_text );
346 assert( Vec_WrdSize(&pPin->vFunc) == 0 );
347 Vec_WrdGrow( &pPin->vFunc, Abc_Truth6WordNum(pCell->n_inputs) );
348 for ( k = 0; k < Vec_WrdCap(&pPin->vFunc); k++ )
349 Vec_WrdPush( &pPin->vFunc, Vec_StrGetW(vOut, pPos) );
350 }
351 else
352 {
353 // formula is given - derive truth table
354 SC_Pin * pPin2;
355 Vec_Ptr_t * vNames;
356 Vec_Wrd_t * vFunc;
357 // collect input names
358 vNames = Vec_PtrAlloc( pCell->n_inputs );
359 SC_CellForEachPinIn( pCell, pPin2, n )
360 Vec_PtrPush( vNames, pPin2->pName );
361 // derive truth table
362 assert( Vec_WrdSize(&pPin->vFunc) == 0 );
363 Vec_WrdErase( &pPin->vFunc );
364 vFunc = Mio_ParseFormulaTruth( pPin->func_text, (char **)Vec_PtrArray(vNames), pCell->n_inputs );
365 pPin->vFunc = *vFunc;
366 ABC_FREE( vFunc );
367 Vec_PtrFree( vNames );
368 // skip truth table
369 assert( Vec_WrdSize(&pPin->vFunc) == Abc_Truth6WordNum(pCell->n_inputs) );
370 for ( k = 0; k < Vec_WrdSize(&pPin->vFunc); k++ )
371 {
372 word Value = Vec_StrGetW(vOut, pPos);
373 assert( Value == Vec_WrdEntry(&pPin->vFunc, k) );
374 }
375 }
376
377 // Read 'rtiming': (pin-to-pin timing tables for this particular output)
378 for ( k = 0; k < pCell->n_inputs; k++ )
379 {
380 SC_Timings * pRTime = Abc_SclTimingsAlloc();
381 Vec_PtrPush( &pPin->vRTimings, pRTime );
382
383 pRTime->pName = Vec_StrGetS(vOut, pPos);
384 n = Vec_StrGetI(vOut, pPos); assert( n <= 1 );
385 if ( n == 1 )
386 {
387 SC_Timing * pTime = Abc_SclTimingAlloc();
388 Vec_PtrPush( &pRTime->vTimings, pTime );
389
390 pTime->tsense = (SC_TSense)Vec_StrGetI(vOut, pPos);
391 Abc_SclReadSurface( vOut, pPos, &pTime->pCellRise );
392 Abc_SclReadSurface( vOut, pPos, &pTime->pCellFall );
393 Abc_SclReadSurface( vOut, pPos, &pTime->pRiseTrans );
394 Abc_SclReadSurface( vOut, pPos, &pTime->pFallTrans );
395 }
396 else
397 assert( Vec_PtrSize(&pRTime->vTimings) == 0 );
398 }
399 }
400 }
401 return 1;
402}
404{
405 SC_Lib * p;
406 int Pos = 0;
407 // read the library
408 p = Abc_SclLibAlloc();
409 if ( !Abc_SclReadLibrary( vOut, &Pos, p ) )
410 return NULL;
411 assert( Pos == Vec_StrSize(vOut) );
412 // hash gates by name
415 return p;
416}
417SC_Lib * Abc_SclReadFromFile( char * pFileName )
418{
419 SC_Lib * p;
420 FILE * pFile;
421 Vec_Str_t * vOut;
422 int nFileSize;
423 pFile = fopen( pFileName, "rb" );
424 if ( pFile == NULL )
425 {
426 printf( "Cannot open file \"%s\" for reading.\n", pFileName );
427 return NULL;
428 }
429 // get the file size, in bytes
430 fseek( pFile, 0, SEEK_END );
431 nFileSize = ftell( pFile );
432 rewind( pFile );
433 // load the contents
434 vOut = Vec_StrAlloc( nFileSize );
435 vOut->nSize = vOut->nCap;
436 assert( nFileSize == Vec_StrSize(vOut) );
437 nFileSize = fread( Vec_StrArray(vOut), 1, Vec_StrSize(vOut), pFile );
438 assert( nFileSize == Vec_StrSize(vOut) );
439 fclose( pFile );
440 // read the library
441 p = Abc_SclReadFromStr( vOut );
442 if ( p != NULL )
443 p->pFileName = Abc_UtilStrsav( pFileName );
444 if ( p != NULL )
446 Vec_StrFree( vOut );
447 return p;
448}
449
461static void Abc_SclWriteSurface( Vec_Str_t * vOut, SC_Surface * p )
462{
463 Vec_Flt_t * vVec;
464 float Entry;
465 int i, k;
466
467 Vec_StrPutI( vOut, Vec_FltSize(&p->vIndex0) );
468 Vec_FltForEachEntry( &p->vIndex0, Entry, i )
469 Vec_StrPutF( vOut, Entry );
470
471 Vec_StrPutI( vOut, Vec_FltSize(&p->vIndex1) );
472 Vec_FltForEachEntry( &p->vIndex1, Entry, i )
473 Vec_StrPutF( vOut, Entry );
474
475 Vec_PtrForEachEntry( Vec_Flt_t *, &p->vData, vVec, i )
476 Vec_FltForEachEntry( vVec, Entry, k )
477 Vec_StrPutF( vOut, Entry );
478
479 for ( i = 0; i < 3; i++ )
480 Vec_StrPutF( vOut, p->approx[0][i] );
481 for ( i = 0; i < 4; i++ )
482 Vec_StrPutF( vOut, p->approx[1][i] );
483 for ( i = 0; i < 6; i++ )
484 Vec_StrPutF( vOut, p->approx[2][i] );
485}
486static void Abc_SclWriteLibraryCellsOnly( Vec_Str_t * vOut, SC_Lib * p, int fAddOn )
487{
488 SC_Cell * pCell;
489 SC_Pin * pPin;
490 int i, j, k;
491 SC_LibForEachCell( p, pCell, i )
492 {
493 if ( pCell->seq || pCell->unsupp )
494 continue;
495
496 if ( fAddOn ) {
497 Vec_StrPush( vOut, 'L' );
498 Vec_StrPush( vOut, '0'+(char)fAddOn );
499 Vec_StrPush( vOut, '_' );
500 }
501
502 Vec_StrPutS( vOut, pCell->pName );
503 Vec_StrPutF( vOut, pCell->area );
504 Vec_StrPutF( vOut, pCell->leakage );
505 Vec_StrPutI( vOut, pCell->drive_strength );
506
507 // Write 'pins': (sorted at this point; first inputs, then outputs)
508 Vec_StrPutI( vOut, pCell->n_inputs);
509 Vec_StrPutI( vOut, pCell->n_outputs);
510
511 SC_CellForEachPinIn( pCell, pPin, j )
512 {
513 assert(pPin->dir == sc_dir_Input);
514 Vec_StrPutS( vOut, pPin->pName );
515 Vec_StrPutF( vOut, pPin->rise_cap );
516 Vec_StrPutF( vOut, pPin->fall_cap );
517 }
518
519 SC_CellForEachPinOut( pCell, pPin, j )
520 {
521 SC_Timings * pRTime;
522 word uWord;
523
524 assert(pPin->dir == sc_dir_Output);
525 Vec_StrPutS( vOut, pPin->pName );
526 Vec_StrPutF( vOut, pPin->max_out_cap );
527 Vec_StrPutF( vOut, pPin->max_out_slew );
528 Vec_StrPutI( vOut, pCell->n_inputs );
529
530 // write function
531 Vec_StrPutS( vOut, pPin->func_text ? pPin->func_text : (char *)"" );
532
533 // write truth table
534 assert( Vec_WrdSize(&pPin->vFunc) == Abc_Truth6WordNum(pCell->n_inputs) );
535 Vec_WrdForEachEntry( &pPin->vFunc, uWord, k ) // -- 'size = 1u << (n_vars - 6)'
536 Vec_StrPutW( vOut, uWord ); // -- 64-bit number, written uncompressed (low-byte first)
537
538 // Write 'rtiming': (pin-to-pin timing tables for this particular output)
539 assert( Vec_PtrSize(&pPin->vRTimings) == pCell->n_inputs );
540 SC_PinForEachRTiming( pPin, pRTime, k )
541 {
542 Vec_StrPutS( vOut, pRTime->pName );
543 Vec_StrPutI( vOut, Vec_PtrSize(&pRTime->vTimings) );
544 // -- NOTE! After post-processing, the size of the 'rtiming[k]' vector is either
545 // 0 or 1 (in static timing, we have merged all tables to get the worst case).
546 // The case with size 0 should only occur for multi-output gates.
547 if ( Vec_PtrSize(&pRTime->vTimings) == 1 )
548 {
549 SC_Timing * pTime = (SC_Timing *)Vec_PtrEntry( &pRTime->vTimings, 0 );
550 // -- NOTE! We don't need to save 'related_pin' string because we have sorted
551 // the elements on input pins.
552 Vec_StrPutI( vOut, (int)pTime->tsense);
553 Abc_SclWriteSurface( vOut, &pTime->pCellRise );
554 Abc_SclWriteSurface( vOut, &pTime->pCellFall );
555 Abc_SclWriteSurface( vOut, &pTime->pRiseTrans );
556 Abc_SclWriteSurface( vOut, &pTime->pFallTrans );
557 }
558 else
559 assert( Vec_PtrSize(&pRTime->vTimings) == 0 );
560 }
561 }
562 }
563}
565{
566 SC_Cell * pCell;
567 int i, n_valid_cells = 0;
568 SC_LibForEachCell( p, pCell, i )
569 if ( !(pCell->seq || pCell->unsupp) )
570 n_valid_cells++;
571 return n_valid_cells;
572}
573static void Abc_SclWriteLibrary( Vec_Str_t * vOut, SC_Lib * p, int nExtra, int fUsePrefix )
574{
575 SC_WireLoad * pWL;
576 SC_WireLoadSel * pWLS;
577 int n_valid_cells;
578 int i, j;
579
580 Vec_StrPutI( vOut, ABC_SCL_CUR_VERSION );
581
582 // Write non-composite fields:
583 Vec_StrPutS( vOut, p->pName );
584 Vec_StrPutS( vOut, p->default_wire_load );
585 Vec_StrPutS( vOut, p->default_wire_load_sel );
586 Vec_StrPutF( vOut, p->default_max_out_slew );
587
588 assert( p->unit_time >= 0 );
589 assert( p->unit_cap_snd >= 0 );
590 Vec_StrPutI( vOut, p->unit_time );
591 Vec_StrPutF( vOut, p->unit_cap_fst );
592 Vec_StrPutI( vOut, p->unit_cap_snd );
593
594 // Write 'wire_load' vector:
595 Vec_StrPutI( vOut, Vec_PtrSize(&p->vWireLoads) );
596 SC_LibForEachWireLoad( p, pWL, i )
597 {
598 Vec_StrPutS( vOut, pWL->pName );
599 Vec_StrPutF( vOut, pWL->cap );
600 Vec_StrPutF( vOut, pWL->slope );
601
602 Vec_StrPutI( vOut, Vec_IntSize(&pWL->vFanout) );
603 for ( j = 0; j < Vec_IntSize(&pWL->vFanout); j++ )
604 {
605 Vec_StrPutI( vOut, Vec_IntEntry(&pWL->vFanout, j) );
606 Vec_StrPutF( vOut, Vec_FltEntry(&pWL->vLen, j) );
607 }
608 }
609
610 // Write 'wire_load_sel' vector:
611 Vec_StrPutI( vOut, Vec_PtrSize(&p->vWireLoadSels) );
612 SC_LibForEachWireLoadSel( p, pWLS, i )
613 {
614 Vec_StrPutS( vOut, pWLS->pName );
615 Vec_StrPutI( vOut, Vec_FltSize(&pWLS->vAreaFrom) );
616 for ( j = 0; j < Vec_FltSize(&pWLS->vAreaFrom); j++)
617 {
618 Vec_StrPutF( vOut, Vec_FltEntry(&pWLS->vAreaFrom, j) );
619 Vec_StrPutF( vOut, Vec_FltEntry(&pWLS->vAreaTo, j) );
620 Vec_StrPutS( vOut, (char *)Vec_PtrEntry(&pWLS->vWireLoadModel, j) );
621 }
622 }
623
624 // Write 'cells' vector:
625 n_valid_cells = Abc_SclCountValidCells( p );
626 Vec_StrPutI( vOut, n_valid_cells + nExtra );
627 Abc_SclWriteLibraryCellsOnly( vOut, p, fUsePrefix ? 1 : 0 );
628}
629void Abc_SclWriteScl( char * pFileName, SC_Lib * p )
630{
631 Vec_Str_t * vOut;
632 vOut = Vec_StrAlloc( 10000 );
633 Abc_SclWriteLibrary( vOut, p, 0, 0 );
634 if ( Vec_StrSize(vOut) > 0 )
635 {
636 FILE * pFile = fopen( pFileName, "wb" );
637 if ( pFile == NULL )
638 printf( "Cannot open file \"%s\" for writing.\n", pFileName );
639 else
640 {
641 fwrite( Vec_StrArray(vOut), 1, Vec_StrSize(vOut), pFile );
642 fclose( pFile );
643 }
644 }
645 Vec_StrFree( vOut );
646}
647
648
660static void Abc_SclWriteSurfaceText( FILE * s, SC_Surface * p )
661{
662 Vec_Flt_t * vVec;
663 float Entry;
664 int i, k;
665
666 fprintf( s, " index_1(\"" );
667 Vec_FltForEachEntry( &p->vIndex0, Entry, i )
668 fprintf( s, "%f%s", Entry, i == Vec_FltSize(&p->vIndex0)-1 ? "":", " );
669 fprintf( s, "\");\n" );
670
671 fprintf( s, " index_2(\"" );
672 Vec_FltForEachEntry( &p->vIndex1, Entry, i )
673 fprintf( s, "%f%s", Entry, i == Vec_FltSize(&p->vIndex1)-1 ? "":", " );
674 fprintf( s, "\");\n" );
675
676 fprintf( s, " values (\"" );
677 Vec_PtrForEachEntry( Vec_Flt_t *, &p->vData, vVec, i )
678 {
679 Vec_FltForEachEntry( vVec, Entry, k )
680 fprintf( s, "%f%s", Entry, i == Vec_PtrSize(&p->vData)-1 && k == Vec_FltSize(vVec)-1 ? "\");":", " );
681 if ( i == Vec_PtrSize(&p->vData)-1 )
682 fprintf( s, "\n" );
683 else
684 {
685 fprintf( s, "\\\n" );
686 fprintf( s, " " );
687 }
688 }
689/*
690 fprintf( s, " approximations: \n" );
691 fprintf( s, " " );
692 for ( i = 0; i < 3; i++ )
693 fprintf( s, "%f ", p->approx[0][i] );
694 fprintf( s, "\n" );
695 fprintf( s, " " );
696 for ( i = 0; i < 4; i++ )
697 fprintf( s, "%f ", p->approx[1][i] );
698 fprintf( s, "\n" );
699 fprintf( s, " " );
700 for ( i = 0; i < 6; i++ )
701 fprintf( s, "%f ", p->approx[2][i] );
702 fprintf( s, "\n" );
703 fprintf( s, " \n" );
704*/
705}
706static void Abc_SclWriteLibraryText( FILE * s, SC_Lib * p )
707{
708 SC_WireLoad * pWL;
709 SC_WireLoadSel * pWLS;
710 SC_Cell * pCell;
711 SC_Pin * pPin;
712 int n_valid_cells;
713 int i, j, k;
714 fprintf( s, "/* This Liberty file was generated by ABC on %s */\n", Extra_TimeStamp() );
715 fprintf( s, "/* The original unabridged library came from file \"%s\".*/\n\n", p->pFileName );
716
717// fprintf( s, "%d", ABC_SCL_CUR_VERSION );
718 fprintf( s, "library(%s) {\n\n", p->pName );
719 if ( p->default_wire_load && strlen(p->default_wire_load) )
720 fprintf( s, " default_wire_load : \"%s\";\n", p->default_wire_load );
721 if ( p->default_wire_load_sel && strlen(p->default_wire_load_sel) )
722 fprintf( s, " default_wire_load_selection : \"%s\";\n", p->default_wire_load_sel );
723 if ( p->default_max_out_slew != -1 )
724 fprintf( s, " default_max_transition : %f;\n", p->default_max_out_slew );
725 if ( p->unit_time == 9 )
726 fprintf( s, " time_unit : \"1ns\";\n" );
727 else if ( p->unit_time == 10 )
728 fprintf( s, " time_unit : \"100ps\";\n" );
729 else if ( p->unit_time == 11 )
730 fprintf( s, " time_unit : \"10ps\";\n" );
731 else if ( p->unit_time == 12 )
732 fprintf( s, " time_unit : \"1ps\";\n" );
733 else assert( 0 );
734 fprintf( s, " capacitive_load_unit(%.1f,%s);\n", p->unit_cap_fst, p->unit_cap_snd == 12 ? "pf" : "ff" );
735 fprintf( s, "\n" );
736
737 // Write 'wire_load' vector:
738 SC_LibForEachWireLoad( p, pWL, i )
739 {
740 fprintf( s, " wire_load(\"%s\") {\n", pWL->pName );
741 fprintf( s, " capacitance : %f;\n", pWL->cap );
742 fprintf( s, " slope : %f;\n", pWL->slope );
743 for ( j = 0; j < Vec_IntSize(&pWL->vFanout); j++ )
744 fprintf( s, " fanout_length( %d, %f );\n", Vec_IntEntry(&pWL->vFanout, j), Vec_FltEntry(&pWL->vLen, j) );
745 fprintf( s, " }\n\n" );
746 }
747
748 // Write 'wire_load_sel' vector:
749 SC_LibForEachWireLoadSel( p, pWLS, i )
750 {
751 fprintf( s, " wire_load_selection(\"%s\") {\n", pWLS->pName );
752 for ( j = 0; j < Vec_FltSize(&pWLS->vAreaFrom); j++)
753 fprintf( s, " wire_load_from_area( %f, %f, %s );\n",
754 Vec_FltEntry(&pWLS->vAreaFrom, j),
755 Vec_FltEntry(&pWLS->vAreaTo, j),
756 (char *)Vec_PtrEntry(&pWLS->vWireLoadModel, j) );
757 fprintf( s, " }\n\n" );
758 }
759
760 // Write 'cells' vector:
761 n_valid_cells = 0;
762 SC_LibForEachCell( p, pCell, i )
763 if ( !(pCell->seq || pCell->unsupp) )
764 n_valid_cells++;
765
766 SC_LibForEachCell( p, pCell, i )
767 {
768 if ( pCell->seq || pCell->unsupp )
769 continue;
770
771 fprintf( s, "\n" );
772 fprintf( s, " cell(%s) {\n", pCell->pName );
773 fprintf( s, " /* n_inputs = %d n_outputs = %d */\n", pCell->n_inputs, pCell->n_outputs );
774 fprintf( s, " area : %f;\n", pCell->area );
775 fprintf( s, " cell_leakage_power : %f;\n", pCell->leakage );
776 fprintf( s, " drive_strength : %d;\n", pCell->drive_strength );
777
778 SC_CellForEachPinIn( pCell, pPin, j )
779 {
780 assert(pPin->dir == sc_dir_Input);
781 fprintf( s, " pin(%s) {\n", pPin->pName );
782 fprintf( s, " direction : %s;\n", "input" );
783 fprintf( s, " fall_capacitance : %f;\n", pPin->fall_cap );
784 fprintf( s, " rise_capacitance : %f;\n", pPin->rise_cap );
785 fprintf( s, " }\n" );
786 }
787
788 SC_CellForEachPinOut( pCell, pPin, j )
789 {
790 SC_Timings * pRTime;
791// word uWord;
792 assert(pPin->dir == sc_dir_Output);
793 fprintf( s, " pin(%s) {\n", pPin->pName );
794 fprintf( s, " direction : %s;\n", "output" );
795 fprintf( s, " max_capacitance : %f;\n", pPin->max_out_cap );
796 fprintf( s, " max_transition : %f;\n", pPin->max_out_slew );
797 fprintf( s, " function : \"%s\";\n", pPin->func_text ? pPin->func_text : "?" );
798 fprintf( s, " /* truth table = " );
799 Extra_PrintHex( s, (unsigned *)Vec_WrdArray(&pPin->vFunc), pCell->n_inputs );
800 fprintf( s, " */\n" );
801
802 // Write 'rtiming': (pin-to-pin timing tables for this particular output)
803 assert( Vec_PtrSize(&pPin->vRTimings) == pCell->n_inputs );
804 SC_PinForEachRTiming( pPin, pRTime, k )
805 {
806 if ( Vec_PtrSize(&pRTime->vTimings) == 1 )
807 {
808 SC_Timing * pTime = (SC_Timing *)Vec_PtrEntry( &pRTime->vTimings, 0 );
809 fprintf( s, " timing() {\n" );
810 fprintf( s, " related_pin : \"%s\"\n", pRTime->pName );
811 if ( pTime->tsense == sc_ts_Pos )
812 fprintf( s, " timing_sense : positive_unate;\n" );
813 else if ( pTime->tsense == sc_ts_Neg )
814 fprintf( s, " timing_sense : negative_unate;\n" );
815 else if ( pTime->tsense == sc_ts_Non )
816 fprintf( s, " timing_sense : non_unate;\n" );
817 else assert( 0 );
818
819 fprintf( s, " cell_rise() {\n" );
820 Abc_SclWriteSurfaceText( s, &pTime->pCellRise );
821 fprintf( s, " }\n" );
822
823 fprintf( s, " cell_fall() {\n" );
824 Abc_SclWriteSurfaceText( s, &pTime->pCellFall );
825 fprintf( s, " }\n" );
826
827 fprintf( s, " rise_transition() {\n" );
828 Abc_SclWriteSurfaceText( s, &pTime->pRiseTrans );
829 fprintf( s, " }\n" );
830
831 fprintf( s, " fall_transition() {\n" );
832 Abc_SclWriteSurfaceText( s, &pTime->pFallTrans );
833 fprintf( s, " }\n" );
834 fprintf( s, " }\n" );
835 }
836 else
837 assert( Vec_PtrSize(&pRTime->vTimings) == 0 );
838 }
839 fprintf( s, " }\n" );
840 }
841 fprintf( s, " }\n" );
842 }
843 fprintf( s, "}\n\n" );
844}
845void Abc_SclWriteLiberty( char * pFileName, SC_Lib * p )
846{
847 FILE * pFile = fopen( pFileName, "wb" );
848 if ( pFile == NULL )
849 printf( "Cannot open text file \"%s\" for writing.\n", pFileName );
850 else
851 {
852 Abc_SclWriteLibraryText( pFile, p );
853 fclose( pFile );
854 printf( "Dumped internal library with %d cells into Liberty file \"%s\".\n", SC_LibCellNum(p), pFileName );
855 }
856}
857
869SC_Lib * Abc_SclMergeLibraries( SC_Lib * pLib1, SC_Lib * pLib2, int fUsePrefix )
870{
871 Vec_Str_t * vOut = Vec_StrAlloc( 10000 );
872 int n_valid_cells2 = Abc_SclCountValidCells( pLib2 );
873 Abc_SclWriteLibrary( vOut, pLib1, n_valid_cells2, fUsePrefix );
874 Abc_SclWriteLibraryCellsOnly( vOut, pLib2, fUsePrefix ? 2 : 0 );
875 SC_Lib * p = Abc_SclReadFromStr( vOut );
876 p->pFileName = Abc_UtilStrsav( pLib1->pFileName );
877 p->pName = ABC_ALLOC( char, strlen(pLib1->pName) + strlen(pLib2->pName) + 10 );
878 sprintf( p->pName, "%s__and__%s", pLib1->pName, pLib2->pName );
879 Vec_StrFree( vOut );
880 printf( "Updated library \"%s\" with additional %d cells from library \"%s\".\n", pLib1->pName, n_valid_cells2, pLib2->pName );
881 return p;
882}
883
887
888
890
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
ush Pos
Definition deflate.h:88
Cube * p
Definition exorList.c:222
char * Extra_TimeStamp()
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
int Mio_GateReadPinNum(Mio_Gate_t *pGate)
Definition mioApi.c:177
Vec_Wrd_t * Mio_ParseFormulaTruth(char *pFormInit, char **ppVarNames, int nVars)
Definition mioParse.c:396
char * Mio_LibraryReadName(Mio_Library_t *pLib)
DECLARATIONS ///.
Definition mioApi.c:43
Mio_PinPhase_t
INCLUDES ///.
Definition mio.h:40
@ MIO_PHASE_INV
Definition mio.h:40
@ MIO_PHASE_NONINV
Definition mio.h:40
@ MIO_PHASE_UNKNOWN
Definition mio.h:40
double Mio_GateReadArea(Mio_Gate_t *pGate)
Definition mioApi.c:171
struct Mio_LibraryStruct_t_ Mio_Library_t
Definition mio.h:42
Mio_PinPhase_t Mio_PinReadPhase(Mio_Pin_t *pPin)
Definition mioApi.c:209
char * Mio_PinReadName(Mio_Pin_t *pPin)
Definition mioApi.c:208
#define Mio_LibraryForEachGate(Lib, Gate)
GLOBAL VARIABLES ///.
Definition mio.h:81
char * Mio_GateReadName(Mio_Gate_t *pGate)
Definition mioApi.c:169
struct Mio_PinStruct_t_ Mio_Pin_t
Definition mio.h:44
char * Mio_GateReadOutName(Mio_Gate_t *pGate)
Definition mioApi.c:170
#define Mio_GateForEachPin(Gate, Pin)
Definition mio.h:92
struct Mio_GateStruct_t_ Mio_Gate_t
Definition mio.h:43
char * Mio_GateReadForm(Mio_Gate_t *pGate)
Definition mioApi.c:172
word * Mio_GateReadTruthP(Mio_Gate_t *pGate)
Definition mioApi.c:182
const char * version()
void Abc_SclWriteScl(char *pFileName, SC_Lib *p)
Definition sclLibScl.c:629
int Abc_SclCountValidCells(SC_Lib *p)
Definition sclLibScl.c:564
SC_Lib * Abc_SclMergeLibraries(SC_Lib *pLib1, SC_Lib *pLib2, int fUsePrefix)
Definition sclLibScl.c:869
void Abc_SclWriteLiberty(char *pFileName, SC_Lib *p)
Definition sclLibScl.c:845
SC_Lib * Abc_SclReadFromStr(Vec_Str_t *vOut)
Definition sclLibScl.c:403
SC_Lib * Abc_SclReadFromFile(char *pFileName)
Definition sclLibScl.c:417
SC_Lib * Abc_SclReadFromGenlib(void *pLib0)
Definition sclLibScl.c:169
#define SC_CellForEachPinIn(p, pPin, i)
Definition sclLib.h:275
#define SC_PinForEachRTiming(p, pRTime, i)
Definition sclLib.h:279
struct SC_Timing_ SC_Timing
Definition sclLib.h:124
SC_TSense
Definition sclLib.h:55
@ sc_ts_Neg
Definition sclLib.h:58
@ sc_ts_Non
Definition sclLib.h:59
@ sc_ts_Pos
Definition sclLib.h:57
#define SC_LibForEachCell(p, pCell, i)
Definition sclLib.h:269
struct SC_Lib_ SC_Lib
Definition sclLib.h:128
#define SC_CellForEachPinOut(p, pPin, i)
Definition sclLib.h:276
struct SC_WireLoadSel_ SC_WireLoadSel
Definition sclLib.h:121
void Abc_SclLibNormalize(SC_Lib *p)
Definition sclLibUtil.c:750
struct SC_Pin_ SC_Pin
Definition sclLib.h:126
@ sc_dir_Output
Definition sclLib.h:49
@ sc_dir_Input
Definition sclLib.h:48
#define SC_LibForEachWireLoadSel(p, pWLS, i)
Definition sclLib.h:272
struct SC_Timings_ SC_Timings
Definition sclLib.h:125
void Abc_SclHashCells(SC_Lib *p)
Definition sclLibUtil.c:65
void Abc_SclLinkCells(SC_Lib *p)
Definition sclLibUtil.c:264
#define SC_LibForEachWireLoad(p, pWL, i)
Definition sclLib.h:271
struct SC_Surface_ SC_Surface
Definition sclLib.h:123
struct SC_WireLoad_ SC_WireLoad
STRUCTURE DEFINITIONS ///.
Definition sclLib.h:120
struct SC_Cell_ SC_Cell
Definition sclLib.h:127
#define ABC_SCL_CUR_VERSION
INCLUDES ///.
Definition sclLib.h:43
float area
Definition sclLib.h:207
int n_outputs
Definition sclLib.h:214
char * pName
Definition sclLib.h:202
int drive_strength
Definition sclLib.h:211
int areaI
Definition sclLib.h:209
Vec_Ptr_t vPins
Definition sclLib.h:212
int n_inputs
Definition sclLib.h:213
int seq
Definition sclLib.h:205
int Id
Definition sclLib.h:203
float leakage
Definition sclLib.h:208
int leakageI
Definition sclLib.h:210
int unsupp
Definition sclLib.h:206
char * pFileName
Definition sclLib.h:226
char * pName
Definition sclLib.h:225
SC_Dir dir
Definition sclLib.h:186
float max_out_cap
Definition sclLib.h:192
int rise_capI
Definition sclLib.h:190
float rise_cap
Definition sclLib.h:188
float fall_cap
Definition sclLib.h:189
char * pName
Definition sclLib.h:185
char * func_text
Definition sclLib.h:194
Vec_Wrd_t vFunc
Definition sclLib.h:195
int fall_capI
Definition sclLib.h:191
float max_out_slew
Definition sclLib.h:193
Vec_Ptr_t vRTimings
Definition sclLib.h:196
SC_Surface pRiseTrans
Definition sclLib.h:173
SC_TSense tsense
Definition sclLib.h:169
SC_Surface pCellRise
Definition sclLib.h:171
SC_Surface pFallTrans
Definition sclLib.h:174
SC_Surface pCellFall
Definition sclLib.h:172
char * pName
Definition sclLib.h:179
Vec_Ptr_t vTimings
Definition sclLib.h:180
Vec_Flt_t vAreaFrom
Definition sclLib.h:142
char * pName
Definition sclLib.h:141
Vec_Flt_t vAreaTo
Definition sclLib.h:143
Vec_Ptr_t vWireLoadModel
Definition sclLib.h:144
float cap
Definition sclLib.h:133
char * pName
Definition sclLib.h:132
Vec_Int_t vFanout
Definition sclLib.h:135
float slope
Definition sclLib.h:134
Vec_Flt_t vLen
Definition sclLib.h:136
int nCap
Definition bblif.c:49
int nSize
Definition bblif.c:50
#define assert(ex)
Definition util_old.h:213
int strlen()
char * sprintf()
VOID_HACK rewind()
#define Vec_FltForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecFlt.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
Definition vecFlt.h:42
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55
#define Vec_WrdForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecWrd.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition vecWrd.h:42
#define SEEK_END
Definition zconf.h:392