ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaIff.c
Go to the documentation of this file.
1
20
21#include "gia.h"
22#include "map/if/if.h"
23
25
29
30typedef struct Iff_Man_t_ Iff_Man_t;
32{
33 Gia_Man_t * pGia; // mapped GIA
34 If_LibLut_t * pLib; // LUT library
35 int nLutSize; // LUT size
36 int nDegree; // degree
37 Vec_Flt_t * vTimes; // arrival times
38 Vec_Int_t * vMatch[4]; // matches
39};
40
41static inline float Iff_ObjTimeId( Iff_Man_t * p, int iObj ) { return Vec_FltEntry( p->vTimes, iObj ); }
42static inline float Iff_ObjTime( Iff_Man_t * p, Gia_Obj_t * pObj ) { return Iff_ObjTimeId( p, Gia_ObjId(p->pGia, pObj) ); }
43static inline void Iff_ObjSetTimeId( Iff_Man_t * p, int iObj, float Time ) { Vec_FltWriteEntry( p->vTimes, iObj, Time ); }
44static inline void Iff_ObjSetTime( Iff_Man_t * p, Gia_Obj_t * pObj, float Time ) { Iff_ObjSetTimeId( p, Gia_ObjId(p->pGia, pObj), Time ); }
45
46static inline int Iff_ObjMatchId( Iff_Man_t * p, int iObj, int Type ) { return Vec_IntEntry( p->vMatch[Type], iObj ); }
47static inline int Iff_ObjMatch( Iff_Man_t * p, Gia_Obj_t * pObj, int Type ) { return Iff_ObjMatchId( p, Gia_ObjId(p->pGia, pObj), Type ); }
48static inline void Iff_ObjSetMatchId( Iff_Man_t * p, int iObj, int Type, int Match ) { Vec_IntWriteEntry( p->vMatch[Type], iObj, Match ); }
49static inline void Iff_ObjSetMatch( Iff_Man_t * p, Gia_Obj_t * pObj, int Type, int Match ) { Iff_ObjSetMatchId( p, Gia_ObjId(p->pGia, pObj), Type, Match );}
50
54
67{
69 p->vTimes = Vec_FltStartFull( Gia_ManObjNum(pGia) );
70 p->vMatch[2] = Vec_IntStartFull( Gia_ManObjNum(pGia) );
71 p->vMatch[3] = Vec_IntStartFull( Gia_ManObjNum(pGia) );
72 return p;
73}
75{
76 Vec_FltFree( p->vTimes );
77 Vec_IntFree( p->vMatch[2] );
78 Vec_IntFree( p->vMatch[3] );
79 ABC_FREE( p );
80}
81
93int Gia_IffObjCount( Gia_Man_t * pGia, int iObj, int iFaninSkip2, int iFaninSkip3 )
94{
95 int i, iFanin, Count = 0;
97 Gia_LutForEachFanin( pGia, iObj, iFanin, i )
98 {
99 if ( iFanin == iFaninSkip2 || iFanin == iFaninSkip3 )
100 continue;
101 if ( Gia_ObjIsTravIdCurrentId( pGia, iFanin ) )
102 continue;
103 Gia_ObjSetTravIdCurrentId( pGia, iFanin );
104 Count++;
105 }
106 if ( iFaninSkip2 >= 0 )
107 {
108 Gia_LutForEachFanin( pGia, iFaninSkip2, iFanin, i )
109 {
110 if ( iFanin == iFaninSkip3 )
111 continue;
112 if ( Gia_ObjIsTravIdCurrentId( pGia, iFanin ) )
113 continue;
114 Gia_ObjSetTravIdCurrentId( pGia, iFanin );
115 Count++;
116 }
117 }
118 if ( iFaninSkip3 >= 0 )
119 {
120 Gia_LutForEachFanin( pGia, iFaninSkip3, iFanin, i )
121 {
122 if ( iFanin == iFaninSkip2 )
123 continue;
124 if ( Gia_ObjIsTravIdCurrentId( pGia, iFanin ) )
125 continue;
126 Gia_ObjSetTravIdCurrentId( pGia, iFanin );
127 Count++;
128 }
129 }
130 return Count;
131}
132
144float Gia_IffObjTimeOne( Iff_Man_t * p, int iObj, int iFaninSkip2, int iFaninSkip3 )
145{
146 int i, iFanin;
147 float DelayMax = -ABC_INFINITY;
148 Gia_LutForEachFanin( p->pGia, iObj, iFanin, i )
149 if ( iFanin != iFaninSkip2 && iFanin != iFaninSkip3 && DelayMax < Iff_ObjTimeId(p, iFanin) )
150 DelayMax = Iff_ObjTimeId(p, iFanin);
151 assert( i == Gia_ObjLutSize(p->pGia, iObj) );
152 if ( iFaninSkip2 == -1 )
153 return DelayMax;
154 Gia_LutForEachFanin( p->pGia, iFaninSkip2, iFanin, i )
155 if ( iFanin != iFaninSkip3 && DelayMax < Iff_ObjTimeId(p, iFanin) )
156 DelayMax = Iff_ObjTimeId(p, iFanin);
157 if ( iFaninSkip3 == -1 )
158 return DelayMax;
159 Gia_LutForEachFanin( p->pGia, iFaninSkip3, iFanin, i )
160 if ( iFanin != iFaninSkip2 && DelayMax < Iff_ObjTimeId(p, iFanin) )
161 DelayMax = Iff_ObjTimeId(p, iFanin);
162 assert( DelayMax >= 0 );
163 return DelayMax;
164}
165float Gia_IffObjTimeTwo( Iff_Man_t * p, int iObj, int * piFanin, float DelayMin )
166{
167 int i, iFanin, nSize;
168 float This;
169 *piFanin = -1;
170 Gia_LutForEachFanin( p->pGia, iObj, iFanin, i )
171 {
172 if ( Gia_ObjIsCi(Gia_ManObj(p->pGia, iFanin)) )
173 continue;
174 This = Gia_IffObjTimeOne( p, iObj, iFanin, -1 );
175 nSize = Gia_IffObjCount( p->pGia, iObj, iFanin, -1 );
176 assert( nSize <= p->pLib->LutMax );
177 This += p->pLib->pLutDelays[nSize][0];
178 if ( DelayMin > This )
179 {
180 DelayMin = This;
181 *piFanin = iFanin;
182 }
183 }
184 return DelayMin;
185}
186float Gia_IffObjTimeThree( Iff_Man_t * p, int iObj, int * piFanin, int * piFanin2, float DelayMin )
187{
188 int i, k, iFanin, iFanin2, nSize;
189 float This;
190 *piFanin = -1;
191 *piFanin2 = -1;
192 Gia_LutForEachFanin( p->pGia, iObj, iFanin, i )
193 Gia_LutForEachFanin( p->pGia, iObj, iFanin2, k )
194 {
195 if ( iFanin == iFanin2 )
196 continue;
197 if ( Gia_ObjIsCi(Gia_ManObj(p->pGia, iFanin)) )
198 continue;
199 if ( Gia_ObjIsCi(Gia_ManObj(p->pGia, iFanin2)) )
200 continue;
201 This = Gia_IffObjTimeOne( p, iObj, iFanin, iFanin2 );
202 nSize = Gia_IffObjCount( p->pGia, iObj, iFanin, iFanin2 );
203 assert( nSize <= p->pLib->LutMax );
204 This += p->pLib->pLutDelays[nSize][0];
205 if ( DelayMin > This )
206 {
207 DelayMin = This;
208 *piFanin = iFanin;
209 *piFanin2 = iFanin2;
210 }
211 }
212 return DelayMin;
213}
214
226Iff_Man_t * Gia_ManIffPerform( Gia_Man_t * pGia, If_LibLut_t * pLib, Tim_Man_t * pTime, int nLutSize, int nDegree )
227{
228 Iff_Man_t * p;
229 Gia_Obj_t * pObj;
230 int iObj, iFanin, iFanin1, iFanin2;
231 int CountAll = 0, Count2 = 0, Count3 = 0;
232 float arrTime1, arrTime2, arrTime3, arrMax = -ABC_INFINITY;
233 assert( nDegree == 2 || nDegree == 3 );
234 // start the mapping manager and set its parameters
235 p = Gia_ManIffStart( pGia );
236 p->pGia = pGia;
237 p->pLib = pLib;
238 p->nLutSize = nLutSize;
239 p->nDegree = nDegree;
240 // compute arrival times of each node
241 Iff_ObjSetTimeId( p, 0, 0 );
242 Tim_ManIncrementTravId( pTime );
243 Gia_ManForEachObj1( pGia, pObj, iObj )
244 {
245 if ( Gia_ObjIsAnd(pObj) )
246 {
247 if ( !Gia_ObjIsLut(pGia, iObj) )
248 continue;
249 CountAll++;
250 // compute arrival times of LUT inputs
251 arrTime1 = Gia_IffObjTimeOne( p, iObj, -1, -1 );
252 arrTime1 += p->pLib->pLutDelays[Gia_ObjLutSize(pGia, iObj)][0];
253 // compute arrival times of LUT pairs
254 arrTime2 = Gia_IffObjTimeTwo( p, iObj, &iFanin, arrTime1 );
255 if ( nDegree == 2 )
256 {
257 // set arrival times
258 Iff_ObjSetTimeId( p, iObj, arrTime2 );
259 if ( arrTime2 < arrTime1 )
260 Iff_ObjSetMatchId( p, iObj, 2, iFanin ), Count2++;
261 }
262 else if ( nDegree == 3 )
263 {
264 // compute arrival times of LUT triples
265 arrTime3 = Gia_IffObjTimeThree( p, iObj, &iFanin1, &iFanin2, arrTime2 );
266 // set arrival times
267 Iff_ObjSetTimeId( p, iObj, arrTime3 );
268 if ( arrTime3 == arrTime1 )
269 continue;
270 if ( arrTime3 == arrTime2 )
271 Iff_ObjSetMatchId( p, iObj, 2, iFanin ), Count2++;
272 else
273 {
274 assert( arrTime3 < arrTime2 );
275 Iff_ObjSetMatchId( p, iObj, 2, iFanin1 );
276 Iff_ObjSetMatchId( p, iObj, 3, iFanin2 ), Count3++;
277 }
278 }
279 else assert( 0 );
280 }
281 else if ( Gia_ObjIsCi(pObj) )
282 {
283 arrTime1 = Tim_ManGetCiArrival( pTime, Gia_ObjCioId(pObj) );
284 Iff_ObjSetTime( p, pObj, arrTime1 );
285 }
286 else if ( Gia_ObjIsCo(pObj) )
287 {
288 arrTime1 = Iff_ObjTimeId( p, Gia_ObjFaninId0p(pGia, pObj) );
289 Tim_ManSetCoArrival( pTime, Gia_ObjCioId(pObj), arrTime1 );
290 Iff_ObjSetTime( p, pObj, arrTime1 );
291 arrMax = Abc_MaxFloat( arrMax, arrTime1 );
292 }
293 else assert( 0 );
294 }
295 printf( "Max delay = %.2f. Count1 = %d. Count2 = %d. Count3 = %d.\n",
296 arrMax, CountAll - Count2 - Count3, Count2, Count3 );
297 return p;
298}
299
311void Gia_ManIffSelect_rec( Iff_Man_t * p, int iObj, Vec_Int_t * vPacking )
312{
313 int i, iFanin, iFaninSkip2, iFaninSkip3;
314 if ( Gia_ObjIsTravIdCurrentId( p->pGia, iObj ) )
315 return;
316 Gia_ObjSetTravIdCurrentId( p->pGia, iObj );
317 assert( Gia_ObjIsLut(p->pGia, iObj) );
318 iFaninSkip2 = Iff_ObjMatchId(p, iObj, 2);
319 iFaninSkip3 = Iff_ObjMatchId(p, iObj, 3);
320 if ( iFaninSkip2 == -1 )
321 {
322 assert( iFaninSkip3 == -1 );
323 Gia_LutForEachFanin( p->pGia, iObj, iFanin, i )
324 Gia_ManIffSelect_rec( p, iFanin, vPacking );
325 Vec_IntPush( vPacking, 1 );
326 Vec_IntPush( vPacking, iObj );
327 }
328 else if ( iFaninSkip3 == -1 )
329 {
330 assert( iFaninSkip2 > 0 );
331 Gia_LutForEachFanin( p->pGia, iObj, iFanin, i )
332 if ( iFanin != iFaninSkip2 )
333 Gia_ManIffSelect_rec( p, iFanin, vPacking );
334 Gia_LutForEachFanin( p->pGia, iFaninSkip2, iFanin, i )
335 Gia_ManIffSelect_rec( p, iFanin, vPacking );
336 Vec_IntPush( vPacking, 2 );
337 Vec_IntPush( vPacking, iFaninSkip2 );
338 Vec_IntPush( vPacking, iObj );
339 }
340 else
341 {
342 assert( iFaninSkip2 > 0 && iFaninSkip3 > 0 );
343 Gia_LutForEachFanin( p->pGia, iObj, iFanin, i )
344 if ( iFanin != iFaninSkip2 && iFanin != iFaninSkip3 )
345 Gia_ManIffSelect_rec( p, iFanin, vPacking );
346 Gia_LutForEachFanin( p->pGia, iFaninSkip2, iFanin, i )
347 if ( iFanin != iFaninSkip3 )
348 Gia_ManIffSelect_rec( p, iFanin, vPacking );
349 Gia_LutForEachFanin( p->pGia, iFaninSkip3, iFanin, i )
350 if ( iFanin != iFaninSkip2 )
351 Gia_ManIffSelect_rec( p, iFanin, vPacking );
352 Vec_IntPush( vPacking, 3 );
353 Vec_IntPush( vPacking, iFaninSkip2 );
354 Vec_IntPush( vPacking, iFaninSkip3 );
355 Vec_IntPush( vPacking, iObj );
356 }
357 Vec_IntAddToEntry( vPacking, 0, 1 );
358}
360{
361 Vec_Int_t * vPacking;
362 Gia_Obj_t * pObj; int i;
363 vPacking = Vec_IntAlloc( Gia_ManObjNum(p->pGia) );
364 Vec_IntPush( vPacking, 0 );
365 // mark const0 and PIs
366 Gia_ManIncrementTravId( p->pGia );
367 Gia_ObjSetTravIdCurrentId( p->pGia, 0 );
368 Gia_ManForEachCi( p->pGia, pObj, i )
369 Gia_ObjSetTravIdCurrent( p->pGia, pObj );
370 // recursively collect internal nodes
371 Gia_ManForEachCo( p->pGia, pObj, i )
372 Gia_ManIffSelect_rec( p, Gia_ObjFaninId0p(p->pGia, pObj), vPacking );
373 return vPacking;
374}
375
387void Gia_ManIffTest( Gia_Man_t * pGia, If_LibLut_t * pLib, int fVerbose )
388{
389 Iff_Man_t * p;
390 Tim_Man_t * pTemp = NULL;
391 int nDegree = -1;
392 int nLutSize = Gia_ManLutSizeMax( pGia );
393 if ( nLutSize <= 4 )
394 {
395 nLutSize = 4;
396 if ( pLib->LutMax == 7 )
397 nDegree = 2;
398 else if ( pLib->LutMax == 10 )
399 nDegree = 3;
400 else
401 { printf( "LUT library for packing 4-LUTs should have 7 or 10 inputs.\n" ); return; }
402 }
403 else if ( nLutSize <= 6 )
404 {
405 nLutSize = 6;
406 if ( pLib->LutMax == 11 )
407 nDegree = 2;
408 else if ( pLib->LutMax == 16 )
409 nDegree = 3;
410 else
411 { printf( "LUT library for packing 6-LUTs should have 11 or 16 inputs.\n" ); return; }
412 }
413 else
414 {
415 printf( "The LUT size is more than 6.\n" );
416 return;
417 }
418 if ( fVerbose )
419 printf( "Performing %d-clustering with %d-LUTs:\n", nDegree, nLutSize );
420 // create timing manager
421 if ( pGia->pManTime == NULL )
422 pGia->pManTime = pTemp = Tim_ManStart( Gia_ManCiNum(pGia), Gia_ManCoNum(pGia) );
423 // perform timing computation
424 p = Gia_ManIffPerform( pGia, pLib, (Tim_Man_t *)pGia->pManTime, nLutSize, nDegree );
425 // remove timing manager
426 if ( pGia->pManTime == pTemp )
427 pGia->pManTime = NULL;
428 Tim_ManStopP( (Tim_Man_t **)&pTemp );
429 // derive clustering
430 Vec_IntFreeP( &pGia->vPacking );
431 pGia->vPacking = Gia_ManIffSelect( p );
432 Gia_ManIffStop( p );
433 // print statistics
434 if ( fVerbose )
436}
437
441
442
444
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#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
Cube * p
Definition exorList.c:222
int Gia_IffObjCount(Gia_Man_t *pGia, int iObj, int iFaninSkip2, int iFaninSkip3)
Definition giaIff.c:93
Iff_Man_t * Gia_ManIffStart(Gia_Man_t *pGia)
FUNCTION DEFINITIONS ///.
Definition giaIff.c:66
void Gia_ManIffSelect_rec(Iff_Man_t *p, int iObj, Vec_Int_t *vPacking)
Definition giaIff.c:311
void Gia_ManIffStop(Iff_Man_t *p)
Definition giaIff.c:74
Iff_Man_t * Gia_ManIffPerform(Gia_Man_t *pGia, If_LibLut_t *pLib, Tim_Man_t *pTime, int nLutSize, int nDegree)
Definition giaIff.c:226
Vec_Int_t * Gia_ManIffSelect(Iff_Man_t *p)
Definition giaIff.c:359
float Gia_IffObjTimeTwo(Iff_Man_t *p, int iObj, int *piFanin, float DelayMin)
Definition giaIff.c:165
float Gia_IffObjTimeThree(Iff_Man_t *p, int iObj, int *piFanin, int *piFanin2, float DelayMin)
Definition giaIff.c:186
typedefABC_NAMESPACE_IMPL_START struct Iff_Man_t_ Iff_Man_t
DECLARATIONS ///.
Definition giaIff.c:30
float Gia_IffObjTimeOne(Iff_Man_t *p, int iObj, int iFaninSkip2, int iFaninSkip3)
Definition giaIff.c:144
void Gia_ManIffTest(Gia_Man_t *pGia, If_LibLut_t *pLib, int fVerbose)
Definition giaIff.c:387
void Gia_ManPrintPackingStats(Gia_Man_t *p)
Definition giaIf.c:663
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
#define Gia_LutForEachFanin(p, i, iFan, k)
Definition gia.h:1161
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
#define Gia_ManForEachObj1(p, pObj, i)
Definition gia.h:1192
int Gia_ManLutSizeMax(Gia_Man_t *p)
Definition giaIf.c:127
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition giaUtil.c:190
#define Gia_ManForEachCo(p, pObj, i)
Definition gia.h:1236
#define Gia_ManForEachCi(p, pObj, i)
Definition gia.h:1228
struct If_LibLut_t_ If_LibLut_t
Definition if.h:82
Vec_Int_t * vPacking
Definition gia.h:141
void * pManTime
Definition gia.h:194
int LutMax
Definition if.h:190
Vec_Int_t * vMatch[4]
Definition giaIff.c:38
Gia_Man_t * pGia
Definition giaIff.c:33
Vec_Flt_t * vTimes
Definition giaIff.c:37
int nLutSize
Definition giaIff.c:35
int nDegree
Definition giaIff.c:36
If_LibLut_t * pLib
Definition giaIff.c:34
void Tim_ManStopP(Tim_Man_t **p)
Definition timMan.c:387
void Tim_ManSetCoArrival(Tim_Man_t *p, int iCo, float Delay)
Definition timTime.c:116
typedefABC_NAMESPACE_HEADER_START struct Tim_Man_t_ Tim_Man_t
INCLUDES ///.
Definition tim.h:92
void Tim_ManIncrementTravId(Tim_Man_t *p)
DECLARATIONS ///.
Definition timTrav.c:44
Tim_Man_t * Tim_ManStart(int nCis, int nCos)
DECLARATIONS ///.
Definition timMan.c:45
float Tim_ManGetCiArrival(Tim_Man_t *p, int iCi)
Definition timTime.c:174
#define assert(ex)
Definition util_old.h:213
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
Definition vecFlt.h:42