abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sclUtil.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [sclUtil.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Standard-cell library representation.]
8 
9  Synopsis [Various 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: sclUtil.c,v 1.0 2012/08/24 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "sclSize.h"
22 #include "map/mio/mio.h"
23 #include "base/main/main.h"
24 
26 
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 /**Function*************************************************************
37 
38  Synopsis [Converts pNode->pData gates into array of SC_Lit gate IDs and back.]
39 
40  Description []
41 
42  SideEffects []
43 
44  SeeAlso []
45 
46 ***********************************************************************/
48 {
49  Abc_Obj_t * pObj;
50  int i, gateId, bufferId;
51  // find buffer
52  if ( Mio_LibraryReadBuf((Mio_Library_t *)p->pManFunc) == NULL )
53  {
54  printf( "Cannot find buffer in the current library. Quitting.\n" );
55  return;
56  }
58  assert( bufferId >= 0 );
59  // remap cells
60  assert( p->vGates == NULL );
62  Abc_NtkForEachNode1( p, pObj, i )
63  {
64  if ( Abc_ObjIsBarBuf(pObj) )
65  gateId = bufferId;
66  else
67  gateId = Abc_SclCellFind( pLib, Mio_GateReadName((Mio_Gate_t *)pObj->pData) );
68  assert( gateId >= 0 );
69  Vec_IntWriteEntry( p->vGates, i, gateId );
70  }
71  p->pSCLib = pLib;
72 }
74 {
75  Abc_Obj_t * pObj;
76  SC_Cell * pCell;
77  int i, Counter = 0, CounterAll = 0;
78  assert( p->vGates != NULL );
79  Abc_NtkForEachNode1( p, pObj, i )
80  {
81  pCell = Abc_SclObjCell(pObj);
82  assert( pCell->n_inputs == Abc_ObjFaninNum(pObj) );
83  if ( Abc_ObjIsBarBuf(pObj) )
84  pObj->pData = NULL;
85  else
86  pObj->pData = Mio_LibraryReadGateByName( (Mio_Library_t *)p->pManFunc, pCell->pName, NULL );
87  Counter += (pObj->pData == NULL);
88  assert( pObj->fMarkA == 0 && pObj->fMarkB == 0 );
89  CounterAll++;
90  }
91  if ( Counter )
92  printf( "Could not find %d (out of %d) gates in the current library.\n", Counter, CounterAll );
93  Vec_IntFreeP( &p->vGates );
94  p->pSCLib = NULL;
95 }
96 
97 /**Function*************************************************************
98 
99  Synopsis [Reports percentage of gates of each size.]
100 
101  Description []
102 
103  SideEffects []
104 
105  SeeAlso []
106 
107 ***********************************************************************/
108 #define ABC_SCL_MAX_SIZE 64
110 {
111  Abc_Obj_t * pObj;
112  SC_Cell * pCell;
113  int i, nGates = 0, Counters[ABC_SCL_MAX_SIZE] = {0};
114  double TotArea = 0, Areas[ABC_SCL_MAX_SIZE] = {0};
115  Abc_NtkForEachNode1( p, pObj, i )
116  {
117  pCell = SC_LibCell( pLib, Vec_IntEntry(vGates, Abc_ObjId(pObj)) );
118  assert( pCell->Order < ABC_SCL_MAX_SIZE );
119  Counters[pCell->Order]++;
120  Areas[pCell->Order] += pCell->area;
121  TotArea += pCell->area;
122  nGates++;
123  }
124  printf( "Total gates = %d. Total area = %.1f\n", nGates, TotArea );
125  for ( i = 0; i < ABC_SCL_MAX_SIZE; i++ )
126  {
127  if ( Counters[i] == 0 )
128  continue;
129  printf( "Cell size = %d. ", i );
130  printf( "Count = %6d ", Counters[i] );
131  printf( "(%5.1f %%) ", 100.0 * Counters[i] / nGates );
132  printf( "Area = %12.1f ", Areas[i] );
133  printf( "(%5.1f %%) ", 100.0 * Areas[i] / TotArea );
134  printf( "\n" );
135  }
136 }
138 {
139  Abc_SclMioGates2SclGates( pLib, p );
140  Abc_SclManPrintGateSizes( pLib, p, p->vGates );
141  Abc_SclSclGates2MioGates( pLib, p );
142  Vec_IntFreeP( &p->vGates );
143  p->pSCLib = NULL;
144 }
145 
146 /**Function*************************************************************
147 
148  Synopsis [Downsizes each gate to its minimium size.]
149 
150  Description []
151 
152  SideEffects []
153 
154  SeeAlso []
155 
156 ***********************************************************************/
158 {
159  SC_Cell * pCell, * pBest = pRepr;
160  float AreaBest = pRepr->area;
161  int i;
162  SC_RingForEachCell( pRepr, pCell, i )
163  if ( AreaBest < pCell->area )
164  {
165  AreaBest = pCell->area;
166  pBest = pCell;
167  }
168  return pBest;
169 }
170 Vec_Int_t * Abc_SclFindMinAreas( SC_Lib * pLib, int fUseMax )
171 {
172  Vec_Int_t * vMinCells;
173  SC_Cell * pCell, * pRepr = NULL, * pBest = NULL;
174  int i, k;
175  // map each gate in the library into its min/max-size prototype
176  vMinCells = Vec_IntStartFull( Vec_PtrSize(pLib->vCells) );
177  SC_LibForEachCellClass( pLib, pRepr, i )
178  {
179  pBest = fUseMax ? Abc_SclFindMaxAreaCell(pRepr) : pRepr;
180  SC_RingForEachCell( pRepr, pCell, k )
181  Vec_IntWriteEntry( vMinCells, pCell->Id, pBest->Id );
182  }
183  return vMinCells;
184 }
185 void Abc_SclMinsizePerform( SC_Lib * pLib, Abc_Ntk_t * p, int fUseMax, int fVerbose )
186 {
187  Vec_Int_t * vMinCells;
188  Abc_Obj_t * pObj;
189  int i, gateId;
190  vMinCells = Abc_SclFindMinAreas( pLib, fUseMax );
191  Abc_SclMioGates2SclGates( pLib, p );
192  Abc_NtkForEachNode1( p, pObj, i )
193  {
194  gateId = Vec_IntEntry( p->vGates, i );
195  assert( gateId >= 0 && gateId < Vec_PtrSize(pLib->vCells) );
196  gateId = Vec_IntEntry( vMinCells, gateId );
197  assert( gateId >= 0 && gateId < Vec_PtrSize(pLib->vCells) );
198  Vec_IntWriteEntry( p->vGates, i, gateId );
199  }
200  Abc_SclSclGates2MioGates( pLib, p );
201  Vec_IntFree( vMinCells );
202 }
203 int Abc_SclCountMinSize( SC_Lib * pLib, Abc_Ntk_t * p, int fUseMax )
204 {
205  Vec_Int_t * vMinCells;
206  Abc_Obj_t * pObj;
207  int i, gateId, Counter = 0;
208  vMinCells = Abc_SclFindMinAreas( pLib, fUseMax );
209  Abc_NtkForEachNode1( p, pObj, i )
210  {
211  gateId = Vec_IntEntry( p->vGates, i );
212  Counter += ( gateId == Vec_IntEntry(vMinCells, gateId) );
213  }
214  Vec_IntFree( vMinCells );
215  return Counter;
216 }
217 
218 /**Function*************************************************************
219 
220  Synopsis [Reads timing constraints.]
221 
222  Description []
223 
224  SideEffects []
225 
226  SeeAlso []
227 
228 ***********************************************************************/
229 void Abc_SclReadTimingConstr( Abc_Frame_t * pAbc, char * pFileName, int fVerbose )
230 {
231  char Buffer[1000], * pToken;
232  FILE * pFile = fopen( pFileName, "rb" );
233  while ( fgets( Buffer, 1000, pFile ) )
234  {
235  pToken = strtok( Buffer, " \t\r\n" );
236  if ( pToken == NULL )
237  continue;
238  if ( !strcmp(pToken, "set_driving_cell") )
239  {
240  Abc_FrameSetDrivingCell( Abc_UtilStrsav(strtok(NULL, " \t\r\n")) );
241  if ( fVerbose )
242  printf( "Setting driving cell to be \"%s\".\n", Abc_FrameReadDrivingCell() );
243  }
244  else if ( !strcmp(pToken, "set_load") )
245  {
246  Abc_FrameSetMaxLoad( atof(strtok(NULL, " \t\r\n")) );
247  if ( fVerbose )
248  printf( "Setting driving cell to be %f.\n", Abc_FrameReadMaxLoad() );
249  }
250  else
251  printf( "Unrecognized token \"%s\".\n", pToken );
252  }
253  fclose( pFile );
254 }
255 
256 /**Function*************************************************************
257 
258  Synopsis []
259 
260  Description []
261 
262  SideEffects []
263 
264  SeeAlso []
265 
266 ***********************************************************************/
268 {
269  Vec_Int_t * vBufs;
270  Mio_Gate_t * pBuffer;
271  Abc_Obj_t * pObj; int i;
272  pBuffer = Mio_LibraryReadBuf( (Mio_Library_t *)pNtk->pManFunc );
273  if ( pBuffer == NULL )
274  {
275  printf( "Cannot find buffer in the current library. Quitting.\n" );
276  return NULL;
277  }
278  vBufs = Vec_IntAlloc( 100 );
279  Abc_NtkForEachBarBuf( pNtk, pObj, i )
280  {
281  assert( pObj->pData == NULL );
282  pObj->pData = pBuffer;
283  Vec_IntPush( vBufs, i );
284  }
285  return vBufs;
286 }
287 void Abc_SclInsertBarBufs( Abc_Ntk_t * pNtk, Vec_Int_t * vBufs )
288 {
289  Abc_Obj_t * pObj; int i;
290  Abc_NtkForEachObjVec( vBufs, pNtk, pObj, i )
291  pObj->pData = NULL;
292 }
293 
294 ////////////////////////////////////////////////////////////////////////
295 /// END OF FILE ///
296 ////////////////////////////////////////////////////////////////////////
297 
298 
300 
Mio_Gate_t * Mio_LibraryReadBuf(Mio_Library_t *pLib)
Definition: mioApi.c:47
#define Abc_NtkForEachNode1(pNtk, pNode, i)
Definition: abc.h:467
ABC_DLL float Abc_FrameReadMaxLoad()
Definition: mainFrame.c:98
static unsigned Abc_ObjId(Abc_Obj_t *pObj)
Definition: abc.h:329
Mio_Gate_t * Mio_LibraryReadGateByName(Mio_Library_t *pLib, char *pName, char *pOutName)
Definition: mioApi.c:99
void Abc_SclSclGates2MioGates(SC_Lib *pLib, Abc_Ntk_t *p)
Definition: sclUtil.c:73
ABC_DLL char * Abc_FrameReadDrivingCell()
Definition: mainFrame.c:97
void * pSCLib
Definition: abc.h:206
unsigned fMarkA
Definition: abc.h:134
#define ABC_SCL_MAX_SIZE
Definition: sclUtil.c:108
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
void Abc_SclInsertBarBufs(Abc_Ntk_t *pNtk, Vec_Int_t *vBufs)
Definition: sclUtil.c:287
void Abc_SclReadTimingConstr(Abc_Frame_t *pAbc, char *pFileName, int fVerbose)
Definition: sclUtil.c:229
int Order
Definition: sclLib.h:198
Vec_Int_t * Abc_SclFindMinAreas(SC_Lib *pLib, int fUseMax)
Definition: sclUtil.c:170
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static int Abc_ObjIsBarBuf(Abc_Obj_t *pObj)
Definition: abc.h:360
char * strtok()
Vec_Int_t * vGates
Definition: abc.h:207
#define SC_LibForEachCellClass(p, pCell, i)
Definition: sclLib.h:249
#define SC_RingForEachCell(pRing, pCell, i)
Definition: sclLib.h:256
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static Vec_Int_t * Vec_IntStartFull(int nSize)
Definition: vecInt.h:119
int strcmp()
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
void * pManFunc
Definition: abc.h:191
ABC_DLL void Abc_FrameSetMaxLoad(float Load)
Definition: mainFrame.c:100
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
float area
Definition: sclLib.h:188
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
#define Abc_NtkForEachObjVec(vIds, pNtk, pObj, i)
Definition: abc.h:452
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Vec_Int_t * Abc_SclExtractBarBufs(Abc_Ntk_t *pNtk)
Definition: sclUtil.c:267
ABC_NAMESPACE_IMPL_START void Abc_SclMioGates2SclGates(SC_Lib *pLib, Abc_Ntk_t *p)
DECLARATIONS ///.
Definition: sclUtil.c:47
int Id
Definition: sclLib.h:184
STRUCTURE DEFINITIONS ///.
Definition: mioInt.h:61
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
char * pName
Definition: sclLib.h:183
#define Abc_NtkForEachBarBuf(pNtk, pNode, i)
Definition: abc.h:479
static int Counter
static void Vec_IntFreeP(Vec_Int_t **p)
Definition: vecInt.h:289
static SC_Cell * SC_LibCell(SC_Lib *p, int i)
Definition: sclLib.h:240
void Abc_SclManPrintGateSizes(SC_Lib *pLib, Abc_Ntk_t *p, Vec_Int_t *vGates)
Definition: sclUtil.c:109
void Abc_SclPrintGateSizes(SC_Lib *pLib, Abc_Ntk_t *p)
Definition: sclUtil.c:137
double atof()
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int Abc_SclCountMinSize(SC_Lib *pLib, Abc_Ntk_t *p, int fUseMax)
Definition: sclUtil.c:203
unsigned fMarkB
Definition: abc.h:135
SC_Cell * Abc_SclFindMaxAreaCell(SC_Cell *pRepr)
Definition: sclUtil.c:157
int Abc_SclCellFind(SC_Lib *p, char *pName)
Definition: sclLibUtil.c:79
void Abc_SclMinsizePerform(SC_Lib *pLib, Abc_Ntk_t *p, int fUseMax, int fVerbose)
Definition: sclUtil.c:185
int n_inputs
Definition: sclLib.h:192
#define assert(ex)
Definition: util_old.h:213
void * pData
Definition: abc.h:145
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
ABC_DLL void Abc_FrameSetDrivingCell(char *pName)
Definition: mainFrame.c:99
Vec_Ptr_t * vCells
Definition: sclLib.h:215
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
char * Mio_GateReadName(Mio_Gate_t *pGate)
Definition: mioApi.c:143
static SC_Cell * Abc_SclObjCell(Abc_Obj_t *p)
Definition: sclSize.h:110