ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaNf.c
Go to the documentation of this file.
1
20
21#include <float.h>
22#include "gia.h"
23#include "misc/st/st.h"
24#include "map/mio/mio.h"
25#include "misc/util/utilTruth.h"
26#include "misc/extra/extra.h"
27#include "base/main/main.h"
28#include "misc/vec/vecMem.h"
29#include "misc/vec/vecWec.h"
30#include "opt/dau/dau.h"
31#include "misc/util/utilNam.h"
32#include "map/scl/sclCon.h"
33#include "misc/tim/tim.h"
34
35#ifdef _MSC_VER
36# include <intrin.h>
37# define __builtin_popcount __popcnt
38#endif
39
41
45
46#define NF_LEAF_MAX 6
47#define NF_CUT_MAX 32
48#define NF_NO_LEAF 31
49#define NF_NO_FUNC 0x3FFFFFF
50#define NF_EPSILON 0.001
51
52typedef struct Nf_Cut_t_ Nf_Cut_t;
54{
55 word Sign; // signature
56 int Delay; // delay
57 float Flow; // flow
58 unsigned iFunc : 26; // function (NF_NO_FUNC)
59 unsigned Useless : 1; // function
60 unsigned nLeaves : 5; // leaf number (NF_NO_LEAF)
61 int pLeaves[NF_LEAF_MAX+1]; // leaves
62};
63typedef struct Nf_Cfg_t_ Nf_Cfg_t;
65{
66 unsigned fCompl : 1; // complemented
67 unsigned Phase : 7; // match phase
68 unsigned Perm : 24; // match permutation
69};
70typedef struct Nf_Mat_t_ Nf_Mat_t;
72{
73 unsigned Gate : 20; // gate
74 unsigned CutH : 10; // cut handle
75 unsigned fCompl : 1; // complemented
76 unsigned fBest : 1; // best cut
77 Nf_Cfg_t Cfg; // input literals
78 int D; // delay
79 float F; // area
80};
81typedef struct Nf_Obj_t_ Nf_Obj_t;
83{
84 Nf_Mat_t M[2][2]; // del/area (2x)
85};
86typedef struct Nf_Man_t_ Nf_Man_t;
88{
89 // user data
90 Gia_Man_t * pGia; // derived manager
91 Tim_Man_t * pManTim; // timing manager
92 Jf_Par_t * pPars; // parameters
93 // matching
94 Vec_Mem_t * vTtMem; // truth tables
95 Vec_Wec_t * vTt2Match; // matches for truth tables
96 Mio_Cell2_t * pCells; // library gates
97 int nCells; // library gate count
98 // cut data
99 Nf_Obj_t * pNfObjs; // best cuts
100 Vec_Ptr_t vPages; // cut memory
101 Vec_Int_t vCutSets; // cut offsets
102 Vec_Int_t vMapRefs; // mapping refs (2x)
103 Vec_Flt_t vFlowRefs; // flow refs (2x)
104 Vec_Int_t vRequired; // required times (2x)
105 Vec_Flt_t vCutFlows; // temporary cut area
106 Vec_Int_t vCutDelays; // temporary cut delay
107 Vec_Int_t vBackup; // backup literals
108 int iCur; // current position
109 int Iter; // mapping iterations
110 int fUseEla; // use exact area
111 int nInvs; // the inverter count
112 int InvDelayI; // inverter delay
113 word InvAreaW; // inverter delay
114 float InvAreaF; // inverter area
115 // statistics
116 abctime clkStart; // starting time
117 double CutCount[6]; // cut counts
118 int nCutUseAll; // objects with useful cuts
119};
120
121static inline int Nf_Cfg2Int( Nf_Cfg_t Mat ) { union { int x; Nf_Cfg_t y; } v; v.y = Mat; return v.x; }
122static inline Nf_Cfg_t Nf_Int2Cfg( int Int ) { union { int x; Nf_Cfg_t y; } v; v.x = Int; return v.y; }
123
124static inline Nf_Obj_t * Nf_ManObj( Nf_Man_t * p, int i ) { return p->pNfObjs + i; }
125static inline Mio_Cell2_t* Nf_ManCell( Nf_Man_t * p, int i ) { return p->pCells + i; }
126static inline int * Nf_ManCutSet( Nf_Man_t * p, int i ) { return (int *)Vec_PtrEntry(&p->vPages, i >> 16) + (i & 0xFFFF); }
127static inline int Nf_ObjCutSetId( Nf_Man_t * p, int i ) { return Vec_IntEntry( &p->vCutSets, i ); }
128static inline int * Nf_ObjCutSet( Nf_Man_t * p, int i ) { return Nf_ManCutSet(p, Nf_ObjCutSetId(p, i)); }
129static inline int Nf_ObjHasCuts( Nf_Man_t * p, int i ) { return (int)(Vec_IntEntry(&p->vCutSets, i) > 0); }
130static inline int * Nf_ObjCutBest( Nf_Man_t * p, int i ) { return NULL; }
131static inline int Nf_ObjCutUseless( Nf_Man_t * p, int TruthId ) { return (int)(TruthId >= Vec_WecSize(p->vTt2Match)); }
132
133static inline float Nf_ObjCutFlow( Nf_Man_t * p, int i ) { return Vec_FltEntry(&p->vCutFlows, i); }
134static inline int Nf_ObjCutDelay( Nf_Man_t * p, int i ) { return Vec_IntEntry(&p->vCutDelays, i); }
135static inline void Nf_ObjSetCutFlow( Nf_Man_t * p, int i, float a ) { Vec_FltWriteEntry(&p->vCutFlows, i, a); }
136static inline void Nf_ObjSetCutDelay( Nf_Man_t * p, int i, int d ) { Vec_IntWriteEntry(&p->vCutDelays, i, d); }
137
138static inline int Nf_ObjMapRefNum( Nf_Man_t * p, int i, int c ) { return Vec_IntEntry(&p->vMapRefs, Abc_Var2Lit(i,c)); }
139static inline int Nf_ObjMapRefInc( Nf_Man_t * p, int i, int c ) { return (*Vec_IntEntryP(&p->vMapRefs, Abc_Var2Lit(i,c)))++; }
140static inline int Nf_ObjMapRefDec( Nf_Man_t * p, int i, int c ) { return --(*Vec_IntEntryP(&p->vMapRefs, Abc_Var2Lit(i,c))); }
141static inline float Nf_ObjFlowRefs( Nf_Man_t * p, int i, int c ) { return Vec_FltEntry(&p->vFlowRefs, Abc_Var2Lit(i,c)); }
142static inline int Nf_ObjRequired( Nf_Man_t * p, int i, int c ) { return Vec_IntEntry(&p->vRequired, Abc_Var2Lit(i,c)); }
143static inline void Nf_ObjSetRequired( Nf_Man_t * p,int i, int c, int f ) { Vec_IntWriteEntry(&p->vRequired, Abc_Var2Lit(i,c), f); }
144static inline void Nf_ObjUpdateRequired( Nf_Man_t * p,int i, int c, int f ) { if (Nf_ObjRequired(p, i, c) > f) Nf_ObjSetRequired(p, i, c, f); }
145
146static inline Nf_Mat_t * Nf_ObjMatchD( Nf_Man_t * p, int i, int c ) { return &Nf_ManObj(p, i)->M[c][0]; }
147static inline Nf_Mat_t * Nf_ObjMatchA( Nf_Man_t * p, int i, int c ) { return &Nf_ManObj(p, i)->M[c][1]; }
148
149static inline int Nf_CutSize( int * pCut ) { return pCut[0] & NF_NO_LEAF; }
150static inline int Nf_CutFunc( int * pCut ) { return ((unsigned)pCut[0] >> 5); }
151static inline int * Nf_CutLeaves( int * pCut ) { return pCut + 1; }
152static inline int Nf_CutSetBoth( int n, int f ) { return n | (f << 5); }
153static inline int Nf_CutIsTriv( int * pCut, int i ) { return Nf_CutSize(pCut) == 1 && pCut[1] == i; }
154static inline int Nf_CutHandle( int * pCutSet, int * pCut ) { assert( pCut > pCutSet ); return pCut - pCutSet; }
155static inline int * Nf_CutFromHandle( int * pCutSet, int h ) { assert( h > 0 ); return pCutSet + h; }
156
157static inline int Nf_CfgVar( Nf_Cfg_t Cfg, int i ) { return (Cfg.Perm >> (i<<2)) & 15; }
158static inline int Nf_CfgCompl( Nf_Cfg_t Cfg, int i ) { return (Cfg.Phase >> i) & 1; }
159
160#define Nf_SetForEachCut( pList, pCut, i ) for ( i = 0, pCut = pList + 1; i < pList[0]; i++, pCut += Nf_CutSize(pCut) + 1 )
161#define Nf_CutForEachVarCompl( pCut, Cfg, iVar, fCompl, i ) for ( i = 0; i < Nf_CutSize(pCut) && (iVar = Nf_CutLeaves(pCut)[Nf_CfgVar(Cfg, i)]) && ((fCompl = Nf_CfgCompl(Cfg, i)), 1); i++ )
162#define Nf_CfgForEachVarCompl( Cfg, Size, iVar, fCompl, i ) for ( i = 0; i < Size && ((iVar = Nf_CfgVar(Cfg, i)), 1) && ((fCompl = Nf_CfgCompl(Cfg, i)), 1); i++ )
163
167
179int Nf_StoCellIsDominated( Mio_Cell2_t * pCell, int * pFans, int * pProf )
180{
181 int k;
182 if ( pCell->AreaF + NF_EPSILON < Abc_Int2Float(pProf[0]) )
183 return 0;
184 for ( k = 0; k < (int)pCell->nFanins; k++ )
185 if ( pCell->iDelays[Abc_Lit2Var(pFans[k])] < pProf[k+1] )
186 return 0;
187 return 1; // pCell is dominated
188}
189void Nf_StoCreateGateAdd( Vec_Mem_t * vTtMem, Vec_Wec_t * vTt2Match, Mio_Cell2_t * pCell, word uTruth, int * pFans, int nFans, Vec_Wec_t * vProfs, Vec_Int_t * vStore, int fPinFilter, int fPinPerm, int fPinQuick )
190{
191 Vec_Int_t * vArray, * vArrayProfs = NULL;
192 int i, k, GateId, Entry, fCompl = (int)(uTruth & 1);
193 word uFunc = fCompl ? ~uTruth : uTruth;
194 int iFunc = Vec_MemHashInsert( vTtMem, &uFunc );
195 Nf_Cfg_t Mat = Nf_Int2Cfg(0);
196 // get match array
197 if ( iFunc == Vec_WecSize(vTt2Match) )
198 Vec_WecPushLevel( vTt2Match );
199 vArray = Vec_WecEntry( vTt2Match, iFunc );
200 // create match
201 Mat.fCompl = fCompl;
202 assert( nFans == (int)pCell->nFanins );
203 for ( i = 0; i < nFans; i++ )
204 {
205 Mat.Perm |= (unsigned)(i << (Abc_Lit2Var(pFans[i]) << 2));
206 Mat.Phase |= (unsigned)(Abc_LitIsCompl(pFans[i]) << Abc_Lit2Var(pFans[i]));
207 }
208 // check other profiles
209 if ( fPinFilter )
210 {
211 // get profile array
212 assert( Vec_WecSize(vTt2Match) == Vec_WecSize(vProfs) );
213 if ( iFunc == Vec_WecSize(vProfs) )
214 Vec_WecPushLevel( vProfs );
215 vArrayProfs = Vec_WecEntry( vProfs, iFunc );
216 assert( Vec_IntSize(vArray) == 2 * Vec_IntSize(vArrayProfs) );
217 // skip dominated matches
218 Vec_IntForEachEntryDouble( vArray, GateId, Entry, i )
219 if ( Nf_Int2Cfg(Entry).Phase == Mat.Phase && Nf_Int2Cfg(Entry).fCompl == Mat.fCompl )
220 {
221 int Offset = Vec_IntEntry(vArrayProfs, i/2);
222 int * pProf = Vec_IntEntryP(vStore, Offset);
223 if ( Nf_StoCellIsDominated(pCell, pFans, pProf) )
224 return;
225 }
226 }
227 // check pin permutation
228 if ( !fPinPerm ) // do not use pin-permutation (improves delay when pin-delays differ)
229 {
230 if ( fPinQuick ) // reduce the number of matches agressively
231 {
232 Vec_IntForEachEntryDouble( vArray, GateId, Entry, i )
233 if ( GateId == (int)pCell->Id && __builtin_popcount( Nf_Int2Cfg(Entry).Phase & 0xff ) == __builtin_popcount( Mat.Phase & 0xff ) )
234 return;
235 }
236 else // reduce the number of matches less agressively
237 {
238 Vec_IntForEachEntryDouble( vArray, GateId, Entry, i )
239 if ( GateId == (int)pCell->Id && Nf_Int2Cfg(Entry).Phase == Mat.Phase )
240 return;
241 }
242 }
243 // save data and profile
244 Vec_IntPush( vArray, pCell->Id );
245 Vec_IntPush( vArray, Nf_Cfg2Int(Mat) );
246 // add delay profile
247 if ( fPinFilter )
248 {
249 Vec_IntPush( vArrayProfs, Vec_IntSize(vStore) );
250 Vec_IntPush( vStore, Abc_Float2Int(pCell->AreaF) );
251 for ( k = 0; k < nFans; k++ )
252 Vec_IntPush( vStore, pCell->iDelays[Abc_Lit2Var(pFans[k])] );
253 }
254}
255void Nf_StoCreateGateMaches( Vec_Mem_t * vTtMem, Vec_Wec_t * vTt2Match, Mio_Cell2_t * pCell, int ** pComp, int ** pPerm, int * pnPerms, Vec_Wec_t * vProfs, Vec_Int_t * vStore, int fPinFilter, int fPinPerm, int fPinQuick )
256{
257 int Perm[NF_LEAF_MAX], * Perm1, * Perm2;
258 int nPerms = pnPerms[pCell->nFanins];
259 int nMints = (1 << pCell->nFanins);
260 word tCur, tTemp1, tTemp2;
261 int i, p, c;
262 assert( pCell->nFanins <= 6 );
263 for ( i = 0; i < (int)pCell->nFanins; i++ )
264 Perm[i] = Abc_Var2Lit( i, 0 );
265 tCur = tTemp1 = pCell->uTruth;
266 for ( p = 0; p < nPerms; p++ )
267 {
268 tTemp2 = tCur;
269 for ( c = 0; c < nMints; c++ )
270 {
271 Nf_StoCreateGateAdd( vTtMem, vTt2Match, pCell, tCur, Perm, pCell->nFanins, vProfs, vStore, fPinFilter, fPinPerm, fPinQuick );
272 // update
273 tCur = Abc_Tt6Flip( tCur, pComp[pCell->nFanins][c] );
274 Perm1 = Perm + pComp[pCell->nFanins][c];
275 *Perm1 = Abc_LitNot( *Perm1 );
276 }
277 assert( tTemp2 == tCur );
278 if ( nPerms == 1 )
279 continue;
280 // update
281 tCur = Abc_Tt6SwapAdjacent( tCur, pPerm[pCell->nFanins][p] );
282 Perm1 = Perm + pPerm[pCell->nFanins][p];
283 Perm2 = Perm1 + 1;
284 ABC_SWAP( int, *Perm1, *Perm2 );
285 }
286 assert( tTemp1 == tCur );
287}
288Mio_Cell2_t * Nf_StoDeriveMatches( Vec_Mem_t * vTtMem, Vec_Wec_t * vTt2Match, int * pnCells, int fPinFilter, int fPinPerm, int fPinQuick )
289{
290 int fVerbose = 0;
291 //abctime clk = Abc_Clock();
292 Vec_Wec_t * vProfs = Vec_WecAlloc( 1000 );
293 Vec_Int_t * vStore = Vec_IntAlloc( 10000 );
294 int * pComp[7], * pPerm[7], nPerms[7], i;
295 Mio_Cell2_t * pCells;
296 Vec_WecPushLevel( vProfs );
297 Vec_WecPushLevel( vProfs );
298 for ( i = 1; i <= 6; i++ )
299 pComp[i] = Extra_GreyCodeSchedule( i );
300 for ( i = 1; i <= 6; i++ )
301 pPerm[i] = Extra_PermSchedule( i );
302 for ( i = 1; i <= 6; i++ )
303 nPerms[i] = Extra_Factorial( i );
304 pCells = Mio_CollectRootsNewDefault2( 6, pnCells, fVerbose );
305 if ( pCells != NULL )
306 for ( i = 2; i < *pnCells; i++ )
307 Nf_StoCreateGateMaches( vTtMem, vTt2Match, pCells+i, pComp, pPerm, nPerms, vProfs, vStore, fPinFilter, fPinPerm, fPinQuick );
308 for ( i = 1; i <= 6; i++ )
309 ABC_FREE( pComp[i] );
310 for ( i = 1; i <= 6; i++ )
311 ABC_FREE( pPerm[i] );
312 Vec_WecFree( vProfs );
313 Vec_IntFree( vStore );
314 //Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
315 return pCells;
316}
317void Nf_StoPrintOne( Nf_Man_t * p, int Count, int t, int i, int GateId, Nf_Cfg_t Mat )
318{
319 Mio_Cell2_t * pC = p->pCells + GateId;
320 word * pTruth = Vec_MemReadEntry(p->vTtMem, t);
321 int k, nSuppSize = Abc_TtSupportSize(pTruth, 6);
322 printf( "%6d : ", Count );
323 printf( "%6d : ", t );
324 printf( "%6d : ", i );
325 printf( "Gate %16s ", pC->pName );
326 printf( "Area =%8.2f ", pC->AreaF );
327 printf( "In = %d ", pC->nFanins );
328 if ( Mat.fCompl )
329 printf( " compl " );
330 else
331 printf( " " );
332 for ( k = 0; k < (int)pC->nFanins; k++ )
333 {
334 int fComplF = (Mat.Phase >> k) & 1;
335 int iFanin = (Mat.Perm >> (3*k)) & 7;
336 printf( "%c", 'a' + iFanin - fComplF * ('a' - 'A') );
337 }
338 printf( " " );
339 Dau_DsdPrintFromTruth( pTruth, nSuppSize );
340}
341void Nf_StoPrint( Nf_Man_t * p, int fVerbose )
342{
343 int t, i, GateId, Entry, Count = 0;
344 for ( t = 2; t < Vec_WecSize(p->vTt2Match); t++ )
345 {
346 Vec_Int_t * vArr = Vec_WecEntry( p->vTt2Match, t );
347 Vec_IntForEachEntryDouble( vArr, GateId, Entry, i )
348 {
349 Count++;
350 if ( !fVerbose )
351 continue;
352 //if ( t < 10 )
353 // Nf_StoPrintOne( p, Count, t, i/2, GateId, Pf_Int2Mat(Entry) );
354 }
355 }
356 printf( "Gates = %d. Truths = %d. Matches = %d.\n",
357 p->nCells, Vec_MemEntryNum(p->vTtMem), Count );
358}
359
360
361
374{
375 extern void Mf_ManSetFlowRefs( Gia_Man_t * p, Vec_Int_t * vRefs );
376 Vec_Int_t * vFlowRefs;
377 Nf_Man_t * p;
378 int i, Entry;
379 assert( pPars->nCutNum > 1 && pPars->nCutNum <= NF_CUT_MAX );
380 assert( pPars->nLutSize > 1 && pPars->nLutSize <= NF_LEAF_MAX );
381 ABC_FREE( pGia->pRefs );
382 Vec_IntFreeP( &pGia->vCellMapping );
383 if ( Gia_ManHasChoices(pGia) )
384 Gia_ManSetPhase(pGia);
385 // create
386 p = ABC_CALLOC( Nf_Man_t, 1 );
387 p->clkStart = Abc_Clock();
388 p->pGia = pGia;
389 p->pManTim = (Tim_Man_t *)pGia->pManTime;
390 p->pPars = pPars;
391 p->pNfObjs = ABC_CALLOC( Nf_Obj_t, Gia_ManObjNum(pGia) );
392 p->iCur = 2;
393 // other
394 Vec_PtrGrow( &p->vPages, 256 ); // cut memory
395 Vec_IntFill( &p->vMapRefs, 2*Gia_ManObjNum(pGia), 0 ); // mapping refs (2x)
396 Vec_FltFill( &p->vFlowRefs, 2*Gia_ManObjNum(pGia), 0 ); // flow refs (2x)
397 Vec_IntFill( &p->vRequired, 2*Gia_ManObjNum(pGia), SCL_INFINITY ); // required times (2x)
398 Vec_IntFill( &p->vCutSets, Gia_ManObjNum(pGia), 0 ); // cut offsets
399 Vec_FltFill( &p->vCutFlows, Gia_ManObjNum(pGia), 0 ); // cut area
400 Vec_IntFill( &p->vCutDelays,Gia_ManObjNum(pGia), 0 ); // cut delay
401 Vec_IntGrow( &p->vBackup, 1000 );
402 // references
403 vFlowRefs = Vec_IntAlloc(0);
404 Mf_ManSetFlowRefs( pGia, vFlowRefs );
405 Vec_IntForEachEntry( vFlowRefs, Entry, i )
406 {
407 Vec_FltWriteEntry( &p->vFlowRefs, 2*i, /*0.5* */Entry );
408 Vec_FltWriteEntry( &p->vFlowRefs, 2*i+1, /*0.5* */Entry );
409 }
410 Vec_IntFree(vFlowRefs);
411 // matching
412 Mio_LibraryMatchesFetch( (Mio_Library_t *)Abc_FrameReadLibGen(), &p->vTtMem, &p->vTt2Match, &p->pCells, &p->nCells, p->pPars->fPinFilter, p->pPars->fPinPerm, p->pPars->fPinQuick );
413 if ( p->pCells == NULL )
414 return NULL;
415 p->InvDelayI = p->pCells[3].iDelays[0];
416 p->InvAreaW = p->pCells[3].AreaW;
417 p->InvAreaF = p->pCells[3].AreaF;
418 Nf_ObjMatchD(p, 0, 0)->Gate = 0;
419 Nf_ObjMatchD(p, 0, 1)->Gate = 1;
420 // prepare cuts
421 return p;
422}
424{
425 Vec_PtrFreeData( &p->vPages );
426 ABC_FREE( p->vPages.pArray );
427 ABC_FREE( p->vMapRefs.pArray );
428 ABC_FREE( p->vFlowRefs.pArray );
429 ABC_FREE( p->vRequired.pArray );
430 ABC_FREE( p->vCutSets.pArray );
431 ABC_FREE( p->vCutFlows.pArray );
432 ABC_FREE( p->vCutDelays.pArray );
433 ABC_FREE( p->vBackup.pArray );
434 ABC_FREE( p->pNfObjs );
435 ABC_FREE( p );
436}
437
438
439
440
452static inline int Nf_CutComputeTruth6( Nf_Man_t * p, Nf_Cut_t * pCut0, Nf_Cut_t * pCut1, int fCompl0, int fCompl1, Nf_Cut_t * pCutR, int fIsXor )
453{
454// extern int Nf_ManTruthCanonicize( word * t, int nVars );
455 int nOldSupp = pCutR->nLeaves, truthId, fCompl; word t;
456 word t0 = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut0->iFunc));
457 word t1 = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut1->iFunc));
458 if ( Abc_LitIsCompl(pCut0->iFunc) ^ fCompl0 ) t0 = ~t0;
459 if ( Abc_LitIsCompl(pCut1->iFunc) ^ fCompl1 ) t1 = ~t1;
460 t0 = Abc_Tt6Expand( t0, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
461 t1 = Abc_Tt6Expand( t1, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
462 t = fIsXor ? t0 ^ t1 : t0 & t1;
463 if ( (fCompl = (int)(t & 1)) ) t = ~t;
464 pCutR->nLeaves = Abc_Tt6MinBase( &t, pCutR->pLeaves, pCutR->nLeaves );
465 assert( (int)(t & 1) == 0 );
466 truthId = Vec_MemHashInsert(p->vTtMem, &t);
467 pCutR->iFunc = Abc_Var2Lit( truthId, fCompl );
468 pCutR->Useless = Nf_ObjCutUseless( p, truthId );
469 assert( (int)pCutR->nLeaves <= nOldSupp );
470 return (int)pCutR->nLeaves < nOldSupp;
471}
472static inline int Nf_CutComputeTruthMux6( Nf_Man_t * p, Nf_Cut_t * pCut0, Nf_Cut_t * pCut1, Nf_Cut_t * pCutC, int fCompl0, int fCompl1, int fComplC, Nf_Cut_t * pCutR )
473{
474 int nOldSupp = pCutR->nLeaves, truthId, fCompl; word t;
475 word t0 = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut0->iFunc));
476 word t1 = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut1->iFunc));
477 word tC = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCutC->iFunc));
478 if ( Abc_LitIsCompl(pCut0->iFunc) ^ fCompl0 ) t0 = ~t0;
479 if ( Abc_LitIsCompl(pCut1->iFunc) ^ fCompl1 ) t1 = ~t1;
480 if ( Abc_LitIsCompl(pCutC->iFunc) ^ fComplC ) tC = ~tC;
481 t0 = Abc_Tt6Expand( t0, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
482 t1 = Abc_Tt6Expand( t1, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
483 tC = Abc_Tt6Expand( tC, pCutC->pLeaves, pCutC->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
484 t = (tC & t1) | (~tC & t0);
485 if ( (fCompl = (int)(t & 1)) ) t = ~t;
486 pCutR->nLeaves = Abc_Tt6MinBase( &t, pCutR->pLeaves, pCutR->nLeaves );
487 assert( (int)(t & 1) == 0 );
488 truthId = Vec_MemHashInsert(p->vTtMem, &t);
489 pCutR->iFunc = Abc_Var2Lit( truthId, fCompl );
490 pCutR->Useless = Nf_ObjCutUseless( p, truthId );
491 assert( (int)pCutR->nLeaves <= nOldSupp );
492 return (int)pCutR->nLeaves < nOldSupp;
493}
494
495
507static inline int Nf_CutCountBits( word i )
508{
509 i = i - ((i >> 1) & 0x5555555555555555);
510 i = (i & 0x3333333333333333) + ((i >> 2) & 0x3333333333333333);
511 i = ((i + (i >> 4)) & 0x0F0F0F0F0F0F0F0F);
512 return (i*(0x0101010101010101))>>56;
513}
514static inline word Nf_CutGetSign( int * pLeaves, int nLeaves )
515{
516 word Sign = 0; int i;
517 for ( i = 0; i < nLeaves; i++ )
518 Sign |= ((word)1) << (pLeaves[i] & 0x3F);
519 return Sign;
520}
521static inline int Nf_CutCreateUnit( Nf_Cut_t * p, int i )
522{
523 p->Delay = 0;
524 p->Flow = 0;
525 p->iFunc = 2;
526 p->nLeaves = 1;
527 p->pLeaves[0] = i;
528 p->Sign = ((word)1) << (i & 0x3F);
529 return 1;
530}
531static inline void Nf_CutPrint( Nf_Man_t * p, Nf_Cut_t * pCut )
532{
533 int i, nDigits = Abc_Base10Log(Gia_ManObjNum(p->pGia));
534 printf( "%d {", pCut->nLeaves );
535 for ( i = 0; i < (int)pCut->nLeaves; i++ )
536 printf( " %*d", nDigits, pCut->pLeaves[i] );
537 for ( ; i < (int)p->pPars->nLutSize; i++ )
538 printf( " %*s", nDigits, " " );
539 printf( " } Useless = %d. D = %4d A = %9.4f F = %6d ",
540 pCut->Useless, pCut->Delay, pCut->Flow, pCut->iFunc );
541 if ( p->vTtMem )
542 Dau_DsdPrintFromTruth( Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut->iFunc)), pCut->nLeaves );
543 else
544 printf( "\n" );
545}
546static inline int Nf_ManPrepareCuts( Nf_Cut_t * pCuts, Nf_Man_t * p, int iObj, int fAddUnit )
547{
548 if ( Nf_ObjHasCuts(p, iObj) )
549 {
550 Nf_Cut_t * pMfCut = pCuts;
551 int i, * pCut, * pList = Nf_ObjCutSet(p, iObj);
552 Nf_SetForEachCut( pList, pCut, i )
553 {
554 pMfCut->Delay = 0;
555 pMfCut->Flow = 0;
556 pMfCut->iFunc = Nf_CutFunc( pCut );
557 pMfCut->nLeaves = Nf_CutSize( pCut );
558 pMfCut->Sign = Nf_CutGetSign( pCut+1, Nf_CutSize(pCut) );
559 pMfCut->Useless = Nf_ObjCutUseless( p, Abc_Lit2Var(pMfCut->iFunc) );
560 memcpy( pMfCut->pLeaves, pCut+1, sizeof(int) * Nf_CutSize(pCut) );
561 pMfCut++;
562 }
563 if ( fAddUnit && pCuts->nLeaves > 1 )
564 return pList[0] + Nf_CutCreateUnit( pMfCut, iObj );
565 return pList[0];
566 }
567 return Nf_CutCreateUnit( pCuts, iObj );
568}
569static inline int Nf_ManSaveCuts( Nf_Man_t * p, Nf_Cut_t ** pCuts, int nCuts, int fUseful )
570{
571 int i, * pPlace, iCur, nInts = 1, nCutsNew = 0;
572 for ( i = 0; i < nCuts; i++ )
573 if ( !fUseful || !pCuts[i]->Useless )
574 nInts += pCuts[i]->nLeaves + 1, nCutsNew++;
575 if ( (p->iCur & 0xFFFF) + nInts > 0xFFFF )
576 p->iCur = ((p->iCur >> 16) + 1) << 16;
577 if ( Vec_PtrSize(&p->vPages) == (p->iCur >> 16) )
578 Vec_PtrPush( &p->vPages, ABC_ALLOC(int, (1<<16)) );
579 iCur = p->iCur; p->iCur += nInts;
580 pPlace = Nf_ManCutSet( p, iCur );
581 *pPlace++ = nCutsNew;
582 for ( i = 0; i < nCuts; i++ )
583 if ( !fUseful || !pCuts[i]->Useless )
584 {
585 *pPlace++ = Nf_CutSetBoth( pCuts[i]->nLeaves, pCuts[i]->iFunc );
586 memcpy( pPlace, pCuts[i]->pLeaves, sizeof(int) * pCuts[i]->nLeaves );
587 pPlace += pCuts[i]->nLeaves;
588 }
589 return iCur;
590}
591static inline int Nf_ManCountUseful( Nf_Cut_t ** pCuts, int nCuts )
592{
593 int i, Count = 0;
594 for ( i = 0; i < nCuts; i++ )
595 Count += !pCuts[i]->Useless;
596 return Count;
597}
598static inline int Nf_ManCountMatches( Nf_Man_t * p, Nf_Cut_t ** pCuts, int nCuts )
599{
600 int i, Count = 0;
601 for ( i = 0; i < nCuts; i++ )
602 if ( !pCuts[i]->Useless )
603 Count += Vec_IntSize(Vec_WecEntry(p->vTt2Match, Abc_Lit2Var(pCuts[i]->iFunc))) / 2;
604 return Count;
605}
606
618static inline int Nf_CutCheck( Nf_Cut_t * pBase, Nf_Cut_t * pCut ) // check if pCut is contained in pBase
619{
620 int nSizeB = pBase->nLeaves;
621 int nSizeC = pCut->nLeaves;
622 int i, * pB = pBase->pLeaves;
623 int k, * pC = pCut->pLeaves;
624 for ( i = 0; i < nSizeC; i++ )
625 {
626 for ( k = 0; k < nSizeB; k++ )
627 if ( pC[i] == pB[k] )
628 break;
629 if ( k == nSizeB )
630 return 0;
631 }
632 return 1;
633}
634static inline int Nf_SetCheckArray( Nf_Cut_t ** ppCuts, int nCuts )
635{
636 Nf_Cut_t * pCut0, * pCut1;
637 int i, k, m, n, Value;
638 assert( nCuts > 0 );
639 for ( i = 0; i < nCuts; i++ )
640 {
641 pCut0 = ppCuts[i];
642 assert( pCut0->nLeaves <= NF_LEAF_MAX );
643 assert( pCut0->Sign == Nf_CutGetSign(pCut0->pLeaves, pCut0->nLeaves) );
644 // check duplicates
645 for ( m = 0; m < (int)pCut0->nLeaves; m++ )
646 for ( n = m + 1; n < (int)pCut0->nLeaves; n++ )
647 assert( pCut0->pLeaves[m] < pCut0->pLeaves[n] );
648 // check pairs
649 for ( k = 0; k < nCuts; k++ )
650 {
651 pCut1 = ppCuts[k];
652 if ( pCut0 == pCut1 )
653 continue;
654 // check containments
655 Value = Nf_CutCheck( pCut0, pCut1 );
656 assert( Value == 0 );
657 }
658 }
659 return 1;
660}
661
662
674static inline int Nf_CutMergeOrder( Nf_Cut_t * pCut0, Nf_Cut_t * pCut1, Nf_Cut_t * pCut, int nLutSize )
675{
676 int nSize0 = pCut0->nLeaves;
677 int nSize1 = pCut1->nLeaves;
678 int i, * pC0 = pCut0->pLeaves;
679 int k, * pC1 = pCut1->pLeaves;
680 int c, * pC = pCut->pLeaves;
681 // the case of the largest cut sizes
682 if ( nSize0 == nLutSize && nSize1 == nLutSize )
683 {
684 for ( i = 0; i < nSize0; i++ )
685 {
686 if ( pC0[i] != pC1[i] ) return 0;
687 pC[i] = pC0[i];
688 }
689 pCut->nLeaves = nLutSize;
690 pCut->iFunc = NF_NO_FUNC;
691 pCut->Sign = pCut0->Sign | pCut1->Sign;
692 return 1;
693 }
694 // compare two cuts with different numbers
695 i = k = c = 0;
696 if ( nSize0 == 0 ) goto FlushCut1;
697 if ( nSize1 == 0 ) goto FlushCut0;
698 while ( 1 )
699 {
700 if ( c == nLutSize ) return 0;
701 if ( pC0[i] < pC1[k] )
702 {
703 pC[c++] = pC0[i++];
704 if ( i >= nSize0 ) goto FlushCut1;
705 }
706 else if ( pC0[i] > pC1[k] )
707 {
708 pC[c++] = pC1[k++];
709 if ( k >= nSize1 ) goto FlushCut0;
710 }
711 else
712 {
713 pC[c++] = pC0[i++]; k++;
714 if ( i >= nSize0 ) goto FlushCut1;
715 if ( k >= nSize1 ) goto FlushCut0;
716 }
717 }
718
719FlushCut0:
720 if ( c + nSize0 > nLutSize + i ) return 0;
721 while ( i < nSize0 )
722 pC[c++] = pC0[i++];
723 pCut->nLeaves = c;
724 pCut->iFunc = NF_NO_FUNC;
725 pCut->Sign = pCut0->Sign | pCut1->Sign;
726 return 1;
727
728FlushCut1:
729 if ( c + nSize1 > nLutSize + k ) return 0;
730 while ( k < nSize1 )
731 pC[c++] = pC1[k++];
732 pCut->nLeaves = c;
733 pCut->iFunc = NF_NO_FUNC;
734 pCut->Sign = pCut0->Sign | pCut1->Sign;
735 return 1;
736}
737static inline int Nf_CutMergeOrderMux( Nf_Cut_t * pCut0, Nf_Cut_t * pCut1, Nf_Cut_t * pCut2, Nf_Cut_t * pCut, int nLutSize )
738{
739 int x0, i0 = 0, nSize0 = pCut0->nLeaves, * pC0 = pCut0->pLeaves;
740 int x1, i1 = 0, nSize1 = pCut1->nLeaves, * pC1 = pCut1->pLeaves;
741 int x2, i2 = 0, nSize2 = pCut2->nLeaves, * pC2 = pCut2->pLeaves;
742 int xMin, c = 0, * pC = pCut->pLeaves;
743 while ( 1 )
744 {
745 x0 = (i0 == nSize0) ? ABC_INFINITY : pC0[i0];
746 x1 = (i1 == nSize1) ? ABC_INFINITY : pC1[i1];
747 x2 = (i2 == nSize2) ? ABC_INFINITY : pC2[i2];
748 xMin = Abc_MinInt( Abc_MinInt(x0, x1), x2 );
749 if ( xMin == ABC_INFINITY ) break;
750 if ( c == nLutSize ) return 0;
751 pC[c++] = xMin;
752 if (x0 == xMin) i0++;
753 if (x1 == xMin) i1++;
754 if (x2 == xMin) i2++;
755 }
756 pCut->nLeaves = c;
757 pCut->iFunc = NF_NO_FUNC;
758 pCut->Sign = pCut0->Sign | pCut1->Sign | pCut2->Sign;
759 return 1;
760}
761static inline int Nf_SetCutIsContainedOrder( Nf_Cut_t * pBase, Nf_Cut_t * pCut ) // check if pCut is contained in pBase
762{
763 int i, nSizeB = pBase->nLeaves;
764 int k, nSizeC = pCut->nLeaves;
765 if ( nSizeB == nSizeC )
766 {
767 for ( i = 0; i < nSizeB; i++ )
768 if ( pBase->pLeaves[i] != pCut->pLeaves[i] )
769 return 0;
770 return 1;
771 }
772 assert( nSizeB > nSizeC );
773 if ( nSizeC == 0 )
774 return 1;
775 for ( i = k = 0; i < nSizeB; i++ )
776 {
777 if ( pBase->pLeaves[i] > pCut->pLeaves[k] )
778 return 0;
779 if ( pBase->pLeaves[i] == pCut->pLeaves[k] )
780 {
781 if ( ++k == nSizeC )
782 return 1;
783 }
784 }
785 return 0;
786}
787static inline int Nf_SetLastCutIsContained( Nf_Cut_t ** pCuts, int nCuts )
788{
789 int i;
790 for ( i = 0; i < nCuts; i++ )
791 if ( pCuts[i]->nLeaves <= pCuts[nCuts]->nLeaves && (pCuts[i]->Sign & pCuts[nCuts]->Sign) == pCuts[i]->Sign && Nf_SetCutIsContainedOrder(pCuts[nCuts], pCuts[i]) )
792 return 1;
793 return 0;
794}
795static inline int Nf_SetLastCutContainsArea( Nf_Cut_t ** pCuts, int nCuts )
796{
797 int i, k, fChanges = 0;
798 for ( i = 0; i < nCuts; i++ )
799 if ( pCuts[nCuts]->nLeaves < pCuts[i]->nLeaves && (pCuts[nCuts]->Sign & pCuts[i]->Sign) == pCuts[nCuts]->Sign && Nf_SetCutIsContainedOrder(pCuts[i], pCuts[nCuts]) )
800 pCuts[i]->nLeaves = NF_NO_LEAF, fChanges = 1;
801 if ( !fChanges )
802 return nCuts;
803 for ( i = k = 0; i <= nCuts; i++ )
804 {
805 if ( pCuts[i]->nLeaves == NF_NO_LEAF )
806 continue;
807 if ( k < i )
808 ABC_SWAP( Nf_Cut_t *, pCuts[k], pCuts[i] );
809 k++;
810 }
811 return k - 1;
812}
813static inline int Nf_CutCompareArea( Nf_Cut_t * pCut0, Nf_Cut_t * pCut1 )
814{
815 if ( pCut0->Useless < pCut1->Useless ) return -1;
816 if ( pCut0->Useless > pCut1->Useless ) return 1;
817 if ( pCut0->Flow < pCut1->Flow - NF_EPSILON ) return -1;
818 if ( pCut0->Flow > pCut1->Flow + NF_EPSILON ) return 1;
819 if ( pCut0->Delay < pCut1->Delay ) return -1;
820 if ( pCut0->Delay > pCut1->Delay ) return 1;
821 if ( pCut0->nLeaves < pCut1->nLeaves ) return -1;
822 if ( pCut0->nLeaves > pCut1->nLeaves ) return 1;
823 return 0;
824}
825static inline void Nf_SetSortByArea( Nf_Cut_t ** pCuts, int nCuts )
826{
827 int i;
828 for ( i = nCuts; i > 0; i-- )
829 {
830 if ( Nf_CutCompareArea(pCuts[i - 1], pCuts[i]) < 0 )
831 return;
832 ABC_SWAP( Nf_Cut_t *, pCuts[i - 1], pCuts[i] );
833 }
834}
835static inline int Nf_SetAddCut( Nf_Cut_t ** pCuts, int nCuts, int nCutNum )
836{
837 if ( nCuts == 0 )
838 return 1;
839 nCuts = Nf_SetLastCutContainsArea(pCuts, nCuts);
840 Nf_SetSortByArea( pCuts, nCuts );
841 return Abc_MinInt( nCuts + 1, nCutNum - 1 );
842}
843static inline int Nf_CutArea( Nf_Man_t * p, int nLeaves )
844{
845 if ( nLeaves < 2 )
846 return 0;
847 return nLeaves + p->pPars->nAreaTuner;
848}
849static inline void Nf_CutParams( Nf_Man_t * p, Nf_Cut_t * pCut, float FlowRefs )
850{
851 int i, nLeaves = pCut->nLeaves;
852 assert( nLeaves <= p->pPars->nLutSize );
853 pCut->Delay = 0;
854 pCut->Flow = 0;
855 for ( i = 0; i < nLeaves; i++ )
856 {
857 pCut->Delay = Abc_MaxInt( pCut->Delay, Nf_ObjCutDelay(p, pCut->pLeaves[i]) );
858 pCut->Flow += Nf_ObjCutFlow(p, pCut->pLeaves[i]);
859 }
860 pCut->Delay += (int)(nLeaves > 1);
861 pCut->Flow = (pCut->Flow + Nf_CutArea(p, nLeaves)) / FlowRefs;
862}
863void Nf_ObjMergeOrder( Nf_Man_t * p, int iObj )
864{
865 Nf_Cut_t pCuts0[NF_CUT_MAX], pCuts1[NF_CUT_MAX], pCuts[NF_CUT_MAX], * pCutsR[NF_CUT_MAX];
866 Gia_Obj_t * pObj = Gia_ManObj(p->pGia, iObj);
867 //Nf_Obj_t * pBest = Nf_ManObj(p, iObj);
868 float dFlowRefs = Nf_ObjFlowRefs(p, iObj, 0) + Nf_ObjFlowRefs(p, iObj, 1);
869 int nLutSize = p->pPars->nLutSize;
870 int nCutNum = p->pPars->nCutNum;
871 int nCuts0 = Nf_ManPrepareCuts(pCuts0, p, Gia_ObjFaninId0(pObj, iObj), 1);
872 int nCuts1 = Nf_ManPrepareCuts(pCuts1, p, Gia_ObjFaninId1(pObj, iObj), 1);
873 int fComp0 = Gia_ObjFaninC0(pObj);
874 int fComp1 = Gia_ObjFaninC1(pObj);
875 int iSibl = Gia_ObjSibl(p->pGia, iObj);
876 Nf_Cut_t * pCut0, * pCut1, * pCut0Lim = pCuts0 + nCuts0, * pCut1Lim = pCuts1 + nCuts1;
877 int i, nCutsUse, nCutsR = 0;
878 assert( !Gia_ObjIsBuf(pObj) );
879 for ( i = 0; i < nCutNum; i++ )
880 pCutsR[i] = pCuts + i;
881 if ( iSibl )
882 {
883 Nf_Cut_t pCuts2[NF_CUT_MAX];
884 Gia_Obj_t * pObjE = Gia_ObjSiblObj(p->pGia, iObj);
885 int fCompE = Gia_ObjPhase(pObj) ^ Gia_ObjPhase(pObjE);
886 int nCuts2 = Nf_ManPrepareCuts(pCuts2, p, iSibl, 0);
887 Nf_Cut_t * pCut2, * pCut2Lim = pCuts2 + nCuts2;
888 for ( pCut2 = pCuts2; pCut2 < pCut2Lim; pCut2++ )
889 {
890 *pCutsR[nCutsR] = *pCut2;
891 pCutsR[nCutsR]->iFunc = Abc_LitNotCond( pCutsR[nCutsR]->iFunc, fCompE );
892 Nf_CutParams( p, pCutsR[nCutsR], dFlowRefs );
893 nCutsR = Nf_SetAddCut( pCutsR, nCutsR, nCutNum );
894 }
895 }
896 if ( Gia_ObjIsMuxId(p->pGia, iObj) )
897 {
898 Nf_Cut_t pCuts2[NF_CUT_MAX];
899 int nCuts2 = Nf_ManPrepareCuts(pCuts2, p, Gia_ObjFaninId2(p->pGia, iObj), 1);
900 int fComp2 = Gia_ObjFaninC2(p->pGia, pObj);
901 Nf_Cut_t * pCut2, * pCut2Lim = pCuts2 + nCuts2;
902 p->CutCount[0] += nCuts0 * nCuts1 * nCuts2;
903 for ( pCut0 = pCuts0; pCut0 < pCut0Lim; pCut0++ )
904 for ( pCut1 = pCuts1; pCut1 < pCut1Lim; pCut1++ )
905 for ( pCut2 = pCuts2; pCut2 < pCut2Lim; pCut2++ )
906 {
907 if ( Nf_CutCountBits(pCut0->Sign | pCut1->Sign | pCut2->Sign) > nLutSize )
908 continue;
909 p->CutCount[1]++;
910 if ( !Nf_CutMergeOrderMux(pCut0, pCut1, pCut2, pCutsR[nCutsR], nLutSize) )
911 continue;
912 if ( Nf_SetLastCutIsContained(pCutsR, nCutsR) )
913 continue;
914 p->CutCount[2]++;
915 if ( Nf_CutComputeTruthMux6(p, pCut0, pCut1, pCut2, fComp0, fComp1, fComp2, pCutsR[nCutsR]) )
916 pCutsR[nCutsR]->Sign = Nf_CutGetSign(pCutsR[nCutsR]->pLeaves, pCutsR[nCutsR]->nLeaves);
917 Nf_CutParams( p, pCutsR[nCutsR], dFlowRefs );
918 nCutsR = Nf_SetAddCut( pCutsR, nCutsR, nCutNum );
919 }
920 }
921 else
922 {
923 int fIsXor = Gia_ObjIsXor(pObj);
924 p->CutCount[0] += nCuts0 * nCuts1;
925 for ( pCut0 = pCuts0; pCut0 < pCut0Lim; pCut0++ )
926 for ( pCut1 = pCuts1; pCut1 < pCut1Lim; pCut1++ )
927 {
928 if ( (int)(pCut0->nLeaves + pCut1->nLeaves) > nLutSize && Nf_CutCountBits(pCut0->Sign | pCut1->Sign) > nLutSize )
929 continue;
930 p->CutCount[1]++;
931 if ( !Nf_CutMergeOrder(pCut0, pCut1, pCutsR[nCutsR], nLutSize) )
932 continue;
933 if ( Nf_SetLastCutIsContained(pCutsR, nCutsR) )
934 continue;
935 p->CutCount[2]++;
936 if ( Nf_CutComputeTruth6(p, pCut0, pCut1, fComp0, fComp1, pCutsR[nCutsR], fIsXor) )
937 pCutsR[nCutsR]->Sign = Nf_CutGetSign(pCutsR[nCutsR]->pLeaves, pCutsR[nCutsR]->nLeaves);
938 Nf_CutParams( p, pCutsR[nCutsR], dFlowRefs );
939 nCutsR = Nf_SetAddCut( pCutsR, nCutsR, nCutNum );
940 }
941 }
942 // debug printout
943 if ( 0 )
944// if ( iObj % 10000 == 0 )
945// if ( iObj == 1090 )
946 {
947 printf( "*** Obj = %d Useful = %d\n", iObj, Nf_ManCountUseful(pCutsR, nCutsR) );
948 for ( i = 0; i < nCutsR; i++ )
949 Nf_CutPrint( p, pCutsR[i] );
950 printf( "\n" );
951 }
952 // verify
953 assert( nCutsR > 0 && nCutsR < nCutNum );
954// assert( Nf_SetCheckArray(pCutsR, nCutsR) );
955 // store the cutset
956 Nf_ObjSetCutFlow( p, iObj, pCutsR[0]->Flow );
957 Nf_ObjSetCutDelay( p, iObj, pCutsR[0]->Delay );
958 *Vec_IntEntryP(&p->vCutSets, iObj) = Nf_ManSaveCuts(p, pCutsR, nCutsR, 0);
959 p->CutCount[3] += nCutsR;
960 nCutsUse = Nf_ManCountUseful(pCutsR, nCutsR);
961 p->CutCount[4] += nCutsUse;
962 p->nCutUseAll += nCutsUse == nCutsR;
963 p->CutCount[5] += Nf_ManCountMatches(p, pCutsR, nCutsR);
964}
966{
967 Gia_Obj_t * pObj; int i, iFanin, arrTime;
968 float CutFlow = 0, CutFlowAve = 0; int fFirstCi = 0, nCutFlow = 0;
969 if ( p->pManTim )
970 Tim_ManIncrementTravId( p->pManTim );
971 Gia_ManForEachObjWithBoxes( p->pGia, pObj, i )
972 if ( Gia_ObjIsBuf(pObj) )
973 {
974 iFanin = Gia_ObjFaninId0(pObj, i);
975 Nf_ObjSetCutFlow( p, i, Nf_ObjCutFlow(p, iFanin) );
976 Nf_ObjSetCutDelay( p, i, Nf_ObjCutDelay(p, iFanin) );
977 }
978 else if ( Gia_ObjIsAnd(pObj) )
979 Nf_ObjMergeOrder( p, i );
980 else if ( Gia_ObjIsCi(pObj) )
981 {
982 if ( fFirstCi ) {
983 CutFlowAve = CutFlow / nCutFlow;
984 CutFlow = 0;
985 nCutFlow = 0;
986 fFirstCi = 0;
987 }
988 arrTime = Tim_ManGetCiArrival( p->pManTim, Gia_ObjCioId(pObj) );
989 Nf_ObjSetCutFlow( p, i, CutFlowAve ); // approximation!
990 Nf_ObjSetCutDelay( p, i, arrTime );
991 }
992 else if ( Gia_ObjIsCo(pObj) )
993 {
994 iFanin = Gia_ObjFaninId0(pObj, i);
995 CutFlow += Nf_ObjCutFlow(p, iFanin);
996 arrTime = Nf_ObjCutDelay(p, iFanin);
997 Tim_ManSetCoArrival( p->pManTim, Gia_ObjCioId(pObj), arrTime );
998 nCutFlow++;
999 fFirstCi = 1;
1000 }
1001}
1002
1014void Nf_ManPrintStats( Nf_Man_t * p, char * pTitle )
1015{
1016 if ( !p->pPars->fVerbose )
1017 return;
1018 printf( "%s : ", pTitle );
1019 printf( "Delay =%8.2f ", Scl_Int2Flt(p->pPars->MapDelay) );
1020 printf( "Area =%12.2f ", p->pPars->MapAreaF );
1021 printf( "Gate =%6d ", (int)p->pPars->Area );
1022 printf( "Inv =%6d ", (int)p->nInvs );
1023 printf( "Edge =%7d ", (int)p->pPars->Edge );
1024 Abc_PrintTime( 1, "Time", Abc_Clock() - p->clkStart );
1025 fflush( stdout );
1026}
1028{
1029 int nChoices;
1030 if ( !p->pPars->fVerbose )
1031 return;
1032 printf( "LutSize = %d ", p->pPars->nLutSize );
1033 printf( "CutNum = %d ", p->pPars->nCutNum );
1034 printf( "Iter = %d ", p->pPars->nRounds );//+ p->pPars->nRoundsEla );
1035 printf( "Coarse = %d ", p->pPars->fCoarsen );
1036 printf( "Cells = %d ", p->nCells );
1037 printf( "Funcs = %d ", Vec_MemEntryNum(p->vTtMem) );
1038 printf( "Matches = %d ", Vec_WecSizeSize(p->vTt2Match)/2 );
1039 printf( "And = %d ", Gia_ManAndNum(p->pGia) );
1040 nChoices = Gia_ManChoiceNum( p->pGia );
1041 if ( nChoices )
1042 printf( "Choices = %d ", nChoices );
1043 printf( "\n" );
1044 printf( "Computing cuts...\r" );
1045 fflush( stdout );
1046}
1048{
1049 float MemGia = Gia_ManMemory(p->pGia) / (1<<20);
1050 float MemMan =(1.0 * sizeof(Nf_Obj_t) + 8.0 * sizeof(int)) * Gia_ManObjNum(p->pGia) / (1<<20);
1051 float MemCuts = 1.0 * sizeof(int) * (1 << 16) * Vec_PtrSize(&p->vPages) / (1<<20);
1052 float MemTt = p->vTtMem ? Vec_MemMemory(p->vTtMem) / (1<<20) : 0;
1053 if ( p->CutCount[0] == 0 )
1054 p->CutCount[0] = 1;
1055 if ( !p->pPars->fVerbose )
1056 return;
1057 printf( "CutPair = %.0f ", p->CutCount[0] );
1058 printf( "Merge = %.0f (%.1f) ", p->CutCount[1], 1.0*p->CutCount[1]/Gia_ManAndNum(p->pGia) );
1059 printf( "Eval = %.0f (%.1f) ", p->CutCount[2], 1.0*p->CutCount[2]/Gia_ManAndNum(p->pGia) );
1060 printf( "Cut = %.0f (%.1f) ", p->CutCount[3], 1.0*p->CutCount[3]/Gia_ManAndNum(p->pGia) );
1061 printf( "Use = %.0f (%.1f) ", p->CutCount[4], 1.0*p->CutCount[4]/Gia_ManAndNum(p->pGia) );
1062 printf( "Mat = %.0f (%.1f) ", p->CutCount[5], 1.0*p->CutCount[5]/Gia_ManAndNum(p->pGia) );
1063// printf( "Equ = %d (%.2f %%) ", p->nCutUseAll, 100.0*p->nCutUseAll /p->CutCount[0] );
1064 printf( "\n" );
1065 printf( "Gia = %.2f MB ", MemGia );
1066 printf( "Man = %.2f MB ", MemMan );
1067 printf( "Cut = %.2f MB ", MemCuts );
1068 printf( "TT = %.2f MB ", MemTt );
1069 printf( "Total = %.2f MB ", MemGia + MemMan + MemCuts + MemTt );
1070// printf( "\n" );
1071 Abc_PrintTime( 1, "Time", Abc_Clock() - p->clkStart );
1072 fflush( stdout );
1073}
1074
1075
1087void Nf_ManCutMatchPrint( Nf_Man_t * p, int iObj, char * pStr, Nf_Mat_t * pM )
1088{
1089 Mio_Cell2_t * pCell;
1090 int i, * pCut;
1091 printf( "%5d %s : ", iObj, pStr );
1092 if ( pM->CutH == 0 )
1093 {
1094 printf( "Unassigned\n" );
1095 return;
1096 }
1097 pCell = Nf_ManCell( p, pM->Gate );
1098 pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, iObj), pM->CutH );
1099 printf( "D =%6.2f ", Scl_Int2Flt(pM->D) );
1100 printf( "A =%6.2f ", pM->F );
1101 printf( "C = %d ", pM->fCompl );
1102// printf( "B = %d ", pM->fBest );
1103 printf( " " );
1104 printf( "Cut = {" );
1105 for ( i = 0; i < (int)pCell->nFanins; i++ )
1106 printf( "%4d ", Nf_CutLeaves(pCut)[i] );
1107 for ( ; i < 6; i++ )
1108 printf( " " );
1109 printf( "} " );
1110 printf( "%10s ", pCell->pName );
1111 printf( "%d ", pCell->nFanins );
1112 printf( "{" );
1113 for ( i = 0; i < (int)pCell->nFanins; i++ )
1114 printf( "%6.2f ", Scl_Int2Flt(pCell->iDelays[i]) );
1115 for ( ; i < 6; i++ )
1116 printf( " " );
1117 printf( " } " );
1118 for ( i = 0; i < (int)pCell->nFanins; i++ )
1119 printf( "%s%d ", Nf_CfgCompl(pM->Cfg, i) ? "!":" ", Nf_CfgVar(pM->Cfg, i) );
1120 for ( ; i < 6; i++ )
1121 printf( " " );
1122 Dau_DsdPrintFromTruth( &pCell->uTruth, pCell->nFanins );
1123}
1124void Nf_ManCutMatchOne( Nf_Man_t * p, int iObj, int * pCut, int * pCutSet )
1125{
1126 Nf_Obj_t * pBest = Nf_ManObj(p, iObj);
1127 int * pFans = Nf_CutLeaves(pCut);
1128 int nFans = Nf_CutSize(pCut);
1129 int iFuncLit = Nf_CutFunc(pCut);
1130 int fComplExt = Abc_LitIsCompl(iFuncLit);
1131 Vec_Int_t * vArr = Vec_WecEntry( p->vTt2Match, Abc_Lit2Var(iFuncLit) );
1132 int i, k, c, Info, Offset, iFanin, fComplF;
1133 int ArrivalD, ArrivalA;
1134 Nf_Mat_t * pD, * pA;
1135 // assign fanins matches
1136 Nf_Obj_t * pBestF[NF_LEAF_MAX];
1137 for ( i = 0; i < nFans; i++ )
1138 pBestF[i] = Nf_ManObj( p, pFans[i] );
1139 // special cases
1140 if ( nFans == 0 )
1141 {
1142 int Const = (iFuncLit == 1);
1143 assert( iFuncLit == 0 || iFuncLit == 1 );
1144 for ( c = 0; c < 2; c++ )
1145 {
1146 pD = Nf_ObjMatchD( p, iObj, c );
1147 pA = Nf_ObjMatchA( p, iObj, c );
1148 pD->D = pA->D = 0;
1149 pD->F = pA->F = p->pCells[c ^ Const].AreaF;
1150 pD->CutH = pA->CutH = Nf_CutHandle(pCutSet, pCut);
1151 pD->Gate = pA->Gate = c ^ Const;
1152// pD->Conf = pA->Conf = 0;
1153 pD->Cfg = pA->Cfg = Nf_Int2Cfg(0);
1154 }
1155 return;
1156 }
1157 // consider matches of this function
1158 Vec_IntForEachEntryDouble( vArr, Info, Offset, i )
1159 {
1160 Nf_Cfg_t Cfg = Nf_Int2Cfg(Offset);
1161 Mio_Cell2_t*pC = Nf_ManCell( p, Info );
1162 int fCompl = Cfg.fCompl ^ fComplExt;
1163 int Required = Nf_ObjRequired( p, iObj, fCompl ), Delay = 0;
1164 Nf_Mat_t * pD = &pBest->M[fCompl][0];
1165 Nf_Mat_t * pA = &pBest->M[fCompl][1];
1166 float AreaF = pC->AreaF;
1167 assert( nFans == (int)pC->nFanins );
1168 Nf_CfgForEachVarCompl( Cfg, nFans, iFanin, fComplF, k )
1169 {
1170 ArrivalD = pBestF[iFanin]->M[fComplF][0].D;
1171 ArrivalA = pBestF[iFanin]->M[fComplF][1].D;
1172 if ( ArrivalA + pC->iDelays[k] <= Required && Required != SCL_INFINITY )
1173 {
1174 Delay = Abc_MaxInt( Delay, ArrivalA + pC->iDelays[k] );
1175 if ( AreaF >= (float)1e32 || pBestF[iFanin]->M[fComplF][1].F >= (float)1e32 )
1176 AreaF = (float)1e32;
1177 else
1178 AreaF += pBestF[iFanin]->M[fComplF][1].F;
1179 }
1180 else
1181 {
1182 if ( pD->D < SCL_INFINITY && pA->D < SCL_INFINITY && ArrivalD + pC->iDelays[k] > Required )
1183 break;
1184 Delay = Abc_MaxInt( Delay, ArrivalD + pC->iDelays[k] );
1185 //AreaF += pBestF[iFanin]->M[fComplF][0].F;
1186 if ( AreaF >= (float)1e32 || pBestF[iFanin]->M[fComplF][0].F >= (float)1e32 )
1187 AreaF = (float)1e32;
1188 else
1189 AreaF += pBestF[iFanin]->M[fComplF][0].F;
1190 }
1191 }
1192 if ( k < nFans )
1193 continue;
1194 // select best Cfgch
1195 if ( pD->D > Delay )
1196 {
1197 pD->D = Delay;
1198 pD->F = AreaF;
1199 pD->CutH = Nf_CutHandle(pCutSet, pCut);
1200 pD->Gate = pC->Id;
1201 pD->Cfg = Cfg;
1202 pD->Cfg.fCompl = 0;
1203 }
1204
1205 if ( pA->F > AreaF + NF_EPSILON )
1206 {
1207 pA->D = Delay;
1208 pA->F = AreaF;
1209 pA->CutH = Nf_CutHandle(pCutSet, pCut);
1210 pA->Gate = pC->Id;
1211 pA->Cfg = Cfg;
1212 pA->Cfg.fCompl = 0;
1213 }
1214 }
1215}
1216static inline void Nf_ObjPrepareCi( Nf_Man_t * p, int iObj, int Time )
1217{
1218 Nf_Mat_t * pD0 = Nf_ObjMatchD( p, iObj, 0 );
1219 Nf_Mat_t * pA0 = Nf_ObjMatchA( p, iObj, 0 );
1220 Nf_Mat_t * pD = Nf_ObjMatchD( p, iObj, 1 );
1221 Nf_Mat_t * pA = Nf_ObjMatchA( p, iObj, 1 );
1222 pD0->D = pA0->D = pD->D = pA->D = Time;
1223 pD->fCompl = 1;
1224 pD->D += p->InvDelayI;
1225 pD->F = p->InvAreaF;
1226 pA->fCompl = 1;
1227 pA->D += p->InvDelayI;
1228 pA->F = p->InvAreaF;
1229 Nf_ObjMatchD( p, iObj, 0 )->fBest = 1;
1230 Nf_ObjMatchD( p, iObj, 1 )->fBest = 1;
1231}
1232static inline void Nf_ObjPrepareBuf( Nf_Man_t * p, Gia_Obj_t * pObj )
1233{
1234 // get fanin info
1235 int iObj = Gia_ObjId( p->pGia, pObj );
1236 int iFanin = Gia_ObjFaninId0( pObj, iObj );
1237 Nf_Mat_t * pDf = Nf_ObjMatchD( p, iFanin, Gia_ObjFaninC0(pObj) );
1238 //Nf_Mat_t * pAf = Nf_ObjMatchA( p, iFanin, Gia_ObjFaninC0(pObj) );
1239 // set the direct phase
1240 Nf_Mat_t * pDp = Nf_ObjMatchD( p, iObj, 0 );
1241 Nf_Mat_t * pAp = Nf_ObjMatchA( p, iObj, 0 );
1242 Nf_Mat_t * pDn = Nf_ObjMatchD( p, iObj, 1 );
1243 Nf_Mat_t * pAn = Nf_ObjMatchA( p, iObj, 1 );
1244 assert( Gia_ObjIsBuf(pObj) );
1245 memset( Nf_ManObj(p, iObj), 0, sizeof(Nf_Obj_t) );
1246 // set the direct phase
1247 pDp->D = pAp->D = pDf->D;
1248 pDp->F = pAp->F = pDf->F; // do not pass flow???
1249 pDp->fBest = 1;
1250 // set the inverted phase
1251 pDn->D = pAn->D = pDf->D + p->InvDelayI;
1252 pDn->F = pAn->F = pDf->F + p->InvAreaF;
1253 pDn->fCompl = pAn->fCompl = 1;
1254 pDn->fBest = 1;
1255}
1256static inline int Nf_CutRequired( Nf_Man_t * p, Nf_Mat_t * pM, int * pCutSet )
1257{
1258 Mio_Cell2_t * pCell = Nf_ManCell( p, pM->Gate );
1259 int * pCut = Nf_CutFromHandle( pCutSet, pM->CutH );
1260 int i, iVar, fCompl;
1261 int Arr, Req, Arrival = 0, Required = 0;
1262 Nf_CutForEachVarCompl( pCut, pM->Cfg, iVar, fCompl, i )
1263 {
1264 Arr = Nf_ManObj(p, iVar)->M[fCompl][0].D + pCell->iDelays[i];
1265 Req = Nf_ObjRequired(p, iVar, fCompl);
1266 Arrival = Abc_MaxInt( Arrival, Arr );
1267 if ( Req < SCL_INFINITY )
1268 Required = Abc_MaxInt( Required, Req + pCell->iDelays[i] );
1269 }
1270 return Abc_MaxInt( Required + p->pPars->nReqTimeFlex*p->InvDelayI, Arrival );
1271}
1272static inline void Nf_ObjComputeRequired( Nf_Man_t * p, int iObj )
1273{
1274 Nf_Obj_t * pBest = Nf_ManObj(p, iObj);
1275 int c, * pCutSet = Nf_ObjCutSet( p, iObj );
1276 for ( c = 0; c < 2; c++ )
1277 if ( Nf_ObjRequired(p, iObj, c) == SCL_INFINITY )
1278 Nf_ObjSetRequired( p, iObj, c, Nf_CutRequired(p, &pBest->M[c][0], pCutSet) );
1279}
1280void Nf_ManCutMatch( Nf_Man_t * p, int iObj )
1281{
1282 Nf_Obj_t * pBest = Nf_ManObj(p, iObj);
1283 Nf_Mat_t * pDp = &pBest->M[0][0];
1284 Nf_Mat_t * pDn = &pBest->M[1][0];
1285 Nf_Mat_t * pAp = &pBest->M[0][1];
1286 Nf_Mat_t * pAn = &pBest->M[1][1];
1287 float FlowRefPf = Nf_ObjFlowRefs(p, iObj, 0);
1288 float FlowRefNf = Nf_ObjFlowRefs(p, iObj, 1);
1289 int i, * pCut, * pCutSet = Nf_ObjCutSet( p, iObj );
1290 int Required[2] = {0};
1291 if ( p->Iter )
1292 {
1293 Nf_ObjComputeRequired( p, iObj );
1294 Required[0] = Nf_ObjRequired( p, iObj, 0 );
1295 Required[1] = Nf_ObjRequired( p, iObj, 1 );
1296 }
1297 memset( pBest, 0, sizeof(Nf_Obj_t) );
1298 pDp->D = SCL_INFINITY; pDp->F = FLT_MAX;
1299 pDn->D = SCL_INFINITY; pDn->F = FLT_MAX;
1300 pAp->D = SCL_INFINITY; pAp->F = FLT_MAX;
1301 pAn->D = SCL_INFINITY; pAn->F = FLT_MAX;
1302 Nf_SetForEachCut( pCutSet, pCut, i )
1303 {
1304 if ( Abc_Lit2Var(Nf_CutFunc(pCut)) >= Vec_WecSize(p->vTt2Match) )
1305 continue;
1306 assert( !Nf_CutIsTriv(pCut, iObj) );
1307 assert( Nf_CutSize(pCut) <= p->pPars->nLutSize );
1308 assert( Abc_Lit2Var(Nf_CutFunc(pCut)) < Vec_WecSize(p->vTt2Match) );
1309 Nf_ManCutMatchOne( p, iObj, pCut, pCutSet );
1310 }
1311
1312/*
1313 if ( 461 == iObj && p->Iter == 0 )
1314 {
1315 printf( "\nObj %6d (%.2f %.2f):\n", iObj, Scl_Int2Flt(Required[0]), Scl_Int2Flt(Required[1]) );
1316 Nf_ManCutMatchPrint( p, iObj, "Dp", &pBest->M[0][0] );
1317 Nf_ManCutMatchPrint( p, iObj, "Dn", &pBest->M[1][0] );
1318 Nf_ManCutMatchPrint( p, iObj, "Ap", &pBest->M[0][1] );
1319 Nf_ManCutMatchPrint( p, iObj, "An", &pBest->M[1][1] );
1320 printf( "\n" );
1321 }
1322*/
1323 // divide by ref count
1324 pDp->F = pDp->F / FlowRefPf;
1325 pAp->F = pAp->F / FlowRefPf;
1326 pDn->F = pDn->F / FlowRefNf;
1327 pAn->F = pAn->F / FlowRefNf;
1328
1329 // add the inverters
1330 assert( pDp->D < SCL_INFINITY || pDn->D < SCL_INFINITY );
1331 if ( pDp->D > pDn->D + p->InvDelayI )
1332 {
1333 *pDp = *pDn;
1334 pDp->D += p->InvDelayI;
1335 pDp->F += p->InvAreaF;
1336 pDp->fCompl = 1;
1337 if ( pAp->D == SCL_INFINITY )
1338 *pAp = *pDp;
1339 //printf( "Using inverter to improve delay at node %d in phase %d.\n", iObj, 1 );
1340 }
1341 else if ( pDn->D > pDp->D + p->InvDelayI )
1342 {
1343 *pDn = *pDp;
1344 pDn->D += p->InvDelayI;
1345 pDn->F += p->InvAreaF;
1346 pDn->fCompl = 1;
1347 if ( pAn->D == SCL_INFINITY )
1348 *pAn = *pDn;
1349 //printf( "Using inverter to improve delay at node %d in phase %d.\n", iObj, 0 );
1350 }
1351 //assert( pAp->F < FLT_MAX || pAn->F < FLT_MAX );
1352 // try replacing pos with neg
1353 if ( pAp->D == SCL_INFINITY || (pAp->F > pAn->F + p->InvAreaF + NF_EPSILON && pAn->D + p->InvDelayI <= Required[0]) )
1354 {
1355 assert( p->Iter > 0 );
1356 *pAp = *pAn;
1357 pAp->D += p->InvDelayI;
1358 pAp->F += p->InvAreaF;
1359 pAp->fCompl = 1;
1360 if ( pDp->D == SCL_INFINITY )
1361 *pDp = *pAp;
1362 //printf( "Using inverter to improve area at node %d in phase %d.\n", iObj, 1 );
1363 }
1364 // try replacing neg with pos
1365 else if ( pAn->D == SCL_INFINITY || (pAn->F > pAp->F + p->InvAreaF + NF_EPSILON && pAp->D + p->InvDelayI <= Required[1]) )
1366 {
1367 assert( p->Iter > 0 );
1368 *pAn = *pAp;
1369 pAn->D += p->InvDelayI;
1370 pAn->F += p->InvAreaF;
1371 pAn->fCompl = 1;
1372 if ( pDn->D == SCL_INFINITY )
1373 *pDn = *pAn;
1374 //printf( "Using inverter to improve area at node %d in phase %d.\n", iObj, 0 );
1375 }
1376
1377 if ( pDp->D == SCL_INFINITY )
1378 printf( "Object %d has pDp unassigned.\n", iObj );
1379 if ( pDn->D == SCL_INFINITY )
1380 printf( "Object %d has pDn unassigned.\n", iObj );
1381 if ( pAp->D == SCL_INFINITY )
1382 printf( "Object %d has pAp unassigned.\n", iObj );
1383 if ( pAn->D == SCL_INFINITY )
1384 printf( "Object %d has pAn unassigned.\n", iObj );
1385/*
1386 pDp->F = Abc_MinFloat( pDp->F, FLT_MAX/SCL_NUM );
1387 pDn->F = Abc_MinFloat( pDn->F, FLT_MAX/SCL_NUM );
1388 pAp->F = Abc_MinFloat( pAp->F, FLT_MAX/SCL_NUM );
1389 pAn->F = Abc_MinFloat( pAn->F, FLT_MAX/SCL_NUM );
1390*/
1391 assert( pDp->D < SCL_INFINITY );
1392 assert( pDn->D < SCL_INFINITY );
1393 assert( pAp->D < SCL_INFINITY );
1394 assert( pAn->D < SCL_INFINITY );
1395
1396 assert( pDp->F < FLT_MAX );
1397 assert( pDn->F < FLT_MAX );
1398 assert( pAp->F < FLT_MAX );
1399 assert( pAn->F < FLT_MAX );
1400
1401/*
1402 if ( p->Iter && (pDp->D > Required[0] || pDn->D > Required[1]) )
1403 {
1404 printf( "%5d : ", iObj );
1405 printf( "Dp = %6.2f ", Scl_Int2Flt(pDp->D) );
1406 printf( "Dn = %6.2f ", Scl_Int2Flt(pDn->D) );
1407 printf( " " );
1408 printf( "Ap = %6.2f ", Scl_Int2Flt(pAp->D) );
1409 printf( "An = %6.2f ", Scl_Int2Flt(pAn->D) );
1410 printf( " " );
1411 printf( "Rp = %6.2f ", Scl_Int2Flt(Required[0]) );
1412 printf( "Rn = %6.2f ", Scl_Int2Flt(Required[1]) );
1413 printf( "\n" );
1414 }
1415*/
1416}
1417static inline Nf_Mat_t * Nf_ObjMatchBest( Nf_Man_t * p, int i, int c )
1418{
1419 Nf_Mat_t * pD = Nf_ObjMatchD(p, i, c);
1420 Nf_Mat_t * pA = Nf_ObjMatchA(p, i, c);
1421 assert( pD->fBest != pA->fBest );
1422 //assert( Nf_ObjMapRefNum(p, i, c) > 0 );
1423 if ( pA->fBest )
1424 return pA;
1425 if ( pD->fBest )
1426 return pD;
1427 return NULL;
1428}
1430{
1431 Gia_Obj_t * pObj; int i, arrTime;
1432 if ( p->pManTim )
1433 Tim_ManIncrementTravId( p->pManTim );
1434 Gia_ManForEachObjWithBoxes( p->pGia, pObj, i )
1435 if ( Gia_ObjIsBuf(pObj) )
1436 Nf_ObjPrepareBuf( p, pObj );
1437 else if ( Gia_ObjIsAnd(pObj) )
1438 Nf_ManCutMatch( p, i );
1439 else if ( Gia_ObjIsCi(pObj) ) {
1440 arrTime = Tim_ManGetCiArrival( p->pManTim, Gia_ObjCioId(pObj) );
1441 Nf_ObjPrepareCi( p, i, arrTime );
1442 }
1443 else if ( Gia_ObjIsCo(pObj) ) {
1444 arrTime = Nf_ObjMatchD( p, Gia_ObjFaninId0(pObj, i), Gia_ObjFaninC0(pObj) )->D;
1445 Tim_ManSetCoArrival( p->pManTim, Gia_ObjCioId(pObj), arrTime );
1446 }
1447}
1448
1449
1461void Nf_ManSetOutputRequireds( Nf_Man_t * p, int fPropCompl )
1462{
1463 Gia_Obj_t * pObj;
1464 int Required = 0, MapDelayOld = p->pPars->MapDelay;
1465 int fUseConMan = Scl_ConIsRunning() && Scl_ConHasOutReqs();
1466 int i, iObj, fCompl, nLits = 2*Gia_ManObjNum(p->pGia);
1467 Vec_IntFill( &p->vRequired, nLits, SCL_INFINITY );
1468 // compute delay
1469 p->pPars->MapDelay = 0;
1470 Gia_ManForEachCoWithBoxes( p->pGia, pObj, i )
1471 {
1472 Required = Nf_ObjMatchD( p, Gia_ObjFaninId0p(p->pGia, pObj), Gia_ObjFaninC0(pObj) )->D;
1473 p->pPars->MapDelay = Abc_MaxInt( p->pPars->MapDelay, Required );
1474 }
1475 if ( p->Iter && MapDelayOld < p->pPars->MapDelay && p->pGia->vOutReqs == NULL )
1476 printf( "******** Critical delay violation %.2f -> %.2f ********\n", Scl_Int2Flt(MapDelayOld), Scl_Int2Flt(p->pPars->MapDelay) );
1477 p->pPars->MapDelay = Abc_MaxInt( p->pPars->MapDelay, MapDelayOld );
1478 // check delay target
1479 if ( p->pPars->MapDelayTarget == 0 && p->pPars->nRelaxRatio )
1480 p->pPars->MapDelayTarget = p->pPars->MapDelay * (100 + p->pPars->nRelaxRatio) / 100;
1481 if ( p->pPars->MapDelayTarget > 0 )
1482 {
1483 if ( p->pPars->MapDelay < p->pPars->MapDelayTarget )
1484 p->pPars->MapDelay = p->pPars->MapDelayTarget;
1485 else if ( p->pPars->nRelaxRatio == 0 )
1486 Abc_Print( 0, "Relaxing user-specified delay target from %.2f to %.2f.\n", Scl_Int2Flt(p->pPars->MapDelayTarget), Scl_Int2Flt(p->pPars->MapDelay) );
1487 }
1488 //assert( p->pPars->MapDelayTarget == 0 );
1489 // set required times
1490 if ( p->pManTim )
1491 Tim_ManIncrementTravId( p->pManTim );
1492 Gia_ManForEachCoWithBoxes( p->pGia, pObj, i )
1493 {
1494 iObj = Gia_ObjFaninId0p(p->pGia, pObj);
1495 fCompl = Gia_ObjFaninC0(pObj);
1496 Required = Nf_ObjMatchD(p, iObj, fCompl)->D;
1497 Required = p->pPars->fDoAverage ? Required * (100 + p->pPars->nRelaxRatio) / 100 : p->pPars->MapDelay;
1498 // if external required time can be achieved, use it
1499 if ( fUseConMan )
1500 {
1501 if ( Scl_ConGetOutReq(i) > 0 && Required <= Scl_ConGetOutReq(i) )
1502 Required = Scl_ConGetOutReq(i);
1503 }
1504 else if ( p->pGia->vOutReqs )
1505 {
1506 int NewRequired = Scl_Flt2Int(Vec_FltEntry(p->pGia->vOutReqs, i));
1507 if ( NewRequired > 0 && Required <= NewRequired )
1508 Required = Abc_MinInt( 2*Required, NewRequired );
1509 }
1510 // if external required cannot be achieved, set the earliest possible arrival time
1511// else if ( p->pGia->vOutReqs && Vec_FltEntry(p->pGia->vOutReqs, i) > 0 && Required > Vec_FltEntry(p->pGia->vOutReqs, i) )
1512// ptTime->Rise = ptTime->Fall = ptTime->Worst = Required;
1513 // otherwise, set the global required time
1514 Nf_ObjUpdateRequired( p, iObj, fCompl, Required );
1515 if ( fPropCompl && iObj > 0 && Nf_ObjMatchBest(p, iObj, fCompl)->fCompl )
1516 Nf_ObjUpdateRequired( p, iObj, !fCompl, Required - p->InvDelayI );
1517
1518 if ( p->pManTim == NULL )
1519 continue;
1520 if ( fPropCompl && iObj > 0 && Nf_ObjMatchBest(p, iObj, fCompl)->fCompl )
1521 Tim_ManSetCoRequired( p->pManTim, Gia_ObjCioId(pObj), Required - p->InvDelayI );
1522 else
1523 Tim_ManSetCoRequired( p->pManTim, Gia_ObjCioId(pObj), Required );
1524 //Nf_ObjMapRefInc( p, Gia_ObjFaninId0p(p->pGia, pObj), Gia_ObjFaninC0(pObj));
1525 }
1526}
1527void Nf_ManSetMapRefsGate( Nf_Man_t * p, int iObj, int Required, Nf_Mat_t * pM )
1528{
1529 int k, iVar, fCompl;
1530 Mio_Cell2_t * pCell = Nf_ManCell( p, pM->Gate );
1531 int * pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, iObj), pM->CutH );
1532 Nf_CutForEachVarCompl( pCut, pM->Cfg, iVar, fCompl, k )
1533 {
1534 Nf_ObjMapRefInc( p, iVar, fCompl );
1535 Nf_ObjUpdateRequired( p, iVar, fCompl, Required - pCell->iDelays[k] );
1536 }
1537 assert( Nf_CutSize(pCut) == (int)pCell->nFanins );
1538 // update global stats
1539 p->pPars->MapAreaF += pCell->AreaF;
1540 p->pPars->Edge += Nf_CutSize(pCut);
1541 p->pPars->Area++;
1542 // update status of the gate
1543 assert( pM->fBest == 0 );
1544 pM->fBest = 1;
1545}
1547{
1548 Gia_Obj_t * pObj; int i;
1549 Gia_ManForEachAnd( p->pGia, pObj, i )
1550 {
1551 Nf_Mat_t * pDp = Nf_ObjMatchD( p, i, 0 );
1552 Nf_Mat_t * pAp = Nf_ObjMatchA( p, i, 0 );
1553 Nf_Mat_t * pDn = Nf_ObjMatchD( p, i, 1 );
1554 Nf_Mat_t * pAn = Nf_ObjMatchA( p, i, 1 );
1555
1556 printf( "%5d : ", i );
1557 printf( "Dp = %6.2f ", Scl_Int2Flt(pDp->D) );
1558 printf( "Dn = %6.2f ", Scl_Int2Flt(pDn->D) );
1559 printf( " " );
1560 printf( "Ap = %6.2f ", Scl_Int2Flt(pAp->D) );
1561 printf( "An = %6.2f ", Scl_Int2Flt(pAn->D) );
1562 printf( " " );
1563 printf( "Dp = %8s ", Nf_ManCell(p, pDp->Gate)->pName );
1564 printf( "Dn = %8s ", Nf_ManCell(p, pDn->Gate)->pName );
1565 printf( "Ap = %8s ", Nf_ManCell(p, pAp->Gate)->pName );
1566 printf( "An = %8s ", Nf_ManCell(p, pAn->Gate)->pName );
1567 printf( "\n" );
1568
1569 }
1570}
1572{
1573 float Coef = 1.0 / (1.0 + (p->Iter + 1) * (p->Iter + 1));
1574 float * pFlowRefs = Vec_FltArray( &p->vFlowRefs );
1575 int * pMapRefs = Vec_IntArray( &p->vMapRefs );
1576 int nLits = 2*Gia_ManObjNum(p->pGia);
1577 int i, c, Id, nRefs[2], reqTime;
1578 Gia_Obj_t * pObj;
1579 Nf_Mat_t * pD, * pA, * pM;
1580 Nf_Mat_t * pDs[2], * pAs[2], * pMs[2];
1581 int Required = 0, Requireds[2];
1582 assert( !p->fUseEla );
1583// if ( p->Iter == 0 )
1584// Nf_ManPrintMatches( p );
1586 // set output references
1587 memset( pMapRefs, 0, sizeof(int) * nLits );
1588 Gia_ManForEachCo( p->pGia, pObj, i )
1589 Nf_ObjMapRefInc( p, Gia_ObjFaninId0p(p->pGia, pObj), Gia_ObjFaninC0(pObj));
1590
1591 // compute area and edges
1592 p->nInvs = 0;
1593 p->pPars->MapAreaF = 0;
1594 p->pPars->Area = p->pPars->Edge = 0;
1595 Gia_ManForEachObjReverseWithBoxes( p->pGia, pObj, i )
1596 {
1597 if ( Gia_ObjIsBuf(pObj) )
1598 {
1599 if ( Nf_ObjMapRefNum(p, i, 1) )
1600 {
1601 Nf_ObjMapRefInc( p, i, 0 );
1602 Nf_ObjUpdateRequired( p, i, 0, Nf_ObjRequired(p, i, 1) - p->InvDelayI );
1603 p->pPars->MapAreaF += p->InvAreaF;
1604 p->pPars->Edge++;
1605 p->pPars->Area++;
1606 p->nInvs++;
1607 }
1608 Nf_ObjUpdateRequired( p, Gia_ObjFaninId0(pObj, i), Gia_ObjFaninC0(pObj), Nf_ObjRequired(p, i, 0) );
1609 Nf_ObjMapRefInc( p, Gia_ObjFaninId0(pObj, i), Gia_ObjFaninC0(pObj));
1610 continue;
1611 }
1612 if ( Gia_ObjIsCi(pObj) )
1613 {
1614 if ( Nf_ObjMapRefNum(p, i, 1) )
1615 {
1616 Nf_ObjMapRefInc( p, i, 0 );
1617 Nf_ObjUpdateRequired( p, i, 0, Nf_ObjRequired(p, i, 1) - p->InvDelayI );
1618 p->pPars->MapAreaF += p->InvAreaF;
1619 p->pPars->Edge++;
1620 p->pPars->Area++;
1621 p->nInvs++;
1622 }
1623 Tim_ManSetCiRequired( p->pManTim, Gia_ObjCioId(pObj), Nf_ObjRequired(p, i, 0) );
1624 continue;
1625 }
1626 if ( Gia_ObjIsCo(pObj) )
1627 {
1628 reqTime = Tim_ManGetCoRequired( p->pManTim, Gia_ObjCioId(pObj) );
1629 Nf_ObjUpdateRequired( p, Gia_ObjFaninId0(pObj, i), Gia_ObjFaninC0(pObj), reqTime );
1630 Nf_ObjMapRefInc( p, Gia_ObjFaninId0(pObj, i), Gia_ObjFaninC0(pObj));
1631 continue;
1632 }
1633 // skip if this node is not used
1634 for ( c = 0; c < 2; c++ )
1635 nRefs[c] = Nf_ObjMapRefNum(p, i, c);
1636 if ( !nRefs[0] && !nRefs[1] )
1637 continue;
1638
1639 // consider two cases
1640 if ( nRefs[0] && nRefs[1] )
1641 {
1642 // find best matches for both phases
1643 for ( c = 0; c < 2; c++ )
1644 {
1645 Requireds[c] = Nf_ObjRequired( p, i, c );
1646 //assert( Requireds[c] < SCL_INFINITY );
1647 pDs[c] = Nf_ObjMatchD( p, i, c );
1648 pAs[c] = Nf_ObjMatchA( p, i, c );
1649 pMs[c] = (pAs[c]->D <= Requireds[c]) ? pAs[c] : pDs[c];
1650 }
1651 // swap complemented matches
1652 if ( pMs[0]->fCompl && pMs[1]->fCompl )
1653 {
1654// pMs[0]->fCompl = pMs[1]->fCompl = 0;
1655// ABC_SWAP( Nf_Mat_t *, pMs[0], pMs[1] );
1656 // find best matches for both phases
1657 pMs[0] = Nf_ObjMatchD( p, i, 0 );
1658 pMs[1] = Nf_ObjMatchD( p, i, 1 );
1659 assert( !pMs[0]->fCompl || !pMs[1]->fCompl );
1660 }
1661 // check if intervers are involved
1662 if ( !pMs[0]->fCompl && !pMs[1]->fCompl ) // no inverters
1663 {
1664 for ( c = 0; c < 2; c++ )
1665 Nf_ManSetMapRefsGate( p, i, Requireds[c], pMs[c] );
1666 }
1667 else
1668 {
1669 // one interver
1670 assert( !pMs[0]->fCompl || !pMs[1]->fCompl );
1671 c = pMs[1]->fCompl;
1672 assert( pMs[c]->fCompl && !pMs[!c]->fCompl );
1673 //printf( "Using inverter at node %d in phase %d\n", i, c );
1674 // update this phase
1675 pM = pMs[c];
1676 pM->fBest = 1;
1677 Required = Requireds[c];
1678 // update opposite phase
1679 Nf_ObjMapRefInc( p, i, !c );
1680 Nf_ObjUpdateRequired( p, i, !c, Required - p->InvDelayI );
1681 // select opposite phase
1682 Required = Nf_ObjRequired( p, i, !c );
1683 //assert( Required < SCL_INFINITY );
1684 pD = Nf_ObjMatchD( p, i, !c );
1685 pA = Nf_ObjMatchA( p, i, !c );
1686 pM = (pA->D <= Required) ? pA : pD;
1687 assert( !pM->fCompl );
1688 // create gate
1689 Nf_ManSetMapRefsGate( p, i, Required, pM );
1690 // account for the inverter
1691 p->pPars->MapAreaF += p->InvAreaF;
1692 p->pPars->Edge++;
1693 p->pPars->Area++;
1694 p->nInvs++;
1695 }
1696 }
1697 else
1698 {
1699 c = (int)(nRefs[1] > 0);
1700 assert( nRefs[c] && !nRefs[!c] );
1701 // consider this phase
1702 Required = Nf_ObjRequired( p, i, c );
1703 //assert( Required < SCL_INFINITY );
1704 pD = Nf_ObjMatchD( p, i, c );
1705 pA = Nf_ObjMatchA( p, i, c );
1706 pM = (pA->D <= Required) ? pA : pD;
1707 if ( pM->fCompl ) // use inverter
1708 {
1709 p->nInvs++;
1710 //printf( "Using inverter at node %d in phase %d\n", i, c );
1711 pM->fBest = 1;
1712 // update opposite phase
1713 Nf_ObjMapRefInc( p, i, !c );
1714 Nf_ObjUpdateRequired( p, i, !c, Required - p->InvDelayI );
1715 // select opposite phase
1716 Required = Nf_ObjRequired( p, i, !c );
1717 //assert( Required < SCL_INFINITY );
1718 pD = Nf_ObjMatchD( p, i, !c );
1719 pA = Nf_ObjMatchA( p, i, !c );
1720 pM = (pA->D <= Required) ? pA : pD;
1721 assert( !pM->fCompl );
1722 // account for the inverter
1723 p->pPars->MapAreaF += p->InvAreaF;
1724 p->pPars->Edge++;
1725 p->pPars->Area++;
1726 }
1727 // create gate
1728 Nf_ManSetMapRefsGate( p, i, Required, pM );
1729 }
1730 // the result of this:
1731 // - only one phase can be implemented as inverter of the other phase
1732 // - required times are propagated correctly
1733 // - references are set correctly
1734 }
1735 Gia_ManForEachCiIdWithBoxes( p->pGia, Id, i )
1736 if ( Nf_ObjMapRefNum(p, Id, 1) )
1737 {
1738 Nf_ObjMapRefInc( p, Id, 0 );
1739 Nf_ObjUpdateRequired( p, Id, 0, Required - p->InvDelayI );
1740 p->pPars->MapAreaF += p->InvAreaF;
1741 p->pPars->Edge++;
1742 p->pPars->Area++;
1743 p->nInvs++;
1744 }
1745 // blend references
1746 for ( i = 0; i < nLits; i++ )
1747 pFlowRefs[i] = Abc_MaxFloat(1.0, Coef * pFlowRefs[i] + (1.0 - Coef) * Abc_MaxFloat(1, pMapRefs[i]));
1748// pFlowRefs[i] = 0.2 * pFlowRefs[i] + 0.8 * Abc_MaxFloat(1, pMapRefs[i]);
1749 return p->pPars->Area;
1750}
1751
1752
1753
1765word Nf_MatchDeref_rec( Nf_Man_t * p, int i, int c, Nf_Mat_t * pM )
1766{
1767 word Area = 0;
1768 int k, iVar, fCompl, * pCut;
1769 assert( pM->fBest );
1770 if ( pM->fCompl )
1771 {
1772 assert( Nf_ObjMapRefNum(p, i, !c) > 0 );
1773 if ( !Nf_ObjMapRefDec(p, i, !c) )
1774 Area += Nf_MatchDeref_rec( p, i, !c, Nf_ObjMatchD(p, i, !c) );
1775 return Area + p->InvAreaW;
1776 }
1777 if ( Nf_ObjCutSetId(p, i) == 0 )
1778 return 0;
1779 pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, i), pM->CutH );
1780 Nf_CutForEachVarCompl( pCut, pM->Cfg, iVar, fCompl, k )
1781 {
1782 assert( Nf_ObjMapRefNum(p, iVar, fCompl) > 0 );
1783 if ( !Nf_ObjMapRefDec(p, iVar, fCompl) )
1784 Area += Nf_MatchDeref_rec( p, iVar, fCompl, Nf_ObjMatchD(p, iVar, fCompl) );
1785 }
1786 return Area + Nf_ManCell(p, pM->Gate)->AreaW;
1787}
1788word Nf_MatchRef_rec( Nf_Man_t * p, int i, int c, Nf_Mat_t * pM, int Required, Vec_Int_t * vBackup )
1789{
1790 word Area = 0;
1791 int ReqFanin;
1792 int k, iVar, fCompl, * pCut;
1793 assert( pM->fBest );
1794 assert( pM->D <= Required );
1795 if ( pM->fCompl )
1796 {
1797 ReqFanin = Required - p->InvDelayI;
1798 if ( vBackup )
1799 Vec_IntPush( vBackup, Abc_Var2Lit(i, !c) );
1800 assert( Nf_ObjMapRefNum(p, i, !c) >= 0 );
1801 if ( !Nf_ObjMapRefInc(p, i, !c) )
1802 Area += Nf_MatchRef_rec( p, i, !c, Nf_ObjMatchD(p, i, !c), ReqFanin, vBackup );
1803 return Area + p->InvAreaW;
1804 }
1805 if ( Nf_ObjCutSetId(p, i) == 0 )
1806 return 0;
1807 pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, i), pM->CutH );
1808 Nf_CutForEachVarCompl( pCut, pM->Cfg, iVar, fCompl, k )
1809 {
1810 ReqFanin = Required - Nf_ManCell(p, pM->Gate)->iDelays[k];
1811 if ( vBackup )
1812 Vec_IntPush( vBackup, Abc_Var2Lit(iVar, fCompl) );
1813 assert( Nf_ObjMapRefNum(p, iVar, fCompl) >= 0 );
1814 if ( !Nf_ObjMapRefInc(p, iVar, fCompl) )
1815 Area += Nf_MatchRef_rec( p, iVar, fCompl, Nf_ObjMatchD(p, iVar, fCompl), ReqFanin, vBackup );
1816 }
1817 return Area + Nf_ManCell(p, pM->Gate)->AreaW;
1818}
1819word Nf_MatchRefArea( Nf_Man_t * p, int i, int c, Nf_Mat_t * pM, int Required )
1820{
1821 word Area; int iLit, k;
1822 Vec_IntClear( &p->vBackup );
1823 Area = Nf_MatchRef_rec( p, i, c, pM, Required, &p->vBackup );
1824 Vec_IntForEachEntry( &p->vBackup, iLit, k )
1825 {
1826 assert( Nf_ObjMapRefNum(p, Abc_Lit2Var(iLit), Abc_LitIsCompl(iLit)) > 0 );
1827 Nf_ObjMapRefDec( p, Abc_Lit2Var(iLit), Abc_LitIsCompl(iLit) );
1828 }
1829 return Area;
1830}
1831void Nf_ManElaBestMatchOne( Nf_Man_t * p, int iObj, int c, int * pCut, int * pCutSet, Nf_Mat_t * pRes, int Required )
1832{
1833 Nf_Mat_t Mb,*pMb = &Mb, * pMd;
1834 int * pFans = Nf_CutLeaves(pCut);
1835 int nFans = Nf_CutSize(pCut);
1836 int iFuncLit = Nf_CutFunc(pCut);
1837 int fComplExt = Abc_LitIsCompl(iFuncLit);
1838 Vec_Int_t * vArr = Vec_WecEntry( p->vTt2Match, Abc_Lit2Var(iFuncLit) );
1839 int i, k, Info, Offset, iFanin, fComplF;
1840 // assign fanins matches
1841 Nf_Obj_t * pBestF[NF_LEAF_MAX];
1842 for ( i = 0; i < nFans; i++ )
1843 pBestF[i] = Nf_ManObj( p, pFans[i] );
1844 // consider matches of this function
1845 memset( pMb, 0, sizeof(Nf_Mat_t) );
1846 pMb->D = SCL_INFINITY; pMb->F = FLT_MAX;
1847 // special cases
1848 if ( nFans == 0 )
1849 {
1850 int Const = (iFuncLit == 1);
1851 //printf( "Node %d(%d) is const\n", iObj, c );
1852 assert( iFuncLit == 0 || iFuncLit == 1 );
1853 pMb->D = 0;
1854 pMb->F = p->pCells[c ^ Const].AreaF;
1855 pMb->CutH = Nf_CutHandle(pCutSet, pCut);
1856 pMb->Gate = c ^ Const;
1857// pMb->Conf = 0;
1858 pMb->Cfg = Nf_Int2Cfg(0);
1859 pMb->fBest = 1;
1860 // compare
1861 if ( pRes->F > pMb->F + NF_EPSILON || (pRes->F > pMb->F - NF_EPSILON && pRes->D > pMb->D) )
1862 *pRes = *pMb;
1863 return;
1864 }
1865 // consider matches of this function
1866 Vec_IntForEachEntryDouble( vArr, Info, Offset, i )
1867 {
1868 Nf_Cfg_t Cfg = Nf_Int2Cfg(Offset);
1869 Mio_Cell2_t*pC = Nf_ManCell( p, Info );
1870 int fCompl = Cfg.fCompl ^ fComplExt;
1871 int Delay = 0;
1872 assert( nFans == (int)pC->nFanins );
1873 if ( fCompl != c )
1874 continue;
1875 Nf_CfgForEachVarCompl( Cfg, nFans, iFanin, fComplF, k )
1876 {
1877 pMd = &pBestF[iFanin]->M[fComplF][0];
1878 assert( pMd->fBest );
1879 Delay = Abc_MaxInt( Delay, pMd->D + pC->iDelays[k] );
1880 if ( Delay > Required )
1881 break;
1882 }
1883 if ( k < nFans )
1884 continue;
1885 // create match
1886 pMb->D = Delay;
1887 pMb->F = FLT_MAX;
1888 pMb->fBest = 1;
1889 pMb->fCompl = 0;
1890 pMb->CutH = Nf_CutHandle(pCutSet, pCut);
1891 pMb->Gate = pC->Id;
1892 pMb->Cfg = Cfg;
1893 pMb->Cfg.fCompl = 0;
1894 // compute area
1895 pMb->F = Scl_Int2Flt((int)Nf_MatchRefArea(p, iObj, c, pMb, Required));
1896 // compare
1897 if ( pRes->F > pMb->F + NF_EPSILON || (pRes->F > pMb->F - NF_EPSILON && pRes->D > pMb->D) )
1898 *pRes = *pMb;
1899 }
1900}
1901void Nf_ManElaBestMatch( Nf_Man_t * p, int iObj, int c, Nf_Mat_t * pRes, int Required )
1902{
1903 int k, * pCut, * pCutSet = Nf_ObjCutSet( p, iObj );
1904 memset( pRes, 0, sizeof(Nf_Mat_t) );
1905 pRes->D = SCL_INFINITY; pRes->F = FLT_MAX;
1906 Nf_SetForEachCut( pCutSet, pCut, k )
1907 {
1908 if ( Abc_Lit2Var(Nf_CutFunc(pCut)) >= Vec_WecSize(p->vTt2Match) )
1909 continue;
1910 Nf_ManElaBestMatchOne( p, iObj, c, pCut, pCutSet, pRes, Required );
1911 }
1912}
1913int Nf_ManComputeArrival( Nf_Man_t * p, Nf_Mat_t * pM, int * pCutSet )
1914{
1915 int Delay = 0;
1916 Nf_Mat_t * pMfan;
1917 int iVar, fCompl, k;
1918 Mio_Cell2_t * pCell = Nf_ManCell( p, pM->Gate );
1919 int * pCut = Nf_CutFromHandle( pCutSet, pM->CutH );
1920 assert( !pM->fCompl );
1921 Nf_CutForEachVarCompl( pCut, pM->Cfg, iVar, fCompl, k )
1922 {
1923 pMfan = Nf_ObjMatchBest( p, iVar, fCompl );
1924 Delay = Abc_MaxInt( Delay, pMfan->D + pCell->iDelays[k] );
1925 }
1926 //if ( pM->fCompl ) Delay += p->InvDelayI;
1927 return Delay;
1928}
1929void Nf_ManResetMatches( Nf_Man_t * p, int Round )
1930{
1931 Gia_Obj_t * pObj;
1932 Nf_Mat_t * pDc, * pAc, * pMfan, * pM[2];
1933 int i, c, Arrival;
1934 // go through matches in the topo order
1935 if ( p->pManTim )
1936 Tim_ManIncrementTravId( p->pManTim );
1937 Gia_ManForEachObjWithBoxes( p->pGia, pObj, i )
1938 {
1939 if ( Gia_ObjIsBuf(pObj) )
1940 {
1941 pMfan = Nf_ObjMatchBest( p, Gia_ObjFaninId0(pObj, i), Gia_ObjFaninC0(pObj) );
1942 for ( c = 0; c < 2; c++ )
1943 {
1944 pDc = Nf_ObjMatchD( p, i, c );
1945 pAc = Nf_ObjMatchA( p, i, c );
1946 pDc->F = pAc->F = 0;
1947 pDc->D = pMfan->D + (c ? p->InvDelayI : 0);
1948 assert( pDc->fBest );
1949 assert( !pAc->fBest );
1950 assert( c==0 || pDc->fCompl );
1951 }
1952 continue;
1953 }
1954 if ( Gia_ObjIsCi(pObj) )
1955 {
1956 Arrival = Tim_ManGetCiArrival( p->pManTim, Gia_ObjCioId(pObj) );
1957 Nf_ObjPrepareCi( p, i, Arrival );
1958 continue;
1959 }
1960 if ( Gia_ObjIsCo(pObj) )
1961 {
1962 Arrival = Nf_ObjMatchD( p, Gia_ObjFaninId0(pObj, i), Gia_ObjFaninC0(pObj) )->D;
1963 Tim_ManSetCoArrival( p->pManTim, Gia_ObjCioId(pObj), Arrival );
1964 continue;
1965 }
1966 // select the best match for each phase
1967 for ( c = 0; c < 2; c++ )
1968 {
1969 pDc = Nf_ObjMatchD( p, i, c );
1970 pAc = Nf_ObjMatchA( p, i, c );
1971 pDc->F = pAc->F = 0;
1972 if ( Nf_ObjMapRefNum(p, i, c) )
1973 {
1974 assert( pDc->fBest != pAc->fBest );
1975 if ( pAc->fBest )
1976 ABC_SWAP( Nf_Mat_t, *pDc, *pAc );
1977 assert( pDc->fBest );
1978 assert( !pAc->fBest );
1979 }
1980 else
1981 {
1982 assert( Round > 0 || (!pDc->fBest && !pAc->fBest) );
1983// if ( (p->pPars->fAreaOnly || (Round & 1)) && !pAc->fCompl )
1984 if ( (Round & 1) && !pAc->fCompl )
1985 ABC_SWAP( Nf_Mat_t, *pDc, *pAc );
1986 pDc->fBest = 1;
1987 pAc->fBest = 0;
1988 }
1989 }
1990 // consider best matches of both phases
1991 pM[0] = Nf_ObjMatchD( p, i, 0 );
1992 pM[1] = Nf_ObjMatchD( p, i, 1 );
1993 assert( pM[0]->fBest && pM[1]->fBest );
1994 // swap complemented matches
1995 if ( pM[0]->fCompl && pM[1]->fCompl )
1996 {
1997// pM[0]->fCompl = pM[1]->fCompl = 0;
1998// ABC_SWAP( Nf_Mat_t *, pM[0], pM[1] );
1999 assert( 0 );
2000 }
2001 if ( !pM[0]->fCompl && !pM[1]->fCompl )
2002 {
2003 for ( c = 0; c < 2; c++ )
2004 {
2005 Arrival = Nf_ManComputeArrival( p, pM[c], Nf_ObjCutSet(p, i) );
2006 //if ( Nf_ObjMapRefNum(p, i, c) )
2007 // assert( Round || Arrival <= pM[c]->D );
2008 pM[c]->D = Arrival;
2009 }
2010 }
2011 else
2012 {
2013 // consider non-complemented match
2014 c = !pM[1]->fCompl;
2015 assert( !pM[c]->fCompl );
2016 assert( pM[!c]->fCompl );
2017 Arrival = Nf_ManComputeArrival( p, pM[c], Nf_ObjCutSet(p, i) );
2018 //if ( Nf_ObjMapRefNum(p, i, c) )
2019 // assert( Round || Arrival <= pM[c]->D );
2020 pM[c]->D = Arrival;
2021 // consider complemented match
2022 Arrival = pM[!c]->D;
2023 *pM[!c] = *pM[c];
2024 pM[!c]->D += p->InvDelayI;
2025 pM[!c]->fCompl = 1;
2026 //if ( Nf_ObjMapRefNum(p, i, !c) )
2027 // assert( Round || pM[!c]->D <= Arrival );
2028 }
2029 }
2030}
2032{
2033 int fVerbose = 0;
2034 Gia_Obj_t * pObj;
2035 Mio_Cell2_t * pCell;
2036 Nf_Mat_t Mb, * pMb = &Mb, * pM;
2037 word AreaBef, AreaAft, Gain = 0;
2038 int i, c, iVar, Id, fCompl, k, * pCut, Required;
2039 Nf_ManResetMatches( p, p->Iter - p->pPars->nRounds );
2041 Gia_ManForEachObjReverseWithBoxes( p->pGia, pObj, i )
2042 {
2043 if ( Gia_ObjIsBuf(pObj) )
2044 {
2045 if ( Nf_ObjMapRefNum(p, i, 1) )
2046 Nf_ObjUpdateRequired( p, i, 0, Nf_ObjRequired(p, i, 1) - p->InvDelayI );
2047 int reqTime = Nf_ObjRequired(p, i, 0);
2048 int iObj = Gia_ObjFaninId0p(p->pGia, pObj);
2049 int fCompl = Gia_ObjFaninC0(pObj);
2050 Nf_ObjUpdateRequired( p, iObj, fCompl, reqTime );
2051 if ( iObj > 0 && Nf_ObjMatchBest(p, iObj, fCompl)->fCompl )
2052 Nf_ObjUpdateRequired( p, iObj, !fCompl, reqTime - p->InvDelayI );
2053 continue;
2054 }
2055 if ( Gia_ObjIsCi(pObj) )
2056 {
2057 if ( Nf_ObjMapRefNum(p, i, 1) )
2058 Nf_ObjUpdateRequired( p, i, 0, Nf_ObjRequired(p, i, 1) - p->InvDelayI );
2059 Tim_ManSetCiRequired( p->pManTim, Gia_ObjCioId(pObj), Nf_ObjRequired(p, i, 0) );
2060 continue;
2061 }
2062 if ( Gia_ObjIsCo(pObj) )
2063 {
2064 int reqTime = Tim_ManGetCoRequired( p->pManTim, Gia_ObjCioId(pObj) );
2065 int iObj = Gia_ObjFaninId0p(p->pGia, pObj);
2066 int fCompl = Gia_ObjFaninC0(pObj);
2067 Nf_ObjUpdateRequired( p, iObj, fCompl, reqTime );
2068 if ( iObj > 0 && Nf_ObjMatchBest(p, iObj, fCompl)->fCompl )
2069 Nf_ObjUpdateRequired( p, iObj, !fCompl, reqTime - p->InvDelayI );
2070 continue;
2071 }
2072 for ( c = 0; c < 2; c++ )
2073 if ( Nf_ObjMapRefNum(p, i, c) )
2074 {
2075 pM = Nf_ObjMatchBest( p, i, c );
2076 Required = Nf_ObjRequired( p, i, c );
2077 assert( pM->D <= Required );
2078 if ( pM->fCompl )
2079 continue;
2080 // search for a better match
2081 assert( !pM->fCompl );
2082 AreaBef = Nf_MatchDeref_rec( p, i, c, pM );
2083 assert( pM->fBest );
2084 Nf_ManElaBestMatch( p, i, c, pMb, Required );
2085 AreaAft = Nf_MatchRef_rec( p, i, c, pMb, Required, NULL );
2086 Gain += AreaBef - AreaAft;
2087 // print area recover progress
2088 if ( fVerbose && Nf_ManCell(p, pM->Gate)->pName != Nf_ManCell(p, pMb->Gate)->pName )
2089 {
2090 printf( "%4d (%d) ", i, c );
2091 printf( "%8s ->%8s ", Nf_ManCell(p, pM->Gate)->pName, Nf_ManCell(p, pMb->Gate)->pName );
2092 printf( "%d -> %d ", Nf_ManCell(p, pM->Gate)->nFanins, Nf_ManCell(p, pMb->Gate)->nFanins );
2093 printf( "D: %7.2f -> %7.2f ", Scl_Int2Flt(pM->D), Scl_Int2Flt(pMb->D) );
2094 printf( "R: %7.2f ", Required == SCL_INFINITY ? 9999.99 : Scl_Int2Flt(Required) );
2095 printf( "A: %7.2f -> %7.2f ", Scl_Int2Flt((int)AreaBef), Scl_Int2Flt((int)AreaAft) );
2096 printf( "G: %7.2f (%7.2f) ", Scl_Int2Flt((int)AreaBef - (int)AreaAft), Scl_Int2Flt((int)Gain) );
2097 printf( "\n" );
2098 }
2099 // set best match
2100 assert( pMb->fBest );
2101 assert( pMb->D <= Required );
2102 //assert( Scl_Flt2Int(pMb->F) == (int)AreaAft );
2103 //assert( AreaBef >= AreaAft );
2104 *pM = *pMb;
2105 // update timing
2106 pCell = Nf_ManCell( p, pMb->Gate );
2107 pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, i), pMb->CutH );
2108 Nf_CutForEachVarCompl( pCut, pMb->Cfg, iVar, fCompl, k )
2109 {
2110 pM = Nf_ObjMatchBest( p, iVar, fCompl );
2111 assert( pM->D <= Required - pCell->iDelays[k] );
2112 Nf_ObjUpdateRequired( p, iVar, fCompl, Required - pCell->iDelays[k] );
2113 if ( pM->fCompl )
2114 {
2115 pM = Nf_ObjMatchBest( p, iVar, !fCompl );
2116 assert( pM->D <= Required - pCell->iDelays[k] - p->InvDelayI );
2117 Nf_ObjUpdateRequired( p, iVar, !fCompl, Required - pCell->iDelays[k] - p->InvDelayI );
2118 }
2119 }
2120 }
2121 }
2122 Gia_ManForEachCiIdWithBoxes( p->pGia, Id, i )
2123 if ( Nf_ObjMapRefNum(p, Id, 1) )
2124 {
2125 Required = Nf_ObjRequired( p, i, 1 );
2126 Nf_ObjUpdateRequired( p, Id, 0, Required - p->InvDelayI );
2127 }
2128}
2130{
2131 Gia_Obj_t * pObj;
2132 Nf_Mat_t * pM, * pMc;
2133 int i, iDriver, Count = 0;
2134 Gia_ManForEachCo( p->pGia, pObj, i )
2135 {
2136 iDriver = Gia_ObjFaninId0p(p->pGia, pObj);
2137 if ( !Gia_ObjIsAnd(Gia_ManObj(p->pGia, iDriver)) )
2138 continue;
2139 // skip unless both are used
2140 if ( !Nf_ObjMapRefNum(p, iDriver, 0) || !Nf_ObjMapRefNum(p, iDriver, 1) )
2141 continue;
2142 pM = Nf_ObjMatchD( p, iDriver, Gia_ObjFaninC0(pObj) );
2143 pMc = Nf_ObjMatchD( p, iDriver, !Gia_ObjFaninC0(pObj) );
2144 // skip unless both are non-complemented
2145 if ( pM->fCompl || pMc->fCompl )
2146 continue;
2147 // skip if arrival time exceeds the required time
2148 if ( pMc->D + p->InvDelayI > p->pPars->MapDelay )
2149 continue;
2150 // update references
2151 Nf_MatchDeref_rec( p, iDriver, Gia_ObjFaninC0(pObj), pM );
2152 Nf_ObjMapRefInc( p, iDriver, !Gia_ObjFaninC0(pObj) );
2153 // add inverter
2154 *pM = *pMc;
2155 pM->D += p->InvDelayI;
2156 pM->fCompl = 1;
2157 pM->fBest = 1;
2158 pMc->fBest = 1;
2159 Count++;
2160 }
2161 //printf( "Fixed %d PO drivers.\n", Count );
2162}
2163
2176{
2177 FILE * pFile = fopen( p->pPars->ZFile, "wb" );
2178 Gia_Obj_t * pObj; int n, iObj;
2179 // output matches
2180 Gia_ManForEachCi( p->pGia, pObj, n )
2181 fprintf( pFile, "%d input %.2f\n", Abc_Var2Lit(Gia_ObjId(p->pGia, pObj), 0), 0.0 );
2182 Gia_ManForEachAnd( p->pGia, pObj, iObj ) {
2183 assert( !Gia_ObjIsBuf(pObj) );
2184 for ( n = 0; n < 2; n++ ) {
2185 int c, * pCut, * pCutSet = Nf_ObjCutSet( p, iObj );
2186 Nf_SetForEachCut( pCutSet, pCut, c ) {
2187 if ( Abc_Lit2Var(Nf_CutFunc(pCut)) >= Vec_WecSize(p->vTt2Match) )
2188 continue;
2189 assert( !Nf_CutIsTriv(pCut, iObj) );
2190 assert( Nf_CutSize(pCut) <= p->pPars->nLutSize );
2191 assert( Abc_Lit2Var(Nf_CutFunc(pCut)) < Vec_WecSize(p->vTt2Match) );
2192 int iFuncLit = Nf_CutFunc(pCut);
2193 int fComplExt = Abc_LitIsCompl(iFuncLit);
2194 Vec_Int_t * v = Vec_WecEntry( p->vTt2Match, Abc_Lit2Var(iFuncLit) );
2195 int j, k, Info, Offset, iFanin, fComplF;
2196 Vec_IntForEachEntryDouble( v, Info, Offset, j ) {
2197 Nf_Cfg_t Cfg = Nf_Int2Cfg(Offset);
2198 int fCompl = Cfg.fCompl ^ fComplExt;
2199 if ( fCompl != n )
2200 continue;
2201 Mio_Cell2_t*pC = Nf_ManCell( p, Info );
2202 assert( Nf_CutSize(pCut) == (int)pC->nFanins );
2203 fprintf( pFile, "%d ", Abc_Var2Lit(iObj, n) );
2204 fprintf( pFile, "%s ", pC->pName );
2205 fprintf( pFile, "%.2f", pC->AreaF );
2206 Nf_CutForEachVarCompl( pCut, Cfg, iFanin, fComplF, k )
2207 fprintf( pFile, " %d", Abc_Var2Lit(iFanin, fComplF) );
2208 fprintf( pFile, "\n" );
2209 }
2210 }
2211 }
2212 }
2213 Gia_ManForEachCo( p->pGia, pObj, n )
2214 fprintf( pFile, "%d output %.2f %d\n", Abc_Var2Lit(Gia_ObjId(p->pGia, pObj), 0), 0.0, Gia_ObjFaninLit0p(p->pGia, pObj) );
2215 // output levels
2216 extern int Gia_ManChoiceLevel( Gia_Man_t * p );
2217 int LevelMax = Gia_ManChoiceLevel( p->pGia );
2218 Gia_ManForEachCiId( p->pGia, iObj, n )
2219 fprintf( pFile, "L%d %d\n", Abc_Var2Lit(iObj, 0), 0 );
2220 Gia_ManForEachAnd( p->pGia, pObj, iObj )
2221 fprintf( pFile, "L%d %d\n", Abc_Var2Lit(iObj, 0), Gia_ObjLevelId(p->pGia, iObj) );
2222 Gia_ManForEachCoId( p->pGia, iObj, n )
2223 fprintf( pFile, "L%d %d\n", Abc_Var2Lit(iObj, 0), LevelMax+1 );
2224 // output mapping
2225 Gia_ManForEachCiId( p->pGia, iObj, n )
2226 if ( Nf_ObjMapRefNum(p, iObj, 1) )
2227 fprintf( pFile, "M%d %s %.2f %d\n", Abc_Var2Lit(iObj, 1), p->pCells[3].pName, p->pCells[3].AreaF, Abc_Var2Lit(iObj, 0) );
2228 Gia_ManForEachAnd( p->pGia, pObj, iObj )
2229 for ( n = 0; n < 2; n++ )
2230 if ( Nf_ObjMapRefNum(p, iObj, n) ) {
2231 Nf_Mat_t * pM = Nf_ObjMatchBest(p, iObj, n);
2232 if ( pM->fCompl ) {
2233 fprintf( pFile, "M%d %s %.2f %d\n", Abc_Var2Lit(iObj, n), p->pCells[3].pName, p->pCells[3].AreaF, Abc_Var2Lit(iObj, !n) );
2234 continue;
2235 }
2236 int k, iVar, fCompl, * pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, iObj), pM->CutH );
2237 Mio_Cell2_t*pC = Nf_ManCell( p, pM->Gate );
2238 fprintf( pFile, "M%d ", Abc_Var2Lit(iObj, n) );
2239 fprintf( pFile, "%s ", pC->pName );
2240 fprintf( pFile, "%.2f", pC->AreaF );
2241 Nf_CutForEachVarCompl( pCut, pM->Cfg, iVar, fCompl, k )
2242 fprintf( pFile, " %d", Abc_Var2Lit(iVar, fCompl) );
2243 fprintf( pFile, "\n" );
2244 }
2245 fclose( pFile );
2246}
2247
2260{
2261 Vec_Int_t * vMapping;
2262 Nf_Mat_t * pM;
2263 int i, k, c, Id, iVar, fCompl, * pCut;
2264 assert( p->pGia->vCellMapping == NULL );
2265 vMapping = Vec_IntAlloc( 2*Gia_ManObjNum(p->pGia) + (int)p->pPars->Edge + (int)p->pPars->Area * 2 );
2266 Vec_IntFill( vMapping, 2*Gia_ManObjNum(p->pGia), 0 );
2267 // create CI inverters
2268 Gia_ManForEachCiId( p->pGia, Id, i )
2269 if ( Nf_ObjMapRefNum(p, Id, 1) )
2270 Vec_IntWriteEntry( vMapping, Abc_Var2Lit(Id, 1), -1 );
2271 // create internal nodes
2272 Gia_ManForEachAndId( p->pGia, i )
2273 {
2274 Gia_Obj_t * pObj = Gia_ManObj(p->pGia, i);
2275 if ( Gia_ObjIsBuf(pObj) )
2276 {
2277 if ( Nf_ObjMapRefNum(p, i, 1) )
2278 Vec_IntWriteEntry( vMapping, Abc_Var2Lit(i, 1), -1 );
2279 Vec_IntWriteEntry( vMapping, Abc_Var2Lit(i, 0), -2 );
2280 continue;
2281 }
2282 for ( c = 0; c < 2; c++ )
2283 if ( Nf_ObjMapRefNum(p, i, c) )
2284 {
2285 pM = Nf_ObjMatchBest( p, i, c );
2286 // remember inverter
2287 if ( pM->fCompl )
2288 {
2289 Vec_IntWriteEntry( vMapping, Abc_Var2Lit(i, c), -1 );
2290 continue;
2291 }
2292 // Nf_ManCutMatchPrint( p, i, c, pM );
2293 pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, i), pM->CutH );
2294 Vec_IntWriteEntry( vMapping, Abc_Var2Lit(i, c), Vec_IntSize(vMapping) );
2295 Vec_IntPush( vMapping, Nf_CutSize(pCut) );
2296 Nf_CutForEachVarCompl( pCut, pM->Cfg, iVar, fCompl, k )
2297 Vec_IntPush( vMapping, Abc_Var2Lit(iVar, fCompl) );
2298 Vec_IntPush( vMapping, pM->Gate );
2299 }
2300 }
2301// assert( Vec_IntCap(vMapping) == 16 || Vec_IntSize(vMapping) == Vec_IntCap(vMapping) );
2302 p->pGia->vCellMapping = vMapping;
2303 if ( p->pPars->ZFile )
2305 return p->pGia;
2306}
2308{
2309 Nf_Mat_t * pM;
2310 Gia_Obj_t * pObj;
2311 Mio_Cell2_t * pCell;
2312 int i, c, Id, * pCut;
2313 p->pPars->MapAreaF = 0; p->nInvs = 0;
2314 p->pPars->Area = p->pPars->Edge = 0;
2315 Gia_ManForEachAndReverse( p->pGia, pObj, i )
2316 {
2317 if ( Gia_ObjIsBuf(pObj) )
2318 {
2319 if ( Nf_ObjMapRefNum(p, i, 1) )
2320 {
2321 p->pPars->MapAreaF += p->InvAreaF;
2322 p->pPars->Edge++;
2323 p->pPars->Area++;
2324 p->nInvs++;
2325 }
2326 continue;
2327 }
2328 for ( c = 0; c < 2; c++ )
2329 if ( Nf_ObjMapRefNum(p, i, c) )
2330 {
2331 pM = Nf_ObjMatchBest( p, i, c );
2332 if ( pM->fCompl )
2333 {
2334 p->pPars->MapAreaF += p->InvAreaF;
2335 p->pPars->Edge++;
2336 p->pPars->Area++;
2337 p->nInvs++;
2338 continue;
2339 }
2340 pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, i), pM->CutH );
2341 pCell = Nf_ManCell( p, pM->Gate );
2342 assert( Nf_CutSize(pCut) == (int)pCell->nFanins );
2343 p->pPars->MapAreaF += pCell->AreaF;
2344 p->pPars->Edge += Nf_CutSize(pCut);
2345 p->pPars->Area++;
2346 //printf( "%5d (%d) : Gate = %7s \n", i, c, pCell->pName );
2347 }
2348 }
2349 Gia_ManForEachCiId( p->pGia, Id, i )
2350 if ( Nf_ObjMapRefNum(p, Id, 1) )
2351 {
2352 p->pPars->MapAreaF += p->InvAreaF;
2353 p->pPars->Edge++;
2354 p->pPars->Area++;
2355 p->nInvs++;
2356 }
2357}
2358
2370
2371/*
2372 int nInputs; // the number of inputs
2373 int nObjs; // number of all objects
2374 Vec_Int_t * vRoots; // output drivers to be mapped (root -> obj lit)
2375 Vec_Wec_t * vCuts; // cuts (cut -> obj lit + fanin lits)
2376 Vec_Wec_t * vObjCuts; // cuts (obj lit -> obj lit + cut lits)
2377 Vec_Int_t * vSolCuts; // current solution (index -> cut)
2378 Vec_Int_t * vCutGates; // gates (cut -> gate)
2379*/
2380
2381int Nf_ManExtractWindow( void * pMan, Vec_Int_t * vRoots, Vec_Wec_t * vCuts, Vec_Wec_t * vObjCuts, Vec_Int_t * vSolCuts, Vec_Int_t * vCutGates, Vec_Wrd_t * vCutAreas, word * pInvArea, int StartVar, int nVars )
2382{
2383 Nf_Man_t * p = (Nf_Man_t *)pMan;
2384 int nInputs = Gia_ManCiNum(p->pGia);
2385 int LitShift = 2*nInputs+2;
2386 Gia_Obj_t * pObj;
2387 int c, iObj;
2388 if ( 2*Gia_ManAndNum(p->pGia) + Gia_ManCiNum(p->pGia) > nVars )
2389 {
2390 printf( "The number of variables is too large: 2*%d + %d = %d > %d.\n", Gia_ManAndNum(p->pGia), Gia_ManCiNum(p->pGia), 2*Gia_ManAndNum(p->pGia) + Gia_ManCiNum(p->pGia), nVars );
2391 return 0;
2392 }
2393 *pInvArea = p->InvAreaW;
2394 // save roots
2395 Vec_IntClear( vRoots );
2396 Gia_ManForEachCo( p->pGia, pObj, c )
2397 {
2398 assert( !Gia_ObjIsCi(Gia_ObjFanin0(pObj)) );
2399 Vec_IntPush( vRoots, Gia_ObjFaninLit0p(p->pGia, pObj)-LitShift );
2400 }
2401 // prepare
2402 Vec_WecClear( vCuts );
2403 Vec_WecClear( vObjCuts );
2404 Vec_IntClear( vSolCuts );
2405 Vec_IntClear( vCutGates );
2406 Vec_WrdClear( vCutAreas );
2407 // collect cuts for each node
2408 Gia_ManForEachAndId( p->pGia, iObj )
2409 {
2410 Vec_Int_t * vObj[2], * vCutOne;
2411 int iCut, * pCut, * pCutSet;
2412 int iCutInv[2] = {-1, -1};
2413 // get matches
2414 Nf_Mat_t * pM[2] = {NULL, NULL};
2415 for ( c = 0; c < 2; c++ )
2416 {
2417 if ( Nf_ObjMapRefNum(p, iObj, c) == 0 )
2418 continue;
2419 if ( Nf_ObjMatchBest(p, iObj, c)->fCompl )
2420 {
2421 assert( iCutInv[c] == -1 );
2422 iCutInv[c] = Vec_IntSize(vSolCuts);
2423 Vec_IntPush( vSolCuts, -1 );
2424 continue;
2425 }
2426 pM[c] = Nf_ObjMatchBest(p, iObj, c);
2427 }
2428 // start collecting cuts of pos-obj and neg-obj
2429 assert( Vec_WecSize(vObjCuts) == 2*iObj-LitShift );
2430 for ( c = 0; c < 2; c++ )
2431 {
2432 vObj[c] = Vec_WecPushLevel( vObjCuts );
2433 Vec_IntPush( vObj[c], Abc_Var2Lit(Abc_Var2Lit(iObj, c)-LitShift, 1) );
2434 }
2435 // enumerate cuts
2436 pCutSet = Nf_ObjCutSet( p, iObj );
2437 Nf_SetForEachCut( pCutSet, pCut, iCut )
2438 {
2439 assert( !Nf_CutIsTriv(pCut, iObj) );
2440 assert( Nf_CutSize(pCut) <= p->pPars->nLutSize );
2441 if ( Abc_Lit2Var(Nf_CutFunc(pCut)) < Vec_WecSize(p->vTt2Match) )
2442 {
2443 int * pFans = Nf_CutLeaves(pCut);
2444 int nFans = Nf_CutSize(pCut);
2445 int iFuncLit = Nf_CutFunc(pCut);
2446 int fComplExt = Abc_LitIsCompl(iFuncLit);
2447 Vec_Int_t * vArr = Vec_WecEntry( p->vTt2Match, Abc_Lit2Var(iFuncLit) );
2448 int i, k, c, Info, Offset, iFanin, fComplF, iCutLit;
2449 Vec_IntForEachEntryDouble( vArr, Info, Offset, i )
2450 {
2451 Nf_Cfg_t Cfg = Nf_Int2Cfg(Offset);
2452 int fCompl = Cfg.fCompl ^ fComplExt;
2453 Mio_Cell2_t*pC = Nf_ManCell( p, Info );
2454 assert( nFans == (int)pC->nFanins );
2455 Vec_IntPush( vCutGates, Info );
2456 Vec_WrdPush( vCutAreas, pC->AreaW );
2457 // to make comparison possible
2458 Cfg.fCompl = 0;
2459 // add solution cut
2460 for ( c = 0; c < 2; c++ )
2461 {
2462 if ( pM[c] == NULL )
2463 continue;
2464 if ( (int)pM[c]->CutH == Nf_CutHandle(pCutSet, pCut) && (int)pM[c]->Gate == Info && Nf_Cfg2Int(pM[c]->Cfg) == Nf_Cfg2Int(Cfg) )
2465 {
2466 Vec_IntPush( vSolCuts, Vec_WecSize(vCuts) );
2467 //printf( "adding solution for %d\n", Abc_Var2Lit(iObj, c)-LitShift );
2468 }
2469 }
2470 // add new cut
2471 iCutLit = Abc_Var2Lit( StartVar + Vec_WecSize(vCuts), 0 );
2472 vCutOne = Vec_WecPushLevel( vCuts );
2473 // add literals
2474 Vec_IntPush( vCutOne, Abc_Var2Lit(iObj, fCompl) );
2475 Vec_IntPush( vObj[fCompl], iCutLit );
2476 Nf_CfgForEachVarCompl( Cfg, nFans, iFanin, fComplF, k )
2477 if ( pFans[iFanin] >= nInputs + 1 ) // internal node
2478 {
2479 Vec_IntPush( vCutOne, Abc_Var2Lit(pFans[iFanin], fComplF) );
2480 //Vec_IntPush( Vec_WecEntry(vObjCuts, Abc_Var2Lit(pFans[iFanin], fComplF)-LitShift), iCutLit );
2481 }
2482 else if ( fComplF ) // complemented primary input
2483 Vec_IntPush( vCutOne, Abc_Var2Lit(pFans[iFanin], 1) );
2484 }
2485 }
2486 }
2487 assert( iCutInv[0] == -1 || iCutInv[1] == -1 );
2488 // add inverter cut
2489 for ( c = 0; c < 2; c++ )
2490 {
2491 if ( iCutInv[c] != -1 )
2492 Vec_IntWriteEntry( vSolCuts, iCutInv[c], Vec_WecSize(vCuts) );
2493 // the obj-lit implies its cut
2494 Vec_IntPush( Vec_WecEntry(vObjCuts, Abc_Var2Lit(iObj, c)-LitShift), Abc_Var2Lit(StartVar + Vec_WecSize(vCuts), 0) );
2495 // the cut includes both literals
2496 vCutOne = Vec_WecPushLevel( vCuts );
2497 Vec_IntPush( vCutOne, Abc_Var2Lit(iObj, c) );
2498 Vec_IntPush( vCutOne, Abc_Var2Lit(iObj, !c) );
2499 Vec_IntPush( vCutGates, 3 );
2500 Vec_WrdPush( vCutAreas, p->InvAreaW );
2501 }
2502 }
2503// for ( c = 0; c < p->nCells; c++ )
2504// printf( "%d=%s ", c, p->pCells[c].pName );
2505// printf( "\n" );
2506 // add complemented inputs
2507 Gia_ManForEachCiId( p->pGia, iObj, c )
2508 if ( Nf_ObjMapRefNum(p, iObj, 1) )
2509 Vec_IntPush( vSolCuts, -(2*Gia_ManAndNum(p->pGia)+c) );
2510 assert( Vec_WecSize(vCuts) == Vec_IntSize(vCutGates) );
2511 assert( Vec_WecSize(vCuts) == Vec_WrdSize(vCutAreas) );
2512 assert( Vec_WecSize(vObjCuts) == 2*Gia_ManAndNum(p->pGia) );
2513 return nInputs;
2514}
2515
2528{
2529 memset( pPars, 0, sizeof(Jf_Par_t) );
2530 pPars->nLutSize = 6;
2531 pPars->nCutNum = 16;
2532 pPars->nProcNum = 0;
2533 pPars->nRounds = 4;
2534 pPars->nRoundsEla = 2;
2535 pPars->nRelaxRatio = 0;
2536 pPars->nCoarseLimit = 3;
2537 pPars->nAreaTuner = 0;
2538 pPars->nReqTimeFlex = 0;
2539 pPars->nVerbLimit = 5;
2540 pPars->DelayTarget = -1;
2541 pPars->fAreaOnly = 0;
2542 pPars->fPinPerm = 0;
2543 pPars->fPinQuick = 0;
2544 pPars->fPinFilter = 0;
2545 pPars->fOptEdge = 1;
2546 pPars->fCoarsen = 0;
2547 pPars->fCutMin = 1;
2548 pPars->fGenCnf = 0;
2549 pPars->fPureAig = 0;
2550 pPars->fVerbose = 0;
2551 pPars->fVeryVerbose = 0;
2552 pPars->nLutSizeMax = NF_LEAF_MAX;
2553 pPars->nCutNumMax = NF_CUT_MAX;
2554 pPars->MapDelayTarget = 0;
2555}
2557{
2558 Gia_Man_t * pNew = NULL, * pCls;
2559 Nf_Man_t * p; int i, Id;
2560 if ( Gia_ManHasChoices(pGia) || pGia->pManTime )
2561 pPars->fCoarsen = 0;
2562 pCls = pPars->fCoarsen ? Gia_ManDupMuxes(pGia, pPars->nCoarseLimit) : pGia;
2563 p = Nf_StoCreate( pCls, pPars );
2564 if ( p == NULL )
2565 return NULL;
2566// if ( p->pManTim ) Tim_ManPrint( p->pManTim );
2567 p->pGia->iFirstNonPiId = p->pManTim ? Tim_ManPiNum(p->pManTim) : Gia_ManCiNum(p->pGia);
2568 p->pGia->iFirstPoId = p->pManTim ? Gia_ManCoNum(p->pGia) - Tim_ManPoNum(p->pManTim) : 0;
2569 p->pGia->iFirstAndObj = 1 + p->pGia->iFirstNonPiId;
2570 p->pGia->iFirstPoObj = Gia_ManObjNum(p->pGia) - Gia_ManCoNum(p->pGia) + p->pGia->iFirstPoId;
2571// if ( pPars->fVeryVerbose )
2572// Nf_StoPrint( p, pPars->fVeryVerbose );
2573 if ( pPars->fVerbose && pPars->fCoarsen )
2574 {
2575 printf( "Initial " ); Gia_ManPrintMuxStats( pGia ); printf( "\n" );
2576 printf( "Derived " ); Gia_ManPrintMuxStats( pCls ); printf( "\n" );
2577 }
2578 Nf_ManPrintInit( p );
2580 Nf_ManPrintQuit( p );
2581 if ( Scl_ConIsRunning() )
2582 {
2583 Gia_ManForEachCiIdWithBoxes( p->pGia, Id, i )
2584 Nf_ObjPrepareCi( p, Id, Scl_ConGetInArr(i) );
2585 }
2586 else
2587 {
2588 Gia_ManForEachCiIdWithBoxes( p->pGia, Id, i )
2589// Nf_ObjPrepareCi( p, Id, Scl_Flt2Int(p->pGia->vInArrs ? Abc_MaxFloat(0.0, Vec_FltEntry(p->pGia->vInArrs, i)) : 0.0) );
2590 Nf_ObjPrepareCi( p, Id, Scl_Flt2Int(p->pGia->vInArrs ? Vec_FltEntry(p->pGia->vInArrs, i) : 0.0) );
2591 }
2592 for ( p->Iter = 0; p->Iter < p->pPars->nRounds; p->Iter++ )
2593 {
2596 Nf_ManPrintStats( p, (char *)(p->Iter ? "Area " : "Delay") );
2597 }
2598
2599 p->fUseEla = 1;
2600 for ( ; p->Iter < p->pPars->nRounds + pPars->nRoundsEla; p->Iter++ )
2601 {
2604 Nf_ManPrintStats( p, "Ela " );
2605 }
2607 pNew = Nf_ManDeriveMapping( p );
2608/*
2609 if ( pPars->fAreaOnly )
2610 {
2611 int Sbm_ManTestSat( void * pMan );
2612 Sbm_ManTestSat( p );
2613 }
2614*/
2615 Nf_StoDelete( p );
2616 return pNew;
2617}
2618
2619
2632{
2633 int iFanLit, k, Result = 1;
2634 if ( Abc_LitIsCompl(iLit) && Gia_ObjIsTravIdCurrentId(p, Abc_Lit2Var(iLit)) )
2635 return 1;
2636 if ( !Abc_LitIsCompl(iLit) && Gia_ObjIsTravIdPreviousId(p, Abc_Lit2Var(iLit)) )
2637 return 1;
2638 if ( Abc_LitIsCompl(iLit) )
2639 Gia_ObjSetTravIdCurrentId(p, Abc_Lit2Var(iLit));
2640 else
2641 Gia_ObjSetTravIdPreviousId(p, Abc_Lit2Var(iLit));
2642 if ( !Gia_ObjIsAndNotBuf(Gia_ManObj(p, Abc_Lit2Var(iLit))) )
2643 return 1;
2644 if ( !Gia_ObjIsCell(p, iLit) )
2645 {
2646 Abc_Print( -1, "Gia_ManCellMappingVerify: Internal literal %d does not have mapping.\n", iLit );
2647 return 0;
2648 }
2649 if ( Gia_ObjIsCellBuf(p, iLit) )
2650 return Gia_ManCellMappingVerify_rec( p, Gia_ObjFaninLit0p(p, Gia_ManObj(p, Abc_Lit2Var(iLit))) );
2651 if ( Gia_ObjIsCellInv(p, iLit) )
2652 return Gia_ManCellMappingVerify_rec( p, Abc_LitNot(iLit) );
2653 Gia_CellForEachFanin( p, iLit, iFanLit, k )
2654 if ( Result )
2655 Result &= Gia_ManCellMappingVerify_rec( p, iFanLit );
2656 return Result;
2657}
2659{
2660 Gia_Obj_t * pObj;
2661 int i, iLit, Result = 1;
2662 assert( Gia_ManHasCellMapping(p) );
2665 Gia_ManForEachBuf( p, pObj, i )
2666 {
2667 if ( !Gia_ObjIsAndNotBuf(Gia_ObjFanin0(pObj)) )
2668 continue;
2669 iLit = Gia_ObjFaninLit0p(p, pObj);
2670 if ( !Gia_ObjIsCell(p, iLit) )
2671 {
2672 Abc_Print( -1, "Gia_ManCellMappingVerify: Buffer driver %d does not have mapping.\n", Gia_ObjFaninId0p(p, pObj) );
2673 Result = 0;
2674 continue;
2675 }
2676 Result &= Gia_ManCellMappingVerify_rec( p, iLit );
2677 }
2678 Gia_ManForEachCo( p, pObj, i )
2679 {
2680 if ( !Gia_ObjIsAndNotBuf(Gia_ObjFanin0(pObj)) )
2681 continue;
2682 iLit = Gia_ObjFaninLit0p(p, pObj);
2683 if ( !Gia_ObjIsCell(p, iLit) )
2684 {
2685 Abc_Print( -1, "Gia_ManCellMappingVerify: CO driver %d does not have mapping.\n", Gia_ObjFaninId0p(p, pObj) );
2686 Result = 0;
2687 continue;
2688 }
2689 Result &= Gia_ManCellMappingVerify_rec( p, iLit );
2690 }
2691// if ( Result )
2692// Abc_Print( 1, "Mapping verified correctly.\n" );
2693}
2694
2696{
2697 int iLit, iLitNew, k, iFanLit, iPlace;
2698 if ( !Gia_ManHasCellMapping(pGia) )
2699 return;
2701 Vec_IntFreeP( &p->vCellMapping );
2702 p->vCellMapping = Vec_IntAlloc( 4 * Gia_ManObjNum(p) );
2703 Vec_IntFill( p->vCellMapping, 2 * Gia_ManObjNum(p), 0 );
2704 Gia_ManForEachCell( pGia, iLit )
2705 {
2706 Gia_Obj_t * pObj = Gia_ManObj(pGia, Abc_Lit2Var(iLit));
2707 if ( Gia_ObjValue(pObj) == ~0 ) // handle dangling LUT
2708 continue;
2709 assert( !Abc_LitIsCompl( Gia_ObjValue(pObj) ) );
2710 iLitNew = Abc_LitNotCond( Gia_ObjValue(pObj), Abc_LitIsCompl(iLit) );
2711 if ( Gia_ObjIsCellInv(pGia, iLit) ) {
2712 Vec_IntWriteEntry( p->vCellMapping, iLitNew, -1 );
2713 continue;
2714 }
2715 if ( Gia_ObjIsCellBuf(pGia, iLit) ) {
2716 Vec_IntWriteEntry( p->vCellMapping, iLitNew, -2 );
2717 continue;
2718 }
2719 Vec_IntWriteEntry( p->vCellMapping, iLitNew, Vec_IntSize(p->vCellMapping) );
2720 iPlace = Vec_IntSize( p->vCellMapping );
2721 Vec_IntPush( p->vCellMapping, Gia_ObjCellSize(pGia, iLit) );
2722 Gia_CellForEachFanin( pGia, iLit, iFanLit, k )
2723 {
2724 int iFanLitNew = Gia_ObjValue( Gia_ManObj(pGia, Abc_Lit2Var(iFanLit)) );
2725 if ( iFanLitNew == ~0 ) // handle dangling LUT fanin
2726 Vec_IntAddToEntry( p->vCellMapping, iPlace, -1 );
2727 else
2728 Vec_IntPush( p->vCellMapping, Abc_LitNotCond(iFanLitNew, Abc_LitIsCompl(iFanLit)) );
2729 }
2730 Vec_IntPush( p->vCellMapping, Gia_ObjCellId(pGia, iLit) );
2731 }
2733}
2735{
2736 Gia_Man_t * pNew;
2737 if ( p->pManTime && Tim_ManBoxNum((Tim_Man_t*)p->pManTime) && Gia_ManIsNormalized(p) )
2738 {
2739 pNew = Gia_ManDupUnnormalize( p );
2740 if ( pNew == NULL )
2741 return NULL;
2742 Gia_ManTransferTiming( pNew, p );
2743 p = pNew;
2744 // mapping
2745 pNew = Nf_ManPerformMappingInt( p, pPars );
2746 if ( pNew != p )
2747 {
2748 Gia_ManTransferTiming( pNew, p );
2749 Gia_ManStop( p );
2750 }
2751 // normalize
2752 pNew = Gia_ManDupNormalize( p = pNew, 0 );
2754 Gia_ManTransferTiming( pNew, p );
2755 Gia_ManStop( p );
2756 assert( Gia_ManIsNormalized(pNew) );
2757 }
2758 else
2759 {
2760 pNew = Nf_ManPerformMappingInt( p, pPars );
2761 Gia_ManTransferTiming( pNew, p );
2762 //Gia_ManCellMappingVerify( pNew );
2763 // remove choices after mapping
2764 ABC_FREE( pNew->pReprs );
2765 ABC_FREE( pNew->pNexts );
2766 }
2767 //pNew->MappedDelay = (int)((If_Par_t *)pp)->FinalDelay;
2768 //pNew->MappedArea = (int)((If_Par_t *)pp)->FinalArea;
2769 return pNew;
2770}
2771
2775
2776
2778
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#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
ABC_DLL void * Abc_FrameReadLibGen()
Definition mainFrame.c:59
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
void Dau_DsdPrintFromTruth(word *pTruth, int nVarsInit)
Definition dauDsd.c:1968
Cube * p
Definition exorList.c:222
int * Extra_PermSchedule(int n)
int Extra_Factorial(int n)
int * Extra_GreyCodeSchedule(int n)
int Gia_ManChoiceLevel(Gia_Man_t *p)
Definition giaIf.c:813
void Mf_ManSetFlowRefs(Gia_Man_t *p, Vec_Int_t *vRefs)
Definition giaMf.c:1137
word Nf_MatchRef_rec(Nf_Man_t *p, int i, int c, Nf_Mat_t *pM, int Required, Vec_Int_t *vBackup)
Definition giaNf.c:1788
void Nf_ManPrintMatches(Nf_Man_t *p)
Definition giaNf.c:1546
int Nf_ManExtractWindow(void *pMan, Vec_Int_t *vRoots, Vec_Wec_t *vCuts, Vec_Wec_t *vObjCuts, Vec_Int_t *vSolCuts, Vec_Int_t *vCutGates, Vec_Wrd_t *vCutAreas, word *pInvArea, int StartVar, int nVars)
Definition giaNf.c:2381
void Nf_ManCutMatchOne(Nf_Man_t *p, int iObj, int *pCut, int *pCutSet)
Definition giaNf.c:1124
void Nf_ManSetMapRefsGate(Nf_Man_t *p, int iObj, int Required, Nf_Mat_t *pM)
Definition giaNf.c:1527
#define Nf_CutForEachVarCompl(pCut, Cfg, iVar, fCompl, i)
Definition giaNf.c:161
void Nf_StoCreateGateMaches(Vec_Mem_t *vTtMem, Vec_Wec_t *vTt2Match, Mio_Cell2_t *pCell, int **pComp, int **pPerm, int *pnPerms, Vec_Wec_t *vProfs, Vec_Int_t *vStore, int fPinFilter, int fPinPerm, int fPinQuick)
Definition giaNf.c:255
void Nf_ManCutMatch(Nf_Man_t *p, int iObj)
Definition giaNf.c:1280
void Nf_ManComputeMapping(Nf_Man_t *p)
Definition giaNf.c:1429
#define Nf_CfgForEachVarCompl(Cfg, Size, iVar, fCompl, i)
Definition giaNf.c:162
void Nf_ManSetOutputRequireds(Nf_Man_t *p, int fPropCompl)
Definition giaNf.c:1461
struct Nf_Obj_t_ Nf_Obj_t
Definition giaNf.c:81
void Nf_StoDelete(Nf_Man_t *p)
Definition giaNf.c:423
void Gia_ManTransferCellMapping(Gia_Man_t *p, Gia_Man_t *pGia)
Definition giaNf.c:2695
void Nf_ManResetMatches(Nf_Man_t *p, int Round)
Definition giaNf.c:1929
#define NF_NO_FUNC
Definition giaNf.c:49
word Nf_MatchRefArea(Nf_Man_t *p, int i, int c, Nf_Mat_t *pM, int Required)
Definition giaNf.c:1819
int Nf_StoCellIsDominated(Mio_Cell2_t *pCell, int *pFans, int *pProf)
FUNCTION DEFINITIONS ///.
Definition giaNf.c:179
void Nf_ManSetDefaultPars(Jf_Par_t *pPars)
Definition giaNf.c:2527
struct Nf_Mat_t_ Nf_Mat_t
Definition giaNf.c:70
void Nf_ManElaBestMatch(Nf_Man_t *p, int iObj, int c, Nf_Mat_t *pRes, int Required)
Definition giaNf.c:1901
struct Nf_Cfg_t_ Nf_Cfg_t
Definition giaNf.c:63
#define NF_CUT_MAX
Definition giaNf.c:47
void Nf_ManUpdateStats(Nf_Man_t *p)
Definition giaNf.c:2307
#define NF_NO_LEAF
Definition giaNf.c:48
void Nf_ManElaBestMatchOne(Nf_Man_t *p, int iObj, int c, int *pCut, int *pCutSet, Nf_Mat_t *pRes, int Required)
Definition giaNf.c:1831
#define NF_EPSILON
Definition giaNf.c:50
void Nf_ManPrintInit(Nf_Man_t *p)
Definition giaNf.c:1027
Mio_Cell2_t * Nf_StoDeriveMatches(Vec_Mem_t *vTtMem, Vec_Wec_t *vTt2Match, int *pnCells, int fPinFilter, int fPinPerm, int fPinQuick)
Definition giaNf.c:288
#define NF_LEAF_MAX
DECLARATIONS ///.
Definition giaNf.c:46
Nf_Man_t * Nf_StoCreate(Gia_Man_t *pGia, Jf_Par_t *pPars)
Definition giaNf.c:373
void Nf_ManFixPoDrivers(Nf_Man_t *p)
Definition giaNf.c:2129
struct Nf_Man_t_ Nf_Man_t
Definition giaNf.c:86
void Nf_StoPrintOne(Nf_Man_t *p, int Count, int t, int i, int GateId, Nf_Cfg_t Mat)
Definition giaNf.c:317
Gia_Man_t * Nf_ManDeriveMapping(Nf_Man_t *p)
Definition giaNf.c:2259
#define Nf_SetForEachCut(pList, pCut, i)
Definition giaNf.c:160
word Nf_MatchDeref_rec(Nf_Man_t *p, int i, int c, Nf_Mat_t *pM)
Definition giaNf.c:1765
Gia_Man_t * Nf_ManPerformMapping(Gia_Man_t *p, Jf_Par_t *pPars)
Definition giaNf.c:2734
void Nf_ManPrintQuit(Nf_Man_t *p)
Definition giaNf.c:1047
int Nf_ManComputeArrival(Nf_Man_t *p, Nf_Mat_t *pM, int *pCutSet)
Definition giaNf.c:1913
void Nf_ManCutMatchPrint(Nf_Man_t *p, int iObj, char *pStr, Nf_Mat_t *pM)
Definition giaNf.c:1087
int Nf_ManSetMapRefs(Nf_Man_t *p)
Definition giaNf.c:1571
void Nf_ManComputeMappingEla(Nf_Man_t *p)
Definition giaNf.c:2031
Gia_Man_t * Nf_ManPerformMappingInt(Gia_Man_t *pGia, Jf_Par_t *pPars)
Definition giaNf.c:2556
void Nf_StoPrint(Nf_Man_t *p, int fVerbose)
Definition giaNf.c:341
void Nf_StoCreateGateAdd(Vec_Mem_t *vTtMem, Vec_Wec_t *vTt2Match, Mio_Cell2_t *pCell, word uTruth, int *pFans, int nFans, Vec_Wec_t *vProfs, Vec_Int_t *vStore, int fPinFilter, int fPinPerm, int fPinQuick)
Definition giaNf.c:189
struct Nf_Cut_t_ Nf_Cut_t
Definition giaNf.c:52
void Nf_ManComputeCuts(Nf_Man_t *p)
Definition giaNf.c:965
void Nf_ObjMergeOrder(Nf_Man_t *p, int iObj)
Definition giaNf.c:863
int Gia_ManCellMappingVerify_rec(Gia_Man_t *p, int iLit)
Definition giaNf.c:2631
void Nf_ManDumpMatches(Nf_Man_t *p)
Definition giaNf.c:2175
void Nf_ManPrintStats(Nf_Man_t *p, char *pTitle)
Definition giaNf.c:1014
void Gia_ManCellMappingVerify(Gia_Man_t *p)
Definition giaNf.c:2658
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
Gia_Man_t * Gia_ManDupMuxes(Gia_Man_t *p, int Limit)
Definition giaMuxes.c:98
#define Gia_ManForEachBuf(p, pObj, i)
Definition gia.h:1210
double Gia_ManMemory(Gia_Man_t *p)
Definition giaMan.c:194
int Gia_ManIsNormalized(Gia_Man_t *p)
Definition giaTim.c:114
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
#define Gia_ManForEachCoId(p, Id, i)
Definition gia.h:1240
#define Gia_ManForEachAndReverse(p, pObj, i)
Definition gia.h:1222
#define Gia_ManForEachCell(p, i)
Definition gia.h:1181
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
#define Gia_ManForEachCiIdWithBoxes(p, Id, i)
Definition gia.h:1265
void Gia_ManPrintMuxStats(Gia_Man_t *p)
Definition giaMuxes.c:63
void Gia_ManTransferTiming(Gia_Man_t *p, Gia_Man_t *pGia)
Definition giaIf.c:2370
Gia_Man_t * Gia_ManDupNormalize(Gia_Man_t *p, int fHashMapping)
Definition giaTim.c:139
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition giaUtil.c:190
struct Jf_Par_t_ Jf_Par_t
Definition gia.h:333
#define Gia_ManForEachCo(p, pObj, i)
Definition gia.h:1236
#define Gia_ManForEachCi(p, pObj, i)
Definition gia.h:1228
#define Gia_CellForEachFanin(p, i, iFanLit, k)
Definition gia.h:1183
void Gia_ManSetPhase(Gia_Man_t *p)
Definition giaUtil.c:420
#define Gia_ManForEachObjWithBoxes(p, pObj, i)
Definition gia.h:1261
Gia_Man_t * Gia_ManDupUnnormalize(Gia_Man_t *p)
Definition giaTim.c:382
#define Gia_ManForEachObjReverseWithBoxes(p, pObj, i)
Definition gia.h:1263
#define Gia_ManForEachAndId(p, i)
Definition gia.h:1216
#define Gia_ManForEachCiId(p, Id, i)
Definition gia.h:1230
#define Gia_ManForEachCoWithBoxes(p, pObj, i)
Definition gia.h:1267
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
word M(word f1, word f2, int n)
Definition kitPerm.c:240
struct Mio_LibraryStruct_t_ Mio_Library_t
Definition mio.h:42
Mio_Cell2_t * Mio_CollectRootsNewDefault2(int nInputs, int *pnGates, int fVerbose)
Definition mioUtils.c:877
struct Mio_Cell2_t_ Mio_Cell2_t
Definition mio.h:57
void Mio_LibraryMatchesFetch(Mio_Library_t *pLib, Vec_Mem_t **pvTtMem, Vec_Wec_t **pvTt2Match, Mio_Cell2_t **ppCells, int *pnCells, int fPinFilter, int fPinPerm, int fPinQuick)
Definition mioUtils.c:1785
#define SCL_INFINITY
Definition sclCon.h:63
Gia_Rpr_t * pReprs
Definition gia.h:126
Vec_Int_t * vCellMapping
Definition gia.h:139
int * pNexts
Definition gia.h:127
void * pManTime
Definition gia.h:194
int * pRefs
Definition gia.h:118
float MapDelayTarget
Definition gia.h:387
int nReqTimeFlex
Definition gia.h:344
int fPinQuick
Definition gia.h:352
int nRounds
Definition gia.h:339
int fGenCnf
Definition gia.h:360
int nProcNum
Definition gia.h:338
int nRelaxRatio
Definition gia.h:341
int nCutNum
Definition gia.h:337
int nRoundsEla
Definition gia.h:340
int fOptEdge
Definition gia.h:354
int fAreaOnly
Definition gia.h:350
int nCutNumMax
Definition gia.h:373
int fCoarsen
Definition gia.h:357
int nLutSizeMax
Definition gia.h:372
int fPinPerm
Definition gia.h:351
int nLutSize
Definition gia.h:336
int fPinFilter
Definition gia.h:353
int nAreaTuner
Definition gia.h:343
int fVeryVerbose
Definition gia.h:371
int fCutMin
Definition gia.h:358
int fPureAig
Definition gia.h:365
int nCoarseLimit
Definition gia.h:342
int fVerbose
Definition gia.h:370
int nVerbLimit
Definition gia.h:345
int DelayTarget
Definition gia.h:349
float AreaF
Definition mio.h:65
word uTruth
Definition mio.h:67
word AreaW
Definition mio.h:66
char * pName
Definition mio.h:60
unsigned Id
Definition mio.h:62
unsigned nFanins
Definition mio.h:64
int iDelays[6]
Definition mio.h:69
unsigned Phase
Definition giaNf.c:67
unsigned fCompl
Definition giaNf.c:66
unsigned Perm
Definition giaNf.c:68
unsigned iFunc
Definition giaNf.c:58
int Delay
Definition giaNf.c:56
word Sign
Definition giaNf.c:55
int pLeaves[NF_LEAF_MAX+1]
Definition giaNf.c:61
unsigned Useless
Definition giaNf.c:59
float Flow
Definition giaNf.c:57
unsigned nLeaves
Definition giaNf.c:60
Vec_Ptr_t vPages
Definition giaNf.c:100
int nCutUseAll
Definition giaNf.c:118
Vec_Int_t vCutSets
Definition giaNf.c:101
double CutCount[6]
Definition giaNf.c:117
word InvAreaW
Definition giaNf.c:113
abctime clkStart
Definition giaNf.c:116
Nf_Obj_t * pNfObjs
Definition giaNf.c:99
Vec_Wec_t * vTt2Match
Definition giaNf.c:95
int Iter
Definition giaNf.c:109
int iCur
Definition giaNf.c:108
int fUseEla
Definition giaNf.c:110
Vec_Flt_t vCutFlows
Definition giaNf.c:105
Jf_Par_t * pPars
Definition giaNf.c:92
Vec_Mem_t * vTtMem
Definition giaNf.c:94
Vec_Flt_t vFlowRefs
Definition giaNf.c:103
int nCells
Definition giaNf.c:97
Vec_Int_t vRequired
Definition giaNf.c:104
Vec_Int_t vBackup
Definition giaNf.c:107
Vec_Int_t vCutDelays
Definition giaNf.c:106
int nInvs
Definition giaNf.c:111
float InvAreaF
Definition giaNf.c:114
Mio_Cell2_t * pCells
Definition giaNf.c:96
Tim_Man_t * pManTim
Definition giaNf.c:91
Vec_Int_t vMapRefs
Definition giaNf.c:102
Gia_Man_t * pGia
Definition giaNf.c:90
int InvDelayI
Definition giaNf.c:112
unsigned fCompl
Definition giaNf.c:75
unsigned CutH
Definition giaNf.c:74
unsigned fBest
Definition giaNf.c:76
unsigned Gate
Definition giaNf.c:73
float F
Definition giaNf.c:79
Nf_Cfg_t Cfg
Definition giaNf.c:77
int D
Definition giaNf.c:78
Nf_Mat_t M[2][2]
Definition giaNf.c:84
void Tim_ManSetCoArrival(Tim_Man_t *p, int iCo, float Delay)
Definition timTime.c:116
int Tim_ManBoxNum(Tim_Man_t *p)
Definition timMan.c:722
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
int Tim_ManPoNum(Tim_Man_t *p)
Definition timMan.c:714
void Tim_ManSetCiRequired(Tim_Man_t *p, int iCi, float Delay)
Definition timTime.c:135
int Tim_ManPiNum(Tim_Man_t *p)
Definition timMan.c:708
void Tim_ManSetCoRequired(Tim_Man_t *p, int iCo, float Delay)
Definition timTime.c:154
float Tim_ManGetCiArrival(Tim_Man_t *p, int iCi)
Definition timTime.c:174
float Tim_ManGetCoRequired(Tim_Man_t *p, int iCo)
Definition timTime.c:222
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
Definition utilMem.c:35
#define assert(ex)
Definition util_old.h:213
char * memcpy()
char * memset()
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
Definition vecFlt.h:42
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition vecInt.h:72
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition vecWec.h:42
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition vecWrd.h:42