abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaLf.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [giaLf.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Scalable AIG package.]
8 
9  Synopsis [Cut computation.]
10 
11  Author [Alan Mishchenko]`
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: giaLf.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "gia.h"
22 #include "misc/tim/tim.h"
23 #include "misc/vec/vecSet.h"
24 #include "misc/vec/vecMem.h"
25 #include "misc/util/utilTruth.h"
26 
28 
29 ////////////////////////////////////////////////////////////////////////
30 /// DECLARATIONS ///
31 ////////////////////////////////////////////////////////////////////////
32 
33 #define LF_LEAF_MAX 12
34 #define LF_CUT_MAX 32
35 #define LF_LOG_PAGE 12
36 #define LF_NO_LEAF 255
37 #define LF_CUT_WORDS (4+LF_LEAF_MAX/2)
38 #define LF_TT_WORDS ((LF_LEAF_MAX > 6) ? 1 << (LF_LEAF_MAX-6) : 1)
39 
40 typedef struct Lf_Cut_t_ Lf_Cut_t;
41 struct Lf_Cut_t_
42 {
43  word Sign; // signature
44  int Delay; // delay
45  float Flow; // flow
46  int iFunc; // functionality
47  unsigned Cost : 22; // misc cut cost
48  unsigned fLate : 1; // fails timing
49  unsigned fMux7 : 1; // specialized cut
50  unsigned nLeaves : 8; // the number of leaves
51  int pLeaves[0]; // leaves
52 };
53 typedef struct Lf_Plc_t_ Lf_Plc_t;
54 struct Lf_Plc_t_
55 {
56  unsigned fUsed : 1; // the cut is used
57  unsigned Handle : 31; // the cut handle
58 };
59 typedef struct Lf_Bst_t_ Lf_Bst_t;
60 struct Lf_Bst_t_
61 {
62  int Delay[3]; // delay
63  float Flow[3]; // flow
64  Lf_Plc_t Cut[2]; // cut info
65 };
66 typedef struct Lf_Mem_t_ Lf_Mem_t;
67 struct Lf_Mem_t_
68 {
69  int LogPage; // log size of memory page
70  int MaskPage; // page mask
71  int nCutWords; // cut size in words
72  int iCur; // writing position
73  Vec_Ptr_t vPages; // memory pages
74  Vec_Ptr_t * vFree; // free pages
75 };
76 typedef struct Lf_Man_t_ Lf_Man_t;
77 struct Lf_Man_t_
78 {
79  // user data
80  Gia_Man_t * pGia; // manager
81  Jf_Par_t * pPars; // parameters
82  // cut data
83  int nCutWords; // cut size in words
84  int nSetWords; // set size in words
85  Lf_Bst_t * pObjBests; // best cuts
86  Vec_Ptr_t vMemSets; // memory for cutsets
87  Vec_Int_t vFreeSets; // free cutsets
88  Vec_Mem_t * vTtMem; // truth tables
89  Vec_Ptr_t vFreePages; // free memory pages
90  Lf_Mem_t vStoreOld; // previous cuts
91  Lf_Mem_t vStoreNew; // current cuts
92  // mapper data
93  Vec_Int_t vOffsets; // offsets
94  Vec_Int_t vRequired; // required times
95  Vec_Int_t vCutSets; // cutsets (pObj->Value stores cut refs)
96  Vec_Flt_t vFlowRefs; // flow refs
97  Vec_Int_t vMapRefs; // mapping refs
98  Vec_Flt_t vSwitches; // switching activity
99  Vec_Int_t vCiArrivals; // arrival times of the CIs
100  // statistics
101  abctime clkStart; // starting time
102  double CutCount[4]; // cut counts
103  double Switches; // switching activity
104  int nFrontMax; // frontier
105  int nCoDrivers; // CO drivers
106  int nInverters; // inverters
107  int nTimeFails; // timing fails
108  int Iter; // mapping iteration
109  int fUseEla; // use exact local area
110  int nCutMux; // non-trivial MUX cuts
111  int nCutEqual; // equal two cuts
113 };
114 
115 static inline void Lf_CutCopy( Lf_Cut_t * p, Lf_Cut_t * q, int n ) { memcpy(p, q, sizeof(word) * n); }
116 static inline Lf_Cut_t * Lf_CutNext( Lf_Cut_t * p, int n ) { return (Lf_Cut_t *)((word *)p + n); }
117 static inline word * Lf_CutTruth( Lf_Man_t * p, Lf_Cut_t * pCut ) { return Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut->iFunc)); }
118 
119 static inline int Lf_ObjOff( Lf_Man_t * p, int i ) { return Vec_IntEntry(&p->vOffsets, i); }
120 static inline int Lf_ObjRequired( Lf_Man_t * p, int i ) { return Vec_IntEntry(&p->vRequired, i); }
121 static inline void Lf_ObjSetRequired( Lf_Man_t * p, int i, int t ) { Vec_IntDowndateEntry(&p->vRequired, i, t); }
122 static inline Lf_Bst_t * Lf_ObjReadBest( Lf_Man_t * p, int i ) { return p->pObjBests + Lf_ObjOff(p,i); }
123 static inline float Lf_ObjFlowRefs( Lf_Man_t * p, int i ) { return Vec_FltEntry(&p->vFlowRefs, Lf_ObjOff(p,i)); }
124 static inline int Lf_ObjMapRefNum( Lf_Man_t * p, int i ) { return Vec_IntEntry(&p->vMapRefs, Lf_ObjOff(p,i)); }
125 static inline int Lf_ObjMapRefInc( Lf_Man_t * p, int i ) { return (*Vec_IntEntryP(&p->vMapRefs, Lf_ObjOff(p,i)))++; }
126 static inline int Lf_ObjMapRefDec( Lf_Man_t * p, int i ) { return --(*Vec_IntEntryP(&p->vMapRefs, Lf_ObjOff(p,i))); }
127 static inline float Lf_ObjSwitches( Lf_Man_t * p, int i ) { return Vec_FltEntry(&p->vSwitches, i); }
128 static inline int Lf_BestDiffCuts( Lf_Bst_t * p ) { return p->Cut[0].Handle != p->Cut[1].Handle; }
129 static inline int Lf_BestIsMapped( Lf_Bst_t * p ) { return (int)(p->Cut[0].fUsed ^ p->Cut[1].fUsed); }
130 static inline int Lf_BestIndex( Lf_Bst_t * p ) { return p->Cut[1].fUsed; }
131 static inline int Lf_BestCutIndex( Lf_Bst_t * p ) { if (p->Cut[0].fUsed) return 0; if (p->Cut[1].fUsed) return 1; return 2; }
132 
133 #define Lf_CutSetForEachCut( nWords, pCutSet, pCut, i, nCuts ) for ( i = 0, pCut = pCutSet; i < nCuts; pCut = Lf_CutNext(pCut, nWords), i++ )
134 #define Lf_CutForEachVar( pCut, Var, i ) for ( i = 0; i < (int)pCut->nLeaves && (Var = pCut->pLeaves[i]); i++ ) if ( Lf_ObjOff(p, Var) < 0 ) {} else
135 
136 extern int Kit_TruthToGia( Gia_Man_t * pMan, unsigned * pTruth, int nVars, Vec_Int_t * vMemory, Vec_Int_t * vLeaves, int fHash );
137 
138 ////////////////////////////////////////////////////////////////////////
139 /// FUNCTION DEFINITIONS ///
140 ////////////////////////////////////////////////////////////////////////
141 
142 /**Function*************************************************************
143 
144  Synopsis []
145 
146  Description []
147 
148  SideEffects []
149 
150  SeeAlso []
151 
152 ***********************************************************************/
153 static inline void Lf_ObjSetCiArrival( Lf_Man_t * p, int iCi, int Time )
154 {
155  Vec_IntWriteEntry( &p->vCiArrivals, iCi, Time );
156 }
157 static inline int Lf_ObjCiArrival( Lf_Man_t * p, int iCi )
158 {
159  return Vec_IntEntry( &p->vCiArrivals, iCi );
160 }
162 {
163  if ( Gia_ObjIsBuf(pDriver) )
164  return Lf_ObjArrival_rec( p, Gia_ObjFanin0(pDriver) );
165  if ( Gia_ObjIsAnd(pDriver) )
166  return Lf_ObjReadBest(p, Gia_ObjId(p->pGia, pDriver))->Delay[0];
167  if ( Gia_ObjIsCi(pDriver) )
168  return Lf_ObjCiArrival(p, Gia_ObjCioId(pDriver));
169  return 0;
170 }
171 static inline int Lf_ObjCoArrival( Lf_Man_t * p, int iCo )
172 {
173  Gia_Obj_t * pObj = Gia_ManCo(p->pGia, iCo);
174  Gia_Obj_t * pDriver = Gia_ObjFanin0(pObj);
175  return Lf_ObjArrival_rec( p, pDriver );
176 // if ( Gia_ObjIsAnd(pDriver) )
177 // return Lf_ObjReadBest(p, Gia_ObjId(p->pGia, pDriver))->Delay[0];
178 // if ( Gia_ObjIsCi(pDriver) )
179 // return Lf_ObjCiArrival(p, Gia_ObjCioId(pDriver));
180 // return 0;
181 }
183 {
184  if ( Gia_ObjIsBuf(pDriver) )
185  return Lf_ObjCoArrival2_rec( p, Gia_ObjFanin0(pDriver) );
186  if ( Gia_ObjIsAnd(pDriver) )
187  {
188  Lf_Bst_t * pBest = Lf_ObjReadBest(p, Gia_ObjId(p->pGia, pDriver));
189  int Index = Lf_BestCutIndex( pBest );
190  assert( Index < 2 || Gia_ObjIsMux(p->pGia, pDriver) );
191  return pBest->Delay[Index];
192  }
193  if ( Gia_ObjIsCi(pDriver) )
194  return Lf_ObjCiArrival(p, Gia_ObjCioId(pDriver));
195  return 0;
196 }
197 static inline int Lf_ObjCoArrival2( Lf_Man_t * p, int iCo )
198 {
199  Gia_Obj_t * pObj = Gia_ManCo(p->pGia, iCo);
200  Gia_Obj_t * pDriver = Gia_ObjFanin0(pObj);
201  return Lf_ObjCoArrival2_rec( p, pDriver );
202 // if ( Gia_ObjIsAnd(pDriver) )
203 // {
204 // Lf_Bst_t * pBest = Lf_ObjReadBest(p, Gia_ObjId(p->pGia, pDriver));
205 // int Index = Lf_BestCutIndex( pBest );
206 // assert( Index < 2 || Gia_ObjIsMux(p->pGia, pDriver) );
207 // return pBest->Delay[Index];
208 // }
209 // if ( Gia_ObjIsCi(pDriver) )
210 // return Lf_ObjCiArrival(p, Gia_ObjCioId(pDriver));
211 // return 0;
212 }
213 
214 /**Function*************************************************************
215 
216  Synopsis []
217 
218  Description []
219 
220  SideEffects []
221 
222  SeeAlso []
223 
224 ***********************************************************************/
226 {
227  Gia_Obj_t * pObj;
228  int i, nCutMax = 0, nCutCur = 0;
229  assert( p->pMuxes == NULL );
230  Gia_ManForEachObj( p, pObj, i )
231  pObj->Value = 0;
232  Gia_ManForEachAnd( p, pObj, i )
233  {
234  if ( Gia_ObjIsAnd(Gia_ObjFanin0(pObj)) )
235  Gia_ObjFanin0(pObj)->Value++;
236  if ( Gia_ObjIsAnd(Gia_ObjFanin1(pObj)) )
237  Gia_ObjFanin1(pObj)->Value++;
238  }
239  Gia_ManForEachAnd( p, pObj, i )
240  {
241  if ( pObj->Value )
242  nCutCur++;
243  if ( nCutMax < nCutCur )
244  nCutMax = nCutCur;
245  if ( Gia_ObjIsAnd(Gia_ObjFanin0(pObj)) && --Gia_ObjFanin0(pObj)->Value == 0 )
246  nCutCur--;
247  if ( Gia_ObjIsAnd(Gia_ObjFanin1(pObj)) && --Gia_ObjFanin1(pObj)->Value == 0 )
248  nCutCur--;
249  }
250  assert( nCutCur == 0 );
251  if ( nCutCur )
252  printf( "Cutset is not 0\n" );
253  Gia_ManForEachObj( p, pObj, i )
254  assert( pObj->Value == 0 );
255  printf( "CutMax = %d\n", nCutMax );
256  return nCutMax;
257 }
258 
259 /**Function*************************************************************
260 
261  Synopsis [Detect MUX truth tables.]
262 
263  Description []
264 
265  SideEffects []
266 
267  SeeAlso []
268 
269 ***********************************************************************/
271 {
272  static unsigned s_Muxes[24] = {
273  (~0xAAAAAAAA & ~0xCCCCCCCC) | ( 0xAAAAAAAA & ~0xF0F0F0F0),
274  (~0xAAAAAAAA & ~0xCCCCCCCC) | ( 0xAAAAAAAA & 0xF0F0F0F0),
275  (~0xAAAAAAAA & 0xCCCCCCCC) | ( 0xAAAAAAAA & ~0xF0F0F0F0),
276  (~0xAAAAAAAA & 0xCCCCCCCC) | ( 0xAAAAAAAA & 0xF0F0F0F0),
277  ( 0xAAAAAAAA & ~0xCCCCCCCC) | (~0xAAAAAAAA & ~0xF0F0F0F0),
278  ( 0xAAAAAAAA & ~0xCCCCCCCC) | (~0xAAAAAAAA & 0xF0F0F0F0),
279  ( 0xAAAAAAAA & 0xCCCCCCCC) | (~0xAAAAAAAA & ~0xF0F0F0F0),
280  ( 0xAAAAAAAA & 0xCCCCCCCC) | (~0xAAAAAAAA & 0xF0F0F0F0),
281 
282  (~0xCCCCCCCC & ~0xAAAAAAAA) | ( 0xCCCCCCCC & ~0xF0F0F0F0),
283  (~0xCCCCCCCC & ~0xAAAAAAAA) | ( 0xCCCCCCCC & 0xF0F0F0F0),
284  (~0xCCCCCCCC & 0xAAAAAAAA) | ( 0xCCCCCCCC & ~0xF0F0F0F0),
285  (~0xCCCCCCCC & 0xAAAAAAAA) | ( 0xCCCCCCCC & 0xF0F0F0F0),
286  ( 0xCCCCCCCC & ~0xAAAAAAAA) | (~0xCCCCCCCC & ~0xF0F0F0F0),
287  ( 0xCCCCCCCC & ~0xAAAAAAAA) | (~0xCCCCCCCC & 0xF0F0F0F0),
288  ( 0xCCCCCCCC & 0xAAAAAAAA) | (~0xCCCCCCCC & ~0xF0F0F0F0),
289  ( 0xCCCCCCCC & 0xAAAAAAAA) | (~0xCCCCCCCC & 0xF0F0F0F0),
290 
291  (~0xF0F0F0F0 & ~0xCCCCCCCC) | ( 0xF0F0F0F0 & ~0xAAAAAAAA),
292  (~0xF0F0F0F0 & ~0xCCCCCCCC) | ( 0xF0F0F0F0 & 0xAAAAAAAA),
293  (~0xF0F0F0F0 & 0xCCCCCCCC) | ( 0xF0F0F0F0 & ~0xAAAAAAAA),
294  (~0xF0F0F0F0 & 0xCCCCCCCC) | ( 0xF0F0F0F0 & 0xAAAAAAAA),
295  ( 0xF0F0F0F0 & ~0xCCCCCCCC) | (~0xF0F0F0F0 & ~0xAAAAAAAA),
296  ( 0xF0F0F0F0 & ~0xCCCCCCCC) | (~0xF0F0F0F0 & 0xAAAAAAAA),
297  ( 0xF0F0F0F0 & 0xCCCCCCCC) | (~0xF0F0F0F0 & ~0xAAAAAAAA),
298  ( 0xF0F0F0F0 & 0xCCCCCCCC) | (~0xF0F0F0F0 & 0xAAAAAAAA)
299  };
300  int i;
301  for ( i = 0; i < 24; i++ )
302  if ( ((unsigned)t) == s_Muxes[i] )
303  return 1;
304  return 0;
305 }
306 
307 /**Function*************************************************************
308 
309  Synopsis [Count the number of unique drivers and invertors.]
310 
311  Description []
312 
313  SideEffects []
314 
315  SeeAlso []
316 
317 ***********************************************************************/
318 void Lf_ManAnalyzeCoDrivers( Gia_Man_t * p, int * pnDrivers, int * pnInverts )
319 {
320  Gia_Obj_t * pObj;
321  int i, Entry, nDrivers, nInverts;
322  Vec_Int_t * vMarks = Vec_IntStart( Gia_ManObjNum(p) );
323  nDrivers = nInverts = 0;
324  Gia_ManForEachCo( p, pObj, i )
325  *Vec_IntEntryP( vMarks, Gia_ObjFaninId0p(p, pObj) ) |= Gia_ObjFaninC0(pObj) ? 2 : 1;
326  Vec_IntForEachEntry( vMarks, Entry, i )
327  nDrivers += (int)(Entry != 0), nInverts += (int)(Entry == 3);
328  Vec_IntFree( vMarks );
329  *pnDrivers = nDrivers;
330  *pnInverts = nInverts;
331 }
333 {
334 // abctime clk = Abc_Clock();
335  Vec_Flt_t * vSwitching = (Vec_Flt_t *)Gia_ManComputeSwitchProbs( p, 48, 16, 0 );
336  assert( Vec_FltCap(vSwitches) == 0 );
337  *vSwitches = *vSwitching;
338  ABC_FREE( vSwitching );
339 // Abc_PrintTime( 1, "Computing switching activity", Abc_Clock() - clk );
340 }
341 
342 /**Function*************************************************************
343 
344  Synopsis []
345 
346  Description []
347 
348  SideEffects []
349 
350  SeeAlso []
351 
352 ***********************************************************************/
353 static inline int Lf_CutCreateUnit( Lf_Cut_t * p, int i )
354 {
355  p->fLate = 0;
356  p->fMux7 = 0;
357  p->iFunc = 2;
358  p->nLeaves = 1;
359  p->pLeaves[0] = i;
360  p->Sign = ((word)1) << (i & 0x3F);
361  return 1;
362 }
363 static inline Lf_Cut_t * Lf_ManFetchSet( Lf_Man_t * p, int i )
364 {
365  int uMaskPage = (1 << LF_LOG_PAGE) - 1;
366  Gia_Obj_t * pObj = Gia_ManObj( p->pGia, i );
367  int iOffSet = Vec_IntEntry( &p->vOffsets, i );
368  int Entry = Vec_IntEntry( &p->vCutSets, iOffSet );
369  assert( Gia_ObjIsAndNotBuf(pObj) );
370  assert( pObj->Value > 0 );
371  if ( Entry == -1 ) // first visit
372  {
373  if ( Vec_IntSize(&p->vFreeSets) == 0 ) // add new
374  {
375  Lf_Cut_t * pCut = (Lf_Cut_t *)ABC_CALLOC( word, p->nSetWords * (1 << LF_LOG_PAGE) );
376  int uMaskShift = Vec_PtrSize(&p->vMemSets) << LF_LOG_PAGE;
377  Vec_PtrPush( &p->vMemSets, pCut );
378  for ( Entry = uMaskPage; Entry >= 0; Entry-- )
379  {
380  Vec_IntPush( &p->vFreeSets, uMaskShift | Entry );
381  pCut[Entry].nLeaves = LF_NO_LEAF;
382  }
383  }
384  Entry = Vec_IntPop( &p->vFreeSets );
385  Vec_IntWriteEntry( &p->vCutSets, iOffSet, Entry );
386  p->nFrontMax = Abc_MaxInt( p->nFrontMax, Entry + 1 );
387  }
388  else if ( --pObj->Value == 0 )
389  {
390  Vec_IntPush( &p->vFreeSets, Entry );
391  Vec_IntWriteEntry( &p->vCutSets, iOffSet, -1 );
392  }
393  return (Lf_Cut_t *)((word *)Vec_PtrEntry(&p->vMemSets, Entry >> LF_LOG_PAGE) + p->nSetWords * (Entry & uMaskPage));
394 }
395 static inline int Lf_ManPrepareSet( Lf_Man_t * p, int iObj, int Index, Lf_Cut_t ** ppCutSet )
396 {
397  static word CutTemp[3][LF_CUT_WORDS];
398  if ( Vec_IntEntry(&p->vOffsets, iObj) == -1 )
399  return Lf_CutCreateUnit( (*ppCutSet = (Lf_Cut_t *)CutTemp[Index]), iObj );
400  {
401  Lf_Cut_t * pCut;
402  int i, nCutNum = p->pPars->nCutNum;
403  *ppCutSet = Lf_ManFetchSet(p, iObj);
404  Lf_CutSetForEachCut( p->nCutWords, *ppCutSet, pCut, i, nCutNum )
405  if ( pCut->nLeaves == LF_NO_LEAF )
406  return i;
407  return i;
408  }
409 }
410 
411 /**Function*************************************************************
412 
413  Synopsis [Cut manipulation.]
414 
415  Description []
416 
417  SideEffects []
418 
419  SeeAlso []
420 
421 ***********************************************************************/
422 static inline word Lf_CutGetSign( Lf_Cut_t * pCut )
423 {
424  word Sign = 0; int i;
425  for ( i = 0; i < (int)pCut->nLeaves; i++ )
426  Sign |= ((word)1) << (pCut->pLeaves[i] & 0x3F);
427  return Sign;
428 }
429 static inline int Lf_CutCountBits( word i )
430 {
431  i = i - ((i >> 1) & 0x5555555555555555);
432  i = (i & 0x3333333333333333) + ((i >> 2) & 0x3333333333333333);
433  i = ((i + (i >> 4)) & 0x0F0F0F0F0F0F0F0F);
434  return (i*(0x0101010101010101))>>56;
435 }
436 static inline int Lf_CutEqual( Lf_Cut_t * pCut0, Lf_Cut_t * pCut1 )
437 {
438  int i;
439  if ( pCut0->iFunc != pCut1->iFunc )
440  return 0;
441  if ( pCut0->nLeaves != pCut1->nLeaves )
442  return 0;
443  for ( i = 0; i < (int)pCut0->nLeaves; i++ )
444  if ( pCut0->pLeaves[i] != pCut1->pLeaves[i] )
445  return 0;
446  return 1;
447 }
448 static inline float Lf_CutSwitches( Lf_Man_t * p, Lf_Cut_t * pCut )
449 {
450  float Switches = 0; int i;
451  for ( i = 0; i < (int)pCut->nLeaves; i++ )
452  Switches += Lf_ObjSwitches(p, pCut->pLeaves[i]);
453 //printf( "%.2f ", Switches );
454  return Switches;
455 }
456 static inline void Lf_CutPrint( Lf_Man_t * p, Lf_Cut_t * pCut )
457 {
458  int i, nDigits = Abc_Base10Log(Gia_ManObjNum(p->pGia));
459  printf( "%d {", pCut->nLeaves );
460  for ( i = 0; i < (int)pCut->nLeaves; i++ )
461  printf( " %*d", nDigits, pCut->pLeaves[i] );
462  for ( ; i < (int)p->pPars->nLutSize; i++ )
463  printf( " %*s", nDigits, " " );
464  printf( " } Late = %d D = %4d A = %9.4f F = %6d\n",
465  pCut->fLate, pCut->Delay, pCut->Flow, pCut->iFunc );
466 }
467 static inline float Lf_CutArea( Lf_Man_t * p, Lf_Cut_t * pCut )
468 {
469  if ( pCut->nLeaves < 2 || pCut->fMux7 )
470  return 0;
471  if ( p->pPars->fPower )
472  return 1.0 * pCut->nLeaves + Lf_CutSwitches( p, pCut );
473  if ( p->pPars->fOptEdge )
474  return pCut->nLeaves + p->pPars->nAreaTuner;
475  return 1;
476 }
477 static inline int Lf_CutIsMux( Lf_Man_t * p, Lf_Cut_t * pCut, Gia_Obj_t * pMux )
478 {
479  int i, Id;
480  if ( pCut->nLeaves != 3 )
481  return 0;
482  assert( Gia_ObjIsMux(p->pGia, pMux) );
483  if ( Gia_ObjIsCi(Gia_ObjFanin0(pMux)) || Gia_ObjIsCi(Gia_ObjFanin1(pMux)) )
484  return 0;
485  Id = Gia_ObjFaninId0p( p->pGia, pMux );
486  for ( i = 0; i < 3; i++ )
487  if ( pCut->pLeaves[i] == Id )
488  break;
489  if ( i == 3 )
490  return 0;
491  Id = Gia_ObjFaninId1p( p->pGia, pMux );
492  for ( i = 0; i < 3; i++ )
493  if ( pCut->pLeaves[i] == Id )
494  break;
495  if ( i == 3 )
496  return 0;
497  Id = Gia_ObjFaninId2p( p->pGia, pMux );
498  for ( i = 0; i < 3; i++ )
499  if ( pCut->pLeaves[i] == Id )
500  break;
501  if ( i == 3 )
502  return 0;
503  return 1;
504 }
505 
506 /**Function*************************************************************
507 
508  Synopsis [Cut packing.]
509 
510  Description []
511 
512  SideEffects []
513 
514  SeeAlso []
515 
516 ***********************************************************************/
517 static inline void Lf_MemAlloc( Lf_Mem_t * p, int LogPage, Vec_Ptr_t * vFree, int nCutWords )
518 {
519  memset( p, 0, sizeof(Lf_Mem_t) );
520  p->LogPage = LogPage;
521  p->MaskPage = (1 << LogPage) - 1;
522  p->nCutWords = nCutWords;
523  p->vFree = vFree;
524 }
525 static inline int Lf_MemSaveCut( Lf_Mem_t * p, Lf_Cut_t * pCut, int iObj )
526 {
527  unsigned char * pPlace;
528  int i, iPlace, Prev = iObj, iCur = p->iCur;
529  assert( !pCut->fMux7 );
530  if ( Vec_PtrSize(&p->vPages) == (p->iCur >> p->LogPage) )
531  Vec_PtrPush( &p->vPages, Vec_PtrSize(p->vFree) ? Vec_PtrPop(p->vFree) : ABC_ALLOC(char,p->MaskPage+1) );
532  assert( p->MaskPage - (p->iCur & p->MaskPage) >= 4 * (LF_LEAF_MAX + 2) );
533  iPlace = iCur & p->MaskPage;
534  pPlace = (unsigned char *)Vec_PtrEntry(&p->vPages, p->iCur >> p->LogPage);
535  iPlace = Gia_AigerWriteUnsignedBuffer( pPlace, iPlace, pCut->nLeaves );
536  for ( i = pCut->nLeaves - 1; i >= 0; i-- )
537  iPlace = Gia_AigerWriteUnsignedBuffer( pPlace, iPlace, Prev - pCut->pLeaves[i] ), Prev = pCut->pLeaves[i];
538  assert( pCut->nLeaves >= 2 || pCut->iFunc <= 3 );
539  if ( pCut->iFunc >= 0 )
540  iPlace = Gia_AigerWriteUnsignedBuffer( pPlace, iPlace, pCut->iFunc );
541  if ( p->MaskPage - (iPlace & p->MaskPage) < 4 * (LF_LEAF_MAX + 2) )
542  p->iCur = ((p->iCur >> p->LogPage) + 1) << p->LogPage;
543  else
544  p->iCur = (p->iCur & ~p->MaskPage) | iPlace;
545  return iCur;
546 }
547 static inline Lf_Cut_t * Lf_MemLoadCut( Lf_Mem_t * p, int iCur, int iObj, Lf_Cut_t * pCut, int fTruth, int fRecycle )
548 {
549  unsigned char * pPlace;
550  int i, Prev = iObj, Page = iCur >> p->LogPage;
551  assert( Page < Vec_PtrSize(&p->vPages) );
552  pPlace = (unsigned char *)Vec_PtrEntry(&p->vPages, Page) + (iCur & p->MaskPage);
553  pCut->nLeaves = Gia_AigerReadUnsigned(&pPlace);
554  assert( pCut->nLeaves <= LF_LEAF_MAX );
555  for ( i = pCut->nLeaves - 1; i >= 0; i-- )
556  pCut->pLeaves[i] = Prev - Gia_AigerReadUnsigned(&pPlace), Prev = pCut->pLeaves[i];
557  pCut->iFunc = fTruth ? Gia_AigerReadUnsigned(&pPlace) : -1;
558  assert( pCut->nLeaves >= 2 || pCut->iFunc <= 3 );
559  if ( fRecycle && Page && Vec_PtrEntry(&p->vPages, Page-1) )
560  {
561  Vec_PtrPush( p->vFree, Vec_PtrEntry(&p->vPages, Page-1) );
562  Vec_PtrWriteEntry( &p->vPages, Page-1, NULL );
563  }
564  pCut->Sign = fRecycle ? Lf_CutGetSign(pCut) : 0;
565  pCut->fMux7 = 0;
566  return pCut;
567 }
568 static inline void Lf_MemRecycle( Lf_Mem_t * p )
569 {
570  void * pPlace; int i;
571  Vec_PtrForEachEntry( void *, &p->vPages, pPlace, i )
572  if ( pPlace )
573  Vec_PtrPush( p->vFree, pPlace );
574  Vec_PtrClear( &p->vPages );
575  p->iCur = 0;
576 }
577 static inline Lf_Cut_t * Lf_MemLoadMuxCut( Lf_Man_t * p, int iObj, Lf_Cut_t * pCut )
578 {
579  Gia_Obj_t * pMux = Gia_ManObj( p->pGia, iObj );
580  assert( Gia_ObjIsMux(p->pGia, pMux) );
581  pCut->iFunc = p->pPars->fCutMin ? 4 : -1;
582  pCut->pLeaves[0] = Gia_ObjFaninId0( pMux, iObj );
583  pCut->pLeaves[1] = Gia_ObjFaninId1( pMux, iObj );
584  pCut->pLeaves[2] = Gia_ObjFaninId2( p->pGia, iObj );
585  pCut->nLeaves = 3;
586  pCut->fMux7 = 1;
587  return pCut;
588 }
589 static inline Lf_Cut_t * Lf_ObjCutMux( Lf_Man_t * p, int i )
590 {
591  static word CutSet[LF_CUT_WORDS];
592  return Lf_MemLoadMuxCut( p, i, (Lf_Cut_t *)CutSet );
593 }
594 static inline Lf_Cut_t * Lf_ObjCutBest( Lf_Man_t * p, int i )
595 {
596  static word CutSet[LF_CUT_WORDS];
597  Lf_Bst_t * pBest = Lf_ObjReadBest( p, i );
598  Lf_Cut_t * pCut = (Lf_Cut_t *)CutSet;
599  int Index = Lf_BestCutIndex( pBest );
600  pCut->Delay = pBest->Delay[Index];
601  pCut->Flow = pBest->Flow[Index];
602  if ( Index == 2 )
603  return Lf_MemLoadMuxCut( p, i, pCut );
604  return Lf_MemLoadCut( &p->vStoreOld, pBest->Cut[Index].Handle, i, pCut, p->pPars->fCutMin, 0 );
605 }
606 static inline Lf_Cut_t * Lf_ObjCutBestNew( Lf_Man_t * p, int i, Lf_Cut_t * pCut )
607 {
608  Lf_Bst_t * pBest = Lf_ObjReadBest( p, i );
609  int Index = Lf_BestCutIndex( pBest );
610  pCut->Delay = pBest->Delay[Index];
611  pCut->Flow = pBest->Flow[Index];
612  if ( Index == 2 )
613  return Lf_MemLoadMuxCut( p, i, pCut );
614  return Lf_MemLoadCut( &p->vStoreNew, pBest->Cut[Index].Handle, i, pCut, 0, 0 );
615 }
616 
617 /**Function*************************************************************
618 
619  Synopsis [Check correctness of cuts.]
620 
621  Description []
622 
623  SideEffects []
624 
625  SeeAlso []
626 
627 ***********************************************************************/
628 static inline int Lf_CutCheck( Lf_Cut_t * pBase, Lf_Cut_t * pCut ) // check if pCut is contained in pBase
629 {
630  int nSizeB = pBase->nLeaves;
631  int nSizeC = pCut->nLeaves;
632  int i, * pB = pBase->pLeaves;
633  int k, * pC = pCut->pLeaves;
634  for ( i = 0; i < nSizeC; i++ )
635  {
636  for ( k = 0; k < nSizeB; k++ )
637  if ( pC[i] == pB[k] )
638  break;
639  if ( k == nSizeB )
640  return 0;
641  }
642  return 1;
643 }
644 static inline int Lf_SetCheckArray( Lf_Cut_t ** ppCuts, int nCuts )
645 {
646  Lf_Cut_t * pCut0, * pCut1;
647  int i, k, m, n, Value;
648  assert( nCuts > 0 );
649  for ( i = 0; i < nCuts; i++ )
650  {
651  pCut0 = ppCuts[i];
652  assert( !pCut0->fMux7 );
653  assert( pCut0->nLeaves < LF_LEAF_MAX );
654  assert( pCut0->Sign == Lf_CutGetSign(pCut0) );
655  // check duplicates
656  for ( m = 0; m < (int)pCut0->nLeaves; m++ )
657  for ( n = m + 1; n < (int)pCut0->nLeaves; n++ )
658  assert( pCut0->pLeaves[m] < pCut0->pLeaves[n] );
659  // check pairs
660  for ( k = 0; k < nCuts; k++ )
661  {
662  pCut1 = ppCuts[k];
663  if ( pCut0 == pCut1 )
664  continue;
665  // check containments
666  Value = Lf_CutCheck( pCut0, pCut1 );
667  assert( Value == 0 );
668  }
669  }
670  return 1;
671 }
672 
673 /**Function*************************************************************
674 
675  Synopsis []
676 
677  Description []
678 
679  SideEffects []
680 
681  SeeAlso []
682 
683 ***********************************************************************/
684 static inline int Lf_CutMergeOrder( Lf_Cut_t * pCut0, Lf_Cut_t * pCut1, Lf_Cut_t * pCut, int nLutSize )
685 {
686  int nSize0 = pCut0->nLeaves;
687  int nSize1 = pCut1->nLeaves;
688  int i, * pC0 = pCut0->pLeaves;
689  int k, * pC1 = pCut1->pLeaves;
690  int c, * pC = pCut->pLeaves;
691  // the case of the largest cut sizes
692  if ( nSize0 == nLutSize && nSize1 == nLutSize )
693  {
694  for ( i = 0; i < nSize0; i++ )
695  {
696  if ( pC0[i] != pC1[i] ) return 0;
697  pC[i] = pC0[i];
698  }
699  pCut->nLeaves = nLutSize;
700  pCut->iFunc = -1;
701  pCut->Sign = pCut0->Sign | pCut1->Sign;
702  return 1;
703  }
704  // compare two cuts with different numbers
705  i = k = c = 0;
706  if ( nSize0 == 0 ) goto FlushCut1;
707  if ( nSize1 == 0 ) goto FlushCut0;
708  while ( 1 )
709  {
710  if ( c == nLutSize ) return 0;
711  if ( pC0[i] < pC1[k] )
712  {
713  pC[c++] = pC0[i++];
714  if ( i >= nSize0 ) goto FlushCut1;
715  }
716  else if ( pC0[i] > pC1[k] )
717  {
718  pC[c++] = pC1[k++];
719  if ( k >= nSize1 ) goto FlushCut0;
720  }
721  else
722  {
723  pC[c++] = pC0[i++]; k++;
724  if ( i >= nSize0 ) goto FlushCut1;
725  if ( k >= nSize1 ) goto FlushCut0;
726  }
727  }
728 
729 FlushCut0:
730  if ( c + nSize0 > nLutSize + i ) return 0;
731  while ( i < nSize0 )
732  pC[c++] = pC0[i++];
733  pCut->nLeaves = c;
734  pCut->iFunc = -1;
735  pCut->fMux7 = 0;
736  pCut->Sign = pCut0->Sign | pCut1->Sign;
737  return 1;
738 
739 FlushCut1:
740  if ( c + nSize1 > nLutSize + k ) return 0;
741  while ( k < nSize1 )
742  pC[c++] = pC1[k++];
743  pCut->nLeaves = c;
744  pCut->iFunc = -1;
745  pCut->fMux7 = 0;
746  pCut->Sign = pCut0->Sign | pCut1->Sign;
747  return 1;
748 }
749 static inline int Lf_CutMergeOrder2( Lf_Cut_t * pCut0, Lf_Cut_t * pCut1, Lf_Cut_t * pCut, int nLutSize )
750 {
751  int x0, i0 = 0, nSize0 = pCut0->nLeaves, * pC0 = pCut0->pLeaves;
752  int x1, i1 = 0, nSize1 = pCut1->nLeaves, * pC1 = pCut1->pLeaves;
753  int xMin, c = 0, * pC = pCut->pLeaves;
754  while ( 1 )
755  {
756  x0 = (i0 == nSize0) ? ABC_INFINITY : pC0[i0];
757  x1 = (i1 == nSize1) ? ABC_INFINITY : pC1[i1];
758  xMin = Abc_MinInt(x0, x1);
759  if ( xMin == ABC_INFINITY ) break;
760  if ( c == nLutSize ) return 0;
761  pC[c++] = xMin;
762  if (x0 == xMin) i0++;
763  if (x1 == xMin) i1++;
764  }
765  pCut->nLeaves = c;
766  pCut->iFunc = -1;
767  pCut->fMux7 = 0;
768  pCut->Sign = pCut0->Sign | pCut1->Sign;
769  return 1;
770 }
771 static inline int Lf_CutMergeOrderMux( Lf_Cut_t * pCut0, Lf_Cut_t * pCut1, Lf_Cut_t * pCut2, Lf_Cut_t * pCut, int nLutSize )
772 {
773  int x0, i0 = 0, nSize0 = pCut0->nLeaves, * pC0 = pCut0->pLeaves;
774  int x1, i1 = 0, nSize1 = pCut1->nLeaves, * pC1 = pCut1->pLeaves;
775  int x2, i2 = 0, nSize2 = pCut2->nLeaves, * pC2 = pCut2->pLeaves;
776  int xMin, c = 0, * pC = pCut->pLeaves;
777  while ( 1 )
778  {
779  x0 = (i0 == nSize0) ? ABC_INFINITY : pC0[i0];
780  x1 = (i1 == nSize1) ? ABC_INFINITY : pC1[i1];
781  x2 = (i2 == nSize2) ? ABC_INFINITY : pC2[i2];
782  xMin = Abc_MinInt( Abc_MinInt(x0, x1), x2 );
783  if ( xMin == ABC_INFINITY ) break;
784  if ( c == nLutSize ) return 0;
785  pC[c++] = xMin;
786  if (x0 == xMin) i0++;
787  if (x1 == xMin) i1++;
788  if (x2 == xMin) i2++;
789  }
790  pCut->nLeaves = c;
791  pCut->iFunc = -1;
792  pCut->fMux7 = 0;
793  pCut->Sign = pCut0->Sign | pCut1->Sign | pCut2->Sign;
794  return 1;
795 }
796 
797 static inline int Lf_SetCutIsContainedOrder( Lf_Cut_t * pBase, Lf_Cut_t * pCut ) // check if pCut is contained in pBase
798 {
799  int i, nSizeB = pBase->nLeaves;
800  int k, nSizeC = pCut->nLeaves;
801  if ( nSizeB == nSizeC )
802  {
803  for ( i = 0; i < nSizeB; i++ )
804  if ( pBase->pLeaves[i] != pCut->pLeaves[i] )
805  return 0;
806  return 1;
807  }
808  assert( nSizeB > nSizeC );
809  if ( nSizeC == 0 )
810  return 1;
811  for ( i = k = 0; i < nSizeB; i++ )
812  {
813  if ( pBase->pLeaves[i] > pCut->pLeaves[k] )
814  return 0;
815  if ( pBase->pLeaves[i] == pCut->pLeaves[k] )
816  {
817  if ( ++k == nSizeC )
818  return 1;
819  }
820  }
821  return 0;
822 }
823 static inline int Lf_SetLastCutIsContained( Lf_Cut_t ** pCuts, int nCuts )
824 {
825  int i;
826  for ( i = 0; i < nCuts; i++ )
827  if ( pCuts[i]->nLeaves <= pCuts[nCuts]->nLeaves && (pCuts[i]->Sign & pCuts[nCuts]->Sign) == pCuts[i]->Sign && Lf_SetCutIsContainedOrder(pCuts[nCuts], pCuts[i]) )
828  return 1;
829  return 0;
830 }
831 
832 
833 /**Function*************************************************************
834 
835  Synopsis []
836 
837  Description []
838 
839  SideEffects []
840 
841  SeeAlso []
842 
843 ***********************************************************************/
844 static inline int Lf_CutCompareDelay( Lf_Cut_t * pCut0, Lf_Cut_t * pCut1 )
845 {
846  if ( pCut0->Delay < pCut1->Delay ) return -1;
847  if ( pCut0->Delay > pCut1->Delay ) return 1;
848  if ( pCut0->nLeaves < pCut1->nLeaves ) return -1;
849  if ( pCut0->nLeaves > pCut1->nLeaves ) return 1;
850  if ( pCut0->Flow < pCut1->Flow ) return -1;
851  if ( pCut0->Flow > pCut1->Flow ) return 1;
852  return 0;
853 }
854 static inline int Lf_CutCompareArea( Lf_Cut_t * pCut0, Lf_Cut_t * pCut1 )
855 {
856  if ( pCut0->fLate < pCut1->fLate ) return -1;
857  if ( pCut0->fLate > pCut1->fLate ) return 1;
858  if ( pCut0->Flow < pCut1->Flow ) return -1;
859  if ( pCut0->Flow > pCut1->Flow ) return 1;
860  if ( pCut0->Delay < pCut1->Delay ) return -1;
861  if ( pCut0->Delay > pCut1->Delay ) return 1;
862  if ( pCut0->nLeaves < pCut1->nLeaves ) return -1;
863  if ( pCut0->nLeaves > pCut1->nLeaves ) return 1;
864  return 0;
865 }
866 static inline int Lf_SetLastCutContainsArea( Lf_Cut_t ** pCuts, int nCuts )
867 {
868  int i, k, fChanges = 0;
869  for ( i = 1; i < nCuts; i++ )
870  if ( pCuts[nCuts]->nLeaves < pCuts[i]->nLeaves && (pCuts[nCuts]->Sign & pCuts[i]->Sign) == pCuts[nCuts]->Sign && Lf_SetCutIsContainedOrder(pCuts[i], pCuts[nCuts]) )
871  pCuts[i]->nLeaves = LF_NO_LEAF, fChanges = 1;
872  if ( !fChanges )
873  return nCuts;
874  for ( i = k = 1; i <= nCuts; i++ )
875  {
876  if ( pCuts[i]->nLeaves == LF_NO_LEAF )
877  continue;
878  if ( k < i )
879  ABC_SWAP( Lf_Cut_t *, pCuts[k], pCuts[i] );
880  k++;
881  }
882  return k - 1;
883 }
884 static inline void Lf_SetSortByArea( Lf_Cut_t ** pCuts, int nCuts )
885 {
886  int i;
887  for ( i = nCuts; i > 1; i-- )
888  {
889  if ( Lf_CutCompareArea(pCuts[i - 1], pCuts[i]) < 0 )//!= 1 )
890  return;
891  ABC_SWAP( Lf_Cut_t *, pCuts[i - 1], pCuts[i] );
892  }
893 }
894 static inline int Lf_SetAddCut( Lf_Cut_t ** pCuts, int nCuts, int nCutNum )
895 {
896  if ( nCuts == 0 )
897  return 1;
898  nCuts = Lf_SetLastCutContainsArea(pCuts, nCuts);
899  assert( nCuts >= 1 );
900  if ( Lf_CutCompareDelay(pCuts[0], pCuts[nCuts]) == 1 ) // new cut is better for delay
901  {
902  ABC_SWAP( Lf_Cut_t *, pCuts[0], pCuts[nCuts] );
903  // if old cut (now cut number nCuts) is contained - remove it
904  if ( pCuts[0]->nLeaves < pCuts[nCuts]->nLeaves && (pCuts[0]->Sign & pCuts[nCuts]->Sign) == pCuts[0]->Sign && Lf_SetCutIsContainedOrder(pCuts[nCuts], pCuts[0]) )
905  return nCuts;
906  }
907  // sort area cuts by area
908  Lf_SetSortByArea( pCuts, nCuts );
909  // add new cut if there is room
910  return Abc_MinInt( nCuts + 1, nCutNum - 1 );
911 }
912 static inline void Lf_SetSortBySize( Lf_Cut_t ** pCutsR, int nCutsR )
913 {
914  int i, j, best_i;
915  for ( i = 1; i < nCutsR-1; i++ )
916  {
917  best_i = i;
918  for ( j = i+1; j < nCutsR; j++ )
919  if ( pCutsR[j]->nLeaves > pCutsR[best_i]->nLeaves )
920  best_i = j;
921  ABC_SWAP( Lf_Cut_t *, pCutsR[i], pCutsR[best_i] );
922  }
923 }
924 
925 /**Function*************************************************************
926 
927  Synopsis [Check if truth table has non-const-cof cofactoring variable.]
928 
929  Description []
930 
931  SideEffects []
932 
933  SeeAlso []
934 
935 ***********************************************************************/
936 static inline int Lf_ManFindCofVar( word * pTruth, int nWords, int nVars )
937 {
938  word uTruthCof[LF_TT_WORDS]; int iVar;
939  for ( iVar = 0; iVar < nVars; iVar++ )
940  {
941  Abc_TtCofactor0p( uTruthCof, pTruth, nWords, iVar );
942  if ( Abc_TtSupportSize(uTruthCof, nVars) < 2 )
943  continue;
944  Abc_TtCofactor1p( uTruthCof, pTruth, nWords, iVar );
945  if ( Abc_TtSupportSize(uTruthCof, nVars) < 2 )
946  continue;
947  return iVar;
948  }
949  return -1;
950 }
951 
952 /**Function*************************************************************
953 
954  Synopsis []
955 
956  Description []
957 
958  SideEffects []
959 
960  SeeAlso []
961 
962 ***********************************************************************/
963 static inline int Lf_CutComputeTruth6( Lf_Man_t * p, Lf_Cut_t * pCut0, Lf_Cut_t * pCut1, int fCompl0, int fCompl1, Lf_Cut_t * pCutR, int fIsXor )
964 {
965 // extern int Mf_ManTruthCanonicize( word * t, int nVars );
966  int nOldSupp = pCutR->nLeaves, truthId, fCompl; word t;
967  word t0 = *Lf_CutTruth(p, pCut0);
968  word t1 = *Lf_CutTruth(p, pCut1);
969  if ( Abc_LitIsCompl(pCut0->iFunc) ^ fCompl0 ) t0 = ~t0;
970  if ( Abc_LitIsCompl(pCut1->iFunc) ^ fCompl1 ) t1 = ~t1;
971  t0 = Abc_Tt6Expand( t0, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
972  t1 = Abc_Tt6Expand( t1, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
973  t = fIsXor ? t0 ^ t1 : t0 & t1;
974  if ( (fCompl = (int)(t & 1)) ) t = ~t;
975  pCutR->nLeaves = Abc_Tt6MinBase( &t, pCutR->pLeaves, pCutR->nLeaves );
976  assert( (int)(t & 1) == 0 );
977  truthId = Vec_MemHashInsert(p->vTtMem, &t);
978  pCutR->iFunc = Abc_Var2Lit( truthId, fCompl );
979 // p->nCutMux += Lf_ManTtIsMux( t );
980  assert( (int)pCutR->nLeaves <= nOldSupp );
981 // Mf_ManTruthCanonicize( &t, pCutR->nLeaves );
982  return (int)pCutR->nLeaves < nOldSupp;
983 }
984 static inline int Lf_CutComputeTruth( Lf_Man_t * p, Lf_Cut_t * pCut0, Lf_Cut_t * pCut1, int fCompl0, int fCompl1, Lf_Cut_t * pCutR, int fIsXor )
985 {
986  if ( p->pPars->nLutSize <= 6 )
987  return Lf_CutComputeTruth6( p, pCut0, pCut1, fCompl0, fCompl1, pCutR, fIsXor );
988  {
989  word uTruth[LF_TT_WORDS], uTruth0[LF_TT_WORDS], uTruth1[LF_TT_WORDS];
990  int nOldSupp = pCutR->nLeaves, truthId;
991  int LutSize = p->pPars->nLutSize, fCompl;
992  int nWords = Abc_Truth6WordNum(LutSize);
993  word * pTruth0 = Lf_CutTruth(p, pCut0);
994  word * pTruth1 = Lf_CutTruth(p, pCut1);
995  Abc_TtCopy( uTruth0, pTruth0, nWords, Abc_LitIsCompl(pCut0->iFunc) ^ fCompl0 );
996  Abc_TtCopy( uTruth1, pTruth1, nWords, Abc_LitIsCompl(pCut1->iFunc) ^ fCompl1 );
997  Abc_TtExpand( uTruth0, LutSize, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
998  Abc_TtExpand( uTruth1, LutSize, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
999  if ( fIsXor )
1000  Abc_TtXor( uTruth, uTruth0, uTruth1, nWords, (fCompl = (int)((uTruth0[0] ^ uTruth1[0]) & 1)) );
1001  else
1002  Abc_TtAnd( uTruth, uTruth0, uTruth1, nWords, (fCompl = (int)((uTruth0[0] & uTruth1[0]) & 1)) );
1003  pCutR->nLeaves = Abc_TtMinBase( uTruth, pCutR->pLeaves, pCutR->nLeaves, LutSize );
1004  assert( (uTruth[0] & 1) == 0 );
1005 //Kit_DsdPrintFromTruth( uTruth, pCutR->nLeaves ), printf("\n" ), printf("\n" );
1006  truthId = Vec_MemHashInsert(p->vTtMem, uTruth);
1007  pCutR->iFunc = Abc_Var2Lit( truthId, fCompl );
1008  assert( (int)pCutR->nLeaves <= nOldSupp );
1009  return (int)pCutR->nLeaves < nOldSupp;
1010  }
1011 }
1012 static inline int Lf_CutComputeTruthMux6( Lf_Man_t * p, Lf_Cut_t * pCut0, Lf_Cut_t * pCut1, Lf_Cut_t * pCutC, int fCompl0, int fCompl1, int fComplC, Lf_Cut_t * pCutR )
1013 {
1014  int nOldSupp = pCutR->nLeaves, truthId, fCompl; word t;
1015  word t0 = *Lf_CutTruth(p, pCut0);
1016  word t1 = *Lf_CutTruth(p, pCut1);
1017  word tC = *Lf_CutTruth(p, pCutC);
1018  if ( Abc_LitIsCompl(pCut0->iFunc) ^ fCompl0 ) t0 = ~t0;
1019  if ( Abc_LitIsCompl(pCut1->iFunc) ^ fCompl1 ) t1 = ~t1;
1020  if ( Abc_LitIsCompl(pCutC->iFunc) ^ fComplC ) tC = ~tC;
1021  t0 = Abc_Tt6Expand( t0, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
1022  t1 = Abc_Tt6Expand( t1, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
1023  tC = Abc_Tt6Expand( tC, pCutC->pLeaves, pCutC->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
1024  t = (tC & t1) | (~tC & t0);
1025  if ( (fCompl = (int)(t & 1)) ) t = ~t;
1026  pCutR->nLeaves = Abc_Tt6MinBase( &t, pCutR->pLeaves, pCutR->nLeaves );
1027  assert( (int)(t & 1) == 0 );
1028  truthId = Vec_MemHashInsert(p->vTtMem, &t);
1029  pCutR->iFunc = Abc_Var2Lit( truthId, fCompl );
1030  assert( (int)pCutR->nLeaves <= nOldSupp );
1031  return (int)pCutR->nLeaves < nOldSupp;
1032 }
1033 static inline int Lf_CutComputeTruthMux( Lf_Man_t * p, Lf_Cut_t * pCut0, Lf_Cut_t * pCut1, Lf_Cut_t * pCutC, int fCompl0, int fCompl1, int fComplC, Lf_Cut_t * pCutR )
1034 {
1035  if ( p->pPars->nLutSize <= 6 )
1036  return Lf_CutComputeTruthMux6( p, pCut0, pCut1, pCutC, fCompl0, fCompl1, fComplC, pCutR );
1037  {
1038  word uTruth[LF_TT_WORDS], uTruth0[LF_TT_WORDS], uTruth1[LF_TT_WORDS], uTruthC[LF_TT_WORDS];
1039  int nOldSupp = pCutR->nLeaves, truthId;
1040  int LutSize = p->pPars->nLutSize, fCompl;
1041  int nWords = Abc_Truth6WordNum(LutSize);
1042  word * pTruth0 = Lf_CutTruth(p, pCut0);
1043  word * pTruth1 = Lf_CutTruth(p, pCut1);
1044  word * pTruthC = Lf_CutTruth(p, pCutC);
1045  Abc_TtCopy( uTruth0, pTruth0, nWords, Abc_LitIsCompl(pCut0->iFunc) ^ fCompl0 );
1046  Abc_TtCopy( uTruth1, pTruth1, nWords, Abc_LitIsCompl(pCut1->iFunc) ^ fCompl1 );
1047  Abc_TtCopy( uTruthC, pTruthC, nWords, Abc_LitIsCompl(pCutC->iFunc) ^ fComplC );
1048  Abc_TtExpand( uTruth0, LutSize, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
1049  Abc_TtExpand( uTruth1, LutSize, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
1050  Abc_TtExpand( uTruthC, LutSize, pCutC->pLeaves, pCutC->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
1051  Abc_TtMux( uTruth, uTruthC, uTruth1, uTruth0, nWords );
1052  fCompl = (int)(uTruth[0] & 1);
1053  if ( fCompl ) Abc_TtNot( uTruth, nWords );
1054  pCutR->nLeaves = Abc_TtMinBase( uTruth, pCutR->pLeaves, pCutR->nLeaves, LutSize );
1055  assert( (uTruth[0] & 1) == 0 );
1056  truthId = Vec_MemHashInsert(p->vTtMem, uTruth);
1057  pCutR->iFunc = Abc_Var2Lit( truthId, fCompl );
1058  assert( (int)pCutR->nLeaves <= nOldSupp );
1059  return (int)pCutR->nLeaves < nOldSupp;
1060  }
1061 }
1062 
1063 /**Function*************************************************************
1064 
1065  Synopsis [Exact local area.]
1066 
1067  Description []
1068 
1069  SideEffects []
1070 
1071  SeeAlso []
1072 
1073 ***********************************************************************/
1074 float Lf_CutRef_rec( Lf_Man_t * p, Lf_Cut_t * pCut )
1075 {
1076  word CutTemp[LF_CUT_WORDS] = {0};
1077  float Count = Lf_CutArea(p, pCut);
1078  int i, Var;
1079  Lf_CutForEachVar( pCut, Var, i )
1080  if ( !Lf_ObjMapRefInc(p, Var) )
1081  Count += Lf_CutRef_rec( p, Lf_ObjCutBestNew(p, Var, (Lf_Cut_t *)CutTemp) );
1082  return Count;
1083 }
1085 {
1086  word CutTemp[LF_CUT_WORDS] = {0};
1087  float Count = Lf_CutArea(p, pCut);
1088  int i, Var;
1089  Lf_CutForEachVar( pCut, Var, i )
1090  if ( !Lf_ObjMapRefDec(p, Var) )
1091  Count += Lf_CutDeref_rec( p, Lf_ObjCutBestNew(p, Var, (Lf_Cut_t *)CutTemp) );
1092  return Count;
1093 }
1094 static inline float Lf_CutAreaDerefed( Lf_Man_t * p, Lf_Cut_t * pCut )
1095 {
1096  float Ela1 = Lf_CutRef_rec( p, pCut );
1097  Lf_CutDeref_rec( p, pCut );
1098 // float Ela2 = Lf_CutDeref_rec( p, pCut );
1099 // assert( Ela1 == Ela2 );
1100  return Ela1;
1101 }
1102 
1103 
1104 /**Function*************************************************************
1105 
1106  Synopsis []
1107 
1108  Description []
1109 
1110  SideEffects []
1111 
1112  SeeAlso []
1113 
1114 ***********************************************************************/
1115 static inline int Lf_CutRequired( Lf_Man_t * p, Lf_Cut_t * pCut )
1116 {
1117  int i, Arr, Req, Arrival = 0, Required = 0;
1118  for ( i = 0; i < (int)pCut->nLeaves; i++ )
1119  {
1120  if ( Lf_ObjOff(p, pCut->pLeaves[i]) < 0 )
1121 // Arr = Lf_ObjCiArrival( p, Gia_ObjCioId(Gia_ManObj(p->pGia, pCut->pLeaves[i])) );
1122  Arr = Lf_ObjArrival_rec( p, Gia_ManObj(p->pGia, pCut->pLeaves[i]) );
1123  else
1124  Arr = Lf_ObjReadBest(p, pCut->pLeaves[i])->Delay[0];
1125  Arrival = Abc_MaxInt( Arrival, Arr );
1126  Req = Lf_ObjRequired(p, pCut->pLeaves[i]);
1127  if ( Req < ABC_INFINITY )
1128  Required = Abc_MaxInt( Required, Req );
1129  }
1130  return Abc_MaxInt( Required + 2, Arrival + 1 );
1131 }
1132 static inline void Lf_CutParams( Lf_Man_t * p, Lf_Cut_t * pCut, int Required, float FlowRefs, Gia_Obj_t * pMux )
1133 {
1134  Lf_Bst_t * pBest;
1135  int i, Index, Delay;
1136  assert( !pCut->fMux7 || Gia_ObjIsMux(p->pGia, pMux) );
1137  pCut->fLate = 0;
1138  pCut->Delay = 0;
1139  pCut->Flow = 0;
1140  assert( pCut->nLeaves < LF_NO_LEAF );
1141  for ( i = 0; i < (int)pCut->nLeaves; i++ )
1142  {
1143  if ( Lf_ObjOff(p, pCut->pLeaves[i]) < 0 )
1144 // Delay = Lf_ObjCiArrival( p, Gia_ObjCioId(Gia_ManObj(p->pGia, pCut->pLeaves[i])) );
1145  Delay = Lf_ObjArrival_rec( p, Gia_ManObj(p->pGia, pCut->pLeaves[i]) );
1146  else
1147  {
1148  pBest = Lf_ObjReadBest(p, pCut->pLeaves[i]);
1149  assert( pBest->Delay[0] <= pBest->Delay[1] );
1150  assert( pBest->Flow[0] >= pBest->Flow[1] );
1151  if ( p->fUseEla )
1152  Index = Lf_BestIndex(pBest);
1153  else
1154  {
1155  Index = (int)(pBest->Delay[1] + 1 <= Required && Required != ABC_INFINITY);
1156  pCut->Flow += pBest->Flow[Index];
1157  }
1158  Delay = pBest->Delay[Index];
1159  }
1160 // if ( pCut->fMux7 && pCut->pLeaves[i] == Gia_ObjFaninId2p(p->pGia, pMux) )
1161 // Delay += 1;
1162  pCut->Delay = Abc_MaxInt( pCut->Delay, Delay );
1163  }
1164  pCut->Delay += (int)(pCut->nLeaves > 1);// && !pCut->fMux7;
1165  if ( pCut->Delay > Required )
1166  pCut->fLate = 1;
1167  if ( p->fUseEla )
1168  pCut->Flow = Lf_CutAreaDerefed(p, pCut) / FlowRefs;
1169  else
1170  pCut->Flow = (pCut->Flow + Lf_CutArea(p, pCut)) / FlowRefs;
1171 }
1172 
1173 void Lf_ObjMergeOrder( Lf_Man_t * p, int iObj )
1174 {
1175  word CutSet[LF_CUT_MAX][LF_CUT_WORDS] = {{0}};
1176  Lf_Cut_t * pCutSet0, * pCutSet1, * pCutSet2, * pCut0, * pCut1, * pCut2;
1177  Lf_Cut_t * pCutSet = (Lf_Cut_t *)CutSet, * pCutsR[LF_CUT_MAX];
1178  Gia_Obj_t * pObj = Gia_ManObj(p->pGia, iObj);
1179  Lf_Bst_t * pBest = Lf_ObjReadBest(p, iObj);
1180  float FlowRefs = Lf_ObjFlowRefs(p, iObj);
1181  int Required = Lf_ObjRequired(p, iObj);
1182  int nLutSize = p->pPars->nLutSize;
1183  int nCutNum = p->pPars->nCutNum;
1184  int nCutWords = p->nCutWords;
1185  int fComp0 = Gia_ObjFaninC0(pObj);
1186  int fComp1 = Gia_ObjFaninC1(pObj);
1187  int nCuts0 = Lf_ManPrepareSet( p, Gia_ObjFaninId0(pObj, iObj), 0, &pCutSet0 );
1188  int nCuts1 = Lf_ManPrepareSet( p, Gia_ObjFaninId1(pObj, iObj), 1, &pCutSet1 );
1189  int iSibl = Gia_ObjSibl(p->pGia, iObj);
1190  int i, k, n, iCutUsed, nCutsR = 0;
1191  float Value1 = -1, Value2 = -1;
1192  assert( !Gia_ObjIsBuf(pObj) );
1193  Lf_CutSetForEachCut( nCutWords, pCutSet, pCut0, i, nCutNum )
1194  pCutsR[i] = pCut0;
1195  if ( p->Iter )
1196  {
1197  assert( nCutsR == 0 );
1198  // load cuts
1199  Lf_MemLoadCut( &p->vStoreOld, pBest->Cut[0].Handle, iObj, pCutsR[0], p->pPars->fCutMin, 1 );
1200  if ( Lf_BestDiffCuts(pBest) )
1201  Lf_MemLoadCut( &p->vStoreOld, pBest->Cut[1].Handle, iObj, pCutsR[1], p->pPars->fCutMin, 1 );
1202  // deref the cut
1203  if ( p->fUseEla && Lf_ObjMapRefNum(p, iObj) > 0 )
1204  Value1 = Lf_CutDeref_rec( p, pCutsR[Lf_BestIndex(pBest)] );
1205  // update required times
1206  if ( Required == ABC_INFINITY )//&& !p->fUseEla )
1207  Required = Lf_CutRequired( p, pCutsR[0] );
1208  // compute parameters
1209  Lf_CutParams( p, pCutsR[nCutsR++], Required, FlowRefs, pObj );
1210  if ( Lf_BestDiffCuts(pBest) )
1211  {
1212  assert( nCutsR == 1 );
1213  Lf_CutParams( p, pCutsR[nCutsR], Required, FlowRefs, pObj );
1214  nCutsR = Lf_SetAddCut( pCutsR, nCutsR, nCutNum );
1215  }
1216  if ( pCutsR[0]->fLate )
1217  p->nTimeFails++;
1218  }
1219  if ( iSibl )
1220  {
1221  Gia_Obj_t * pObjE = Gia_ObjSiblObj(p->pGia, iObj);
1222  int fCompE = Gia_ObjPhase(pObj) ^ Gia_ObjPhase(pObjE);
1223  int nCutsE = Lf_ManPrepareSet( p, iSibl, 2, &pCutSet2 );
1224  Lf_CutSetForEachCut( nCutWords, pCutSet2, pCut2, n, nCutsE )
1225  {
1226  if ( pCut2->pLeaves[0] == iSibl )
1227  continue;
1228  Lf_CutCopy( pCutsR[nCutsR], pCut2, nCutWords );
1229  if ( pCutsR[nCutsR]->iFunc >= 0 )
1230  pCutsR[nCutsR]->iFunc = Abc_LitNotCond( pCutsR[nCutsR]->iFunc, fCompE );
1231  Lf_CutParams( p, pCutsR[nCutsR], Required, FlowRefs, pObj );
1232  nCutsR = Lf_SetAddCut( pCutsR, nCutsR, nCutNum );
1233  }
1234  }
1235  if ( Gia_ObjIsMuxId(p->pGia, iObj) )
1236  {
1237  int fComp2 = Gia_ObjFaninC2(p->pGia, pObj);
1238  int nCuts2 = Lf_ManPrepareSet( p, Gia_ObjFaninId2(p->pGia, iObj), 2, &pCutSet2 );
1239  p->CutCount[0] += nCuts0 * nCuts1 * nCuts2;
1240  Lf_CutSetForEachCut( nCutWords, pCutSet0, pCut0, i, nCuts0 )
1241  Lf_CutSetForEachCut( nCutWords, pCutSet1, pCut1, k, nCuts1 )
1242  Lf_CutSetForEachCut( nCutWords, pCutSet2, pCut2, n, nCuts2 )
1243  {
1244  if ( Lf_CutCountBits(pCut0->Sign | pCut1->Sign | pCut2->Sign) > nLutSize )
1245  continue;
1246  p->CutCount[1]++;
1247  if ( !Lf_CutMergeOrderMux(pCut0, pCut1, pCut2, pCutsR[nCutsR], nLutSize) )
1248  continue;
1249  if ( Lf_SetLastCutIsContained(pCutsR, nCutsR) )
1250  continue;
1251  p->CutCount[2]++;
1252  if ( p->pPars->fCutMin && Lf_CutComputeTruthMux(p, pCut0, pCut1, pCut2, fComp0, fComp1, fComp2, pCutsR[nCutsR]) )
1253  pCutsR[nCutsR]->Sign = Lf_CutGetSign(pCutsR[nCutsR]);
1254  if ( p->pPars->nLutSizeMux && p->pPars->nLutSizeMux == (int)pCutsR[nCutsR]->nLeaves &&
1255  Lf_ManFindCofVar(Lf_CutTruth(p,pCutsR[nCutsR]), Abc_Truth6WordNum(nLutSize), pCutsR[nCutsR]->nLeaves) == -1 )
1256  continue;
1257  Lf_CutParams( p, pCutsR[nCutsR], Required, FlowRefs, pObj );
1258  nCutsR = Lf_SetAddCut( pCutsR, nCutsR, nCutNum );
1259  }
1260  }
1261  else
1262  {
1263  int fIsXor = Gia_ObjIsXor(pObj);
1264  p->CutCount[0] += nCuts0 * nCuts1;
1265  Lf_CutSetForEachCut( nCutWords, pCutSet0, pCut0, i, nCuts0 )
1266  Lf_CutSetForEachCut( nCutWords, pCutSet1, pCut1, k, nCuts1 )
1267  {
1268  if ( (int)(pCut0->nLeaves + pCut1->nLeaves) > nLutSize && Lf_CutCountBits(pCut0->Sign | pCut1->Sign) > nLutSize )
1269  continue;
1270  p->CutCount[1]++;
1271  if ( !Lf_CutMergeOrder(pCut0, pCut1, pCutsR[nCutsR], nLutSize) )
1272  continue;
1273  if ( Lf_SetLastCutIsContained(pCutsR, nCutsR) )
1274  continue;
1275  p->CutCount[2]++;
1276  if ( p->pPars->fCutMin && Lf_CutComputeTruth(p, pCut0, pCut1, fComp0, fComp1, pCutsR[nCutsR], fIsXor) )
1277  pCutsR[nCutsR]->Sign = Lf_CutGetSign(pCutsR[nCutsR]);
1278  if ( p->pPars->nLutSizeMux && p->pPars->nLutSizeMux == (int)pCutsR[nCutsR]->nLeaves &&
1279  Lf_ManFindCofVar(Lf_CutTruth(p,pCutsR[nCutsR]), Abc_Truth6WordNum(nLutSize), pCutsR[nCutsR]->nLeaves) == -1 )
1280  continue;
1281  Lf_CutParams( p, pCutsR[nCutsR], Required, FlowRefs, pObj );
1282  nCutsR = Lf_SetAddCut( pCutsR, nCutsR, nCutNum );
1283  }
1284  }
1285  // debug printout
1286  if ( 0 )
1287  {
1288  printf( "*** Obj = %d FlowRefs = %.2f MapRefs = %2d Required = %2d\n", iObj, FlowRefs, Lf_ObjMapRefNum(p, iObj), Required );
1289  for ( i = 0; i < nCutsR; i++ )
1290  Lf_CutPrint( p, pCutsR[i] );
1291  printf( "\n" );
1292  }
1293  // verify
1294  assert( nCutsR > 0 && nCutsR < nCutNum );
1295 // assert( Lf_SetCheckArray(pCutsR, nCutsR) );
1296  // delay cut
1297  assert( nCutsR == 1 || pCutsR[0]->Delay <= pCutsR[1]->Delay );
1298  pBest->Cut[0].fUsed = pBest->Cut[1].fUsed = 0;
1299  pBest->Cut[0].Handle = pBest->Cut[1].Handle = Lf_MemSaveCut(&p->vStoreNew, pCutsR[0], iObj);
1300  pBest->Delay[0] = pBest->Delay[1] = pCutsR[0]->Delay;
1301  pBest->Flow[0] = pBest->Flow[1] = pCutsR[0]->Flow;
1302  p->nCutCounts[pCutsR[0]->nLeaves]++;
1303  p->CutCount[3] += nCutsR;
1304  p->nCutEqual++;
1305  // area cut
1306  iCutUsed = 0;
1307  if ( nCutsR > 1 && pCutsR[0]->Flow > pCutsR[1]->Flow )//&& !pCutsR[1]->fLate ) // can remove !fLate
1308  {
1309  pBest->Cut[1].Handle = Lf_MemSaveCut(&p->vStoreNew, pCutsR[1], iObj);
1310  pBest->Delay[1] = pCutsR[1]->Delay;
1311  pBest->Flow[1] = pCutsR[1]->Flow;
1312  p->nCutCounts[pCutsR[1]->nLeaves]++;
1313  p->nCutEqual--;
1314  if ( !pCutsR[1]->fLate )
1315  iCutUsed = 1;
1316  }
1317  // mux cut
1318  if ( p->pPars->fUseMux7 && Gia_ObjIsMuxId(p->pGia, iObj) )
1319  {
1320  pCut2 = Lf_ObjCutMux( p, iObj );
1321  Lf_CutParams( p, pCut2, Required, FlowRefs, pObj );
1322  pBest->Delay[2] = pCut2->Delay;
1323  pBest->Flow[2] = pCut2->Flow;
1324  // update area value of the best area cut
1325 // if ( !pCut2->fLate )
1326 // pBest->Flow[1] = Abc_MinFloat( pBest->Flow[1], pBest->Flow[2] );
1327  }
1328  // reference resulting cut
1329  if ( p->fUseEla )
1330  {
1331  pBest->Cut[iCutUsed].fUsed = 1;
1332  if ( Lf_ObjMapRefNum(p, iObj) > 0 )
1333  Value2 = Lf_CutRef_rec( p, pCutsR[iCutUsed] );
1334 // if ( Value1 < Value2 )
1335 // printf( "ELA degradated cost at node %d from %d to %d.\n", iObj, Value1, Value2 ), fflush(stdout);
1336 // assert( Value1 >= Value2 );
1337 // if ( Value1 != -1 )
1338 // printf( "%.2f -> %.2f ", Value1, Value2 );
1339  }
1340  if ( pObj->Value == 0 )
1341  return;
1342  // store the cutset
1343  pCutSet = Lf_ManFetchSet(p, iObj);
1344  Lf_CutSetForEachCut( nCutWords, pCutSet, pCut0, i, nCutNum )
1345  {
1346  assert( !pCut0->fMux7 );
1347  if ( i < nCutsR )
1348  Lf_CutCopy( pCut0, pCutsR[i], nCutWords );
1349  else if ( i == nCutsR && pCutsR[0]->nLeaves > 1 && (nCutsR == 1 || pCutsR[1]->nLeaves > 1) )
1350  Lf_CutCreateUnit( pCut0, iObj );
1351  else
1352  pCut0->nLeaves = LF_NO_LEAF;
1353  }
1354 }
1355 
1356 /**Function*************************************************************
1357 
1358  Synopsis [Computing delay/area.]
1359 
1360  Description []
1361 
1362  SideEffects []
1363 
1364  SeeAlso []
1365 
1366 ***********************************************************************/
1367 static inline void Lf_ManSetFlowRefInc( Gia_Man_t * p, Vec_Flt_t * vRefs, Vec_Int_t * vOffsets, int i )
1368 {
1369  if ( Gia_ObjIsAndNotBuf(Gia_ManObj(p, i)) )
1370  Vec_FltAddToEntry( vRefs, Vec_IntEntry(vOffsets, i), 1 );
1371 }
1372 void Lf_ManSetFlowRefs( Gia_Man_t * p, Vec_Flt_t * vRefs, Vec_Int_t * vOffsets )
1373 {
1374  int fDiscount = 1;
1375  Gia_Obj_t * pObj, * pCtrl, * pData0, * pData1;
1376  int i, Id;
1377  Vec_FltFill( vRefs, Gia_ManAndNotBufNum(p), 0 );
1378  Gia_ManForEachAnd( p, pObj, i )
1379  {
1380  if ( Gia_ObjIsAndNotBuf(Gia_ObjFanin0(pObj)) )
1381  Vec_FltAddToEntry( vRefs, Vec_IntEntry(vOffsets, Gia_ObjFaninId0(pObj, i)), 1 );
1382  if ( Gia_ObjIsBuf(pObj) )
1383  continue;
1384  if ( Gia_ObjIsAndNotBuf(Gia_ObjFanin1(pObj)) )
1385  Vec_FltAddToEntry( vRefs, Vec_IntEntry(vOffsets, Gia_ObjFaninId1(pObj, i)), 1 );
1386  if ( p->pMuxes )
1387  {
1388  if ( Gia_ObjIsMuxId(p, i) && Gia_ObjIsAndNotBuf(Gia_ObjFanin2(p, pObj)) )
1389  Vec_FltAddToEntry( vRefs, Vec_IntEntry(vOffsets, Gia_ObjFaninId2(p, i)), 1 );
1390  }
1391  else if ( fDiscount && Gia_ObjIsMuxType(pObj) ) // discount XOR/MUX
1392  {
1393  pCtrl = Gia_Regular(Gia_ObjRecognizeMux(pObj, &pData1, &pData0));
1394  pData0 = Gia_Regular(pData0);
1395  pData1 = Gia_Regular(pData1);
1396  if ( Gia_ObjIsAndNotBuf(pCtrl) )
1397  Vec_FltAddToEntry( vRefs, Vec_IntEntry(vOffsets, Gia_ObjId(p, pCtrl)), -1 );
1398  if ( pData0 == pData1 && Gia_ObjIsAndNotBuf(pData0) )
1399  Vec_FltAddToEntry( vRefs, Vec_IntEntry(vOffsets, Gia_ObjId(p, pData0)), -1 );
1400  }
1401  }
1402  Gia_ManForEachCoDriverId( p, Id, i )
1403  if ( Gia_ObjIsAndNotBuf(Gia_ManObj(p, Id)) )
1404  Vec_FltAddToEntry( vRefs, Vec_IntEntry(vOffsets, Id), 1 );
1405  for ( i = 0; i < Vec_FltSize(vRefs); i++ )
1406  Vec_FltUpdateEntry( vRefs, i, 1 );
1407 }
1409 {
1410  Gia_Obj_t * pObj; int i;
1411  if ( Vec_PtrSize(&p->vMemSets) * (1 << LF_LOG_PAGE) != Vec_IntSize(&p->vFreeSets) )
1412  printf( "The number of used cutsets = %d.\n", Vec_PtrSize(&p->vMemSets) * (1 << LF_LOG_PAGE) - Vec_IntSize(&p->vFreeSets) );
1413  Gia_ManForEachAnd( p->pGia, pObj, i )
1414  {
1415  assert( pObj->Value == 0 );
1416  if ( Gia_ObjIsBuf(pObj) )
1417  continue;
1418  if ( Gia_ObjIsAndNotBuf(Gia_ObjFanin0(pObj)) )
1419  Gia_ObjFanin0(pObj)->Value++;
1420  if ( Gia_ObjIsAndNotBuf(Gia_ObjFanin1(pObj)) )
1421  Gia_ObjFanin1(pObj)->Value++;
1422  if ( Gia_ObjIsMuxId(p->pGia, i) && Gia_ObjIsAndNotBuf(Gia_ObjFanin2(p->pGia, pObj)) )
1423  Gia_ObjFanin2(p->pGia, pObj)->Value++;
1424  if ( Gia_ObjSibl(p->pGia, i) && Gia_ObjIsAndNotBuf(Gia_ObjSiblObj(p->pGia, i)) )
1425  Gia_ObjSiblObj(p->pGia, i)->Value++;
1426  }
1427 }
1428 
1429 static inline int Lf_ManSetMuxCut( Lf_Man_t * p, Lf_Bst_t * pBest, int iObj, int Required )
1430 {
1431  Gia_Obj_t * pMux;
1432  if ( !Gia_ObjIsMuxId(p->pGia, iObj) )
1433  return 0;
1434  if ( pBest->Delay[2] > Required )
1435  return 0;
1436  if ( pBest->Flow[2] > 1.1 * pBest->Flow[1] )
1437  return 0;
1438  pMux = Gia_ManObj(p->pGia, iObj);
1439  if ( pMux->fMark0 || Gia_ObjFanin0(pMux)->fMark0 || Gia_ObjFanin1(pMux)->fMark0 )
1440  return 0;
1441  Gia_ObjFanin0(pMux)->fMark0 = 1;
1442  Gia_ObjFanin1(pMux)->fMark0 = 1;
1443  return 1;
1444 }
1445 void Lf_ManSetMapRefsOne( Lf_Man_t * p, int iObj )
1446 {
1447  Lf_Cut_t * pCut;
1448  Lf_Bst_t * pBest = Lf_ObjReadBest( p, iObj );
1449  int k, Index, Required = Lf_ObjRequired( p, iObj );
1450  assert( Lf_ObjMapRefNum(p, iObj) > 0 );
1451  assert( !pBest->Cut[0].fUsed && !pBest->Cut[1].fUsed );
1452  if ( !p->pPars->fUseMux7 || !Lf_ManSetMuxCut(p, pBest, iObj, Required) )
1453  {
1454  Index = (int)(Lf_BestDiffCuts(pBest) && pBest->Delay[1] <= Required);
1455  pBest->Cut[Index].fUsed = 1;
1456  }
1457  pCut = Lf_ObjCutBest( p, iObj );
1458  assert( !pCut->fMux7 || pCut->nLeaves == 3 );
1459 // assert( pCut->Delay <= Required );
1460  for ( k = 0; k < (int)pCut->nLeaves; k++ )
1461  {
1462 // if ( pCut->fMux7 && pCut->pLeaves[k] != Gia_ObjFaninId2(p->pGia, iObj) )
1463 // Lf_ObjSetRequired( p, pCut->pLeaves[k], Required );
1464 // else
1465  Lf_ObjSetRequired( p, pCut->pLeaves[k], Required - 1 );
1466  if ( Gia_ObjIsAndNotBuf(Gia_ManObj(p->pGia, pCut->pLeaves[k])) )
1467  Lf_ObjMapRefInc( p, pCut->pLeaves[k] );
1468  }
1469  if ( pCut->fMux7 )
1470  {
1471  p->pPars->Mux7++;
1472  p->pPars->Edge++;
1473  return;
1474  }
1475  if ( Vec_FltSize(&p->vSwitches) )
1476  p->Switches += Lf_CutSwitches(p, pCut);
1477  p->pPars->Edge += pCut->nLeaves;
1478  p->pPars->Area++;
1479 }
1481 {
1482  float Coef = 1.0 / (1.0 + (p->Iter + 1) * (p->Iter + 1));
1483  float * pFlowRefs;
1484  int * pMapRefs, i;
1485  Gia_Obj_t * pObj;
1486  // compute delay
1487  int Delay = 0;
1488  for ( i = 0; i < Gia_ManCoNum(p->pGia); i++ )
1489  Delay = Abc_MaxInt( Delay, Lf_ObjCoArrival(p, i) );
1490  // check delay target
1491  if ( p->pPars->DelayTarget == -1 && p->pPars->nRelaxRatio )
1492  p->pPars->DelayTarget = (int)((float)Delay * (100.0 + p->pPars->nRelaxRatio) / 100.0);
1493  if ( p->pPars->DelayTarget != -1 )
1494  {
1495  if ( Delay < p->pPars->DelayTarget + 0.01 )
1496  Delay = p->pPars->DelayTarget;
1497  else if ( p->pPars->nRelaxRatio == 0 )
1498  Abc_Print( 0, "Relaxing user-specified delay target from %d to %d.\n", p->pPars->DelayTarget, Delay );
1499  }
1500  p->pPars->Delay = Delay;
1501  // compute area/edges/required
1502  p->pPars->Mux7 = p->pPars->Area = p->pPars->Edge = p->Switches = 0;
1505  if ( p->pPars->fUseMux7 )
1506  {
1507  Gia_ManCleanMark0(p->pGia);
1508  Gia_ManForEachCi( p->pGia, pObj, i )
1509  pObj->fMark0 = 1;
1510  }
1511  if ( p->pGia->pManTime != NULL )
1512  {
1513  assert( Gia_ManBufNum(p->pGia) );
1515  if ( p->pPars->fDoAverage )
1516  for ( i = 0; i < Gia_ManCoNum(p->pGia); i++ )
1517  Tim_ManSetCoRequired( p->pGia->pManTime, i, (int)(Lf_ObjCoArrival(p, i) * (100.0 + p->pPars->nRelaxRatio) / 100.0) );
1518  else
1519  Tim_ManInitPoRequiredAll( p->pGia->pManTime, Delay );
1520  Gia_ManForEachObjReverse1( p->pGia, pObj, i )
1521  {
1522  if ( Gia_ObjIsBuf(pObj) )
1523  Lf_ObjSetRequired( p, Gia_ObjFaninId0(pObj, i), Lf_ObjRequired(p, i) );
1524  else if ( Gia_ObjIsAnd(pObj) )
1525  {
1526  if ( Lf_ObjMapRefNum(p, i) )
1527  Lf_ManSetMapRefsOne( p, i );
1528  }
1529  else if ( Gia_ObjIsCi(pObj) )
1531  else if ( Gia_ObjIsCo(pObj) )
1532  {
1533  int iDriverId = Gia_ObjFaninId0(pObj, i);
1534  int reqTime = Tim_ManGetCoRequired( p->pGia->pManTime, Gia_ObjCioId(pObj) );
1535  Lf_ObjSetRequired( p, iDriverId, reqTime );
1536  if ( Gia_ObjIsAndNotBuf(Gia_ObjFanin0(pObj)) )
1537  Lf_ObjMapRefInc( p, iDriverId );
1538  }
1539  else assert( 0 );
1540  }
1541  }
1542  else
1543  {
1544  Gia_ManForEachCo( p->pGia, pObj, i )
1545  {
1546  int iDriverId = Gia_ObjFaninId0p(p->pGia, pObj);
1547  int reqTime = p->pPars->fDoAverage ? (int)(Lf_ObjCoArrival(p, i) * (100.0 + p->pPars->nRelaxRatio) / 100.0) : Delay;
1548  Lf_ObjSetRequired( p, iDriverId, reqTime );
1549  if ( Gia_ObjIsAndNotBuf(Gia_ObjFanin0(pObj)) )
1550  Lf_ObjMapRefInc( p, iDriverId );
1551  }
1552  Gia_ManForEachAndReverse( p->pGia, pObj, i )
1553  {
1554  if ( Gia_ObjIsBuf(pObj) )
1555  {
1556  Lf_ObjSetRequired( p, Gia_ObjFaninId0(pObj, i), Lf_ObjRequired(p, i) );
1557  if ( Gia_ObjIsAndNotBuf(Gia_ObjFanin0(pObj)) )
1558  Lf_ObjMapRefInc( p, Gia_ObjFaninId0(pObj, i) );
1559  }
1560  else if ( Lf_ObjMapRefNum(p, i) )
1561  Lf_ManSetMapRefsOne( p, i );
1562  }
1563  }
1564  if ( p->pPars->fUseMux7 )
1565  Gia_ManCleanMark0(p->pGia);
1566  // blend references
1569  pMapRefs = Vec_IntArray(&p->vMapRefs);
1570  pFlowRefs = Vec_FltArray(&p->vFlowRefs);
1571  for ( i = 0; i < Vec_IntSize(&p->vMapRefs); i++ )
1572  pFlowRefs[i] = Coef * pFlowRefs[i] + (1.0 - Coef) * Abc_MaxFloat(1, pMapRefs[i]);
1573 // pFlowRefs[i] = 0.2 * pFlowRefs[i] + 0.8 * Abc_MaxFloat(1, pMapRefs[i]);
1574  return p->pPars->Area;
1575 }
1576 
1577 void Lf_ManCountMapRefsOne( Lf_Man_t * p, int iObj )
1578 {
1579  Lf_Bst_t * pBest = Lf_ObjReadBest( p, iObj );
1580  Lf_Cut_t * pCut = Lf_ObjCutBest( p, iObj );
1581  int k ,Required = Lf_ObjRequired( p, iObj );
1582  assert( Lf_ObjMapRefNum(p, iObj) > 0 );
1583  assert( Lf_BestIsMapped(pBest) );
1584  assert( !pCut->fMux7 );
1585 // assert( pCut->Delay <= Required );
1586  for ( k = 0; k < (int)pCut->nLeaves; k++ )
1587  Lf_ObjSetRequired( p, pCut->pLeaves[k], Required - 1 );
1588  if ( Vec_FltSize(&p->vSwitches) )
1589  p->Switches += Lf_CutSwitches(p, pCut);
1590  p->pPars->Edge += pCut->nLeaves;
1591  p->pPars->Area++;
1592 }
1594 {
1595  // compute delay
1596  Gia_Obj_t * pObj;
1597  int i, Id, Delay = 0;
1598  for ( i = 0; i < Gia_ManCoNum(p->pGia); i++ )
1599  Delay = Abc_MaxInt( Delay, Lf_ObjCoArrival2(p, i) );
1600  // check delay target
1601  if ( p->pPars->DelayTarget == -1 && p->pPars->nRelaxRatio )
1602  p->pPars->DelayTarget = (int)((float)Delay * (100.0 + p->pPars->nRelaxRatio) / 100.0);
1603  if ( p->pPars->DelayTarget != -1 )
1604  {
1605  if ( Delay < p->pPars->DelayTarget + 0.01 )
1606  Delay = p->pPars->DelayTarget;
1607  else if ( p->pPars->nRelaxRatio == 0 )
1608  Abc_Print( 0, "Relaxing user-specified delay target from %d to %d.\n", p->pPars->DelayTarget, Delay );
1609  }
1610  p->pPars->Delay = Delay;
1611  // compute area/edges/required
1612  p->pPars->Mux7 = p->pPars->Area = p->pPars->Edge = p->Switches = 0;
1614  if ( p->pPars->fUseMux7 )
1615  Gia_ManCleanMark0(p->pGia);
1616  if ( p->pGia->pManTime != NULL )
1617  {
1619  if ( p->pPars->fDoAverage )
1620  for ( i = 0; i < Gia_ManCoNum(p->pGia); i++ )
1621  Tim_ManSetCoRequired( p->pGia->pManTime, i, (int)(Lf_ObjCoArrival(p, i) * (100.0 + p->pPars->nRelaxRatio) / 100.0) );
1622  else
1623  Tim_ManInitPoRequiredAll( p->pGia->pManTime, Delay );
1624  Gia_ManForEachObjReverse1( p->pGia, pObj, i )
1625  {
1626  if ( Gia_ObjIsBuf(pObj) )
1627  Lf_ObjSetRequired( p, Gia_ObjFaninId0(pObj, i), Lf_ObjRequired(p, i) );
1628  else if ( Gia_ObjIsAnd(pObj) )
1629  {
1630  if ( Lf_ObjMapRefNum(p, i) )
1631  Lf_ManCountMapRefsOne( p, i );
1632  }
1633  else if ( Gia_ObjIsCi(pObj) )
1635  else if ( Gia_ObjIsCo(pObj) )
1636  {
1637  int reqTime = Tim_ManGetCoRequired( p->pGia->pManTime, Gia_ObjCioId(pObj) );
1638  Lf_ObjSetRequired( p, Gia_ObjFaninId0(pObj, i), reqTime );
1639  }
1640  else assert( 0 );
1641  }
1642  }
1643  else
1644  {
1645  Gia_ManForEachCoDriverId( p->pGia, Id, i )
1646  Lf_ObjSetRequired( p, Id, p->pPars->fDoAverage ? (int)(Lf_ObjCoArrival(p, i) * (100.0 + p->pPars->nRelaxRatio) / 100.0) : Delay );
1647  Gia_ManForEachAndReverse( p->pGia, pObj, i )
1648  if ( Gia_ObjIsBuf(pObj) )
1649  Lf_ObjSetRequired( p, Gia_ObjFaninId0(pObj, i), Lf_ObjRequired(p, i) );
1650  else if ( Lf_ObjMapRefNum(p, i) )
1651  Lf_ManCountMapRefsOne( p, i );
1652  }
1653  if ( p->pPars->fUseMux7 )
1654  Gia_ManCleanMark0(p->pGia);
1655 }
1656 
1657 
1658 /**Function*************************************************************
1659 
1660  Synopsis []
1661 
1662  Description []
1663 
1664  SideEffects []
1665 
1666  SeeAlso []
1667 
1668 ***********************************************************************/
1670 {
1671  Vec_Int_t * vMapping;
1672  Lf_Cut_t * pCut;
1673  int i, k;
1674  assert( !p->pPars->fCutMin && p->pGia->vMapping == NULL );
1675  vMapping = Vec_IntAlloc( Gia_ManObjNum(p->pGia) + (int)p->pPars->Edge + (int)p->pPars->Area * 2 );
1676  Vec_IntFill( vMapping, Gia_ManObjNum(p->pGia), 0 );
1677  Gia_ManForEachAndId( p->pGia, i )
1678  {
1679  if ( !Lf_ObjMapRefNum(p, i) )
1680  continue;
1681  assert( !Gia_ObjIsBuf(Gia_ManObj(p->pGia,i)) );
1682  pCut = Lf_ObjCutBest( p, i );
1683  assert( !pCut->fMux7 );
1684  Vec_IntWriteEntry( vMapping, i, Vec_IntSize(vMapping) );
1685  Vec_IntPush( vMapping, pCut->nLeaves );
1686  for ( k = 0; k < (int)pCut->nLeaves; k++ )
1687  Vec_IntPush( vMapping, pCut->pLeaves[k] );
1688  Vec_IntPush( vMapping, i );
1689  }
1690  assert( Vec_IntCap(vMapping) == 16 || Vec_IntSize(vMapping) == Vec_IntCap(vMapping) );
1691  p->pGia->vMapping = vMapping;
1692  return p->pGia;
1693 }
1695 {
1696  Gia_Man_t * pNew, * pGia = p->pGia;
1697  Gia_Obj_t * pObj;
1698  Lf_Cut_t * pCut;
1699  int i, k;
1700  assert( !p->pPars->fCutMin && pGia->pMuxes );
1701  // create new manager
1702  pNew = Gia_ManStart( Gia_ManObjNum(pGia) );
1703  pNew->pName = Abc_UtilStrsav( pGia->pName );
1704  pNew->pSpec = Abc_UtilStrsav( pGia->pSpec );
1705  // start mapping
1706  pNew->vMapping = Vec_IntAlloc( Gia_ManObjNum(pGia) + 2*Gia_ManXorNum(pGia) + 2*Gia_ManMuxNum(pGia) + (int)p->pPars->Edge + 2*(int)p->pPars->Area + 4*(int)p->pPars->Mux7 );
1707  Vec_IntFill( pNew->vMapping, Gia_ManObjNum(pGia) + 2*Gia_ManXorNum(pGia) + 2*Gia_ManMuxNum(pGia), 0 );
1708  // process objects
1709  Gia_ManConst0(pGia)->Value = 0;
1710  Gia_ManForEachObj1( pGia, pObj, i )
1711  {
1712  if ( Gia_ObjIsCi(pObj) )
1713  { pObj->Value = Gia_ManAppendCi( pNew ); continue; }
1714  if ( Gia_ObjIsCo(pObj) )
1715  { pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); continue; }
1716  if ( Gia_ObjIsBuf(pObj) )
1717  { pObj->Value = Gia_ManAppendBuf( pNew, Gia_ObjFanin0Copy(pObj) ); continue; }
1718  if ( Gia_ObjIsMuxId(pGia, i) )
1719  pObj->Value = Gia_ManAppendMux( pNew, Gia_ObjFanin2Copy(pGia, pObj), Gia_ObjFanin1Copy(pObj), Gia_ObjFanin0Copy(pObj) );
1720  else if ( Gia_ObjIsXor(pObj) )
1721  pObj->Value = Gia_ManAppendXor( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
1722  else
1723  pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
1724  if ( !Lf_ObjMapRefNum(p, i) )
1725  continue;
1726  pCut = Lf_ObjCutBest( p, i );
1728  Vec_IntPush( pNew->vMapping, pCut->nLeaves );
1729  for ( k = 0; k < (int)pCut->nLeaves; k++ )
1730  Vec_IntPush( pNew->vMapping, Abc_Lit2Var(Gia_ManObj(pGia, pCut->pLeaves[k])->Value) );
1731  Vec_IntPush( pNew->vMapping, pCut->fMux7 ? -Abc_Lit2Var(pObj->Value) : Abc_Lit2Var(pObj->Value) );
1732  }
1733  Gia_ManSetRegNum( pNew, Gia_ManRegNum(pGia) );
1734  assert( Vec_IntCap(pNew->vMapping) == 16 || Vec_IntSize(pNew->vMapping) == Vec_IntCap(pNew->vMapping) );
1735  return pNew;
1736 }
1737 static inline int Lf_ManDerivePart( Lf_Man_t * p, Gia_Man_t * pNew, Vec_Int_t * vMapping, Vec_Int_t * vMapping2, Vec_Int_t * vCopies, Lf_Cut_t * pCut, Vec_Int_t * vLeaves, Vec_Int_t * vCover, Gia_Obj_t * pObj )
1738 {
1739  word * pTruth;
1740  int k, iLit, iTemp;
1741  if ( p->pPars->nLutSizeMux && p->pPars->nLutSizeMux == (int)pCut->nLeaves )
1742  {
1743  word pTruthCof[LF_TT_WORDS], * pTruth = Lf_CutTruth( p, pCut );
1744  int pVarsNew[LF_LEAF_MAX], nVarsNew, iLitCofs[2];
1745  int LutSize = p->pPars->nLutSize;
1746  int nWords = Abc_Truth6WordNum(LutSize);
1747  int c, iVar = Lf_ManFindCofVar( pTruth, nWords, pCut->nLeaves );
1748  assert( iVar >= 0 && iVar < (int)pCut->nLeaves );
1749  for ( c = 0; c < 2; c++ )
1750  {
1751  for ( k = 0; k < (int)pCut->nLeaves; k++ )
1752  pVarsNew[k] = k;
1753  if ( c )
1754  Abc_TtCofactor1p( pTruthCof, pTruth, nWords, iVar );
1755  else
1756  Abc_TtCofactor0p( pTruthCof, pTruth, nWords, iVar );
1757  nVarsNew = Abc_TtMinBase( pTruthCof, pVarsNew, pCut->nLeaves, LutSize );
1758  assert( nVarsNew > 0 );
1759  // derive LUT
1760  Vec_IntClear( vLeaves );
1761  for ( k = 0; k < nVarsNew; k++ )
1762  Vec_IntPush( vLeaves, Vec_IntEntry(vCopies, pCut->pLeaves[pVarsNew[k]]) );
1763  iLitCofs[c] = Kit_TruthToGia( pNew, (unsigned *)pTruthCof, nVarsNew, vCover, vLeaves, 0 );
1764  // create mapping
1765  Vec_IntSetEntry( vMapping, Abc_Lit2Var(iLitCofs[c]), Vec_IntSize(vMapping2) );
1766  Vec_IntPush( vMapping2, Vec_IntSize(vLeaves) );
1767  Vec_IntForEachEntry( vLeaves, iTemp, k )
1768  Vec_IntPush( vMapping2, Abc_Lit2Var(iTemp) );
1769  Vec_IntPush( vMapping2, Abc_Lit2Var(iLitCofs[c]) );
1770  }
1771  // derive MUX
1772  pTruthCof[0] = ABC_CONST(0xCACACACACACACACA);
1773  Vec_IntClear( vLeaves );
1774  Vec_IntPush( vLeaves, iLitCofs[0] );
1775  Vec_IntPush( vLeaves, iLitCofs[1] );
1776  Vec_IntPush( vLeaves, Vec_IntEntry(vCopies, pCut->pLeaves[iVar]) );
1777  iLit = Kit_TruthToGia( pNew, (unsigned *)pTruthCof, Vec_IntSize(vLeaves), vCover, vLeaves, 0 );
1778  // create mapping
1779  Vec_IntSetEntry( vMapping, Abc_Lit2Var(iLit), Vec_IntSize(vMapping2) );
1780  Vec_IntPush( vMapping2, Vec_IntSize(vLeaves) );
1781  Vec_IntForEachEntry( vLeaves, iTemp, k )
1782  Vec_IntPush( vMapping2, Abc_Lit2Var(iTemp) );
1783  Vec_IntPush( vMapping2, -Abc_Lit2Var(iLit) );
1784  return iLit;
1785  }
1786  Vec_IntClear( vLeaves );
1787  if ( pCut->fMux7 )
1788  {
1789  assert( pCut->nLeaves == 3 );
1790  Vec_IntPush( vLeaves, Abc_LitNotCond(Vec_IntEntry(vCopies, pCut->pLeaves[0]), Gia_ObjFaninC0(pObj)) );
1791  Vec_IntPush( vLeaves, Abc_LitNotCond(Vec_IntEntry(vCopies, pCut->pLeaves[1]), Gia_ObjFaninC1(pObj)) );
1792  Vec_IntPush( vLeaves, Abc_LitNotCond(Vec_IntEntry(vCopies, pCut->pLeaves[2]), Gia_ObjFaninC2(p->pGia,pObj)) );
1793  }
1794  else
1795  {
1796  for ( k = 0; k < (int)pCut->nLeaves; k++ )
1797  Vec_IntPush( vLeaves, Vec_IntEntry(vCopies, pCut->pLeaves[k]) );
1798  }
1799  pTruth = Lf_CutTruth( p, pCut );
1800  iLit = Kit_TruthToGia( pNew, (unsigned *)pTruth, Vec_IntSize(vLeaves), vCover, vLeaves, 0 );
1801  // create mapping
1802  Vec_IntSetEntry( vMapping, Abc_Lit2Var(iLit), Vec_IntSize(vMapping2) );
1803  Vec_IntPush( vMapping2, Vec_IntSize(vLeaves) );
1804  Vec_IntForEachEntry( vLeaves, iTemp, k )
1805  Vec_IntPush( vMapping2, Abc_Lit2Var(iTemp) );
1806  Vec_IntPush( vMapping2, pCut->fMux7 ? -Abc_Lit2Var(iLit) : Abc_Lit2Var(iLit) );
1807  return iLit;
1808 }
1810 {
1811  Gia_Man_t * pNew;
1812  Gia_Obj_t * pObj;
1813  Vec_Int_t * vCopies = Vec_IntStartFull( Gia_ManObjNum(p->pGia) );
1814  Vec_Int_t * vMapping = Vec_IntStart( 2*Gia_ManObjNum(p->pGia) + (int)p->pPars->Edge + 2*(int)p->pPars->Area + 4*(int)p->pPars->Mux7 );
1815  Vec_Int_t * vMapping2 = Vec_IntStart( (int)p->pPars->Edge + 2*(int)p->pPars->Area + 1000 );
1816  Vec_Int_t * vCover = Vec_IntAlloc( 1 << 16 );
1817  Vec_Int_t * vLeaves = Vec_IntAlloc( 16 );
1818  Lf_Cut_t * pCut;
1819  int i, iLit;
1820  assert( p->pPars->fCutMin );
1821  // create new manager
1822  pNew = Gia_ManStart( Gia_ManObjNum(p->pGia) );
1823  pNew->pName = Abc_UtilStrsav( p->pGia->pName );
1824  pNew->pSpec = Abc_UtilStrsav( p->pGia->pSpec );
1825  Vec_IntWriteEntry( vCopies, 0, 0 );
1826  Gia_ManForEachObj1( p->pGia, pObj, i )
1827  {
1828  if ( Gia_ObjIsCi(pObj) )
1829  {
1830  Vec_IntWriteEntry( vCopies, i, Gia_ManAppendCi(pNew) );
1831  continue;
1832  }
1833  if ( Gia_ObjIsCo(pObj) )
1834  {
1835  iLit = Vec_IntEntry( vCopies, Gia_ObjFaninId0p(p->pGia, pObj) );
1836  iLit = Gia_ManAppendCo( pNew, Abc_LitNotCond(iLit, Gia_ObjFaninC0(pObj)) );
1837  continue;
1838  }
1839  if ( Gia_ObjIsBuf(pObj) )
1840  {
1841  iLit = Vec_IntEntry( vCopies, Gia_ObjFaninId0p(p->pGia, pObj) );
1842  iLit = Gia_ManAppendBuf( pNew, Abc_LitNotCond(iLit, Gia_ObjFaninC0(pObj)) );
1843  Vec_IntWriteEntry( vCopies, i, iLit );
1844  continue;
1845  }
1846  if ( !Lf_ObjMapRefNum(p, i) )
1847  continue;
1848  pCut = Lf_ObjCutBest( p, i );
1849  assert( pCut->iFunc >= 0 );
1850  if ( pCut->nLeaves == 0 )
1851  {
1852  assert( Abc_Lit2Var(pCut->iFunc) == 0 );
1853  Vec_IntWriteEntry( vCopies, i, pCut->iFunc );
1854  continue;
1855  }
1856  if ( pCut->nLeaves == 1 )
1857  {
1858  assert( Abc_Lit2Var(pCut->iFunc) == 1 );
1859  iLit = Vec_IntEntry( vCopies, pCut->pLeaves[0] );
1860  Vec_IntWriteEntry( vCopies, i, Abc_LitNotCond(iLit, Abc_LitIsCompl(pCut->iFunc)) );
1861  continue;
1862  }
1863  iLit = Lf_ManDerivePart( p, pNew, vMapping, vMapping2, vCopies, pCut, vLeaves, vCover, pObj );
1864  Vec_IntWriteEntry( vCopies, i, Abc_LitNotCond(iLit, Abc_LitIsCompl(pCut->iFunc)) );
1865  }
1866  Vec_IntFree( vCopies );
1867  Vec_IntFree( vCover );
1868  Vec_IntFree( vLeaves );
1869  // finish mapping
1870  if ( Vec_IntSize(vMapping) > Gia_ManObjNum(pNew) )
1871  Vec_IntShrink( vMapping, Gia_ManObjNum(pNew) );
1872  else
1873  Vec_IntFillExtra( vMapping, Gia_ManObjNum(pNew), 0 );
1874  assert( Vec_IntSize(vMapping) == Gia_ManObjNum(pNew) );
1875  Vec_IntForEachEntry( vMapping, iLit, i )
1876  if ( iLit > 0 )
1877  Vec_IntAddToEntry( vMapping, i, Gia_ManObjNum(pNew) );
1878  Vec_IntAppend( vMapping, vMapping2 );
1879  Vec_IntFree( vMapping2 );
1880  // attach mapping and packing
1881  assert( pNew->vMapping == NULL );
1882  pNew->vMapping = vMapping;
1883  Gia_ManSetRegNum( pNew, Gia_ManRegNum(p->pGia) );
1884  return pNew;
1885 }
1886 
1887 /**Function*************************************************************
1888 
1889  Synopsis []
1890 
1891  Description []
1892 
1893  SideEffects []
1894 
1895  SeeAlso []
1896 
1897 ***********************************************************************/
1899 {
1900  Lf_Man_t * p; int i, k = 0;
1901  assert( pPars->nCutNum > 1 && pPars->nCutNum <= LF_CUT_MAX );
1902  assert( pPars->nLutSize > 1 && pPars->nLutSize <= LF_LEAF_MAX );
1903  ABC_FREE( pGia->pRefs );
1904  Vec_IntFreeP( &pGia->vMapping );
1905  Gia_ManCleanValue( pGia );
1906  if ( Gia_ManHasChoices(pGia) )
1907  Gia_ManSetPhase(pGia);
1908  p = ABC_CALLOC( Lf_Man_t, 1 );
1909  Lf_ManAnalyzeCoDrivers( pGia, &p->nCoDrivers, &p->nInverters );
1910  if ( pPars->fPower )
1911  Lf_ManComputeSwitching( pGia, &p->vSwitches );
1912  p->clkStart = Abc_Clock();
1913  p->pGia = pGia;
1914  p->pPars = pPars;
1915  p->nCutWords = (sizeof(Lf_Cut_t)/sizeof(int) + pPars->nLutSize + 1) >> 1;
1916  p->nSetWords = p->nCutWords * pPars->nCutNum;
1917  p->vTtMem = pPars->fCutMin ? Vec_MemAllocForTT( pPars->nLutSize, 0 ) : NULL;
1918  if ( pPars->fCutMin && pPars->fUseMux7 )
1919  Vec_MemAddMuxTT( p->vTtMem, pPars->nLutSize );
1921  Vec_IntGrow( &p->vFreeSets, (1<<14) );
1922  Vec_PtrGrow( &p->vFreePages, 256 );
1923  Lf_MemAlloc( &p->vStoreOld, 16, &p->vFreePages, p->nCutWords );
1924  Lf_MemAlloc( &p->vStoreNew, 16, &p->vFreePages, p->nCutWords );
1925  Vec_IntFill( &p->vOffsets, Gia_ManObjNum(pGia), -1 );
1927  Vec_IntFill( &p->vCutSets, Gia_ManAndNotBufNum(pGia), -1 );
1928  Vec_FltFill( &p->vFlowRefs, Gia_ManAndNotBufNum(pGia), 0 );
1929  Vec_IntFill( &p->vMapRefs, Gia_ManAndNotBufNum(pGia), 0 );
1930  Vec_IntFill( &p->vCiArrivals, Gia_ManCiNum(pGia), 0 );
1931  Gia_ManForEachAndId( pGia, i )
1932  if ( !Gia_ObjIsBuf(Gia_ManObj(pGia, i)) )
1933  Vec_IntWriteEntry( &p->vOffsets, i, k++ );
1934  assert( k == Gia_ManAndNotBufNum(pGia) );
1935  Lf_ManSetFlowRefs( pGia, &p->vFlowRefs, &p->vOffsets );
1936  if ( pPars->pTimesArr )
1937  for ( i = 0; i < Gia_ManPiNum(pGia); i++ )
1938  Vec_IntWriteEntry( &p->vCiArrivals, i, pPars->pTimesArr[i] );
1939  return p;
1940 }
1942 {
1943  ABC_FREE( p->pPars->pTimesArr );
1944  ABC_FREE( p->pPars->pTimesReq );
1945  if ( p->pPars->fCutMin )
1946  Vec_MemHashFree( p->vTtMem );
1947  if ( p->pPars->fCutMin )
1948  Vec_MemFree( p->vTtMem );
1949  Vec_PtrFreeData( &p->vMemSets );
1950  Vec_PtrFreeData( &p->vFreePages );
1953  ABC_FREE( p->vMemSets.pArray );
1954  ABC_FREE( p->vFreePages.pArray );
1955  ABC_FREE( p->vStoreOld.vPages.pArray );
1956  ABC_FREE( p->vStoreNew.vPages.pArray );
1957  ABC_FREE( p->vFreePages.pArray );
1958  ABC_FREE( p->vFreeSets.pArray );
1959  ABC_FREE( p->vOffsets.pArray );
1960  ABC_FREE( p->vRequired.pArray );
1961  ABC_FREE( p->vCutSets.pArray );
1962  ABC_FREE( p->vFlowRefs.pArray );
1963  ABC_FREE( p->vMapRefs.pArray );
1964  ABC_FREE( p->vSwitches.pArray );
1965  ABC_FREE( p->vCiArrivals.pArray );
1966  ABC_FREE( p->pObjBests );
1967  ABC_FREE( p );
1968 }
1969 
1970 /**Function*************************************************************
1971 
1972  Synopsis []
1973 
1974  Description []
1975 
1976  SideEffects []
1977 
1978  SeeAlso []
1979 
1980 ***********************************************************************/
1982 {
1983  memset( pPars, 0, sizeof(Jf_Par_t) );
1984  pPars->nLutSize = 6;
1985  pPars->nCutNum = 8;
1986  pPars->nProcNum = 0;
1987  pPars->nRounds = 4;
1988  pPars->nRoundsEla = 1;
1989  pPars->nRelaxRatio = 0;
1990  pPars->nCoarseLimit = 3;
1991  pPars->nAreaTuner = 1;
1992  pPars->nVerbLimit = 5;
1993  pPars->DelayTarget = -1;
1994  pPars->fAreaOnly = 0;
1995  pPars->fOptEdge = 1;
1996  pPars->fUseMux7 = 0;
1997  pPars->fPower = 0;
1998  pPars->fCoarsen = 1;
1999  pPars->fCutMin = 0;
2000  pPars->fFuncDsd = 0;
2001  pPars->fGenCnf = 0;
2002  pPars->fPureAig = 0;
2003  pPars->fCutHashing = 0;
2004  pPars->fCutSimple = 0;
2005  pPars->fVerbose = 0;
2006  pPars->fVeryVerbose = 0;
2007  pPars->nLutSizeMax = LF_LEAF_MAX;
2008  pPars->nCutNumMax = LF_CUT_MAX;
2009 }
2010 void Lf_ManPrintStats( Lf_Man_t * p, char * pTitle )
2011 {
2012  if ( !p->pPars->fVerbose )
2013  return;
2014  printf( "%s : ", pTitle );
2015  printf( "Level =%6lu ", p->pPars->Delay );
2016  printf( "Area =%9lu ", p->pPars->Area );
2017  printf( "Edge =%9lu ", p->pPars->Edge );
2018  printf( "LUT =%9lu ", p->pPars->Area+p->nInverters );
2019  if ( Vec_FltSize(&p->vSwitches) )
2020  printf( "Swt =%8.1f ", p->Switches );
2021  if ( p->pPars->fUseMux7 )
2022  printf( "Mux7 =%7lu ", p->pPars->Mux7 );
2023  Abc_PrintTime( 1, "Time", Abc_Clock() - p->clkStart );
2024  fflush( stdout );
2025 }
2027 {
2028  if ( !p->pPars->fVerbose )
2029  return;
2030  printf( "LutSize = %d ", p->pPars->nLutSize );
2031  printf( "CutNum = %d ", p->pPars->nCutNum );
2032  printf( "Iter = %d ", p->pPars->nRounds + p->pPars->nRoundsEla );
2033  if ( p->pPars->nRelaxRatio )
2034  printf( "Ratio = %d ", p->pPars->nRelaxRatio );
2035  printf( "Edge = %d ", p->pPars->fOptEdge );
2036  if ( p->pPars->DelayTarget != -1 )
2037  printf( "Delay = %d ", p->pPars->DelayTarget );
2038  printf( "CutMin = %d ", p->pPars->fCutMin );
2039  printf( "Coarse = %d ", p->pPars->fCoarsen );
2040  printf( "Cut/Set = %d/%d Bytes", 8*p->nCutWords, 8*p->nSetWords );
2041  printf( "\n" );
2042  printf( "Computing cuts...\r" );
2043  fflush( stdout );
2044 }
2046 {
2047  float MemGia = Gia_ManMemory(p->pGia) / (1<<20);
2048  float MemMan = 1.0 * sizeof(int) * (2 * Gia_ManObjNum(p->pGia) + 3 * Gia_ManAndNotBufNum(p->pGia)) / (1<<20); // offset, required, cutsets, maprefs, flowrefs
2049  float MemCutsB = 1.0 * (p->vStoreOld.MaskPage + 1) * (Vec_PtrSize(&p->vFreePages) + Vec_PtrSize(&p->vStoreOld.vPages)) / (1<<20) + 1.0 * sizeof(Lf_Bst_t) * Gia_ManAndNotBufNum(p->pGia) / (1<<20);
2050  float MemCutsF = 1.0 * sizeof(word) * p->nSetWords * (1<<LF_LOG_PAGE) * Vec_PtrSize(&p->vMemSets) / (1<<20);
2051  float MemTt = p->vTtMem ? Vec_MemMemory(p->vTtMem) / (1<<20) : 0;
2052  float MemMap = Vec_IntMemory(pNew->vMapping) / (1<<20);
2053  if ( p->CutCount[0] == 0 )
2054  p->CutCount[0] = 1;
2055  if ( !p->pPars->fVerbose )
2056  return;
2057  printf( "CutPair = %.0f ", p->CutCount[0] );
2058  printf( "Merge = %.0f (%.2f %%) ", p->CutCount[1], 100.0*p->CutCount[1]/p->CutCount[0] );
2059  printf( "Eval = %.0f (%.2f %%) ", p->CutCount[2], 100.0*p->CutCount[2]/p->CutCount[0] );
2060  printf( "Cut = %.0f (%.2f %%) ", p->CutCount[3], 100.0*p->CutCount[3]/p->CutCount[0] );
2061  printf( "\n" );
2062  printf( "Gia = %.2f MB ", MemGia );
2063  printf( "Man = %.2f MB ", MemMan );
2064  printf( "Best = %.2f MB ", MemCutsB );
2065  printf( "Front = %.2f MB ", MemCutsF );
2066  printf( "Map = %.2f MB ", MemMap );
2067  printf( "TT = %.2f MB ", MemTt );
2068  printf( "Total = %.2f MB", MemGia + MemMan + MemCutsB + MemCutsF + MemMap + MemTt );
2069  printf( "\n" );
2070  if ( 1 )
2071  {
2072  int i;
2073  for ( i = 0; i <= p->pPars->nLutSize; i++ )
2074  printf( "%d:%d ", i, p->nCutCounts[i] );
2075  printf( "Equal = %d (%.0f %%) ", p->nCutEqual, 100.0 * p->nCutEqual / p->Iter / Gia_ManAndNotBufNum(p->pGia) );
2076  if ( p->vTtMem )
2077  printf( "TT = %d (%.2f %%) ", Vec_MemEntryNum(p->vTtMem), 100.0 * Vec_MemEntryNum(p->vTtMem) / p->CutCount[2] );
2078  if ( p->pGia->pMuxes && p->nCutMux )
2079  printf( "MuxTT = %d (%.0f %%) ", p->nCutMux, 100.0 * p->nCutMux / p->Iter / Gia_ManMuxNum(p->pGia) );
2080  printf( "\n" );
2081  }
2082  printf( "CoDrvs = %d (%.2f %%) ", p->nCoDrivers, 100.0*p->nCoDrivers/Gia_ManCoNum(p->pGia) );
2083  printf( "CoInvs = %d (%.2f %%) ", p->nInverters, 100.0*p->nInverters/Gia_ManCoNum(p->pGia) );
2084  printf( "Front = %d (%.2f %%) ", p->nFrontMax, 100.0*p->nFrontMax/Gia_ManAndNum(p->pGia) );
2085  printf( "TimeFails = %d ", p->nTimeFails );
2086  Abc_PrintTime( 1, "Time", Abc_Clock() - p->clkStart );
2087  fflush( stdout );
2088 }
2090 {
2091  Gia_Obj_t * pObj;
2092  int i, arrTime;
2093  assert( p->vStoreNew.iCur == 0 );
2094  Lf_ManSetCutRefs( p );
2095  if ( p->pGia->pManTime != NULL )
2096  {
2097  assert( !Gia_ManBufNum(p->pGia) );
2099  Gia_ManForEachObj1( p->pGia, pObj, i )
2100  {
2101  if ( Gia_ObjIsBuf(pObj) )
2102  continue;
2103  if ( Gia_ObjIsAnd(pObj) )
2104  Lf_ObjMergeOrder( p, i );
2105  else if ( Gia_ObjIsCi(pObj) )
2106  {
2107  arrTime = Tim_ManGetCiArrival( p->pGia->pManTime, Gia_ObjCioId(pObj) );
2108  Lf_ObjSetCiArrival( p, Gia_ObjCioId(pObj), arrTime );
2109  }
2110  else if ( Gia_ObjIsCo(pObj) )
2111  {
2112  arrTime = Lf_ObjCoArrival( p, Gia_ObjCioId(pObj) );
2113  Tim_ManSetCoArrival( p->pGia->pManTime, Gia_ObjCioId(pObj), arrTime );
2114  }
2115  else assert( 0 );
2116  }
2117 // Tim_ManPrint( p->pGia->pManTime );
2118  }
2119  else
2120  {
2121  Gia_ManForEachAnd( p->pGia, pObj, i )
2122  if ( !Gia_ObjIsBuf(pObj) )
2123  Lf_ObjMergeOrder( p, i );
2124  }
2125  Lf_MemRecycle( &p->vStoreOld );
2126  ABC_SWAP( Lf_Mem_t, p->vStoreOld, p->vStoreNew );
2127  if ( p->fUseEla )
2128  Lf_ManCountMapRefs( p );
2129  else
2130  Lf_ManSetMapRefs( p );
2131  Lf_ManPrintStats( p, p->fUseEla ? "Ela " : (p->Iter ? "Area " : "Delay") );
2132 }
2134 {
2135  int fUsePowerMode = 0;
2136  Lf_Man_t * p;
2137  Gia_Man_t * pNew, * pCls;
2138  if ( pPars->fUseMux7 )
2139  pPars->fCoarsen = 1, pPars->nRoundsEla = 0;
2140  if ( Gia_ManHasChoices(pGia) || pPars->nLutSizeMux )
2141  pPars->fCutMin = 1;
2142  if ( pPars->fCoarsen )
2143  {
2144  pCls = Gia_ManDupMuxes(pGia, pPars->nCoarseLimit);
2145  pCls->pManTime = pGia->pManTime; pGia->pManTime = NULL;
2146  }
2147  else pCls = pGia;
2148  p = Lf_ManAlloc( pCls, pPars );
2149  if ( pPars->fVerbose && pPars->fCoarsen )
2150  {
2151  printf( "Initial " ); Gia_ManPrintMuxStats( pGia ); printf( "\n" );
2152  printf( "Derived " ); Gia_ManPrintMuxStats( pCls ); printf( "\n" );
2153  }
2154  Lf_ManPrintInit( p );
2155 
2156  // power mode
2157  if ( fUsePowerMode && Vec_FltSize(&p->vSwitches) )
2158  pPars->fPower = 0;
2159 
2160  // perform mapping
2161  for ( p->Iter = 0; p->Iter < p->pPars->nRounds; p->Iter++ )
2162  Lf_ManComputeMapping( p );
2163  p->fUseEla = 1;
2164  for ( ; p->Iter < p->pPars->nRounds + pPars->nRoundsEla; p->Iter++ )
2165  Lf_ManComputeMapping( p );
2166 
2167  // power mode
2168  if ( fUsePowerMode && Vec_FltSize(&p->vSwitches) )
2169  {
2170  pPars->fPower = 1;
2171  for ( ; p->Iter < p->pPars->nRounds + pPars->nRoundsEla + 2; p->Iter++ )
2172  Lf_ManComputeMapping( p );
2173  }
2174 
2175  if ( pPars->fVeryVerbose && pPars->fCutMin )
2177  if ( pPars->fCutMin )
2178  pNew = Lf_ManDeriveMappingGia( p );
2179  else if ( pPars->fCoarsen )
2180  pNew = Lf_ManDeriveMappingCoarse( p );
2181  else
2182  pNew = Lf_ManDeriveMapping( p );
2183  Gia_ManMappingVerify( pNew );
2184  Lf_ManPrintQuit( p, pNew );
2185  Lf_ManFree( p );
2186  if ( pCls != pGia )
2187  {
2188  pGia->pManTime = pCls->pManTime; pCls->pManTime = NULL;
2189  Gia_ManStop( pCls );
2190  }
2191  return pNew;
2192 }
2194 {
2195  Gia_Man_t * pNew;
2196  if ( p->pManTime && Tim_ManBoxNum(p->pManTime) && Gia_ManIsNormalized(p) )
2197  {
2198  Tim_Man_t * pTimOld = (Tim_Man_t *)p->pManTime;
2199  p->pManTime = Tim_ManDup( pTimOld, 1 );
2200  pNew = Gia_ManDupUnnormalize( p );
2201  if ( pNew == NULL )
2202  return NULL;
2203  Gia_ManTransferTiming( pNew, p );
2204  p = pNew;
2205  // mapping
2206  pNew = Lf_ManPerformMappingInt( p, pPars );
2207  if ( pNew != p )
2208  {
2209  Gia_ManTransferTiming( pNew, p );
2210  Gia_ManStop( p );
2211  }
2212  // normalize
2213  pNew = Gia_ManDupNormalize( p = pNew );
2214  Gia_ManTransferMapping( pNew, p );
2215 // Gia_ManTransferPacking( pNew, p );
2216  Gia_ManTransferTiming( pNew, p );
2217  Gia_ManStop( p ); // do not delete if the original one!
2218  // cleanup
2219  Tim_ManStop( (Tim_Man_t *)pNew->pManTime );
2220  pNew->pManTime = pTimOld;
2221  assert( Gia_ManIsNormalized(pNew) );
2222  }
2223  else
2224  {
2225  // mapping
2226  pNew = Lf_ManPerformMappingInt( p, pPars );
2227  Gia_ManTransferTiming( pNew, p );
2228  }
2229  return pNew;
2230 }
2231 
2232 /**Function*************************************************************
2233 
2234  Synopsis [Interface of LUT mapping package.]
2235 
2236  Description []
2237 
2238  SideEffects []
2239 
2240  SeeAlso []
2241 
2242 ***********************************************************************/
2243 Gia_Man_t * Gia_ManPerformLfMapping( Gia_Man_t * p, Jf_Par_t * pPars, int fNormalized )
2244 {
2245  Gia_Man_t * pNew;
2246  // reconstruct GIA according to the hierarchy manager
2247  assert( pPars->pTimesArr == NULL );
2248  assert( pPars->pTimesReq == NULL );
2249  if ( p->pManTime )
2250  {
2251  if ( fNormalized )
2252  {
2253  pNew = Gia_ManDupUnnormalize( p );
2254  if ( pNew == NULL )
2255  return NULL;
2256  Gia_ManTransferTiming( pNew, p );
2257  p = pNew;
2258  // set arrival and required times
2259  pPars->pTimesArr = Tim_ManGetArrTimes( (Tim_Man_t *)p->pManTime );
2260  pPars->pTimesReq = Tim_ManGetReqTimes( (Tim_Man_t *)p->pManTime );
2261  }
2262  else
2263  p = Gia_ManDup( p );
2264  }
2265  else
2266  p = Gia_ManDup( p );
2267  // perform mapping
2268  pNew = Lf_ManPerformMappingInt( p, pPars );
2269  if ( pNew != p )
2270  {
2271  // transfer name
2272  ABC_FREE( pNew->pName );
2273  ABC_FREE( pNew->pSpec );
2274  pNew->pName = Abc_UtilStrsav( p->pName );
2275  pNew->pSpec = Abc_UtilStrsav( p->pSpec );
2276  Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
2277  // return the original (unmodified by the mapper) timing manager
2278  Gia_ManTransferTiming( pNew, p );
2279  Gia_ManStop( p );
2280  }
2281  // normalize and transfer mapping
2282  pNew = Gia_ManDupNormalize( p = pNew );
2283  Gia_ManTransferMapping( pNew, p );
2284 // Gia_ManTransferPacking( pNew, p );
2285  Gia_ManTransferTiming( pNew, p );
2286  Gia_ManStop( p );
2287  return pNew;
2288 }
2289 
2290 ////////////////////////////////////////////////////////////////////////
2291 /// END OF FILE ///
2292 ////////////////////////////////////////////////////////////////////////
2293 
2294 
2296 
#define LF_NO_LEAF
Definition: giaLf.c:36
static int Gia_ObjFanin2Copy(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:483
char * memset()
word Sign
Definition: giaLf.c:43
static int Lf_CutCreateUnit(Lf_Cut_t *p, int i)
Definition: giaLf.c:353
word Mux7
Definition: gia.h:301
#define LF_LOG_PAGE
Definition: giaLf.c:35
double Switches
Definition: giaLf.c:103
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
static int Gia_ManAppendAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition: gia.h:592
static int Lf_ObjMapRefNum(Lf_Man_t *p, int i)
Definition: giaLf.c:124
static void Lf_CutCopy(Lf_Cut_t *p, Lf_Cut_t *q, int n)
Definition: giaLf.c:115
static word Abc_Tt6Expand(word t, int *pCut0, int nCutSize0, int *pCut, int nCutSize)
Definition: utilTruth.h:1345
Lf_Mem_t vStoreNew
Definition: giaLf.c:91
float * pTimesArr
Definition: gia.h:306
static int Gia_ManMuxNum(Gia_Man_t *p)
Definition: gia.h:391
static void Lf_CutPrint(Lf_Man_t *p, Lf_Cut_t *pCut)
Definition: giaLf.c:456
unsigned nLeaves
Definition: giaLf.c:50
static int Gia_ObjFaninC2(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:453
struct Lf_Bst_t_ Lf_Bst_t
Definition: giaLf.c:59
int LogPage
Definition: giaLf.c:69
struct Lf_Cut_t_ Lf_Cut_t
Definition: giaLf.c:40
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Gia_ObjIsAndNotBuf(Gia_Obj_t *pObj)
Definition: gia.h:428
Gia_Man_t * Gia_ManDupUnnormalize(Gia_Man_t *p)
Definition: giaTim.c:373
static int Lf_CutIsMux(Lf_Man_t *p, Lf_Cut_t *pCut, Gia_Obj_t *pMux)
Definition: giaLf.c:477
static void Vec_MemAddMuxTT(Vec_Mem_t *p, int nVars)
Definition: vecMem.h:394
int nCoDrivers
Definition: giaLf.c:105
static int Gia_ObjPhase(Gia_Obj_t *pObj)
Definition: gia.h:415
static Gia_Obj_t * Gia_ObjSiblObj(Gia_Man_t *p, int Id)
Definition: gia.h:894
int nCutMux
Definition: giaLf.c:110
static int Gia_ManAppendXor(Gia_Man_t *p, int iLit0, int iLit1)
Definition: gia.h:735
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
static int Abc_TtMinBase(word *pTruth, int *pVars, int nVars, int nVarsAll)
Definition: utilTruth.h:1395
float Lf_CutDeref_rec(Lf_Man_t *p, Lf_Cut_t *pCut)
Definition: giaLf.c:1084
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
void Tim_ManIncrementTravId(Tim_Man_t *p)
DECLARATIONS ///.
Definition: timTrav.c:44
word Edge
Definition: gia.h:299
static double Vec_IntMemory(Vec_Int_t *p)
Definition: vecInt.h:384
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
static int Lf_CutComputeTruth6(Lf_Man_t *p, Lf_Cut_t *pCut0, Lf_Cut_t *pCut1, int fCompl0, int fCompl1, Lf_Cut_t *pCutR, int fIsXor)
Definition: giaLf.c:963
int fUseEla
Definition: giaLf.c:109
int nInverters
Definition: giaLf.c:106
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
int nLutSizeMux
Definition: gia.h:296
static int Lf_CutCompareArea(Lf_Cut_t *pCut0, Lf_Cut_t *pCut1)
Definition: giaLf.c:854
static int Gia_ManAppendCo(Gia_Man_t *p, int iLit0)
Definition: gia.h:703
Gia_Man_t * Lf_ManDeriveMappingGia(Lf_Man_t *p)
Definition: giaLf.c:1809
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Lf_Plc_t Cut[2]
Definition: giaLf.c:64
static void Abc_TtCofactor1p(word *pOut, word *pIn, int nWords, int iVar)
Definition: utilTruth.h:403
Vec_Mem_t * vTtMem
Definition: giaLf.c:88
static void Vec_IntFillExtra(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:376
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static float Lf_ObjFlowRefs(Lf_Man_t *p, int i)
Definition: giaLf.c:123
static Gia_Obj_t * Gia_Regular(Gia_Obj_t *p)
Definition: gia.h:377
static int Vec_FltCap(Vec_Flt_t *p)
Definition: vecFlt.h:310
#define LF_LEAF_MAX
DECLARATIONS ///.
Definition: giaLf.c:33
static int Lf_ManPrepareSet(Lf_Man_t *p, int iObj, int Index, Lf_Cut_t **ppCutSet)
Definition: giaLf.c:395
static char * Gia_ManName(Gia_Man_t *p)
Definition: gia.h:382
static void Vec_PtrGrow(Vec_Ptr_t *p, int nCapMin)
Definition: vecPtr.h:430
int pLeaves[0]
Definition: giaLf.c:51
static int Lf_SetCutIsContainedOrder(Lf_Cut_t *pBase, Lf_Cut_t *pCut)
Definition: giaLf.c:797
static int Abc_Truth6WordNum(int nVars)
Definition: abc_global.h:257
Vec_Int_t vRequired
Definition: giaLf.c:94
static int Lf_CutMergeOrderMux(Lf_Cut_t *pCut0, Lf_Cut_t *pCut1, Lf_Cut_t *pCut2, Lf_Cut_t *pCut, int nLutSize)
Definition: giaLf.c:771
Gia_Man_t * Lf_ManDeriveMappingCoarse(Lf_Man_t *p)
Definition: giaLf.c:1694
int nProcNum
Definition: gia.h:269
static int Gia_ManAppendCi(Gia_Man_t *p)
Definition: gia.h:583
abctime clkStart
Definition: giaLf.c:101
void Lf_ManComputeSwitching(Gia_Man_t *p, Vec_Flt_t *vSwitches)
Definition: giaLf.c:332
void Gia_ManCleanValue(Gia_Man_t *p)
Definition: giaUtil.c:310
int nAreaTuner
Definition: gia.h:274
void Gia_ManCleanMark0(Gia_Man_t *p)
Definition: giaUtil.c:215
static int Lf_CutComputeTruth(Lf_Man_t *p, Lf_Cut_t *pCut0, Lf_Cut_t *pCut1, int fCompl0, int fCompl1, Lf_Cut_t *pCutR, int fIsXor)
Definition: giaLf.c:984
float * pTimesReq
Definition: gia.h:307
int nCutNumMax
Definition: gia.h:294
void Tim_ManSetCoArrival(Tim_Man_t *p, int iCo, float Delay)
Definition: timTime.c:116
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
Vec_Ptr_t * vFree
Definition: giaLf.c:74
int fCutSimple
Definition: gia.h:290
#define Lf_CutForEachVar(pCut, Var, i)
Definition: giaLf.c:134
Vec_Flt_t vSwitches
Definition: giaLf.c:98
Vec_Int_t vFreeSets
Definition: giaLf.c:87
float Flow
Definition: giaLf.c:45
static Lf_Bst_t * Lf_ObjReadBest(Lf_Man_t *p, int i)
Definition: giaLf.c:122
unsigned * pMuxes
Definition: gia.h:104
static int Gia_ObjFaninId1p(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:464
int Lf_ManTtIsMux(word t)
Definition: giaLf.c:270
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
Definition: utilMem.c:35
#define LF_CUT_WORDS
Definition: giaLf.c:37
char * memcpy()
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
static int Lf_SetCheckArray(Lf_Cut_t **ppCuts, int nCuts)
Definition: giaLf.c:644
static void Vec_IntSetEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:418
unsigned Handle
Definition: giaLf.c:57
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int Gia_ObjIsBuf(Gia_Obj_t *pObj)
Definition: gia.h:427
static int Lf_ManSetMuxCut(Lf_Man_t *p, Lf_Bst_t *pBest, int iObj, int Required)
Definition: giaLf.c:1429
static float * Vec_FltArray(Vec_Flt_t *p)
Definition: vecFlt.h:274
static int Lf_CutComputeTruthMux6(Lf_Man_t *p, Lf_Cut_t *pCut0, Lf_Cut_t *pCut1, Lf_Cut_t *pCutC, int fCompl0, int fCompl1, int fComplC, Lf_Cut_t *pCutR)
Definition: giaLf.c:1012
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition: giaMan.c:628
static void Lf_ObjSetCiArrival(Lf_Man_t *p, int iCi, int Time)
FUNCTION DEFINITIONS ///.
Definition: giaLf.c:153
static int Gia_ManAndNotBufNum(Gia_Man_t *p)
Definition: gia.h:393
int fAreaOnly
Definition: gia.h:277
Vec_Ptr_t vMemSets
Definition: giaLf.c:86
int nVerbLimit
Definition: gia.h:275
static Lf_Cut_t * Lf_ManFetchSet(Lf_Man_t *p, int i)
Definition: giaLf.c:363
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
unsigned fLate
Definition: giaLf.c:48
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
int fCutHashing
Definition: gia.h:289
static void * Vec_PtrPop(Vec_Ptr_t *p)
Definition: vecPtr.h:677
int Lf_ManSetMapRefs(Lf_Man_t *p)
Definition: giaLf.c:1480
static int Lf_ManFindCofVar(word *pTruth, int nWords, int nVars)
Definition: giaLf.c:936
static void Vec_FltFill(Vec_Flt_t *p, int nSize, float Entry)
Definition: vecFlt.h:450
int nSetWords
Definition: giaLf.c:84
static Vec_Int_t * Vec_IntStartFull(int nSize)
Definition: vecInt.h:119
int nWords
Definition: abcNpn.c:127
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 int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
static int Lf_CutCountBits(word i)
Definition: giaLf.c:429
int iFunc
Definition: giaLf.c:46
int fPower
Definition: gia.h:280
static int Lf_ObjMapRefInc(Lf_Man_t *p, int i)
Definition: giaLf.c:125
int * pRefs
Definition: gia.h:114
Definition: gia.h:75
Gia_Man_t * pGia
Definition: giaLf.c:80
int Kit_TruthToGia(Gia_Man_t *pMan, unsigned *pTruth, int nVars, Vec_Int_t *vMemory, Vec_Int_t *vLeaves, int fHash)
DECLARATIONS ///.
Definition: kitHop.c:80
#define ABC_SWAP(Type, a, b)
Definition: abc_global.h:218
int nCutWords
Definition: giaLf.c:83
void Lf_ManSetFlowRefs(Gia_Man_t *p, Vec_Flt_t *vRefs, Vec_Int_t *vOffsets)
Definition: giaLf.c:1372
int fVeryVerbose
Definition: gia.h:292
static int Lf_CutCheck(Lf_Cut_t *pBase, Lf_Cut_t *pCut)
Definition: giaLf.c:628
static int Abc_Tt6MinBase(word *pTruth, int *pVars, int nVars)
Definition: utilTruth.h:1374
static int Lf_SetLastCutIsContained(Lf_Cut_t **pCuts, int nCuts)
Definition: giaLf.c:823
static void Lf_MemAlloc(Lf_Mem_t *p, int LogPage, Vec_Ptr_t *vFree, int nCutWords)
Definition: giaLf.c:517
static int Gia_ManHasChoices(Gia_Man_t *p)
Definition: gia.h:397
int nRelaxRatio
Definition: gia.h:272
int nCutEqual
Definition: giaLf.c:111
#define LF_TT_WORDS
Definition: giaLf.c:38
static float Lf_CutAreaDerefed(Lf_Man_t *p, Lf_Cut_t *pCut)
Definition: giaLf.c:1094
static void Lf_SetSortByArea(Lf_Cut_t **pCuts, int nCuts)
Definition: giaLf.c:884
word Delay
Definition: gia.h:297
void Lf_ManAnalyzeCoDrivers(Gia_Man_t *p, int *pnDrivers, int *pnInverts)
Definition: giaLf.c:318
static int Lf_ObjOff(Lf_Man_t *p, int i)
Definition: giaLf.c:119
word Area
Definition: gia.h:298
#define Gia_ManForEachCoDriverId(p, DriverId, i)
Definition: gia.h:1032
void Tim_ManSetCiRequired(Tim_Man_t *p, int iCi, float Delay)
Definition: timTime.c:135
static void Vec_IntGrow(Vec_Int_t *p, int nCapMin)
Definition: bblif.c:336
#define Gia_ManForEachCi(p, pObj, i)
Definition: gia.h:1016
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
int fOptEdge
Definition: gia.h:278
static void Lf_ObjSetRequired(Lf_Man_t *p, int i, int t)
Definition: giaLf.c:121
Lf_Man_t * Lf_ManAlloc(Gia_Man_t *pGia, Jf_Par_t *pPars)
Definition: giaLf.c:1898
static int Lf_BestIsMapped(Lf_Bst_t *p)
Definition: giaLf.c:129
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static int Gia_ManAppendMux(Gia_Man_t *p, int iCtrl, int iData1, int iData0)
Definition: gia.h:722
static int Lf_CutEqual(Lf_Cut_t *pCut0, Lf_Cut_t *pCut1)
Definition: giaLf.c:436
static int Gia_ManAndNum(Gia_Man_t *p)
Definition: gia.h:389
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 Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
static Lf_Cut_t * Lf_ObjCutBest(Lf_Man_t *p, int i)
Definition: giaLf.c:594
double CutCount[4]
Definition: giaLf.c:102
static int Gia_ObjIsMuxId(Gia_Man_t *p, int iObj)
Definition: gia.h:424
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
static void Abc_TtCopy(word *pOut, word *pIn, int nWords, int fCompl)
Definition: utilTruth.h:221
static void Vec_IntDowndateEntry(Vec_Int_t *p, int i, int Value)
Definition: vecInt.h:473
char * pName
Definition: gia.h:97
Vec_Ptr_t vPages
Definition: giaLf.c:73
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static void Abc_TtCofactor0p(word *pOut, word *pIn, int nWords, int iVar)
Definition: utilTruth.h:381
static int Lf_SetAddCut(Lf_Cut_t **pCuts, int nCuts, int nCutNum)
Definition: giaLf.c:894
static void Vec_FltUpdateEntry(Vec_Flt_t *p, int i, float Value)
Definition: vecFlt.h:398
unsigned Cost
Definition: giaLf.c:47
Definition: gia.h:265
int Iter
Definition: giaLf.c:108
static int Gia_ObjFanin1Copy(Gia_Obj_t *pObj)
Definition: gia.h:482
static void Vec_IntAddToEntry(Vec_Int_t *p, int i, int Addition)
Definition: bblif.c:302
#define Lf_CutSetForEachCut(nWords, pCutSet, pCut, i, nCuts)
Definition: giaLf.c:133
static void Lf_SetSortBySize(Lf_Cut_t **pCutsR, int nCutsR)
Definition: giaLf.c:912
static Vec_Mem_t * Vec_MemAllocForTT(int nVars, int fCompl)
Definition: vecMem.h:378
Gia_Man_t * Gia_ManDupNormalize(Gia_Man_t *p)
Definition: giaTim.c:134
#define Gia_ManForEachAndReverse(p, pObj, i)
Definition: gia.h:1010
static word * Lf_CutTruth(Lf_Man_t *p, Lf_Cut_t *pCut)
Definition: giaLf.c:117
static int Gia_ManAppendBuf(Gia_Man_t *p, int iLit)
Definition: gia.h:694
int nTimeFails
Definition: giaLf.c:107
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
int MaskPage
Definition: giaLf.c:70
int nFrontMax
Definition: giaLf.c:104
static int Abc_Base10Log(unsigned n)
Definition: abc_global.h:252
Vec_Int_t vCutSets
Definition: giaLf.c:95
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
void Lf_ManPrintInit(Lf_Man_t *p)
Definition: giaLf.c:2026
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:356
static Lf_Cut_t * Lf_CutNext(Lf_Cut_t *p, int n)
Definition: giaLf.c:116
char * pSpec
Definition: gia.h:98
static double Vec_MemMemory(Vec_Mem_t *p)
Definition: vecMem.h:175
static int Vec_IntPop(Vec_Int_t *p)
Gia_Man_t * Gia_ManStart(int nObjsMax)
DECLARATIONS ///.
Definition: giaMan.c:52
Gia_Man_t * Gia_ManDupMuxes(Gia_Man_t *p, int Limit)
Definition: giaMuxes.c:96
static int Gia_ObjIsXor(Gia_Obj_t *pObj)
Definition: gia.h:423
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
int nCutCounts[LF_LEAF_MAX+1]
Definition: giaLf.c:112
static int Lf_CutComputeTruthMux(Lf_Man_t *p, Lf_Cut_t *pCut0, Lf_Cut_t *pCut1, Lf_Cut_t *pCutC, int fCompl0, int fCompl1, int fComplC, Lf_Cut_t *pCutR)
Definition: giaLf.c:1033
Tim_Man_t * Tim_ManDup(Tim_Man_t *p, int fUnitDelay)
Definition: timMan.c:86
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
void Lf_ManSetDefaultPars(Jf_Par_t *pPars)
Definition: giaLf.c:1981
static void Vec_IntAppend(Vec_Int_t *vVec1, Vec_Int_t *vVec2)
void * pManTime
Definition: gia.h:165
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
void Tim_ManStop(Tim_Man_t *p)
Definition: timMan.c:375
static int Lf_MemSaveCut(Lf_Mem_t *p, Lf_Cut_t *pCut, int iObj)
Definition: giaLf.c:525
static int Gia_ManXorNum(Gia_Man_t *p)
Definition: gia.h:390
void Lf_ManPrintStats(Lf_Man_t *p, char *pTitle)
Definition: giaLf.c:2010
int Tim_ManBoxNum(Tim_Man_t *p)
Definition: timMan.c:702
void Gia_ManTransferTiming(Gia_Man_t *p, Gia_Man_t *pGia)
Definition: giaIf.c:1912
int iCur
Definition: giaLf.c:72
static void Vec_IntFreeP(Vec_Int_t **p)
Definition: vecInt.h:289
void Gia_ManMappingVerify(Gia_Man_t *p)
Definition: giaIf.c:1807
static int Vec_IntCap(Vec_Int_t *p)
Definition: vecInt.h:368
static void Vec_MemDumpTruthTables(Vec_Mem_t *p, char *pName, int nLutSize)
Definition: vecMem.h:402
static void Lf_ManSetFlowRefInc(Gia_Man_t *p, Vec_Flt_t *vRefs, Vec_Int_t *vOffsets, int i)
Definition: giaLf.c:1367
#define LF_CUT_MAX
Definition: giaLf.c:34
int Delay
Definition: giaLf.c:44
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
static int Lf_ObjCoArrival2(Lf_Man_t *p, int iCo)
Definition: giaLf.c:197
static int Lf_ObjCiArrival(Lf_Man_t *p, int iCi)
Definition: giaLf.c:157
static Lf_Cut_t * Lf_MemLoadMuxCut(Lf_Man_t *p, int iObj, Lf_Cut_t *pCut)
Definition: giaLf.c:577
void Gia_ManPrintMuxStats(Gia_Man_t *p)
Definition: giaMuxes.c:61
float * Tim_ManGetReqTimes(Tim_Man_t *p)
Definition: timMan.c:494
static int Gia_ObjFanin0Copy(Gia_Obj_t *pObj)
Definition: gia.h:481
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
Gia_Man_t * Lf_ManPerformMappingInt(Gia_Man_t *pGia, Jf_Par_t *pPars)
Definition: giaLf.c:2133
static float Lf_ObjSwitches(Lf_Man_t *p, int i)
Definition: giaLf.c:127
static Gia_Obj_t * Gia_ObjFanin2(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:456
Gia_Man_t * Lf_ManPerformMapping(Gia_Man_t *p, Jf_Par_t *pPars)
Definition: giaLf.c:2193
Vec_Int_t vCiArrivals
Definition: giaLf.c:99
static int Lf_CutMergeOrder(Lf_Cut_t *pCut0, Lf_Cut_t *pCut1, Lf_Cut_t *pCut, int nLutSize)
Definition: giaLf.c:684
static Lf_Cut_t * Lf_ObjCutMux(Lf_Man_t *p, int i)
Definition: giaLf.c:589
static int Gia_ObjIsCo(Gia_Obj_t *pObj)
Definition: gia.h:421
static void Lf_MemRecycle(Lf_Mem_t *p)
Definition: giaLf.c:568
static int Lf_BestIndex(Lf_Bst_t *p)
Definition: giaLf.c:130
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int fDoAverage
Definition: gia.h:288
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int Gia_ObjIsMuxType(Gia_Obj_t *pNode)
Definition: giaUtil.c:885
static Lf_Cut_t * Lf_ObjCutBestNew(Lf_Man_t *p, int i, Lf_Cut_t *pCut)
Definition: giaLf.c:606
static int Gia_ManCiNum(Gia_Man_t *p)
Definition: gia.h:383
float Lf_CutRef_rec(Lf_Man_t *p, Lf_Cut_t *pCut)
Definition: giaLf.c:1074
Jf_Par_t * pPars
Definition: giaLf.c:81
Gia_Man_t * Gia_ManPerformLfMapping(Gia_Man_t *p, Jf_Par_t *pPars, int fNormalized)
Definition: giaLf.c:2243
int nRounds
Definition: gia.h:270
static void Vec_FltAddToEntry(Vec_Flt_t *p, int i, float Addition)
Definition: vecFlt.h:381
static Gia_Obj_t * Gia_ManCo(Gia_Man_t *p, int v)
Definition: gia.h:404
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
Gia_Man_t * Lf_ManDeriveMapping(Lf_Man_t *p)
Definition: giaLf.c:1669
static void Abc_TtExpand(word *pTruth0, int nVars, int *pCut0, int nCutSize0, int *pCut, int nCutSize)
Definition: utilTruth.h:1360
static int Lf_SetLastCutContainsArea(Lf_Cut_t **pCuts, int nCuts)
Definition: giaLf.c:866
Vec_Int_t vOffsets
Definition: giaLf.c:93
static int Lf_CutRequired(Lf_Man_t *p, Lf_Cut_t *pCut)
Definition: giaLf.c:1115
static void Vec_IntShrink(Vec_Int_t *p, int nSizeNew)
Definition: bblif.c:435
unsigned fMark0
Definition: gia.h:79
static int Lf_ObjCoArrival(Lf_Man_t *p, int iCo)
Definition: giaLf.c:171
#define ABC_CONST(number)
PARAMETERS ///.
Definition: abc_global.h:206
static int Lf_ManDerivePart(Lf_Man_t *p, Gia_Man_t *pNew, Vec_Int_t *vMapping, Vec_Int_t *vMapping2, Vec_Int_t *vCopies, Lf_Cut_t *pCut, Vec_Int_t *vLeaves, Vec_Int_t *vCover, Gia_Obj_t *pObj)
Definition: giaLf.c:1737
#define ABC_FREE(obj)
Definition: abc_global.h:232
Gia_Obj_t * Gia_ObjRecognizeMux(Gia_Obj_t *pNode, Gia_Obj_t **ppNodeT, Gia_Obj_t **ppNodeE)
Definition: giaUtil.c:959
static void Abc_TtMux(word *pOut, word *pCtrl, word *pIn1, word *pIn0, int nWords)
Definition: utilTruth.h:263
Definition: gia.h:95
int Gia_ManIsNormalized(Gia_Man_t *p)
Definition: giaTim.c:109
static int Gia_ManBufNum(Gia_Man_t *p)
Definition: gia.h:392
int fPureAig
Definition: gia.h:287
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition: gia.h:984
int fCutMin
Definition: gia.h:282
void Lf_ManCountMapRefsOne(Lf_Man_t *p, int iObj)
Definition: giaLf.c:1577
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
Vec_Ptr_t vFreePages
Definition: giaLf.c:89
int Lf_ObjCoArrival2_rec(Lf_Man_t *p, Gia_Obj_t *pDriver)
Definition: giaLf.c:182
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
int Var
Definition: SolverTypes.h:42
static int Abc_TtSupportSize(word *t, int nVars)
Definition: utilTruth.h:986
static int Gia_ObjFaninId0p(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:463
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
Definition: vecFlt.h:42
int Delay[3]
Definition: giaLf.c:62
static int Gia_ObjFaninId2p(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:465
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
int fFuncDsd
Definition: gia.h:283
int Lf_ObjArrival_rec(Lf_Man_t *p, Gia_Obj_t *pDriver)
Definition: giaLf.c:161
static word Lf_CutGetSign(Lf_Cut_t *pCut)
Definition: giaLf.c:422
static int Vec_MemHashInsert(Vec_Mem_t *p, word *pEntry)
Definition: vecMem.h:351
void Lf_ManComputeMapping(Lf_Man_t *p)
Definition: giaLf.c:2089
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition: abc_global.h:216
static int Lf_ObjMapRefDec(Lf_Man_t *p, int i)
Definition: giaLf.c:126
static void Vec_MemHashFree(Vec_Mem_t *p)
Definition: vecMem.h:311
static float Lf_CutArea(Lf_Man_t *p, Lf_Cut_t *pCut)
Definition: giaLf.c:467
void Gia_ManTransferMapping(Gia_Man_t *p, Gia_Man_t *pGia)
Definition: giaIf.c:1855
float Tim_ManGetCoRequired(Tim_Man_t *p, int iCo)
Definition: timTime.c:222
int fGenCnf
Definition: gia.h:284
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
static int * Vec_IntEntryP(Vec_Int_t *p, int i)
Definition: vecInt.h:417
double Gia_ManMemory(Gia_Man_t *p)
Definition: giaMan.c:156
void Lf_ManFree(Lf_Man_t *p)
Definition: giaLf.c:1941
void Gia_ManSetPhase(Gia_Man_t *p)
Definition: giaUtil.c:379
static int Gia_ObjFaninId2(Gia_Man_t *p, int ObjId)
Definition: gia.h:462
unsigned Value
Definition: gia.h:87
unsigned fMux7
Definition: giaLf.c:49
typedefABC_NAMESPACE_HEADER_START struct Tim_Man_t_ Tim_Man_t
INCLUDES ///.
Definition: tim.h:92
static unsigned Gia_AigerReadUnsigned(unsigned char **ppPos)
Definition: gia.h:840
static float Vec_FltEntry(Vec_Flt_t *p, int i)
Definition: vecFlt.h:342
static float Lf_CutSwitches(Lf_Man_t *p, Lf_Cut_t *pCut)
Definition: giaLf.c:448
unsigned fUsed
Definition: giaLf.c:56
int nLutSizeMax
Definition: gia.h:293
static Lf_Cut_t * Lf_MemLoadCut(Lf_Mem_t *p, int iCur, int iObj, Lf_Cut_t *pCut, int fTruth, int fRecycle)
Definition: giaLf.c:547
static int Lf_BestDiffCuts(Lf_Bst_t *p)
Definition: giaLf.c:128
void Tim_ManSetCoRequired(Tim_Man_t *p, int iCo, float Delay)
Definition: timTime.c:154
#define Gia_ManForEachObj1(p, pObj, i)
Definition: gia.h:986
#define Gia_ManForEachAndId(p, i)
Definition: gia.h:1004
#define Gia_ManForEachObjReverse1(p, pObj, i)
Definition: gia.h:996
static int Gia_AigerWriteUnsignedBuffer(unsigned char *pBuffer, int Pos, unsigned x)
Definition: gia.h:872
void Lf_ManCountMapRefs(Lf_Man_t *p)
Definition: giaLf.c:1593
Vec_Int_t vMapRefs
Definition: giaLf.c:97
static int Lf_CutMergeOrder2(Lf_Cut_t *pCut0, Lf_Cut_t *pCut1, Lf_Cut_t *pCut, int nLutSize)
Definition: giaLf.c:749
static word * Vec_MemReadEntry(Vec_Mem_t *p, int i)
Definition: vecMem.h:191
Vec_Int_t * vMapping
Definition: gia.h:131
Vec_Flt_t vFlowRefs
Definition: giaLf.c:96
Lf_Mem_t vStoreOld
Definition: giaLf.c:90
static int Lf_BestCutIndex(Lf_Bst_t *p)
Definition: giaLf.c:131
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
float * Tim_ManGetArrTimes(Tim_Man_t *p)
Definition: timMan.c:479
static void Abc_TtAnd(word *pOut, word *pIn1, word *pIn2, int nWords, int fCompl)
Definition: utilTruth.h:231
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static int Gia_ManPiNum(Gia_Man_t *p)
Definition: gia.h:385
int Lf_ManComputeCrossCut(Gia_Man_t *p)
Definition: giaLf.c:225
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
ABC_INT64_T abctime
Definition: abc_global.h:278
static void Lf_CutParams(Lf_Man_t *p, Lf_Cut_t *pCut, int Required, float FlowRefs, Gia_Obj_t *pMux)
Definition: giaLf.c:1132
static int Gia_ObjIsCi(Gia_Obj_t *pObj)
Definition: gia.h:420
static int Vec_FltSize(Vec_Flt_t *p)
Definition: vecFlt.h:294
Vec_Int_t * Gia_ManComputeSwitchProbs(Gia_Man_t *pGia, int nFrames, int nPref, int fProbOne)
Definition: giaSwitch.c:658
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
void Lf_ManSetCutRefs(Lf_Man_t *p)
Definition: giaLf.c:1408
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
static int Lf_CutCompareDelay(Lf_Cut_t *pCut0, Lf_Cut_t *pCut1)
Definition: giaLf.c:844
static int Gia_ObjFaninId1(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:461
int nCutWords
Definition: giaLf.c:71
static int Gia_ObjIsMux(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:425
float Tim_ManGetCiArrival(Tim_Man_t *p, int iCi)
Definition: timTime.c:174
Lf_Bst_t * pObjBests
Definition: giaLf.c:85
int nRoundsEla
Definition: gia.h:271
int fUseMux7
Definition: gia.h:279
static void Vec_PtrFreeData(Vec_Ptr_t *p)
Definition: vecPtr.h:561
void Lf_ManSetMapRefsOne(Lf_Man_t *p, int iObj)
Definition: giaLf.c:1445
void Lf_ManPrintQuit(Lf_Man_t *p, Gia_Man_t *pNew)
Definition: giaLf.c:2045
int DelayTarget
Definition: gia.h:276
static void Abc_TtXor(word *pOut, word *pIn1, word *pIn2, int nWords, int fCompl)
Definition: utilTruth.h:253
int nCoarseLimit
Definition: gia.h:273
static void Abc_TtNot(word *pOut, int nWords)
Definition: utilTruth.h:215
static int Gia_ObjCioId(Gia_Obj_t *pObj)
Definition: gia.h:411
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
float Flow[3]
Definition: giaLf.c:63
void Tim_ManInitPoRequiredAll(Tim_Man_t *p, float Delay)
Definition: timTime.c:97
int fVerbose
Definition: gia.h:291
static int Lf_ObjRequired(Lf_Man_t *p, int i)
Definition: giaLf.c:120
static int Gia_ObjFaninId0(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:460
int fCoarsen
Definition: gia.h:281
static int Gia_ManCoNum(Gia_Man_t *p)
Definition: gia.h:384
void Lf_ObjMergeOrder(Lf_Man_t *p, int iObj)
Definition: giaLf.c:1173
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387