abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaNf.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [giaNf.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Scalable AIG package.]
8 
9  Synopsis [Standard-cell mapper.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: giaNf.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
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 
33 
34 ////////////////////////////////////////////////////////////////////////
35 /// DECLARATIONS ///
36 ////////////////////////////////////////////////////////////////////////
37 
38 #define NF_LEAF_MAX 6
39 #define NF_CUT_MAX 32
40 #define NF_NO_LEAF 31
41 #define NF_INFINITY FLT_MAX
42 
43 enum { NF_ANDOR = 1, NF_XOR = 2, NF_PRIME = 3 };
44 
45 typedef struct Nf_Cut_t_ Nf_Cut_t;
46 struct Nf_Cut_t_
47 {
48  word Sign; // signature
49  int Delay; // delay
50  float Flow; // flow
51  unsigned iFunc : 26; // function
52  unsigned Useless : 1; // function
53  unsigned nLeaves : 5; // leaf number (NF_NO_LEAF)
54  int pLeaves[NF_LEAF_MAX+1]; // leaves
55 };
56 typedef struct Nf_Mat_t_ Nf_Mat_t;
57 struct Nf_Mat_t_
58 {
59  unsigned Gate : 20; // gate
60  unsigned CutH : 10; // cut handle
61  unsigned fCompl : 1; // complemented
62  unsigned fBest : 1; // best cut
63  int Conf; // input literals
64  float D; // delay
65  float A; // area
66 };
67 typedef struct Nf_Obj_t_ Nf_Obj_t;
68 struct Nf_Obj_t_
69 {
70  Nf_Mat_t M[2][2]; // del/area (2x)
71 };
72 typedef struct Nf_Man_t_ Nf_Man_t;
73 struct Nf_Man_t_
74 {
75  // user data
76  Gia_Man_t * pGia; // derived manager
77  Jf_Par_t * pPars; // parameters
78  // matching
79  Vec_Mem_t * vTtMem; // truth tables
80  Vec_Wec_t * vTt2Match; // matches for truth tables
81  Vec_Str_t * vMemStore; // memory for matches
82  Mio_Cell_t * pCells; // library gates
83  int nCells; // library gate count
84  // cut data
85  Nf_Obj_t * pNfObjs; // best cuts
86  Vec_Ptr_t vPages; // cut memory
87  Vec_Int_t vCutSets; // cut offsets
88  Vec_Int_t vMapRefs; // mapping refs (2x)
89  Vec_Flt_t vFlowRefs; // flow refs (2x)
90  Vec_Flt_t vRequired; // required times (2x)
91  Vec_Flt_t vCutFlows; // temporary cut area
92  Vec_Int_t vCutDelays; // temporary cut delay
93  Vec_Int_t vBackup; // backup literals
94  Vec_Int_t vBackup2; // backup literals
95  int iCur; // current position
96  int Iter; // mapping iterations
97  int fUseEla; // use exact area
98  int nInvs; // the inverter count
99  float InvDelay; // inverter delay
100  float InvArea; // inverter area
101  // statistics
102  abctime clkStart; // starting time
103  double CutCount[6]; // cut counts
104  int nCutUseAll; // objects with useful cuts
105 };
106 
107 static inline Nf_Obj_t * Nf_ManObj( Nf_Man_t * p, int i ) { return p->pNfObjs + i; }
108 static inline Mio_Cell_t* Nf_ManCell( Nf_Man_t * p, int i ) { return p->pCells + i; }
109 static inline int * Nf_ManCutSet( Nf_Man_t * p, int i ) { return (int *)Vec_PtrEntry(&p->vPages, i >> 16) + (i & 0xFFFF); }
110 static inline int Nf_ObjCutSetId( Nf_Man_t * p, int i ) { return Vec_IntEntry( &p->vCutSets, i ); }
111 static inline int * Nf_ObjCutSet( Nf_Man_t * p, int i ) { return Nf_ManCutSet(p, Nf_ObjCutSetId(p, i)); }
112 static inline int Nf_ObjHasCuts( Nf_Man_t * p, int i ) { return (int)(Vec_IntEntry(&p->vCutSets, i) > 0); }
113 static inline int * Nf_ObjCutBest( Nf_Man_t * p, int i ) { return NULL; }
114 static inline int Nf_ObjCutUseless( Nf_Man_t * p, int TruthId ) { return (int)(TruthId >= Vec_WecSize(p->vTt2Match)); }
115 
116 static inline float Nf_ObjCutFlow( Nf_Man_t * p, int i ) { return Vec_FltEntry(&p->vCutFlows, i); }
117 static inline int Nf_ObjCutDelay( Nf_Man_t * p, int i ) { return Vec_IntEntry(&p->vCutDelays, i); }
118 static inline void Nf_ObjSetCutFlow( Nf_Man_t * p, int i, float a ) { Vec_FltWriteEntry(&p->vCutFlows, i, a); }
119 static inline void Nf_ObjSetCutDelay( Nf_Man_t * p, int i, int d ) { Vec_IntWriteEntry(&p->vCutDelays, i, d); }
120 
121 static inline int Nf_ObjMapRefNum( Nf_Man_t * p, int i, int c ) { return Vec_IntEntry(&p->vMapRefs, Abc_Var2Lit(i,c)); }
122 static inline int Nf_ObjMapRefInc( Nf_Man_t * p, int i, int c ) { return (*Vec_IntEntryP(&p->vMapRefs, Abc_Var2Lit(i,c)))++; }
123 static inline int Nf_ObjMapRefDec( Nf_Man_t * p, int i, int c ) { return --(*Vec_IntEntryP(&p->vMapRefs, Abc_Var2Lit(i,c))); }
124 static inline float Nf_ObjFlowRefs( Nf_Man_t * p, int i, int c ) { return Vec_FltEntry(&p->vFlowRefs, Abc_Var2Lit(i,c)); }
125 static inline float Nf_ObjRequired( Nf_Man_t * p, int i, int c ) { return Vec_FltEntry(&p->vRequired, Abc_Var2Lit(i,c)); }
126 static inline void Nf_ObjSetRequired(Nf_Man_t * p,int i, int c, float f) { Vec_FltWriteEntry(&p->vRequired, Abc_Var2Lit(i,c), f); }
127 static inline void Nf_ObjUpdateRequired(Nf_Man_t * p,int i, int c, float f) { if (Nf_ObjRequired(p, i, c) > f) Nf_ObjSetRequired(p, i, c, f); }
128 
129 static inline Nf_Mat_t * Nf_ObjMatchD( Nf_Man_t * p, int i, int c ) { return &Nf_ManObj(p, i)->M[c][0]; }
130 static inline Nf_Mat_t * Nf_ObjMatchA( Nf_Man_t * p, int i, int c ) { return &Nf_ManObj(p, i)->M[c][1]; }
131 
132 static inline Nf_Mat_t * Nf_ObjMatchBest( Nf_Man_t * p, int i, int c )
133 {
134  Nf_Mat_t * pD = Nf_ObjMatchD(p, i, c);
135  Nf_Mat_t * pA = Nf_ObjMatchA(p, i, c);
136  assert( pD->fBest != pA->fBest );
137  assert( Nf_ObjMapRefNum(p, i, c) > 0 );
138  if ( pA->fBest )
139  return pA;
140  if ( pD->fBest )
141  return pD;
142  return NULL;
143 }
144 
145 static inline int Nf_CutSize( int * pCut ) { return pCut[0] & NF_NO_LEAF; }
146 static inline int Nf_CutFunc( int * pCut ) { return ((unsigned)pCut[0] >> 5); }
147 static inline int * Nf_CutLeaves( int * pCut ) { return pCut + 1; }
148 static inline int Nf_CutSetBoth( int n, int f ) { return n | (f << 5); }
149 static inline int Nf_CutIsTriv( int * pCut, int i ) { return Nf_CutSize(pCut) == 1 && pCut[1] == i; }
150 static inline int Nf_CutHandle( int * pCutSet, int * pCut ) { assert( pCut > pCutSet ); return pCut - pCutSet; }
151 static inline int * Nf_CutFromHandle( int * pCutSet, int h ) { assert( h > 0 ); return pCutSet + h; }
152 static inline int Nf_CutConfLit( int Conf, int i ) { return 15 & (Conf >> (i << 2)); }
153 static inline int Nf_CutConfVar( int Conf, int i ) { return Abc_Lit2Var( Nf_CutConfLit(Conf, i) ); }
154 static inline int Nf_CutConfC( int Conf, int i ) { return Abc_LitIsCompl( Nf_CutConfLit(Conf, i) ); }
155 
156 #define Nf_SetForEachCut( pList, pCut, i ) for ( i = 0, pCut = pList + 1; i < pList[0]; i++, pCut += Nf_CutSize(pCut) + 1 )
157 #define Nf_ObjForEachCut( pCuts, i, nCuts ) for ( i = 0, i < nCuts; i++ )
158 #define Nf_CutForEachLit( pCut, Conf, iLit, i ) for ( i = 0; i < Nf_CutSize(pCut) && (iLit = Abc_Lit2LitV(Nf_CutLeaves(pCut), Nf_CutConfLit(Conf, i))); i++ )
159 #define Nf_CutForEachVar( pCut, Conf, iVar, c, i ) for ( i = 0; i < Nf_CutSize(pCut) && (iVar = Nf_CutLeaves(pCut)[Nf_CutConfVar(Conf, i)]) && ((c = Nf_CutConfC(Conf, i)), 1); i++ )
160 
161 /*
162 Three types of config:
163 <match> : <gate> <compl> <type> <offset>
164 <type> : AND/OR | XOR | prime
165 <offset> : <record>
166 <record>
167 - XOR : <array>
168 - prime : <array>, ... <array>
169 - AND/OR : <num_configs>, <config>, ... <config>
170 <config> : <num_entries>, <num_neg_entries>, <array>
171 <array> : <entry>, ...., <entry> (sorted by increasing order of arrivals)
172 */
173 
174 ////////////////////////////////////////////////////////////////////////
175 /// FUNCTION DEFINITIONS ///
176 ////////////////////////////////////////////////////////////////////////
177 
178 /**Function*************************************************************
179 
180  Synopsis [Sort inputs by delay.]
181 
182  Description []
183 
184  SideEffects []
185 
186  SeeAlso []
187 
188 ***********************************************************************/
189 static inline void Nf_StoSelectSort( int * pArray, int nSize, Mio_Cell_t * pCell )
190 {
191  int i, j, best_i;
192  for ( i = 0; i < nSize-1; i++ )
193  {
194  best_i = i;
195  for ( j = i+1; j < nSize; j++ )
196  if ( pCell->Delays[Abc_Lit2Var(pArray[j])] < pCell->Delays[Abc_Lit2Var(pArray[best_i])] )
197  best_i = j;
198  if ( i != best_i )
199  ABC_SWAP( int, pArray[i], pArray[best_i] );
200  }
201 }
202 static inline void Nf_StoSelectSortLit( int * pArray, int nSize, Mio_Cell_t * pCell )
203 {
204  int i, j, best_i;
205  for ( i = 0; i < nSize-1; i++ )
206  {
207  best_i = i;
208  for ( j = i+1; j < nSize; j++ )
209  if ( Abc_LitIsCompl(pArray[j]) > Abc_LitIsCompl(pArray[best_i]) ||
210  (Abc_LitIsCompl(pArray[j]) == Abc_LitIsCompl(pArray[best_i]) &&
211  pCell->Delays[Abc_Lit2Var(pArray[j])] < pCell->Delays[Abc_Lit2Var(pArray[best_i])]) )
212  best_i = j;
213  if ( i != best_i )
214  ABC_SWAP( int, pArray[i], pArray[best_i] );
215  }
216 }
217 void Nf_StoCreateGateAdd( Nf_Man_t * pMan, word uTruth, int * pFans, int nFans, int CellId, int Type )
218 {
219  Vec_Int_t * vArray;
220  int i, fCompl = (int)(uTruth & 1);
221  word uFunc = fCompl ? ~uTruth : uTruth;
222  int iFunc = Vec_MemHashInsert( pMan->vTtMem, &uFunc );
223  if ( iFunc == Vec_WecSize(pMan->vTt2Match) )
224  Vec_WecPushLevel( pMan->vTt2Match );
225  vArray = Vec_WecEntry( pMan->vTt2Match, iFunc );
226  Vec_IntPush( vArray, (CellId << 8) | (Type << 4) | fCompl );
227  Vec_IntPush( vArray, Vec_StrSize(pMan->vMemStore) );
228  if ( Type == NF_ANDOR )
229  return;
230  for ( i = 0; i < nFans; i++ )
231  Vec_StrPush( pMan->vMemStore, (char)pFans[i] );
232 }
233 
234 /**Function*************************************************************
235 
236  Synopsis []
237 
238  Description []
239 
240  SideEffects []
241 
242  SeeAlso []
243 
244 ***********************************************************************/
245 int Nf_StoBuildDsdAnd_rec( Nf_Man_t * pMan, Mio_Cell_t * pCell, char * pStr, char ** p, int * pMatches,
246  int pGroups[NF_LEAF_MAX][NF_LEAF_MAX], int * nGroupSizes, int * pnGroups )
247 {
248  int fCompl = 0;
249  if ( **p == '!' )
250  (*p)++, fCompl = 1;
251  if ( **p >= 'a' && **p < 'a' + NF_LEAF_MAX ) // var
252 // return Abc_Var2Lit( **p - 'a', fCompl );
253  return Abc_Var2Lit( **p - 'a', 0 );
254  if ( **p == '(' ) // and/or
255  {
256  char * q = pStr + pMatches[ *p - pStr ];
257  int pFans[NF_LEAF_MAX], nFans = 0;
258  assert( **p == '(' && *q == ')' );
259  for ( (*p)++; *p < q; (*p)++ )
260  {
261  int Value = Nf_StoBuildDsdAnd_rec( pMan, pCell, pStr, p, pMatches, pGroups, nGroupSizes, pnGroups );
262  if ( Value == -1 )
263  continue;
264  pFans[nFans++] = Value;
265  }
266  // collect
267  if ( nFans > 0 )
268  {
269  memcpy( pGroups[*pnGroups], pFans, sizeof(int) * nFans );
270  nGroupSizes[*pnGroups] = nFans;
271  (*pnGroups)++;
272  }
273  assert( *p == q );
274  return -1;
275  }
276  assert( 0 );
277  return 0;
278 }
279 int Nf_StoBuildDsdAnd( Nf_Man_t * pMan, Mio_Cell_t * pCell, char * p )
280 {
281  int pGroups[NF_LEAF_MAX][NF_LEAF_MAX], pGroups2[NF_LEAF_MAX][NF_LEAF_MAX];
282  int nGroupSizes[NF_LEAF_MAX], nGroupInvs[NF_LEAF_MAX], Phases[NF_LEAF_MAX];
283  int nGroups = 0, nVars = 0, nConfigs = 1;
284  int i, k, c, Res, fCompl = 0;
285  char ** pp = &p;
286  word uTruth;
287  assert( *(p+1) != 0 );
288  if ( *p == '!' )
289  (*pp)++, fCompl = 1;
290  assert( **pp != '!' );
291  Res = Nf_StoBuildDsdAnd_rec( pMan, pCell, p, pp, Dau_DsdComputeMatches(p), pGroups, nGroupSizes, &nGroups );
292  assert( Res == -1 );
293  assert( *++p == 0 );
294  // create groups
295  for ( i = 0; i < nGroups; i++ )
296  {
297  nVars += nGroupSizes[i];
298  nConfigs *= (1 << nGroupSizes[i]);
299  }
300  assert( nVars == (int)pCell->nFanins );
301  // iterate through phase assignments
302  for ( c = 0; c < nConfigs; c++ )
303  {
304  int Start = c;
305  for ( i = nGroups - 1; i >= 0; i-- )
306  {
307  Phases[i] = Start % (1 << nGroupSizes[i]);
308  Start /= (1 << nGroupSizes[i]);
309  memcpy( pGroups2[i], pGroups[i], sizeof(int) * nGroupSizes[i] );
310 // printf( "%d ", Phases[i] );
311  }
312 // printf( "\n" );
313 
314  // create configuration
315  uTruth = pCell->uTruth;
316  for ( i = 0; i < nGroups; i++ )
317  {
318  nGroupInvs[i] = 0;
319  for ( k = 0; k < nGroupSizes[i]; k++ )
320  if ( (Phases[i] >> k) & 1 )
321  {
322  pGroups2[i][k] = Abc_LitNot(pGroups2[i][k]);
323  uTruth = Abc_Tt6Flip( uTruth, Abc_Lit2Var(pGroups2[i][k]) );
324  nGroupInvs[i]++;
325  }
326 /*
327  if ( pCell->nFanins == 4 && nGroups == 1 )
328  {
329  printf( "Group before:\n" );
330  for ( k = 0; k < nGroupSizes[i]; k++ )
331  printf( "%d %.2f\n", pGroups2[i][k], pCell->Delays[Abc_Lit2Var(pGroups2[i][k])] );
332  }
333 */
334 // Nf_StoSelectSortLit( pGroups2[i], nGroupSizes[i], pCell );
335 /*
336  if ( pCell->nFanins == 4 && nGroups == 1 )
337  {
338  printf( "Group after:\n" );
339  for ( k = 0; k < nGroupSizes[i]; k++ )
340  printf( "%d %.2f\n", pGroups2[i][k], pCell->Delays[Abc_Lit2Var(pGroups2[i][k])] );
341  printf( "\n" );
342  }
343 */
344  }
345  // save
346  Nf_StoCreateGateAdd( pMan, uTruth, NULL, -1, pCell->Id, NF_ANDOR );
347  Vec_StrPush( pMan->vMemStore, (char)nGroups );
348  for ( i = 0; i < nGroups; i++ )
349  for ( k = 0; k < nGroupSizes[i]; k++ )
350  {
351  Vec_StrPush( pMan->vMemStore, (char)nGroupSizes[i] );
352  Vec_StrPush( pMan->vMemStore, (char)nGroupInvs[i] );
353  for ( k = 0; k < nGroupSizes[i]; k++ )
354  Vec_StrPush( pMan->vMemStore, (char)pGroups2[i][k] );
355  }
356  }
357  return Res;
358 }
359 
360 int Nf_StoCheckDsdAnd_rec( char * pStr, char ** p, int * pMatches )
361 {
362  if ( **p == '!' )
363  (*p)++;
364  if ( **p >= 'a' && **p < 'a' + NF_LEAF_MAX ) // var
365  return 1;
366  if ( **p == '(' ) // and/or
367  {
368  char * q = pStr + pMatches[ *p - pStr ];
369  assert( **p == '(' && *q == ')' );
370  for ( (*p)++; *p < q; (*p)++ )
371  if ( Nf_StoCheckDsdAnd_rec(pStr, p, pMatches) != 1 )
372  return 0;
373  assert( *p == q );
374  return 1;
375  }
376  return 0;
377 }
378 int Nf_StoCheckDsdAnd( char * p )
379 {
380  int Res;
381  assert( *(p+1) != 0 );
382  Res = Nf_StoCheckDsdAnd_rec( p, &p, Dau_DsdComputeMatches(p) );
383 // assert( *++p == 0 );
384  return Res;
385 }
386 
387 int Nf_StoCheckDsdXor_rec( char * pStr, char ** p, int * pMatches )
388 {
389  int Value, fCompl = 0;
390  if ( **p == '!' )
391  (*p)++, fCompl ^= 1;
392  if ( **p >= 'a' && **p < 'a' + NF_LEAF_MAX ) // var
393  return fCompl;
394  if ( **p == '[' ) // xor
395  {
396  char * q = pStr + pMatches[ *p - pStr ];
397  assert( **p == '[' && *q == ']' );
398  for ( (*p)++; *p < q; (*p)++ )
399  {
400  Value = Nf_StoCheckDsdXor_rec( pStr, p, pMatches );
401  if ( Value == -1 )
402  return -1;
403  fCompl ^= Value;
404  }
405  assert( *p == q );
406  return fCompl;
407  }
408  return -1;
409 }
410 int Nf_StoCheckDsdXor( char * p )
411 {
412  int Res;
413  assert( *(p+1) != 0 );
414  Res = Nf_StoCheckDsdXor_rec( p, &p, Dau_DsdComputeMatches(p) );
415 // assert( *++p == 0 );
416  return Res;
417 }
418 
419 /**Function*************************************************************
420 
421  Synopsis []
422 
423  Description []
424 
425  SideEffects []
426 
427  SeeAlso []
428 
429 ***********************************************************************/
430 void Nf_StoCreateGateNonDsd( Nf_Man_t * pMan, Mio_Cell_t * pCell, int ** pComp, int ** pPerm, int * pnPerms )
431 {
432  int Perm[NF_LEAF_MAX], * Perm1, * Perm2;
433  int nPerms = pnPerms[pCell->nFanins];
434  int nMints = (1 << pCell->nFanins);
435  word tCur, tTemp1, tTemp2;
436  int i, p, c;
437  for ( i = 0; i < (int)pCell->nFanins; i++ )
438  Perm[i] = Abc_Var2Lit( i, 0 );
439  tCur = tTemp1 = pCell->uTruth;
440  for ( p = 0; p < nPerms; p++ )
441  {
442  tTemp2 = tCur;
443  for ( c = 0; c < nMints; c++ )
444  {
445  Nf_StoCreateGateAdd( pMan, tCur, Perm, pCell->nFanins, pCell->Id, NF_PRIME );
446  // update
447  tCur = Abc_Tt6Flip( tCur, pComp[pCell->nFanins][c] );
448  Perm1 = Perm + pComp[pCell->nFanins][c];
449  *Perm1 = Abc_LitNot( *Perm1 );
450  }
451  assert( tTemp2 == tCur );
452  // update
453  tCur = Abc_Tt6SwapAdjacent( tCur, pPerm[pCell->nFanins][p] );
454  Perm1 = Perm + pPerm[pCell->nFanins][p];
455  Perm2 = Perm1 + 1;
456  ABC_SWAP( int, *Perm1, *Perm2 );
457  }
458  assert( tTemp1 == tCur );
459 }
460 void Nf_StoCreateGateDsd( Nf_Man_t * pMan, Mio_Cell_t * pCell, int ** pComp, int ** pPerm, int * pnPerms )
461 {
462 /*
463  char pDsd[1000];
464  int i, Value, Perm[NF_LEAF_MAX];
465  word uTruth = pCell->uTruth;
466  int nSizeNonDec = Dau_DsdDecompose( &uTruth, pCell->nFanins, 0, 0, pDsd );
467  assert( pCell->nFanins > 1 );
468  if ( nSizeNonDec == 0 )
469  {
470  if ( Nf_StoCheckDsdAnd(pDsd) )
471  {
472  Nf_StoBuildDsdAnd( pMan, pCell, pDsd );
473  return;
474  }
475  Value = Nf_StoCheckDsdXor(pDsd);
476  if ( Value >= 0 )
477  {
478  for ( i = 0; i < (int)pCell->nFanins; i++ )
479  Perm[i] = Abc_Var2Lit(i, 0);
480 // Nf_StoSelectSort( Perm, pCell->nFanins, pCell );
481  Nf_StoCreateGateAdd( pMan, pCell->uTruth, Perm, pCell->nFanins, pCell->Id, NF_XOR );
482  return;
483  }
484  }
485 */
486  Nf_StoCreateGateNonDsd( pMan, pCell, pComp, pPerm, pnPerms );
487 }
488 void Nf_StoDeriveMatches( Nf_Man_t * p, int fVerbose )
489 {
490 // abctime clk = Abc_Clock();
491  int * pComp[7];
492  int * pPerm[7];
493  int nPerms[7], i;
494  for ( i = 2; i <= 6; i++ )
495  pComp[i] = Extra_GreyCodeSchedule( i );
496  for ( i = 2; i <= 6; i++ )
497  pPerm[i] = Extra_PermSchedule( i );
498  for ( i = 2; i <= 6; i++ )
499  nPerms[i] = Extra_Factorial( i );
500  p->pCells = Mio_CollectRootsNewDefault( 6, &p->nCells, fVerbose );
501  for ( i = 4; i < p->nCells; i++ )
502  Nf_StoCreateGateDsd( p, p->pCells + i, pComp, pPerm, nPerms );
503  for ( i = 2; i <= 6; i++ )
504  ABC_FREE( pComp[i] );
505  for ( i = 2; i <= 6; i++ )
506  ABC_FREE( pPerm[i] );
507 // Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
508 }
509 void Nf_StoPrintOne( Nf_Man_t * p, int Count, int t, int i, Mio_Cell_t * pC, int Type, int fCompl, char * pInfo )
510 {
511  word * pTruth = Vec_MemReadEntry(p->vTtMem, t);
512  int k, nSuppSize = Abc_TtSupportSize(pTruth, 6);
513  printf( "%6d : ", Count++ );
514  printf( "%6d : ", t );
515  printf( "%6d : ", i/2 );
516  printf( "Gate %16s ", pC->pName );
517  printf( "Inputs = %d ", pC->nFanins );
518  if ( Type == NF_PRIME )
519  printf( "prime" );
520  else if ( Type == NF_XOR )
521  printf( "xor " );
522  else if ( Type == NF_ANDOR )
523  printf( "andor" );
524  else assert( 0 );
525  if ( fCompl )
526  printf( " compl " );
527  else
528  printf( " " );
529  if ( Type == NF_PRIME || Type == NF_XOR )
530  {
531  for ( k = 0; k < (int)pC->nFanins; k++ )
532  {
533  int fComplF = Abc_LitIsCompl((int)pInfo[k]);
534  int iFanin = Abc_Lit2Var((int)pInfo[k]);
535  printf( "%c", 'a' + iFanin - fComplF * ('a' - 'A') );
536  }
537  }
538  else if ( Type == NF_ANDOR )
539  {
540  int g, nGroups = (int)*pInfo++;
541  for ( g = 0; g < nGroups; g++ )
542  {
543  int nSizeAll = (int)*pInfo++;
544  int nSizeNeg = (int)*pInfo++;
545  printf( "{" );
546  for ( k = 0; k < nSizeAll; k++ )
547  {
548  int fComplF = Abc_LitIsCompl((int)pInfo[k]);
549  int iFanin = Abc_Lit2Var((int)pInfo[k]);
550  printf( "%c", 'a' + iFanin - fComplF * ('a' - 'A') );
551  }
552  printf( "}" );
553  pInfo += nSizeAll; nSizeNeg = 0;
554  }
555  }
556  else assert( 0 );
557  printf( " " );
558  Dau_DsdPrintFromTruth( pTruth, nSuppSize );
559 }
560 void Nf_StoPrint( Nf_Man_t * p, int fVerbose )
561 {
562  int t, i, Info, Offset, Count = 0, CountMux = 0;
563  for ( t = 2; t < Vec_WecSize(p->vTt2Match); t++ )
564  {
565  Vec_Int_t * vArr = Vec_WecEntry( p->vTt2Match, t );
566  Vec_IntForEachEntryDouble( vArr, Info, Offset, i )
567  {
568  Mio_Cell_t*pC = p->pCells + (Info >> 8);
569  int Type = (Info >> 4) & 15;
570  int fCompl = (Info & 1);
571  char * pInfo = Vec_StrEntryP( p->vMemStore, Offset );
572  if ( Type == NF_PRIME && pC->nFanins != 3 )
573  {
574  Count++;
575  CountMux++;
576  continue;
577  }
578  if ( !fVerbose )
579  {
580  Count++;
581  continue;
582  }
583  Nf_StoPrintOne( p, Count, t, i, pC, Type, fCompl, pInfo );
584  }
585  }
586  printf( "Gates = %d. Truths = %d. Matches = %d. MatchesPrime = %d. Size = %d.\n",
587  p->nCells, Vec_MemEntryNum(p->vTtMem), Count, CountMux, Vec_StrSize(p->vMemStore) );
588 }
589 /*
590 void Nf_ManPrepareLibraryTest()
591 {
592  int fVerbose = 0;
593  abctime clk = Abc_Clock();
594  Nf_Man_t * p;
595  p = Nf_StoCreate( NULL, NULL, fVerbose );
596  Nf_StoPrint( p, fVerbose );
597  Nf_StoDelete(p);
598  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
599 }
600 */
601 
602 
603 
604 /**Function*************************************************************
605 
606  Synopsis []
607 
608  Description []
609 
610  SideEffects []
611 
612  SeeAlso []
613 
614 ***********************************************************************/
616 {
617  extern void Mf_ManSetFlowRefs( Gia_Man_t * p, Vec_Int_t * vRefs );
618  Vec_Int_t * vFlowRefs;
619  Nf_Man_t * p;
620  int i, Entry;
621  assert( pPars->nCutNum > 1 && pPars->nCutNum <= NF_CUT_MAX );
622  assert( pPars->nLutSize > 1 && pPars->nLutSize <= NF_LEAF_MAX );
623  ABC_FREE( pGia->pRefs );
624  Vec_IntFreeP( &pGia->vCellMapping );
625  if ( Gia_ManHasChoices(pGia) )
626  Gia_ManSetPhase(pGia);
627  // create
628  p = ABC_CALLOC( Nf_Man_t, 1 );
629  p->clkStart = Abc_Clock();
630  p->pGia = pGia;
631  p->pPars = pPars;
632  p->pNfObjs = ABC_CALLOC( Nf_Obj_t, Gia_ManObjNum(pGia) );
633  p->iCur = 2;
634  // other
635  Vec_PtrGrow( &p->vPages, 256 ); // cut memory
636  Vec_IntFill( &p->vMapRefs, 2*Gia_ManObjNum(pGia), 0 ); // mapping refs (2x)
637  Vec_FltFill( &p->vFlowRefs, 2*Gia_ManObjNum(pGia), 0 ); // flow refs (2x)
638  Vec_FltFill( &p->vRequired, 2*Gia_ManObjNum(pGia), NF_INFINITY ); // required times (2x)
639  Vec_IntFill( &p->vCutSets, Gia_ManObjNum(pGia), 0 ); // cut offsets
640  Vec_FltFill( &p->vCutFlows, Gia_ManObjNum(pGia), 0 ); // cut area
641  Vec_IntFill( &p->vCutDelays,Gia_ManObjNum(pGia), 0 ); // cut delay
642  Vec_IntGrow( &p->vBackup, 1000 );
643  Vec_IntGrow( &p->vBackup2, 1000 );
644  // references
645  vFlowRefs = Vec_IntAlloc(0);
646  Mf_ManSetFlowRefs( pGia, vFlowRefs );
647  Vec_IntForEachEntry( vFlowRefs, Entry, i )
648  {
649  Vec_FltWriteEntry( &p->vFlowRefs, 2*i, /*0.5* */Entry );
650  Vec_FltWriteEntry( &p->vFlowRefs, 2*i+1, /*0.5* */Entry );
651  }
652  Vec_IntFree(vFlowRefs);
653  // matching
654  p->vTtMem = Vec_MemAllocForTT( 6, 0 );
655  p->vTt2Match = Vec_WecAlloc( 1000 );
656  p->vMemStore = Vec_StrAlloc( 10000 );
660  Nf_StoDeriveMatches( p, 0 );//pPars->fVerbose );
661  p->InvDelay = p->pCells[3].Delays[0];
662  p->InvArea = p->pCells[3].Area;
663  Nf_ObjMatchD(p, 0, 0)->Gate = 0;
664  Nf_ObjMatchD(p, 0, 1)->Gate = 1;
665  // prepare cuts
666  return p;
667 }
669 {
670  Vec_PtrFreeData( &p->vPages );
671  ABC_FREE( p->vPages.pArray );
672  ABC_FREE( p->vMapRefs.pArray );
673  ABC_FREE( p->vFlowRefs.pArray );
674  ABC_FREE( p->vRequired.pArray );
675  ABC_FREE( p->vCutSets.pArray );
676  ABC_FREE( p->vCutFlows.pArray );
677  ABC_FREE( p->vCutDelays.pArray );
678  ABC_FREE( p->vBackup.pArray );
679  ABC_FREE( p->vBackup2.pArray );
680  ABC_FREE( p->pNfObjs );
681  // matching
682  Vec_WecFree( p->vTt2Match );
683  Vec_MemHashFree( p->vTtMem );
684  Vec_MemFree( p->vTtMem );
685  Vec_StrFree( p->vMemStore );
686  ABC_FREE( p->pCells );
687  ABC_FREE( p );
688 }
689 
690 
691 
692 
693 /**Function*************************************************************
694 
695  Synopsis []
696 
697  Description []
698 
699  SideEffects []
700 
701  SeeAlso []
702 
703 ***********************************************************************/
704 static 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 )
705 {
706 // extern int Nf_ManTruthCanonicize( word * t, int nVars );
707  int nOldSupp = pCutR->nLeaves, truthId, fCompl; word t;
708  word t0 = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut0->iFunc));
709  word t1 = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut1->iFunc));
710  if ( Abc_LitIsCompl(pCut0->iFunc) ^ fCompl0 ) t0 = ~t0;
711  if ( Abc_LitIsCompl(pCut1->iFunc) ^ fCompl1 ) t1 = ~t1;
712  t0 = Abc_Tt6Expand( t0, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
713  t1 = Abc_Tt6Expand( t1, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
714  t = fIsXor ? t0 ^ t1 : t0 & t1;
715  if ( (fCompl = (int)(t & 1)) ) t = ~t;
716  pCutR->nLeaves = Abc_Tt6MinBase( &t, pCutR->pLeaves, pCutR->nLeaves );
717  assert( (int)(t & 1) == 0 );
718  truthId = Vec_MemHashInsert(p->vTtMem, &t);
719  pCutR->iFunc = Abc_Var2Lit( truthId, fCompl );
720  pCutR->Useless = Nf_ObjCutUseless( p, truthId );
721  assert( (int)pCutR->nLeaves <= nOldSupp );
722  return (int)pCutR->nLeaves < nOldSupp;
723 }
724 static 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 )
725 {
726  int nOldSupp = pCutR->nLeaves, truthId, fCompl; word t;
727  word t0 = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut0->iFunc));
728  word t1 = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut1->iFunc));
729  word tC = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCutC->iFunc));
730  if ( Abc_LitIsCompl(pCut0->iFunc) ^ fCompl0 ) t0 = ~t0;
731  if ( Abc_LitIsCompl(pCut1->iFunc) ^ fCompl1 ) t1 = ~t1;
732  if ( Abc_LitIsCompl(pCutC->iFunc) ^ fComplC ) tC = ~tC;
733  t0 = Abc_Tt6Expand( t0, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
734  t1 = Abc_Tt6Expand( t1, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
735  tC = Abc_Tt6Expand( tC, pCutC->pLeaves, pCutC->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
736  t = (tC & t1) | (~tC & t0);
737  if ( (fCompl = (int)(t & 1)) ) t = ~t;
738  pCutR->nLeaves = Abc_Tt6MinBase( &t, pCutR->pLeaves, pCutR->nLeaves );
739  assert( (int)(t & 1) == 0 );
740  truthId = Vec_MemHashInsert(p->vTtMem, &t);
741  pCutR->iFunc = Abc_Var2Lit( truthId, fCompl );
742  pCutR->Useless = Nf_ObjCutUseless( p, truthId );
743  assert( (int)pCutR->nLeaves <= nOldSupp );
744  return (int)pCutR->nLeaves < nOldSupp;
745 }
746 
747 
748 /**Function*************************************************************
749 
750  Synopsis []
751 
752  Description []
753 
754  SideEffects []
755 
756  SeeAlso []
757 
758 ***********************************************************************/
759 static inline int Nf_CutCountBits( word i )
760 {
761  i = i - ((i >> 1) & 0x5555555555555555);
762  i = (i & 0x3333333333333333) + ((i >> 2) & 0x3333333333333333);
763  i = ((i + (i >> 4)) & 0x0F0F0F0F0F0F0F0F);
764  return (i*(0x0101010101010101))>>56;
765 }
766 static inline word Nf_CutGetSign( int * pLeaves, int nLeaves )
767 {
768  word Sign = 0; int i;
769  for ( i = 0; i < nLeaves; i++ )
770  Sign |= ((word)1) << (pLeaves[i] & 0x3F);
771  return Sign;
772 }
773 static inline int Nf_CutCreateUnit( Nf_Cut_t * p, int i )
774 {
775  p->Delay = 0;
776  p->Flow = 0;
777  p->iFunc = 2;
778  p->nLeaves = 1;
779  p->pLeaves[0] = i;
780  p->Sign = ((word)1) << (i & 0x3F);
781  return 1;
782 }
783 static inline void Nf_Cutprintf( Nf_Man_t * p, Nf_Cut_t * pCut )
784 {
785  int i, nDigits = Abc_Base10Log(Gia_ManObjNum(p->pGia));
786  printf( "%d {", pCut->nLeaves );
787  for ( i = 0; i < (int)pCut->nLeaves; i++ )
788  printf( " %*d", nDigits, pCut->pLeaves[i] );
789  for ( ; i < (int)p->pPars->nLutSize; i++ )
790  printf( " %*s", nDigits, " " );
791  printf( " } Useless = %d. D = %4d A = %9.4f F = %6d ",
792  pCut->Useless, pCut->Delay, pCut->Flow, pCut->iFunc );
793  if ( p->vTtMem )
795  else
796  printf( "\n" );
797 }
798 static inline int Nf_ManPrepareCuts( Nf_Cut_t * pCuts, Nf_Man_t * p, int iObj, int fAddUnit )
799 {
800  if ( Nf_ObjHasCuts(p, iObj) )
801  {
802  Nf_Cut_t * pMfCut = pCuts;
803  int i, * pCut, * pList = Nf_ObjCutSet(p, iObj);
804  Nf_SetForEachCut( pList, pCut, i )
805  {
806  pMfCut->Delay = 0;
807  pMfCut->Flow = 0;
808  pMfCut->iFunc = Nf_CutFunc( pCut );
809  pMfCut->nLeaves = Nf_CutSize( pCut );
810  pMfCut->Sign = Nf_CutGetSign( pCut+1, Nf_CutSize(pCut) );
811  memcpy( pMfCut->pLeaves, pCut+1, sizeof(int) * Nf_CutSize(pCut) );
812  pMfCut++;
813  }
814  if ( fAddUnit && pCuts->nLeaves > 1 )
815  return pList[0] + Nf_CutCreateUnit( pMfCut, iObj );
816  return pList[0];
817  }
818  return Nf_CutCreateUnit( pCuts, iObj );
819 }
820 static inline int Nf_ManSaveCuts( Nf_Man_t * p, Nf_Cut_t ** pCuts, int nCuts, int fUseful )
821 {
822  int i, * pPlace, iCur, nInts = 1, nCutsNew = 0;
823  for ( i = 0; i < nCuts; i++ )
824  if ( !fUseful || !pCuts[i]->Useless )
825  nInts += pCuts[i]->nLeaves + 1, nCutsNew++;
826  if ( (p->iCur & 0xFFFF) + nInts > 0xFFFF )
827  p->iCur = ((p->iCur >> 16) + 1) << 16;
828  if ( Vec_PtrSize(&p->vPages) == (p->iCur >> 16) )
829  Vec_PtrPush( &p->vPages, ABC_ALLOC(int, (1<<16)) );
830  iCur = p->iCur; p->iCur += nInts;
831  pPlace = Nf_ManCutSet( p, iCur );
832  *pPlace++ = nCutsNew;
833  for ( i = 0; i < nCuts; i++ )
834  if ( !fUseful || !pCuts[i]->Useless )
835  {
836  *pPlace++ = Nf_CutSetBoth( pCuts[i]->nLeaves, pCuts[i]->iFunc );
837  memcpy( pPlace, pCuts[i]->pLeaves, sizeof(int) * pCuts[i]->nLeaves );
838  pPlace += pCuts[i]->nLeaves;
839  }
840  return iCur;
841 }
842 static inline int Nf_ManCountUseful( Nf_Cut_t ** pCuts, int nCuts )
843 {
844  int i, Count = 0;
845  for ( i = 0; i < nCuts; i++ )
846  Count += !pCuts[i]->Useless;
847  return Count;
848 }
849 static inline int Nf_ManCountMatches( Nf_Man_t * p, Nf_Cut_t ** pCuts, int nCuts )
850 {
851  int i, Count = 0;
852  for ( i = 0; i < nCuts; i++ )
853  if ( !pCuts[i]->Useless )
854  Count += Vec_IntSize(Vec_WecEntry(p->vTt2Match, Abc_Lit2Var(pCuts[i]->iFunc))) / 2;
855  return Count;
856 }
857 
858 /**Function*************************************************************
859 
860  Synopsis [Check correctness of cuts.]
861 
862  Description []
863 
864  SideEffects []
865 
866  SeeAlso []
867 
868 ***********************************************************************/
869 static inline int Nf_CutCheck( Nf_Cut_t * pBase, Nf_Cut_t * pCut ) // check if pCut is contained in pBase
870 {
871  int nSizeB = pBase->nLeaves;
872  int nSizeC = pCut->nLeaves;
873  int i, * pB = pBase->pLeaves;
874  int k, * pC = pCut->pLeaves;
875  for ( i = 0; i < nSizeC; i++ )
876  {
877  for ( k = 0; k < nSizeB; k++ )
878  if ( pC[i] == pB[k] )
879  break;
880  if ( k == nSizeB )
881  return 0;
882  }
883  return 1;
884 }
885 static inline int Nf_SetCheckArray( Nf_Cut_t ** ppCuts, int nCuts )
886 {
887  Nf_Cut_t * pCut0, * pCut1;
888  int i, k, m, n, Value;
889  assert( nCuts > 0 );
890  for ( i = 0; i < nCuts; i++ )
891  {
892  pCut0 = ppCuts[i];
893  assert( pCut0->nLeaves <= NF_LEAF_MAX );
894  assert( pCut0->Sign == Nf_CutGetSign(pCut0->pLeaves, pCut0->nLeaves) );
895  // check duplicates
896  for ( m = 0; m < (int)pCut0->nLeaves; m++ )
897  for ( n = m + 1; n < (int)pCut0->nLeaves; n++ )
898  assert( pCut0->pLeaves[m] < pCut0->pLeaves[n] );
899  // check pairs
900  for ( k = 0; k < nCuts; k++ )
901  {
902  pCut1 = ppCuts[k];
903  if ( pCut0 == pCut1 )
904  continue;
905  // check containments
906  Value = Nf_CutCheck( pCut0, pCut1 );
907  assert( Value == 0 );
908  }
909  }
910  return 1;
911 }
912 
913 
914 /**Function*************************************************************
915 
916  Synopsis []
917 
918  Description []
919 
920  SideEffects []
921 
922  SeeAlso []
923 
924 ***********************************************************************/
925 static inline int Nf_CutMergeOrder( Nf_Cut_t * pCut0, Nf_Cut_t * pCut1, Nf_Cut_t * pCut, int nLutSize )
926 {
927  int nSize0 = pCut0->nLeaves;
928  int nSize1 = pCut1->nLeaves;
929  int i, * pC0 = pCut0->pLeaves;
930  int k, * pC1 = pCut1->pLeaves;
931  int c, * pC = pCut->pLeaves;
932  // the case of the largest cut sizes
933  if ( nSize0 == nLutSize && nSize1 == nLutSize )
934  {
935  for ( i = 0; i < nSize0; i++ )
936  {
937  if ( pC0[i] != pC1[i] ) return 0;
938  pC[i] = pC0[i];
939  }
940  pCut->nLeaves = nLutSize;
941  pCut->iFunc = -1;
942  pCut->Sign = pCut0->Sign | pCut1->Sign;
943  return 1;
944  }
945  // compare two cuts with different numbers
946  i = k = c = 0;
947  if ( nSize0 == 0 ) goto FlushCut1;
948  if ( nSize1 == 0 ) goto FlushCut0;
949  while ( 1 )
950  {
951  if ( c == nLutSize ) return 0;
952  if ( pC0[i] < pC1[k] )
953  {
954  pC[c++] = pC0[i++];
955  if ( i >= nSize0 ) goto FlushCut1;
956  }
957  else if ( pC0[i] > pC1[k] )
958  {
959  pC[c++] = pC1[k++];
960  if ( k >= nSize1 ) goto FlushCut0;
961  }
962  else
963  {
964  pC[c++] = pC0[i++]; k++;
965  if ( i >= nSize0 ) goto FlushCut1;
966  if ( k >= nSize1 ) goto FlushCut0;
967  }
968  }
969 
970 FlushCut0:
971  if ( c + nSize0 > nLutSize + i ) return 0;
972  while ( i < nSize0 )
973  pC[c++] = pC0[i++];
974  pCut->nLeaves = c;
975  pCut->iFunc = -1;
976  pCut->Sign = pCut0->Sign | pCut1->Sign;
977  return 1;
978 
979 FlushCut1:
980  if ( c + nSize1 > nLutSize + k ) return 0;
981  while ( k < nSize1 )
982  pC[c++] = pC1[k++];
983  pCut->nLeaves = c;
984  pCut->iFunc = -1;
985  pCut->Sign = pCut0->Sign | pCut1->Sign;
986  return 1;
987 }
988 static inline int Nf_CutMergeOrderMux( Nf_Cut_t * pCut0, Nf_Cut_t * pCut1, Nf_Cut_t * pCut2, Nf_Cut_t * pCut, int nLutSize )
989 {
990  int x0, i0 = 0, nSize0 = pCut0->nLeaves, * pC0 = pCut0->pLeaves;
991  int x1, i1 = 0, nSize1 = pCut1->nLeaves, * pC1 = pCut1->pLeaves;
992  int x2, i2 = 0, nSize2 = pCut2->nLeaves, * pC2 = pCut2->pLeaves;
993  int xMin, c = 0, * pC = pCut->pLeaves;
994  while ( 1 )
995  {
996  x0 = (i0 == nSize0) ? ABC_INFINITY : pC0[i0];
997  x1 = (i1 == nSize1) ? ABC_INFINITY : pC1[i1];
998  x2 = (i2 == nSize2) ? ABC_INFINITY : pC2[i2];
999  xMin = Abc_MinInt( Abc_MinInt(x0, x1), x2 );
1000  if ( xMin == ABC_INFINITY ) break;
1001  if ( c == nLutSize ) return 0;
1002  pC[c++] = xMin;
1003  if (x0 == xMin) i0++;
1004  if (x1 == xMin) i1++;
1005  if (x2 == xMin) i2++;
1006  }
1007  pCut->nLeaves = c;
1008  pCut->iFunc = -1;
1009  pCut->Sign = pCut0->Sign | pCut1->Sign | pCut2->Sign;
1010  return 1;
1011 }
1012 static inline int Nf_SetCutIsContainedOrder( Nf_Cut_t * pBase, Nf_Cut_t * pCut ) // check if pCut is contained in pBase
1013 {
1014  int i, nSizeB = pBase->nLeaves;
1015  int k, nSizeC = pCut->nLeaves;
1016  if ( nSizeB == nSizeC )
1017  {
1018  for ( i = 0; i < nSizeB; i++ )
1019  if ( pBase->pLeaves[i] != pCut->pLeaves[i] )
1020  return 0;
1021  return 1;
1022  }
1023  assert( nSizeB > nSizeC );
1024  if ( nSizeC == 0 )
1025  return 1;
1026  for ( i = k = 0; i < nSizeB; i++ )
1027  {
1028  if ( pBase->pLeaves[i] > pCut->pLeaves[k] )
1029  return 0;
1030  if ( pBase->pLeaves[i] == pCut->pLeaves[k] )
1031  {
1032  if ( ++k == nSizeC )
1033  return 1;
1034  }
1035  }
1036  return 0;
1037 }
1038 static inline int Nf_SetLastCutIsContained( Nf_Cut_t ** pCuts, int nCuts )
1039 {
1040  int i;
1041  for ( i = 0; i < nCuts; i++ )
1042  if ( pCuts[i]->nLeaves <= pCuts[nCuts]->nLeaves && (pCuts[i]->Sign & pCuts[nCuts]->Sign) == pCuts[i]->Sign && Nf_SetCutIsContainedOrder(pCuts[nCuts], pCuts[i]) )
1043  return 1;
1044  return 0;
1045 }
1046 static inline int Nf_SetLastCutContainsArea( Nf_Cut_t ** pCuts, int nCuts )
1047 {
1048  int i, k, fChanges = 0;
1049  for ( i = 0; i < nCuts; i++ )
1050  if ( pCuts[nCuts]->nLeaves < pCuts[i]->nLeaves && (pCuts[nCuts]->Sign & pCuts[i]->Sign) == pCuts[nCuts]->Sign && Nf_SetCutIsContainedOrder(pCuts[i], pCuts[nCuts]) )
1051  pCuts[i]->nLeaves = NF_NO_LEAF, fChanges = 1;
1052  if ( !fChanges )
1053  return nCuts;
1054  for ( i = k = 0; i <= nCuts; i++ )
1055  {
1056  if ( pCuts[i]->nLeaves == NF_NO_LEAF )
1057  continue;
1058  if ( k < i )
1059  ABC_SWAP( Nf_Cut_t *, pCuts[k], pCuts[i] );
1060  k++;
1061  }
1062  return k - 1;
1063 }
1064 static inline int Nf_CutCompareArea( Nf_Cut_t * pCut0, Nf_Cut_t * pCut1 )
1065 {
1066  if ( pCut0->Useless < pCut1->Useless ) return -1;
1067  if ( pCut0->Useless > pCut1->Useless ) return 1;
1068  if ( pCut0->Flow < pCut1->Flow ) return -1;
1069  if ( pCut0->Flow > pCut1->Flow ) return 1;
1070  if ( pCut0->Delay < pCut1->Delay ) return -1;
1071  if ( pCut0->Delay > pCut1->Delay ) return 1;
1072  if ( pCut0->nLeaves < pCut1->nLeaves ) return -1;
1073  if ( pCut0->nLeaves > pCut1->nLeaves ) return 1;
1074  return 0;
1075 }
1076 static inline void Nf_SetSortByArea( Nf_Cut_t ** pCuts, int nCuts )
1077 {
1078  int i;
1079  for ( i = nCuts; i > 0; i-- )
1080  {
1081  if ( Nf_CutCompareArea(pCuts[i - 1], pCuts[i]) < 0 )//!= 1 )
1082  return;
1083  ABC_SWAP( Nf_Cut_t *, pCuts[i - 1], pCuts[i] );
1084  }
1085 }
1086 static inline int Nf_SetAddCut( Nf_Cut_t ** pCuts, int nCuts, int nCutNum )
1087 {
1088  if ( nCuts == 0 )
1089  return 1;
1090  nCuts = Nf_SetLastCutContainsArea(pCuts, nCuts);
1091  Nf_SetSortByArea( pCuts, nCuts );
1092  return Abc_MinInt( nCuts + 1, nCutNum - 1 );
1093 }
1094 static inline int Nf_CutArea( Nf_Man_t * p, int nLeaves )
1095 {
1096  if ( nLeaves < 2 )
1097  return 0;
1098  return nLeaves + p->pPars->nAreaTuner;
1099 }
1100 static inline void Nf_CutParams( Nf_Man_t * p, Nf_Cut_t * pCut, float FlowRefs )
1101 {
1102  int i, nLeaves = pCut->nLeaves;
1103  assert( nLeaves <= p->pPars->nLutSize );
1104  pCut->Delay = 0;
1105  pCut->Flow = 0;
1106  for ( i = 0; i < nLeaves; i++ )
1107  {
1108  pCut->Delay = Abc_MaxInt( pCut->Delay, Nf_ObjCutDelay(p, pCut->pLeaves[i]) );
1109  pCut->Flow += Nf_ObjCutFlow(p, pCut->pLeaves[i]);
1110  }
1111  pCut->Delay += (int)(nLeaves > 1);
1112  pCut->Flow = (pCut->Flow + Nf_CutArea(p, nLeaves)) / FlowRefs;
1113 }
1114 void Nf_ObjMergeOrder( Nf_Man_t * p, int iObj )
1115 {
1116  Nf_Cut_t pCuts0[NF_CUT_MAX], pCuts1[NF_CUT_MAX], pCuts[NF_CUT_MAX], * pCutsR[NF_CUT_MAX];
1117  Gia_Obj_t * pObj = Gia_ManObj(p->pGia, iObj);
1118  //Nf_Obj_t * pBest = Nf_ManObj(p, iObj);
1119  float dFlowRefs = Nf_ObjFlowRefs(p, iObj, 0) + Nf_ObjFlowRefs(p, iObj, 1);
1120  int nLutSize = p->pPars->nLutSize;
1121  int nCutNum = p->pPars->nCutNum;
1122  int nCuts0 = Nf_ManPrepareCuts(pCuts0, p, Gia_ObjFaninId0(pObj, iObj), 1);
1123  int nCuts1 = Nf_ManPrepareCuts(pCuts1, p, Gia_ObjFaninId1(pObj, iObj), 1);
1124  int fComp0 = Gia_ObjFaninC0(pObj);
1125  int fComp1 = Gia_ObjFaninC1(pObj);
1126  int iSibl = Gia_ObjSibl(p->pGia, iObj);
1127  Nf_Cut_t * pCut0, * pCut1, * pCut0Lim = pCuts0 + nCuts0, * pCut1Lim = pCuts1 + nCuts1;
1128  int i, nCutsUse, nCutsR = 0;
1129  assert( !Gia_ObjIsBuf(pObj) );
1130  for ( i = 0; i < nCutNum; i++ )
1131  pCutsR[i] = pCuts + i;
1132  if ( iSibl )
1133  {
1134  Nf_Cut_t pCuts2[NF_CUT_MAX];
1135  Gia_Obj_t * pObjE = Gia_ObjSiblObj(p->pGia, iObj);
1136  int fCompE = Gia_ObjPhase(pObj) ^ Gia_ObjPhase(pObjE);
1137  int nCuts2 = Nf_ManPrepareCuts(pCuts2, p, iSibl, 0);
1138  Nf_Cut_t * pCut2, * pCut2Lim = pCuts2 + nCuts2;
1139  for ( pCut2 = pCuts2; pCut2 < pCut2Lim; pCut2++ )
1140  {
1141  *pCutsR[nCutsR] = *pCut2;
1142  pCutsR[nCutsR]->iFunc = Abc_LitNotCond( pCutsR[nCutsR]->iFunc, fCompE );
1143  Nf_CutParams( p, pCutsR[nCutsR], dFlowRefs );
1144  nCutsR = Nf_SetAddCut( pCutsR, nCutsR, nCutNum );
1145  }
1146  }
1147  if ( Gia_ObjIsMuxId(p->pGia, iObj) )
1148  {
1149  Nf_Cut_t pCuts2[NF_CUT_MAX];
1150  int nCuts2 = Nf_ManPrepareCuts(pCuts2, p, Gia_ObjFaninId2(p->pGia, iObj), 1);
1151  int fComp2 = Gia_ObjFaninC2(p->pGia, pObj);
1152  Nf_Cut_t * pCut2, * pCut2Lim = pCuts2 + nCuts2;
1153  p->CutCount[0] += nCuts0 * nCuts1 * nCuts2;
1154  for ( pCut0 = pCuts0; pCut0 < pCut0Lim; pCut0++ )
1155  for ( pCut1 = pCuts1; pCut1 < pCut1Lim; pCut1++ )
1156  for ( pCut2 = pCuts2; pCut2 < pCut2Lim; pCut2++ )
1157  {
1158  if ( Nf_CutCountBits(pCut0->Sign | pCut1->Sign | pCut2->Sign) > nLutSize )
1159  continue;
1160  p->CutCount[1]++;
1161  if ( !Nf_CutMergeOrderMux(pCut0, pCut1, pCut2, pCutsR[nCutsR], nLutSize) )
1162  continue;
1163  if ( Nf_SetLastCutIsContained(pCutsR, nCutsR) )
1164  continue;
1165  p->CutCount[2]++;
1166  if ( Nf_CutComputeTruthMux6(p, pCut0, pCut1, pCut2, fComp0, fComp1, fComp2, pCutsR[nCutsR]) )
1167  pCutsR[nCutsR]->Sign = Nf_CutGetSign(pCutsR[nCutsR]->pLeaves, pCutsR[nCutsR]->nLeaves);
1168  Nf_CutParams( p, pCutsR[nCutsR], dFlowRefs );
1169  nCutsR = Nf_SetAddCut( pCutsR, nCutsR, nCutNum );
1170  }
1171  }
1172  else
1173  {
1174  int fIsXor = Gia_ObjIsXor(pObj);
1175  p->CutCount[0] += nCuts0 * nCuts1;
1176  for ( pCut0 = pCuts0; pCut0 < pCut0Lim; pCut0++ )
1177  for ( pCut1 = pCuts1; pCut1 < pCut1Lim; pCut1++ )
1178  {
1179  if ( (int)(pCut0->nLeaves + pCut1->nLeaves) > nLutSize && Nf_CutCountBits(pCut0->Sign | pCut1->Sign) > nLutSize )
1180  continue;
1181  p->CutCount[1]++;
1182  if ( !Nf_CutMergeOrder(pCut0, pCut1, pCutsR[nCutsR], nLutSize) )
1183  continue;
1184  if ( Nf_SetLastCutIsContained(pCutsR, nCutsR) )
1185  continue;
1186  p->CutCount[2]++;
1187  if ( Nf_CutComputeTruth6(p, pCut0, pCut1, fComp0, fComp1, pCutsR[nCutsR], fIsXor) )
1188  pCutsR[nCutsR]->Sign = Nf_CutGetSign(pCutsR[nCutsR]->pLeaves, pCutsR[nCutsR]->nLeaves);
1189  Nf_CutParams( p, pCutsR[nCutsR], dFlowRefs );
1190  nCutsR = Nf_SetAddCut( pCutsR, nCutsR, nCutNum );
1191  }
1192  }
1193  // debug printout
1194  if ( 0 )
1195 // if ( iObj % 10000 == 0 )
1196 // if ( iObj == 1090 )
1197  {
1198  printf( "*** Obj = %d Useful = %d\n", iObj, Nf_ManCountUseful(pCutsR, nCutsR) );
1199  for ( i = 0; i < nCutsR; i++ )
1200  Nf_Cutprintf( p, pCutsR[i] );
1201  printf( "\n" );
1202  }
1203  // verify
1204  assert( nCutsR > 0 && nCutsR < nCutNum );
1205 // assert( Nf_SetCheckArray(pCutsR, nCutsR) );
1206  // store the cutset
1207  Nf_ObjSetCutFlow( p, iObj, pCutsR[0]->Flow );
1208  Nf_ObjSetCutDelay( p, iObj, pCutsR[0]->Delay );
1209  *Vec_IntEntryP(&p->vCutSets, iObj) = Nf_ManSaveCuts(p, pCutsR, nCutsR, 0);
1210  p->CutCount[3] += nCutsR;
1211  nCutsUse = Nf_ManCountUseful(pCutsR, nCutsR);
1212  p->CutCount[4] += nCutsUse;
1213  p->nCutUseAll += nCutsUse == nCutsR;
1214  p->CutCount[5] += Nf_ManCountMatches(p, pCutsR, nCutsR);
1215 }
1217 {
1218  Gia_Obj_t * pObj; int i, iFanin;
1219  Gia_ManForEachAnd( p->pGia, pObj, i )
1220  if ( Gia_ObjIsBuf(pObj) )
1221  {
1222  iFanin = Gia_ObjFaninId0(pObj, i);
1223  Nf_ObjSetCutFlow( p, i, Nf_ObjCutFlow(p, iFanin) );
1224  Nf_ObjSetCutDelay( p, i, Nf_ObjCutDelay(p, iFanin) );
1225  }
1226  else
1227  Nf_ObjMergeOrder( p, i );
1228 }
1229 
1230 
1231 
1232 
1233 /**Function*************************************************************
1234 
1235  Synopsis []
1236 
1237  Description []
1238 
1239  SideEffects []
1240 
1241  SeeAlso []
1242 
1243 ***********************************************************************/
1244 void Nf_ManPrintStats( Nf_Man_t * p, char * pTitle )
1245 {
1246  if ( !p->pPars->fVerbose )
1247  return;
1248  printf( "%s : ", pTitle );
1249  printf( "Delay =%8.2f ", p->pPars->MapDelay );
1250  printf( "Area =%12.2f ", p->pPars->MapArea );
1251  printf( "Gate =%6d ", (int)p->pPars->Area );
1252  printf( "Inv =%6d ", (int)p->nInvs );
1253  printf( "Edge =%7d ", (int)p->pPars->Edge );
1254  Abc_PrintTime( 1, "Time", Abc_Clock() - p->clkStart );
1255  fflush( stdout );
1256 }
1258 {
1259  int nChoices;
1260  if ( !p->pPars->fVerbose )
1261  return;
1262  printf( "LutSize = %d ", p->pPars->nLutSize );
1263  printf( "CutNum = %d ", p->pPars->nCutNum );
1264  printf( "Iter = %d ", p->pPars->nRounds + p->pPars->nRoundsEla );
1265  printf( "Coarse = %d ", p->pPars->fCoarsen );
1266  printf( "Cells = %d ", p->nCells );
1267  printf( "Funcs = %d ", Vec_MemEntryNum(p->vTtMem) );
1268  printf( "Matches = %d ", Vec_WecSizeSize(p->vTt2Match)/2 );
1269  nChoices = Gia_ManChoiceNum( p->pGia );
1270  if ( nChoices )
1271  printf( "Choices = %d ", nChoices );
1272  printf( "\n" );
1273  printf( "Computing cuts...\r" );
1274  fflush( stdout );
1275 }
1277 {
1278  float MemGia = Gia_ManMemory(p->pGia) / (1<<20);
1279  float MemMan =(1.0 * sizeof(Nf_Obj_t) + 8.0 * sizeof(int)) * Gia_ManObjNum(p->pGia) / (1<<20);
1280  float MemCuts = 1.0 * sizeof(int) * (1 << 16) * Vec_PtrSize(&p->vPages) / (1<<20);
1281  float MemTt = p->vTtMem ? Vec_MemMemory(p->vTtMem) / (1<<20) : 0;
1282  if ( p->CutCount[0] == 0 )
1283  p->CutCount[0] = 1;
1284  if ( !p->pPars->fVerbose )
1285  return;
1286  printf( "CutPair = %.0f ", p->CutCount[0] );
1287  printf( "Merge = %.0f (%.1f) ", p->CutCount[1], 1.0*p->CutCount[1]/Gia_ManAndNum(p->pGia) );
1288  printf( "Eval = %.0f (%.1f) ", p->CutCount[2], 1.0*p->CutCount[2]/Gia_ManAndNum(p->pGia) );
1289  printf( "Cut = %.0f (%.1f) ", p->CutCount[3], 1.0*p->CutCount[3]/Gia_ManAndNum(p->pGia) );
1290  printf( "Use = %.0f (%.1f) ", p->CutCount[4], 1.0*p->CutCount[4]/Gia_ManAndNum(p->pGia) );
1291  printf( "Mat = %.0f (%.1f) ", p->CutCount[5], 1.0*p->CutCount[5]/Gia_ManAndNum(p->pGia) );
1292 // printf( "Equ = %d (%.2f %%) ", p->nCutUseAll, 100.0*p->nCutUseAll /p->CutCount[0] );
1293  printf( "\n" );
1294  printf( "Gia = %.2f MB ", MemGia );
1295  printf( "Man = %.2f MB ", MemMan );
1296  printf( "Cut = %.2f MB ", MemCuts );
1297  printf( "TT = %.2f MB ", MemTt );
1298  printf( "Total = %.2f MB ", MemGia + MemMan + MemCuts + MemTt );
1299 // printf( "\n" );
1300  Abc_PrintTime( 1, "Time", Abc_Clock() - p->clkStart );
1301  fflush( stdout );
1302 }
1303 
1304 
1305 /**Function*************************************************************
1306 
1307  Synopsis [Technology mappping.]
1308 
1309  Description []
1310 
1311  SideEffects []
1312 
1313  SeeAlso []
1314 
1315 ***********************************************************************/
1316 float Nf_MatchDeref2_rec( Nf_Man_t * p, int i, int c, Nf_Mat_t * pM )
1317 {
1318  int k, iVar, fCompl, * pCut;
1319  float Area = 0;
1320  if ( pM->fCompl )
1321  {
1322  assert( Nf_ObjMapRefNum(p, i, !c) > 0 );
1323  if ( !Nf_ObjMapRefDec(p, i, !c) )
1324  Area += Nf_MatchDeref2_rec( p, i, !c, Nf_ObjMatchBest(p, i, !c) );
1325  return Area + p->InvArea;
1326  }
1327  if ( Nf_ObjCutSetId(p, i) == 0 )
1328  return 0;
1329  pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, i), pM->CutH );
1330  Nf_CutForEachVar( pCut, pM->Conf, iVar, fCompl, k )
1331  {
1332  assert( Nf_ObjMapRefNum(p, iVar, fCompl) > 0 );
1333  if ( !Nf_ObjMapRefDec(p, iVar, fCompl) )
1334  Area += Nf_MatchDeref2_rec( p, iVar, fCompl, Nf_ObjMatchBest(p, iVar, fCompl) );
1335  }
1336  return Area + Nf_ManCell(p, pM->Gate)->Area;
1337 }
1338 float Nf_MatchRef2_rec( Nf_Man_t * p, int i, int c, Nf_Mat_t * pM, Vec_Int_t * vBackup )
1339 {
1340  int k, iVar, fCompl, * pCut;
1341  float Area = 0;
1342  if ( pM->fCompl )
1343  {
1344  if ( vBackup )
1345  Vec_IntPush( vBackup, Abc_Var2Lit(i, !c) );
1346  assert( Nf_ObjMapRefNum(p, i, !c) >= 0 );
1347  if ( !Nf_ObjMapRefInc(p, i, !c) )
1348  Area += Nf_MatchRef2_rec( p, i, !c, Nf_ObjMatchBest(p, i, !c), vBackup );
1349  return Area + p->InvArea;
1350  }
1351  if ( Nf_ObjCutSetId(p, i) == 0 )
1352  return 0;
1353  pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, i), pM->CutH );
1354  Nf_CutForEachVar( pCut, pM->Conf, iVar, fCompl, k )
1355  {
1356  if ( vBackup )
1357  Vec_IntPush( vBackup, Abc_Var2Lit(iVar, fCompl) );
1358  assert( Nf_ObjMapRefNum(p, iVar, fCompl) >= 0 );
1359  if ( !Nf_ObjMapRefInc(p, iVar, fCompl) )
1360  Area += Nf_MatchRef2_rec( p, iVar, fCompl, Nf_ObjMatchBest(p, iVar, fCompl), vBackup );
1361  }
1362  return Area + Nf_ManCell(p, pM->Gate)->Area;
1363 }
1364 float Nf_MatchRef2Area( Nf_Man_t * p, int i, int c, Nf_Mat_t * pM )
1365 {
1366  float Area; int iLit, k;
1367  Vec_IntClear( &p->vBackup );
1368  Area = Nf_MatchRef2_rec( p, i, c, pM, &p->vBackup );
1369  Vec_IntForEachEntry( &p->vBackup, iLit, k )
1370  {
1371  assert( Nf_ObjMapRefNum(p, Abc_Lit2Var(iLit), Abc_LitIsCompl(iLit)) > 0 );
1372  Nf_ObjMapRefDec( p, Abc_Lit2Var(iLit), Abc_LitIsCompl(iLit) );
1373  }
1374  return Area;
1375 }
1376 
1377 /**Function*************************************************************
1378 
1379  Synopsis []
1380 
1381  Description []
1382 
1383  SideEffects []
1384 
1385  SeeAlso []
1386 
1387 ***********************************************************************/
1388 void Nf_ManCutMatchprintf( Nf_Man_t * p, int iObj, int fCompl, Nf_Mat_t * pM )
1389 {
1390  Mio_Cell_t * pCell;
1391  int i, * pCut;
1392  printf( "%5d %d : ", iObj, fCompl );
1393  if ( pM->CutH == 0 )
1394  {
1395  printf( "Unassigned\n" );
1396  return;
1397  }
1398  pCell = Nf_ManCell( p, pM->Gate );
1399  pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, iObj), pM->CutH );
1400  printf( "D = %8.2f ", pM->D );
1401  printf( "A = %8.2f ", pM->A );
1402  printf( "C = %d ", pM->fCompl );
1403 // printf( "B = %d ", pM->fBest );
1404  printf( " " );
1405  printf( "Cut = {" );
1406  for ( i = 0; i < (int)pCell->nFanins; i++ )
1407  printf( "%5d ", Nf_CutLeaves(pCut)[i] );
1408  for ( ; i < 6; i++ )
1409  printf( " " );
1410  printf( "} " );
1411  printf( "%12s ", pCell->pName );
1412  printf( "%d ", pCell->nFanins );
1413  printf( "{" );
1414  for ( i = 0; i < (int)pCell->nFanins; i++ )
1415  printf( "%7.2f ", pCell->Delays[i] );
1416  for ( ; i < 6; i++ )
1417  printf( " " );
1418  printf( " } " );
1419  for ( i = 0; i < (int)pCell->nFanins; i++ )
1420  printf( "%2d ", Nf_CutConfLit(pM->Conf, i) );
1421  for ( ; i < 6; i++ )
1422  printf( " " );
1423  Dau_DsdPrintFromTruth( &pCell->uTruth, pCell->nFanins );
1424 }
1425 void Nf_ManCutMatchOne( Nf_Man_t * p, int iObj, int * pCut, int * pCutSet )
1426 {
1427  Nf_Obj_t * pBest = Nf_ManObj(p, iObj);
1428  int * pFans = Nf_CutLeaves(pCut);
1429  int nFans = Nf_CutSize(pCut);
1430  int iFuncLit = Nf_CutFunc(pCut);
1431  int fComplExt = Abc_LitIsCompl(iFuncLit);
1432  float Epsilon = p->pPars->Epsilon;
1433  Vec_Int_t * vArr = Vec_WecEntry( p->vTt2Match, Abc_Lit2Var(iFuncLit) );
1434  int i, k, c, Info, Offset, iFanin, fComplF;
1435  float ArrivalD, ArrivalA;
1436  Nf_Mat_t * pD, * pA;
1437  // assign fanins matches
1438  Nf_Obj_t * pBestF[NF_LEAF_MAX];
1439  for ( i = 0; i < nFans; i++ )
1440  pBestF[i] = Nf_ManObj( p, pFans[i] );
1441  // special cases
1442  if ( nFans == 0 )
1443  {
1444  int Const = (iFuncLit == 1);
1445  assert( iFuncLit == 0 || iFuncLit == 1 );
1446  for ( c = 0; c < 2; c++ )
1447  {
1448  pD = Nf_ObjMatchD( p, iObj, c );
1449  pA = Nf_ObjMatchA( p, iObj, c );
1450  pD->D = pA->D = 0;
1451  pD->A = pA->A = p->pCells[c ^ Const].Area;
1452  pD->CutH = pA->CutH = Nf_CutHandle(pCutSet, pCut);
1453  pD->Gate = pA->Gate = c ^ Const;
1454  pD->Conf = pA->Conf = 0;
1455  }
1456  return;
1457  }
1458  if ( nFans == 1 )
1459  {
1460  int Const = (iFuncLit == 3);
1461  assert( iFuncLit == 2 || iFuncLit == 3 );
1462  for ( c = 0; c < 2; c++ )
1463  {
1464  pD = Nf_ObjMatchD( p, iObj, c );
1465  pA = Nf_ObjMatchA( p, iObj, c );
1466  pD->D = pA->D = pBestF[0]->M[c ^ !Const][0].D + p->pCells[2 + (c ^ Const)].Delays[0];
1467  pD->A = pA->A = pBestF[0]->M[c ^ !Const][0].A + p->pCells[2 + (c ^ Const)].Area;
1468  pD->CutH = pA->CutH = Nf_CutHandle(pCutSet, pCut);
1469  pD->Gate = pA->Gate = 2 + (c ^ Const);
1470  pD->Conf = pA->Conf = 0;
1471  }
1472  return;
1473  }
1474  // consider matches of this function
1475  Vec_IntForEachEntryDouble( vArr, Info, Offset, i )
1476  {
1477  Mio_Cell_t* pC = Nf_ManCell( p, Info >> 8 );
1478  int Type = (Info >> 4) & 15;
1479  int fCompl = (Info & 1) ^ fComplExt;
1480  char * pInfo = Vec_StrEntryP( p->vMemStore, Offset );
1481  float Required = Nf_ObjRequired( p, iObj, fCompl );
1482  Nf_Mat_t * pD = &pBest->M[fCompl][0];
1483  Nf_Mat_t * pA = &pBest->M[fCompl][1];
1484  assert( nFans == (int)pC->nFanins );
1485 // if ( iObj == 9 && fCompl == 0 && i == 192 )
1486 // Nf_StoPrintOne( p, -1, Abc_Lit2Var(iFuncLit), i, pC, Type, fCompl, pInfo );
1487  if ( Type == NF_PRIME )
1488  {
1489  float Area = pC->Area, Delay = 0;
1490  for ( k = 0; k < nFans; k++ )
1491  {
1492  iFanin = Abc_Lit2Var((int)pInfo[k]);
1493  fComplF = Abc_LitIsCompl((int)pInfo[k]);
1494  ArrivalD = pBestF[k]->M[fComplF][0].D;
1495  ArrivalA = pBestF[k]->M[fComplF][1].D;
1496  if ( ArrivalA + pC->Delays[iFanin] < Required + Epsilon && Required != NF_INFINITY )
1497  {
1498  Delay = Abc_MaxFloat( Delay, ArrivalA + pC->Delays[iFanin] );
1499  Area += pBestF[k]->M[fComplF][1].A;
1500  }
1501  else
1502  {
1503 // assert( ArrivalD + pC->Delays[iFanin] < Required + Epsilon );
1504  if ( pD->D < NF_INFINITY && pA->D < NF_INFINITY && ArrivalD + pC->Delays[iFanin] >= Required + Epsilon )
1505  break;
1506  Delay = Abc_MaxFloat( Delay, ArrivalD + pC->Delays[iFanin] );
1507  Area += pBestF[k]->M[fComplF][0].A;
1508  }
1509  }
1510  if ( k < nFans )
1511  continue;
1512  if ( p->fUseEla )
1513  {
1514  Nf_Mat_t Temp, * pTemp = &Temp;
1515  memset( pTemp, 0, sizeof(Nf_Mat_t) );
1516  pTemp->D = Delay;
1517  pTemp->A = Area;
1518  pTemp->CutH = Nf_CutHandle(pCutSet, pCut);
1519  pTemp->Gate = pC->Id;
1520  pTemp->Conf = 0;
1521  for ( k = 0; k < nFans; k++ )
1522 // pD->Conf |= ((int)pInfo[k] << (k << 2));
1523  pTemp->Conf |= (Abc_Var2Lit(k, Abc_LitIsCompl((int)pInfo[k])) << (Abc_Lit2Var((int)pInfo[k]) << 2));
1524  Area = Nf_MatchRef2Area(p, iObj, fCompl, pTemp );
1525  }
1526  // select best match
1527  if ( pD->D > Delay )//+ Epsilon )
1528  {
1529  pD->D = Delay;
1530  pD->A = Area;
1531  pD->CutH = Nf_CutHandle(pCutSet, pCut);
1532  pD->Gate = pC->Id;
1533  pD->Conf = 0;
1534  for ( k = 0; k < nFans; k++ )
1535 // pD->Conf |= ((int)pInfo[k] << (k << 2));
1536  pD->Conf |= (Abc_Var2Lit(k, Abc_LitIsCompl((int)pInfo[k])) << (Abc_Lit2Var((int)pInfo[k]) << 2));
1537  }
1538  if ( pA->A > Area )//+ Epsilon )
1539  {
1540  pA->D = Delay;
1541  pA->A = Area;
1542  pA->CutH = Nf_CutHandle(pCutSet, pCut);
1543  pA->Gate = pC->Id;
1544  pA->Conf = 0;
1545  for ( k = 0; k < nFans; k++ )
1546 // pA->Conf |= ((int)pInfo[k] << (k << 2));
1547  pA->Conf |= (Abc_Var2Lit(k, Abc_LitIsCompl((int)pInfo[k])) << (Abc_Lit2Var((int)pInfo[k]) << 2));
1548  }
1549  }
1550  else if ( Type == NF_XOR )
1551  {
1552  int m, nMints = 1 << nFans;
1553  for ( m = 0; m < nMints; m++ )
1554  {
1555  int fComplAll = fCompl;
1556  // collect best fanin delays
1557  float Area = pC->Area, Delay = 0;
1558  for ( k = 0; k < nFans; k++ )
1559  {
1560  assert( !Abc_LitIsCompl((int)pInfo[k]) );
1561  iFanin = Abc_Lit2Var((int)pInfo[k]);
1562  fComplF = ((m >> k) & 1);
1563  ArrivalD = pBestF[k]->M[fComplF][0].D;
1564  ArrivalA = pBestF[k]->M[fComplF][1].D;
1565  if ( ArrivalA + pC->Delays[iFanin] <= Required && Required != NF_INFINITY )
1566  {
1567  Delay = Abc_MaxFloat( Delay, ArrivalA + pC->Delays[iFanin] );
1568  Area += pBestF[k]->M[fComplF][1].A;
1569  }
1570  else
1571  {
1572  assert( ArrivalD + pC->Delays[iFanin] < Required + Epsilon );
1573  Delay = Abc_MaxFloat( Delay, ArrivalD + pC->Delays[iFanin] );
1574  Area += pBestF[k]->M[fComplF][0].A;
1575  }
1576  fComplAll ^= fComplF;
1577  }
1578  pD = &pBest->M[fComplAll][0];
1579  pA = &pBest->M[fComplAll][1];
1580  if ( pD->D > Delay )
1581  {
1582  pD->D = Delay;
1583  pD->A = Area;
1584  pD->CutH = Nf_CutHandle(pCutSet, pCut);
1585  pD->Gate = pC->Id;
1586  pD->Conf = 0;
1587  for ( k = 0; k < nFans; k++ )
1588 // pD->Conf |= Abc_LitNotCond((int)pInfo[k], (m >> k) & 1) << (k << 2);
1589  pD->Conf |= (Abc_Var2Lit(k, (m >> k) & 1) << (Abc_Lit2Var((int)pInfo[k]) << 2));
1590  }
1591  if ( pA->A > Area )
1592  {
1593  pA->D = Delay;
1594  pA->A = Area;
1595  pA->CutH = Nf_CutHandle(pCutSet, pCut);
1596  pA->Gate = pC->Id;
1597  pA->Conf = 0;
1598  for ( k = 0; k < nFans; k++ )
1599 // pA->Conf |= Abc_LitNotCond((int)pInfo[k], (m >> k) & 1) << (k << 2);
1600  pA->Conf |= (Abc_Var2Lit(k, (m >> k) & 1) << (Abc_Lit2Var((int)pInfo[k]) << 2));
1601  }
1602  }
1603  }
1604  else if ( Type == NF_ANDOR )
1605  {
1606  float Area = pC->Area, Delay = 0;
1607  int g, Conf = 0, nGroups = (int)*pInfo++;
1608  for ( g = 0; g < nGroups; g++ )
1609  {
1610  int nSizeAll = (int)*pInfo++;
1611  int nSizeNeg = (int)*pInfo++;
1612  float ArrivalD, ArrivalA;
1613  for ( k = 0; k < nSizeAll; k++ )
1614  {
1615  fComplF = Abc_LitIsCompl((int)pInfo[k]);
1616  iFanin = Abc_Lit2Var((int)pInfo[k]);
1617  ArrivalD = pBestF[k]->M[fComplF][0].D;
1618  ArrivalA = pBestF[k]->M[fComplF][1].D;
1619  if ( ArrivalA + pC->Delays[iFanin] < Required + Epsilon && Required != NF_INFINITY )
1620  {
1621  Delay = Abc_MaxFloat( Delay, ArrivalA + pC->Delays[iFanin] );
1622  Area += pBestF[k]->M[fComplF][1].A;
1623  }
1624  else
1625  {
1626  assert( ArrivalD + pC->Delays[iFanin] < Required + Epsilon );
1627  Delay = Abc_MaxFloat( Delay, ArrivalD + pC->Delays[iFanin] );
1628  Area += pBestF[k]->M[fComplF][0].A;
1629  }
1630 // Conf |= Abc_LitNotCond((int)pInfo[k], 0) << (iFanin << 2);
1631  Conf |= Abc_Var2Lit(iFanin, Abc_LitIsCompl((int)pInfo[k])) << (Abc_Lit2Var((int)pInfo[k]) << 2);
1632  }
1633  pInfo += nSizeAll; nSizeNeg = 0;
1634  }
1635  assert( Conf > 0 );
1636  if ( pD->D > Delay )
1637  {
1638  pD->D = Delay;
1639  pD->A = Area;
1640  pD->CutH = Nf_CutHandle(pCutSet, pCut);
1641  pD->Gate = pC->Id;
1642  pD->Conf = Conf;
1643  }
1644  if ( pA->A > Area )
1645  {
1646  pA->D = Delay;
1647  pA->A = Area;
1648  pA->CutH = Nf_CutHandle(pCutSet, pCut);
1649  pA->Gate = pC->Id;
1650  pA->Conf = Conf;
1651  }
1652  }
1653  }
1654 /*
1655  Nf_ManCutMatchprintf( p, iObj, 0, &pBest->M[0][0] );
1656  Nf_ManCutMatchprintf( p, iObj, 0, &pBest->M[0][1] );
1657  Nf_ManCutMatchprintf( p, iObj, 1, &pBest->M[1][0] );
1658  Nf_ManCutMatchprintf( p, iObj, 1, &pBest->M[1][1] );
1659 */
1660 }
1661 static inline void Nf_ObjPrepareCi( Nf_Man_t * p, int iObj )
1662 {
1663  Nf_Mat_t * pD = Nf_ObjMatchD( p, iObj, 1 );
1664  Nf_Mat_t * pA = Nf_ObjMatchA( p, iObj, 1 );
1665  pD->fCompl = 1;
1666  pD->D = p->InvDelay;
1667  pD->A = p->InvArea;
1668  pA->fCompl = 1;
1669  pA->D = p->InvDelay;
1670  pA->A = p->InvArea;
1671  Nf_ObjMatchD( p, iObj, 0 )->fBest = 1;
1672  Nf_ObjMatchD( p, iObj, 1 )->fBest = 1;
1673 }
1674 static inline void Nf_ObjPrepareBuf( Nf_Man_t * p, Gia_Obj_t * pObj )
1675 {
1676  // get fanin info
1677  int iObj = Gia_ObjId( p->pGia, pObj );
1678  int iFanin = Gia_ObjFaninId0( pObj, iObj );
1679  Nf_Mat_t * pDf = Nf_ObjMatchD( p, iFanin, Gia_ObjFaninC0(pObj) );
1680  //Nf_Mat_t * pAf = Nf_ObjMatchA( p, iFanin, Gia_ObjFaninC0(pObj) );
1681  // set the direct phase
1682  Nf_Mat_t * pDp = Nf_ObjMatchD( p, iObj, 0 );
1683  Nf_Mat_t * pAp = Nf_ObjMatchA( p, iObj, 0 );
1684  Nf_Mat_t * pDn = Nf_ObjMatchD( p, iObj, 1 );
1685  Nf_Mat_t * pAn = Nf_ObjMatchA( p, iObj, 1 );
1686  assert( Gia_ObjIsBuf(pObj) );
1687  memset( Nf_ManObj(p, iObj), 0, sizeof(Nf_Obj_t) );
1688  // set the direct phase
1689  pDp->D = pAp->D = pDf->D;
1690  pDp->A = pAp->A = pDf->A; // do not pass flow???
1691  pDp->fBest = 1;
1692  // set the inverted phase
1693  pDn->D = pAn->D = pDf->D + p->InvDelay;
1694  pDn->A = pAn->A = pDf->A + p->InvArea;
1695  pDn->fCompl = pAn->fCompl = 1;
1696  pDn->fBest = 1;
1697 }
1698 static inline float Nf_CutRequired( Nf_Man_t * p, Nf_Mat_t * pM, int * pCutSet )
1699 {
1700  Mio_Cell_t * pCell = Nf_ManCell( p, pM->Gate );
1701  int * pCut = Nf_CutFromHandle( pCutSet, pM->CutH );
1702  int * pFans = Nf_CutLeaves(pCut);
1703  int i, nFans = Nf_CutSize(pCut);
1704  float Arrival = 0, Required = 0;
1705  for ( i = 0; i < nFans; i++ )
1706  {
1707  int iLit = Nf_CutConfLit( pM->Conf, i );
1708  int iFanin = pFans[ Abc_Lit2Var(iLit) ];
1709  int fCompl = Abc_LitIsCompl( iLit );
1710  float Arr = Nf_ManObj(p, iFanin)->M[fCompl][0].D + pCell->Delays[i];
1711  float Req = Nf_ObjRequired(p, iFanin, fCompl);
1712  Arrival = Abc_MaxInt( Arrival, Arr );
1713  if ( Req < NF_INFINITY )
1714  Required = Abc_MaxInt( Required, Req + pCell->Delays[i] );
1715  }
1716  return Abc_MaxFloat( Required + 2*p->InvDelay, Arrival );
1717 }
1718 static inline void Nf_ObjComputeRequired( Nf_Man_t * p, int iObj )
1719 {
1720  Nf_Obj_t * pBest = Nf_ManObj(p, iObj);
1721  int c, * pCutSet = Nf_ObjCutSet( p, iObj );
1722  for ( c = 0; c < 2; c++ )
1723  if ( Nf_ObjRequired(p, iObj, c) == NF_INFINITY )
1724  Nf_ObjSetRequired( p, iObj, c, Nf_CutRequired(p, &pBest->M[c][0], pCutSet) );
1725 }
1726 void Nf_ManCutMatch( Nf_Man_t * p, int iObj )
1727 {
1728  Nf_Obj_t * pBest = Nf_ManObj(p, iObj);
1729  Nf_Mat_t * pDp = &pBest->M[0][0];
1730  Nf_Mat_t * pDn = &pBest->M[1][0];
1731  Nf_Mat_t * pAp = &pBest->M[0][1];
1732  Nf_Mat_t * pAn = &pBest->M[1][1];
1733  float FlowRefP = Nf_ObjFlowRefs(p, iObj, 0);
1734  float FlowRefN = Nf_ObjFlowRefs(p, iObj, 1);
1735  float Epsilon = p->pPars->Epsilon;
1736  int i, Index, * pCut, * pCutSet = Nf_ObjCutSet( p, iObj );
1737  float ValueBeg[2] = {0}, ValueEnd[2] = {0}, Required[2] = {0};
1738  if ( p->Iter )
1739  {
1740  Nf_ObjComputeRequired( p, iObj );
1741  Required[0] = Nf_ObjRequired( p, iObj, 0 );
1742  Required[1] = Nf_ObjRequired( p, iObj, 1 );
1743  }
1744  if ( p->fUseEla && Nf_ObjMapRefNum(p, iObj, 0) > 0 )
1745  ValueBeg[0] = Nf_MatchDeref2_rec( p, iObj, 0, Nf_ObjMatchBest(p, iObj, 0) );
1746  if ( p->fUseEla && Nf_ObjMapRefNum(p, iObj, 1) > 0 )
1747  ValueBeg[1] = Nf_MatchDeref2_rec( p, iObj, 1, Nf_ObjMatchBest(p, iObj, 1) );
1748  memset( pBest, 0, sizeof(Nf_Obj_t) );
1749  pDp->D = pDp->A = NF_INFINITY;
1750  pDn->D = pDn->A = NF_INFINITY;
1751  pAp->D = pAp->A = NF_INFINITY;
1752  pAn->D = pAn->A = NF_INFINITY;
1753  Nf_SetForEachCut( pCutSet, pCut, i )
1754  {
1755  if ( Abc_Lit2Var(Nf_CutFunc(pCut)) >= Vec_WecSize(p->vTt2Match) )
1756  continue;
1757  assert( !Nf_CutIsTriv(pCut, iObj) );
1758  assert( Nf_CutSize(pCut) <= p->pPars->nLutSize );
1760  Nf_ManCutMatchOne( p, iObj, pCut, pCutSet );
1761  }
1762 
1763 /*
1764  if ( 18687 == iObj )
1765  {
1766  printf( "Obj %6d (%f %f):\n", iObj, Required[0], Required[1] );
1767  Nf_ManCutMatchprintf( p, iObj, 0, &pBest->M[0][0] );
1768  Nf_ManCutMatchprintf( p, iObj, 0, &pBest->M[0][1] );
1769  Nf_ManCutMatchprintf( p, iObj, 1, &pBest->M[1][0] );
1770  Nf_ManCutMatchprintf( p, iObj, 1, &pBest->M[1][1] );
1771  printf( "\n" );
1772  }
1773 */
1774 
1775  // divide by ref count
1776  pDp->A /= FlowRefP;
1777  pAp->A /= FlowRefP;
1778  pDn->A /= FlowRefN;
1779  pAn->A /= FlowRefN;
1780 
1781  // add the inverters
1782  //assert( pDp->D < NF_INFINITY || pDn->D < NF_INFINITY );
1783  if ( pDp->D > pDn->D + p->InvDelay + Epsilon )
1784  {
1785  *pDp = *pDn;
1786  pDp->D += p->InvDelay;
1787  pDp->A += p->InvArea;
1788  pDp->fCompl = 1;
1789  if ( pAp->D == NF_INFINITY )
1790  *pAp = *pDp;
1791  //printf( "Using inverter to improve delay at node %d in phase %d.\n", iObj, 1 );
1792  }
1793  else if ( pDn->D > pDp->D + p->InvDelay + Epsilon )
1794  {
1795  *pDn = *pDp;
1796  pDn->D += p->InvDelay;
1797  pDn->A += p->InvArea;
1798  pDn->fCompl = 1;
1799  if ( pAn->D == NF_INFINITY )
1800  *pAn = *pDn;
1801  //printf( "Using inverter to improve delay at node %d in phase %d.\n", iObj, 0 );
1802  }
1803  //assert( pAp->A < NF_INFINITY || pAn->A < NF_INFINITY );
1804  // try replacing pos with neg
1805  if ( pAp->D == NF_INFINITY || (pAp->A > pAn->A + p->InvArea + Epsilon && pAn->D + p->InvDelay + Epsilon < Required[1]) )
1806  {
1807  assert( p->Iter > 0 );
1808  *pAp = *pAn;
1809  pAp->D += p->InvDelay;
1810  pAp->A += p->InvArea;
1811  pAp->fCompl = 1;
1812  if ( pDp->D == NF_INFINITY )
1813  *pDp = *pAp;
1814  //printf( "Using inverter to improve area at node %d in phase %d.\n", iObj, 1 );
1815  }
1816  // try replacing neg with pos
1817  else if ( pAn->D == NF_INFINITY || (pAn->A > pAp->A + p->InvArea + Epsilon && pAp->D + p->InvDelay + Epsilon < Required[0]) )
1818  {
1819  assert( p->Iter > 0 );
1820  *pAn = *pAp;
1821  pAn->D += p->InvDelay;
1822  pAn->A += p->InvArea;
1823  pAn->fCompl = 1;
1824  if ( pDn->D == NF_INFINITY )
1825  *pDn = *pAn;
1826  //printf( "Using inverter to improve area at node %d in phase %d.\n", iObj, 0 );
1827  }
1828 
1829  if ( pDp->D == NF_INFINITY )
1830  printf( "Object %d has pDp unassigned.\n", iObj );
1831  if ( pDn->D == NF_INFINITY )
1832  printf( "Object %d has pDn unassigned.\n", iObj );
1833  if ( pAp->D == NF_INFINITY )
1834  printf( "Object %d has pAp unassigned.\n", iObj );
1835  if ( pAn->D == NF_INFINITY )
1836  printf( "Object %d has pAn unassigned.\n", iObj );
1837 
1838  pDp->A = Abc_MinFloat( pDp->A, NF_INFINITY/1000000 );
1839  pDn->A = Abc_MinFloat( pDn->A, NF_INFINITY/1000000 );
1840  pAp->A = Abc_MinFloat( pAp->A, NF_INFINITY/1000000 );
1841  pAn->A = Abc_MinFloat( pAn->A, NF_INFINITY/1000000 );
1842 
1843  assert( pDp->D < NF_INFINITY );
1844  assert( pDn->D < NF_INFINITY );
1845  assert( pAp->D < NF_INFINITY );
1846  assert( pAn->D < NF_INFINITY );
1847 
1848  assert( pDp->A < NF_INFINITY );
1849  assert( pDn->A < NF_INFINITY );
1850  assert( pAp->A < NF_INFINITY );
1851  assert( pAn->A < NF_INFINITY );
1852 
1853  //printf( "%16f %16f %16f %16f\n", pDp->A, pDn->A, pAp->A, pAn->A );
1854 // assert ( pDp->A < 1000 );
1855 
1856  if ( p->fUseEla )
1857  {
1858  // set the first good cut
1859  Index = (pAp->D != NF_INFINITY && pAp->D < Nf_ObjRequired(p, iObj, 0) + Epsilon);
1860  assert( !pDp->fBest && !pAp->fBest );
1861  pBest->M[0][Index].fBest = 1;
1862  assert( pDp->fBest != pAp->fBest );
1863  // set the second good cut
1864  Index = (pAn->D != NF_INFINITY && pAn->D < Nf_ObjRequired(p, iObj, 1) + Epsilon);
1865  assert( !pDn->fBest && !pAn->fBest );
1866  pBest->M[1][Index].fBest = 1;
1867  assert( pDn->fBest != pAn->fBest );
1868  // reference if needed
1869  if ( Nf_ObjMapRefNum(p, iObj, 0) > 0 )
1870  ValueEnd[0] = Nf_MatchRef2_rec( p, iObj, 0, Nf_ObjMatchBest(p, iObj, 0), NULL );
1871  if ( Nf_ObjMapRefNum(p, iObj, 1) > 0 )
1872  ValueEnd[1] = Nf_MatchRef2_rec( p, iObj, 1, Nf_ObjMatchBest(p, iObj, 1), NULL );
1873 // assert( ValueBeg[0] > ValueEnd[0] - Epsilon );
1874 // assert( ValueBeg[1] > ValueEnd[1] - Epsilon );
1875  }
1876 }
1878 {
1879  Gia_Obj_t * pObj; int i;
1880  Gia_ManForEachAnd( p->pGia, pObj, i )
1881  if ( Gia_ObjIsBuf(pObj) )
1882  Nf_ObjPrepareBuf( p, pObj );
1883  else
1884  Nf_ManCutMatch( p, i );
1885 }
1886 
1887 
1888 /**Function*************************************************************
1889 
1890  Synopsis []
1891 
1892  Description []
1893 
1894  SideEffects []
1895 
1896  SeeAlso []
1897 
1898 ***********************************************************************/
1899 void Nf_ManSetMapRefsGate( Nf_Man_t * p, int iObj, float Required, Nf_Mat_t * pM )
1900 {
1901  int k, iVar, fCompl;
1902  Mio_Cell_t * pCell = Nf_ManCell( p, pM->Gate );
1903  int * pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, iObj), pM->CutH );
1904  Nf_CutForEachVar( pCut, pM->Conf, iVar, fCompl, k )
1905  {
1906  Nf_ObjMapRefInc( p, iVar, fCompl );
1907  Nf_ObjUpdateRequired( p, iVar, fCompl, Required - pCell->Delays[k] );
1908  }
1909  assert( Nf_CutSize(pCut) == (int)pCell->nFanins );
1910  // update global stats
1911  p->pPars->MapArea += pCell->Area;
1912  p->pPars->Edge += Nf_CutSize(pCut);
1913  p->pPars->Area++;
1914  // update status of the gate
1915  assert( pM->fBest == 0 );
1916  pM->fBest = 1;
1917 }
1919 {
1920  float Coef = 1.0 / (1.0 + (p->Iter + 1) * (p->Iter + 1));
1921  float * pFlowRefs = Vec_FltArray( &p->vFlowRefs );
1922  int * pMapRefs = Vec_IntArray( &p->vMapRefs );
1923  float Epsilon = p->pPars->Epsilon;
1924  int nLits = 2*Gia_ManObjNum(p->pGia);
1925  int i, c, Id, nRefs[2];
1926  Nf_Mat_t * pD, * pA, * pM;
1927  Nf_Mat_t * pDs[2], * pAs[2], * pMs[2];
1928  Gia_Obj_t * pObj;
1929  float Required = 0, Requireds[2];
1930  // check references
1931  assert( !p->fUseEla );
1932  memset( pMapRefs, 0, sizeof(int) * nLits );
1933  Vec_FltFill( &p->vRequired, nLits, NF_INFINITY );
1934 // for ( i = 0; i < Gia_ManObjNum(p->pGia); i++ )
1935 // assert( !Nf_ObjMapRefNum(p, i, 0) && !Nf_ObjMapRefNum(p, i, 1) );
1936  // compute delay
1937  p->pPars->MapDelay = 0;
1938  Gia_ManForEachCo( p->pGia, pObj, i )
1939  {
1940  Required = Nf_ObjMatchD( p, Gia_ObjFaninId0p(p->pGia, pObj), Gia_ObjFaninC0(pObj) )->D;
1941  if ( Required == NF_INFINITY )
1942  {
1944  }
1945  p->pPars->MapDelay = Abc_MaxFloat( p->pPars->MapDelay, Required );
1946  }
1947  // check delay target
1948  if ( p->pPars->MapDelayTarget == -1 && p->pPars->nRelaxRatio )
1949  p->pPars->MapDelayTarget = (int)((float)p->pPars->MapDelay * (100.0 + p->pPars->nRelaxRatio) / 100.0);
1950  if ( p->pPars->MapDelayTarget != -1 )
1951  {
1952  if ( p->pPars->MapDelay < p->pPars->MapDelayTarget + Epsilon )
1953  p->pPars->MapDelay = p->pPars->MapDelayTarget;
1954  else if ( p->pPars->nRelaxRatio == 0 )
1955  Abc_Print( 0, "Relaxing user-specified delay target from %.2f to %.2f.\n", p->pPars->MapDelayTarget, p->pPars->MapDelay );
1956  }
1957  // set required times
1958  Gia_ManForEachCo( p->pGia, pObj, i )
1959  {
1960  Required = Nf_ObjMatchD( p, Gia_ObjFaninId0p(p->pGia, pObj), Gia_ObjFaninC0(pObj) )->D;
1961  Required = p->pPars->fDoAverage ? Required * (100.0 + p->pPars->nRelaxRatio) / 100.0 : p->pPars->MapDelay;
1962  Nf_ObjUpdateRequired( p, Gia_ObjFaninId0p(p->pGia, pObj), Gia_ObjFaninC0(pObj), Required );
1963  Nf_ObjMapRefInc( p, Gia_ObjFaninId0p(p->pGia, pObj), Gia_ObjFaninC0(pObj));
1964  }
1965  // compute area and edges
1966  p->nInvs = 0;
1967  p->pPars->MapArea = 0;
1968  p->pPars->Area = p->pPars->Edge = 0;
1969  Gia_ManForEachAndReverse( p->pGia, pObj, i )
1970  {
1971  if ( Gia_ObjIsBuf(pObj) )
1972  {
1973  if ( Nf_ObjMapRefNum(p, i, 1) )
1974  {
1975  Nf_ObjMapRefInc( p, i, 0 );
1976  Nf_ObjUpdateRequired( p, i, 0, Nf_ObjRequired(p, i, 1) - p->InvDelay );
1977  p->pPars->MapArea += p->InvArea;
1978  p->pPars->Edge++;
1979  p->pPars->Area++;
1980  p->nInvs++;
1981  }
1982  Nf_ObjUpdateRequired( p, Gia_ObjFaninId0(pObj, i), Gia_ObjFaninC0(pObj), Nf_ObjRequired(p, i, 0) );
1983  Nf_ObjMapRefInc( p, Gia_ObjFaninId0(pObj, i), Gia_ObjFaninC0(pObj));
1984  continue;
1985  }
1986  // skip if this node is not used
1987  for ( c = 0; c < 2; c++ )
1988  {
1989  nRefs[c] = Nf_ObjMapRefNum(p, i, c);
1990 
1991  //if ( Nf_ObjMatchD( p, i, c )->fCompl )
1992  // printf( "Match D of node %d has inv in phase %d.\n", i, c );
1993  //if ( Nf_ObjMatchA( p, i, c )->fCompl )
1994  // printf( "Match A of node %d has inv in phase %d.\n", i, c );
1995  }
1996  if ( !nRefs[0] && !nRefs[1] )
1997  continue;
1998 
1999  // consider two cases
2000  if ( nRefs[0] && nRefs[1] )
2001  {
2002  // find best matches for both phases
2003  for ( c = 0; c < 2; c++ )
2004  {
2005  Requireds[c] = Nf_ObjRequired( p, i, c );
2006  //assert( Requireds[c] < NF_INFINITY );
2007  pDs[c] = Nf_ObjMatchD( p, i, c );
2008  pAs[c] = Nf_ObjMatchA( p, i, c );
2009  pMs[c] = (pAs[c]->D < Requireds[c] + Epsilon) ? pAs[c] : pDs[c];
2010  }
2011  // swap complemented matches
2012  if ( pMs[0]->fCompl && pMs[1]->fCompl )
2013  {
2014  pMs[0]->fCompl = pMs[1]->fCompl = 0;
2015  ABC_SWAP( Nf_Mat_t *, pMs[0], pMs[1] );
2016  }
2017  // check if intervers are involved
2018  if ( !pMs[0]->fCompl && !pMs[1]->fCompl )
2019  {
2020  // no inverters
2021  for ( c = 0; c < 2; c++ )
2022  Nf_ManSetMapRefsGate( p, i, Requireds[c], pMs[c] );
2023  }
2024  else
2025  {
2026  // one interver
2027  assert( !pMs[0]->fCompl || !pMs[1]->fCompl );
2028  c = pMs[1]->fCompl;
2029  assert( pMs[c]->fCompl && !pMs[!c]->fCompl );
2030  //printf( "Using inverter at node %d in phase %d\n", i, c );
2031 
2032  // update this phase phase
2033  pM = pMs[c];
2034  pM->fBest = 1;
2035  Required = Requireds[c];
2036 
2037  // update opposite phase
2038  Nf_ObjMapRefInc( p, i, !c );
2039  Nf_ObjUpdateRequired( p, i, !c, Required - p->InvDelay );
2040 
2041  // select oppositve phase
2042  Required = Nf_ObjRequired( p, i, !c );
2043  //assert( Required < NF_INFINITY );
2044  pD = Nf_ObjMatchD( p, i, !c );
2045  pA = Nf_ObjMatchA( p, i, !c );
2046  pM = (pA->D < Required + Epsilon) ? pA : pD;
2047  assert( !pM->fCompl );
2048 
2049  // account for the inverter
2050  p->pPars->MapArea += p->InvArea;
2051  p->pPars->Edge++;
2052  p->pPars->Area++;
2053  p->nInvs++;
2054 
2055  // create gate
2056  Nf_ManSetMapRefsGate( p, i, Required, pM );
2057  }
2058  }
2059  else
2060  {
2061  c = (int)(nRefs[1] > 0);
2062  assert( nRefs[c] && !nRefs[!c] );
2063  // consider this phase
2064  Required = Nf_ObjRequired( p, i, c );
2065  //assert( Required < NF_INFINITY );
2066  pD = Nf_ObjMatchD( p, i, c );
2067  pA = Nf_ObjMatchA( p, i, c );
2068  pM = (pA->D < Required + Epsilon) ? pA : pD;
2069 
2070  if ( pM->fCompl ) // use inverter
2071  {
2072  p->nInvs++;
2073  //printf( "Using inverter at node %d in phase %d\n", i, c );
2074  pM->fBest = 1;
2075  // update opposite phase
2076  Nf_ObjMapRefInc( p, i, !c );
2077  Nf_ObjUpdateRequired( p, i, !c, Required - p->InvDelay );
2078  // select oppositve phase
2079  Required = Nf_ObjRequired( p, i, !c );
2080  //assert( Required < NF_INFINITY );
2081  pD = Nf_ObjMatchD( p, i, !c );
2082  pA = Nf_ObjMatchA( p, i, !c );
2083  pM = (pA->D < Required + Epsilon) ? pA : pD;
2084  assert( !pM->fCompl );
2085 
2086  // account for the inverter
2087  p->pPars->MapArea += p->InvArea;
2088  p->pPars->Edge++;
2089  p->pPars->Area++;
2090  }
2091 
2092  // create gate
2093  Nf_ManSetMapRefsGate( p, i, Required, pM );
2094  }
2095 
2096 
2097  // the result of this:
2098  // - only one phase can be implemented as inverter of the other phase
2099  // - required times are propagated correctly
2100  // - references are set correctly
2101  }
2102  Gia_ManForEachCiId( p->pGia, Id, i )
2103  if ( Nf_ObjMapRefNum(p, Id, 1) )
2104  {
2105  Nf_ObjMapRefInc( p, Id, 0 );
2106  Nf_ObjUpdateRequired( p, Id, 0, Required - p->InvDelay );
2107  p->pPars->MapArea += p->InvArea;
2108  p->pPars->Edge++;
2109  p->pPars->Area++;
2110  p->nInvs++;
2111  }
2112  // blend references
2113  for ( i = 0; i < nLits; i++ )
2114 // pFlowRefs[i] = Abc_MaxFloat(1.0, pMapRefs[i]);
2115  pFlowRefs[i] = Abc_MaxFloat(1.0, Coef * pFlowRefs[i] + (1.0 - Coef) * Abc_MaxFloat(1, pMapRefs[i]));
2116 // pFlowRefs[i] = 0.2 * pFlowRefs[i] + 0.8 * Abc_MaxFloat(1, pMapRefs[i]);
2117 // memset( pMapRefs, 0, sizeof(int) * nLits );
2118  return p->pPars->Area;
2119 }
2121 {
2122  Vec_Int_t * vMapping;
2123  Nf_Mat_t * pM;
2124  int i, k, c, Id, iLit, * pCut;
2125  assert( p->pGia->vCellMapping == NULL );
2126  vMapping = Vec_IntAlloc( 2*Gia_ManObjNum(p->pGia) + (int)p->pPars->Edge + (int)p->pPars->Area * 2 );
2127  Vec_IntFill( vMapping, 2*Gia_ManObjNum(p->pGia), 0 );
2128  // create CI inverters
2129  Gia_ManForEachCiId( p->pGia, Id, i )
2130  if ( Nf_ObjMapRefNum(p, Id, 1) )
2131  Vec_IntWriteEntry( vMapping, Abc_Var2Lit(Id, 1), -1 );
2132  // create internal nodes
2133  Gia_ManForEachAndId( p->pGia, i )
2134  {
2135  Gia_Obj_t * pObj = Gia_ManObj(p->pGia, i);
2136  if ( Gia_ObjIsBuf(pObj) )
2137  {
2138  if ( Nf_ObjMapRefNum(p, i, 1) )
2139  Vec_IntWriteEntry( vMapping, Abc_Var2Lit(i, 1), -1 );
2140  Vec_IntWriteEntry( vMapping, Abc_Var2Lit(i, 0), -2 );
2141  continue;
2142  }
2143  for ( c = 0; c < 2; c++ )
2144  if ( Nf_ObjMapRefNum(p, i, c) )
2145  {
2146  // printf( "Using %d %d\n", i, c );
2147  pM = Nf_ObjMatchBest( p, i, c );
2148  // remember inverter
2149  if ( pM->fCompl )
2150  {
2151  Vec_IntWriteEntry( vMapping, Abc_Var2Lit(i, c), -1 );
2152  continue;
2153  }
2154  // Nf_ManCutMatchprintf( p, i, c, pM );
2155  pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, i), pM->CutH );
2156  // create mapping
2157  Vec_IntWriteEntry( vMapping, Abc_Var2Lit(i, c), Vec_IntSize(vMapping) );
2158  Vec_IntPush( vMapping, Nf_CutSize(pCut) );
2159  Nf_CutForEachLit( pCut, pM->Conf, iLit, k )
2160  Vec_IntPush( vMapping, iLit );
2161  Vec_IntPush( vMapping, pM->Gate );
2162  }
2163  }
2164 // assert( Vec_IntCap(vMapping) == 16 || Vec_IntSize(vMapping) == Vec_IntCap(vMapping) );
2165  p->pGia->vCellMapping = vMapping;
2166  return p->pGia;
2167 }
2169 {
2170  Nf_Mat_t * pM;
2171  Gia_Obj_t * pObj;
2172  Mio_Cell_t * pCell;
2173  int i, c, Id, * pCut;
2174  p->pPars->MapDelay = 0;
2175  Gia_ManForEachCo( p->pGia, pObj, i )
2176  {
2177  float Delay = Nf_ObjMatchD( p, Gia_ObjFaninId0p(p->pGia, pObj), Gia_ObjFaninC0(pObj) )->D;
2178  p->pPars->MapDelay = Abc_MaxFloat( p->pPars->MapDelay, Delay );
2179  }
2180  p->pPars->MapArea = 0;
2181  p->pPars->Area = p->pPars->Edge = 0;
2182  Gia_ManForEachAndId( p->pGia, i )
2183  for ( c = 0; c < 2; c++ )
2184  if ( Nf_ObjMapRefNum(p, i, c) )
2185  {
2186  pM = Nf_ObjMatchBest( p, i, c );
2187  pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, i), pM->CutH );
2188  pCell = Nf_ManCell( p, pM->Gate );
2189  assert( Nf_CutSize(pCut) == (int)pCell->nFanins );
2190  p->pPars->MapArea += pCell->Area;
2191  p->pPars->Edge += Nf_CutSize(pCut);
2192  p->pPars->Area++;
2193  }
2194  Gia_ManForEachCiId( p->pGia, Id, i )
2195  if ( Nf_ObjMapRefNum(p, Id, 1) )
2196  {
2197  p->pPars->MapArea += p->InvArea;
2198  p->pPars->Edge++;
2199  p->pPars->Area++;
2200  }
2201 }
2202 
2203 /**Function*************************************************************
2204 
2205  Synopsis [Technology mappping.]
2206 
2207  Description []
2208 
2209  SideEffects []
2210 
2211  SeeAlso []
2212 
2213 ***********************************************************************/
2214 
2215 /*
2216 static inline Nf_Mat_t * Nf_ObjMatchBestReq( Nf_Man_t * p, int i, int c, float r )
2217 {
2218  Nf_Mat_t * pD = Nf_ObjMatchD(p, i, c);
2219  Nf_Mat_t * pA = Nf_ObjMatchA(p, i, c);
2220  assert( !pD->fBest && !pA->fBest );
2221  assert( Nf_ObjMapRefNum(p, i, c) == 0 );
2222  if ( pA->D < r + p->pPars->Epsilon )
2223  return pA;
2224  return pD;
2225 }
2226 float Nf_MatchDeref_rec( Nf_Man_t * p, int i, int c, Nf_Mat_t * pM )
2227 {
2228  int k, iVar, fCompl, * pCut;
2229  float Area = 0;
2230  int Value = pM->fBest;
2231  pM->fBest = 0;
2232  if ( pM->fCompl )
2233  {
2234  assert( Nf_ObjMapRefNum(p, i, !c) > 0 );
2235  if ( !Nf_ObjMapRefDec(p, i, !c) )
2236  Area += Nf_MatchDeref_rec( p, i, !c, Nf_ObjMatchBest(p, i, !c) );
2237  return Area + p->InvArea;
2238  }
2239  if ( Nf_ObjCutSetId(p, i) == 0 )
2240  return 0;
2241  assert( Value == 1 );
2242  pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, i), pM->CutH );
2243  Nf_CutForEachVar( pCut, pM->Conf, iVar, fCompl, k )
2244  {
2245  assert( Nf_ObjMapRefNum(p, iVar, fCompl) > 0 );
2246  if ( !Nf_ObjMapRefDec(p, iVar, fCompl) )
2247  Area += Nf_MatchDeref_rec( p, iVar, fCompl, Nf_ObjMatchBest(p, iVar, fCompl) );
2248  }
2249  return Area + Nf_ManCell(p, pM->Gate)->Area;
2250 }
2251 float Nf_MatchRef_rec( Nf_Man_t * p, int i, int c, Nf_Mat_t * pM, float Required, Vec_Int_t * vBackup )
2252 {
2253  int k, iVar, fCompl, * pCut;
2254  float ReqFanin, Area = 0;
2255  assert( pM->fBest == 0 );
2256  if ( vBackup == NULL )
2257  pM->fBest = 1;
2258  if ( pM->fCompl )
2259  {
2260  ReqFanin = Required - p->InvDelay;
2261  if ( vBackup )
2262  Vec_IntPush( vBackup, Abc_Var2Lit(i, !c) );
2263  assert( Nf_ObjMapRefNum(p, i, !c) >= 0 );
2264  if ( !Nf_ObjMapRefInc(p, i, !c) )
2265  Area += Nf_MatchRef_rec( p, i, !c, Nf_ObjMatchBestReq(p, i, !c, ReqFanin), ReqFanin, vBackup );
2266  return Area + p->InvArea;
2267  }
2268  if ( Nf_ObjCutSetId(p, i) == 0 )
2269  return 0;
2270  pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, i), pM->CutH );
2271  Nf_CutForEachVar( pCut, pM->Conf, iVar, fCompl, k )
2272  {
2273  ReqFanin = Required - Nf_ManCell(p, pM->Gate)->Delays[k];
2274  if ( vBackup )
2275  Vec_IntPush( vBackup, Abc_Var2Lit(iVar, fCompl) );
2276  assert( Nf_ObjMapRefNum(p, iVar, fCompl) >= 0 );
2277  if ( !Nf_ObjMapRefInc(p, iVar, fCompl) )
2278  Area += Nf_MatchRef_rec( p, iVar, fCompl, Nf_ObjMatchBestReq(p, iVar, fCompl, ReqFanin), ReqFanin, vBackup );
2279  }
2280  return Area + Nf_ManCell(p, pM->Gate)->Area;
2281 }
2282 float Nf_MatchRefArea( Nf_Man_t * p, int i, int c, Nf_Mat_t * pM, float Required )
2283 {
2284  float Area; int iLit, k;
2285  Vec_IntClear( &p->vBackup );
2286  Area = Nf_MatchRef_rec( p, i, c, pM, Required, &p->vBackup );
2287  Vec_IntForEachEntry( &p->vBackup, iLit, k )
2288  {
2289  assert( Nf_ObjMapRefNum(p, Abc_Lit2Var(iLit), Abc_LitIsCompl(iLit)) > 0 );
2290  Nf_ObjMapRefDec( p, Abc_Lit2Var(iLit), Abc_LitIsCompl(iLit) );
2291  }
2292  return Area;
2293 }
2294 void Nf_ManElaBestMatchOne( Nf_Man_t * p, int iObj, int c, int * pCut, int * pCutSet, Nf_Mat_t * pRes, float Required )
2295 {
2296  Nf_Mat_t Mb, * pMb = &Mb;
2297  Nf_Obj_t * pBest = Nf_ManObj(p, iObj);
2298  int * pFans = Nf_CutLeaves(pCut);
2299  int nFans = Nf_CutSize(pCut);
2300  int iFuncLit = Nf_CutFunc(pCut);
2301  int fComplExt = Abc_LitIsCompl(iFuncLit);
2302  float Epsilon = p->pPars->Epsilon;
2303  Vec_Int_t * vArr = Vec_WecEntry( p->vTt2Match, Abc_Lit2Var(iFuncLit) );
2304  int i, k, Info, Offset, iFanin, fComplF;
2305  float ArrivalD, ArrivalA;
2306  // assign fanins matches
2307  Nf_Obj_t * pBestF[NF_LEAF_MAX];
2308  for ( i = 0; i < nFans; i++ )
2309  pBestF[i] = Nf_ManObj( p, pFans[i] );
2310  // special cases
2311  if ( nFans < 2 )
2312  {
2313  *pRes = *Nf_ObjMatchBestReq( p, iObj, c, Required );
2314  return;
2315  }
2316  // consider matches of this function
2317  memset( pMb, 0, sizeof(Nf_Mat_t) );
2318  pMb->D = pMb->A = NF_INFINITY;
2319  Vec_IntForEachEntryDouble( vArr, Info, Offset, i )
2320  {
2321  Mio_Cell_t* pC = Nf_ManCell( p, Info >> 8 );
2322  int Type = (Info >> 4) & 15;
2323  int fCompl = (Info & 1) ^ fComplExt;
2324  char * pInfo = Vec_StrEntryP( p->vMemStore, Offset );
2325  Nf_Mat_t * pD = &pBest->M[fCompl][0];
2326  Nf_Mat_t * pA = &pBest->M[fCompl][1];
2327  assert( nFans == (int)pC->nFanins );
2328  if ( fCompl != c )
2329  continue;
2330  if ( Type == NF_PRIME )
2331  {
2332  float Delay = 0;
2333  for ( k = 0; k < nFans; k++ )
2334  {
2335  iFanin = Abc_Lit2Var((int)pInfo[k]);
2336  fComplF = Abc_LitIsCompl((int)pInfo[k]);
2337  ArrivalD = pBestF[k]->M[fComplF][0].D;
2338  ArrivalA = pBestF[k]->M[fComplF][1].D;
2339  if ( ArrivalA + pC->Delays[iFanin] < Required + Epsilon && Required != NF_INFINITY )
2340  Delay = Abc_MaxFloat( Delay, ArrivalA + pC->Delays[iFanin] );
2341  else
2342  Delay = Abc_MaxFloat( Delay, ArrivalD + pC->Delays[iFanin] );
2343  if ( Delay > Required + Epsilon )
2344  break;
2345  }
2346  if ( k < nFans )
2347  continue;
2348  // create match
2349  pMb->D = Delay;
2350  pMb->A = -1;
2351  pMb->CutH = Nf_CutHandle(pCutSet, pCut);
2352  pMb->Gate = pC->Id;
2353  pMb->Conf = 0;
2354  for ( k = 0; k < nFans; k++ )
2355 // pD->Conf |= ((int)pInfo[k] << (k << 2));
2356  pMb->Conf |= (Abc_Var2Lit(k, Abc_LitIsCompl((int)pInfo[k])) << (Abc_Lit2Var((int)pInfo[k]) << 2));
2357  // compute area
2358  pMb->A = Nf_MatchRefArea( p, iObj, c, pMb, Required );
2359  // compare
2360  if ( pRes->A > pMb->A + Epsilon || (pRes->A == pMb->A && pRes->D > pMb->D + Epsilon) )
2361  *pRes = *pMb;
2362  }
2363  }
2364 }
2365 void Nf_ManElaBestMatch( Nf_Man_t * p, int iObj, int c, Nf_Mat_t * pRes, float Required )
2366 {
2367  int k, * pCut, * pCutSet = Nf_ObjCutSet( p, iObj );
2368  memset( pRes, 0, sizeof(Nf_Mat_t) );
2369  pRes->D = pRes->A = NF_INFINITY;
2370  Nf_SetForEachCut( pCutSet, pCut, k )
2371  {
2372  if ( Abc_Lit2Var(Nf_CutFunc(pCut)) >= Vec_WecSize(p->vTt2Match) )
2373  continue;
2374  Nf_ManElaBestMatchOne( p, iObj, c, pCut, pCutSet, pRes, Required );
2375  }
2376 }
2377 // the best match is stored in pA provided that it satisfies pA->D < req
2378 // area is never compared
2379 void Nf_ManComputeMappingEla( Nf_Man_t * p )
2380 {
2381  Gia_Obj_t * pObj;
2382  Mio_Cell_t * pCell;
2383  Nf_Mat_t Mb, * pMb = &Mb, * pM;
2384  float Epsilon = p->pPars->Epsilon;
2385  float AreaBef, AreaAft, Required, MapArea;
2386  int nLits = 2*Gia_ManObjNum(p->pGia);
2387  int i, c, iVar, Id, fCompl, k, * pCut;
2388  Vec_FltFill( &p->vRequired, nLits, NF_INFINITY );
2389  // compute delay
2390  p->pPars->MapDelay = 0;
2391  Gia_ManForEachCo( p->pGia, pObj, i )
2392  {
2393  Required = Nf_ObjMatchD( p, Gia_ObjFaninId0p(p->pGia, pObj), Gia_ObjFaninC0(pObj) )->D;
2394  p->pPars->MapDelay = Abc_MaxFloat( p->pPars->MapDelay, Required );
2395  }
2396  // check delay target
2397  if ( p->pPars->MapDelayTarget == -1 && p->pPars->nRelaxRatio )
2398  p->pPars->MapDelayTarget = (int)((float)p->pPars->MapDelay * (100.0 + p->pPars->nRelaxRatio) / 100.0);
2399  if ( p->pPars->MapDelayTarget != -1 )
2400  {
2401  if ( p->pPars->MapDelay < p->pPars->MapDelayTarget + Epsilon )
2402  p->pPars->MapDelay = p->pPars->MapDelayTarget;
2403  else if ( p->pPars->nRelaxRatio == 0 )
2404  Abc_Print( 0, "Relaxing user-specified delay target from %.2f to %.2f.\n", p->pPars->MapDelayTarget, p->pPars->MapDelay );
2405  }
2406  // set required times
2407  Gia_ManForEachCo( p->pGia, pObj, i )
2408  {
2409  Required = Nf_ObjMatchD( p, Gia_ObjFaninId0p(p->pGia, pObj), Gia_ObjFaninC0(pObj) )->D;
2410  Required = p->pPars->fDoAverage ? Required * (100.0 + p->pPars->nRelaxRatio) / 100.0 : p->pPars->MapDelay;
2411  Nf_ObjUpdateRequired( p, Gia_ObjFaninId0p(p->pGia, pObj), Gia_ObjFaninC0(pObj), Required );
2412  Nf_ObjMapRefInc( p, Gia_ObjFaninId0p(p->pGia, pObj), Gia_ObjFaninC0(pObj));
2413  }
2414  // compute area and edges
2415  MapArea = p->pPars->MapArea;
2416  p->pPars->MapArea = 0;
2417  p->pPars->Area = p->pPars->Edge = 0;
2418  Gia_ManForEachAndReverseId( p->pGia, i )
2419  for ( c = 0; c < 2; c++ )
2420  if ( Nf_ObjMapRefNum(p, i, c) )
2421  {
2422  pM = Nf_ObjMatchBest( p, i, c );
2423  Required = Nf_ObjRequired( p, i, c );
2424  assert( pM->D < Required + Epsilon );
2425  // try different cuts at this node and find best match
2426  Vec_IntClear( &p->vBackup2 );
2427  AreaBef = Nf_MatchDeref_rec( p, i, c, pM );
2428  Nf_ManElaBestMatch( p, i, c, pMb, Required );
2429  AreaAft = Nf_MatchRef_rec( p, i, c, pMb, Required, NULL );
2430  assert( pMb->A == AreaAft );
2431  assert( AreaBef + Epsilon > AreaAft );
2432  MapArea += AreaAft - AreaBef;
2433 // printf( "%8.2f %8.2f\n", AreaBef, AreaAft );
2434  // set match
2435  assert( pMb->D < Required + Epsilon );
2436  assert( pMb->fBest == 0 );
2437  *Nf_ObjMatchA(p, i, c) = *pMb;
2438  assert( Nf_ObjMatchA(p, i, c) == Nf_ObjMatchBest( p, i, c ) );
2439  // count status
2440  pCell = Nf_ManCell( p, pMb->Gate );
2441  pCut = Nf_CutFromHandle( Nf_ObjCutSet(p, i), pMb->CutH );
2442  Nf_CutForEachVar( pCut, pMb->Conf, iVar, fCompl, k )
2443  Nf_ObjUpdateRequired( p, iVar, fCompl, Required - pCell->Delays[k] );
2444  p->pPars->MapArea += pCell->Area;
2445  p->pPars->Edge += Nf_CutSize(pCut);
2446  p->pPars->Area++;
2447  }
2448  Gia_ManForEachCiId( p->pGia, Id, i )
2449  if ( Nf_ObjMapRefNum(p, Id, 1) )
2450  {
2451  Nf_ObjMapRefInc( p, Id, 0 );
2452  Nf_ObjUpdateRequired( p, Id, 0, Required - p->InvDelay );
2453  p->pPars->MapArea += p->InvArea;
2454  p->pPars->Edge++;
2455  p->pPars->Area++;
2456  }
2457 // Nf_ManUpdateStats( p );
2458  if ( !(MapArea < p->pPars->MapArea + Epsilon && MapArea + Epsilon > p->pPars->MapArea) )
2459  printf( "Mismatch: Estimated = %.2f Real = %.2f\n", MapArea, p->pPars->MapArea );
2460 // assert( MapArea < p->pPars->MapArea + Epsilon && MapArea + Epsilon > p->pPars->MapArea );
2461  Nf_ManPrintStats( p, "Ela " );
2462 }
2463 */
2464 
2465 /**Function*************************************************************
2466 
2467  Synopsis [Technology mappping.]
2468 
2469  Description []
2470 
2471  SideEffects []
2472 
2473  SeeAlso []
2474 
2475 ***********************************************************************/
2477 {
2478  memset( pPars, 0, sizeof(Jf_Par_t) );
2479  pPars->nLutSize = 6;
2480  pPars->nCutNum = 16;
2481  pPars->nProcNum = 0;
2482  pPars->nRounds = 3;
2483  pPars->nRoundsEla = 0;
2484  pPars->nRelaxRatio = 0;
2485  pPars->nCoarseLimit = 3;
2486  pPars->nAreaTuner = 1;
2487  pPars->nVerbLimit = 5;
2488  pPars->DelayTarget = -1;
2489  pPars->fAreaOnly = 0;
2490  pPars->fOptEdge = 1;
2491  pPars->fCoarsen = 0;
2492  pPars->fCutMin = 1;
2493  pPars->fGenCnf = 0;
2494  pPars->fPureAig = 0;
2495  pPars->fVerbose = 0;
2496  pPars->fVeryVerbose = 0;
2497  pPars->nLutSizeMax = NF_LEAF_MAX;
2498  pPars->nCutNumMax = NF_CUT_MAX;
2499  pPars->MapDelayTarget = -1;
2500  pPars->Epsilon = (float)0.01;
2501 }
2503 {
2504  Gia_Man_t * pNew = NULL, * pCls;
2505  Nf_Man_t * p; int i, Id;
2506  if ( Gia_ManHasChoices(pGia) )
2507  pPars->fCoarsen = 0;
2508  pCls = pPars->fCoarsen ? Gia_ManDupMuxes(pGia, pPars->nCoarseLimit) : pGia;
2509  p = Nf_StoCreate( pCls, pPars );
2510 // if ( pPars->fVeryVerbose )
2511 // Nf_StoPrint( p, pPars->fVeryVerbose );
2512  if ( pPars->fVerbose && pPars->fCoarsen )
2513  {
2514  printf( "Initial " ); Gia_ManPrintMuxStats( pGia ); printf( "\n" );
2515  printf( "Derived " ); Gia_ManPrintMuxStats( pCls ); printf( "\n" );
2516  }
2517  Nf_ManPrintInit( p );
2518  Nf_ManComputeCuts( p );
2519  Nf_ManPrintQuit( p );
2520  Gia_ManForEachCiId( p->pGia, Id, i )
2521  Nf_ObjPrepareCi( p, Id );
2522  for ( p->Iter = 0; p->Iter < p->pPars->nRounds; p->Iter++ )
2523  {
2524  Nf_ManComputeMapping( p );
2525  Nf_ManSetMapRefs( p );
2526  Nf_ManPrintStats( p, p->Iter ? "Area " : "Delay" );
2527  }
2528  p->fUseEla = 1;
2529  for ( ; p->Iter < p->pPars->nRounds + pPars->nRoundsEla; p->Iter++ )
2530  {
2531  Nf_ManComputeMapping( p );
2532  Nf_ManUpdateStats( p );
2533  Nf_ManPrintStats( p, "Ela " );
2534  }
2535  pNew = Nf_ManDeriveMapping( p );
2536 // Gia_ManMappingVerify( pNew );
2537  Nf_StoDelete( p );
2538  if ( pCls != pGia )
2539  Gia_ManStop( pCls );
2540  if ( pNew == NULL )
2541  return Gia_ManDup( pGia );
2542  return pNew;
2543 }
2544 
2545 ////////////////////////////////////////////////////////////////////////
2546 /// END OF FILE ///
2547 ////////////////////////////////////////////////////////////////////////
2548 
2549 
2551 
char * memset()
Definition: giaNf.c:43
int Nf_ManSetMapRefs(Nf_Man_t *p)
Definition: giaNf.c:1918
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
unsigned fBest
Definition: giaNf.c:62
static word Abc_Tt6Expand(word t, int *pCut0, int nCutSize0, int *pCut, int nCutSize)
Definition: utilTruth.h:1345
#define NF_LEAF_MAX
DECLARATIONS ///.
Definition: giaNf.c:38
static int Gia_ObjFaninC2(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:453
char * pName
Definition: mio.h:49
int nInvs
Definition: giaNf.c:98
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Nf_Mat_t * Nf_ObjMatchD(Nf_Man_t *p, int i, int c)
Definition: giaNf.c:129
static Vec_Wec_t * Vec_WecAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecWec.h:87
#define Nf_SetForEachCut(pList, pCut, i)
Definition: giaNf.c:156
static int Gia_ObjPhase(Gia_Obj_t *pObj)
Definition: gia.h:415
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition: vecWec.h:42
static int Nf_CutCreateUnit(Nf_Cut_t *p, int i)
Definition: giaNf.c:773
static float Abc_MinFloat(float a, float b)
Definition: abc_global.h:244
static Gia_Obj_t * Gia_ObjSiblObj(Gia_Man_t *p, int Id)
Definition: gia.h:894
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition: giaDup.c:552
int nCutNum
Definition: gia.h:268
int nLutSize
Definition: gia.h:267
float MapArea
Definition: gia.h:303
void Nf_StoPrint(Nf_Man_t *p, int fVerbose)
Definition: giaNf.c:560
Vec_Wec_t * vTt2Match
Definition: giaNf.c:80
struct Nf_Obj_t_ Nf_Obj_t
Definition: giaNf.c:67
unsigned CutH
Definition: giaNf.c:60
int Iter
Definition: giaNf.c:96
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
int Nf_StoCheckDsdAnd_rec(char *pStr, char **p, int *pMatches)
Definition: giaNf.c:360
static int Nf_SetLastCutIsContained(Nf_Cut_t **pCuts, int nCuts)
Definition: giaNf.c:1038
int * Extra_GreyCodeSchedule(int n)
int * Extra_PermSchedule(int n)
static void Vec_FltWriteEntry(Vec_Flt_t *p, int i, float Entry)
Definition: vecFlt.h:364
word Edge
Definition: gia.h:299
Definition: giaNf.c:43
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
Vec_Int_t vCutSets
Definition: giaNf.c:87
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
Vec_Str_t * vMemStore
Definition: giaNf.c:81
void Nf_StoCreateGateNonDsd(Nf_Man_t *pMan, Mio_Cell_t *pCell, int **pComp, int **pPerm, int *pnPerms)
Definition: giaNf.c:430
int Nf_StoCheckDsdAnd(char *p)
Definition: giaNf.c:378
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Gia_ManChoiceNum(Gia_Man_t *p)
Definition: gia.h:398
static int Nf_ManPrepareCuts(Nf_Cut_t *pCuts, Nf_Man_t *p, int iObj, int fAddUnit)
Definition: giaNf.c:798
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int * Nf_ManCutSet(Nf_Man_t *p, int i)
Definition: giaNf.c:109
static void Vec_PtrGrow(Vec_Ptr_t *p, int nCapMin)
Definition: vecPtr.h:430
static void Nf_CutParams(Nf_Man_t *p, Nf_Cut_t *pCut, float FlowRefs)
Definition: giaNf.c:1100
float Flow
Definition: giaNf.c:50
static void Vec_WecFree(Vec_Wec_t *p)
Definition: vecWec.h:345
int nProcNum
Definition: gia.h:269
int nAreaTuner
Definition: gia.h:274
int nCells
Definition: giaNf.c:83
void Nf_ManPrintStats(Nf_Man_t *p, char *pTitle)
Definition: giaNf.c:1244
static Vec_Int_t * Vec_WecPushLevel(Vec_Wec_t *p)
Definition: vecWec.h:284
static void Nf_Cutprintf(Nf_Man_t *p, Nf_Cut_t *pCut)
Definition: giaNf.c:783
int nCutNumMax
Definition: gia.h:294
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
Vec_Int_t vCutDelays
Definition: giaNf.c:92
#define Nf_CutForEachLit(pCut, Conf, iLit, i)
Definition: giaNf.c:158
Gia_Man_t * Nf_ManDeriveMapping(Nf_Man_t *p)
Definition: giaNf.c:2120
static int Nf_CutArea(Nf_Man_t *p, int nLeaves)
Definition: giaNf.c:1094
float A
Definition: giaNf.c:65
static int Nf_ManCountUseful(Nf_Cut_t **pCuts, int nCuts)
Definition: giaNf.c:842
Vec_Int_t vBackup2
Definition: giaNf.c:94
static int Nf_CutConfC(int Conf, int i)
Definition: giaNf.c:154
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
Definition: utilMem.c:35
void Dau_DsdPrintFromTruth(word *pTruth, int nVarsInit)
Definition: dauDsd.c:1968
char * memcpy()
float MapDelay
Definition: gia.h:302
static int Vec_MemEntryNum(Vec_Mem_t *p)
Definition: vecMem.h:151
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
Nf_Mat_t M[2][2]
Definition: giaNf.c:70
static void Nf_ObjComputeRequired(Nf_Man_t *p, int iObj)
Definition: giaNf.c:1718
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int Gia_ObjIsBuf(Gia_Obj_t *pObj)
Definition: gia.h:427
static float * Vec_FltArray(Vec_Flt_t *p)
Definition: vecFlt.h:274
Nf_Man_t * Nf_StoCreate(Gia_Man_t *pGia, Jf_Par_t *pPars)
Definition: giaNf.c:615
Vec_Int_t vBackup
Definition: giaNf.c:93
Vec_Int_t vMapRefs
Definition: giaNf.c:88
int fAreaOnly
Definition: gia.h:277
int nVerbLimit
Definition: gia.h:275
static float Nf_ObjFlowRefs(Nf_Man_t *p, int i, int c)
Definition: giaNf.c:124
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
static void Nf_SetSortByArea(Nf_Cut_t **pCuts, int nCuts)
Definition: giaNf.c:1076
word uTruth
Definition: mio.h:50
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static void Vec_StrPush(Vec_Str_t *p, char Entry)
Definition: vecStr.h:535
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static int Nf_ObjCutSetId(Nf_Man_t *p, int i)
Definition: giaNf.c:110
static void Vec_FltFill(Vec_Flt_t *p, int nSize, float Entry)
Definition: vecFlt.h:450
#define NF_INFINITY
Definition: giaNf.c:41
static int Nf_SetAddCut(Nf_Cut_t **pCuts, int nCuts, int nCutNum)
Definition: giaNf.c:1086
void Nf_ManPrintInit(Nf_Man_t *p)
Definition: giaNf.c:1257
static Gia_Obj_t * Gia_ManObj(Gia_Man_t *p, int v)
Definition: gia.h:402
static float Abc_MaxFloat(float a, float b)
Definition: abc_global.h:243
static void Nf_ObjSetCutFlow(Nf_Man_t *p, int i, float a)
Definition: giaNf.c:118
#define Nf_CutForEachVar(pCut, Conf, iVar, c, i)
Definition: giaNf.c:159
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
void Nf_ManCutMatchprintf(Nf_Man_t *p, int iObj, int fCompl, Nf_Mat_t *pM)
Definition: giaNf.c:1388
int * pRefs
Definition: gia.h:114
Definition: gia.h:75
static int Vec_WecSize(Vec_Wec_t *p)
Definition: vecWec.h:193
#define ABC_SWAP(Type, a, b)
Definition: abc_global.h:218
int fVeryVerbose
Definition: gia.h:292
static int Abc_Tt6MinBase(word *pTruth, int *pVars, int nVars)
Definition: utilTruth.h:1374
static int Nf_SetCheckArray(Nf_Cut_t **ppCuts, int nCuts)
Definition: giaNf.c:885
unsigned nLeaves
Definition: giaNf.c:53
static int Gia_ManHasChoices(Gia_Man_t *p)
Definition: gia.h:397
static Mio_Cell_t * Nf_ManCell(Nf_Man_t *p, int i)
Definition: giaNf.c:108
int nRelaxRatio
Definition: gia.h:272
float Nf_MatchDeref2_rec(Nf_Man_t *p, int i, int c, Nf_Mat_t *pM)
Definition: giaNf.c:1316
abctime clkStart
Definition: giaNf.c:102
static void Nf_ObjSetRequired(Nf_Man_t *p, int i, int c, float f)
Definition: giaNf.c:126
float Epsilon
Definition: gia.h:305
float MapDelayTarget
Definition: gia.h:304
static int Nf_SetCutIsContainedOrder(Nf_Cut_t *pBase, Nf_Cut_t *pCut)
Definition: giaNf.c:1012
word Area
Definition: gia.h:298
#define Gia_ManForEachCiId(p, Id, i)
Definition: gia.h:1018
unsigned fCompl
Definition: giaNf.c:61
static void Vec_IntGrow(Vec_Int_t *p, int nCapMin)
Definition: bblif.c:336
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
int fOptEdge
Definition: gia.h:278
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static int Gia_ManAndNum(Gia_Man_t *p)
Definition: gia.h:389
Mio_Cell_t * pCells
Definition: giaNf.c:82
static int Abc_MinInt(int a, int b)
Definition: abc_global.h:239
static int Gia_ObjSibl(Gia_Man_t *p, int Id)
Definition: gia.h:893
static word Abc_Tt6SwapAdjacent(word Truth, int iVar)
Definition: utilTruth.h:1186
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
static int Gia_ObjIsMuxId(Gia_Man_t *p, int iObj)
Definition: gia.h:424
void Nf_ManUpdateStats(Nf_Man_t *p)
Definition: giaNf.c:2168
int * Dau_DsdComputeMatches(char *p)
Definition: dauDsd.c:80
double CutCount[6]
Definition: giaNf.c:103
unsigned nFanins
Definition: mio.h:53
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Nf_ObjHasCuts(Nf_Man_t *p, int i)
Definition: giaNf.c:112
int iCur
Definition: giaNf.c:95
unsigned Id
Definition: mio.h:52
Definition: gia.h:265
unsigned Gate
Definition: giaNf.c:59
int Conf
Definition: giaNf.c:63
static int Nf_CutCountBits(word i)
Definition: giaNf.c:759
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
static int * Nf_ObjCutSet(Nf_Man_t *p, int i)
Definition: giaNf.c:111
#define NF_CUT_MAX
Definition: giaNf.c:39
Vec_Flt_t vFlowRefs
Definition: giaNf.c:89
static Vec_Mem_t * Vec_MemAllocForTT(int nVars, int fCompl)
Definition: vecMem.h:378
void Nf_StoPrintOne(Nf_Man_t *p, int Count, int t, int i, Mio_Cell_t *pC, int Type, int fCompl, char *pInfo)
Definition: giaNf.c:509
void Nf_ManComputeCuts(Nf_Man_t *p)
Definition: giaNf.c:1216
#define Gia_ManForEachAndReverse(p, pObj, i)
Definition: gia.h:1010
static int Nf_CutFunc(int *pCut)
Definition: giaNf.c:146
static int Nf_ObjCutUseless(Nf_Man_t *p, int TruthId)
Definition: giaNf.c:114
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static void Nf_ObjPrepareBuf(Nf_Man_t *p, Gia_Obj_t *pObj)
Definition: giaNf.c:1674
float Nf_MatchRef2Area(Nf_Man_t *p, int i, int c, Nf_Mat_t *pM)
Definition: giaNf.c:1364
static int Abc_Base10Log(unsigned n)
Definition: abc_global.h:252
float InvDelay
Definition: giaNf.c:99
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:356
Definition: giaNf.c:43
static double Vec_MemMemory(Vec_Mem_t *p)
Definition: vecMem.h:175
static int Nf_ManCountMatches(Nf_Man_t *p, Nf_Cut_t **pCuts, int nCuts)
Definition: giaNf.c:849
Gia_Man_t * Gia_ManDupMuxes(Gia_Man_t *p, int Limit)
Definition: giaMuxes.c:96
void Nf_ManComputeMapping(Nf_Man_t *p)
Definition: giaNf.c:1877
static int Gia_ObjIsXor(Gia_Obj_t *pObj)
Definition: gia.h:423
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
static void Nf_StoSelectSortLit(int *pArray, int nSize, Mio_Cell_t *pCell)
Definition: giaNf.c:202
static int Nf_ObjMapRefInc(Nf_Man_t *p, int i, int c)
Definition: giaNf.c:122
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
static float Nf_ObjCutFlow(Nf_Man_t *p, int i)
Definition: giaNf.c:116
static int Nf_ObjMapRefNum(Nf_Man_t *p, int i, int c)
Definition: giaNf.c:121
void Nf_StoCreateGateDsd(Nf_Man_t *pMan, Mio_Cell_t *pCell, int **pComp, int **pPerm, int *pnPerms)
Definition: giaNf.c:460
static void Vec_IntFreeP(Vec_Int_t **p)
Definition: vecInt.h:289
Jf_Par_t * pPars
Definition: giaNf.c:77
static Nf_Obj_t * Nf_ManObj(Nf_Man_t *p, int i)
Definition: giaNf.c:107
int Nf_StoBuildDsdAnd(Nf_Man_t *pMan, Mio_Cell_t *pCell, char *p)
Definition: giaNf.c:279
Vec_Int_t * vCellMapping
Definition: gia.h:132
static void Nf_ObjSetCutDelay(Nf_Man_t *p, int i, int d)
Definition: giaNf.c:119
static int Nf_CutConfVar(int Conf, int i)
Definition: giaNf.c:153
static word Abc_Tt6Flip(word Truth, int iVar)
Definition: utilTruth.h:1126
static void Vec_MemFree(Vec_Mem_t *p)
Definition: utilMem.c:93
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
int Delay
Definition: giaNf.c:49
static void Nf_ObjUpdateRequired(Nf_Man_t *p, int i, int c, float f)
Definition: giaNf.c:127
static int pPerm[13719]
Definition: rwrTemp.c:32
static float Nf_CutRequired(Nf_Man_t *p, Nf_Mat_t *pM, int *pCutSet)
Definition: giaNf.c:1698
void Gia_ManPrintMuxStats(Gia_Man_t *p)
Definition: giaMuxes.c:61
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition: vecInt.h:66
static 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)
Definition: giaNf.c:724
void Nf_ManSetDefaultPars(Jf_Par_t *pPars)
Definition: giaNf.c:2476
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int fDoAverage
Definition: gia.h:288
static 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)
Definition: giaNf.c:704
static Vec_Int_t * Vec_WecEntry(Vec_Wec_t *p, int i)
Definition: vecWec.h:142
int fUseEla
Definition: giaNf.c:97
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static int Vec_StrSize(Vec_Str_t *p)
Definition: bblif.c:600
static int Abc_LitNot(int Lit)
Definition: abc_global.h:266
int nRounds
Definition: gia.h:270
int pLeaves[NF_LEAF_MAX+1]
Definition: giaNf.c:54
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
float Area
Definition: mio.h:51
static int Nf_ObjMapRefDec(Nf_Man_t *p, int i, int c)
Definition: giaNf.c:123
static int Nf_CutCheck(Nf_Cut_t *pBase, Nf_Cut_t *pCut)
Definition: giaNf.c:869
Vec_Ptr_t vPages
Definition: giaNf.c:86
void Nf_StoCreateGateAdd(Nf_Man_t *pMan, word uTruth, int *pFans, int nFans, int CellId, int Type)
Definition: giaNf.c:217
void Nf_StoDeriveMatches(Nf_Man_t *p, int fVerbose)
Definition: giaNf.c:488
int Nf_StoCheckDsdXor_rec(char *pStr, char **p, int *pMatches)
Definition: giaNf.c:387
static int Nf_CutSetBoth(int n, int f)
Definition: giaNf.c:148
#define ABC_FREE(obj)
Definition: abc_global.h:232
Vec_Mem_t * vTtMem
Definition: giaNf.c:79
Definition: gia.h:95
void Nf_ManPrintQuit(Nf_Man_t *p)
Definition: giaNf.c:1276
static int * Nf_ObjCutBest(Nf_Man_t *p, int i)
Definition: giaNf.c:113
int fPureAig
Definition: gia.h:287
static int Nf_CutIsTriv(int *pCut, int i)
Definition: giaNf.c:149
int fCutMin
Definition: gia.h:282
static Nf_Mat_t * Nf_ObjMatchBest(Nf_Man_t *p, int i, int c)
Definition: giaNf.c:132
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
static int Abc_TtSupportSize(word *t, int nVars)
Definition: utilTruth.h:986
int Extra_Factorial(int n)
static int Nf_CutMergeOrderMux(Nf_Cut_t *pCut0, Nf_Cut_t *pCut1, Nf_Cut_t *pCut2, Nf_Cut_t *pCut, int nLutSize)
Definition: giaNf.c:988
static int Nf_CutSize(int *pCut)
Definition: giaNf.c:145
static int Gia_ObjFaninId0p(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:463
void Nf_ManSetMapRefsGate(Nf_Man_t *p, int iObj, float Required, Nf_Mat_t *pM)
Definition: giaNf.c:1899
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
Definition: vecFlt.h:42
unsigned iFunc
Definition: giaNf.c:51
int Nf_StoCheckDsdXor(char *p)
Definition: giaNf.c:410
static word Nf_CutGetSign(int *pLeaves, int nLeaves)
Definition: giaNf.c:766
Mio_Cell_t * Mio_CollectRootsNewDefault(int nInputs, int *pnGates, int fVerbose)
Definition: mioUtils.c:498
static int Nf_CutMergeOrder(Nf_Cut_t *pCut0, Nf_Cut_t *pCut1, Nf_Cut_t *pCut, int nLutSize)
Definition: giaNf.c:925
static Nf_Mat_t * Nf_ObjMatchA(Nf_Man_t *p, int i, int c)
Definition: giaNf.c:130
static int Vec_MemHashInsert(Vec_Mem_t *p, word *pEntry)
Definition: vecMem.h:351
static void Nf_StoSelectSort(int *pArray, int nSize, Mio_Cell_t *pCell)
FUNCTION DEFINITIONS ///.
Definition: giaNf.c:189
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition: abc_global.h:216
static void Vec_MemHashFree(Vec_Mem_t *p)
Definition: vecMem.h:311
static int * Nf_CutLeaves(int *pCut)
Definition: giaNf.c:147
int fGenCnf
Definition: gia.h:284
Gia_Man_t * Nf_ManPerformMapping(Gia_Man_t *pGia, Jf_Par_t *pPars)
Definition: giaNf.c:2502
#define assert(ex)
Definition: util_old.h:213
static int Nf_SetLastCutContainsArea(Nf_Cut_t **pCuts, int nCuts)
Definition: giaNf.c:1046
static int * Vec_IntEntryP(Vec_Int_t *p, int i)
Definition: vecInt.h:417
float InvArea
Definition: giaNf.c:100
double Gia_ManMemory(Gia_Man_t *p)
Definition: giaMan.c:156
void Gia_ManSetPhase(Gia_Man_t *p)
Definition: giaUtil.c:379
void Mf_ManSetFlowRefs(Gia_Man_t *p, Vec_Int_t *vRefs)
Definition: giaMf.c:1077
static int Gia_ObjFaninId2(Gia_Man_t *p, int ObjId)
Definition: gia.h:462
static int Nf_ManSaveCuts(Nf_Man_t *p, Nf_Cut_t **pCuts, int nCuts, int fUseful)
Definition: giaNf.c:820
static float Vec_FltEntry(Vec_Flt_t *p, int i)
Definition: vecFlt.h:342
Vec_Flt_t vRequired
Definition: giaNf.c:90
void Nf_StoDelete(Nf_Man_t *p)
Definition: giaNf.c:668
int nLutSizeMax
Definition: gia.h:293
void Nf_ObjMergeOrder(Nf_Man_t *p, int iObj)
Definition: giaNf.c:1114
#define Gia_ManForEachAndId(p, i)
Definition: gia.h:1004
static int Nf_CutConfLit(int Conf, int i)
Definition: giaNf.c:152
int nCutUseAll
Definition: giaNf.c:104
static word * Vec_MemReadEntry(Vec_Mem_t *p, int i)
Definition: vecMem.h:191
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
static void Nf_ObjPrepareCi(Nf_Man_t *p, int iObj)
Definition: giaNf.c:1661
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
ABC_INT64_T abctime
Definition: abc_global.h:278
static int Nf_CutCompareArea(Nf_Cut_t *pCut0, Nf_Cut_t *pCut1)
Definition: giaNf.c:1064
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
static int Gia_ObjFaninId1(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:461
void Nf_ManCutMatch(Nf_Man_t *p, int iObj)
Definition: giaNf.c:1726
int nRoundsEla
Definition: gia.h:271
float Nf_MatchRef2_rec(Nf_Man_t *p, int i, int c, Nf_Mat_t *pM, Vec_Int_t *vBackup)
Definition: giaNf.c:1338
float Delays[6]
Definition: mio.h:54
void Nf_ManCutMatchOne(Nf_Man_t *p, int iObj, int *pCut, int *pCutSet)
Definition: giaNf.c:1425
static void Vec_PtrFreeData(Vec_Ptr_t *p)
Definition: vecPtr.h:561
Nf_Obj_t * pNfObjs
Definition: giaNf.c:85
Gia_Man_t * pGia
Definition: giaNf.c:76
Vec_Flt_t vCutFlows
Definition: giaNf.c:91
word Sign
Definition: giaNf.c:48
static int * Nf_CutFromHandle(int *pCutSet, int h)
Definition: giaNf.c:151
int DelayTarget
Definition: gia.h:276
static float Nf_ObjRequired(Nf_Man_t *p, int i, int c)
Definition: giaNf.c:125
int nCoarseLimit
Definition: gia.h:273
int Nf_StoBuildDsdAnd_rec(Nf_Man_t *pMan, Mio_Cell_t *pCell, char *pStr, char **p, int *pMatches, int pGroups[NF_LEAF_MAX][NF_LEAF_MAX], int *nGroupSizes, int *pnGroups)
Definition: giaNf.c:245
static int Nf_ObjCutDelay(Nf_Man_t *p, int i)
Definition: giaNf.c:117
static char * Vec_StrEntryP(Vec_Str_t *p, int i)
Definition: vecStr.h:353
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
static int Vec_WecSizeSize(Vec_Wec_t *p)
Definition: vecWec.h:202
int fVerbose
Definition: gia.h:291
float D
Definition: giaNf.c:64
static int Nf_CutHandle(int *pCutSet, int *pCut)
Definition: giaNf.c:150
static int Gia_ObjFaninId0(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:460
int fCoarsen
Definition: gia.h:281
#define NF_NO_LEAF
Definition: giaNf.c:40
unsigned Useless
Definition: giaNf.c:52