abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcFanOrder.c File Reference
#include "abc.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START void Abc_NtkOrderFaninsById (Abc_Ntk_t *pNtk)
 DECLARATIONS ///. More...
 
void Abc_NtkOrderFaninsByLitCount (Abc_Ntk_t *pNtk)
 
void Abc_NtkOrderFaninsByLitCountAndCubeCount (Abc_Ntk_t *pNtk)
 
void Abc_NodeSplitLarge (Abc_Obj_t *pNode)
 
void Abc_NtkSplitLarge (Abc_Ntk_t *pNtk, int nFaninsMax, int nCubesMax)
 
int Abc_NodeCompareCubes (char **pp1, char **pp2)
 
void Abc_NodeSortCubes (Abc_Obj_t *pNode, Vec_Ptr_t *vCubes, Vec_Str_t *vStore)
 
void Abc_NtkSortCubes (Abc_Ntk_t *pNtk)
 
void Abc_NtkSortSops (Abc_Ntk_t *pNtk)
 
static int Abc_CubeContain (char *pCube1, char *pCube2, int nVars)
 
int Abc_NodeMakeSCCFree (Abc_Obj_t *pNode)
 
void Abc_NodeMakeDist1Free (Abc_Obj_t *pNode)
 
void Abc_NodeCheckDist1Free (Abc_Obj_t *pNode)
 
int Abc_NodeMakeLegit (Abc_Obj_t *pNode)
 
int Abc_NtkMakeLegit (Abc_Ntk_t *pNtk)
 

Function Documentation

static int Abc_CubeContain ( char *  pCube1,
char *  pCube2,
int  nVars 
)
inlinestatic

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

Synopsis [Makes cover legitimate for "fast_extract".]

Description [Iteratively removes distance-1 and contained cubes.]

SideEffects []

SeeAlso []

Definition at line 367 of file abcFanOrder.c.

368 {
369  int v, fCont12 = 1, fCont21 = 1;
370  for ( v = 0; v < nVars; v++ )
371  {
372  if ( pCube1[v] == pCube2[v] )
373  continue;
374  if ( pCube1[v] == '-' )
375  fCont21 = 0;
376  else if ( pCube2[v] == '-' )
377  fCont12 = 0;
378  else
379  return 0;
380  if ( !fCont21 && !fCont21 )
381  return 0;
382  }
383  assert( fCont21 || fCont12 );
384  return (fCont21 << 1) | fCont12;
385 }
#define assert(ex)
Definition: util_old.h:213
void Abc_NodeCheckDist1Free ( Abc_Obj_t pNode)

Definition at line 433 of file abcFanOrder.c.

434 {
435  char * pSop = (char *)pNode->pData;
436  char * pCube, * pCube2;
437  int i, nVars = Abc_ObjFaninNum(pNode);
438  Abc_SopForEachCube( pSop, nVars, pCube )
439  Abc_SopForEachCube( pSop, nVars, pCube2 )
440  {
441  int Counter = 0;
442  if ( pCube == pCube2 )
443  continue;
444  for ( i = 0; i < nVars; i++ )
445  if ( pCube[i] != pCube2[i] )
446  Counter++;
447  assert( Counter > 1 );
448  }
449 }
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition: abc.h:531
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static int Counter
#define assert(ex)
Definition: util_old.h:213
void * pData
Definition: abc.h:145
int Abc_NodeCompareCubes ( char **  pp1,
char **  pp2 
)

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

Synopsis [Sorts the cubes in a topological order.]

Description []

SideEffects []

SeeAlso []

Definition at line 294 of file abcFanOrder.c.

295 {
296  return strcmp( *pp1, *pp2 );
297 }
int strcmp()
void Abc_NodeMakeDist1Free ( Abc_Obj_t pNode)

Definition at line 417 of file abcFanOrder.c.

