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
25 ABC_NAMESPACE_IMPL_START
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 ***********************************************************************/
Abc_SclMioGates2SclGates(SC_Lib * pLib,Abc_Ntk_t * p)47 void Abc_SclMioGates2SclGates( SC_Lib * pLib, Abc_Ntk_t * p )
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 }
57 bufferId = Abc_SclCellFind( pLib, Mio_GateReadName(Mio_LibraryReadBuf((Mio_Library_t *)p->pManFunc)) );
58 assert( bufferId >= 0 );
59 // remap cells
60 assert( p->vGates == NULL );
61 p->vGates = Vec_IntStartFull( Abc_NtkObjNumMax(p) );
62 Abc_NtkForEachNodeNotBarBuf1( p, pObj, i )
63 {
64 gateId = Abc_SclCellFind( pLib, Mio_GateReadName((Mio_Gate_t *)pObj->pData) );
65 assert( gateId >= 0 );
66 Vec_IntWriteEntry( p->vGates, i, gateId );
67 }
68 p->pSCLib = pLib;
69 }
Abc_SclSclGates2MioGates(SC_Lib * pLib,Abc_Ntk_t * p)70 void Abc_SclSclGates2MioGates( SC_Lib * pLib, Abc_Ntk_t * p )
71 {
72 Abc_Obj_t * pObj;
73 SC_Cell * pCell;
74 int i, Counter = 0, CounterAll = 0;
75 assert( p->vGates != NULL );
76 Abc_NtkForEachNodeNotBarBuf1( p, pObj, i )
77 {
78 pCell = Abc_SclObjCell(pObj);
79 assert( pCell->n_inputs == Abc_ObjFaninNum(pObj) );
80 pObj->pData = Mio_LibraryReadGateByName( (Mio_Library_t *)p->pManFunc, pCell->pName, NULL );
81 Counter += (pObj->pData == NULL);
82 assert( pObj->fMarkA == 0 && pObj->fMarkB == 0 );
83 CounterAll++;
84 }
85 if ( Counter )
86 printf( "Could not find %d (out of %d) gates in the current library.\n", Counter, CounterAll );
87 Vec_IntFreeP( &p->vGates );
88 p->pSCLib = NULL;
89 }
90
91 /**Function*************************************************************
92
93 Synopsis [Transfer gate sizes from AIG without barbufs.]
94
95 Description []
96
97 SideEffects []
98
99 SeeAlso []
100
101 ***********************************************************************/
Abc_SclTransferGates(Abc_Ntk_t * pOld,Abc_Ntk_t * pNew)102 void Abc_SclTransferGates( Abc_Ntk_t * pOld, Abc_Ntk_t * pNew )
103 {
104 Abc_Obj_t * pObj; int i;
105 assert( pOld->nBarBufs2 > 0 );
106 assert( pNew->nBarBufs2 == 0 );
107 Abc_NtkForEachNodeNotBarBuf( pOld, pObj, i )
108 {
109 if ( pObj->pCopy == NULL )
110 continue;
111 assert( Abc_ObjNtk(pObj->pCopy) == pNew );
112 pObj->pData = pObj->pCopy->pData;
113 }
114 }
115
116 /**Function*************************************************************
117
118 Synopsis [Reports percentage of gates of each size.]
119
120 Description []
121
122 SideEffects []
123
124 SeeAlso []
125
126 ***********************************************************************/
127 #define ABC_SCL_MAX_SIZE 64
Abc_SclManPrintGateSizes(SC_Lib * pLib,Abc_Ntk_t * p,Vec_Int_t * vGates)128 void Abc_SclManPrintGateSizes( SC_Lib * pLib, Abc_Ntk_t * p, Vec_Int_t * vGates )
129 {
130 Abc_Obj_t * pObj;
131 SC_Cell * pCell;
132 int i, nGates = 0, Counters[ABC_SCL_MAX_SIZE] = {0};
133 double TotArea = 0, Areas[ABC_SCL_MAX_SIZE] = {0};
134 Abc_NtkForEachNodeNotBarBuf1( p, pObj, i )
135 {
136 pCell = SC_LibCell( pLib, Vec_IntEntry(vGates, Abc_ObjId(pObj)) );
137 assert( pCell->Order < ABC_SCL_MAX_SIZE );
138 Counters[pCell->Order]++;
139 Areas[pCell->Order] += pCell->area;
140 TotArea += pCell->area;
141 nGates++;
142 }
143 printf( "Total gates = %d. Total area = %.1f\n", nGates, TotArea );
144 for ( i = 0; i < ABC_SCL_MAX_SIZE; i++ )
145 {
146 if ( Counters[i] == 0 )
147 continue;
148 printf( "Cell size = %d. ", i );
149 printf( "Count = %6d ", Counters[i] );
150 printf( "(%5.1f %%) ", 100.0 * Counters[i] / nGates );
151 printf( "Area = %12.1f ", Areas[i] );
152 printf( "(%5.1f %%) ", 100.0 * Areas[i] / TotArea );
153 printf( "\n" );
154 }
155 }
Abc_SclPrintGateSizes(SC_Lib * pLib,Abc_Ntk_t * p)156 void Abc_SclPrintGateSizes( SC_Lib * pLib, Abc_Ntk_t * p )
157 {
158 Abc_SclMioGates2SclGates( pLib, p );
159 Abc_SclManPrintGateSizes( pLib, p, p->vGates );
160 Abc_SclSclGates2MioGates( pLib, p );
161 Vec_IntFreeP( &p->vGates );
162 p->pSCLib = NULL;
163 }
164
165 /**Function*************************************************************
166
167 Synopsis [Downsizes each gate to its minimium size.]
168
169 Description []
170
171 SideEffects []
172
173 SeeAlso []
174
175 ***********************************************************************/
Abc_SclFindMaxAreaCell(SC_Cell * pRepr)176 SC_Cell * Abc_SclFindMaxAreaCell( SC_Cell * pRepr )
177 {
178 SC_Cell * pCell, * pBest = pRepr;
179 float AreaBest = pRepr->area;
180 int i;
181 SC_RingForEachCell( pRepr, pCell, i )
182 if ( AreaBest < pCell->area )
183 {
184 AreaBest = pCell->area;
185 pBest = pCell;
186 }
187 return pBest;
188 }
Abc_SclFindMinAreas(SC_Lib * pLib,int fUseMax)189 Vec_Int_t * Abc_SclFindMinAreas( SC_Lib * pLib, int fUseMax )
190 {
191 Vec_Int_t * vMinCells;
192 SC_Cell * pCell, * pRepr = NULL, * pBest = NULL;
193 int i, k;
194 // map each gate in the library into its min/max-size prototype
195 vMinCells = Vec_IntStartFull( Vec_PtrSize(&pLib->vCells) );
196 SC_LibForEachCellClass( pLib, pRepr, i )
197 {
198 pBest = fUseMax ? Abc_SclFindMaxAreaCell(pRepr) : pRepr;
199 SC_RingForEachCell( pRepr, pCell, k )
200 Vec_IntWriteEntry( vMinCells, pCell->Id, pBest->Id );
201 }
202 return vMinCells;
203 }
Abc_SclMinsizePerform(SC_Lib * pLib,Abc_Ntk_t * p,int fUseMax,int fVerbose)204 void Abc_SclMinsizePerform( SC_Lib * pLib, Abc_Ntk_t * p, int fUseMax, int fVerbose )
205 {
206 Vec_Int_t * vMinCells;
207 Abc_Obj_t * pObj;
208 int i, gateId;
209 vMinCells = Abc_SclFindMinAreas( pLib, fUseMax );
210 Abc_SclMioGates2SclGates( pLib, p );
211 Abc_NtkForEachNodeNotBarBuf1( p, pObj, i )
212 {
213 gateId = Vec_IntEntry( p->vGates, i );
214 assert( gateId >= 0 && gateId < Vec_PtrSize(&pLib->vCells) );
215 gateId = Vec_IntEntry( vMinCells, gateId );
216 assert( gateId >= 0 && gateId < Vec_PtrSize(&pLib->vCells) );
217 Vec_IntWriteEntry( p->vGates, i, gateId );
218 }
219 Abc_SclSclGates2MioGates( pLib, p );
220 Vec_IntFree( vMinCells );
221 }
Abc_SclCountMinSize(SC_Lib * pLib,Abc_Ntk_t * p,int fUseMax)222 int Abc_SclCountMinSize( SC_Lib * pLib, Abc_Ntk_t * p, int fUseMax )
223 {
224 Vec_Int_t * vMinCells;
225 Abc_Obj_t * pObj;
226 int i, gateId, Counter = 0;
227 vMinCells = Abc_SclFindMinAreas( pLib, fUseMax );
228 Abc_NtkForEachNodeNotBarBuf1( p, pObj, i )
229 {
230 gateId = Vec_IntEntry( p->vGates, i );
231 Counter += ( gateId == Vec_IntEntry(vMinCells, gateId) );
232 }
233 Vec_IntFree( vMinCells );
234 return Counter;
235 }
236
237 /**Function*************************************************************
238
239 Synopsis [Reads timing constraints.]
240
241 Description []
242
243 SideEffects []
244
245 SeeAlso []
246
247 ***********************************************************************/
Abc_SclReadTimingConstr(Abc_Frame_t * pAbc,char * pFileName,int fVerbose)248 void Abc_SclReadTimingConstr( Abc_Frame_t * pAbc, char * pFileName, int fVerbose )
249 {
250 char Buffer[1000], * pToken;
251 FILE * pFile = fopen( pFileName, "rb" );
252 while ( fgets( Buffer, 1000, pFile ) )
253 {
254 pToken = strtok( Buffer, " \t\r\n" );
255 if ( pToken == NULL )
256 continue;
257 if ( !strcmp(pToken, "set_driving_cell") )
258 // if ( !strcmp(pToken, "default_input_cell") )
259 {
260 Abc_FrameSetDrivingCell( Abc_UtilStrsav(strtok(NULL, " \t\r\n")) );
261 if ( fVerbose )
262 printf( "Setting driving cell to be \"%s\".\n", Abc_FrameReadDrivingCell() );
263 }
264 else if ( !strcmp(pToken, "set_load") )
265 // else if ( !strcmp(pToken, "default_output_load") )
266 {
267 Abc_FrameSetMaxLoad( atof(strtok(NULL, " \t\r\n")) );
268 if ( fVerbose )
269 printf( "Setting output load to be %f.\n", Abc_FrameReadMaxLoad() );
270 }
271 else printf( "Unrecognized token \"%s\".\n", pToken );
272 }
273 fclose( pFile );
274 }
275
276 /**Function*************************************************************
277
278 Synopsis []
279
280 Description []
281
282 SideEffects []
283
284 SeeAlso []
285
286 ***********************************************************************/
Abc_SclExtractBarBufs(Abc_Ntk_t * pNtk)287 Vec_Int_t * Abc_SclExtractBarBufs( Abc_Ntk_t * pNtk )
288 {
289 Vec_Int_t * vBufs;
290 Mio_Gate_t * pBuffer;
291 Abc_Obj_t * pObj; int i;
292 pBuffer = Mio_LibraryReadBuf( (Mio_Library_t *)pNtk->pManFunc );
293 if ( pBuffer == NULL )
294 {
295 printf( "Cannot find buffer in the current library. Quitting.\n" );
296 return NULL;
297 }
298 vBufs = Vec_IntAlloc( 100 );
299 Abc_NtkForEachBarBuf( pNtk, pObj, i )
300 {
301 assert( pObj->pData == NULL );
302 pObj->pData = pBuffer;
303 Vec_IntPush( vBufs, i );
304 }
305 return vBufs;
306 }
Abc_SclInsertBarBufs(Abc_Ntk_t * pNtk,Vec_Int_t * vBufs)307 void Abc_SclInsertBarBufs( Abc_Ntk_t * pNtk, Vec_Int_t * vBufs )
308 {
309 Abc_Obj_t * pObj; int i;
310 Abc_NtkForEachObjVec( vBufs, pNtk, pObj, i )
311 pObj->pData = NULL;
312 }
313
314 ////////////////////////////////////////////////////////////////////////
315 /// END OF FILE ///
316 ////////////////////////////////////////////////////////////////////////
317
318
319 ABC_NAMESPACE_IMPL_END
320
321