abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcLut.c File Reference
#include "base/abc/abc.h"
#include "opt/cut/cut.h"

Go to the source code of this file.

Data Structures

struct  Abc_ManScl_t_
 

Macros

#define LARGE_LEVEL   1000000
 
#define SCL_LUT_MAX   6
 DECLARATIONS ///. More...
 
#define SCL_VARS_MAX   15
 
#define SCL_NODE_MAX   1000
 

Typedefs

typedef struct Abc_ManScl_t_ Abc_ManScl_t
 

Functions

static Cut_Man_tAbc_NtkStartCutManForScl (Abc_Ntk_t *pNtk, int nLutSize)
 
static Abc_ManScl_tAbc_ManSclStart (int nLutSize, int nCutSizeMax, int nNodesMax)
 
static void Abc_ManSclStop (Abc_ManScl_t *p)
 
static void Abc_NodeLutMap (Cut_Man_t *pManCuts, Abc_Obj_t *pObj)
 
static Abc_Obj_tAbc_NodeSuperChoiceLut (Abc_ManScl_t *pManScl, Abc_Obj_t *pObj)
 
static int Abc_NodeDecomposeStep (Abc_ManScl_t *pManScl)
 
int Abc_NtkSuperChoiceLut (Abc_Ntk_t *pNtk, int nLutSize, int nCutSizeMax, int fVerbose)
 FUNCTION DEFINITIONS ///. More...
 
unsigned * Abc_NodeSuperChoiceTruth (Abc_ManScl_t *pManScl)
 
void Abc_NodeSuperChoiceCollect2_rec (Abc_Obj_t *pObj, Vec_Ptr_t *vVolume)
 