418 {
419  char * pSop = (char *)pNode->pData;
420  char * pCube, * pCube2;
421  int i, nVars = Abc_ObjFaninNum(pNode);
422  Abc_SopForEachCube( pSop, nVars, pCube )
423  Abc_SopForEachCube( pCube + nVars + 3, nVars, pCube2 )
424  {
425  int Counter = 0, iDiff = -1;
426  for ( i = 0; i < nVars; i++ )
427  if ( pCube[i] != pCube2[i] )
428  Counter++, iDiff = i;
429  if ( Counter == 1 && ((pCube[iDiff] == '0' && pCube2[iDiff] == '1') || (pCube[iDiff] == '1' && pCube2[iDiff] == '0')) )
430  pCube[iDiff] = pCube2[iDiff] = '-';
431  }
432 }
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition: abc.h:531
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static int Counter
void * pData
Definition: abc.h:145
int Abc_NodeMakeLegit ( Abc_Obj_t pNode)

Definition at line 450 of file abcFanOrder.c.

451 {
452  int i, fChanges = 1;
453  for ( i = 0; fChanges; i++ )
454  {
455  Abc_NodeMakeDist1Free( pNode );
456  fChanges = Abc_NodeMakeSCCFree( pNode );
457  }
458 // Abc_NodeCheckDist1Free( pNode );
459  return i > 1;
460 }
void Abc_NodeMakeDist1Free(Abc_Obj_t *pNode)
Definition: abcFanOrder.c:417
int Abc_NodeMakeSCCFree(Abc_Obj_t *pNode)
Definition: abcFanOrder.c:386
int Abc_NodeMakeSCCFree ( Abc_Obj_t pNode)

Definition at line 386 of file abcFanOrder.c.

387 {
388  char * pSop = (char *)pNode->pData;
389  char * pCube, * pCube2, * pSopNew;
390  int nVars = Abc_ObjFaninNum(pNode);
391  int Status, nCount = 0;
392  Abc_SopForEachCubePair( pSop, nVars, pCube, pCube2 )
393  {
394  if ( pCube[0] == 'z' || pCube2[0] == 'z' )
395  continue;
396  Status = Abc_CubeContain( pCube, pCube2, nVars );
397  nCount += (int)(Status > 0);
398  if ( Status & 1 )
399  pCube2[0] = 'z';
400  else if ( Status & 2 )
401  pCube[0] = 'z';
402  }
403  if ( nCount == 0 )
404  return 0;
405  // create new cover
406  pSopNew = (char *)pNode->pData;
407  Abc_SopForEachCube( pSop, nVars, pCube )
408  {
409  if ( pCube[0] == 'z' )
410  continue;
411  memcpy( pSopNew, pCube, nVars + 3 );
412  pSopNew += nVars + 3;
413  }
414  *pSopNew = 0;
415  return 1;
416 }
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition: abc.h:531
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
char * memcpy()
static int Abc_CubeContain(char *pCube1, char *pCube2, int nVars)
Definition: abcFanOrder.c:367
void * pData
Definition: abc.h:145
#define Abc_SopForEachCubePair(pSop, nFanins, pCube, pCube2)
Definition: abc.h:533
void Abc_NodeSortCubes ( Abc_Obj_t pNode,
Vec_Ptr_t vCubes,
Vec_Str_t vStore 
)

Definition at line 298 of file abcFanOrder.c.

299 {
300  char * pCube, * pPivot;
301  char * pSop = (char *)pNode->pData;
302  int i, nVars = Abc_ObjFaninNum(pNode);
303  Vec_PtrClear( vCubes );
304  Abc_SopForEachCube( pSop, nVars, pCube )
305  {
306  assert( pCube[nVars] == ' ' );
307  pCube[nVars] = 0;
308  Vec_PtrPush( vCubes, pCube );
309  }
310  Vec_PtrSort( vCubes, (int (*)())Abc_NodeCompareCubes );
311  Vec_StrGrow( vStore, Vec_PtrSize(vCubes) * (nVars + 3) );
312  pPivot = Vec_StrArray( vStore );
313  Vec_PtrForEachEntry( char *, vCubes, pCube, i )
314  {
315  assert( pCube[nVars] == 0 );
316  pCube[nVars] = ' ';
317  memcpy( pPivot, pCube, nVars + 3 );
318  pPivot += nVars + 3;
319  }
320  memcpy( pSop, Vec_StrArray(vStore), Vec_PtrSize(vCubes) * (nVars + 3) );
321 }
int Abc_NodeCompareCubes(char **pp1, char **pp2)
Definition: abcFanOrder.c:294
static char * Vec_StrArray(Vec_Str_t *p)
Definition: vecStr.h:272
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition: abc.h:531
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static void Vec_PtrSort(Vec_Ptr_t *p, int(*Vec_PtrSortCompare)()) ___unused
Definition: vecPtr.h:851
char * memcpy()
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static void Vec_StrGrow(Vec_Str_t *p, int nCapMin)
Definition: vecStr.h:404
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
void * pData
Definition: abc.h:145
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
void Abc_NodeSplitLarge ( Abc_Obj_t pNode)

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

