abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaIf.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [giaMap.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Scalable AIG package.]
8 
9  Synopsis [Manipulation of mapping associated with the AIG.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: giaMap.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "gia.h"
22 #include "aig/aig/aig.h"
23 #include "map/if/if.h"
24 #include "bool/kit/kit.h"
25 #include "base/main/main.h"
26 #include "sat/bsat/satSolver.h"
27 
28 #ifdef WIN32
29 #include <windows.h>
30 #endif
31 
33 
34 
35 ////////////////////////////////////////////////////////////////////////
36 /// DECLARATIONS ///
37 ////////////////////////////////////////////////////////////////////////
38 
39 extern int Kit_TruthToGia( Gia_Man_t * pMan, unsigned * pTruth, int nVars, Vec_Int_t * vMemory, Vec_Int_t * vLeaves, int fHash );
40 extern int Abc_RecToGia3( Gia_Man_t * pMan, If_Man_t * pIfMan, If_Cut_t * pCut, Vec_Int_t * vLeaves, int fHash );
41 
42 ////////////////////////////////////////////////////////////////////////
43 /// FUNCTION DEFINITIONS ///
44 ////////////////////////////////////////////////////////////////////////
45 
46 /**Function*************************************************************
47 
48  Synopsis [Load the network into FPGA manager.]
49 
50  Description []
51 
52  SideEffects []
53 
54  SeeAlso []
55 
56 ***********************************************************************/
57 void Gia_ManSetIfParsDefault( void * pp )
58 {
59  If_Par_t * pPars = (If_Par_t *)pp;
60 // extern void * Abc_FrameReadLibLut();
61  If_Par_t * p = (If_Par_t *)pPars;
62  // set defaults
63  memset( p, 0, sizeof(If_Par_t) );
64  // user-controlable paramters
65  p->nLutSize = -1;
66 // p->nLutSize = 6;
67  p->nCutsMax = 8;
68  p->nFlowIters = 1;
69  p->nAreaIters = 2;
70  p->DelayTarget = -1;
71  p->Epsilon = (float)0.005;
72  p->fPreprocess = 1;
73  p->fArea = 0;
74  p->fFancy = 0;
75  p->fExpRed = 1; ////
76  p->fLatchPaths = 0;
77  p->fEdge = 1;
78  p->fPower = 0;
79  p->fCutMin = 0;
80  p->fVerbose = 0;
81  p->pLutStruct = NULL;
82  // internal parameters
83  p->fTruth = 0;
84  p->nLatchesCi = 0;
85  p->nLatchesCo = 0;
86  p->fLiftLeaves = 0;
87  p->fUseCoAttrs = 1; // use CO attributes
88  p->pLutLib = NULL;
89  p->pTimesArr = NULL;
90  p->pTimesReq = NULL;
91  p->pFuncCost = NULL;
92 }
93 
94 
95 /**Function*************************************************************
96 
97  Synopsis [Prints mapping statistics.]
98 
99  Description []
100 
101  SideEffects []
102 
103  SeeAlso []
104 
105 ***********************************************************************/
107 {
108  int i, Counter = 0;
109  Gia_ManForEachLut( p, i )
110  Counter += Gia_ObjLutSize(p, i);
111  return Counter;
112 }
113 
114 /**Function*************************************************************
115 
116  Synopsis [Prints mapping statistics.]
117 
118  Description []
119 
120  SideEffects []
121 
122  SeeAlso []
123 
124 ***********************************************************************/
126 {
127  int i, nSizeMax = -1;
128  Gia_ManForEachLut( p, i )
129  nSizeMax = Abc_MaxInt( nSizeMax, Gia_ObjLutSize(p, i) );
130  return nSizeMax;
131 }
132 
133 /**Function*************************************************************
134 
135  Synopsis [Prints mapping statistics.]
136 
137  Description []
138 
139  SideEffects []
140 
141  SeeAlso []
142 
143 ***********************************************************************/
145 {
146  int i, Counter = 0;
147  Gia_ManForEachLut( p, i )
148  Counter ++;
149  return Counter;
150 }
151 
152 /**Function*************************************************************
153 
154  Synopsis [Prints mapping statistics.]
155 
156  Description []
157 
158  SideEffects []
159 
160  SeeAlso []
161 
162 ***********************************************************************/
164 {
165  Gia_Obj_t * pObj;
166  int i, k, iFan, Level;
167  int * pLevels = ABC_CALLOC( int, Gia_ManObjNum(p) );
168  Gia_ManForEachLut( p, i )
169  {
170  Level = 0;
171  Gia_LutForEachFanin( p, i, iFan, k )
172  if ( Level < pLevels[iFan] )
173  Level = pLevels[iFan];
174  pLevels[i] = Level + 1;
175  }
176  Level = 0;
177  Gia_ManForEachCo( p, pObj, k )
178  if ( Level < pLevels[Gia_ObjFaninId0p(p, pObj)] )
179  Level = pLevels[Gia_ObjFaninId0p(p, pObj)];
180  ABC_FREE( pLevels );
181  return Level;
182 }
183 
184 /**Function*************************************************************
185 
186  Synopsis [Prints mapping statistics.]
187 
188  Description []
189 
190  SideEffects []
191 
192  SeeAlso []
193 
194 ***********************************************************************/
195 void Gia_ManLutParams( Gia_Man_t * p, int * pnCurLuts, int * pnCurEdges, int * pnCurLevels )
196 {
197  if ( p->pManTime && Tim_ManBoxNum((Tim_Man_t *)p->pManTime) )
198  {
199  int i;
200  *pnCurLuts = 0;
201  *pnCurEdges = 0;
202  Gia_ManForEachLut( p, i )
203  {
204  (*pnCurLuts)++;
205  (*pnCurEdges) += Gia_ObjLutSize(p, i);
206  }
207  *pnCurLevels = Gia_ManLutLevelWithBoxes( p );
208  }
209  else
210  {
211  Gia_Obj_t * pObj;
212  int i, k, iFan;
213  int * pLevels = ABC_CALLOC( int, Gia_ManObjNum(p) );
214  *pnCurLuts = 0;
215  *pnCurEdges = 0;
216  Gia_ManForEachLut( p, i )
217  {
218  int Level = 0;
219  (*pnCurLuts)++;
220  (*pnCurEdges) += Gia_ObjLutSize(p, i);
221  Gia_LutForEachFanin( p, i, iFan, k )
222  if ( Level < pLevels[iFan] )
223  Level = pLevels[iFan];
224  pLevels[i] = Level + 1;
225  }
226  *pnCurLevels = 0;
227  Gia_ManForEachCo( p, pObj, k )
228  if ( *pnCurLevels < pLevels[Gia_ObjFaninId0p(p, pObj)] )
229  *pnCurLevels = pLevels[Gia_ObjFaninId0p(p, pObj)];
230  ABC_FREE( pLevels );
231  }
232 }
233 
234 /**Function*************************************************************
235 
236  Synopsis [Assigns levels.]
237 
238  Description []
239 
240  SideEffects []
241 
242  SeeAlso []
243 
244 ***********************************************************************/
246 {
247  Gia_Obj_t * pObj;
248  int i, k, iFan;
249  ABC_FREE( p->pRefs );
250  p->pRefs = ABC_CALLOC( int, Gia_ManObjNum(p) );
251  Gia_ManForEachCo( p, pObj, i )
252  Gia_ObjRefInc( p, Gia_ObjFanin0(pObj) );
253  Gia_ManForEachLut( p, i )
254  Gia_LutForEachFanin( p, i, iFan, k )
255  Gia_ObjRefInc( p, Gia_ManObj(p, iFan) );
256 }
257 
258 /**Function*************************************************************
259 
260  Synopsis [Calculate mapping overlap.]
261 
262  Description []
263 
264  SideEffects []
265 
266  SeeAlso []
267 
268 ***********************************************************************/
269 int Gia_ManComputeOverlap2One_rec( Gia_Man_t * p, int iObj, Vec_Str_t * vLabel, Vec_Int_t * vVisit )
270 {
271  Gia_Obj_t * pObj;
272  int Counter;
273  if ( Vec_StrEntry(vLabel, iObj) )
274  return 0;
275  Vec_StrWriteEntry( vLabel, iObj, 1 );
276  pObj = Gia_ManObj( p, iObj );
277  assert( Gia_ObjIsAnd(pObj) );
278  Counter = Gia_ManComputeOverlap2One_rec( p, Gia_ObjFaninId0(pObj, iObj), vLabel, vVisit );
279  Counter += Gia_ManComputeOverlap2One_rec( p, Gia_ObjFaninId1(pObj, iObj), vLabel, vVisit );
280  Vec_IntPush( vVisit, iObj );
281  return Counter + 1;
282 }
283 int Gia_ManComputeOverlap2One( Gia_Man_t * p, int iObj, Vec_Str_t * vLabel, Vec_Int_t * vVisit )
284 {
285  int iFan, k, Counter;
286  Vec_IntClear( vVisit );
287  Gia_LutForEachFanin( p, iObj, iFan, k )
288  Vec_StrWriteEntry( vLabel, iFan, 1 );
289  Counter = Gia_ManComputeOverlap2One_rec( p, iObj, vLabel, vVisit );
290  Gia_LutForEachFanin( p, iObj, iFan, k )
291  Vec_StrWriteEntry( vLabel, iFan, 0 );
292  Vec_IntForEachEntry( vVisit, iFan, k )
293  Vec_StrWriteEntry( vLabel, iFan, 0 );
294  return Counter;
295 }
297 {
298  Vec_Int_t * vVisit;
299  Vec_Str_t * vLabel;
300  int i, Count = -Gia_ManAndNum(p);
302  vVisit = Vec_IntAlloc( 100 );
303  vLabel = Vec_StrStart( Gia_ManObjNum(p) );
304  Gia_ManForEachLut( p, i )
305  Count += Gia_ManComputeOverlap2One( p, i, vLabel, vVisit );
306  Vec_StrFree( vLabel );
307  Vec_IntFree( vVisit );
308  return Count;
309 }
310 
311 /**Function*************************************************************
312 
313  Synopsis [Calculate mapping overlap.]
314 
315  Description []
316 
317  SideEffects []
318 
319  SeeAlso []
320 
321 ***********************************************************************/
323 {
324  Gia_Obj_t * pObj;
325  if ( Gia_ObjIsTravIdCurrentId(p, iObj) )
326  return 0;
327  Gia_ObjSetTravIdCurrentId( p, iObj );
328  pObj = Gia_ManObj( p, iObj );
329  assert( Gia_ObjIsAnd(pObj) );
330  return 1 + Gia_ManComputeOverlapOne_rec( p, Gia_ObjFaninId0(pObj, iObj) )
331  + Gia_ManComputeOverlapOne_rec( p, Gia_ObjFaninId1(pObj, iObj) );
332 }
334 {
335  int iFan, k;
337  Gia_LutForEachFanin( p, iObj, iFan, k )
338  Gia_ObjSetTravIdCurrentId( p, iFan );
339  return Gia_ManComputeOverlapOne_rec( p, iObj );
340 }
342 {
343  int i, Count = -Gia_ManAndNum(p);
345  Gia_ManForEachLut( p, i )
346  Count += Gia_ManComputeOverlapOne( p, i );
347  return Count;
348 }
349 
350 /**Function*************************************************************
351 
352  Synopsis [Prints mapping statistics.]
353 
354  Description []
355 
356  SideEffects []
357 
358  SeeAlso []
359 
360 ***********************************************************************/
361 void Gia_ManPrintGetMuxFanins( Gia_Man_t * p, Gia_Obj_t * pObj, int * pFanins )
362 {
363  Gia_Obj_t * pData0, * pData1;
364  Gia_Obj_t * pCtrl = Gia_ObjRecognizeMux( pObj, &pData1, &pData0 );
365  pFanins[0] = Gia_ObjId(p, Gia_Regular(pCtrl));
366  pFanins[1] = Gia_ObjId(p, Gia_Regular(pData1));
367  pFanins[2] = Gia_ObjId(p, Gia_Regular(pData0));
368 }
370 {
371  Gia_Obj_t * pObj, * pFanin;
372  int i, pFanins[3], nCountDup = 0, nCountPis = 0, nCountMux = 0;
373  Gia_ManCleanMark01( p );
374  Gia_ManForEachLut( p, i )
375  if ( Gia_ObjLutIsMux(p, i) )
376  {
377  pObj = Gia_ManObj( p, i );
378  pObj->fMark1 = 1;
379  if ( Gia_ObjLutSize(p, i) == 3 )
380  {
381  Gia_ManPrintGetMuxFanins( p, pObj, pFanins );
382 
383  pFanin = Gia_ManObj(p, pFanins[1]);
384  nCountPis += Gia_ObjIsCi(pFanin);
385  nCountDup += pFanin->fMark0;
386  nCountMux += pFanin->fMark1;
387  pFanin->fMark0 = 1;
388 
389  pFanin = Gia_ManObj(p, pFanins[2]);
390  nCountPis += Gia_ObjIsCi(pFanin);
391  nCountDup += pFanin->fMark0;
392  nCountMux += pFanin->fMark1;
393  pFanin->fMark0 = 1;
394  }
395  else if ( Gia_ObjLutSize(p, i) == 2 )
396  {
397  pFanin = Gia_ObjFanin0(pObj);
398  if ( pFanin->fMark0 || pFanin->fMark1 )
399  {
400  pFanin = Gia_ObjFanin1(pObj);
401  nCountPis += Gia_ObjIsCi(pFanin);
402  nCountDup += pFanin->fMark0;
403  nCountMux += pFanin->fMark1;
404  pFanin->fMark0 = 1;
405  }
406  else
407  {
408  nCountPis += Gia_ObjIsCi(pFanin);
409  nCountDup += pFanin->fMark0;
410  nCountMux += pFanin->fMark1;
411  pFanin->fMark0 = 1;
412  }
413  }
414  else assert( 0 );
415  }
416  Gia_ManCleanMark01( p );
417  if ( nCountDup + nCountPis + nCountMux )
418  printf( "Dup fanins = %d. CI fanins = %d. MUX fanins = %d. Total = %d. (%.2f %%)\n",
419  nCountDup, nCountPis, nCountMux, nCountDup + nCountPis, 100.0 * (nCountDup + nCountPis + nCountMux) / Gia_ManLutNum(p) );
420  return nCountDup + nCountPis;
421 }
422 
423 void Gia_ManPrintMappingStats( Gia_Man_t * p, char * pDumpFile )
424 {
425  Gia_Obj_t * pObj;
426  int * pLevels;
427  int i, k, iFan, nLutSize = 0, nLuts = 0, nFanins = 0, LevelMax = 0, Ave = 0, nMuxF = 0;
428  if ( !Gia_ManHasMapping(p) )
429  return;
430  pLevels = ABC_CALLOC( int, Gia_ManObjNum(p) );
431  Gia_ManForEachLut( p, i )
432  {
433  if ( Gia_ObjLutIsMux(p, i) )
434  {
435  int pFanins[3];
436  if ( Gia_ObjLutSize(p, i) == 3 )
437  {
438  Gia_ManPrintGetMuxFanins( p, Gia_ManObj(p, i), pFanins );
439  pLevels[i] = Abc_MaxInt( pLevels[i], pLevels[pFanins[0]]+1 );
440  pLevels[i] = Abc_MaxInt( pLevels[i], pLevels[pFanins[1]] );
441  pLevels[i] = Abc_MaxInt( pLevels[i], pLevels[pFanins[2]] );
442  }
443  else if ( Gia_ObjLutSize(p, i) == 2 )
444  {
445  pObj = Gia_ManObj( p, i );
446  pLevels[i] = Abc_MaxInt( pLevels[i], pLevels[Gia_ObjFaninId0(pObj, i)] );
447  pLevels[i] = Abc_MaxInt( pLevels[i], pLevels[Gia_ObjFaninId1(pObj, i)] );
448  }
449  LevelMax = Abc_MaxInt( LevelMax, pLevels[i] );
450  nFanins++;
451  nMuxF++;
452  continue;
453  }
454  nLuts++;
455  nFanins += Gia_ObjLutSize(p, i);
456  nLutSize = Abc_MaxInt( nLutSize, Gia_ObjLutSize(p, i) );
457  Gia_LutForEachFanin( p, i, iFan, k )
458  pLevels[i] = Abc_MaxInt( pLevels[i], pLevels[iFan] );
459  pLevels[i]++;
460  LevelMax = Abc_MaxInt( LevelMax, pLevels[i] );
461  }
462  Gia_ManForEachCo( p, pObj, i )
463  Ave += pLevels[Gia_ObjFaninId0p(p, pObj)];
464  ABC_FREE( pLevels );
465 
466 #ifdef WIN32
467  {
468  HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
469  Abc_Print( 1, "Mapping (K=%d) : ", nLutSize );
470  SetConsoleTextAttribute( hConsole, 14 ); // yellow
471  Abc_Print( 1, "lut =%7d ", nLuts );
472  if ( nMuxF )
473  Abc_Print( 1, "muxF =%7d ", nMuxF );
474  SetConsoleTextAttribute( hConsole, 10 ); // green
475  Abc_Print( 1, "edge =%8d ", nFanins );
476  SetConsoleTextAttribute( hConsole, 12 ); // red
477  Abc_Print( 1, "lev =%5d ", LevelMax );
478  Abc_Print( 1, "(%.2f) ", (float)Ave / Gia_ManCoNum(p) );
479 // Abc_Print( 1, "over =%5.1f %% ", 100.0 * Gia_ManComputeOverlap(p) / Gia_ManAndNum(p) );
480  if ( p->pManTime && Tim_ManBoxNum((Tim_Man_t *)p->pManTime) )
481  Abc_Print( 1, "levB =%5d ", Gia_ManLutLevelWithBoxes(p) );
482  SetConsoleTextAttribute( hConsole, 7 ); // normal
483  Abc_Print( 1, "mem =%5.2f MB", 4.0*(Gia_ManObjNum(p) + 2*nLuts + nFanins)/(1<<20) );
484  Abc_Print( 1, "\n" );
485  }
486 #else
487  Abc_Print( 1, "Mapping (K=%d) : ", nLutSize );
488  Abc_Print( 1, "%slut =%7d%s ", "\033[1;33m", nLuts, "\033[0m" ); // yellow
489  Abc_Print( 1, "%sedge =%8d%s ", "\033[1;32m", nFanins, "\033[0m" ); // green
490  Abc_Print( 1, "%slev =%5d%s ", "\033[1;31m", LevelMax, "\033[0m" ); // red
491  Abc_Print( 1, "%s(%.2f)%s ", "\033[1;31m", (float)Ave / Gia_ManCoNum(p), "\033[0m" );
492 // Abc_Print( 1, "over =%5.1f %% ", 100.0 * Gia_ManComputeOverlap(p) / Gia_ManAndNum(p) );
493  if ( p->pManTime && Tim_ManBoxNum((Tim_Man_t *)p->pManTime) )
494  Abc_Print( 1, "%slevB =%5d%s ", "\033[1;31m", Gia_ManLutLevelWithBoxes(p), "\033[0m" );
495  Abc_Print( 1, "mem =%5.2f MB", 4.0*(Gia_ManObjNum(p) + 2*nLuts + nFanins)/(1<<20) );
496  Abc_Print( 1, "\n" );
497 #endif
498 
499  if ( nMuxF )
500  Gia_ManCountDupLut( p );
501 
502  return;
503  if ( pDumpFile )
504  {
505  static char FileNameOld[1000] = {0};
506  static abctime clk = 0;
507  FILE * pTable = fopen( pDumpFile, "a+" );
508  if ( strcmp( FileNameOld, p->pName ) )
509  {
510  sprintf( FileNameOld, "%s", p->pName );
511  fprintf( pTable, "\n" );
512  fprintf( pTable, "%s ", p->pName );
513 // fprintf( pTable, "%d ", Gia_ManCiNum(p) );
514 // fprintf( pTable, "%d ", Gia_ManCoNum(p) );
515 // fprintf( pTable, "%d ", Gia_ManAndNum(p) );
516  fprintf( pTable, "%d ", Gia_ManPiNum(p) - Gia_ManBoxCiNum(p) - Gia_ManRegBoxNum(p) );
517  fprintf( pTable, "%d ", Gia_ManPoNum(p) - Gia_ManBoxCoNum(p) - Gia_ManRegBoxNum(p) );
518  fprintf( pTable, "%d ", Gia_ManClockDomainNum(p) );
519 
520  fprintf( pTable, " " );
521  fprintf( pTable, "%d ", nLuts );
522  fprintf( pTable, "%d ", LevelMax );
523  fprintf( pTable, "%d ", Gia_ManRegBoxNum(p) );
524  fprintf( pTable, "%d ", Gia_ManNonRegBoxNum(p) );
525  clk = Abc_Clock();
526  }
527  else
528  {
529  fprintf( pTable, " " );
530  fprintf( pTable, "%d ", nLuts );
531  fprintf( pTable, "%d ", LevelMax );
532  fprintf( pTable, "%d ", Gia_ManRegBoxNum(p) );
533  fprintf( pTable, "%d ", Gia_ManNonRegBoxNum(p) );
534  fprintf( pTable, "%.2f", 1.0*(Abc_Clock() - clk)/CLOCKS_PER_SEC );
535  clk = Abc_Clock();
536  }
537  fclose( pTable );
538  }
539 
540 }
541 
542 /**Function*************************************************************
543 
544  Synopsis [Prints mapping statistics.]
545 
546  Description []
547 
548  SideEffects []
549 
550  SeeAlso []
551 
552 ***********************************************************************/
554 {
555  int fVerbose = 0;
556  int nObjToShow = 200;
557  int nNumStr[5] = {0};
558  int i, k, Entry, nEntries, nEntries2, MaxSize = -1;
559  if ( p->vPacking == NULL )
560  return;
561  nEntries = Vec_IntEntry( p->vPacking, 0 );
562  nEntries2 = 0;
563  Vec_IntForEachEntryStart( p->vPacking, Entry, i, 1 )
564  {
565  assert( Entry > 0 && Entry < 4 );
566  nNumStr[Entry]++;
567  i++;
568  if ( fVerbose && nEntries2 < nObjToShow ) Abc_Print( 1, "{ " );
569  for ( k = 0; k < Entry; k++, i++ )
570  if ( fVerbose && nEntries2 < nObjToShow ) Abc_Print( 1, "%d ", Vec_IntEntry(p->vPacking, i) );
571  if ( fVerbose && nEntries2 < nObjToShow ) Abc_Print( 1, "}\n" );
572  i--;
573  nEntries2++;
574  }
575  assert( nEntries == nEntries2 );
576  if ( nNumStr[3] > 0 )
577  MaxSize = 3;
578  else if ( nNumStr[2] > 0 )
579  MaxSize = 2;
580  else if ( nNumStr[1] > 0 )
581  MaxSize = 1;
582  Abc_Print( 1, "Packing (N=%d) : ", MaxSize );
583  for ( i = 1; i <= MaxSize; i++ )
584  Abc_Print( 1, "%d x LUT = %d ", i, nNumStr[i] );
585  Abc_Print( 1, "Total = %d", nEntries2 );
586  Abc_Print( 1, "\n" );
587 }
588 
589 /**Function*************************************************************
590 
591  Synopsis []
592 
593  Description []
594 
595  SideEffects []
596 
597  SeeAlso []
598 
599 ***********************************************************************/
600 void Gia_ManPrintNodeProfile( int * pCounts, int nSizeMax )
601 {
602  int i, SizeAll = 0, NodeAll = 0;
603  for ( i = 0; i <= nSizeMax; i++ )
604  {
605  SizeAll += i * pCounts[i];
606  NodeAll += pCounts[i];
607  }
608  Abc_Print( 1, "LUT = %d : ", NodeAll );
609  for ( i = 2; i <= nSizeMax; i++ )
610  Abc_Print( 1, "%d=%d %.1f %% ", i, pCounts[i], 100.0*pCounts[i]/NodeAll );
611  Abc_Print( 1, "Ave = %.2f\n", 1.0*SizeAll/(NodeAll ? NodeAll : 1) );
612 }
614 {
615  int i, nSizeMax, pCounts[33] = {0};
616  nSizeMax = Gia_ManLutSizeMax( p );
617  if ( nSizeMax > 32 )
618  {
619  Abc_Print( 1, "The max LUT size (%d) is too large.\n", nSizeMax );
620  return;
621  }
622  Gia_ManForEachLut( p, i )
623  pCounts[ Gia_ObjLutSize(p, i) ]++;
624  Gia_ManPrintNodeProfile( pCounts, nSizeMax );
625 }
626 
627 /**Function*************************************************************
628 
629  Synopsis [Computes levels for AIG with choices and white boxes.]
630 
631  Description []
632 
633  SideEffects []
634 
635  SeeAlso []
636 
637 ***********************************************************************/
639 {
640  Tim_Man_t * pManTime = (Tim_Man_t *)p->pManTime;
641  Gia_Obj_t * pNext;
642  int i, iBox, iTerm1, nTerms, LevelMax = 0;
643  if ( Gia_ObjIsTravIdCurrent( p, pObj ) )
644  return;
645  Gia_ObjSetTravIdCurrent( p, pObj );
646  if ( Gia_ObjIsCi(pObj) )
647  {
648  if ( pManTime )
649  {
650  iBox = Tim_ManBoxForCi( pManTime, Gia_ObjCioId(pObj) );
651  if ( iBox >= 0 ) // this is not a true PI
652  {
653  iTerm1 = Tim_ManBoxInputFirst( pManTime, iBox );
654  nTerms = Tim_ManBoxInputNum( pManTime, iBox );
655  for ( i = 0; i < nTerms; i++ )
656  {
657  pNext = Gia_ManCo( p, iTerm1 + i );
658  Gia_ManChoiceLevel_rec( p, pNext );
659  if ( LevelMax < Gia_ObjLevel(p, pNext) )
660  LevelMax = Gia_ObjLevel(p, pNext);
661  }
662  LevelMax++;
663  }
664  }
665 // Abc_Print( 1, "%d ", pObj->Level );
666  }
667  else if ( Gia_ObjIsCo(pObj) )
668  {
669  pNext = Gia_ObjFanin0(pObj);
670  Gia_ManChoiceLevel_rec( p, pNext );
671  if ( LevelMax < Gia_ObjLevel(p, pNext) )
672  LevelMax = Gia_ObjLevel(p, pNext);
673  }
674  else if ( Gia_ObjIsAnd(pObj) )
675  {
676  // get the maximum level of the two fanins
677  pNext = Gia_ObjFanin0(pObj);
678  Gia_ManChoiceLevel_rec( p, pNext );
679  if ( LevelMax < Gia_ObjLevel(p, pNext) )
680  LevelMax = Gia_ObjLevel(p, pNext);
681  pNext = Gia_ObjFanin1(pObj);
682  Gia_ManChoiceLevel_rec( p, pNext );
683  if ( LevelMax < Gia_ObjLevel(p, pNext) )
684  LevelMax = Gia_ObjLevel(p, pNext);
685  LevelMax++;
686 
687  // get the level of the nodes in the choice node
688  if ( (pNext = Gia_ObjSiblObj(p, Gia_ObjId(p, pObj))) )
689  {
690  Gia_ManChoiceLevel_rec( p, pNext );
691  if ( LevelMax < Gia_ObjLevel(p, pNext) )
692  LevelMax = Gia_ObjLevel(p, pNext);
693  }
694  }
695  else if ( !Gia_ObjIsConst0(pObj) )
696  assert( 0 );
697  Gia_ObjSetLevel( p, pObj, LevelMax );
698 }
700 {
701  Gia_Obj_t * pObj;
702  int i, LevelMax = 0;
703 // assert( Gia_ManRegNum(p) == 0 );
706  Gia_ManForEachCo( p, pObj, i )
707  {
708  Gia_ManChoiceLevel_rec( p, pObj );
709  if ( LevelMax < Gia_ObjLevel(p, pObj) )
710  LevelMax = Gia_ObjLevel(p, pObj);
711  }
712  // account for dangling boxes
713  Gia_ManForEachCi( p, pObj, i )
714  {
715  Gia_ManChoiceLevel_rec( p, pObj );
716  if ( LevelMax < Gia_ObjLevel(p, pObj) )
717  LevelMax = Gia_ObjLevel(p, pObj);
718 // Abc_Print( 1, "%d ", Gia_ObjLevel(p, pObj) );
719  }
720 // Abc_Print( 1, "\n" );
721  Gia_ManForEachAnd( p, pObj, i )
722  assert( Gia_ObjLevel(p, pObj) > 0 );
723 // printf( "Max level %d\n", LevelMax );
724  return LevelMax;
725 }
726 
727 
728 
729 /**Function*************************************************************
730 
731  Synopsis [Converts GIA into IF manager.]
732 
733  Description []
734 
735  SideEffects []
736 
737  SeeAlso []
738 
739 ***********************************************************************/
740 static inline If_Obj_t * If_ManFanin0Copy( If_Man_t * pIfMan, Gia_Obj_t * pObj ) { return If_NotCond( If_ManObj(pIfMan, Gia_ObjValue(Gia_ObjFanin0(pObj))), Gia_ObjFaninC0(pObj) ); }
741 static inline If_Obj_t * If_ManFanin1Copy( If_Man_t * pIfMan, Gia_Obj_t * pObj ) { return If_NotCond( If_ManObj(pIfMan, Gia_ObjValue(Gia_ObjFanin1(pObj))), Gia_ObjFaninC1(pObj) ); }
743 {
744  If_Man_t * pIfMan;
745  If_Obj_t * pIfObj;
746  Gia_Obj_t * pObj;
747  int i;
748  // create levels with choices
749  Gia_ManChoiceLevel( p );
750  // mark representative nodes
751  if ( Gia_ManHasChoices(p) )
753  // start the mapping manager and set its parameters
754  pIfMan = If_ManStart( pPars );
755  pIfMan->pName = Abc_UtilStrsav( Gia_ManName(p) );
756  // print warning about excessive memory usage
757  if ( 1.0 * Gia_ManObjNum(p) * pIfMan->nObjBytes / (1<<30) > 1.0 )
758  printf( "Warning: The mapper will allocate %.1f GB for to represent the subject graph with %d AIG nodes.\n",
759  1.0 * Gia_ManObjNum(p) * pIfMan->nObjBytes / (1<<30), Gia_ManObjNum(p) );
760  // load the AIG into the mapper
761  Gia_ManFillValue( p );
762  Gia_ManConst0(p)->Value = If_ObjId( If_ManConst1(pIfMan) );
763  Gia_ManForEachObj1( p, pObj, i )
764  {
765  if ( Gia_ObjIsAnd(pObj) )
766  pIfObj = If_ManCreateAnd( pIfMan, If_ManFanin0Copy(pIfMan, pObj), If_ManFanin1Copy(pIfMan, pObj) );
767  else if ( Gia_ObjIsCi(pObj) )
768  {
769  pIfObj = If_ManCreateCi( pIfMan );
770  If_ObjSetLevel( pIfObj, Gia_ObjLevel(p, pObj) );
771 // Abc_Print( 1, "pi%d=%d\n ", If_ObjId(pIfObj), If_ObjLevel(pIfObj) );
772  if ( pIfMan->nLevelMax < (int)pIfObj->Level )
773  pIfMan->nLevelMax = (int)pIfObj->Level;
774  }
775  else if ( Gia_ObjIsCo(pObj) )
776  {
777  pIfObj = If_ManCreateCo( pIfMan, If_NotCond( If_ManFanin0Copy(pIfMan, pObj), Gia_ObjIsConst0(Gia_ObjFanin0(pObj))) );
778 // Abc_Print( 1, "po%d=%d\n ", If_ObjId(pIfObj), If_ObjLevel(pIfObj) );
779  }
780  else assert( 0 );
781  assert( i == If_ObjId(pIfObj) );
782  Gia_ObjSetValue( pObj, If_ObjId(pIfObj) );
783  // set up the choice node
784  if ( Gia_ObjSibl(p, i) && pObj->fMark0 )
785  {
786  Gia_Obj_t * pSibl, * pPrev;
787  for ( pPrev = pObj, pSibl = Gia_ObjSiblObj(p, i); pSibl; pPrev = pSibl, pSibl = Gia_ObjSiblObj(p, Gia_ObjId(p, pSibl)) )
788  If_ObjSetChoice( If_ManObj(pIfMan, Gia_ObjValue(pPrev)), If_ManObj(pIfMan, Gia_ObjValue(pSibl)) );
789  If_ManCreateChoice( pIfMan, If_ManObj(pIfMan, Gia_ObjValue(pObj)) );
790  pPars->fExpRed = 0;
791  }
792 // assert( If_ObjLevel(pIfObj) == Gia_ObjLevel(pNode) );
793  }
794  if ( Gia_ManHasChoices(p) )
795  Gia_ManCleanMark0( p );
796  return pIfMan;
797 }
798 
799 /**Function*************************************************************
800 
801  Synopsis [Rebuilds GIA from mini AIG.]
802 
803  Description []
804 
805  SideEffects []
806 
807  SeeAlso []
808 
809 ***********************************************************************/
810 int Gia_ManBuildFromMiniInt( Gia_Man_t * pNew, Vec_Int_t * vLeaves, Vec_Int_t * vAig, int fHash )
811 {
812  assert( Vec_IntSize(vAig) > 0 );
813  assert( Vec_IntEntryLast(vAig) < 2 );
814  if ( Vec_IntSize(vAig) == 1 ) // const
815  return Vec_IntEntry(vAig, 0);
816  if ( Vec_IntSize(vAig) == 2 ) // variable
817  {
818  assert( Vec_IntEntry(vAig, 0) == 0 );
819  assert( Vec_IntSize(vLeaves) == 1 );
820  return Abc_LitNotCond( Vec_IntEntry(vLeaves, 0), Vec_IntEntry(vAig, 1) );
821  }
822  else
823  {
824  int nLeaves = Vec_IntSize(vLeaves);
825  int i, iVar0, iVar1, iLit0, iLit1, iLit = 0;
826  assert( Vec_IntSize(vAig) & 1 );
827  Vec_IntForEachEntryDouble( vAig, iLit0, iLit1, i )
828  {
829  iVar0 = Abc_Lit2Var( iLit0 );
830  iVar1 = Abc_Lit2Var( iLit1 );
831  iLit0 = Abc_LitNotCond( iVar0 < nLeaves ? Vec_IntEntry(vLeaves, iVar0) : Vec_IntEntry(vAig, iVar0 - nLeaves), Abc_LitIsCompl(iLit0) );
832  iLit1 = Abc_LitNotCond( iVar1 < nLeaves ? Vec_IntEntry(vLeaves, iVar1) : Vec_IntEntry(vAig, iVar1 - nLeaves), Abc_LitIsCompl(iLit1) );
833  if ( fHash )
834  iLit = Gia_ManHashAnd( pNew, iLit0, iLit1 );
835  else if ( iLit0 == iLit1 )
836  iLit = iLit0;
837  else
838  iLit = Gia_ManAppendAnd( pNew, iLit0, iLit1 );
839  assert( (i & 1) == 0 );
840  Vec_IntWriteEntry( vAig, Abc_Lit2Var(i), iLit ); // overwriting entries
841  }
842  assert( i == Vec_IntSize(vAig) - 1 );
843  iLit = Abc_LitNotCond( iLit, Vec_IntEntry(vAig, i) );
844  Vec_IntClear( vAig ); // useless
845  return iLit;
846  }
847 }
848 int Gia_ManBuildFromMini( Gia_Man_t * pNew, If_Man_t * pIfMan, If_Cut_t * pCut, Vec_Int_t * vLeaves, Vec_Int_t * vAig, int fHash, int fUseDsd )
849 {
850  if ( fUseDsd )
851  If_CutDsdBalanceEval( pIfMan, pCut, vAig );
852  else
853  If_CutSopBalanceEval( pIfMan, pCut, vAig );
854  return Gia_ManBuildFromMiniInt( pNew, vLeaves, vAig, fHash );
855 }
856 
857 /**Function*************************************************************
858 
859  Synopsis [Converts IF into GIA manager.]
860 
861  Description []
862 
863  SideEffects []
864 
865  SeeAlso []
866 
867 ***********************************************************************/
868 int Gia_ManFromIfAig_rec( Gia_Man_t * pNew, If_Man_t * pIfMan, If_Obj_t * pIfObj )
869 {
870  int iLit0, iLit1;
871  if ( pIfObj->iCopy )
872  return pIfObj->iCopy;
873  iLit0 = Gia_ManFromIfAig_rec( pNew, pIfMan, pIfObj->pFanin0 );
874  iLit1 = Gia_ManFromIfAig_rec( pNew, pIfMan, pIfObj->pFanin1 );
875  iLit0 = Abc_LitNotCond( iLit0, pIfObj->fCompl0 );
876  iLit1 = Abc_LitNotCond( iLit1, pIfObj->fCompl1 );
877  pIfObj->iCopy = Gia_ManHashAnd( pNew, iLit0, iLit1 );
878  return pIfObj->iCopy;
879 }
881 {
882  int fHash = 0;
883  Gia_Man_t * pNew, * pTemp;
884  If_Obj_t * pIfObj, * pIfLeaf;
885  If_Cut_t * pCutBest;
886  Vec_Int_t * vLeaves;
887  Vec_Int_t * vAig;
888  int i, k;
889  assert( pIfMan->pPars->pLutStruct == NULL );
890  assert( pIfMan->pPars->fDelayOpt || pIfMan->pPars->fDsdBalance || pIfMan->pPars->fUserRecLib );
891  // create new manager
892  pNew = Gia_ManStart( If_ManObjNum(pIfMan) );
893  Gia_ManHashAlloc( pNew );
894  // iterate through nodes used in the mapping
895  vAig = Vec_IntAlloc( 1 << 16 );
896  vLeaves = Vec_IntAlloc( 16 );
897 // If_ManForEachObj( pIfMan, pIfObj, i )
898 // pIfObj->iCopy = 0;
899  If_ManForEachObj( pIfMan, pIfObj, i )
900  {
901  if ( pIfObj->nRefs == 0 && !If_ObjIsTerm(pIfObj) )
902  continue;
903  if ( If_ObjIsAnd(pIfObj) )
904  {
905  pCutBest = If_ObjCutBest( pIfObj );
906  // if the cut does not offer delay improvement
907 // if ( (int)pIfObj->Level <= (int)pCutBest->Delay )
908 // {
909 // Gia_ManFromIfAig_rec( pNew, pIfMan, pIfObj );
910 // continue;
911 // }
912  // collect leaves of the best cut
913  Vec_IntClear( vLeaves );
914  If_CutForEachLeaf( pIfMan, pCutBest, pIfLeaf, k )
915  Vec_IntPush( vLeaves, pIfLeaf->iCopy );
916  // get the functionality
917  if ( pIfMan->pPars->fDelayOpt )
918  pIfObj->iCopy = Gia_ManBuildFromMini( pNew, pIfMan, pCutBest, vLeaves, vAig, fHash, 0 );
919  else if ( pIfMan->pPars->fDsdBalance )
920  pIfObj->iCopy = Gia_ManBuildFromMini( pNew, pIfMan, pCutBest, vLeaves, vAig, fHash, 1 );
921  else if ( pIfMan->pPars->fUserRecLib )
922  pIfObj->iCopy = Abc_RecToGia3( pNew, pIfMan, pCutBest, vLeaves, fHash );
923  else assert( 0 );
924  }
925  else if ( If_ObjIsCi(pIfObj) )
926  pIfObj->iCopy = Gia_ManAppendCi(pNew);
927  else if ( If_ObjIsCo(pIfObj) )
928  pIfObj->iCopy = Gia_ManAppendCo( pNew, Abc_LitNotCond(If_ObjFanin0(pIfObj)->iCopy, If_ObjFaninC0(pIfObj)) );
929  else if ( If_ObjIsConst1(pIfObj) )
930  pIfObj->iCopy = 1;
931  else assert( 0 );
932  }
933  Vec_IntFree( vAig );
934  Vec_IntFree( vLeaves );
935  pNew = Gia_ManRehash( pTemp = pNew, 0 );
936  Gia_ManStop( pTemp );
937  return pNew;
938 }
939 
940 
941 /**Function*************************************************************
942 
943  Synopsis [Write mapping for LUT with given fanins.]
944 
945  Description []
946 
947  SideEffects []
948 
949  SeeAlso []
950 
951 ***********************************************************************/
952 int Gia_ManFromIfLogicCreateLut( Gia_Man_t * pNew, word * pRes, Vec_Int_t * vLeaves, Vec_Int_t * vCover, Vec_Int_t * vMapping, Vec_Int_t * vMapping2 )
953 {
954  int i, iLit, iObjLit1;
955  iObjLit1 = Kit_TruthToGia( pNew, (unsigned *)pRes, Vec_IntSize(vLeaves), vCover, vLeaves, 0 );
956  // do not create LUT in the simple case
957  if ( Abc_Lit2Var(iObjLit1) == 0 )
958  return iObjLit1;
959  Vec_IntForEachEntry( vLeaves, iLit, i )
960  if ( Abc_Lit2Var(iObjLit1) == Abc_Lit2Var(iLit) )
961  return iObjLit1;
962  // write mapping
963  Vec_IntSetEntry( vMapping, Abc_Lit2Var(iObjLit1), Vec_IntSize(vMapping2) );
964  Vec_IntPush( vMapping2, Vec_IntSize(vLeaves) );
965 // Vec_IntForEachEntry( vLeaves, iLit, i )
966 // assert( Abc_Lit2Var(iLit) < Abc_Lit2Var(iObjLit1) );
967  Vec_IntForEachEntry( vLeaves, iLit, i )
968  Vec_IntPush( vMapping2, Abc_Lit2Var(iLit) );
969  Vec_IntPush( vMapping2, Abc_Lit2Var(iObjLit1) );
970  return iObjLit1;
971 }
972 
973 /**Function*************************************************************
974 
975  Synopsis [Write mapping for LUT with given fanins.]
976 
977  Description []
978 
979  SideEffects []
980 
981  SeeAlso []
982 
983 ***********************************************************************/
984 int Gia_ManFromIfLogicCreateLutSpecial( Gia_Man_t * pNew, word * pRes, Vec_Int_t * vLeaves, Vec_Int_t * vLeavesTemp, Vec_Int_t * vCover, Vec_Int_t * vMapping, Vec_Int_t * vMapping2, Vec_Int_t * vPacking )
985 {
986  word z = If_CutPerformDerive07( NULL, (unsigned *)pRes, Vec_IntSize(vLeaves), Vec_IntSize(vLeaves), NULL );
987  word Truth;
988  int i, iObjLit1, iObjLit2;
989  // create first LUT
990  Vec_IntClear( vLeavesTemp );
991  for ( i = 0; i < 4; i++ )
992  {
993  int v = (int)((z >> (16+(i<<2))) & 7);
994  if ( v == 6 && Vec_IntSize(vLeaves) == 5 )
995  continue;
996  Vec_IntPush( vLeavesTemp, Vec_IntEntry(vLeaves, v) );
997  }
998  Truth = (z & 0xffff);
999  Truth |= (Truth << 16);
1000  Truth |= (Truth << 32);
1001  iObjLit1 = Gia_ManFromIfLogicCreateLut( pNew, &Truth, vLeavesTemp, vCover, vMapping, vMapping2 );
1002  // create second LUT
1003  Vec_IntClear( vLeavesTemp );
1004  for ( i = 0; i < 4; i++ )
1005  {
1006  int v = (int)((z >> (48+(i<<2))) & 7);
1007  if ( v == 6 && Vec_IntSize(vLeaves) == 5 )
1008  continue;
1009  if ( v == 7 )
1010  Vec_IntPush( vLeavesTemp, iObjLit1 );
1011  else
1012  Vec_IntPush( vLeavesTemp, Vec_IntEntry(vLeaves, v) );
1013  }
1014  Truth = ((z >> 32) & 0xffff);
1015  Truth |= (Truth << 16);
1016  Truth |= (Truth << 32);
1017  iObjLit2 = Gia_ManFromIfLogicCreateLut( pNew, &Truth, vLeavesTemp, vCover, vMapping, vMapping2 );
1018  // write packing
1019  Vec_IntPush( vPacking, 2 );
1020  Vec_IntPush( vPacking, Abc_Lit2Var(iObjLit1) );
1021  Vec_IntPush( vPacking, Abc_Lit2Var(iObjLit2) );
1022  Vec_IntAddToEntry( vPacking, 0, 1 );
1023  return iObjLit2;
1024 }
1025 
1026 /**Function*************************************************************
1027 
1028  Synopsis [Write the node into a file.]
1029 
1030  Description []
1031 
1032  SideEffects []
1033 
1034  SeeAlso []
1035 
1036 ***********************************************************************/
1037 int Gia_ManFromIfLogicNode( void * pIfMan, Gia_Man_t * pNew, int iObj, Vec_Int_t * vLeaves, Vec_Int_t * vLeavesTemp,
1038  word * pRes, char * pStr, Vec_Int_t * vCover, Vec_Int_t * vMapping, Vec_Int_t * vMapping2, Vec_Int_t * vPacking, int fCheck75, int fCheck44e )
1039 {
1040  int nLeaves = Vec_IntSize(vLeaves);
1041  int i, Length, nLutLeaf, nLutLeaf2, nLutRoot, iObjLit1, iObjLit2, iObjLit3;
1042  // workaround for the special case
1043  if ( fCheck75 )
1044  pStr = "54";
1045  // perform special case matching for 44
1046  if ( fCheck44e )
1047  {
1048  if ( Vec_IntSize(vLeaves) <= 4 )
1049  {
1050  // create mapping
1051  iObjLit1 = Gia_ManFromIfLogicCreateLut( pNew, pRes, vLeaves, vCover, vMapping, vMapping2 );
1052  // write packing
1053  if ( !Gia_ObjIsCi(Gia_ManObj(pNew, Abc_Lit2Var(iObjLit1))) && iObjLit1 > 1 )
1054  {
1055  Vec_IntPush( vPacking, 1 );
1056  Vec_IntPush( vPacking, Abc_Lit2Var(iObjLit1) );
1057  Vec_IntAddToEntry( vPacking, 0, 1 );
1058  }
1059  return iObjLit1;
1060  }
1061  return Gia_ManFromIfLogicCreateLutSpecial( pNew, pRes, vLeaves, vLeavesTemp, vCover, vMapping, vMapping2, vPacking );
1062  }
1063  // check if there is no LUT structures
1064  if ( pStr == NULL )
1065  return Gia_ManFromIfLogicCreateLut( pNew, pRes, vLeaves, vCover, vMapping, vMapping2 );
1066  // quit if parameters are wrong
1067  Length = strlen(pStr);
1068  if ( Length != 2 && Length != 3 )
1069  {
1070  printf( "Wrong LUT struct (%s)\n", pStr );
1071  return -1;
1072  }
1073  for ( i = 0; i < Length; i++ )
1074  if ( pStr[i] - '0' < 3 || pStr[i] - '0' > 6 )
1075  {
1076  printf( "The LUT size (%d) should belong to {3,4,5,6}.\n", pStr[i] - '0' );
1077  return -1;
1078  }
1079 
1080  nLutLeaf = pStr[0] - '0';
1081  nLutLeaf2 = ( Length == 3 ) ? pStr[1] - '0' : 0;
1082  nLutRoot = pStr[Length-1] - '0';
1083  if ( nLeaves > nLutLeaf - 1 + (nLutLeaf2 ? nLutLeaf2 - 1 : 0) + nLutRoot )
1084  {
1085  printf( "The node size (%d) is too large for the LUT structure %s.\n", nLeaves, pStr );
1086  return -1;
1087  }
1088 
1089  // consider easy case
1090  if ( nLeaves <= Abc_MaxInt( nLutLeaf2, Abc_MaxInt(nLutLeaf, nLutRoot) ) )
1091  {
1092  // create mapping
1093  iObjLit1 = Gia_ManFromIfLogicCreateLut( pNew, pRes, vLeaves, vCover, vMapping, vMapping2 );
1094  // write packing
1095  if ( !Gia_ObjIsCi(Gia_ManObj(pNew, Abc_Lit2Var(iObjLit1))) && iObjLit1 > 1 )
1096  {
1097  Vec_IntPush( vPacking, 1 );
1098  Vec_IntPush( vPacking, Abc_Lit2Var(iObjLit1) );
1099  Vec_IntAddToEntry( vPacking, 0, 1 );
1100  }
1101  return iObjLit1;
1102  }
1103  else
1104  {
1105  extern int If_CluMinimumBase( word * t, int * pSupp, int nVarsAll, int * pnVars );
1106 
1107  static word TruthStore[16][1<<10] = {{0}}, * pTruths[16];
1108  word Func0, Func1, Func2;
1109  char pLut0[32], pLut1[32], pLut2[32] = {0};
1110 
1111  if ( TruthStore[0][0] == 0 )
1112  {
1113  static word Truth6[6] = {
1114  0xAAAAAAAAAAAAAAAA,
1115  0xCCCCCCCCCCCCCCCC,
1116  0xF0F0F0F0F0F0F0F0,
1117  0xFF00FF00FF00FF00,
1118  0xFFFF0000FFFF0000,
1119  0xFFFFFFFF00000000
1120  };
1121  int nVarsMax = 16;
1122  int nWordsMax = (1 << 10);
1123  int i, k;
1124  assert( nVarsMax <= 16 );
1125  for ( i = 0; i < nVarsMax; i++ )
1126  pTruths[i] = TruthStore[i];
1127  for ( i = 0; i < 6; i++ )
1128  for ( k = 0; k < nWordsMax; k++ )
1129  pTruths[i][k] = Truth6[i];
1130  for ( i = 6; i < nVarsMax; i++ )
1131  for ( k = 0; k < nWordsMax; k++ )
1132  pTruths[i][k] = ((k >> (i-6)) & 1) ? ~(word)0 : 0;
1133  }
1134  // derive truth table
1135  if ( Kit_TruthIsConst0((unsigned *)pRes, nLeaves) || Kit_TruthIsConst1((unsigned *)pRes, nLeaves) )
1136  {
1137 // fprintf( pFile, ".names %s\n %d\n", Abc_ObjName(Abc_ObjFanout0(pObj)), Kit_TruthIsConst1((unsigned *)pRes, nLeaves) );
1138  iObjLit1 = Abc_LitNotCond( 0, Kit_TruthIsConst1((unsigned *)pRes, nLeaves) );
1139  // write mapping
1140  if ( Vec_IntEntry(vMapping, 0) == 0 )
1141  {
1142  Vec_IntSetEntry( vMapping, 0, Vec_IntSize(vMapping2) );
1143  Vec_IntPush( vMapping2, 0 );
1144  Vec_IntPush( vMapping2, 0 );
1145  }
1146  return iObjLit1;
1147  }
1148  // check for elementary truth table
1149  for ( i = 0; i < nLeaves; i++ )
1150  {
1151  if ( Kit_TruthIsEqual((unsigned *)pRes, (unsigned *)pTruths[i], nLeaves) )
1152  return Vec_IntEntry(vLeaves, i);
1153  if ( Kit_TruthIsOpposite((unsigned *)pRes, (unsigned *)pTruths[i], nLeaves) )
1154  return Abc_LitNot(Vec_IntEntry(vLeaves, i));
1155  }
1156 
1157  // perform decomposition
1158  if ( fCheck75 )
1159  {
1160 // if ( nLeaves < 8 && If_CutPerformCheck16( p, (unsigned *)pTruth, nVars, nLeaves, "44" ) )
1161  if ( nLeaves < 8 && If_CluCheckExt( NULL, pRes, nLeaves, 4, 4, pLut0, pLut1, &Func0, &Func1 ) )
1162  {
1163  nLutLeaf = 4;
1164  nLutRoot = 4;
1165  }
1166 // if ( If_CutPerformCheck45( p, (unsigned *)pTruth, nVars, nLeaves, pStr ) )
1167  else if ( If_CluCheckExt( NULL, pRes, nLeaves, 5, 4, pLut0, pLut1, &Func0, &Func1 ) )
1168  {
1169  nLutLeaf = 5;
1170  nLutRoot = 4;
1171  }
1172 // if ( If_CutPerformCheck54( p, (unsigned *)pTruth, nVars, nLeaves, pStr ) )
1173  else if ( If_CluCheckExt( NULL, pRes, nLeaves, 4, 5, pLut0, pLut1, &Func0, &Func1 ) )
1174  {
1175  nLutLeaf = 4;
1176  nLutRoot = 5;
1177  }
1178  else
1179  {
1180  Extra_PrintHex( stdout, (unsigned *)pRes, nLeaves ); printf( " " );
1181  Kit_DsdPrintFromTruth( (unsigned*)pRes, nLeaves ); printf( "\n" );
1182  printf( "Node %d is not decomposable. Deriving LUT structures has failed.\n", iObj );
1183  return -1;
1184  }
1185  }
1186  else
1187  {
1188  if ( Length == 2 )
1189  {
1190  if ( !If_CluCheckExt( NULL, pRes, nLeaves, nLutLeaf, nLutRoot, pLut0, pLut1, &Func0, &Func1 ) )
1191  {
1192  Extra_PrintHex( stdout, (unsigned *)pRes, nLeaves ); printf( " " );
1193  Kit_DsdPrintFromTruth( (unsigned*)pRes, nLeaves ); printf( "\n" );
1194  printf( "Node %d is not decomposable. Deriving LUT structures has failed.\n", iObj );
1195  return -1;
1196  }
1197  }
1198  else
1199  {
1200  if ( !If_CluCheckExt3( pIfMan, pRes, nLeaves, nLutLeaf, nLutLeaf2, nLutRoot, pLut0, pLut1, pLut2, &Func0, &Func1, &Func2 ) )
1201  {
1202  Extra_PrintHex( stdout, (unsigned *)pRes, nLeaves ); printf( " " );
1203  Kit_DsdPrintFromTruth( (unsigned*)pRes, nLeaves ); printf( "\n" );
1204  printf( "Node %d is not decomposable. Deriving LUT structures has failed.\n", iObj );
1205  return -1;
1206  }
1207  }
1208  }
1209 
1210 /*
1211  // write leaf node
1212  Id = Abc2_NtkAllocObj( pNew, pLut1[0], Abc2_ObjType(pObj) );
1213  iObjLit1 = Abc_Var2Lit( Id, 0 );
1214  pObjNew = Abc2_NtkObj( pNew, Id );
1215  for ( i = 0; i < pLut1[0]; i++ )
1216  Abc2_ObjSetFaninLit( pObjNew, i, Abc2_ObjFaninCopy(pObj, pLut1[2+i]) );
1217  Abc2_ObjSetTruth( pObjNew, Func1 );
1218 */
1219  // write leaf node
1220  Vec_IntClear( vLeavesTemp );
1221  for ( i = 0; i < pLut1[0]; i++ )
1222  Vec_IntPush( vLeavesTemp, Vec_IntEntry(vLeaves, pLut1[2+i]) );
1223  iObjLit1 = Gia_ManFromIfLogicCreateLut( pNew, &Func1, vLeavesTemp, vCover, vMapping, vMapping2 );
1224 
1225  if ( Length == 3 && pLut2[0] > 0 )
1226  {
1227  /*
1228  Id = Abc2_NtkAllocObj( pNew, pLut2[0], Abc2_ObjType(pObj) );
1229  iObjLit2 = Abc_Var2Lit( Id, 0 );
1230  pObjNew = Abc2_NtkObj( pNew, Id );
1231  for ( i = 0; i < pLut2[0]; i++ )
1232  if ( pLut2[2+i] == nLeaves )
1233  Abc2_ObjSetFaninLit( pObjNew, i, iObjLit1 );
1234  else
1235  Abc2_ObjSetFaninLit( pObjNew, i, Abc2_ObjFaninCopy(pObj, pLut2[2+i]) );
1236  Abc2_ObjSetTruth( pObjNew, Func2 );
1237  */
1238 
1239  // write leaf node
1240  Vec_IntClear( vLeavesTemp );
1241  for ( i = 0; i < pLut2[0]; i++ )
1242  if ( pLut2[2+i] == nLeaves )
1243  Vec_IntPush( vLeavesTemp, iObjLit1 );
1244  else
1245  Vec_IntPush( vLeavesTemp, Vec_IntEntry(vLeaves, pLut2[2+i]) );
1246  iObjLit2 = Gia_ManFromIfLogicCreateLut( pNew, &Func2, vLeavesTemp, vCover, vMapping, vMapping2 );
1247 
1248  // write packing
1249  Vec_IntPush( vPacking, 3 );
1250  Vec_IntPush( vPacking, Abc_Lit2Var(iObjLit1) );
1251  Vec_IntPush( vPacking, Abc_Lit2Var(iObjLit2) );
1252  }
1253  else
1254  {
1255  // write packing
1256  Vec_IntPush( vPacking, 2 );
1257  Vec_IntPush( vPacking, Abc_Lit2Var(iObjLit1) );
1258  iObjLit2 = -1;
1259  }
1260 /*
1261  // write root node
1262  Id = Abc2_NtkAllocObj( pNew, pLut0[0], Abc2_ObjType(pObj) );
1263  iObjLit3 = Abc_Var2Lit( Id, 0 );
1264  pObjNew = Abc2_NtkObj( pNew, Id );
1265  for ( i = 0; i < pLut0[0]; i++ )
1266  if ( pLut0[2+i] == nLeaves )
1267  Abc2_ObjSetFaninLit( pObjNew, i, iObjLit1 );
1268  else if ( pLut0[2+i] == nLeaves+1 )
1269  Abc2_ObjSetFaninLit( pObjNew, i, iObjLit2 );
1270  else
1271  Abc2_ObjSetFaninLit( pObjNew, i, Abc2_ObjFaninCopy(pObj, pLut0[2+i]) );
1272  Abc2_ObjSetTruth( pObjNew, Func0 );
1273  Abc2_ObjSetCopy( pObj, iObjLit3 );
1274 */
1275  // write root node
1276  Vec_IntClear( vLeavesTemp );
1277  for ( i = 0; i < pLut0[0]; i++ )
1278  if ( pLut0[2+i] == nLeaves )
1279  Vec_IntPush( vLeavesTemp, iObjLit1 );
1280  else if ( pLut0[2+i] == nLeaves+1 )
1281  Vec_IntPush( vLeavesTemp, iObjLit2 );
1282  else
1283  Vec_IntPush( vLeavesTemp, Vec_IntEntry(vLeaves, pLut0[2+i]) );
1284  iObjLit3 = Gia_ManFromIfLogicCreateLut( pNew, &Func0, vLeavesTemp, vCover, vMapping, vMapping2 );
1285 
1286  // write packing
1287  Vec_IntPush( vPacking, Abc_Lit2Var(iObjLit3) );
1288  Vec_IntAddToEntry( vPacking, 0, 1 );
1289  }
1290  return iObjLit3;
1291 }
1292 
1293 /**Function*************************************************************
1294 
1295  Synopsis [Recursively derives the local AIG for the cut.]
1296 
1297  Description []
1298 
1299  SideEffects []
1300 
1301  SeeAlso []
1302 
1303 ***********************************************************************/
1304 int Gia_ManNodeIfToGia_rec( Gia_Man_t * pNew, If_Man_t * pIfMan, If_Obj_t * pIfObj, Vec_Ptr_t * vVisited, int fHash )
1305 {
1306  If_Cut_t * pCut;
1307  If_Obj_t * pTemp;
1308  int iFunc, iFunc0, iFunc1;
1309  // get the best cut
1310  pCut = If_ObjCutBest(pIfObj);
1311  // if the cut is visited, return the result
1312  if ( If_CutDataInt(pCut) )
1313  return If_CutDataInt(pCut);
1314  // mark the node as visited
1315  Vec_PtrPush( vVisited, pCut );
1316  // insert the worst case
1317  If_CutSetDataInt( pCut, ~0 );
1318  // skip in case of primary input
1319  if ( If_ObjIsCi(pIfObj) )
1320  return If_CutDataInt(pCut);
1321  // compute the functions of the children
1322  for ( pTemp = pIfObj; pTemp; pTemp = pTemp->pEquiv )
1323  {
1324  iFunc0 = Gia_ManNodeIfToGia_rec( pNew, pIfMan, pTemp->pFanin0, vVisited, fHash );
1325  if ( iFunc0 == ~0 )
1326  continue;
1327  iFunc1 = Gia_ManNodeIfToGia_rec( pNew, pIfMan, pTemp->pFanin1, vVisited, fHash );
1328  if ( iFunc1 == ~0 )
1329  continue;
1330  // both branches are solved
1331  if ( fHash )
1332  iFunc = Gia_ManHashAnd( pNew, Abc_LitNotCond(iFunc0, pTemp->fCompl0), Abc_LitNotCond(iFunc1, pTemp->fCompl1) );
1333  else
1334  iFunc = Gia_ManAppendAnd( pNew, Abc_LitNotCond(iFunc0, pTemp->fCompl0), Abc_LitNotCond(iFunc1, pTemp->fCompl1) );
1335  if ( pTemp->fPhase != pIfObj->fPhase )
1336  iFunc = Abc_LitNot(iFunc);
1337  If_CutSetDataInt( pCut, iFunc );
1338  break;
1339  }
1340  return If_CutDataInt(pCut);
1341 }
1342 int Gia_ManNodeIfToGia( Gia_Man_t * pNew, If_Man_t * pIfMan, If_Obj_t * pIfObj, Vec_Int_t * vLeaves, int fHash )
1343 {
1344  If_Cut_t * pCut;
1345  If_Obj_t * pLeaf;
1346  int i, iRes;
1347  // get the best cut
1348  pCut = If_ObjCutBest(pIfObj);
1349  assert( pCut->nLeaves > 1 );
1350  // set the leaf variables
1351  If_CutForEachLeaf( pIfMan, pCut, pLeaf, i )
1352  If_CutSetDataInt( If_ObjCutBest(pLeaf), Vec_IntEntry(vLeaves, i) );
1353  // recursively compute the function while collecting visited cuts
1354  Vec_PtrClear( pIfMan->vTemp );
1355  iRes = Gia_ManNodeIfToGia_rec( pNew, pIfMan, pIfObj, pIfMan->vTemp, fHash );
1356  if ( iRes == ~0 )
1357  {
1358  Abc_Print( -1, "Gia_ManNodeIfToGia(): Computing local AIG has failed.\n" );
1359  return ~0;
1360  }
1361  // clean the cuts
1362  If_CutForEachLeaf( pIfMan, pCut, pLeaf, i )
1363  If_CutSetDataInt( If_ObjCutBest(pLeaf), 0 );
1364  Vec_PtrForEachEntry( If_Cut_t *, pIfMan->vTemp, pCut, i )
1365  If_CutSetDataInt( pCut, 0 );
1366  return iRes;
1367 }
1368 
1369 /**Function*************************************************************
1370 
1371  Synopsis [Converts IF into GIA manager.]
1372 
1373  Description []
1374 
1375  SideEffects []
1376 
1377  SeeAlso []
1378 
1379 ***********************************************************************/
1380 int Gia_ManFromIfLogicFindLut( If_Man_t * pIfMan, Gia_Man_t * pNew, If_Cut_t * pCutBest, sat_solver * pSat, Vec_Int_t * vLeaves, Vec_Int_t * vLits, Vec_Int_t * vCover, Vec_Int_t * vMapping, Vec_Int_t * vMapping2, Vec_Int_t * vPacking )
1381 {
1382  word uBound, uFree;
1383  int nLutSize = (int)(pIfMan->pPars->pLutStruct[0] - '0');
1384  int nVarsF = 0, pVarsF[IF_MAX_FUNC_LUTSIZE];
1385  int nVarsB = 0, pVarsB[IF_MAX_FUNC_LUTSIZE];
1386  int nVarsS = 0, pVarsS[IF_MAX_FUNC_LUTSIZE];
1387  unsigned uSetNew, uSetOld;
1388  int RetValue, RetValue2, k;
1389  char * pPerm;
1390  if ( Vec_IntSize(vLeaves) <= nLutSize )
1391  {
1392  RetValue = Gia_ManFromIfLogicCreateLut( pNew, If_CutTruthW(pIfMan, pCutBest), vLeaves, vCover, vMapping, vMapping2 );
1393  // write packing
1394  if ( !Gia_ObjIsCi(Gia_ManObj(pNew, Abc_Lit2Var(RetValue))) && RetValue > 1 )
1395  {
1396  Vec_IntPush( vPacking, 1 );
1397  Vec_IntPush( vPacking, Abc_Lit2Var(RetValue) );
1398  Vec_IntAddToEntry( vPacking, 0, 1 );
1399  }
1400  return RetValue;
1401  }
1402  assert( If_DsdManSuppSize(pIfMan->pIfDsdMan, If_CutDsdLit(pIfMan, pCutBest)) == (int)pCutBest->nLeaves );
1403  // find the bound set
1404  if ( pIfMan->pPars->fDelayOptLut )
1405  uSetOld = pCutBest->uMaskFunc;
1406  else
1407  uSetOld = If_DsdManCheckXY( pIfMan->pIfDsdMan, If_CutDsdLit(pIfMan, pCutBest), nLutSize, 1, 0, 1, 0 );
1408  // remap bound set
1409  uSetNew = 0;
1410  pPerm = If_CutDsdPerm( pIfMan, pCutBest );
1411  for ( k = 0; k < If_CutLeaveNum(pCutBest); k++ )
1412  {
1413  int iVar = Abc_Lit2Var((int)pPerm[k]);
1414  int Value = ((uSetOld >> (k << 1)) & 3);
1415  if ( Value == 1 )
1416  uSetNew |= (1 << (2*iVar));
1417  else if ( Value == 3 )
1418  uSetNew |= (3 << (2*iVar));
1419  else assert( Value == 0 );
1420  }
1421  RetValue = If_ManSatCheckXY( pSat, nLutSize, If_CutTruthW(pIfMan, pCutBest), pCutBest->nLeaves, uSetNew, &uBound, &uFree, vLits );
1422  assert( RetValue );
1423  // collect variables
1424  for ( k = 0; k < If_CutLeaveNum(pCutBest); k++ )
1425  {
1426  int Value = ((uSetNew >> (k << 1)) & 3);
1427  if ( Value == 0 )
1428  pVarsF[nVarsF++] = k;
1429  else if ( Value == 1 )
1430  pVarsB[nVarsB++] = k;
1431  else if ( Value == 3 )
1432  pVarsS[nVarsS++] = k;
1433  else assert( Value == 0 );
1434  }
1435  // collect bound set variables
1436  Vec_IntClear( vLits );
1437  for ( k = 0; k < nVarsS; k++ )
1438  Vec_IntPush( vLits, Vec_IntEntry(vLeaves, pVarsS[k]) );
1439  for ( k = 0; k < nVarsB; k++ )
1440  Vec_IntPush( vLits, Vec_IntEntry(vLeaves, pVarsB[k]) );
1441  RetValue = Gia_ManFromIfLogicCreateLut( pNew, &uBound, vLits, vCover, vMapping, vMapping2 );
1442  // collecct free set variables
1443  Vec_IntClear( vLits );
1444  Vec_IntPush( vLits, RetValue );
1445  for ( k = 0; k < nVarsS; k++ )
1446  Vec_IntPush( vLits, Vec_IntEntry(vLeaves, pVarsS[k]) );
1447  for ( k = 0; k < nVarsF; k++ )
1448  Vec_IntPush( vLits, Vec_IntEntry(vLeaves, pVarsF[k]) );
1449  // add packing
1450  RetValue2 = Gia_ManFromIfLogicCreateLut( pNew, &uFree, vLits, vCover, vMapping, vMapping2 );
1451  // write packing
1452  Vec_IntPush( vPacking, 2 );
1453  Vec_IntPush( vPacking, Abc_Lit2Var(RetValue) );
1454  Vec_IntPush( vPacking, Abc_Lit2Var(RetValue2) );
1455  Vec_IntAddToEntry( vPacking, 0, 1 );
1456  return RetValue2;
1457 }
1458 
1459 /**Function*************************************************************
1460 
1461  Synopsis [Converts IF into GIA manager.]
1462 
1463  Description []
1464 
1465  SideEffects []
1466 
1467  SeeAlso []
1468 
1469 ***********************************************************************/
1470 int Gia_ManFromIfLogicFindCell( If_Man_t * pIfMan, Gia_Man_t * pNew, Gia_Man_t * pTemp, If_Cut_t * pCutBest, sat_solver * pSat, Vec_Int_t * vPiVars, Vec_Int_t * vPoVars, Ifn_Ntk_t * pNtkCell, int nLutMax, Vec_Int_t * vLeaves, Vec_Int_t * vLits, Vec_Int_t * vCover, Vec_Int_t * vMapping, Vec_Int_t * vMapping2, Vec_Int_t * vPacking )
1471 {
1472  int iLit;
1473  if ( Vec_IntSize(vLeaves) <= nLutMax )
1474  iLit = Gia_ManFromIfLogicCreateLut( pNew, If_CutTruthW(pIfMan, pCutBest), vLeaves, vCover, vMapping, vMapping2 );
1475  else
1476  {
1477  Gia_Obj_t * pObj;
1478  int i, Id, iLitTemp;
1479  // extract variable permutation
1480  char * pCutPerm = If_CutDsdPerm( pIfMan, pCutBest ); // DSD input -> cut input
1481  word Perm = If_DsdManGetFuncPerm( pIfMan->pIfDsdMan, If_CutDsdLit(pIfMan, pCutBest) ); // cell input -> DSD input
1482  assert( Perm > 0 );
1483  // (extend storage for configuration bits)
1484  // derive mapping from cell inputs into cut inputs
1485  // retrieve config bits of the LUTs
1486  // perform boolean matching
1487  if ( !If_ManSatFindCofigBits( pSat, vPiVars, vPoVars, If_CutTruthW(pIfMan, pCutBest), Vec_IntSize(vLeaves), Perm, Ifn_NtkInputNum(pNtkCell), vLits ) )
1488  {
1489  printf( "Boolean matching does not exist.\n" );
1490  return -1;
1491  }
1492  // use config bits to generate the network
1493  iLit = If_ManSatDeriveGiaFromBits( pTemp, pNtkCell, vLits, vCover );
1494  // copy GIA back into the manager
1495  Vec_IntFillExtra( &pTemp->vCopies, Gia_ManObjNum(pTemp), -1 );
1496  Gia_ObjSetCopyArray( pTemp, 0, 0 );
1497  Vec_IntForEachEntry( vLeaves, iLitTemp, i )
1498  Gia_ObjSetCopyArray( pTemp, Gia_ManCiIdToId(pTemp, i), iLitTemp );
1499  // collect nodes
1500  Gia_ManIncrementTravId( pTemp );
1501  Id = Abc_Lit2Var( iLit );
1502  Gia_ManCollectAnds( pTemp, &Id, 1, vCover );
1503  Vec_IntPrint( vCover );
1504  Gia_ManForEachObjVec( vCover, pTemp, pObj, i )
1505  Gia_ObjPrint( pTemp, pObj );
1506  // copy GIA
1507  Gia_ManForEachObjVec( vCover, pTemp, pObj, i )
1508  {
1509  iLit = Gia_ManAppendAnd( pNew, Gia_ObjFanin0CopyArray(pTemp, pObj), Gia_ObjFanin1CopyArray(pTemp, pObj) );
1510  Gia_ObjSetCopyArray( pTemp, Gia_ObjId(pTemp, pObj), iLit );
1511  }
1512  iLit = Abc_LitNotCond( Gia_ObjCopyArray(pTemp, Id), Abc_LitIsCompl(iLit) );
1513  }
1514  // write packing
1515  if ( !Gia_ObjIsCi(Gia_ManObj(pNew, Abc_Lit2Var(iLit))) && iLit > 1 )
1516  {
1517  Vec_IntPush( vPacking, 1 );
1518  Vec_IntPush( vPacking, Abc_Lit2Var(iLit) );
1519  Vec_IntAddToEntry( vPacking, 0, 1 );
1520  }
1521  return iLit;
1522 }
1523 
1524 /**Function*************************************************************
1525 
1526  Synopsis [Converts IF into GIA manager.]
1527 
1528  Description []
1529 
1530  SideEffects []
1531 
1532  SeeAlso []
1533 
1534 ***********************************************************************/
1536 {
1537  Gia_Man_t * pNew, * pHashed = NULL;
1538  If_Cut_t * pCutBest;
1539  If_Obj_t * pIfObj, * pIfLeaf;
1540  Vec_Int_t * vMapping, * vMapping2, * vPacking = NULL;
1541  Vec_Int_t * vLeaves, * vLeaves2, * vCover, * vLits;
1542  Vec_Int_t * vPiVars = NULL, * vPoVars = NULL;
1543  sat_solver * pSat = NULL;
1544  Ifn_Ntk_t * pNtkCell = NULL;
1545  int i, k, nLutMax = -1, Entry;
1546  assert( !pIfMan->pPars->fDeriveLuts || pIfMan->pPars->fTruth );
1547 // if ( pIfMan->pPars->fEnableCheck07 )
1548 // pIfMan->pPars->fDeriveLuts = 0;
1549  // start mapping and packing
1550  vMapping = Vec_IntStart( If_ManObjNum(pIfMan) );
1551  vMapping2 = Vec_IntStart( 1 );
1552  if ( pIfMan->pPars->fDeriveLuts && (pIfMan->pPars->pLutStruct || pIfMan->pPars->fEnableCheck75 || pIfMan->pPars->fEnableCheck75u || pIfMan->pPars->fEnableCheck07 || pIfMan->pPars->fUseDsdTune) )
1553  {
1554  vPacking = Vec_IntAlloc( 1000 );
1555  Vec_IntPush( vPacking, 0 );
1556  }
1557  // create new manager
1558  pNew = Gia_ManStart( If_ManObjNum(pIfMan) );
1559  // iterate through nodes used in the mapping
1560  vLits = Vec_IntAlloc( 1000 );
1561  vCover = Vec_IntAlloc( 1 << 16 );
1562  vLeaves = Vec_IntAlloc( 16 );
1563  vLeaves2 = Vec_IntAlloc( 16 );
1564  If_ManCleanCutData( pIfMan );
1565  If_ManForEachObj( pIfMan, pIfObj, i )
1566  {
1567  if ( pIfObj->nRefs == 0 && !If_ObjIsTerm(pIfObj) )
1568  continue;
1569  if ( If_ObjIsAnd(pIfObj) )
1570  {
1571  pCutBest = If_ObjCutBest( pIfObj );
1572  // perform sorting of cut leaves by delay, so that the slowest pin drives the fastest input of the LUT
1573  if ( !pIfMan->pPars->fUseTtPerm && !pIfMan->pPars->fDelayOpt && !pIfMan->pPars->fDelayOptLut && !pIfMan->pPars->fDsdBalance &&
1574  !pIfMan->pPars->pLutStruct && !pIfMan->pPars->fUserRecLib && !pIfMan->pPars->nGateSize && !pIfMan->pPars->fEnableCheck75 &&
1575  !pIfMan->pPars->fEnableCheck75u && !pIfMan->pPars->fEnableCheck07 && !pIfMan->pPars->fUseDsdTune &&
1576  !pIfMan->pPars->fUseCofVars && !pIfMan->pPars->fUseAndVars )
1577  If_CutRotatePins( pIfMan, pCutBest );
1578  // collect leaves of the best cut
1579  Vec_IntClear( vLeaves );
1580  If_CutForEachLeaf( pIfMan, pCutBest, pIfLeaf, k )
1581  Vec_IntPush( vLeaves, pIfLeaf->iCopy );
1582  // perform one of the two types of mapping: with and without structures
1583  if ( pIfMan->pPars->fUseDsd && pIfMan->pPars->pLutStruct )
1584  {
1585  if ( pSat == NULL )
1586  pSat = (sat_solver *)If_ManSatBuildXY( (int)(pIfMan->pPars->pLutStruct[0] - '0') );
1587  if ( pIfMan->pPars->pLutStruct && pIfMan->pPars->fDeriveLuts )
1588  pIfObj->iCopy = Gia_ManFromIfLogicFindLut( pIfMan, pNew, pCutBest, pSat, vLeaves, vLits, vCover, vMapping, vMapping2, vPacking );
1589  else
1590  pIfObj->iCopy = Gia_ManFromIfLogicCreateLut( pNew, If_CutTruthW(pIfMan, pCutBest), vLeaves, vCover, vMapping, vMapping2 );
1591  pIfObj->iCopy = Abc_LitNotCond( pIfObj->iCopy, pCutBest->fCompl );
1592  }
1593  else if ( pIfMan->pPars->fUseDsd && pIfMan->pPars->fUseDsdTune && pIfMan->pPars->fDeriveLuts )
1594  {
1595  if ( pSat == NULL )
1596  {
1597  pSat = (sat_solver *)If_ManSatBuildFromCell( If_DsdManGetCellStr(pIfMan->pIfDsdMan), &vPiVars, &vPoVars, &pNtkCell );
1598  nLutMax = Ifn_NtkLutSizeMax( pNtkCell );
1599  pHashed = Gia_ManStart( 10000 );
1600  Vec_IntFillExtra( &pHashed->vCopies, 10000, -1 );
1601  for ( k = 0; k < pIfMan->pPars->nLutSize; k++ )
1602  Gia_ManAppendCi( pHashed );
1603  Gia_ManHashAlloc( pHashed );
1604  }
1605  pIfObj->iCopy = Gia_ManFromIfLogicFindCell( pIfMan, pNew, pHashed, pCutBest, pSat, vPiVars, vPoVars, pNtkCell, nLutMax, vLeaves, vLits, vCover, vMapping, vMapping2, vPacking );
1606  pIfObj->iCopy = Abc_LitNotCond( pIfObj->iCopy, pCutBest->fCompl );
1607  }
1608  else if ( pIfMan->pPars->fUseCofVars && pIfMan->pPars->fDeriveLuts && (int)pCutBest->nLeaves > pIfMan->pPars->nLutSize/2 )
1609  {
1610  word pTruthCof[128], * pTruth = If_CutTruthW(pIfMan, pCutBest);
1611  int pVarsNew[16], nVarsNew, iLitCofs[3];
1612  int nLeaves = pCutBest->nLeaves;
1613  int nWords = Abc_Truth6WordNum(nLeaves);
1614  int truthId = Abc_Lit2Var(pCutBest->iCutFunc);
1615  int c, iVar = Vec_StrEntry(pIfMan->vTtVars[nLeaves], truthId), iTemp, iTopLit;
1616  assert( iVar >= 0 && iVar < nLeaves && pIfMan->pPars->nLutSize <= 13 );
1617  for ( c = 0; c < 2; c++ )
1618  {
1619  for ( k = 0; k < nLeaves; k++ )
1620  pVarsNew[k] = k;
1621  if ( c )
1622  Abc_TtCofactor1p( pTruthCof, pTruth, nWords, iVar );
1623  else
1624  Abc_TtCofactor0p( pTruthCof, pTruth, nWords, iVar );
1625  nVarsNew = Abc_TtMinBase( pTruthCof, pVarsNew, pCutBest->nLeaves, Abc_MaxInt(6, pCutBest->nLeaves) );
1626  // derive LUT
1627  Vec_IntClear( vLeaves2 );
1628  for ( k = 0; k < nVarsNew; k++ )
1629  Vec_IntPush( vLeaves2, Vec_IntEntry(vLeaves, pVarsNew[k]) );
1630  iLitCofs[c] = Kit_TruthToGia( pNew, (unsigned *)pTruthCof, nVarsNew, vCover, vLeaves2, 0 );
1631  if ( nVarsNew < 2 )
1632  continue;
1633  // create mapping
1634  assert( Gia_ObjIsAnd(Gia_ManObj(pNew, Abc_Lit2Var(iLitCofs[c]))) );
1635  Vec_IntSetEntry( vMapping, Abc_Lit2Var(iLitCofs[c]), Vec_IntSize(vMapping2) );
1636  Vec_IntPush( vMapping2, Vec_IntSize(vLeaves2) );
1637  Vec_IntForEachEntry( vLeaves2, iTemp, k )
1638  Vec_IntPush( vMapping2, Abc_Lit2Var(iTemp) );
1639  Vec_IntPush( vMapping2, Abc_Lit2Var(iLitCofs[c]) );
1640  }
1641  iLitCofs[2] = Vec_IntEntry(vLeaves, iVar);
1642  // derive MUX
1643  if ( iLitCofs[0] > 1 && iLitCofs[1] > 1 )
1644  {
1645  pTruthCof[0] = ABC_CONST(0xCACACACACACACACA);
1646  Vec_IntClear( vLeaves2 );
1647  Vec_IntPush( vLeaves2, iLitCofs[0] );
1648  Vec_IntPush( vLeaves2, iLitCofs[1] );
1649  Vec_IntPush( vLeaves2, iLitCofs[2] );
1650  pIfObj->iCopy = Kit_TruthToGia( pNew, (unsigned *)pTruthCof, Vec_IntSize(vLeaves2), vCover, vLeaves2, 0 );
1651  iTopLit = pIfObj->iCopy;
1652  }
1653  else
1654  {
1655  assert( iLitCofs[0] > 1 || iLitCofs[1] > 1 );
1656  // collect leaves
1657  Vec_IntClear( vLeaves2 );
1658  for ( k = 0; k < 3; k++ )
1659  if ( iLitCofs[k] > 1 )
1660  Vec_IntPush( vLeaves2, iLitCofs[k] );
1661  assert( Vec_IntSize(vLeaves2) == 2 );
1662  // consider three possibilities
1663  if ( iLitCofs[0] == 0 )
1664  pIfObj->iCopy = Gia_ManAppendAnd( pNew, iLitCofs[2], iLitCofs[1] );
1665  else if ( iLitCofs[0] == 1 )
1666  pIfObj->iCopy = Gia_ManAppendOr( pNew, Abc_LitNot(iLitCofs[2]), iLitCofs[1] );
1667  else if ( iLitCofs[1] == 0 )
1668  pIfObj->iCopy = Gia_ManAppendAnd( pNew, Abc_LitNot(iLitCofs[2]), iLitCofs[0] );
1669  else if ( iLitCofs[1] == 1 )
1670  pIfObj->iCopy = Gia_ManAppendOr( pNew, iLitCofs[2], iLitCofs[0] );
1671  else assert( 0 );
1672  iTopLit = iLitCofs[2];
1673  }
1674  // create mapping
1675  Vec_IntSetEntry( vMapping, Abc_Lit2Var(pIfObj->iCopy), Vec_IntSize(vMapping2) );
1676  Vec_IntPush( vMapping2, Vec_IntSize(vLeaves2) );
1677  Vec_IntForEachEntry( vLeaves2, iTemp, k )
1678  Vec_IntPush( vMapping2, Abc_Lit2Var(iTemp) );
1679  Vec_IntPush( vMapping2, -Abc_Lit2Var(iTopLit) );
1680  pIfObj->iCopy = Abc_LitNotCond( pIfObj->iCopy, pCutBest->fCompl );
1681  }
1682  else if ( pIfMan->pPars->fUseAndVars && pIfMan->pPars->fDeriveLuts && (int)pCutBest->nLeaves > pIfMan->pPars->nLutSize/2 )
1683  {
1684  assert( 0 );
1685  }
1686  else if ( (pIfMan->pPars->fDeriveLuts && pIfMan->pPars->fTruth) || pIfMan->pPars->fUseDsd || pIfMan->pPars->fUseTtPerm )
1687  {
1688  word * pTruth = If_CutTruthW(pIfMan, pCutBest);
1689  if ( pIfMan->pPars->fUseTtPerm )
1690  for ( k = 0; k < (int)pCutBest->nLeaves; k++ )
1691  if ( If_CutLeafBit(pCutBest, k) )
1692  Abc_TtFlip( pTruth, Abc_TtWordNum(pCutBest->nLeaves), k );
1693  // perform decomposition of the cut
1694  pIfObj->iCopy = Gia_ManFromIfLogicNode( pIfMan, pNew, i, vLeaves, vLeaves2, pTruth, pIfMan->pPars->pLutStruct, vCover, vMapping, vMapping2, vPacking, (pIfMan->pPars->fEnableCheck75 || pIfMan->pPars->fEnableCheck75u), pIfMan->pPars->fEnableCheck07 );
1695  pIfObj->iCopy = Abc_LitNotCond( pIfObj->iCopy, pCutBest->fCompl );
1696  }
1697  else
1698  {
1699  pIfObj->iCopy = Gia_ManNodeIfToGia( pNew, pIfMan, pIfObj, vLeaves, 0 );
1700  // write mapping
1701  Vec_IntSetEntry( vMapping, Abc_Lit2Var(pIfObj->iCopy), Vec_IntSize(vMapping2) );
1702  Vec_IntPush( vMapping2, Vec_IntSize(vLeaves) );
1703  Vec_IntForEachEntry( vLeaves, Entry, k )
1704  assert( Abc_Lit2Var(Entry) < Abc_Lit2Var(pIfObj->iCopy) );
1705  Vec_IntForEachEntry( vLeaves, Entry, k )
1706  Vec_IntPush( vMapping2, Abc_Lit2Var(Entry) );
1707  Vec_IntPush( vMapping2, Abc_Lit2Var(pIfObj->iCopy) );
1708  }
1709  }
1710  else if ( If_ObjIsCi(pIfObj) )
1711  pIfObj->iCopy = Gia_ManAppendCi(pNew);
1712  else if ( If_ObjIsCo(pIfObj) )
1713  pIfObj->iCopy = Gia_ManAppendCo( pNew, Abc_LitNotCond(If_ObjFanin0(pIfObj)->iCopy, If_ObjFaninC0(pIfObj)) );
1714  else if ( If_ObjIsConst1(pIfObj) )
1715  {
1716  pIfObj->iCopy = 1;
1717  // create const LUT
1718  Vec_IntWriteEntry( vMapping, 0, Vec_IntSize(vMapping2) );
1719  Vec_IntPush( vMapping2, 0 );
1720  Vec_IntPush( vMapping2, 0 );
1721  }
1722  else assert( 0 );
1723  }
1724  Vec_IntFree( vLits );
1725  Vec_IntFree( vCover );
1726  Vec_IntFree( vLeaves );
1727  Vec_IntFree( vLeaves2 );
1728  Vec_IntFreeP( &vPiVars );
1729  Vec_IntFreeP( &vPoVars );
1730  if ( pNtkCell )
1731  ABC_FREE( pNtkCell );
1732  if ( pSat )
1733  sat_solver_delete(pSat);
1734  if ( pHashed )
1735  Gia_ManStop( pHashed );
1736 // printf( "Mapping array size: IfMan = %d. Gia = %d. Increase = %.2f\n",
1737 // If_ManObjNum(pIfMan), Gia_ManObjNum(pNew), 1.0 * Gia_ManObjNum(pNew) / If_ManObjNum(pIfMan) );
1738  // finish mapping
1739  if ( Vec_IntSize(vMapping) > Gia_ManObjNum(pNew) )
1740  Vec_IntShrink( vMapping, Gia_ManObjNum(pNew) );
1741  else
1742  Vec_IntFillExtra( vMapping, Gia_ManObjNum(pNew), 0 );
1743  assert( Vec_IntSize(vMapping) == Gia_ManObjNum(pNew) );
1744  Vec_IntForEachEntry( vMapping, Entry, i )
1745  if ( Entry > 0 )
1746  Vec_IntAddToEntry( vMapping, i, Gia_ManObjNum(pNew) );
1747  Vec_IntAppend( vMapping, vMapping2 );
1748  Vec_IntFree( vMapping2 );
1749  // attach mapping and packing
1750  assert( pNew->vMapping == NULL );
1751  assert( pNew->vPacking == NULL );
1752  pNew->vMapping = vMapping;
1753  pNew->vPacking = vPacking;
1754  // verify that COs have mapping
1755  {
1756  Gia_Obj_t * pObj;
1757  Gia_ManForEachCo( pNew, pObj, i )
1758  assert( !Gia_ObjIsAnd(Gia_ObjFanin0(pObj)) || Gia_ObjIsLut(pNew, Gia_ObjFaninId0p(pNew, pObj)) );
1759  }
1760  // verify that internal nodes have mapping
1761  {
1762  Gia_Obj_t * pFanin;
1763  Gia_ManForEachLut( pNew, i )
1764  Gia_LutForEachFaninObj( pNew, i, pFanin, k )
1765  assert( !Gia_ObjIsAnd(pFanin) || Gia_ObjIsLut(pNew, Gia_ObjId(pNew, pFanin)) );
1766  }
1767  // verify that CIs have no mapping
1768  {
1769  Gia_Obj_t * pObj;
1770  Gia_ManForEachCi( pNew, pObj, i )
1771  assert( !Gia_ObjIsLut(pNew, Gia_ObjId(pNew, pObj)) );
1772  }
1773  return pNew;
1774 }
1775 
1776 
1777 /**Function*************************************************************
1778 
1779  Synopsis [Verifies mapping.]
1780 
1781  Description []
1782 
1783  SideEffects []
1784 
1785  SeeAlso []
1786 
1787 ***********************************************************************/
1789 {
1790  int Id, iFan, k, Result = 1;
1791  if ( Gia_ObjIsTravIdCurrent(p, pObj) )
1792  return 1;
1793  Gia_ObjSetTravIdCurrent(p, pObj);
1794  if ( !Gia_ObjIsAndNotBuf(pObj) )
1795  return 1;
1796  if ( !Gia_ObjIsLut(p, Gia_ObjId(p, pObj)) )
1797  {
1798  Abc_Print( -1, "Gia_ManMappingVerify: Internal node %d does not have mapping.\n", Gia_ObjId(p, pObj) );
1799  return 0;
1800  }
1801  Id = Gia_ObjId(p, pObj);
1802  Gia_LutForEachFanin( p, Id, iFan, k )
1803  if ( Result )
1804  Result &= Gia_ManMappingVerify_rec( p, Gia_ManObj(p, iFan) );
1805  return Result;
1806 }
1808 {
1809  Gia_Obj_t * pObj, * pFanin;
1810  int i, Result = 1;
1811  assert( Gia_ManHasMapping(p) );
1813  Gia_ManForEachBuf( p, pObj, i )
1814  {
1815  pFanin = Gia_ObjFanin0(pObj);
1816  if ( !Gia_ObjIsAndNotBuf(pFanin) )
1817  continue;
1818  if ( !Gia_ObjIsLut(p, Gia_ObjId(p, pFanin)) )
1819  {
1820  Abc_Print( -1, "Gia_ManMappingVerify: CO driver %d does not have mapping.\n", Gia_ObjId(p, pFanin) );
1821  Result = 0;
1822  continue;
1823  }
1824  Result &= Gia_ManMappingVerify_rec( p, pFanin );
1825  }
1826  Gia_ManForEachCo( p, pObj, i )
1827  {
1828  pFanin = Gia_ObjFanin0(pObj);
1829  if ( !Gia_ObjIsAndNotBuf(pFanin) )
1830  continue;
1831  if ( !Gia_ObjIsLut(p, Gia_ObjId(p, pFanin)) )
1832  {
1833  Abc_Print( -1, "Gia_ManMappingVerify: CO driver %d does not have mapping.\n", Gia_ObjId(p, pFanin) );
1834  Result = 0;
1835  continue;
1836  }
1837  Result &= Gia_ManMappingVerify_rec( p, pFanin );
1838  }
1839 // if ( Result && Gia_NtkIsRoot(p) )
1840 // Abc_Print( 1, "Mapping verified correctly.\n" );
1841 }
1842 
1843 
1844 /**Function*************************************************************
1845 
1846  Synopsis [Transfers mapping from hie GIA to normalized GIA.]
1847 
1848  Description [Hie GIA (pGia) points to normalized GIA (p).]
1849 
1850  SideEffects []
1851 
1852  SeeAlso []
1853 
1854 ***********************************************************************/
1856 {
1857  Gia_Obj_t * pObj;
1858  int i, k, iFan;
1859  if ( !Gia_ManHasMapping(pGia) )
1860  return;
1861  Gia_ManMappingVerify( pGia );
1862  Vec_IntFreeP( &p->vMapping );
1863  p->vMapping = Vec_IntAlloc( 2 * Gia_ManObjNum(p) );
1864  Vec_IntFill( p->vMapping, Gia_ManObjNum(p), 0 );
1865  Gia_ManForEachLut( pGia, i )
1866  {
1868  pObj = Gia_ManObj( p, Abc_Lit2Var(Gia_ObjValue(Gia_ManObj(pGia, i))) );
1870  Vec_IntPush( p->vMapping, Gia_ObjLutSize(pGia, i) );
1871  Gia_LutForEachFanin( pGia, i, iFan, k )
1873  iFan = Abc_Lit2Var( Gia_ObjValue(Gia_ManObj(pGia, Abc_AbsInt(Gia_ObjLutMuxId(pGia, i)))) );
1874  Vec_IntPush( p->vMapping, Gia_ObjLutIsMux(pGia, i) ? -iFan : iFan );
1875  }
1876  Gia_ManMappingVerify( p );
1877 }
1879 {
1880  Vec_Int_t * vPackingNew;
1881  Gia_Obj_t * pObj, * pObjNew;
1882  int i, k, Entry, nEntries, nEntries2;
1883  if ( pGia->vPacking == NULL )
1884  return;
1885  nEntries = Vec_IntEntry( pGia->vPacking, 0 );
1886  nEntries2 = 0;
1887  // create new packing info
1888  vPackingNew = Vec_IntAlloc( Vec_IntSize(pGia->vPacking) );
1889  Vec_IntPush( vPackingNew, nEntries );
1890  Vec_IntForEachEntryStart( pGia->vPacking, Entry, i, 1 )
1891  {
1892  assert( Entry > 0 && Entry < 4 );
1893  Vec_IntPush( vPackingNew, Entry );
1894  i++;
1895  for ( k = 0; k < Entry; k++, i++ )
1896  {
1897  pObj = Gia_ManObj(pGia, Vec_IntEntry(pGia->vPacking, i));
1898  pObjNew = Gia_ManObj(p, Abc_Lit2Var(Gia_ObjValue(pObj)));
1899  assert( Gia_ObjIsLut(pGia, Gia_ObjId(pGia, pObj)) );
1900  assert( Gia_ObjIsLut(p, Gia_ObjId(p, pObjNew)) );
1901  Vec_IntPush( vPackingNew, Gia_ObjId(p, pObjNew) );
1902 // printf( "%d -> %d ", Vec_IntEntry(pGia->vPacking, i), Gia_ObjId(p, pObjNew) );
1903  }
1904  i--;
1905  nEntries2++;
1906  }
1907  assert( nEntries == nEntries2 );
1908  // attach packing info
1909  assert( p->vPacking == NULL );
1910  p->vPacking = vPackingNew;
1911 }
1913 {
1914  if ( pGia->pManTime == NULL || p == pGia )
1915  return;
1916  p->pManTime = pGia->pManTime; pGia->pManTime = NULL;
1917  p->pAigExtra = pGia->pAigExtra; pGia->pAigExtra = NULL;
1918  p->vRegClasses = pGia->vRegClasses; pGia->vRegClasses = NULL;
1919  p->nAnd2Delay = pGia->nAnd2Delay; pGia->nAnd2Delay = 0;
1920 }
1921 
1922 /**Function*************************************************************
1923 
1924  Synopsis [Interface of LUT mapping package.]
1925 
1926  Description []
1927 
1928  SideEffects []
1929 
1930  SeeAlso []
1931 
1932 ***********************************************************************/
1934 {
1935  extern void Gia_ManIffTest( Gia_Man_t * pGia, If_LibLut_t * pLib, int fVerbose );
1936  Gia_Man_t * pNew;
1937  If_Man_t * pIfMan;
1938  assert( pPars->pTimesArr == NULL );
1939  assert( pPars->pTimesReq == NULL );
1940  // disable cut minimization when GIA strucure is needed
1941  if ( !pPars->fDelayOpt && !pPars->fDelayOptLut && !pPars->fDsdBalance && !pPars->fUserRecLib && !pPars->fDeriveLuts && !pPars->fUseDsd && !pPars->fUseTtPerm )
1942  pPars->fCutMin = 0;
1943  // translate into the mapper
1944  pIfMan = Gia_ManToIf( p, pPars );
1945  if ( pIfMan == NULL )
1946  return NULL;
1947  // create DSD manager
1948  if ( pPars->fUseDsd )
1949  {
1951  assert( pPars->nLutSize <= If_DsdManVarNum(p) );
1952  assert( (pPars->pLutStruct == NULL && If_DsdManLutSize(p) == 0) || (pPars->pLutStruct && pPars->pLutStruct[0] - '0' == If_DsdManLutSize(p)) );
1953  pIfMan->pIfDsdMan = (If_DsdMan_t *)Abc_FrameReadManDsd();
1954  if ( pPars->fDsdBalance )
1955  If_DsdManAllocIsops( pIfMan->pIfDsdMan, pPars->nLutSize );
1956  }
1957  // compute switching for the IF objects
1958  if ( pPars->fPower )
1959  {
1960  if ( p->pManTime == NULL )
1961  If_ManComputeSwitching( pIfMan );
1962  else
1963  Abc_Print( 0, "Switching activity computation for designs with boxes is disabled.\n" );
1964  }
1965  if ( p->pManTime )
1966  pIfMan->pManTim = Tim_ManDup( (Tim_Man_t *)p->pManTime, pPars->fDelayOpt || pPars->fDelayOptLut || pPars->fDsdBalance || pPars->fUserRecLib );
1967 // Tim_ManPrint( pIfMan->pManTim );
1968  if ( !If_ManPerformMapping( pIfMan ) )
1969  {
1970  If_ManStop( pIfMan );
1971  return NULL;
1972  }
1973  // transform the result of mapping into the new network
1974  if ( pIfMan->pPars->fDelayOpt || pIfMan->pPars->fDsdBalance || pIfMan->pPars->fUserRecLib )
1975  pNew = Gia_ManFromIfAig( pIfMan );
1976  else
1977  pNew = Gia_ManFromIfLogic( pIfMan );
1978  If_ManStop( pIfMan );
1979  // transfer name
1980  assert( pNew->pName == NULL );
1981  pNew->pName = Abc_UtilStrsav( p->pName );
1982  pNew->pSpec = Abc_UtilStrsav( p->pSpec );
1983  Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
1984  return pNew;
1985 }
1987 {
1988  Gia_Man_t * pNew;
1989  if ( p->pManTime && Tim_ManBoxNum(p->pManTime) && Gia_ManIsNormalized(p) )
1990  {
1991  pNew = Gia_ManDupUnnormalize( p );
1992  if ( pNew == NULL )
1993  return NULL;
1994  Gia_ManTransferTiming( pNew, p );
1995  p = pNew;
1996  // mapping
1997  pNew = Gia_ManPerformMappingInt( p, (If_Par_t *)pp );
1998  if ( pNew != p )
1999  {
2000  Gia_ManTransferTiming( pNew, p );
2001  Gia_ManStop( p );
2002  }
2003  // normalize
2004  pNew = Gia_ManDupNormalize( p = pNew );
2005  Gia_ManTransferMapping( pNew, p );
2006  Gia_ManTransferPacking( pNew, p );
2007  Gia_ManTransferTiming( pNew, p );
2008  Gia_ManStop( p );
2009  assert( Gia_ManIsNormalized(pNew) );
2010  }
2011  else
2012  {
2013  // mapping
2014  pNew = Gia_ManPerformMappingInt( p, (If_Par_t *)pp );
2015  Gia_ManTransferTiming( pNew, p );
2016  }
2017  return pNew;
2018 }
2019 
2020 /**Function*************************************************************
2021 
2022  Synopsis [Interface of other mapping-based procedures.]
2023 
2024  Description []
2025 
2026  SideEffects []
2027 
2028  SeeAlso []
2029 
2030 ***********************************************************************/
2031 Gia_Man_t * Gia_ManPerformSopBalance( Gia_Man_t * p, int nCutNum, int nRelaxRatio, int fVerbose )
2032 {
2033  Gia_Man_t * pNew;
2034  If_Man_t * pIfMan;
2035  If_Par_t Pars, * pPars = &Pars;
2036  If_ManSetDefaultPars( pPars );
2037  pPars->nCutsMax = nCutNum;
2038  pPars->nRelaxRatio = nRelaxRatio;
2039  pPars->fVerbose = fVerbose;
2040  pPars->nLutSize = 6;
2041  pPars->fDelayOpt = 1;
2042  pPars->fCutMin = 1;
2043  pPars->fTruth = 1;
2044  pPars->fExpRed = 0;
2045  // perform mapping
2046  pIfMan = Gia_ManToIf( p, pPars );
2047  If_ManPerformMapping( pIfMan );
2048  pNew = Gia_ManFromIfAig( pIfMan );
2049  If_ManStop( pIfMan );
2050  Gia_ManTransferTiming( pNew, p );
2051  // transfer name
2052  assert( pNew->pName == NULL );
2053  pNew->pName = Abc_UtilStrsav( p->pName );
2054  pNew->pSpec = Abc_UtilStrsav( p->pSpec );
2055  Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
2056  return pNew;
2057 }
2058 Gia_Man_t * Gia_ManPerformDsdBalance( Gia_Man_t * p, int nLutSize, int nCutNum, int nRelaxRatio, int fVerbose )
2059 {
2060  Gia_Man_t * pNew;
2061  If_Man_t * pIfMan;
2062  If_Par_t Pars, * pPars = &Pars;
2063  If_ManSetDefaultPars( pPars );
2064  pPars->nCutsMax = nCutNum;
2065  pPars->nRelaxRatio = nRelaxRatio;
2066  pPars->fVerbose = fVerbose;
2067  pPars->nLutSize = nLutSize;
2068  pPars->fDsdBalance = 1;
2069  pPars->fUseDsd = 1;
2070  pPars->fCutMin = 1;
2071  pPars->fTruth = 1;
2072  pPars->fExpRed = 0;
2073  if ( Abc_FrameReadManDsd2() == NULL )
2075  // perform mapping
2076  pIfMan = Gia_ManToIf( p, pPars );
2078  if ( pPars->fDsdBalance )
2079  If_DsdManAllocIsops( pIfMan->pIfDsdMan, pPars->nLutSize );
2080  If_ManPerformMapping( pIfMan );
2081  pNew = Gia_ManFromIfAig( pIfMan );
2082  If_ManStop( pIfMan );
2083  Gia_ManTransferTiming( pNew, p );
2084  // transfer name
2085  assert( pNew->pName == NULL );
2086  pNew->pName = Abc_UtilStrsav( p->pName );
2087  pNew->pSpec = Abc_UtilStrsav( p->pSpec );
2088  Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
2089  return pNew;
2090 }
2091 
2092 /**Function*************************************************************
2093 
2094  Synopsis [Tests decomposition structures.]
2095 
2096  Description []
2097 
2098  SideEffects []
2099 
2100  SeeAlso []
2101 
2102 ***********************************************************************/
2104 {
2105  int nCutMax = 7;
2106  int LutCount[8] = {0}, LutNDecomp[8] = {0};
2107  int i, k, iFan, nFanins, Status;
2108  Vec_Int_t * vLeaves;
2109  word * pTruth;
2110 
2111  vLeaves = Vec_IntAlloc( 100 );
2112  Gia_ObjComputeTruthTableStart( p, nCutMax );
2113  Gia_ManForEachLut( p, i )
2114  {
2115  nFanins = Gia_ObjLutSize(p, i);
2116  assert( nFanins <= 7 );
2117  LutCount[Abc_MaxInt(nFanins, 5)]++;
2118  if ( nFanins <= 5 )
2119  continue;
2120  Vec_IntClear( vLeaves );
2121  Gia_LutForEachFanin( p, i, iFan, k )
2122  Vec_IntPush( vLeaves, iFan );
2123  pTruth = Gia_ObjComputeTruthTableCut( p, Gia_ManObj(p, i), vLeaves );
2124  // check if it is decomposable
2125  Status = If_CutPerformCheck07( NULL, (unsigned *)pTruth, 7, nFanins, NULL );
2126  if ( Status == 1 )
2127  continue;
2128  LutNDecomp[nFanins]++;
2129  if ( LutNDecomp[nFanins] > 10 )
2130  continue;
2131  Kit_DsdPrintFromTruth( (unsigned *)pTruth, nFanins ); printf( "\n" );
2132  }
2134 
2135  printf( "LUT5 = %d ", LutCount[5] );
2136  printf( "LUT6 = %d NonDec = %d (%.2f %%) ", LutCount[6], LutNDecomp[6], 100.0 * LutNDecomp[6]/Abc_MaxInt(LutCount[6], 1) );
2137  printf( "LUT7 = %d NonDec = %d (%.2f %%) ", LutCount[7], LutNDecomp[7], 100.0 * LutNDecomp[7]/Abc_MaxInt(LutCount[7], 1) );
2138  printf( "\n" );
2139 }
2140 
2141 
2142 ////////////////////////////////////////////////////////////////////////
2143 /// END OF FILE ///
2144 ////////////////////////////////////////////////////////////////////////
2145 
2146 
2148 
static ABC_NAMESPACE_IMPL_START int pTruths[13719]
DECLARATIONS ///.
Definition: rwrTemp.c:30
char * memset()
void Gia_ManTransferPacking(Gia_Man_t *p, Gia_Man_t *pGia)
Definition: giaIf.c:1878
If_Obj_t * pFanin0
Definition: if.h:321
void If_CutRotatePins(If_Man_t *p, If_Cut_t *pCut)
Definition: ifTruth.c:67
int Tim_ManBoxForCi(Tim_Man_t *p, int iCo)
Definition: timBox.c:86
If_DsdMan_t * pIfDsdMan
Definition: if.h:243
static int Gia_ManAppendAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition: gia.h:592
int If_CluCheckExt(void *p, word *pTruth, int nVars, int nLutLeaf, int nLutRoot, char *pLut0, char *pLut1, word *pFunc0, word *pFunc1)
Definition: ifDec16.c:2066
unsigned nLeaves
Definition: if.h:289
static If_Obj_t * If_NotCond(If_Obj_t *p, int c)
Definition: if.h:357
Gia_Man_t * Gia_ManPerformSopBalance(Gia_Man_t *p, int nCutNum, int nRelaxRatio, int fVerbose)
Definition: giaIf.c:2031
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
int If_CluCheckExt3(void *p, word *pTruth, int nVars, int nLutLeaf, int nLutLeaf2, int nLutRoot, char *pLut0, char *pLut1, char *pLut2, word *pFunc0, word *pFunc1, word *pFunc2)
Definition: ifDec16.c:2079
static Gia_Obj_t * Gia_ObjSiblObj(Gia_Man_t *p, int Id)
Definition: gia.h:894
static If_Obj_t * If_ManObj(If_Man_t *p, int i)
Definition: if.h:370
Vec_Str_t * vTtVars[IF_MAX_FUNC_LUTSIZE+1]
Definition: if.h:248
static int Abc_TtMinBase(word *pTruth, int *pVars, int nVars, int nVarsAll)
Definition: utilTruth.h:1395
int iCopy
Definition: if.h:329
int nLutSize
Definition: if.h:103
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
int If_ManSatFindCofigBits(void *pSat, Vec_Int_t *vPiVars, Vec_Int_t *vPoVars, word *pTruth, int nVars, word Perm, int nInps, Vec_Int_t *vValues)
Definition: ifTune.c:687
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
int Gia_ManMappingVerify_rec(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: giaIf.c:1788
void Gia_ObjComputeTruthTableStart(Gia_Man_t *p, int nVarsMax)
Definition: giaTruth.c:282
Gia_Man_t * pAigExtra
Definition: gia.h:149
static int If_ObjId(If_Obj_t *pObj)
Definition: if.h:379
static int Gia_ManPoNum(Gia_Man_t *p)
Definition: gia.h:386
void Gia_ManPrintMappingStats(Gia_Man_t *p, char *pDumpFile)
Definition: giaIf.c:423
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
static void Gia_ObjSetValue(Gia_Obj_t *pObj, int i)
Definition: gia.h:414
static int Gia_ManAppendCo(Gia_Man_t *p, int iLit0)
Definition: gia.h:703
int Gia_ManLutLevel(Gia_Man_t *p)
Definition: giaIf.c:163
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Definition: if.h:100
static void Abc_TtCofactor1p(word *pOut, word *pIn, int nWords, int iVar)
Definition: utilTruth.h:403
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 int Abc_AbsInt(int a)
Definition: abc_global.h:237
int Gia_ManRegBoxNum(Gia_Man_t *p)
Definition: giaTim.c:53
Vec_Int_t * vRegClasses
Definition: gia.h:144
word * Gia_ObjComputeTruthTableCut(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vLeaves)
Definition: giaTruth.c:351
Vec_Ptr_t * vTemp
Definition: if.h:191
static If_Obj_t * If_ManFanin1Copy(If_Man_t *pIfMan, Gia_Obj_t *pObj)
Definition: giaIf.c:741
static Gia_Obj_t * Gia_Regular(Gia_Obj_t *p)
Definition: gia.h:377
static int Gia_ObjIsTravIdCurrent(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:533
If_Man_t * If_ManStart(If_Par_t *pPars)
FUNCTION DEFINITIONS ///.
Definition: ifMan.c:50
static char * Gia_ManName(Gia_Man_t *p)
Definition: gia.h:382
unsigned If_DsdManCheckXY(If_DsdMan_t *p, int iDsd, int LutSize, int fDerive, unsigned uMaskNot, int fHighEffort, int fVerbose)
Definition: ifDsd.c:1986
void If_ManSetDefaultPars(If_Par_t *pPars)
FUNCTION DECLARATIONS ///.
Definition: ifCore.c:47
Definition: if.h:303
int Gia_ManFromIfLogicFindCell(If_Man_t *pIfMan, Gia_Man_t *pNew, Gia_Man_t *pTemp, If_Cut_t *pCutBest, sat_solver *pSat, Vec_Int_t *vPiVars, Vec_Int_t *vPoVars, Ifn_Ntk_t *pNtkCell, int nLutMax, Vec_Int_t *vLeaves, Vec_Int_t *vLits, Vec_Int_t *vCover, Vec_Int_t *vMapping, Vec_Int_t *vMapping2, Vec_Int_t *vPacking)
Definition: giaIf.c:1470
static int If_ObjIsAnd(If_Obj_t *pObj)
Definition: if.h:377
Gia_Man_t * Gia_ManFromIfAig(If_Man_t *pIfMan)
Definition: giaIf.c:880
Definition: if.h:275
int fDeriveLuts
Definition: if.h:138
static int Abc_Truth6WordNum(int nVars)
Definition: abc_global.h:257
#define If_CutForEachLeaf(p, pCut, pLeaf, i)
Definition: if.h:474
static int If_ObjIsCo(If_Obj_t *pObj)
Definition: if.h:374
static int If_CutLeaveNum(If_Cut_t *pCut)
Definition: if.h:390
static int Gia_ObjLutMuxId(Gia_Man_t *p, int Id)
Definition: gia.h:956
int fDelayOptLut
Definition: if.h:122
int fVerbose
Definition: if.h:140
static int Gia_ManAppendCi(Gia_Man_t *p)
Definition: gia.h:583
void sat_solver_delete(sat_solver *s)
Definition: satSolver.c:1141
void Gia_ManCleanMark0(Gia_Man_t *p)
Definition: giaUtil.c:215
static int If_ObjFaninC0(If_Obj_t *pObj)
Definition: if.h:382
static int Gia_ObjIsConst0(Gia_Obj_t *pObj)
Definition: gia.h:430
void Gia_ManPrintPackingStats(Gia_Man_t *p)
Definition: giaIf.c:553
void Gia_ObjComputeTruthTableStop(Gia_Man_t *p)
Definition: giaTruth.c:293
char * pLutStruct
Definition: if.h:141
int nLevelMax
Definition: if.h:194
void Gia_ManLutParams(Gia_Man_t *p, int *pnCurLuts, int *pnCurEdges, int *pnCurLevels)
Definition: giaIf.c:195
void Gia_ManTransferTiming(Gia_Man_t *p, Gia_Man_t *pGia)
Definition: giaIf.c:1912
static int Gia_ObjValue(Gia_Obj_t *pObj)
Definition: gia.h:413
static If_Obj_t * If_ObjFanin0(If_Obj_t *pObj)
Definition: if.h:380
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
int Ifn_NtkLutSizeMax(Ifn_Ntk_t *p)
Definition: ifTune.c:159
static void Vec_IntSetEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:418
int Gia_ManComputeOverlapOne(Gia_Man_t *p, int iObj)
Definition: giaIf.c:333
word If_CutPerformDerive07(If_Man_t *p, unsigned *pTruth, int nVars, int nLeaves, char *pStr)
Definition: ifDec07.c:1029
int Gia_ManComputeOverlap2One(Gia_Man_t *p, int iObj, Vec_Str_t *vLabel, Vec_Int_t *vVisit)
Definition: giaIf.c:283
static int If_ObjIsCi(If_Obj_t *pObj)
Definition: if.h:373
static int Kit_TruthIsEqual(unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: kit.h:274
static If_Cut_t * If_ObjCutBest(If_Obj_t *pObj)
Definition: if.h:401
int Abc_RecToGia3(Gia_Man_t *pMan, If_Man_t *pIfMan, If_Cut_t *pCut, Vec_Int_t *vLeaves, int fHash)
Definition: abcRec3.c:1105
int(* pFuncCost)(If_Man_t *, If_Cut_t *)
Definition: if.h:163
static int Kit_TruthIsConst0(unsigned *pIn, int nVars)
Definition: kit.h:315
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition: giaMan.c:628
unsigned fMark1
Definition: gia.h:84
Vec_Int_t * vPacking
Definition: gia.h:133
void Kit_DsdPrintFromTruth(unsigned *pTruth, int nVars)
Definition: kitDsd.c:490
static abctime Abc_Clock()
Definition: abc_global.h:279
int fUseCoAttrs
Definition: if.h:157
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
int Gia_ManFromIfLogicCreateLutSpecial(Gia_Man_t *pNew, word *pRes, Vec_Int_t *vLeaves, Vec_Int_t *vLeavesTemp, Vec_Int_t *vCover, Vec_Int_t *vMapping, Vec_Int_t *vMapping2, Vec_Int_t *vPacking)
Definition: giaIf.c:984
int Gia_ManFromIfLogicCreateLut(Gia_Man_t *pNew, word *pRes, Vec_Int_t *vLeaves, Vec_Int_t *vCover, Vec_Int_t *vMapping, Vec_Int_t *vMapping2)
Definition: giaIf.c:952
int If_CutPerformCheck07(If_Man_t *p, unsigned *pTruth, int nVars, int nLeaves, char *pStr)
Definition: ifDec07.c:1071
int nWords
Definition: abcNpn.c:127
static Gia_Obj_t * Gia_ManObj(Gia_Man_t *p, int v)
Definition: gia.h:402
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
int Gia_ManLutFaninCount(Gia_Man_t *p)
Definition: giaIf.c:106
static void If_ObjSetLevel(If_Obj_t *pObj, int Level)
Definition: if.h:386
int * pRefs
Definition: gia.h:114
Definition: gia.h:75
#define Gia_ManForEachLut(p, i)
Definition: gia.h:968
int nLatchesCi
Definition: if.h:152
int nRefs
Definition: if.h:318
void If_ManComputeSwitching(If_Man_t *pIfMan)
FUNCTION DEFINITIONS ///.
Definition: abcIf.c:58
int fUseCofVars
Definition: if.h:135
int Gia_ManComputeOverlapOne_rec(Gia_Man_t *p, int iObj)
Definition: giaIf.c:322
If_Obj_t * If_ManCreateCo(If_Man_t *p, If_Obj_t *pDriver)
Definition: ifMan.c:338
int Gia_ManFromIfAig_rec(Gia_Man_t *pNew, If_Man_t *pIfMan, If_Obj_t *pIfObj)
Definition: giaIf.c:868
int fExpRed
Definition: if.h:116
static int Gia_ManAppendOr(Gia_Man_t *p, int iLit0, int iLit1)
Definition: gia.h:718
int fEnableCheck75u
Definition: if.h:132
int nFlowIters
Definition: if.h:105
static int Gia_ManHasChoices(Gia_Man_t *p)
Definition: gia.h:397
int Gia_ManComputeOverlap2One_rec(Gia_Man_t *p, int iObj, Vec_Str_t *vLabel, Vec_Int_t *vVisit)
Definition: giaIf.c:269
int Gia_ManComputeOverlap2(Gia_Man_t *p)
Definition: giaIf.c:296
int strcmp()
void If_DsdManAllocIsops(If_DsdMan_t *p, int nLutSize)
Definition: ifDsd.c:289
Tim_Man_t * pManTim
Definition: if.h:263
int nGateSize
Definition: if.h:107
#define Gia_ManForEachCi(p, pObj, i)
Definition: gia.h:1016
void Gia_ManChoiceLevel_rec(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: giaIf.c:638
#define If_ManForEachObj(p, pObj, i)
Definition: if.h:462
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static word * If_CutTruthW(If_Man_t *p, If_Cut_t *pCut)
Definition: if.h:421
static int Gia_ManAndNum(Gia_Man_t *p)
Definition: gia.h:389
static void Vec_StrWriteEntry(Vec_Str_t *p, int i, char Entry)
Definition: vecStr.h:370
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
int fEnableCheck75
Definition: if.h:131
int fEdge
Definition: if.h:118
static int Gia_ObjLevel(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:501
static int Gia_ObjSibl(Gia_Man_t *p, int Id)
Definition: gia.h:893
void Gia_ManSetRefsMapped(Gia_Man_t *p)
Definition: giaIf.c:245
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
static int Kit_TruthIsConst1(unsigned *pIn, int nVars)
Definition: kit.h:323
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
char * pName
Definition: if.h:182
int If_CluMinimumBase(word *t, int *pSupp, int nVarsAll, int *pnVars)
Definition: ifDec16.c:1532
void * If_ManSatBuildFromCell(char *pStr, Vec_Int_t **pvPiVars, Vec_Int_t **pvPoVars, Ifn_Ntk_t **ppNtk)
Definition: ifTune.c:622
static char Vec_StrEntry(Vec_Str_t *p, int i)
Definition: vecStr.h:336
int fPreprocess
Definition: if.h:113
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
int Gia_ManLutSizeMax(Gia_Man_t *p)
Definition: giaIf.c:125
int fDsdBalance
Definition: if.h:123
char * pName
Definition: gia.h:97
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Gia_ObjLutSize(Gia_Man_t *p, int Id)
Definition: gia.h:953
static void Abc_TtCofactor0p(word *pOut, word *pIn, int nWords, int iVar)
Definition: utilTruth.h:381
static void If_CutSetDataInt(If_Cut_t *pCut, int Data)
Definition: if.h:415
void Gia_ManTransferMapping(Gia_Man_t *p, Gia_Man_t *pGia)
Definition: giaIf.c:1855
#define Gia_LutForEachFaninObj(p, i, pFanin, k)
Definition: gia.h:972
static int Gia_ObjFanin1CopyArray(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:494
int fTruth
Definition: if.h:146
int fLatchPaths
Definition: if.h:117
static void Vec_IntAddToEntry(Vec_Int_t *p, int i, int Addition)
Definition: bblif.c:302
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
Gia_Man_t * Gia_ManDupNormalize(Gia_Man_t *p)
Definition: giaTim.c:134
void Gia_ManPrintGetMuxFanins(Gia_Man_t *p, Gia_Obj_t *pObj, int *pFanins)
Definition: giaIf.c:361
Definition: if.h:180
static word Truth6[6]
Definition: ifDec07.c:52
static If_Obj_t * If_ManFanin0Copy(If_Man_t *pIfMan, Gia_Obj_t *pObj)
Definition: giaIf.c:740
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static void Gia_ObjSetTravIdCurrent(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:531
Gia_Man_t * Gia_ManFromIfLogic(If_Man_t *pIfMan)
Definition: giaIf.c:1535
int Gia_ManLutNum(Gia_Man_t *p)
Definition: giaIf.c:144
static int Gia_ObjCopyArray(Gia_Man_t *p, int iObj)
Definition: gia.h:487
static int Gia_ObjRefInc(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:522
int fEnableCheck07
Definition: if.h:128
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:356
static If_Obj_t * If_ManConst1(If_Man_t *p)
Definition: if.h:365
if(last==0)
Definition: sparse_int.h:34
char * pSpec
Definition: gia.h:98
Gia_Man_t * Gia_ManStart(int nObjsMax)
DECLARATIONS ///.
Definition: giaMan.c:52
#define IF_MAX_FUNC_LUTSIZE
Definition: if.h:54
float * pTimesArr
Definition: if.h:161
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
static int If_CutDataInt(If_Cut_t *pCut)
Definition: if.h:414
int Ifn_NtkInputNum(Ifn_Ntk_t *p)
Definition: ifTune.c:167
static int Gia_ObjLutIsMux(Gia_Man_t *p, int Id)
Definition: gia.h:957
int If_DsdManVarNum(If_DsdMan_t *p)
Definition: ifDsd.c:165
static Vec_Str_t * Vec_StrStart(int nSize)
Definition: vecStr.h:95
Tim_Man_t * Tim_ManDup(Tim_Man_t *p, int fUnitDelay)
Definition: timMan.c:86
Gia_Man_t * Gia_ManRehash(Gia_Man_t *p, int fAddStrash)
Definition: giaHash.c:719
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
Gia_Man_t * Gia_ManPerformMapping(Gia_Man_t *p, void *pp)
Definition: giaIf.c:1986
int Gia_ManBoxCiNum(Gia_Man_t *p)
Definition: giaTim.c:61
static void Vec_IntAppend(Vec_Int_t *vVec1, Vec_Int_t *vVec2)
char * sprintf()
void * pManTime
Definition: gia.h:165
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
void Gia_ManCleanLevels(Gia_Man_t *p, int Size)
Definition: giaUtil.c:470
static int Counter
ABC_DLL void * Abc_FrameReadManDsd()
Definition: mainFrame.c:62
void * If_ManSatBuildXY(int nLutSize)
DECLARATIONS ///.
Definition: ifSat.c:45
void Gia_ManFillValue(Gia_Man_t *p)
Definition: giaUtil.c:328
If_Obj_t * pFanin1
Definition: if.h:322
void Gia_ObjPrint(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: giaUtil.c:1258
int Tim_ManBoxNum(Tim_Man_t *p)
Definition: timMan.c:702
int If_ManSatDeriveGiaFromBits(void *pNew, Ifn_Ntk_t *p, Vec_Int_t *vLeaves, Vec_Int_t *vValues)
Definition: ifTune.c:731
int Gia_ManBoxCoNum(Gia_Man_t *p)
Definition: giaTim.c:65
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition: vecInt.h:56
static void Vec_IntFreeP(Vec_Int_t **p)
Definition: vecInt.h:289
int If_ManSatCheckXY(void *pSat, int nLutSize, word *pTruth, int nVars, unsigned uSet, word *pTBound, word *pTFree, Vec_Int_t *vLits)
Definition: ifSat.c:150
float Epsilon
Definition: if.h:110
float * pTimesReq
Definition: if.h:162
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
void Gia_ManIffTest(Gia_Man_t *pGia, If_LibLut_t *pLib, int fVerbose)
Definition: giaIff.c:387
If_Man_t * Gia_ManToIf(Gia_Man_t *p, If_Par_t *pPars)
Definition: giaIf.c:742
If_Obj_t * pEquiv
Definition: if.h:323
int fUseAndVars
Definition: if.h:136
ABC_DLL void Abc_FrameSetManDsd2(void *pMan)
Definition: mainFrame.c:90
static int pPerm[13719]
Definition: rwrTemp.c:32
int If_CutSopBalanceEval(If_Man_t *p, If_Cut_t *pCut, Vec_Int_t *vAig)
Definition: ifDelay.c:248
int Gia_ManComputeOverlap(Gia_Man_t *p)
Definition: giaIf.c:341
static int If_ObjIsTerm(If_Obj_t *pObj)
Definition: if.h:375
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition: vecInt.h:66
int Tim_ManBoxInputNum(Tim_Man_t *p, int iBox)
Definition: timBox.c:186
ABC_NAMESPACE_IMPL_START 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
int If_DsdManSuppSize(If_DsdMan_t *p, int iDsd)
Definition: ifDsd.c:181
unsigned Level
Definition: if.h:315
static void Abc_TtFlip(word *pTruth, int nWords, int iVar)
Definition: utilTruth.h:1130
int nAnd2Delay
Definition: gia.h:173
static int Gia_ObjIsTravIdCurrentId(Gia_Man_t *p, int Id)
Definition: gia.h:536
int nObjBytes
Definition: if.h:228
ABC_DLL void * Abc_FrameReadManDsd2()
Definition: mainFrame.c:63
static int Gia_ObjIsCo(Gia_Obj_t *pObj)
Definition: gia.h:421
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Definition: gia.h:988
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int fFancy
Definition: if.h:115
int Gia_ManNonRegBoxNum(Gia_Man_t *p)
Definition: giaTim.c:57
static int If_ManObjNum(If_Man_t *p)
Definition: if.h:363
static int If_CutLeafBit(If_Cut_t *pCut, int i)
Definition: if.h:396
int fUseDsd
Definition: if.h:133
static int Vec_IntEntryLast(Vec_Int_t *p)
Definition: bblif.c:319
static void If_ObjSetChoice(If_Obj_t *pObj, If_Obj_t *pEqu)
Definition: if.h:388
int nRelaxRatio
Definition: if.h:111
static int Abc_LitNot(int Lit)
Definition: abc_global.h:266
static int If_CutDsdLit(If_Man_t *p, If_Cut_t *pCut)
Definition: if.h:424
static ABC_NAMESPACE_IMPL_START word Truth[8]
DECLARATIONS ///.
Definition: giaShrink6.c:32
If_Par_t * pPars
Definition: if.h:184
word If_DsdManGetFuncPerm(If_DsdMan_t *p, int iDsd)
Definition: ifDsd.c:199
static void Gia_ObjSetCopyArray(Gia_Man_t *p, int iObj, int iLit)
Definition: gia.h:488
float DelayTarget
Definition: if.h:109
static Gia_Obj_t * Gia_ManCo(Gia_Man_t *p, int v)
Definition: gia.h:404
int uMaskFunc
Definition: if.h:282
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
int nLatchesCo
Definition: if.h:153
static int Gia_ManHasMapping(Gia_Man_t *p)
Definition: gia.h:951
static int Kit_TruthIsOpposite(unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: kit.h:290
static int Abc_TtWordNum(int nVars)
Definition: utilTruth.h:169
If_DsdMan_t * If_DsdManAlloc(int nVars, int nLutSize)
Definition: ifDsd.c:248
int Gia_ManBuildFromMini(Gia_Man_t *pNew, If_Man_t *pIfMan, If_Cut_t *pCut, Vec_Int_t *vLeaves, Vec_Int_t *vAig, int fHash, int fUseDsd)
Definition: giaIf.c:848
void Gia_ManMappingVerify(Gia_Man_t *p)
Definition: giaIf.c:1807
int Gia_ManNodeIfToGia(Gia_Man_t *pNew, If_Man_t *pIfMan, If_Obj_t *pIfObj, Vec_Int_t *vLeaves, int fHash)
Definition: giaIf.c:1342
static void Vec_IntShrink(Vec_Int_t *p, int nSizeNew)
Definition: bblif.c:435
unsigned fMark0
Definition: gia.h:79
int fUseDsdTune
Definition: if.h:134
#define ABC_CONST(number)
PARAMETERS ///.
Definition: abc_global.h:206
static int If_ObjIsConst1(If_Obj_t *pObj)
Definition: if.h:372
void If_ManCreateChoice(If_Man_t *p, If_Obj_t *pRepr)
Definition: ifMan.c:442
int If_ManPerformMapping(If_Man_t *p)
Definition: ifCore.c:80
int nAreaIters
Definition: if.h:106
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Gia_ManFromIfLogicFindLut(If_Man_t *pIfMan, Gia_Man_t *pNew, If_Cut_t *pCutBest, sat_solver *pSat, Vec_Int_t *vLeaves, Vec_Int_t *vLits, Vec_Int_t *vCover, Vec_Int_t *vMapping, Vec_Int_t *vMapping2, Vec_Int_t *vPacking)
Definition: giaIf.c:1380
Gia_Obj_t * Gia_ObjRecognizeMux(Gia_Obj_t *pNode, Gia_Obj_t **ppNodeT, Gia_Obj_t **ppNodeE)
Definition: giaUtil.c:959
int If_DsdManLutSize(If_DsdMan_t *p)
Definition: ifDsd.c:173
Definition: gia.h:95
void If_ManCleanCutData(If_Man_t *p)
Definition: ifUtil.c:64
int Gia_ManNodeIfToGia_rec(Gia_Man_t *pNew, If_Man_t *pIfMan, If_Obj_t *pIfObj, Vec_Ptr_t *vVisited, int fHash)
Definition: giaIf.c:1304
int Gia_ManIsNormalized(Gia_Man_t *p)
Definition: giaTim.c:109
void Gia_ManCollectAnds(Gia_Man_t *p, int *pNodes, int nNodes, Vec_Int_t *vNodes)
Definition: giaDfs.c:123
int fUserRecLib
Definition: if.h:124
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
int fPower
Definition: if.h:119
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
If_Obj_t * If_ManCreateCi(If_Man_t *p)
Definition: ifMan.c:316
void Gia_ManPrintLutStats(Gia_Man_t *p)
Definition: giaIf.c:613
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
int fDelayOpt
Definition: if.h:121
static int Gia_ObjFaninId0p(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:463
void Gia_ManTestStruct(Gia_Man_t *p)
Definition: giaIf.c:2103
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
int fCutMin
Definition: if.h:120
#define Gia_ManForEachBuf(p, pObj, i)
Definition: gia.h:998
char * If_DsdManGetCellStr(If_DsdMan_t *p)
Definition: ifDsd.c:203
int fUseTtPerm
Definition: if.h:137
int Gia_ManLutLevelWithBoxes(Gia_Man_t *p)
Definition: giaTim.c:572
void Gia_ManPrintNodeProfile(int *pCounts, int nSizeMax)
Definition: giaIf.c:600
If_Obj_t * If_ManCreateAnd(If_Man_t *p, If_Obj_t *pFan0, If_Obj_t *pFan1)
Definition: ifMan.c:366
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
int nCutsMax
Definition: if.h:104
int strlen()
void Gia_ManSetIfParsDefault(void *pp)
FUNCTION DEFINITIONS ///.
Definition: giaIf.c:57
static int Gia_ObjFanin0CopyArray(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:493
unsigned Value
Definition: gia.h:87
typedefABC_NAMESPACE_HEADER_START struct Tim_Man_t_ Tim_Man_t
INCLUDES ///.
Definition: tim.h:92
static void Vec_IntPrint(Vec_Int_t *vVec)
Definition: vecInt.h:1803
static int Gia_ObjIsLut(Gia_Man_t *p, int Id)
Definition: gia.h:952
int If_CutDsdBalanceEval(If_Man_t *p, If_Cut_t *pCut, Vec_Int_t *vAig)
Definition: ifDsd.c:2288
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition: giaHash.c:99
#define Gia_ManForEachObj1(p, pObj, i)
Definition: gia.h:986
unsigned fCompl
Definition: if.h:285
int Gia_ManCountDupLut(Gia_Man_t *p)
Definition: giaIf.c:369
int Gia_ManChoiceLevel(Gia_Man_t *p)
Definition: giaIf.c:699
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition: giaUtil.c:149
Vec_Int_t * vMapping
Definition: gia.h:131
int Gia_ManFromIfLogicNode(void *pIfMan, Gia_Man_t *pNew, int iObj, Vec_Int_t *vLeaves, Vec_Int_t *vLeavesTemp, word *pRes, char *pStr, Vec_Int_t *vCover, Vec_Int_t *vMapping, Vec_Int_t *vMapping2, Vec_Int_t *vPacking, int fCheck75, int fCheck44e)
Definition: giaIf.c:1037
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
int fArea
Definition: if.h:114
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
int Tim_ManBoxInputFirst(Tim_Man_t *p, int iBox)
Definition: timBox.c:122
static int Gia_ManPiNum(Gia_Man_t *p)
Definition: gia.h:385
int fLiftLeaves
Definition: if.h:156
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
ABC_INT64_T abctime
Definition: abc_global.h:278
void Gia_ManCleanMark01(Gia_Man_t *p)
Definition: giaUtil.c:177
static int Gia_ObjIsCi(Gia_Obj_t *pObj)
Definition: gia.h:420
static void Gia_ObjSetTravIdCurrentId(Gia_Man_t *p, int Id)
Definition: gia.h:535
int Gia_ManBuildFromMiniInt(Gia_Man_t *pNew, Vec_Int_t *vLeaves, Vec_Int_t *vAig, int fHash)
Definition: giaIf.c:810
static char * If_CutDsdPerm(If_Man_t *p, If_Cut_t *pCut)
Definition: if.h:426
Gia_Man_t * Gia_ManPerformMappingInt(Gia_Man_t *p, If_Par_t *pPars)
Definition: giaIf.c:1933
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
static int Gia_ObjFaninId1(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:461
unsigned fCompl1
Definition: if.h:307
unsigned fCompl0
Definition: if.h:306
int iCutFunc
Definition: if.h:281
void If_ManStop(If_Man_t *p)
Definition: ifMan.c:205
unsigned fPhase
Definition: if.h:308
#define Gia_LutForEachFanin(p, i, iFan, k)
Definition: gia.h:970
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:572
Gia_Man_t * Gia_ManPerformDsdBalance(Gia_Man_t *p, int nLutSize, int nCutNum, int nRelaxRatio, int fVerbose)
Definition: giaIf.c:2058
static int Gia_ObjCioId(Gia_Obj_t *pObj)
Definition: gia.h:411
int Gia_ManClockDomainNum(Gia_Man_t *p)
Definition: giaTim.c:69
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
void Gia_ManMarkFanoutDrivers(Gia_Man_t *p)
Definition: giaUtil.c:1553
static int Gia_ManCiIdToId(Gia_Man_t *p, int CiId)
Definition: gia.h:438
static int Gia_ObjFaninId0(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:460
If_LibLut_t * pLutLib
Definition: if.h:160
static int Gia_ManCoNum(Gia_Man_t *p)
Definition: gia.h:384
Vec_Int_t vCopies
Definition: gia.h:138
static void Gia_ObjSetLevel(Gia_Man_t *p, Gia_Obj_t *pObj, int l)
Definition: gia.h:503
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387