abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ifMan.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ifMan.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [FPGA mapping based on priority cuts.]
8 
9  Synopsis [Mapping manager.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - November 21, 2006.]
16 
17  Revision [$Id: ifMan.c,v 1.00 2006/11/21 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "if.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 static If_Obj_t * If_ManSetupObj( If_Man_t * p );
31 
32 static void If_ManCutSetRecycle( If_Man_t * p, If_Set_t * pSet ) { pSet->pNext = p->pFreeList; p->pFreeList = pSet; }
33 static If_Set_t * If_ManCutSetFetch( If_Man_t * p ) { If_Set_t * pTemp = p->pFreeList; p->pFreeList = p->pFreeList->pNext; return pTemp; }
34 
35 ////////////////////////////////////////////////////////////////////////
36 /// FUNCTION DEFINITIONS ///
37 ////////////////////////////////////////////////////////////////////////
38 
39 /**Function*************************************************************
40 
41  Synopsis [Starts the AIG manager.]
42 
43  Description []
44 
45  SideEffects []
46 
47  SeeAlso []
48 
49 ***********************************************************************/
51 {
52  If_Man_t * p; int v;
53  assert( !pPars->fUseDsd || !pPars->fUseTtPerm );
54  // start the manager
55  p = ABC_ALLOC( If_Man_t, 1 );
56  memset( p, 0, sizeof(If_Man_t) );
57  p->pPars = pPars;
58  p->fEpsilon = pPars->Epsilon;
59  // allocate arrays for nodes
60  p->vCis = Vec_PtrAlloc( 100 );
61  p->vCos = Vec_PtrAlloc( 100 );
62  p->vObjs = Vec_PtrAlloc( 100 );
63  p->vTemp = Vec_PtrAlloc( 100 );
64  // prepare the memory manager
65  if ( p->pPars->fTruth )
66  {
67  for ( v = 0; v <= p->pPars->nLutSize; v++ )
68  p->nTruth6Words[v] = Abc_Truth6WordNum( v );
69  for ( v = 6; v <= Abc_MaxInt(6,p->pPars->nLutSize); v++ )
70  p->vTtMem[v] = Vec_MemAllocForTT( v, pPars->fUseTtPerm );
71  for ( v = 0; v < 6; v++ )
72  p->vTtMem[v] = p->vTtMem[6];
73  if ( p->pPars->fDelayOpt || pPars->nGateSize > 0 )
74  {
75  for ( v = 6; v <= Abc_MaxInt(6,p->pPars->nLutSize); v++ )
76  p->vTtIsops[v] = Vec_WecAlloc( 1000 );
77  for ( v = 6; v <= Abc_MaxInt(6,p->pPars->nLutSize); v++ )
78  Vec_WecInit( p->vTtIsops[v], 2 );
79  for ( v = 0; v < 6; v++ )
80  p->vTtIsops[v] = p->vTtIsops[6];
81  }
82  if ( pPars->fDelayOpt || pPars->nGateSize > 0 || pPars->fDsdBalance )
83  {
84  p->vCover = Vec_IntAlloc( 0 );
85  p->vArray = Vec_IntAlloc( 1000 );
86  }
87  }
89  p->nObjBytes = sizeof(If_Obj_t) + sizeof(int) * (p->pPars->nLutSize + p->nPermWords);
90  p->nCutBytes = sizeof(If_Cut_t) + sizeof(int) * (p->pPars->nLutSize + p->nPermWords);
91  p->nSetBytes = sizeof(If_Set_t) + (sizeof(If_Cut_t *) + p->nCutBytes) * (p->pPars->nCutsMax + 1);
92  p->pMemObj = Mem_FixedStart( p->nObjBytes );
93  // report expected memory usage
94  if ( p->pPars->fVerbose )
95  Abc_Print( 1, "K = %d. Memory (bytes): Truth = %4d. Cut = %4d. Obj = %4d. Set = %4d. CutMin = %s\n",
96  p->pPars->nLutSize, 8 * p->nTruth6Words[p->pPars->nLutSize], p->nCutBytes, p->nObjBytes, p->nSetBytes, p->pPars->fCutMin? "yes":"no" );
97  // room for temporary truth tables
98  p->puTemp[0] = p->pPars->fTruth? ABC_ALLOC( unsigned, 8 * p->nTruth6Words[p->pPars->nLutSize] ) : NULL;
99  p->puTemp[1] = p->puTemp[0] + p->nTruth6Words[p->pPars->nLutSize]*2;
100  p->puTemp[2] = p->puTemp[1] + p->nTruth6Words[p->pPars->nLutSize]*2;
101  p->puTemp[3] = p->puTemp[2] + p->nTruth6Words[p->pPars->nLutSize]*2;
102  p->puTempW = p->pPars->fTruth? ABC_ALLOC( word, p->nTruth6Words[p->pPars->nLutSize] ) : NULL;
103  if ( pPars->fUseDsd )
104  {
105  for ( v = 6; v <= Abc_MaxInt(6,p->pPars->nLutSize); v++ )
106  {
107  p->vTtDsds[v] = Vec_IntAlloc( 1000 );
108  Vec_IntPush( p->vTtDsds[v], 0 );
109  Vec_IntPush( p->vTtDsds[v], 2 );
110  p->vTtPerms[v] = Vec_StrAlloc( 10000 );
111  Vec_StrFill( p->vTtPerms[v], 2 * v, IF_BIG_CHAR );
112  Vec_StrWriteEntry( p->vTtPerms[v], v, 0 );
113  }
114  for ( v = 0; v < 6; v++ )
115  {
116  p->vTtDsds[v] = p->vTtDsds[6];
117  p->vTtPerms[v] = p->vTtPerms[6];
118  }
119  }
120  if ( pPars->fUseTtPerm )
121  {
122  p->vPairHash = Hash_IntManStart( 10000 );
123  p->vPairPerms = Vec_StrAlloc( 10000 );
124  Vec_StrFill( p->vPairPerms, p->pPars->nLutSize, 0 );
125  p->vPairRes = Vec_IntAlloc( 1000 );
126  Vec_IntPush( p->vPairRes, -1 );
127  }
128  if ( pPars->fUseCofVars )
129  {
130  for ( v = 6; v <= Abc_MaxInt(6,p->pPars->nLutSize); v++ )
131  {
132  p->vTtVars[v] = Vec_StrAlloc( 1000 );
133  Vec_StrPush( p->vTtVars[v], 0 );
134  Vec_StrPush( p->vTtVars[v], 0 );
135  }
136  for ( v = 0; v < 6; v++ )
137  p->vTtVars[v] = p->vTtVars[6];
138  }
139  if ( pPars->fUseAndVars )
140  {
141  for ( v = 6; v <= Abc_MaxInt(6,p->pPars->nLutSize); v++ )
142  {
143  p->vTtDecs[v] = Vec_IntAlloc( 1000 );
144  Vec_IntPush( p->vTtDecs[v], 0 );
145  Vec_IntPush( p->vTtDecs[v], 0 );
146  }
147  for ( v = 0; v < 6; v++ )
148  p->vTtDecs[v] = p->vTtDecs[6];
149  }
150  if ( pPars->fUseBat )
151  {
152 // abctime clk = Abc_Clock();
153  extern int Bat_ManCellFuncLookup( void * pMan, unsigned * pTruth, int nVars, int nLeaves, char * pStr );
154  extern void Bat_ManFuncSetupTable();
155  pPars->pFuncCell = (int (*) (If_Man_t *, unsigned *, int, int, char *))Bat_ManCellFuncLookup;
157 // Abc_PrintTime( 1, "Setup time", Abc_Clock() - clk );
158  }
159  // create the constant node
160  p->pConst1 = If_ManSetupObj( p );
161  p->pConst1->Type = IF_CONST1;
162  p->pConst1->fPhase = 1;
163  p->nObjs[IF_CONST1]++;
164  return p;
165 }
166 
167 /**Function*************************************************************
168 
169  Synopsis []
170 
171  Description []
172 
173  SideEffects []
174 
175  SeeAlso []
176 
177 ***********************************************************************/
179 {
180  ABC_FREE( p->pMemCi );
181  Vec_PtrClear( p->vCis );
182  Vec_PtrClear( p->vCos );
183  Vec_PtrClear( p->vObjs );
184  Vec_PtrClear( p->vTemp );
186  // create the constant node
187  p->pConst1 = If_ManSetupObj( p );
188  p->pConst1->Type = IF_CONST1;
189  p->pConst1->fPhase = 1;
190  // reset the counter of other nodes
191  p->nObjs[IF_CI] = p->nObjs[IF_CO] = p->nObjs[IF_AND] = 0;
192 }
193 
194 /**Function*************************************************************
195 
196  Synopsis []
197 
198  Description []
199 
200  SideEffects []
201 
202  SeeAlso []
203 
204 ***********************************************************************/
206 {
207  extern void If_ManCacheAnalize( If_Man_t * p );
208  int i;
209  if ( p->pPars->fVerbose && p->vCutData )
210  If_ManCacheAnalize( p );
211  if ( p->pPars->fVerbose && p->pPars->fTruth )
212  {
213  int nUnique = 0, nMemTotal = 0;
214  for ( i = 6; i <= Abc_MaxInt(6,p->pPars->nLutSize); i++ )
215  nUnique += Vec_MemEntryNum(p->vTtMem[i]);
216  for ( i = 6; i <= Abc_MaxInt(6,p->pPars->nLutSize); i++ )
217  nMemTotal += (int)Vec_MemMemory(p->vTtMem[i]);
218  printf( "Unique truth tables = %d Memory = %.2f MB ", nUnique, 1.0 * nMemTotal / (1<<20) );
219  Abc_PrintTime( 1, "Time", p->timeCache[4] );
220  if ( p->nCacheMisses )
221  {
222  printf( "Cache hits = %d. Cache misses = %d (%.2f %%)\n", p->nCacheHits, p->nCacheMisses, 100.0 * p->nCacheMisses / (p->nCacheHits + p->nCacheMisses) );
223  Abc_PrintTime( 1, "Non-DSD ", p->timeCache[0] );
224  Abc_PrintTime( 1, "DSD hits ", p->timeCache[1] );
225  Abc_PrintTime( 1, "DSD misses", p->timeCache[2] );
226  Abc_PrintTime( 1, "TOTAL ", p->timeCache[0] + p->timeCache[1] + p->timeCache[2] );
227  Abc_PrintTime( 1, "Canon ", p->timeCache[3] );
228  }
229  }
230  if ( p->pPars->fVerbose && p->nCutsUselessAll )
231  {
232  for ( i = 0; i <= 16; i++ )
233  if ( p->nCutsUseless[i] )
234  Abc_Print( 1, "Useless cuts %2d = %9d (out of %9d) (%6.2f %%)\n", i, p->nCutsUseless[i], p->nCutsCount[i], 100.0*p->nCutsUseless[i]/Abc_MaxInt(p->nCutsCount[i],1) );
235  Abc_Print( 1, "Useless cuts all = %9d (out of %9d) (%6.2f %%)\n", p->nCutsUselessAll, p->nCutsCountAll, 100.0*p->nCutsUselessAll/Abc_MaxInt(p->nCutsCountAll,1) );
236  }
237 // if ( p->pPars->fVerbose && p->nCuts5 )
238 // Abc_Print( 1, "Statistics about 5-cuts: Total = %d Non-decomposable = %d (%.2f %%)\n", p->nCuts5, p->nCuts5-p->nCuts5a, 100.0*(p->nCuts5-p->nCuts5a)/p->nCuts5 );
239  if ( p->pIfDsdMan )
240  p->pIfDsdMan = NULL;
241  if ( p->pPars->fUseDsd && (p->nCountNonDec[0] || p->nCountNonDec[1]) )
242  printf( "NonDec0 = %d. NonDec1 = %d.\n", p->nCountNonDec[0], p->nCountNonDec[1] );
243  Vec_IntFreeP( &p->vCoAttrs );
244  Vec_PtrFree( p->vCis );
245  Vec_PtrFree( p->vCos );
246  Vec_PtrFree( p->vObjs );
247  Vec_PtrFree( p->vTemp );
248  Vec_IntFreeP( &p->vCover );
249  Vec_IntFreeP( &p->vArray );
250  Vec_WrdFreeP( &p->vAnds );
251  Vec_WrdFreeP( &p->vAndGate );
252  Vec_WrdFreeP( &p->vOrGate );
253  Vec_PtrFreeP( &p->vObjsRev );
254  Vec_PtrFreeP( &p->vLatchOrder );
255  Vec_IntFreeP( &p->vLags );
256  for ( i = 6; i <= Abc_MaxInt(6,p->pPars->nLutSize); i++ )
257  Vec_IntFreeP( &p->vTtDsds[i] );
258  for ( i = 6; i <= Abc_MaxInt(6,p->pPars->nLutSize); i++ )
259  Vec_StrFreeP( &p->vTtPerms[i] );
260  for ( i = 6; i <= Abc_MaxInt(6,p->pPars->nLutSize); i++ )
261  Vec_StrFreeP( &p->vTtVars[i] );
262  for ( i = 6; i <= Abc_MaxInt(6,p->pPars->nLutSize); i++ )
263  Vec_IntFreeP( &p->vTtDecs[i] );
264  Vec_IntFreeP( &p->vCutData );
265  Vec_IntFreeP( &p->vPairRes );
266  Vec_StrFreeP( &p->vPairPerms );
267  if ( p->vPairHash )
269  for ( i = 6; i <= Abc_MaxInt(6,p->pPars->nLutSize); i++ )
270  Vec_MemHashFree( p->vTtMem[i] );
271  for ( i = 6; i <= Abc_MaxInt(6,p->pPars->nLutSize); i++ )
272  Vec_MemFreeP( &p->vTtMem[i] );
273  for ( i = 6; i <= Abc_MaxInt(6,p->pPars->nLutSize); i++ )
274  Vec_WecFreeP( &p->vTtIsops[i] );
275  Mem_FixedStop( p->pMemObj, 0 );
276  ABC_FREE( p->pMemCi );
277  ABC_FREE( p->pMemAnd );
278  ABC_FREE( p->puTemp[0] );
279  ABC_FREE( p->puTempW );
280  // free pars memory
281  ABC_FREE( p->pPars->pTimesArr );
282  ABC_FREE( p->pPars->pTimesReq );
283  if ( p->pManTim )
284  Tim_ManStop( p->pManTim );
285  if ( p->vSwitching )
286  Vec_IntFree( p->vSwitching );
287  if ( p->pPars->fUseBat )
288  {
289  extern void Bat_ManFuncSetdownTable();
291  }
292  // hash table
293 // if ( p->pPars->fVerbose && p->nTableEntries[0] )
294 // printf( "Hash table 2: Entries = %7d. Size = %7d.\n", p->nTableEntries[0], p->nTableSize[0] );
295 // if ( p->pPars->fVerbose && p->nTableEntries[1] )
296 // printf( "Hash table 3: Entries = %7d. Size = %7d.\n", p->nTableEntries[1], p->nTableSize[1] );
297  ABC_FREE( p->pHashTable[0] );
298  ABC_FREE( p->pHashTable[1] );
299  if ( p->pMemEntries )
300  Mem_FixedStop( p->pMemEntries, 0 );
301  ABC_FREE( p->pName );
302  ABC_FREE( p );
303 }
304 
305 /**Function*************************************************************
306 
307  Synopsis [Creates primary input.]
308 
309  Description []
310 
311  SideEffects []
312 
313  SeeAlso []
314 
315 ***********************************************************************/
317 {
318  If_Obj_t * pObj;
319  pObj = If_ManSetupObj( p );
320  pObj->Type = IF_CI;
321  pObj->IdPio = Vec_PtrSize( p->vCis );
322  Vec_PtrPush( p->vCis, pObj );
323  p->nObjs[IF_CI]++;
324  return pObj;
325 }
326 
327 /**Function*************************************************************
328 
329  Synopsis [Creates primary output with the given driver.]
330 
331  Description []
332 
333  SideEffects []
334 
335  SeeAlso []
336 
337 ***********************************************************************/
339 {
340  If_Obj_t * pObj;
341  pObj = If_ManSetupObj( p );
342  pObj->IdPio = Vec_PtrSize( p->vCos );
343  Vec_PtrPush( p->vCos, pObj );
344  pObj->Type = IF_CO;
345  pObj->fCompl0 = If_IsComplement(pDriver); pDriver = If_Regular(pDriver);
346  pObj->pFanin0 = pDriver; pDriver->nRefs++;
347  pObj->fPhase = (pObj->fCompl0 ^ pDriver->fPhase);
348  pObj->Level = pDriver->Level;
349  if ( p->nLevelMax < (int)pObj->Level )
350  p->nLevelMax = (int)pObj->Level;
351  p->nObjs[IF_CO]++;
352  return pObj;
353 }
354 
355 /**Function*************************************************************
356 
357  Synopsis [Create the new node assuming it does not exist.]
358 
359  Description []
360 
361  SideEffects []
362 
363  SeeAlso []
364 
365 ***********************************************************************/
367 {
368  If_Obj_t * pObj;
369  // perform constant propagation
370  if ( pFan0 == pFan1 )
371  return pFan0;
372  if ( pFan0 == If_Not(pFan1) )
373  return If_Not(p->pConst1);
374  if ( If_Regular(pFan0) == p->pConst1 )
375  return pFan0 == p->pConst1 ? pFan1 : If_Not(p->pConst1);
376  if ( If_Regular(pFan1) == p->pConst1 )
377  return pFan1 == p->pConst1 ? pFan0 : If_Not(p->pConst1);
378  // get memory for the new object
379  pObj = If_ManSetupObj( p );
380  pObj->Type = IF_AND;
381  pObj->fCompl0 = If_IsComplement(pFan0); pFan0 = If_Regular(pFan0);
382  pObj->fCompl1 = If_IsComplement(pFan1); pFan1 = If_Regular(pFan1);
383  pObj->pFanin0 = pFan0; pFan0->nRefs++; pFan0->nVisits++; pFan0->nVisitsCopy++;
384  pObj->pFanin1 = pFan1; pFan1->nRefs++; pFan1->nVisits++; pFan1->nVisitsCopy++;
385  pObj->fPhase = (pObj->fCompl0 ^ pFan0->fPhase) & (pObj->fCompl1 ^ pFan1->fPhase);
386  pObj->Level = 1 + IF_MAX( pFan0->Level, pFan1->Level );
387  if ( p->nLevelMax < (int)pObj->Level )
388  p->nLevelMax = (int)pObj->Level;
389  p->nObjs[IF_AND]++;
390  return pObj;
391 }
392 
393 /**Function*************************************************************
394 
395  Synopsis [Create the new node assuming it does not exist.]
396 
397  Description []
398 
399  SideEffects []
400 
401  SeeAlso []
402 
403 ***********************************************************************/
405 {
406  If_Obj_t * pRes1, * pRes2;
407  pRes1 = If_ManCreateAnd( p, If_Not(pFan0), pFan1 );
408  pRes2 = If_ManCreateAnd( p, pFan0, If_Not(pFan1) );
409  return If_Not( If_ManCreateAnd( p, If_Not(pRes1), If_Not(pRes2) ) );
410 }
411 
412 /**Function*************************************************************
413 
414  Synopsis [Create the new node assuming it does not exist.]
415 
416  Description []
417 
418  SideEffects []
419 
420  SeeAlso []
421 
422 ***********************************************************************/
423 If_Obj_t * If_ManCreateMux( If_Man_t * p, If_Obj_t * pFan0, If_Obj_t * pFan1, If_Obj_t * pCtrl )
424 {
425  If_Obj_t * pRes1, * pRes2;
426  pRes1 = If_ManCreateAnd( p, pFan0, If_Not(pCtrl) );
427  pRes2 = If_ManCreateAnd( p, pFan1, pCtrl );
428  return If_Not( If_ManCreateAnd( p, If_Not(pRes1), If_Not(pRes2) ) );
429 }
430 
431 /**Function*************************************************************
432 
433  Synopsis [Creates the choice node.]
434 
435  Description [Should be called after the equivalence class nodes are linked.]
436 
437  SideEffects []
438 
439  SeeAlso []
440 
441 ***********************************************************************/
443 {
444  If_Obj_t * pTemp;
445  // mark the node as a representative if its class
446  assert( pObj->fRepr == 0 );
447  pObj->fRepr = 1;
448  // update the level of this node (needed for correct required time computation)
449  for ( pTemp = pObj; pTemp; pTemp = pTemp->pEquiv )
450  {
451  pObj->Level = IF_MAX( pObj->Level, pTemp->Level );
452  pTemp->nVisits++; pTemp->nVisitsCopy++;
453  }
454  // mark the largest level
455  if ( p->nLevelMax < (int)pObj->Level )
456  p->nLevelMax = (int)pObj->Level;
457  p->nChoices++;
458 }
459 
460 /**Function*************************************************************
461 
462  Synopsis [Prepares memory for one cutset.]
463 
464  Description []
465 
466  SideEffects []
467 
468  SeeAlso []
469 
470 ***********************************************************************/
472 {
473  char * pArray;
474  int i;
475  pSet->nCuts = 0;
476  pSet->nCutsMax = p->pPars->nCutsMax;
477  pSet->ppCuts = (If_Cut_t **)(pSet + 1);
478  pArray = (char *)pSet->ppCuts + sizeof(If_Cut_t *) * (pSet->nCutsMax+1);
479  for ( i = 0; i <= pSet->nCutsMax; i++ )
480  {
481  pSet->ppCuts[i] = (If_Cut_t *)(pArray + i * p->nCutBytes);
482  If_CutSetup( p, pSet->ppCuts[i] );
483  }
484 // pArray += (pSet->nCutsMax + 1) * p->nCutBytes;
485 // assert( ((char *)pArray) - ((char *)pSet) == p->nSetBytes );
486 }
487 
488 /**Function*************************************************************
489 
490  Synopsis [Prepares memory for one cut.]
491 
492  Description []
493 
494  SideEffects []
495 
496  SeeAlso []
497 
498 ***********************************************************************/
499 void If_ManSetupCutTriv( If_Man_t * p, If_Cut_t * pCut, int ObjId )
500 {
501  pCut->fCompl = 0;
502  pCut->nLimit = p->pPars->nLutSize;
503  pCut->nLeaves = 1;
504  pCut->pLeaves[0] = p->pPars->fLiftLeaves? (ObjId << 8) : ObjId;
505  pCut->uSign = If_ObjCutSign( pCut->pLeaves[0] );
506  pCut->iCutFunc = p->pPars->fUseTtPerm ? 3 : (p->pPars->fTruth ? 2: -1);
507  pCut->uMaskFunc = 0;
508  assert( pCut->pLeaves[0] < p->vObjs->nSize );
509 }
510 
511 /**Function*************************************************************
512 
513  Synopsis [Prepares memory for the node with cuts.]
514 
515  Description []
516 
517  SideEffects []
518 
519  SeeAlso []
520 
521 ***********************************************************************/
523 {
524  If_Obj_t * pObj;
525  // get memory for the object
526  pObj = (If_Obj_t *)Mem_FixedEntryFetch( p->pMemObj );
527  memset( pObj, 0, sizeof(If_Obj_t) );
528  If_CutSetup( p, &pObj->CutBest );
529  // assign ID and save
530  pObj->Id = Vec_PtrSize(p->vObjs);
531  Vec_PtrPush( p->vObjs, pObj );
532  // set the required times
533  pObj->Required = IF_FLOAT_LARGE;
534  return pObj;
535 }
536 
537 /**Function*************************************************************
538 
539  Synopsis [Prepares memory for one cut.]
540 
541  Description []
542 
543  SideEffects []
544 
545  SeeAlso []
546 
547 ***********************************************************************/
549 {
550  If_Obj_t * pObj;
551  int i;
552  assert( p->pMemCi == NULL );
553  // create elementary cuts for the CIs
554  If_ManForEachCi( p, pObj, i )
555  If_ManSetupCutTriv( p, &pObj->CutBest, pObj->Id );
556  // create elementary cutsets for the CIs
557  p->pMemCi = (If_Set_t *)ABC_ALLOC( char, If_ManCiNum(p) * (sizeof(If_Set_t) + sizeof(void *)) );
558  If_ManForEachCi( p, pObj, i )
559  {
560  pObj->pCutSet = (If_Set_t *)((char *)p->pMemCi + i * (sizeof(If_Set_t) + sizeof(void *)));
561  pObj->pCutSet->nCuts = 1;
562  pObj->pCutSet->nCutsMax = p->pPars->nCutsMax;
563  pObj->pCutSet->ppCuts = (If_Cut_t **)(pObj->pCutSet + 1);
564  pObj->pCutSet->ppCuts[0] = &pObj->CutBest;
565  }
566 }
567 
568 /**Function*************************************************************
569 
570  Synopsis [Prepares cutset of the node.]
571 
572  Description [Elementary cutset will be added last.]
573 
574  SideEffects []
575 
576  SeeAlso []
577 
578 ***********************************************************************/
580 {
581  assert( If_ObjIsAnd(pObj) );
582  assert( pObj->pCutSet == NULL );
583 // pObj->pCutSet = (If_Set_t *)Mem_FixedEntryFetch( p->pMemSet );
584 // If_ManSetupSet( p, pObj->pCutSet );
585  pObj->pCutSet = If_ManCutSetFetch( p );
586  pObj->pCutSet->nCuts = 0;
587  pObj->pCutSet->nCutsMax = p->pPars->nCutsMax;
588  return pObj->pCutSet;
589 }
590 
591 /**Function*************************************************************
592 
593  Synopsis [Dereferences cutset of the node.]
594 
595  Description []
596 
597  SideEffects []
598 
599  SeeAlso []
600 
601 ***********************************************************************/
603 {
604  If_Obj_t * pFanin;
605  assert( If_ObjIsAnd(pObj) );
606  // consider the node
607  assert( pObj->nVisits >= 0 );
608  if ( pObj->nVisits == 0 )
609  {
610 // Mem_FixedEntryRecycle( p->pMemSet, (char *)pObj->pCutSet );
611  If_ManCutSetRecycle( p, pObj->pCutSet );
612  pObj->pCutSet = NULL;
613  }
614  // consider the first fanin
615  pFanin = If_ObjFanin0(pObj);
616  assert( pFanin->nVisits > 0 );
617  if ( !If_ObjIsCi(pFanin) && --pFanin->nVisits == 0 )
618  {
619 // Mem_FixedEntryRecycle( p->pMemSet, (char *)pFanin->pCutSet );
620  If_ManCutSetRecycle( p, pFanin->pCutSet );
621  pFanin->pCutSet = NULL;
622  }
623  // consider the second fanin
624  pFanin = If_ObjFanin1(pObj);
625  assert( pFanin->nVisits > 0 );
626  if ( !If_ObjIsCi(pFanin) && --pFanin->nVisits == 0 )
627  {
628 // Mem_FixedEntryRecycle( p->pMemSet, (char *)pFanin->pCutSet );
629  If_ManCutSetRecycle( p, pFanin->pCutSet );
630  pFanin->pCutSet = NULL;
631  }
632 }
633 
634 /**Function*************************************************************
635 
636  Synopsis [Dereferences cutset of the node.]
637 
638  Description []
639 
640  SideEffects []
641 
642  SeeAlso []
643 
644 ***********************************************************************/
646 {
647  If_Obj_t * pTemp;
648  assert( If_ObjIsAnd(pObj) );
649  assert( pObj->fRepr );
650  assert( pObj->nVisits > 0 );
651  // consider the nodes in the choice class
652  for ( pTemp = pObj; pTemp; pTemp = pTemp->pEquiv )
653  {
654 // assert( pTemp == pObj || pTemp->nVisits == 1 );
655  if ( --pTemp->nVisits == 0 )
656  {
657 // Mem_FixedEntryRecycle( p->pMemSet, (char *)pTemp->pCutSet );
658  If_ManCutSetRecycle( p, pTemp->pCutSet );
659  pTemp->pCutSet = NULL;
660  }
661  }
662 }
663 
664 /**Function*************************************************************
665 
666  Synopsis [Dereferences cutset of the node.]
667 
668  Description []
669 
670  SideEffects []
671 
672  SeeAlso []
673 
674 ***********************************************************************/
675 void If_ManSetupSetAll( If_Man_t * p, int nCrossCut )
676 {
677  If_Set_t * pCutSet;
678  int i, nCutSets;
679  nCutSets = 128 + nCrossCut;
680  p->pFreeList = p->pMemAnd = pCutSet = (If_Set_t *)ABC_ALLOC( char, nCutSets * p->nSetBytes );
681  for ( i = 0; i < nCutSets; i++ )
682  {
683  If_ManSetupSet( p, pCutSet );
684  if ( i == nCutSets - 1 )
685  pCutSet->pNext = NULL;
686  else
687  pCutSet->pNext = (If_Set_t *)( (char *)pCutSet + p->nSetBytes );
688  pCutSet = pCutSet->pNext;
689  }
690  assert( pCutSet == NULL );
691 
692  if ( p->pPars->fVerbose )
693  {
694  Abc_Print( 1, "Node = %7d. Ch = %5d. Total mem = %7.2f MB. Peak cut mem = %7.2f MB.\n",
695  If_ManAndNum(p), p->nChoices,
696  1.0 * (p->nObjBytes + 2*sizeof(void *)) * If_ManObjNum(p) / (1<<20),
697  1.0 * p->nSetBytes * nCrossCut / (1<<20) );
698  }
699 // Abc_Print( 1, "Cross cut = %d.\n", nCrossCut );
700 
701 }
702 
703 ////////////////////////////////////////////////////////////////////////
704 /// END OF FILE ///
705 ////////////////////////////////////////////////////////////////////////
706 
707 
709 
int nTruth6Words[IF_MAX_FUNC_LUTSIZE+1]
Definition: if.h:226
char * memset()
If_Obj_t * pFanin0
Definition: if.h:321
Vec_Ptr_t * vObjs
Definition: if.h:189
static Hash_IntMan_t * Hash_IntManStart(int nSize)
FUNCTION DEFINITIONS ///.
Definition: vecHash.h:86
If_DsdMan_t * pIfDsdMan
Definition: if.h:243
#define IF_MAX(a, b)
Definition: if.h:437
If_Set_t * pCutSet
Definition: if.h:332
unsigned nLeaves
Definition: if.h:289
int Id
Definition: if.h:316
unsigned Type
Definition: if.h:305
static Vec_Wec_t * Vec_WecAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecWec.h:87
unsigned nLimit
Definition: if.h:288
Vec_Str_t * vTtVars[IF_MAX_FUNC_LUTSIZE+1]
Definition: if.h:248
int nLutSize
Definition: if.h:103
Vec_Wec_t * vTtIsops[IF_MAX_FUNC_LUTSIZE+1]
Definition: if.h:245
static void If_CutSetup(If_Man_t *p, If_Cut_t *pCut)
Definition: if.h:399
static int If_ManAndNum(If_Man_t *p)
Definition: if.h:362
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Definition: if.h:100
Vec_Mem_t * vTtMem[IF_MAX_FUNC_LUTSIZE+1]
Definition: if.h:244
static If_Set_t * If_ManCutSetFetch(If_Man_t *p)
Definition: ifMan.c:33
Vec_Int_t * vTtDecs[IF_MAX_FUNC_LUTSIZE+1]
Definition: if.h:249
Vec_Ptr_t * vTemp
Definition: if.h:191
If_Set_t * pMemCi
Definition: if.h:233
Definition: if.h:303
#define IF_BIG_CHAR
Definition: if.h:60
static int If_ObjIsAnd(If_Obj_t *pObj)
Definition: if.h:377
Definition: if.h:275
static int Abc_Truth6WordNum(int nVars)
Definition: abc_global.h:257
Vec_Ptr_t * vObjsRev
Definition: if.h:190
float Required
Definition: if.h:325
unsigned fRepr
Definition: if.h:309
int fVerbose
Definition: if.h:140
If_Set_t * If_ManSetupNodeCutSet(If_Man_t *p, If_Obj_t *pObj)
Definition: ifMan.c:579
int nCutsCountAll
Definition: if.h:240
If_Obj_t * If_ManCreateCo(If_Man_t *p, If_Obj_t *pDriver)
Definition: ifMan.c:338
void If_ManDerefNodeCutSet(If_Man_t *p, If_Obj_t *pObj)
Definition: ifMan.c:602
int nLevelMax
Definition: if.h:194
short nCutsMax
Definition: if.h:296
int nChoices
Definition: if.h:207
void If_ManStop(If_Man_t *p)
Definition: ifMan.c:205
static int Vec_MemEntryNum(Vec_Mem_t *p)
Definition: vecMem.h:151
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
Vec_Str_t * vTtPerms[IF_MAX_FUNC_LUTSIZE+1]
Definition: if.h:247
ABC_NAMESPACE_IMPL_START void Bat_ManFuncSetupTable()
DECLARATIONS ///.
Definition: ifMatch2.c:45
Hash_IntMan_t * vPairHash
Definition: if.h:250
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int If_ObjIsCi(If_Obj_t *pObj)
Definition: if.h:373
void Mem_FixedStop(Mem_Fixed_t *p, int fVerbose)
Definition: mem.c:139
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
void If_ManCacheAnalize(If_Man_t *p)
Definition: ifCache.c:70
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static void Vec_StrPush(Vec_Str_t *p, char Entry)
Definition: vecStr.h:535
Vec_Int_t * vSwitching
Definition: if.h:208
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static void Vec_WrdFreeP(Vec_Wrd_t **p)
Definition: vecWrd.h:277
int nCacheMisses
Definition: if.h:256
int nRefs
Definition: if.h:318
void Bat_ManFuncSetdownTable()
Definition: ifMatch2.c:48
int fUseCofVars
Definition: if.h:135
Mem_Fixed_t * pMemObj
Definition: if.h:231
Vec_Wrd_t * vAndGate
Definition: if.h:218
void If_ManSetupCiCutSets(If_Man_t *p)
Definition: ifMan.c:548
Definition: if.h:68
static If_Obj_t * If_Not(If_Obj_t *p)
Definition: if.h:356
Tim_Man_t * pManTim
Definition: if.h:263
struct If_Obj_t_ If_Obj_t
Definition: if.h:78
int nGateSize
Definition: if.h:107
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
Mem_Fixed_t * Mem_FixedStart(int nEntrySize)
FUNCTION DEFINITIONS ///.
Definition: mem.c:100
Definition: if.h:67
static int If_ManCiNum(If_Man_t *p)
Definition: if.h:360
If_Cut_t CutBest
Definition: if.h:333
static void Vec_StrWriteEntry(Vec_Str_t *p, int i, char Entry)
Definition: vecStr.h:370
int pLeaves[0]
Definition: if.h:290
int nCutsUseless[32]
Definition: if.h:238
#define If_ManForEachCi(p, pObj, i)
Definition: if.h:445
Vec_Ptr_t * vCis
Definition: if.h:187
char * pName
Definition: if.h:182
void ** pHashTable[2]
Definition: if.h:268
int fUsePerm
Definition: if.h:147
unsigned * puTemp[4]
Definition: if.h:203
int fDsdBalance
Definition: if.h:123
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
void If_ManSetupSet(If_Man_t *p, If_Set_t *pSet)
Definition: ifMan.c:471
Vec_Wrd_t * vAnds
Definition: if.h:216
int fTruth
Definition: if.h:146
If_Obj_t * If_ManCreateCi(If_Man_t *p)
Definition: ifMan.c:316
void If_ManDerefChoiceCutSet(If_Man_t *p, If_Obj_t *pObj)
Definition: ifMan.c:645
static Vec_Mem_t * Vec_MemAllocForTT(int nVars, int fCompl)
Definition: vecMem.h:378
Definition: if.h:180
static void Vec_MemFreeP(Vec_Mem_t **p)
Definition: vecMem.h:105
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static ABC_NAMESPACE_IMPL_START If_Obj_t * If_ManSetupObj(If_Man_t *p)
DECLARATIONS ///.
Definition: ifMan.c:522
static void Vec_StrFill(Vec_Str_t *p, int nSize, char Fill)
Definition: vecStr.h:423
static void If_ManCutSetRecycle(If_Man_t *p, If_Set_t *pSet)
Definition: ifMan.c:32
static void Hash_IntManStop(Hash_IntMan_t *p)
Definition: vecHash.h:95
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
if(last==0)
Definition: sparse_int.h:34
static double Vec_MemMemory(Vec_Mem_t *p)
Definition: vecMem.h:175
int nCutsUselessAll
Definition: if.h:241
Vec_Int_t * vArray
Definition: if.h:215
float * pTimesArr
Definition: if.h:161
static If_Obj_t * If_ObjFanin1(If_Obj_t *pObj)
Definition: if.h:381
Vec_Int_t * vCutData
Definition: if.h:260
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
int nSetBytes
Definition: if.h:230
void Tim_ManStop(Tim_Man_t *p)
Definition: timMan.c:375
If_Obj_t * pFanin1
Definition: if.h:322
word * puTempW
Definition: if.h:204
static void Vec_IntFreeP(Vec_Int_t **p)
Definition: vecInt.h:289
int nCountNonDec[2]
Definition: if.h:259
Mem_Fixed_t * pMemEntries
Definition: if.h:269
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
If_Obj_t * pEquiv
Definition: if.h:323
int fUseAndVars
Definition: if.h:136
void If_ManSetupCutTriv(If_Man_t *p, If_Cut_t *pCut, int ObjId)
Definition: ifMan.c:499
float fEpsilon
Definition: if.h:195
static unsigned If_ObjCutSign(unsigned ObjId)
Definition: if.h:402
unsigned Level
Definition: if.h:315
int nVisitsCopy
Definition: if.h:320
Vec_Int_t * vCover
Definition: if.h:214
int nObjBytes
Definition: if.h:228
abctime timeCache[6]
Definition: if.h:257
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int nCacheHits
Definition: if.h:255
#define IF_FLOAT_LARGE
Definition: if.h:440
static int If_ManObjNum(If_Man_t *p)
Definition: if.h:363
Vec_Int_t * vPairRes
Definition: if.h:251
int nPermWords
Definition: if.h:227
int fUseDsd
Definition: if.h:133
Vec_Wrd_t * vOrGate
Definition: if.h:217
static If_Obj_t * If_Regular(If_Obj_t *p)
Definition: if.h:355
If_Par_t * pPars
Definition: if.h:184
Vec_Int_t * vLags
Definition: if.h:221
int uMaskFunc
Definition: if.h:282
Vec_Int_t * vTtDsds[IF_MAX_FUNC_LUTSIZE+1]
Definition: if.h:246
short nCuts
Definition: if.h:297
Vec_Int_t * vCoAttrs
Definition: if.h:264
void If_ManCreateChoice(If_Man_t *p, If_Obj_t *pObj)
Definition: ifMan.c:442
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
Definition: if.h:66
int(* pFuncCell)(If_Man_t *, unsigned *, int, int, char *)
Definition: if.h:165
If_Obj_t * If_ManCreateMux(If_Man_t *p, If_Obj_t *pFan0, If_Obj_t *pFan1, If_Obj_t *pCtrl)
Definition: ifMan.c:423
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int If_CutPermWords(int nVarsMax)
Definition: if.h:395
void Mem_FixedRestart(Mem_Fixed_t *p)
Definition: mem.c:239
struct If_Cut_t_ If_Cut_t
Definition: if.h:79
int fDelayOpt
Definition: if.h:121
static void Vec_PtrFreeP(Vec_Ptr_t **p)
Definition: vecPtr.h:240
int fUseBat
Definition: if.h:126
Definition: if.h:294
unsigned uSign
Definition: if.h:283
int nVisits
Definition: if.h:319
int fCutMin
Definition: if.h:120
struct If_Set_t_ If_Set_t
Definition: if.h:80
int fUseTtPerm
Definition: if.h:137
static void Vec_WecFreeP(Vec_Wec_t **p)
Definition: vecWec.h:350
static void Vec_MemHashFree(Vec_Mem_t *p)
Definition: vecMem.h:311
int Bat_ManCellFuncLookup(void *pMan, unsigned *pTruth, int nVars, int nLeaves, char *pStr)
Definition: ifMatch2.c:51
If_Man_t * If_ManStart(If_Par_t *pPars)
FUNCTION DEFINITIONS ///.
Definition: ifMan.c:50
int nObjs[IF_VOID]
Definition: if.h:192
void If_ManSetupSetAll(If_Man_t *p, int nCrossCut)
Definition: ifMan.c:675
If_Obj_t * If_ManCreateXor(If_Man_t *p, If_Obj_t *pFan0, If_Obj_t *pFan1)
Definition: ifMan.c:404
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
Vec_Ptr_t * vCos
Definition: if.h:188
int nCutBytes
Definition: if.h:229
int nCutsMax
Definition: if.h:104
int nCutsCount[32]
Definition: if.h:239
If_Obj_t * If_ManCreateAnd(If_Man_t *p, If_Obj_t *pFan0, If_Obj_t *pFan1)
Definition: ifMan.c:366
If_Cut_t ** ppCuts
Definition: if.h:299
unsigned fCompl
Definition: if.h:285
Vec_Ptr_t * vLatchOrder
Definition: if.h:220
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
If_Set_t * pMemAnd
Definition: if.h:234
void If_ManRestart(If_Man_t *p)
Definition: ifMan.c:178
static int If_IsComplement(If_Obj_t *p)
Definition: if.h:358
int fLiftLeaves
Definition: if.h:156
Definition: if.h:65
If_Set_t * pFreeList
Definition: if.h:235
char * Mem_FixedEntryFetch(Mem_Fixed_t *p)
Definition: mem.c:168
unsigned fCompl1
Definition: if.h:307
unsigned fCompl0
Definition: if.h:306
int iCutFunc
Definition: if.h:281
unsigned fPhase
Definition: if.h:308
If_Obj_t * pConst1
Definition: if.h:186
Vec_Str_t * vPairPerms
Definition: if.h:252
static void Vec_StrFreeP(Vec_Str_t **p)
Definition: vecStr.h:233
int IdPio
Definition: if.h:317
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
static void Vec_WecInit(Vec_Wec_t *p, int nSize)
Definition: vecWec.h:125
If_Set_t * pNext
Definition: if.h:298