Synopsis [Split large nodes by dividing their SOPs in half.]

Description []

SideEffects []

SeeAlso []

Definition at line 245 of file abcFanOrder.c.

246 {
247  Abc_Obj_t * pNode1, * pNode2, * pFanin;
248  int CutPoint, nVars = Abc_ObjFaninNum(pNode);
249  int i, nCubes = Abc_SopGetCubeNum((char *)pNode->pData);
250  pNode1 = Abc_NtkDupObj( pNode->pNtk, pNode, 0 );
251  pNode2 = Abc_NtkDupObj( pNode->pNtk, pNode, 0 );
252  Abc_ObjForEachFanin( pNode, pFanin, i )
253  Abc_ObjAddFanin( pNode1, pFanin );
254  Abc_ObjForEachFanin( pNode, pFanin, i )
255  Abc_ObjAddFanin( pNode2, pFanin );
256  // update the node
257  Abc_ObjRemoveFanins( pNode );
258  Abc_ObjAddFanin( pNode, pNode1 );
259  Abc_ObjAddFanin( pNode, pNode2 );
260  pNode->pData = Abc_SopCreateOr( (Mem_Flex_t *)pNode->pNtk->pManFunc, 2, NULL );
261  // update covers of the nodes
262  assert( nCubes > 1 );
263  CutPoint = (nCubes / 2) * (nVars + 3);
264  ((char *)pNode1->pData)[CutPoint] = 0;
265  pNode2->pData = (char *)pNode2->pData + CutPoint;
266 }
ABC_DLL int Abc_SopGetCubeNum(char *pSop)
Definition: abcSop.c:489
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
ABC_DLL Abc_Obj_t * Abc_NtkDupObj(Abc_Ntk_t *pNtkNew, Abc_Obj_t *pObj, int fCopyName)
Definition: abcObj.c:337
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
ABC_DLL void Abc_ObjRemoveFanins(Abc_Obj_t *pObj)
Definition: abcFanio.c:141
Abc_Ntk_t * pNtk
Definition: abc.h:130
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
#define assert(ex)
Definition: util_old.h:213
void * pData
Definition: abc.h:145
ABC_DLL char * Abc_SopCreateOr(Mem_Flex_t *pMan, int nVars, int *pfCompl)
Definition: abcSop.c:206
int Abc_NtkMakeLegit ( Abc_Ntk_t pNtk)

Definition at line 461 of file abcFanOrder.c.

462 {
463  Abc_Obj_t * pNode;
464  int i, Counter = 0;
465  assert( Abc_NtkHasSop(pNtk) );
466  Abc_NtkForEachNode( pNtk, pNode, i )
467  Counter += Abc_NodeMakeLegit( pNode );
468  if ( Counter )
469  Abc_Print( 0, "%d nodes were made dist1-cube-free and/or single-cube-containment-free.\n", Counter );
470  return 1;
471 }
VOID_HACK free()
static int Abc_NtkHasSop(Abc_Ntk_t *pNtk)
Definition: abc.h:253
if(last==0)
Definition: sparse_int.h:34
static int Counter
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
int Abc_NodeMakeLegit(Abc_Obj_t *pNode)
Definition: abcFanOrder.c:450
#define assert(ex)
Definition: util_old.h:213
ABC_NAMESPACE_IMPL_START void Abc_NtkOrderFaninsById ( Abc_Ntk_t pNtk)

