abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcLut.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcLut.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Superchoicing for K-LUTs.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcLut.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "opt/cut/cut.h"
23 
25 
26 #define LARGE_LEVEL 1000000
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 #define SCL_LUT_MAX 6 // the maximum LUT size
33 #define SCL_VARS_MAX 15 // the maximum number of variables
34 #define SCL_NODE_MAX 1000 // the maximum number of nodes
35 
36 typedef struct Abc_ManScl_t_ Abc_ManScl_t;
38 {
39  // paramers
40  int nLutSize; // the LUT size
41  int nCutSizeMax; // the max number of leaves of the cone
42  int nNodesMax; // the max number of divisors in the cone
43  int nWords; // the number of machine words in sim info
44  // structural representation of the cone
45  Vec_Ptr_t * vLeaves; // leaves of the cut
46  Vec_Ptr_t * vVolume; // volume of the cut
47  int pBSet[SCL_VARS_MAX]; // bound set
48  // functional representation of the cone
49  unsigned * uTruth; // truth table of the cone
50  // representation of truth tables
51  unsigned ** uVars; // elementary truth tables
52  unsigned ** uSims; // truth tables of the nodes
53  unsigned ** uCofs; // truth tables of the cofactors
54 };
55 
56 static Vec_Ptr_t * s_pLeaves = NULL;
57 
58 static Cut_Man_t * Abc_NtkStartCutManForScl( Abc_Ntk_t * pNtk, int nLutSize );
59 static Abc_ManScl_t * Abc_ManSclStart( int nLutSize, int nCutSizeMax, int nNodesMax );
60 static void Abc_ManSclStop( Abc_ManScl_t * p );
61 static void Abc_NodeLutMap( Cut_Man_t * pManCuts, Abc_Obj_t * pObj );
62 
63 static Abc_Obj_t * Abc_NodeSuperChoiceLut( Abc_ManScl_t * pManScl, Abc_Obj_t * pObj );
64 static int Abc_NodeDecomposeStep( Abc_ManScl_t * pManScl );
65 
66 ////////////////////////////////////////////////////////////////////////
67 /// FUNCTION DEFINITIONS ///
68 ////////////////////////////////////////////////////////////////////////
69 
70 /**Function*************************************************************
71 
72  Synopsis [Performs superchoicing for K-LUTs.]
73 
74  Description []
75 
76  SideEffects []
77 
78  SeeAlso []
79 
80 ***********************************************************************/
81 int Abc_NtkSuperChoiceLut( Abc_Ntk_t * pNtk, int nLutSize, int nCutSizeMax, int fVerbose )
82 {
83  ProgressBar * pProgress;
84  Abc_ManCut_t * pManCut;
85  Abc_ManScl_t * pManScl;
86  Cut_Man_t * pManCuts;
87  Abc_Obj_t * pObj, * pFanin, * pObjTop;
88  int i, LevelMax, nNodes;
89  int nNodesTried, nNodesDec, nNodesExist, nNodesUsed;
90 
91  assert( Abc_NtkIsSopLogic(pNtk) );
92  if ( nLutSize < 3 || nLutSize > SCL_LUT_MAX )
93  {
94  printf( "LUT size (%d) does not belong to the interval: 3 <= LUT size <= %d\n", nLutSize, SCL_LUT_MAX );
95  return 0;
96  }
97  if ( nCutSizeMax <= nLutSize || nCutSizeMax > SCL_VARS_MAX )
98  {
99  printf( "Cut size (%d) does not belong to the interval: LUT size (%d) < Cut size <= %d\n", nCutSizeMax, nLutSize, SCL_VARS_MAX );
100  return 0;
101  }
102 
103  assert( nLutSize <= SCL_LUT_MAX );
104  assert( nCutSizeMax <= SCL_VARS_MAX );
105  nNodesTried = nNodesDec = nNodesExist = nNodesUsed = 0;
106 
107  // set the delays of the CIs
108  Abc_NtkForEachCi( pNtk, pObj, i )
109  pObj->Level = 0;
110 
111 //Abc_NtkLevel( pNtk );
112 
113  // start the managers
114  pManScl = Abc_ManSclStart( nLutSize, nCutSizeMax, 1000 );
115  pManCuts = Abc_NtkStartCutManForScl( pNtk, nLutSize );
116  pManCut = Abc_NtkManCutStart( nCutSizeMax, 100000, 100000, 100000 );
118  pManScl->vVolume = Abc_NtkManCutReadVisited( pManCut );
119 
120  // process each internal node (assuming topological order of nodes!!!)
121  nNodes = Abc_NtkObjNumMax(pNtk);
122  pProgress = Extra_ProgressBarStart( stdout, nNodes );
123  Abc_NtkForEachObj( pNtk, pObj, i )
124  {
125 // if ( i != nNodes-1 )
126 // continue;
127  Extra_ProgressBarUpdate( pProgress, i, NULL );
128  if ( i >= nNodes )
129  break;
130  if ( Abc_ObjFaninNum(pObj) != 2 )
131  continue;
132  nNodesTried++;
133 
134  // map this node using regular cuts
135 // pObj->Level = 0;
136  Abc_NodeLutMap( pManCuts, pObj );
137  // compute the cut
138  pManScl->vLeaves = Abc_NodeFindCut( pManCut, pObj, 0 );
139  if ( Vec_PtrSize(pManScl->vLeaves) <= nLutSize )
140  continue;
141  // get the volume of the cut
142  if ( Vec_PtrSize(pManScl->vVolume) > SCL_NODE_MAX )
143  continue;
144  nNodesDec++;
145 
146  // decompose the cut
147  pObjTop = Abc_NodeSuperChoiceLut( pManScl, pObj );
148  if ( pObjTop == NULL )
149  continue;
150  nNodesExist++;
151 
152  // if there is no delay improvement, skip; otherwise, update level
153  if ( pObjTop->Level >= pObj->Level )
154  {
155  Abc_NtkDeleteObj_rec( pObjTop, 1 );
156  continue;
157  }
158  pObj->Level = pObjTop->Level;
159  nNodesUsed++;
160  }
161  Extra_ProgressBarStop( pProgress );
162 
163  // delete the managers
164  Abc_ManSclStop( pManScl );
165  Abc_NtkManCutStop( pManCut );
166  Cut_ManStop( pManCuts );
167 
168  // get the largest arrival time
169  LevelMax = 0;
170  Abc_NtkForEachCo( pNtk, pObj, i )
171  {
172  pFanin = Abc_ObjFanin0( pObj );
173  // skip inv/buf
174  if ( Abc_ObjFaninNum(pFanin) == 1 )
175  pFanin = Abc_ObjFanin0( pFanin );
176  // get the new level
177  LevelMax = Abc_MaxInt( LevelMax, (int)pFanin->Level );
178  }
179 
180  if ( fVerbose )
181  printf( "Try = %d. Dec = %d. Exist = %d. Use = %d. SUPER = %d levels of %d-LUTs.\n",
182  nNodesTried, nNodesDec, nNodesExist, nNodesUsed, LevelMax, nLutSize );
183 // if ( fVerbose )
184 // printf( "The network is superchoiced for %d levels of %d-LUTs.\n", LevelMax, nLutSize );
185 
186  // clean the data field
187  Abc_NtkForEachObj( pNtk, pObj, i )
188  pObj->pNext = NULL;
189 
190  // check
191  if ( !Abc_NtkCheck( pNtk ) )
192  {
193  printf( "Abc_NtkSuperChoiceLut: The network check has failed.\n" );
194  return 0;
195  }
196  return 1;
197 }
198 
199 /**Function*************************************************************
200 
201  Synopsis [Performs LUT mapping of the node.]
202 
203  Description []
204 
205  SideEffects []
206 
207  SeeAlso []
208 
209 ***********************************************************************/
210 void Abc_NodeLutMap( Cut_Man_t * pManCuts, Abc_Obj_t * pObj )
211 {
212  Cut_Cut_t * pCut;
213  Abc_Obj_t * pFanin;
214  int i, DelayMax;
215  pCut = (Cut_Cut_t *)Abc_NodeGetCutsRecursive( pManCuts, pObj, 0, 0 );
216  assert( pCut != NULL );
217  assert( pObj->Level == 0 );
218  // go through the cuts
219  pObj->Level = LARGE_LEVEL;
220  for ( pCut = pCut->pNext; pCut; pCut = pCut->pNext )
221  {
222  DelayMax = 0;
223  for ( i = 0; i < (int)pCut->nLeaves; i++ )
224  {
225  pFanin = Abc_NtkObj( pObj->pNtk, pCut->pLeaves[i] );
226 // assert( Abc_ObjIsCi(pFanin) || pFanin->Level > 0 ); // should hold if node ordering is topological
227  if ( DelayMax < (int)pFanin->Level )
228  DelayMax = pFanin->Level;
229  }
230  if ( (int)pObj->Level > DelayMax )
231  pObj->Level = DelayMax;
232  }
233  assert( pObj->Level < LARGE_LEVEL );
234  pObj->Level++;
235 // printf( "%d(%d) ", pObj->Id, pObj->Level );
236 }
237 
238 /**Function*************************************************************
239 
240  Synopsis [Starts the cut manager for rewriting.]
241 
242  Description []
243 
244  SideEffects []
245 
246  SeeAlso []
247 
248 ***********************************************************************/
250 {
251  static Cut_Params_t Params, * pParams = &Params;
252  Cut_Man_t * pManCut;
253  Abc_Obj_t * pObj;
254  int i;
255  // start the cut manager
256  memset( pParams, 0, sizeof(Cut_Params_t) );
257  pParams->nVarsMax = nLutSize; // the max cut size ("k" of the k-feasible cuts)
258  pParams->nKeepMax = 500; // the max number of cuts kept at a node
259  pParams->fTruth = 0; // compute truth tables
260  pParams->fFilter = 1; // filter dominated cuts
261  pParams->fSeq = 0; // compute sequential cuts
262  pParams->fDrop = 0; // drop cuts on the fly
263  pParams->fVerbose = 0; // the verbosiness flag
264  pParams->nIdsMax = Abc_NtkObjNumMax( pNtk );
265  pManCut = Cut_ManStart( pParams );
266  if ( pParams->fDrop )
268  // set cuts for PIs
269  Abc_NtkForEachCi( pNtk, pObj, i )
270  if ( Abc_ObjFanoutNum(pObj) > 0 )
271  Cut_NodeSetTriv( pManCut, pObj->Id );
272  return pManCut;
273 }
274 
275 /**Function*************************************************************
276 
277  Synopsis [Starts the manager.]
278 
279  Description []
280 
281  SideEffects []
282 
283  SeeAlso []
284 
285 ***********************************************************************/
286 Abc_ManScl_t * Abc_ManSclStart( int nLutSize, int nCutSizeMax, int nNodesMax )
287 {
288  Abc_ManScl_t * p;
289  int i, k;
290  assert( sizeof(unsigned) == 4 );
291  p = ABC_ALLOC( Abc_ManScl_t, 1 );
292  memset( p, 0, sizeof(Abc_ManScl_t) );
293  p->nLutSize = nLutSize;
294  p->nCutSizeMax = nCutSizeMax;
295  p->nNodesMax = nNodesMax;
296  p->nWords = Extra_TruthWordNum(nCutSizeMax);
297  // allocate simulation info
298  p->uVars = (unsigned **)Extra_ArrayAlloc( nCutSizeMax, p->nWords, 4 );
299  p->uSims = (unsigned **)Extra_ArrayAlloc( nNodesMax, p->nWords, 4 );
300  p->uCofs = (unsigned **)Extra_ArrayAlloc( 2 << nLutSize, p->nWords, 4 );
301  memset( p->uVars[0], 0, nCutSizeMax * p->nWords * 4 );
302  // assign elementary truth tables
303  for ( k = 0; k < p->nCutSizeMax; k++ )
304  for ( i = 0; i < p->nWords * 32; i++ )
305  if ( i & (1 << k) )
306  p->uVars[k][i>>5] |= (1 << (i&31));
307  // other data structures
308 // p->vBound = Vec_IntAlloc( nCutSizeMax );
309  return p;
310 }
311 
312 /**Function*************************************************************
313 
314  Synopsis [Stops the manager.]
315 
316  Description []
317 
318  SideEffects []
319 
320  SeeAlso []
321 
322 ***********************************************************************/
324 {
325 // Vec_IntFree( p->vBound );
326  ABC_FREE( p->uVars );
327  ABC_FREE( p->uSims );
328  ABC_FREE( p->uCofs );
329  ABC_FREE( p );
330 }
331 
332 
333 /**Function*************************************************************
334 
335  Synopsis [Performs superchoicing for one node.]
336 
337  Description []
338 
339  SideEffects []
340 
341  SeeAlso []
342 
343 ***********************************************************************/
344 unsigned * Abc_NodeSuperChoiceTruth( Abc_ManScl_t * pManScl )
345 {
346  Abc_Obj_t * pObj;
347  unsigned * puData0, * puData1, * puData = NULL;
348  char * pSop;
349  int i, k;
350  // set elementary truth tables
351  Vec_PtrForEachEntry( Abc_Obj_t *, pManScl->vLeaves, pObj, i )
352  pObj->pNext = (Abc_Obj_t *)pManScl->uVars[i];
353  // compute truth tables for internal nodes
354  Vec_PtrForEachEntry( Abc_Obj_t *, pManScl->vVolume, pObj, i )
355  {
356  // set storage for the node's simulation info
357  pObj->pNext = (Abc_Obj_t *)pManScl->uSims[i];
358  // get pointer to the simulation info
359  puData = (unsigned *)pObj->pNext;
360  puData0 = (unsigned *)Abc_ObjFanin0(pObj)->pNext;
361  puData1 = (unsigned *)Abc_ObjFanin1(pObj)->pNext;
362  // simulate
363  pSop = (char *)pObj->pData;
364  if ( pSop[0] == '0' && pSop[1] == '0' )
365  for ( k = 0; k < pManScl->nWords; k++ )
366  puData[k] = ~puData0[k] & ~puData1[k];
367  else if ( pSop[0] == '0' )
368  for ( k = 0; k < pManScl->nWords; k++ )
369  puData[k] = ~puData0[k] & puData1[k];
370  else if ( pSop[1] == '0' )
371  for ( k = 0; k < pManScl->nWords; k++ )
372  puData[k] = puData0[k] & ~puData1[k];
373  else
374  for ( k = 0; k < pManScl->nWords; k++ )
375  puData[k] = puData0[k] & puData1[k];
376  }
377  return puData;
378 }
379 
380 /**Function*************************************************************
381 
382  Synopsis [Performs superchoicing for one node.]
383 
384  Description []
385 
386  SideEffects []
387 
388  SeeAlso []
389 
390 ***********************************************************************/
392 {
393  if ( pObj->fMarkC )
394  return;
395  pObj->fMarkC = 1;
396  assert( Abc_ObjFaninNum(pObj) == 2 );
399  Vec_PtrPush( vVolume, pObj );
400 }
401 
402 /**Function*************************************************************
403 
404  Synopsis [Performs superchoicing for one node.]
405 
406  Description []
407 
408  SideEffects []
409 
410  SeeAlso []
411 
412 ***********************************************************************/
413 void Abc_NodeSuperChoiceCollect2( Abc_Obj_t * pRoot, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vVolume )
414 {
415  Abc_Obj_t * pObj;
416  int i;
417  Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
418  pObj->fMarkC = 1;
419  Vec_PtrClear( vVolume );
420  Abc_NodeSuperChoiceCollect2_rec( pRoot, vVolume );
421  Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
422  pObj->fMarkC = 0;
423  Vec_PtrForEachEntry( Abc_Obj_t *, vVolume, pObj, i )
424  pObj->fMarkC = 0;
425 }
426 
427 /**Function*************************************************************
428 
429  Synopsis [Performs superchoicing for one node.]
430 
431  Description []
432 
433  SideEffects []
434 
435  SeeAlso []
436 
437 ***********************************************************************/
438 void Abc_NodeSuperChoiceCollect_rec( Abc_Obj_t * pObj, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vVolume )
439 {
440  if ( pObj->fMarkB )
441  {
442  Vec_PtrPush( vLeaves, pObj );
443  pObj->fMarkB = 0;
444  }
445  if ( pObj->fMarkC )
446  return;
447  pObj->fMarkC = 1;
448  assert( Abc_ObjFaninNum(pObj) == 2 );
449  Abc_NodeSuperChoiceCollect_rec( Abc_ObjFanin0(pObj), vLeaves, vVolume );
450  Abc_NodeSuperChoiceCollect_rec( Abc_ObjFanin1(pObj), vLeaves, vVolume );
451  Vec_PtrPush( vVolume, pObj );
452 }
453 
454 /**Function*************************************************************
455 
456  Synopsis [Performs superchoicing for one node.]
457 
458  Description [Orders the leaves topologically.]
459 
460  SideEffects []
461 
462  SeeAlso []
463 
464 ***********************************************************************/
465 void Abc_NodeSuperChoiceCollect( Abc_Obj_t * pRoot, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vVolume )
466 {
467  Abc_Obj_t * pObj;
468  int i, nLeaves;
469  nLeaves = Vec_PtrSize(vLeaves);
470  Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
471  pObj->fMarkB = pObj->fMarkC = 1;
472  Vec_PtrClear( vVolume );
473  Vec_PtrClear( vLeaves );
474  Abc_NodeSuperChoiceCollect_rec( pRoot, vLeaves, vVolume );
475  assert( Vec_PtrSize(vLeaves) == nLeaves );
476  Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
477  pObj->fMarkC = 0;
478  Vec_PtrForEachEntry( Abc_Obj_t *, vVolume, pObj, i )
479  pObj->fMarkC = 0;
480 }
481 
482 /**Function*************************************************************
483 
484  Synopsis [Performs superchoicing for one node.]
485 
486  Description []
487 
488  SideEffects []
489 
490  SeeAlso []
491 
492 ***********************************************************************/
493 void Abc_NodeLeavesRemove( Vec_Ptr_t * vLeaves, unsigned uPhase, int nVars )
494 {
495  int i;
496  for ( i = nVars - 1; i >= 0; i-- )
497  if ( uPhase & (1 << i) )
498  Vec_PtrRemove( vLeaves, Vec_PtrEntry(vLeaves, i) );
499 }
500 
501 /**Function*************************************************************
502 
503  Synopsis [Performs superchoicing for one node.]
504 
505  Description []
506 
507  SideEffects []
508 
509  SeeAlso []
510 
511 ***********************************************************************/
513 {
514  Abc_Obj_t * pFanin;
515  int i, Level;
516  Level = 0;
517  Abc_ObjForEachFanin( pObj, pFanin, i )
518  Level = Abc_MaxInt( Level, (int)pFanin->Level );
519  return Level + 1;
520 }
521 
522 /**Function*************************************************************
523 
524  Synopsis [Performs superchoicing for one node.]
525 
526  Description []
527 
528  SideEffects []
529 
530  SeeAlso []
531 
532 ***********************************************************************/
534 {
535  Abc_Obj_t * pFanin, * pObjNew;
536  int i, nVars, uSupport, nSuppVars;
537  // collect the cone using DFS (excluding leaves)
539  assert( Vec_PtrEntryLast(p->vVolume) == pObj );
540  // compute the truth table
542  // get the support of this truth table
543  nVars = Vec_PtrSize(p->vLeaves);
544  uSupport = Extra_TruthSupport(p->uTruth, nVars);
545  nSuppVars = Extra_WordCountOnes(uSupport);
546  assert( nSuppVars <= nVars );
547  if ( nSuppVars == 0 )
548  {
549  pObj->Level = 0;
550  return NULL;
551  }
552  if ( nSuppVars == 1 )
553  {
554  // find the variable
555  for ( i = 0; i < nVars; i++ )
556  if ( uSupport & (1 << i) )
557  break;
558  assert( i < nVars );
559  pFanin = (Abc_Obj_t *)Vec_PtrEntry( p->vLeaves, i );
560  pObj->Level = pFanin->Level;
561  return NULL;
562  }
563  // support-minimize the truth table
564  if ( nSuppVars != nVars )
565  {
566  Extra_TruthShrink( p->uCofs[0], p->uTruth, nSuppVars, nVars, uSupport );
567  Extra_TruthCopy( p->uTruth, p->uCofs[0], nVars );
568  Abc_NodeLeavesRemove( p->vLeaves, ((1 << nVars) - 1) & ~uSupport, nVars );
569  }
570 // return NULL;
571  // decompose the truth table recursively
572  while ( Vec_PtrSize(p->vLeaves) > p->nLutSize )
573  if ( !Abc_NodeDecomposeStep( p ) )
574  {
575  Vec_PtrForEachEntry( Abc_Obj_t *, p->vLeaves, pFanin, i )
576  if ( Abc_ObjIsNode(pFanin) && Abc_ObjFanoutNum(pFanin) == 0 )
577  Abc_NtkDeleteObj_rec( pFanin, 1 );
578  return NULL;
579  }
580  // create the topmost node
581  pObjNew = Abc_NtkCreateNode( pObj->pNtk );
582  Vec_PtrForEachEntry( Abc_Obj_t *, p->vLeaves, pFanin, i )
583  Abc_ObjAddFanin( pObjNew, pFanin );
584  // create the function
585  pObjNew->pData = Abc_SopCreateFromTruth( (Mem_Flex_t *)pObj->pNtk->pManFunc, Vec_PtrSize(p->vLeaves), p->uTruth ); // need ISOP
586  pObjNew->Level = Abc_NodeGetLevel( pObjNew );
587  return pObjNew;
588 }
589 
590 /**Function*************************************************************
591 
592  Synopsis [Procedure used for sorting the nodes in increasing order of levels.]
593 
594  Description []
595 
596  SideEffects []
597 
598  SeeAlso []
599 
600 ***********************************************************************/
601 int Abc_NodeCompareLevelsInc( int * pp1, int * pp2 )
602 {
603  Abc_Obj_t * pNode1, * pNode2;
604  pNode1 = (Abc_Obj_t *)Vec_PtrEntry(s_pLeaves, *pp1);
605  pNode2 = (Abc_Obj_t *)Vec_PtrEntry(s_pLeaves, *pp2);
606  if ( pNode1->Level < pNode2->Level )
607  return -1;
608  if ( pNode1->Level > pNode2->Level )
609  return 1;
610  return 0;
611 }
612 
613 /**Function*************************************************************
614 
615  Synopsis [Selects the earliest arriving nodes from the array.]
616 
617  Description []
618 
619  SideEffects []
620 
621  SeeAlso []
622 
623 ***********************************************************************/
624 void Abc_NodeDecomposeSort( Abc_Obj_t ** pLeaves, int nVars, int * pBSet, int nLutSize )
625 {
626  Abc_Obj_t * pTemp[SCL_VARS_MAX];
627  int i, k, kBest, LevelMin;
628  assert( nLutSize < nVars );
629  assert( nVars <= SCL_VARS_MAX );
630  // copy nodes into the internal storage
631 // printf( "(" );
632  for ( i = 0; i < nVars; i++ )
633  {
634  pTemp[i] = pLeaves[i];
635 // printf( " %d", pLeaves[i]->Level );
636  }
637 // printf( " )\n" );
638  // choose one node at a time
639  for ( i = 0; i < nLutSize; i++ )
640  {
641  kBest = -1;
642  LevelMin = LARGE_LEVEL;
643  for ( k = 0; k < nVars; k++ )
644  if ( pTemp[k] && LevelMin > (int)pTemp[k]->Level )
645  {
646  LevelMin = pTemp[k]->Level;
647  kBest = k;
648  }
649  pBSet[i] = kBest;
650  pTemp[kBest] = NULL;
651  }
652 }
653 
654 /**Function*************************************************************
655 
656  Synopsis [Performs superchoicing for one node.]
657 
658  Description []
659 
660  SideEffects []
661 
662  SeeAlso []
663 
664 ***********************************************************************/
666 {
667  static char pCofClasses[1<<SCL_LUT_MAX][1<<SCL_LUT_MAX];
668  static char nCofClasses[1<<SCL_LUT_MAX];
669  Abc_Ntk_t * pNtk;
670  Abc_Obj_t * pObjNew, * pFanin, * pNodesNew[SCL_LUT_MAX];
671  unsigned * pTruthCof, * pTruthClass, * pTruth, uPhase;
672  int i, k, c, v, w, nVars, nVarsNew, nClasses, nCofs;
673  // set the network
674  pNtk = ((Abc_Obj_t *)Vec_PtrEntry(p->vLeaves, 0))->pNtk;
675  // find the earliest nodes
676  nVars = Vec_PtrSize(p->vLeaves);
677  assert( nVars > p->nLutSize );
678 /*
679  for ( v = 0; v < nVars; v++ )
680  p->pBSet[v] = v;
681  qsort( (void *)p->pBSet, nVars, sizeof(int),
682  (int (*)(const void *, const void *)) Abc_NodeCompareLevelsInc );
683 */
685  assert( ((Abc_Obj_t *)Vec_PtrEntry(p->vLeaves, p->pBSet[0]))->Level <=
686  ((Abc_Obj_t *)Vec_PtrEntry(p->vLeaves, p->pBSet[1]))->Level );
687  // cofactor w.r.t. the selected variables
688  Extra_TruthCopy( p->uCofs[1], p->uTruth, nVars );
689  c = 2;
690  for ( v = 0; v < p->nLutSize; v++ )
691  for ( k = 0; k < (1<<v); k++ )
692  {
693  Extra_TruthCopy( p->uCofs[c], p->uCofs[c/2], nVars );
694  Extra_TruthCopy( p->uCofs[c+1], p->uCofs[c/2], nVars );
695  Extra_TruthCofactor0( p->uCofs[c], nVars, p->pBSet[v] );
696  Extra_TruthCofactor1( p->uCofs[c+1], nVars, p->pBSet[v] );
697  c += 2;
698  }
699  assert( c == (2 << p->nLutSize) );
700  // count unique cofactors
701  nClasses = 0;
702  nCofs = (1 << p->nLutSize);
703  for ( i = 0; i < nCofs; i++ )
704  {
705  pTruthCof = p->uCofs[ nCofs + i ];
706  for ( k = 0; k < nClasses; k++ )
707  {
708  pTruthClass = p->uCofs[ nCofs + pCofClasses[k][0] ];
709  if ( Extra_TruthIsEqual( pTruthCof, pTruthClass, nVars ) )
710  {
711  pCofClasses[k][(int)nCofClasses[k]++ ] = i;
712  break;
713  }
714  }
715  if ( k != nClasses )
716  continue;
717  // not found
718  pCofClasses[nClasses][0] = i;
719  nCofClasses[nClasses] = 1;
720  nClasses++;
721  if ( nClasses > nCofs/2 )
722  return 0;
723  }
724  // the number of cofactors is acceptable
725  nVarsNew = Abc_Base2Log( nClasses );
726  assert( nVarsNew < p->nLutSize );
727  // create the remainder truth table
728  // for each class of cofactors, multiply cofactor truth table by its code
729  Extra_TruthClear( p->uTruth, nVars );
730  for ( k = 0; k < nClasses; k++ )
731  {
732  pTruthClass = p->uCofs[ nCofs + pCofClasses[k][0] ];
733  for ( v = 0; v < nVarsNew; v++ )
734  if ( k & (1 << v) )
735  Extra_TruthAnd( pTruthClass, pTruthClass, p->uVars[p->pBSet[v]], nVars );
736  else
737  Extra_TruthSharp( pTruthClass, pTruthClass, p->uVars[p->pBSet[v]], nVars );
738  Extra_TruthOr( p->uTruth, p->uTruth, pTruthClass, nVars );
739  }
740  // create nodes
741  pTruth = p->uCofs[0];
742  for ( v = 0; v < nVarsNew; v++ )
743  {
744  Extra_TruthClear( pTruth, p->nLutSize );
745  for ( k = 0; k < nClasses; k++ )
746  if ( k & (1 << v) )
747  for ( i = 0; i < nCofClasses[k]; i++ )
748  {
749  pTruthCof = p->uCofs[1];
750  Extra_TruthFill( pTruthCof, p->nLutSize );
751  for ( w = 0; w < p->nLutSize; w++ )
752  if ( pCofClasses[k][i] & (1 << (p->nLutSize-1-w)) )
753  Extra_TruthAnd( pTruthCof, pTruthCof, p->uVars[w], p->nLutSize );
754  else
755  Extra_TruthSharp( pTruthCof, pTruthCof, p->uVars[w], p->nLutSize );
756  Extra_TruthOr( pTruth, pTruth, pTruthCof, p->nLutSize );
757  }
758  // implement the node
759  pObjNew = Abc_NtkCreateNode( pNtk );
760  for ( i = 0; i < p->nLutSize; i++ )
761  {
762  pFanin = (Abc_Obj_t *)Vec_PtrEntry( p->vLeaves, p->pBSet[i] );
763  Abc_ObjAddFanin( pObjNew, pFanin );
764  }
765  // create the function
766  pObjNew->pData = Abc_SopCreateFromTruth( (Mem_Flex_t *)pNtk->pManFunc, p->nLutSize, pTruth ); // need ISOP
767  pObjNew->Level = Abc_NodeGetLevel( pObjNew );
768  pNodesNew[v] = pObjNew;
769  }
770  // put the new nodes back into the list
771  for ( v = 0; v < nVarsNew; v++ )
772  Vec_PtrWriteEntry( p->vLeaves, p->pBSet[v], pNodesNew[v] );
773  // compute the variables that should be removed
774  uPhase = 0;
775  for ( v = nVarsNew; v < p->nLutSize; v++ )
776  uPhase |= (1 << p->pBSet[v]);
777  // remove entries from the array
778  Abc_NodeLeavesRemove( p->vLeaves, uPhase, nVars );
779  // update truth table
780  Extra_TruthShrink( p->uCofs[0], p->uTruth, nVars - p->nLutSize + nVarsNew, nVars, ((1 << nVars) - 1) & ~uPhase );
781  Extra_TruthCopy( p->uTruth, p->uCofs[0], nVars );
782  assert( !Extra_TruthVarInSupport( p->uTruth, nVars, nVars - p->nLutSize + nVarsNew ) );
783  return 1;
784 }
785 
786 ////////////////////////////////////////////////////////////////////////
787 /// END OF FILE ///
788 ////////////////////////////////////////////////////////////////////////
789 
791 
792 
793 
char * memset()
static void Extra_TruthOr(unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: extra.h:332
int Abc_NtkSuperChoiceLut(Abc_Ntk_t *pNtk, int nLutSize, int nCutSizeMax, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: abcLut.c:81
static void Abc_ManSclStop(Abc_ManScl_t *p)
Definition: abcLut.c:323
void Abc_NodeSuperChoiceCollect2(Abc_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
Definition: abcLut.c:413
void Abc_NodeDecomposeSort(Abc_Obj_t **pLeaves, int nVars, int *pBSet, int nLutSize)
Definition: abcLut.c:624
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
static void Extra_TruthClear(unsigned *pOut, int nVars)
Definition: extra.h:308
int Abc_NodeCompareLevelsInc(int *pp1, int *pp2)
Definition: abcLut.c:601
#define SCL_NODE_MAX
Definition: abcLut.c:34
unsigned * uTruth
Definition: abcLut.c:49
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Vec_Ptr_t * vVolume
Definition: abcLut.c:46
int nWords
Definition: abcLut.c:43
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
static int Abc_NodeDecomposeStep(Abc_ManScl_t *pManScl)
Definition: abcLut.c:665
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
Cut_Cut_t * pNext
Definition: cut.h:88
ABC_DLL void Abc_NtkDeleteObj_rec(Abc_Obj_t *pObj, int fOnlyNodes)
Definition: abcObj.c:273
void ** Extra_ArrayAlloc(int nCols, int nRows, int Size)
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
ABC_DLL Vec_Ptr_t * Abc_NtkManCutReadVisited(Abc_ManCut_t *p)
Definition: abcReconv.c:669
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
static int Abc_NtkIsSopLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:264
void Cut_NodeSetTriv(Cut_Man_t *p, int Node)
Definition: cutApi.c:145
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static Abc_Obj_t * Abc_NtkObj(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:314
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
void Cut_ManSetFanoutCounts(Cut_Man_t *p, Vec_Int_t *vFanCounts)
Definition: cutMan.c:229
int nCutSizeMax
Definition: abcLut.c:41
static void Vec_PtrRemove(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:714
unsigned Level
Definition: abc.h:142
ABC_DLL Vec_Ptr_t * Abc_NodeFindCut(Abc_ManCut_t *p, Abc_Obj_t *pRoot, int fContain)
Definition: abcReconv.c:253
void Extra_TruthCofactor1(unsigned *pTruth, int nVars, int iVar)
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
void Abc_NodeLeavesRemove(Vec_Ptr_t *vLeaves, unsigned uPhase, int nVars)
Definition: abcLut.c:493
int nNodesMax
Definition: abcLut.c:42
void * pManFunc
Definition: abc.h:191
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
int pLeaves[0]
Definition: cut.h:89
unsigned nLeaves
Definition: cut.h:84
DECLARATIONS ///.
static Abc_ManScl_t * Abc_ManSclStart(int nLutSize, int nCutSizeMax, int nNodesMax)
Definition: abcLut.c:286
static void * Vec_PtrEntryLast(Vec_Ptr_t *p)
Definition: vecPtr.h:413
int Extra_TruthSupport(unsigned *pTruth, int nVars)
unsigned fMarkC
Definition: abc.h:136
ABC_DLL Vec_Ptr_t * Abc_NtkManCutReadCutSmall(Abc_ManCut_t *p)
Definition: abcReconv.c:653
void Cut_ManStop(Cut_Man_t *p)
Definition: cutMan.c:124
Cut_Man_t * Cut_ManStart(Cut_Params_t *pParams)
FUNCTION DEFINITIONS ///.
Definition: cutMan.c:47
static void Extra_TruthFill(unsigned *pOut, int nVars)
Definition: extra.h:314
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
if(last==0)
Definition: sparse_int.h:34
ABC_DLL void * Abc_NodeGetCutsRecursive(void *p, Abc_Obj_t *pObj, int fDag, int fTree)
void Abc_NodeSuperChoiceCollect(Abc_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
Definition: abcLut.c:465
static void Extra_TruthAnd(unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: extra.h:326
static void Extra_TruthSharp(unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: extra.h:338
void Extra_ProgressBarStop(ProgressBar *p)
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
static int Extra_TruthIsEqual(unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: extra.h:270
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int nLutSize
Definition: abcLut.c:40
unsigned ** uCofs
Definition: abcLut.c:53
void Abc_NodeSuperChoiceCollect_rec(Abc_Obj_t *pObj, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
Definition: abcLut.c:438
ABC_DLL char * Abc_SopCreateFromTruth(Mem_Flex_t *pMan, int nVars, unsigned *pTruth)
Definition: abcSop.c:377
Abc_Ntk_t * pNtk
Definition: abc.h:130
unsigned fMarkB
Definition: abc.h:135
int Extra_TruthVarInSupport(unsigned *pTruth, int nVars, int iVar)
void Abc_NodeSuperChoiceCollect2_rec(Abc_Obj_t *pObj, Vec_Ptr_t *vVolume)
Definition: abcLut.c:391
#define LARGE_LEVEL
Definition: abcLut.c:26
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition: abc.h:515
static Cut_Man_t * Abc_NtkStartCutManForScl(Abc_Ntk_t *pNtk, int nLutSize)
Definition: abcLut.c:249
static Abc_Obj_t * Abc_NodeSuperChoiceLut(Abc_ManScl_t *pManScl, Abc_Obj_t *pObj)
Definition: abcLut.c:533
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Id
Definition: abc.h:132
static int Abc_Base2Log(unsigned n)
Definition: abc_global.h:251
int Abc_NodeGetLevel(Abc_Obj_t *pObj)
Definition: abcLut.c:512
unsigned ** uSims
Definition: abcLut.c:52
static Abc_Obj_t * Abc_NtkCreateNode(Abc_Ntk_t *pNtk)
Definition: abc.h:308
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
unsigned * Abc_NodeSuperChoiceTruth(Abc_ManScl_t *pManScl)
Definition: abcLut.c:344
static int Extra_WordCountOnes(unsigned uWord)
Definition: extra.h:255
ABC_DLL Abc_ManCut_t * Abc_NtkManCutStart(int nNodeSizeMax, int nConeSizeMax, int nNodeFanStop, int nConeFanStop)
Definition: abcReconv.c:588
static Vec_Ptr_t * s_pLeaves
Definition: abcLut.c:56
static void Abc_NodeLutMap(Cut_Man_t *pManCuts, Abc_Obj_t *pObj)
Definition: abcLut.c:210
Abc_Obj_t * pNext
Definition: abc.h:131
int pBSet[SCL_VARS_MAX]
Definition: abcLut.c:47
ABC_DLL Vec_Int_t * Abc_NtkFanoutCounts(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:1701
void Extra_TruthCofactor0(unsigned *pTruth, int nVars, int iVar)
#define assert(ex)
Definition: util_old.h:213
static void Extra_ProgressBarUpdate(ProgressBar *p, int nItemsCur, char *pString)
Definition: extra.h:243
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
ABC_DLL void Abc_NtkManCutStop(Abc_ManCut_t *p)
Definition: abcReconv.c:616
Vec_Ptr_t * vLeaves
Definition: abcLut.c:45
void * pData
Definition: abc.h:145
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
void Extra_TruthShrink(unsigned *pOut, unsigned *pIn, int nVars, int nVarsAll, unsigned Phase)
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
static void ** Vec_PtrArray(Vec_Ptr_t *p)
Definition: vecPtr.h:279
DECLARATIONS ///.
Definition: abcReconv.c:31
#define SCL_VARS_MAX
Definition: abcLut.c:33
static void Extra_TruthCopy(unsigned *pOut, unsigned *pIn, int nVars)
Definition: extra.h:302
unsigned ** uVars
Definition: abcLut.c:51
#define SCL_LUT_MAX
DECLARATIONS ///.
Definition: abcLut.c:32