void Abc_NodeSuperChoiceCollect2 (Abc_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
 
void Abc_NodeSuperChoiceCollect_rec (Abc_Obj_t *pObj, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
 
void Abc_NodeSuperChoiceCollect (Abc_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
 
void Abc_NodeLeavesRemove (Vec_Ptr_t *vLeaves, unsigned uPhase, int nVars)
 
int Abc_NodeGetLevel (Abc_Obj_t *pObj)
 
int Abc_NodeCompareLevelsInc (int *pp1, int *pp2)
 
void Abc_NodeDecomposeSort (Abc_Obj_t **pLeaves, int nVars, int *pBSet, int nLutSize)
 

Variables

static Vec_Ptr_ts_pLeaves = NULL
 

Macro Definition Documentation

#define LARGE_LEVEL   1000000

CFile****************************************************************

FileName [abcLut.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Superchoicing for K-LUTs.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
abcLut.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 26 of file abcLut.c.

#define SCL_LUT_MAX   6

DECLARATIONS ///.

Definition at line 32 of file abcLut.c.

#define SCL_NODE_MAX   1000

Definition at line 34 of file abcLut.c.

#define SCL_VARS_MAX   15

Definition at line 33 of file abcLut.c.

Typedef Documentation

typedef struct Abc_ManScl_t_ Abc_ManScl_t

Definition at line 36 of file abcLut.c.

Function Documentation

Abc_ManScl_t * Abc_ManSclStart ( int  nLutSize,
int  nCutSizeMax,
int  nNodesMax 
)
static

Function*************************************************************

Synopsis [Starts the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 286 of file abcLut.c.

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 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int nWords
Definition: abcLut.c:43
void ** Extra_ArrayAlloc(int nCols, int nRows, int Size)
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int nCutSizeMax
Definition: abcLut.c:41
int nNodesMax
Definition: abcLut.c:42
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
int nLutSize
Definition: abcLut.c:40
unsigned ** uCofs
Definition: abcLut.c:53
unsigned ** uSims
Definition: abcLut.c:52
#define assert(ex)
Definition: util_old.h:213
unsigned ** uVars
Definition: abcLut.c:51
void Abc_ManSclStop ( Abc_ManScl_t p)
static

Function*************************************************************

Synopsis [Stops the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 323 of file abcLut.c.

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 }
unsigned ** uCofs
Definition: abcLut.c:53
#define ABC_FREE(obj)
Definition: abc_global.h:232
unsigned ** uSims
Definition: abcLut.c:52
unsigned ** uVars
Definition: abcLut.c:51
int Abc_NodeCompareLevelsInc ( int *  pp1,
int *  pp2 
)

Function*************************************************************

Synopsis [Procedure used for sorting the nodes in increasing order of levels.]

Description []

SideEffects []

SeeAlso []

Definition at line 601 of file abcLut.c.

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 }
unsigned Level
Definition: abc.h:142
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static Vec_Ptr_t * s_pLeaves
Definition: abcLut.c:56
void Abc_NodeDecomposeSort ( Abc_Obj_t **  pLeaves,
int  nVars,
int *  pBSet,
int  nLutSize 
)

Function*************************************************************

Synopsis [Selects the earliest arriving nodes from the array.]

Description []

SideEffects []

SeeAlso []

Definition at line 624 of file abcLut.c.

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 }
unsigned Level
Definition: abc.h:142
#define LARGE_LEVEL
Definition: abcLut.c:26
#define assert(ex)
Definition: util_old.h:213
#define SCL_VARS_MAX
Definition: abcLut.c:33
int Abc_NodeDecomposeStep ( Abc_ManScl_t p)
static

Function*************************************************************

Synopsis [Performs superchoicing for one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 665 of file abcLut.c.

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 }
static void Extra_TruthOr(unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: extra.h:332
void Abc_NodeDecomposeSort(Abc_Obj_t **pLeaves, int nVars, int *pBSet, int nLutSize)
Definition: abcLut.c:624
static void Extra_TruthClear(unsigned *pOut, int nVars)
Definition: extra.h:308
unsigned * uTruth
Definition: abcLut.c:49
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
unsigned Level
Definition: abc.h:142
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
void * pManFunc
Definition: abc.h:191
static void Extra_TruthFill(unsigned *pOut, int nVars)
Definition: extra.h:314
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
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
static int Extra_TruthIsEqual(unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: extra.h:270
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
ABC_DLL char * Abc_SopCreateFromTruth(Mem_Flex_t *pMan, int nVars, unsigned *pTruth)
Definition: abcSop.c:377
int Extra_TruthVarInSupport(unsigned *pTruth, int nVars, int iVar)
static int Abc_Base2Log(unsigned n)
Definition: abc_global.h:251
int Abc_NodeGetLevel(Abc_Obj_t *pObj)
Definition: abcLut.c:512
static Abc_Obj_t * Abc_NtkCreateNode(Abc_Ntk_t *pNtk)
Definition: abc.h:308
int pBSet[SCL_VARS_MAX]
Definition: abcLut.c:47
void Extra_TruthCofactor0(unsigned *pTruth, int nVars, int iVar)
#define assert(ex)
Definition: util_old.h:213
Vec_Ptr_t * vLeaves
Definition: abcLut.c:45
void * pData
Definition: abc.h:145
void Extra_TruthShrink(unsigned *pOut, unsigned *pIn, int nVars, int nVarsAll, unsigned Phase)
static void ** Vec_PtrArray(Vec_Ptr_t *p)
Definition: vecPtr.h:279
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
int Abc_NodeGetLevel ( Abc_Obj_t pObj)

Function*************************************************************

Synopsis [Performs superchoicing for one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 512 of file abcLut.c.

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 }
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
void Abc_NodeLeavesRemove ( Vec_Ptr_t vLeaves,
unsigned  uPhase,
int  nVars 
)

Function*************************************************************

Synopsis [Performs superchoicing for one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 493 of file abcLut.c.

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 }
static void Vec_PtrRemove(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:714
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
void Abc_NodeLutMap ( Cut_Man_t pManCuts,
Abc_Obj_t pObj 
)
static

Function*************************************************************

Synopsis [Performs LUT mapping of the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 210 of file abcLut.c.

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 }
Cut_Cut_t * pNext
Definition: cut.h:88
static Abc_Obj_t * Abc_NtkObj(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:314
unsigned Level
Definition: abc.h:142
int pLeaves[0]
Definition: cut.h:89
unsigned nLeaves
Definition: cut.h:84
ABC_DLL void * Abc_NodeGetCutsRecursive(void *p, Abc_Obj_t *pObj, int fDag, int fTree)
Abc_Ntk_t * pNtk
Definition: abc.h:130
#define LARGE_LEVEL
Definition: abcLut.c:26
#define assert(ex)
Definition: util_old.h:213
void Abc_NodeSuperChoiceCollect ( Abc_Obj_t pRoot,
Vec_Ptr_t vLeaves,
Vec_Ptr_t vVolume 
)

Function*************************************************************

Synopsis [Performs superchoicing for one node.]

Description [Orders the leaves topologically.]

SideEffects []

SeeAlso []

Definition at line 465 of file abcLut.c.

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 }
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
void Abc_NodeSuperChoiceCollect_rec(Abc_Obj_t *pObj, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
Definition: abcLut.c:438
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
void Abc_NodeSuperChoiceCollect2 ( Abc_Obj_t pRoot,
Vec_Ptr_t vLeaves,
Vec_Ptr_t vVolume 
)

Function*************************************************************

Synopsis [Performs superchoicing for one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 413 of file abcLut.c.

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 }
void Abc_NodeSuperChoiceCollect2_rec(Abc_Obj_t *pObj, Vec_Ptr_t *vVolume)
Definition: abcLut.c:391
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
void Abc_NodeSuperChoiceCollect2_rec ( Abc_Obj_t pObj,
Vec_Ptr_t vVolume 
)

Function*************************************************************

Synopsis [Performs superchoicing for one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 391 of file abcLut.c.

392 {
393  if ( pObj->fMarkC )
394  return;
395  pObj->fMarkC = 1;
396  assert( Abc_ObjFaninNum(pObj) == 2 );
399  Vec_PtrPush( vVolume, pObj );
400 }
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
unsigned fMarkC
Definition: abc.h:136
void Abc_NodeSuperChoiceCollect2_rec(Abc_Obj_t *pObj, Vec_Ptr_t *vVolume)
Definition: abcLut.c:391
#define assert(ex)
Definition: util_old.h:213
void Abc_NodeSuperChoiceCollect_rec ( Abc_Obj_t pObj,
Vec_Ptr_t vLeaves,
Vec_Ptr_t vVolume 
)

Function*************************************************************

Synopsis [Performs superchoicing for one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 438 of file abcLut.c.

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 }
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
unsigned fMarkC
Definition: abc.h:136
void Abc_NodeSuperChoiceCollect_rec(Abc_Obj_t *pObj, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
Definition: abcLut.c:438
unsigned fMarkB
Definition: abc.h:135
#define assert(ex)
Definition: util_old.h:213
Abc_Obj_t * Abc_NodeSuperChoiceLut ( Abc_ManScl_t p,
Abc_Obj_t pObj 
)
static

Function*************************************************************

Synopsis [Performs superchoicing for one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 533 of file abcLut.c.

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 }
void Abc_NodeSuperChoiceCollect2(Abc_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
Definition: abcLut.c:413
unsigned * uTruth
Definition: abcLut.c:49
Vec_Ptr_t * vVolume
Definition: abcLut.c:46
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
static int Abc_NodeDecomposeStep(Abc_ManScl_t *pManScl)
Definition: abcLut.c:665
ABC_DLL void Abc_NtkDeleteObj_rec(Abc_Obj_t *pObj, int fOnlyNodes)
Definition: abcObj.c:273
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
unsigned Level
Definition: abc.h:142
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
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
static void * Vec_PtrEntryLast(Vec_Ptr_t *p)
Definition: vecPtr.h:413
int Extra_TruthSupport(unsigned *pTruth, int nVars)
if(last==0)
Definition: sparse_int.h:34
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
ABC_DLL char * Abc_SopCreateFromTruth(Mem_Flex_t *pMan, int nVars, unsigned *pTruth)
Definition: abcSop.c:377
int Abc_NodeGetLevel(Abc_Obj_t *pObj)
Definition: abcLut.c:512
static Abc_Obj_t * Abc_NtkCreateNode(Abc_Ntk_t *pNtk)
Definition: abc.h:308
unsigned * Abc_NodeSuperChoiceTruth(Abc_ManScl_t *pManScl)
Definition: abcLut.c:344
static int Extra_WordCountOnes(unsigned uWord)
Definition: extra.h:255
#define assert(ex)
Definition: util_old.h:213
Vec_Ptr_t * vLeaves
Definition: abcLut.c:45
#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)
static void Extra_TruthCopy(unsigned *pOut, unsigned *pIn, int nVars)
Definition: extra.h:302
unsigned* Abc_NodeSuperChoiceTruth ( Abc_ManScl_t pManScl)

Function*************************************************************

Synopsis [Performs superchoicing for one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 344 of file abcLut.c.

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 }
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
int nWords
Definition: abcLut.c:43
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
if(last==0)
Definition: sparse_int.h:34
unsigned ** uSims
Definition: abcLut.c:52
Abc_Obj_t * pNext
Definition: abc.h:131
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
Cut_Man_t * Abc_NtkStartCutManForScl ( Abc_Ntk_t pNtk,
int  nLutSize 
)
static

Function*************************************************************

Synopsis [Starts the cut manager for rewriting.]

Description []

SideEffects []

SeeAlso []

Definition at line 249 of file abcLut.c.

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 }
char * memset()
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
void Cut_NodeSetTriv(Cut_Man_t *p, int Node)
Definition: cutApi.c:145
void Cut_ManSetFanoutCounts(Cut_Man_t *p, Vec_Int_t *vFanCounts)
Definition: cutMan.c:229
Cut_Man_t * Cut_ManStart(Cut_Params_t *pParams)
FUNCTION DEFINITIONS ///.
Definition: cutMan.c:47
if(last==0)
Definition: sparse_int.h:34
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition: abc.h:515
ABC_DLL Vec_Int_t * Abc_NtkFanoutCounts(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:1701
int Abc_NtkSuperChoiceLut ( Abc_Ntk_t pNtk,
int  nLutSize,
int  nCutSizeMax,
int  fVerbose 
)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Performs superchoicing for K-LUTs.]

Description []

SideEffects []

SeeAlso []

Definition at line 81 of file abcLut.c.

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 }
static void Abc_ManSclStop(Abc_ManScl_t *p)
Definition: abcLut.c:323
#define SCL_NODE_MAX
Definition: abcLut.c:34
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
Vec_Ptr_t * vVolume
Definition: abcLut.c:46
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
ABC_DLL void Abc_NtkDeleteObj_rec(Abc_Obj_t *pObj, int fOnlyNodes)
Definition: abcObj.c:273
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
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
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
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
DECLARATIONS ///.
static Abc_ManScl_t * Abc_ManSclStart(int nLutSize, int nCutSizeMax, int nNodesMax)
Definition: abcLut.c:286
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
if(last==0)
Definition: sparse_int.h:34
void Extra_ProgressBarStop(ProgressBar *p)
#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
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
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
#define assert(ex)
Definition: util_old.h:213
static void Extra_ProgressBarUpdate(ProgressBar *p, int nItemsCur, char *pString)
Definition: extra.h:243
ABC_DLL void Abc_NtkManCutStop(Abc_ManCut_t *p)
Definition: abcReconv.c:616
Vec_Ptr_t * vLeaves
Definition: abcLut.c:45
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
DECLARATIONS ///.
Definition: abcReconv.c:31
#define SCL_VARS_MAX
Definition: abcLut.c:33
#define SCL_LUT_MAX
DECLARATIONS ///.
Definition: abcLut.c:32

Variable Documentation

Vec_Ptr_t* s_pLeaves = NULL
static

Definition at line 56 of file abcLut.c.