DECLARATIONS ///.

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

FileName [abcFanOrder.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Fanin ordering procedures.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Reorder fanins of the network.]

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file abcFanOrder.c.

46 {
47  Vec_Int_t * vOrder;
48  Vec_Str_t * vStore;
49  Abc_Obj_t * pNode;
50  char * pSop, * pSopNew;
51  char * pCube, * pCubeNew;
52  int nVars, i, v, * pOrder;
53  assert( Abc_NtkHasSop(pNtk) );
54  vOrder = Vec_IntAlloc( 100 );
55  vStore = Vec_StrAlloc( 100 );
56  Abc_NtkForEachNode( pNtk, pNode, i )
57  {
58  pSop = (char *)pNode->pData;
59  nVars = Abc_SopGetVarNum(pSop);
60  assert( nVars == Abc_ObjFaninNum(pNode) );
61  Vec_IntClear( vOrder );
62  for ( v = 0; v < nVars; v++ )
63  Vec_IntPush( vOrder, v );
64  pOrder = Vec_IntArray(vOrder);
65  Vec_IntSelectSortCost( pOrder, nVars, &pNode->vFanins );
66  // copy the cover
67  Vec_StrGrow( vStore, Abc_SopGetCubeNum(pSop) * (nVars + 3) + 1 );
68  memcpy( Vec_StrArray(vStore), pSop, Abc_SopGetCubeNum(pSop) * (nVars + 3) + 1 );
69  pSopNew = pCubeNew = pSop;
70  pSop = Vec_StrArray(vStore);
71  // generate permuted one
72  Abc_SopForEachCube( pSop, nVars, pCube )
73  {
74  for ( v = 0; v < nVars; v++ )
75  pCubeNew[v] = '-';
76  for ( v = 0; v < nVars; v++ )
77  if ( pCube[pOrder[v]] == '0' )
78  pCubeNew[v] = '0';
79  else if ( pCube[pOrder[v]] == '1' )
80  pCubeNew[v] = '1';
81  pCubeNew += nVars + 3;
82  }
83  pNode->pData = pSopNew;
84  Vec_IntSort( &pNode->vFanins, 0 );
85 // Vec_IntPrint( vOrder );
86  }
87  Vec_IntFree( vOrder );
88  Vec_StrFree( vStore );
89 }
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
static int Abc_NtkHasSop(Abc_Ntk_t *pNtk)
Definition: abc.h:253
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static char * Vec_StrArray(Vec_Str_t *p)
Definition: vecStr.h:272
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition: abc.h:531
ABC_DLL int Abc_SopGetCubeNum(char *pSop)
Definition: abcSop.c:489
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
Vec_Int_t vFanins
Definition: abc.h:143
char * memcpy()
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
static void Vec_IntSort(Vec_Int_t *p, int fReverse)
Definition: vecInt.h:1293
static void Vec_StrGrow(Vec_Str_t *p, int nCapMin)
Definition: vecStr.h:404
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
static void Vec_IntSelectSortCost(int *pArray, int nSize, Vec_Int_t *vCosts)
Definition: vecInt.h:1766
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
ABC_DLL int Abc_SopGetVarNum(char *pSop)
Definition: abcSop.c:536
#define assert(ex)
Definition: util_old.h:213
void * pData
Definition: abc.h:145
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
void Abc_NtkOrderFaninsByLitCount ( Abc_Ntk_t pNtk)

Definition at line 90 of file abcFanOrder.c.

