ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
sclUtil.c
Go to the documentation of this file.
1
20
21#include "sclSize.h"
22#include "map/mio/mio.h"
23#include "base/main/main.h"
24
26
27
31
35
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) );
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}
71{
72 Abc_Obj_t * pObj;
73 SC_Cell * pCell;
74 int i, Counter = 0, CounterAll = 0;
75 assert( p->vGates != NULL );
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
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
127#define ABC_SCL_MAX_SIZE 64
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};
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}
157{
159 Abc_SclManPrintGateSizes( pLib, p, p->vGates );
161 Vec_IntFreeP( &p->vGates );
162 p->pSCLib = NULL;
163}
164
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}
189Vec_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}
204void 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 );
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 }
220 Vec_IntFree( vMinCells );
221}
222int 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 );
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
248void 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
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}
308{
309 Abc_Obj_t * pObj; int i;
310 Abc_NtkForEachObjVec( vBufs, pNtk, pObj, i )
311 pObj->pData = NULL;
312}
313
317
318
320
#define Abc_NtkForEachBarBuf(pNtk, pNode, i)
Definition abc.h:482
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachNodeNotBarBuf(pNtk, pNode, i)
Definition abc.h:467
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
#define Abc_NtkForEachNodeNotBarBuf1(pNtk, pNode, i)
Definition abc.h:473
#define Abc_NtkForEachObjVec(vIds, pNtk, pObj, i)
Definition abc.h:455
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
Definition abcapis.h:38
ABC_DLL float Abc_FrameReadMaxLoad()
Definition mainFrame.c:117
ABC_DLL char * Abc_FrameReadDrivingCell()
Definition mainFrame.c:116
ABC_DLL void Abc_FrameSetDrivingCell(char *pName)
Definition mainFrame.c:118
ABC_DLL void Abc_FrameSetMaxLoad(float Load)
Definition mainFrame.c:119
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
struct Mio_LibraryStruct_t_ Mio_Library_t
Definition mio.h:42
Mio_Gate_t * Mio_LibraryReadGateByName(Mio_Library_t *pLib, char *pName, char *pOutName)
Definition mioApi.c:105
char * Mio_GateReadName(Mio_Gate_t *pGate)
Definition mioApi.c:169
struct Mio_GateStruct_t_ Mio_Gate_t
Definition mio.h:43
Mio_Gate_t * Mio_LibraryReadBuf(Mio_Library_t *pLib)
Definition mioApi.c:49
struct SC_Lib_ SC_Lib
Definition sclLib.h:128
#define SC_RingForEachCell(pRing, pCell, i)
Definition sclLib.h:277
struct SC_Cell_ SC_Cell
Definition sclLib.h:127
#define SC_LibForEachCellClass(p, pCell, i)
Definition sclLib.h:270
int Abc_SclCellFind(SC_Lib *p, char *pName)
Definition sclLibUtil.c:81
#define ABC_SCL_MAX_SIZE
Definition sclUtil.c:127
SC_Cell * Abc_SclFindMaxAreaCell(SC_Cell *pRepr)
Definition sclUtil.c:176
Vec_Int_t * Abc_SclExtractBarBufs(Abc_Ntk_t *pNtk)
Definition sclUtil.c:287
void Abc_SclManPrintGateSizes(SC_Lib *pLib, Abc_Ntk_t *p, Vec_Int_t *vGates)
Definition sclUtil.c:128
void Abc_SclReadTimingConstr(Abc_Frame_t *pAbc, char *pFileName, int fVerbose)
Definition sclUtil.c:248
void Abc_SclSclGates2MioGates(SC_Lib *pLib, Abc_Ntk_t *p)
Definition sclUtil.c:70
int Abc_SclCountMinSize(SC_Lib *pLib, Abc_Ntk_t *p, int fUseMax)
Definition sclUtil.c:222
ABC_NAMESPACE_IMPL_START void Abc_SclMioGates2SclGates(SC_Lib *pLib, Abc_Ntk_t *p)
DECLARATIONS ///.
Definition sclUtil.c:47
void Abc_SclInsertBarBufs(Abc_Ntk_t *pNtk, Vec_Int_t *vBufs)
Definition sclUtil.c:307
void Abc_SclPrintGateSizes(SC_Lib *pLib, Abc_Ntk_t *p)
Definition sclUtil.c:156
Vec_Int_t * Abc_SclFindMinAreas(SC_Lib *pLib, int fUseMax)
Definition sclUtil.c:189
void Abc_SclTransferGates(Abc_Ntk_t *pOld, Abc_Ntk_t *pNew)
Definition sclUtil.c:102
void Abc_SclMinsizePerform(SC_Lib *pLib, Abc_Ntk_t *p, int fUseMax, int fVerbose)
Definition sclUtil.c:204
void * pManFunc
Definition abc.h:191
int nBarBufs2
Definition abc.h:175
void * pData
Definition abc.h:145
unsigned fMarkB
Definition abc.h:135
Abc_Obj_t * pCopy
Definition abc.h:148
unsigned fMarkA
Definition abc.h:134
float area
Definition sclLib.h:207
char * pName
Definition sclLib.h:202
int n_inputs
Definition sclLib.h:213
int Id
Definition sclLib.h:203
int Order
Definition sclLib.h:219
Vec_Ptr_t vCells
Definition sclLib.h:236
#define assert(ex)
Definition util_old.h:213
int strcmp()
char * strtok()
double atof()