91 {
92  Vec_Int_t * vOrder;
93  Vec_Int_t * vCounts;
94  Vec_Int_t * vFanins;
95  Vec_Str_t * vStore;
96  Abc_Obj_t * pNode;
97  char * pSop, * pSopNew;
98  char * pCube, * pCubeNew;
99  int nVars, i, v, * pOrder;
100  assert( Abc_NtkHasSop(pNtk) );
101  vOrder = Vec_IntAlloc( 100 );
102  vStore = Vec_StrAlloc( 100 );
103  vCounts = Vec_IntAlloc( 100 );
104  vFanins = Vec_IntAlloc( 100 );
105  Abc_NtkForEachNode( pNtk, pNode, i )
106  {
107  pSop = (char *)pNode->pData;
108  nVars = Abc_SopGetVarNum(pSop);
109  assert( nVars == Abc_ObjFaninNum(pNode) );
110  // count literals
111  Vec_IntFill( vCounts, nVars, 0 );
112  Abc_SopForEachCube( pSop, nVars, pCube )
113  for ( v = 0; v < nVars; v++ )
114  if ( pCube[v] != '-' )
115  Vec_IntAddToEntry( vCounts, v, 1 );
116  // find good order
117  Vec_IntClear( vOrder );
118  for ( v = 0; v < nVars; v++ )
119  Vec_IntPush( vOrder, v );
120  pOrder = Vec_IntArray(vOrder);
121  Vec_IntSelectSortCost( pOrder, nVars, vCounts );
122  // copy the cover
123  Vec_StrGrow( vStore, Abc_SopGetCubeNum(pSop) * (nVars + 3) + 1 );
124  memcpy( Vec_StrArray(vStore), pSop, Abc_SopGetCubeNum(pSop) * (nVars + 3) + 1 );
125  pSopNew = pCubeNew = pSop;
126  pSop = Vec_StrArray(vStore);
127  // generate permuted one
128  Abc_SopForEachCube( pSop, nVars, pCube )
129  {
130  for ( v = 0; v < nVars; v++ )
131  pCubeNew[v] = '-';
132  for ( v = 0; v < nVars; v++ )
133  if ( pCube[pOrder[v]] == '0' )
134  pCubeNew[v] = '0';
135  else if ( pCube[pOrder[v]] == '1' )
136  pCubeNew[v] = '1';
137  pCubeNew += nVars + 3;
138  }
139  pNode->pData = pSopNew;
140  // generate the fanin order
141  Vec_IntClear( vFanins );
142  for ( v = 0; v < nVars; v++ )
143  Vec_IntPush( vFanins, Abc_ObjFaninId( pNode, pOrder[v] ) );
144  Vec_IntClear( &pNode->vFanins );
145  Vec_IntAppend( &pNode->vFanins, vFanins );
146  }
147  Vec_IntFree( vFanins );
148  Vec_IntFree( vCounts );
149  Vec_IntFree( vOrder );
150  Vec_StrFree( vStore );
151 }
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
static int Abc_NtkHasSop(Abc_Ntk_t *pNtk)
Definition: abc.h:253
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static char * Vec_StrArray(Vec_Str_t *p)
Definition: vecStr.h:272
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition: abc.h:531
ABC_DLL int Abc_SopGetCubeNum(char *pSop)
Definition: abcSop.c:489
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
Vec_Int_t vFanins
Definition: abc.h:143
char * memcpy()
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
for(p=first;p->value< newval;p=p->next)
static void Vec_StrGrow(Vec_Str_t *p, int nCapMin)
Definition: vecStr.h:404
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static void Vec_IntAddToEntry(Vec_Int_t *p, int i, int Addition)
Definition: bblif.c:302
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
static void Vec_IntSelectSortCost(int *pArray, int nSize, Vec_Int_t *vCosts)
Definition: vecInt.h:1766
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:356
if(last==0)
Definition: sparse_int.h:34
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static void Vec_IntAppend(Vec_Int_t *vVec1, Vec_Int_t *vVec2)
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
ABC_DLL int Abc_SopGetVarNum(char *pSop)
Definition: abcSop.c:536
#define assert(ex)
Definition: util_old.h:213
static int Abc_ObjFaninId(Abc_Obj_t *pObj, int i)
Definition: abc.h:366
void * pData
Definition: abc.h:145
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
void Abc_NtkOrderFaninsByLitCountAndCubeCount ( Abc_Ntk_t pNtk)

Definition at line 152 of file abcFanOrder.c.

153 {
154  // assuming that the fanins are sorted by the number of literals in each cube
155  // this procedure sorts the literals appearing only once by the number of their cube
156  Vec_Int_t * vOrder;
157  Vec_Int_t * vCounts;
158  Vec_Int_t * vFanins;
159  Vec_Int_t * vCubeNum;
160  Vec_Str_t * vStore;
161  Abc_Obj_t * pNode;
162  char * pSop, * pSopNew;
163  char * pCube, * pCubeNew;
164  int nVars, i, v, iCube, * pOrder;
165  assert( Abc_NtkHasSop(pNtk) );
166  vStore = Vec_StrAlloc( 100 );
167  vOrder = Vec_IntAlloc( 100 );
168  vCounts = Vec_IntAlloc( 100 );
169  vFanins = Vec_IntAlloc( 100 );
170  vCubeNum = Vec_IntAlloc( 100 );
171  Abc_NtkForEachNode( pNtk, pNode, i )
172  {
173  pSop = (char *)pNode->pData;
174  nVars = Abc_SopGetVarNum(pSop);
175  assert( nVars == Abc_ObjFaninNum(pNode) );
176  // count literals and remember the cube where each literal appears
177  Vec_IntFill( vCounts, nVars, 0 );
178  Vec_IntFill( vCubeNum, nVars, 0 );
179  iCube = 0;
180  Abc_SopForEachCube( pSop, nVars, pCube )
181  {
182  for ( v = 0; v < nVars; v++ )
183  if ( pCube[v] != '-' )
184  {
185  Vec_IntAddToEntry( vCounts, v, 1 );
186  Vec_IntWriteEntry( vCubeNum, v, iCube );
187  }
188  iCube++;
189  }
190  // create new order
191  for ( v = 0; v < nVars; v++ )
192  if ( Vec_IntEntry(vCounts, v) == 1 )
193  Vec_IntWriteEntry( vCounts, v, Vec_IntEntry(vCubeNum, v) );
194  else
195  Vec_IntWriteEntry( vCounts, v, ABC_INFINITY );
196  // find good order
197  Vec_IntClear( vOrder );
198  for ( v = 0; v < nVars; v++ )
199  Vec_IntPush( vOrder, v );
200  pOrder = Vec_IntArray(vOrder);
201  Vec_IntSelectSortCost( pOrder, nVars, vCounts );
202  // copy the cover
203  Vec_StrGrow( vStore, Abc_SopGetCubeNum(pSop) * (nVars + 3) + 1 );
204  memcpy( Vec_StrArray(vStore), pSop, Abc_SopGetCubeNum(pSop) * (nVars + 3) + 1 );
205  pSopNew = pCubeNew = pSop;
206  pSop = Vec_StrArray(vStore);
207  // generate permuted one
208  Abc_SopForEachCube( pSop, nVars, pCube )
209  {
210  for ( v = 0; v < nVars; v++ )
211  pCubeNew[v] = '-';
212  for ( v = 0; v < nVars; v++ )
213  if ( pCube[pOrder[v]] == '0' )
214  pCubeNew[v] = '0';
215  else if ( pCube[pOrder[v]] == '1' )
216  pCubeNew[v] = '1';
217  pCubeNew += nVars + 3;
218  }
219  pNode->pData = pSopNew;
220  // generate the fanin order
221  Vec_IntClear( vFanins );
222  for ( v = 0; v < nVars; v++ )
223  Vec_IntPush( vFanins, Abc_ObjFaninId( pNode, pOrder[v] ) );
224  Vec_IntClear( &pNode->vFanins );
225  Vec_IntAppend( &pNode->vFanins, vFanins );
226  }
227  Vec_IntFree( vCubeNum );
228  Vec_IntFree( vFanins );
229  Vec_IntFree( vCounts );
230  Vec_IntFree( vOrder );
231  Vec_StrFree( vStore );
232 }
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
static int Abc_NtkHasSop(Abc_Ntk_t *pNtk)
Definition: abc.h:253
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static char * Vec_StrArray(Vec_Str_t *p)
Definition: vecStr.h:272
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition: abc.h:531
ABC_DLL int Abc_SopGetCubeNum(char *pSop)
Definition: abcSop.c:489
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
Vec_Int_t vFanins
Definition: abc.h:143
char * memcpy()
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static void Vec_StrGrow(Vec_Str_t *p, int nCapMin)
Definition: vecStr.h:404
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static void Vec_IntAddToEntry(Vec_Int_t *p, int i, int Addition)
Definition: bblif.c:302
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static void Vec_IntSelectSortCost(int *pArray, int nSize, Vec_Int_t *vCosts)
Definition: vecInt.h:1766
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:356
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static void Vec_IntAppend(Vec_Int_t *vVec1, Vec_Int_t *vVec2)
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
ABC_DLL int Abc_SopGetVarNum(char *pSop)
Definition: abcSop.c:536
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition: abc_global.h:216
#define assert(ex)
Definition: util_old.h:213
static int Abc_ObjFaninId(Abc_Obj_t *pObj, int i)
Definition: abc.h:366
void * pData
Definition: abc.h:145
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
void Abc_NtkSortCubes ( Abc_Ntk_t pNtk)

Definition at line 322 of file abcFanOrder.c.

323 {
324  Vec_Ptr_t * vCubes;
325  Vec_Str_t * vStore;
326  Abc_Obj_t * pNode;
327  int i;
328  assert( Abc_NtkHasSop(pNtk) );
329  vCubes = Vec_PtrAlloc( 1000 );
330  vStore = Vec_StrAlloc( 1000 );
331  Abc_NtkForEachNode( pNtk, pNode, i )
332  Abc_NodeSortCubes( pNode, vCubes, vStore );
333  Vec_StrFree( vStore );
334  Vec_PtrFree( vCubes );
335 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Abc_NtkHasSop(Abc_Ntk_t *pNtk)
Definition: abc.h:253
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
void Abc_NodeSortCubes(Abc_Obj_t *pNode, Vec_Ptr_t *vCubes, Vec_Str_t *vStore)
Definition: abcFanOrder.c:298
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
void Abc_NtkSortSops ( Abc_Ntk_t pNtk)

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

Synopsis [Sorts fanins of each node to make SOPs more readable.]

Description []

SideEffects []

SeeAlso []

Definition at line 348 of file abcFanOrder.c.

349 {
351  Abc_NtkSortCubes( pNtk );
353  Abc_NtkSortCubes( pNtk );
354 }
void Abc_NtkSortCubes(Abc_Ntk_t *pNtk)
Definition: abcFanOrder.c:322
void Abc_NtkOrderFaninsByLitCount(Abc_Ntk_t *pNtk)
Definition: abcFanOrder.c:90
void Abc_NtkOrderFaninsByLitCountAndCubeCount(Abc_Ntk_t *pNtk)
Definition: abcFanOrder.c:152
void Abc_NtkSplitLarge ( Abc_Ntk_t pNtk,
int  nFaninsMax,
int  nCubesMax 
)

Definition at line 267 of file abcFanOrder.c.

268 {
269  Abc_Obj_t * pNode;
270  int nObjOld = Abc_NtkObjNumMax(pNtk);
271  int i, nCubes;
272  assert( Abc_NtkHasSop(pNtk) );
273  Abc_NtkForEachNode( pNtk, pNode, i )
274  {
275  if ( i == nObjOld )
276  break;
277  nCubes = Abc_SopGetCubeNum((char *)pNode->pData);
278  if ( (Abc_ObjFaninNum(pNode) > nFaninsMax && nCubes > 1) || nCubes > nCubesMax )
279  Abc_NodeSplitLarge( pNode );
280  }
281 }
static int Abc_NtkHasSop(Abc_Ntk_t *pNtk)
Definition: abc.h:253
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
ABC_DLL int Abc_SopGetCubeNum(char *pSop)
Definition: abcSop.c:489
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
void Abc_NodeSplitLarge(Abc_Obj_t *pNode)
Definition: abcFanOrder.c:245
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
#define assert(ex)
Definition: util_old.h:213
void * pData
Definition: abc.h:145