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

Go to the source code of this file.

Data Structures

struct  Rwr_Man_t_
 
struct  Rwr_Node_t_
 

Macros

#define RWR_LIMIT   1048576/4
 INCLUDES ///. More...
 

Typedefs

typedef struct Rwr_Man_t_ Rwr_Man_t
 
typedef struct Rwr_Node_t_ Rwr_Node_t
 

Functions

static int Rwr_IsComplement (Rwr_Node_t *p)
 
static Rwr_Node_tRwr_Regular (Rwr_Node_t *p)
 
static Rwr_Node_tRwr_Not (Rwr_Node_t *p)
 
static Rwr_Node_tRwr_NotCond (Rwr_Node_t *p, int c)
 
void Rwr_ManPreprocess (Rwr_Man_t *p)
 MACRO DEFINITIONS ///. More...
 
int Rwr_NodeRewrite (Rwr_Man_t *p, Cut_Man_t *pManCut, Abc_Obj_t *pNode, int fUpdateLevel, int fUseZeros, int fPlaceEnable)
 FUNCTION DEFINITIONS ///. More...
 
void Rwr_ScoresClean (Rwr_Man_t *p)
 
void Rwr_ScoresReport (Rwr_Man_t *p)
 
void Rwr_ManPrecompute (Rwr_Man_t *p)
 FUNCTION DEFINITIONS ///. More...
 
Rwr_Node_tRwr_ManAddVar (Rwr_Man_t *p, unsigned uTruth, int fPrecompute)
 
Rwr_Node_tRwr_ManAddNode (Rwr_Man_t *p, Rwr_Node_t *p0, Rwr_Node_t *p1, int fExor, int Level, int Volume)
 
int Rwr_ManNodeVolume (Rwr_Man_t *p, Rwr_Node_t *p0, Rwr_Node_t *p1)
 
void Rwr_ManIncTravId (Rwr_Man_t *p)
 
Rwr_Man_tRwr_ManStart (int fPrecompute)
 DECLARATIONS ///. More...
 
void Rwr_ManStop (Rwr_Man_t *p)
 
void Rwr_ManPrintStats (Rwr_Man_t *p)
 
void Rwr_ManPrintStatsFile (Rwr_Man_t *p)
 
void * Rwr_ManReadDecs (Rwr_Man_t *p)
 
Vec_Ptr_tRwr_ManReadLeaves (Rwr_Man_t *p)
 
int Rwr_ManReadCompl (Rwr_Man_t *p)
 
void Rwr_ManAddTimeCuts (Rwr_Man_t *p, abctime Time)
 
void Rwr_ManAddTimeUpdate (Rwr_Man_t *p, abctime Time)
 
void Rwr_ManAddTimeTotal (Rwr_Man_t *p, abctime Time)
 
void Rwr_ManPrint (Rwr_Man_t *p)
 
void Rwr_ManWriteToArray (Rwr_Man_t *p)
 FUNCTION DEFINITIONS ///. More...
 
void Rwr_ManLoadFromArray (Rwr_Man_t *p, int fVerbose)
 
void Rwr_ManWriteToFile (Rwr_Man_t *p, char *pFileName)
 
void Rwr_ManLoadFromFile (Rwr_Man_t *p, char *pFileName)
 
void Rwr_ListAddToTail (Rwr_Node_t **ppList, Rwr_Node_t *pNode)
 
char * Rwr_ManGetPractical (Rwr_Man_t *p)
 

Macro Definition Documentation

#define RWR_LIMIT   1048576/4

INCLUDES ///.

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

FileName [rwr.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [DAG-aware AIG rewriting package.]

Synopsis [External declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

Id:
rwr.h,v 1.00 2005/06/20 00:00:00 alanmi Exp

]PARAMETERS ///BASIC TYPES ///

Definition at line 45 of file rwr.h.

Typedef Documentation

typedef struct Rwr_Man_t_ Rwr_Man_t

Definition at line 47 of file rwr.h.

typedef struct Rwr_Node_t_ Rwr_Node_t

Definition at line 48 of file rwr.h.

Function Documentation

static int Rwr_IsComplement ( Rwr_Node_t p)
inlinestatic

Definition at line 116 of file rwr.h.

116 { return (int )(((ABC_PTRUINT_T)p) & 01); }
void Rwr_ListAddToTail ( Rwr_Node_t **  ppList,
Rwr_Node_t pNode 
)

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

Synopsis [Adds the node to the end of the list.]

Description []

SideEffects []

SeeAlso []

Definition at line 619 of file rwrUtil.c.

620 {
621  Rwr_Node_t * pTemp;
622  // find the last one
623  for ( pTemp = *ppList; pTemp; pTemp = pTemp->pNext )
624  ppList = &pTemp->pNext;
625  // attach at the end
626  *ppList = pNode;
627 }
Rwr_Node_t * pNext
Definition: rwr.h:112
Rwr_Node_t* Rwr_ManAddNode ( Rwr_Man_t p,
Rwr_Node_t p0,
Rwr_Node_t p1,
int  fExor,
int  Level,
int  Volume 
)

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

Synopsis [Adds one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 206 of file rwrLib.c.

207 {
208  Rwr_Node_t * pNew;
209  unsigned uTruth;
210  // compute truth table, leve, volume
211  p->nConsidered++;
212  if ( fExor )
213  uTruth = (p0->uTruth ^ p1->uTruth);
214  else
215  uTruth = (Rwr_IsComplement(p0)? ~Rwr_Regular(p0)->uTruth : Rwr_Regular(p0)->uTruth) &
216  (Rwr_IsComplement(p1)? ~Rwr_Regular(p1)->uTruth : Rwr_Regular(p1)->uTruth) & 0xFFFF;
217  // create the new node
219  pNew->Id = p->vForest->nSize;
220  pNew->TravId = 0;
221  pNew->uTruth = uTruth;
222  pNew->Level = Level;
223  pNew->Volume = Volume;
224  pNew->fUsed = 0;
225  pNew->fExor = fExor;
226  pNew->p0 = p0;
227  pNew->p1 = p1;
228  pNew->pNext = NULL;
229  Vec_PtrPush( p->vForest, pNew );
230  // do not add if the node is not essential
231  if ( uTruth != p->puCanons[uTruth] )
232  return pNew;
233 
234  // add to the list
235  p->nAdded++;
236  if ( p->pTable[uTruth] == NULL )
237  p->nClasses++;
238  Rwr_ListAddToTail( p->pTable + uTruth, pNew );
239  return pNew;
240 }
unsigned fUsed
Definition: rwr.h:108
int nConsidered
Definition: rwr.h:68
int Id
Definition: rwr.h:100
unsigned Level
Definition: rwr.h:107
unsigned short * puCanons
Definition: rwr.h:54
unsigned uTruth
Definition: rwr.h:105
static int Rwr_IsComplement(Rwr_Node_t *p)
Definition: rwr.h:116
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
Rwr_Node_t * p0
Definition: rwr.h:110
char * Extra_MmFixedEntryFetch(Extra_MmFixed_t *p)
Extra_MmFixed_t * pMmNode
Definition: rwr.h:65
int TravId
Definition: rwr.h:101
unsigned fExor
Definition: rwr.h:109
int nClasses
Definition: rwr.h:70
Rwr_Node_t ** pTable
Definition: rwr.h:63
Rwr_Node_t * p1
Definition: rwr.h:111
unsigned Volume
Definition: rwr.h:106
int nAdded
Definition: rwr.h:69
void Rwr_ListAddToTail(Rwr_Node_t **ppList, Rwr_Node_t *pNode)
Definition: rwrUtil.c:619
Rwr_Node_t * pNext
Definition: rwr.h:112
static Rwr_Node_t * Rwr_Regular(Rwr_Node_t *p)
Definition: rwr.h:117
Vec_Ptr_t * vForest
Definition: rwr.h:62
void Rwr_ManAddTimeCuts ( Rwr_Man_t p,
abctime  Time 
)

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 261 of file rwrMan.c.

262 {
263  p->timeCut += Time;
264 }
abctime timeCut
Definition: rwr.h:90
void Rwr_ManAddTimeTotal ( Rwr_Man_t p,
abctime  Time 
)

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 293 of file rwrMan.c.

294 {
295  p->timeTotal += Time;
296 }
abctime timeTotal
Definition: rwr.h:95
void Rwr_ManAddTimeUpdate ( Rwr_Man_t p,
abctime  Time 
)

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 277 of file rwrMan.c.

278 {
279  p->timeUpdate += Time;
280 }
abctime timeUpdate
Definition: rwr.h:94
Rwr_Node_t* Rwr_ManAddVar ( Rwr_Man_t p,
unsigned  uTruth,
int  fPrecompute 
)

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

Synopsis [Adds one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 253 of file rwrLib.c.

254 {
255  Rwr_Node_t * pNew;
257  pNew->Id = p->vForest->nSize;
258  pNew->TravId = 0;
259  pNew->uTruth = uTruth;
260  pNew->Level = 0;
261  pNew->Volume = 0;
262  pNew->fUsed = 1;
263  pNew->fExor = 0;
264  pNew->p0 = NULL;
265  pNew->p1 = NULL;
266  pNew->pNext = NULL;
267  Vec_PtrPush( p->vForest, pNew );
268  if ( fPrecompute )
269  Rwr_ListAddToTail( p->pTable + uTruth, pNew );
270  return pNew;
271 }
unsigned fUsed
Definition: rwr.h:108
int Id
Definition: rwr.h:100
unsigned Level
Definition: rwr.h:107
unsigned uTruth
Definition: rwr.h:105
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
Rwr_Node_t * p0
Definition: rwr.h:110
char * Extra_MmFixedEntryFetch(Extra_MmFixed_t *p)
Extra_MmFixed_t * pMmNode
Definition: rwr.h:65
int TravId
Definition: rwr.h:101
unsigned fExor
Definition: rwr.h:109
Rwr_Node_t ** pTable
Definition: rwr.h:63
Rwr_Node_t * p1
Definition: rwr.h:111
unsigned Volume
Definition: rwr.h:106
void Rwr_ListAddToTail(Rwr_Node_t **ppList, Rwr_Node_t *pNode)
Definition: rwrUtil.c:619
Rwr_Node_t * pNext
Definition: rwr.h:112
Vec_Ptr_t * vForest
Definition: rwr.h:62
char* Rwr_ManGetPractical ( Rwr_Man_t p)

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

Synopsis [Create practical classes.]

Description []

SideEffects []

SeeAlso []

Definition at line 640 of file rwrUtil.c.

641 {
642  char * pPractical;
643  int i;
644  pPractical = ABC_ALLOC( char, p->nFuncs );
645  memset( pPractical, 0, sizeof(char) * p->nFuncs );
646  pPractical[0] = 1;
647  for ( i = 1; ; i++ )
648  {
649  if ( s_RwrPracticalClasses[i] == 0 )
650  break;
651  pPractical[ s_RwrPracticalClasses[i] ] = 1;
652  }
653  return pPractical;
654 }
char * memset()
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static ABC_NAMESPACE_IMPL_START unsigned short s_RwrPracticalClasses[]
DECLARATIONS ///.
Definition: rwrUtil.c:33
int nFuncs
Definition: rwr.h:53
void Rwr_ManIncTravId ( Rwr_Man_t p)

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

Synopsis [Adds one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 350 of file rwrLib.c.

351 {
352  Rwr_Node_t * pNode;
353  int i;
354  if ( p->nTravIds++ < 0x8FFFFFFF )
355  return;
356  Vec_PtrForEachEntry( Rwr_Node_t *, p->vForest, pNode, i )
357  pNode->TravId = 0;
358  p->nTravIds = 1;
359 }
int nTravIds
Definition: rwr.h:67
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
Vec_Ptr_t * vForest
Definition: rwr.h:62
void Rwr_ManLoadFromArray ( Rwr_Man_t p,
int  fVerbose 
)

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

Synopsis [Loads data.]

Description []

SideEffects []

SeeAlso []

Definition at line 472 of file rwrUtil.c.

473 {
474  unsigned short * pArray = s_RwtAigSubgraphs;
475  Rwr_Node_t * p0, * p1;
476  unsigned Entry0, Entry1;
477  int Level, Volume, nEntries, fExor;
478  int i;
479  abctime clk = Abc_Clock();
480 
481  // reconstruct the forest
482  for ( i = 0; ; i++ )
483  {
484  Entry0 = pArray[2*i + 0];
485  Entry1 = pArray[2*i + 1];
486  if ( Entry0 == 0 && Entry1 == 0 )
487  break;
488  // get EXOR flag
489  fExor = (Entry0 & 1);
490  Entry0 >>= 1;
491  // get the nodes
492  p0 = (Rwr_Node_t *)p->vForest->pArray[Entry0 >> 1];
493  p1 = (Rwr_Node_t *)p->vForest->pArray[Entry1 >> 1];
494  // compute the level and volume of the new nodes
495  Level = 1 + Abc_MaxInt( p0->Level, p1->Level );
496  Volume = 1 + Rwr_ManNodeVolume( p, p0, p1 );
497  // set the complemented attributes
498  p0 = Rwr_NotCond( p0, (Entry0 & 1) );
499  p1 = Rwr_NotCond( p1, (Entry1 & 1) );
500  // add the node
501 // Rwr_ManTryNode( p, p0, p1, Level, Volume );
502  Rwr_ManAddNode( p, p0, p1, fExor, Level, Volume + fExor );
503  }
504  nEntries = i - 1;
505  if ( fVerbose )
506  {
507  printf( "The number of classes = %d. Canonical nodes = %d.\n", p->nClasses, p->nAdded );
508  printf( "The number of nodes loaded = %d. ", nEntries ); ABC_PRT( "Loading", Abc_Clock() - clk );
509  }
510 }
unsigned Level
Definition: rwr.h:107
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static Rwr_Node_t * Rwr_NotCond(Rwr_Node_t *p, int c)
Definition: rwr.h:119
static unsigned short s_RwtAigSubgraphs[]
Definition: rwrUtil.c:50
int Rwr_ManNodeVolume(Rwr_Man_t *p, Rwr_Node_t *p0, Rwr_Node_t *p1)
Definition: rwrLib.c:330
int nClasses
Definition: rwr.h:70
#define ABC_PRT(a, t)
Definition: abc_global.h:220
int nAdded
Definition: rwr.h:69
Rwr_Node_t * Rwr_ManAddNode(Rwr_Man_t *p, Rwr_Node_t *p0, Rwr_Node_t *p1, int fExor, int Level, int Volume)
Definition: rwrLib.c:206
ABC_INT64_T abctime
Definition: abc_global.h:278
Vec_Ptr_t * vForest
Definition: rwr.h:62
void Rwr_ManLoadFromFile ( Rwr_Man_t p,
char *  pFileName 
)

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

Synopsis [Loads data.]

Description []

SideEffects []

SeeAlso []

Definition at line 562 of file rwrUtil.c.

563 {
564  FILE * pFile;
565  Rwr_Node_t * p0, * p1;
566  unsigned * pBuffer;
567  int Level, Volume, nEntries, fExor;
568  int i;
569  abctime clk = Abc_Clock();
570  int RetValue;
571 
572  // load the data
573  pFile = fopen( pFileName, "rb" );
574  if ( pFile == NULL )
575  {
576  printf( "Rwr_ManLoadFromFile: Cannot open file \"%s\".\n", pFileName );
577  return;
578  }
579  RetValue = fread( &nEntries, sizeof(int), 1, pFile );
580  pBuffer = ABC_ALLOC( unsigned, nEntries * 2 );
581  RetValue = fread( pBuffer, sizeof(unsigned), nEntries * 2, pFile );
582  fclose( pFile );
583  // reconstruct the forest
584  for ( i = 0; i < nEntries; i++ )
585  {
586  // get EXOR flag
587  fExor = (pBuffer[2*i + 0] & 1);
588  pBuffer[2*i + 0] = (pBuffer[2*i + 0] >> 1);
589  // get the nodes
590  p0 = (Rwr_Node_t *)p->vForest->pArray[pBuffer[2*i + 0] >> 1];
591  p1 = (Rwr_Node_t *)p->vForest->pArray[pBuffer[2*i + 1] >> 1];
592  // compute the level and volume of the new nodes
593  Level = 1 + Abc_MaxInt( p0->Level, p1->Level );
594  Volume = 1 + Rwr_ManNodeVolume( p, p0, p1 );
595  // set the complemented attributes
596  p0 = Rwr_NotCond( p0, (pBuffer[2*i + 0] & 1) );
597  p1 = Rwr_NotCond( p1, (pBuffer[2*i + 1] & 1) );
598  // add the node
599 // Rwr_ManTryNode( p, p0, p1, Level, Volume );
600  Rwr_ManAddNode( p, p0, p1, fExor, Level, Volume + fExor );
601  }
602  ABC_FREE( pBuffer );
603  printf( "The number of classes = %d. Canonical nodes = %d.\n", p->nClasses, p->nAdded );
604  printf( "The number of nodes loaded = %d. ", nEntries ); ABC_PRT( "Loading", Abc_Clock() - clk );
605 }
unsigned Level
Definition: rwr.h:107
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static Rwr_Node_t * Rwr_NotCond(Rwr_Node_t *p, int c)
Definition: rwr.h:119
int Rwr_ManNodeVolume(Rwr_Man_t *p, Rwr_Node_t *p0, Rwr_Node_t *p1)
Definition: rwrLib.c:330
int nClasses
Definition: rwr.h:70
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_PRT(a, t)
Definition: abc_global.h:220
int nAdded
Definition: rwr.h:69
Rwr_Node_t * Rwr_ManAddNode(Rwr_Man_t *p, Rwr_Node_t *p0, Rwr_Node_t *p1, int fExor, int Level, int Volume)
Definition: rwrLib.c:206
ABC_INT64_T abctime
Definition: abc_global.h:278
Vec_Ptr_t * vForest
Definition: rwr.h:62
int Rwr_ManNodeVolume ( Rwr_Man_t p,
Rwr_Node_t p0,
Rwr_Node_t p1 
)

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

Synopsis [Adds one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 330 of file rwrLib.c.

331 {
332  int Volume = 0;
333  Rwr_ManIncTravId( p );
334  Rwr_Trav_rec( p, p0, &Volume );
335  Rwr_Trav_rec( p, p1, &Volume );
336  return Volume;
337 }
void Rwr_ManIncTravId(Rwr_Man_t *p)
Definition: rwrLib.c:350
void Rwr_Trav_rec(Rwr_Man_t *p, Rwr_Node_t *pNode, int *pVolume)
Definition: rwrLib.c:307
void Rwr_ManPrecompute ( Rwr_Man_t p)

FUNCTION DEFINITIONS ///.

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

Synopsis [Precomputes the forest in the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 48 of file rwrLib.c.

49 {
50  Rwr_Node_t * p0, * p1;
51  int i, k, Level, Volume;
52  int LevelOld = -1;
53  int nNodes;
54 
56  Vec_PtrForEachEntryStart( Rwr_Node_t *, p->vForest, p1, k, 1 )
57  {
58  if ( LevelOld < (int)p0->Level )
59  {
60  LevelOld = p0->Level;
61  printf( "Starting level %d (at %d nodes).\n", LevelOld+1, i );
62  printf( "Considered = %5d M. Found = %8d. Classes = %6d. Trying %7d.\n",
63  p->nConsidered/1000000, p->vForest->nSize, p->nClasses, i );
64  }
65 
66  if ( k == i )
67  break;
68 // if ( p0->Level + p1->Level > 6 ) // hard
69 // break;
70 
71  if ( p0->Level + p1->Level > 5 ) // easy
72  break;
73 
74 // if ( p0->Level + p1->Level > 6 || (p0->Level == 3 && p1->Level == 3) )
75 // break;
76 
77  // compute the level and volume of the new nodes
78  Level = 1 + Abc_MaxInt( p0->Level, p1->Level );
79  Volume = 1 + Rwr_ManNodeVolume( p, p0, p1 );
80  // try four different AND nodes
81  Rwr_ManTryNode( p, p0 , p1 , 0, Level, Volume );
82  Rwr_ManTryNode( p, Rwr_Not(p0), p1 , 0, Level, Volume );
83  Rwr_ManTryNode( p, p0 , Rwr_Not(p1), 0, Level, Volume );
84  Rwr_ManTryNode( p, Rwr_Not(p0), Rwr_Not(p1), 0, Level, Volume );
85  // try EXOR
86  Rwr_ManTryNode( p, p0 , p1 , 1, Level, Volume + 1 );
87  // report the progress
88  if ( p->nConsidered % 50000000 == 0 )
89  printf( "Considered = %5d M. Found = %8d. Classes = %6d. Trying %7d.\n",
90  p->nConsidered/1000000, p->vForest->nSize, p->nClasses, i );
91  // quit after some time
92  if ( p->vForest->nSize == RWR_LIMIT + 5 )
93  {
94  printf( "Considered = %5d M. Found = %8d. Classes = %6d. Trying %7d.\n",
95  p->nConsidered/1000000, p->vForest->nSize, p->nClasses, i );
96  goto save;
97  }
98  }
99 save :
100 
101  // mark the relevant ones
102  Rwr_ManIncTravId( p );
103  k = 5;
104  nNodes = 0;
105  Vec_PtrForEachEntryStart( Rwr_Node_t *, p->vForest, p0, i, 5 )
106  if ( p0->uTruth == p->puCanons[p0->uTruth] )
107  {
108  Rwr_MarkUsed_rec( p, p0 );
109  nNodes++;
110  }
111 
112  // compact the array by throwing away non-canonical
113  k = 5;
114  Vec_PtrForEachEntryStart( Rwr_Node_t *, p->vForest, p0, i, 5 )
115  if ( p0->fUsed )
116  {
117  p->vForest->pArray[k] = p0;
118  p0->Id = k++;
119  }
120  p->vForest->nSize = k;
121  printf( "Total canonical = %4d. Total used = %5d.\n", nNodes, p->vForest->nSize );
122 }
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition: vecPtr.h:57
int nConsidered
Definition: rwr.h:68
static void Rwr_MarkUsed_rec(Rwr_Man_t *p, Rwr_Node_t *pNode)
Definition: rwrLib.c:286
int Id
Definition: rwr.h:100
unsigned Level
Definition: rwr.h:107
int Rwr_ManNodeVolume(Rwr_Man_t *p, Rwr_Node_t *p0, Rwr_Node_t *p1)
Definition: rwrLib.c:330
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
#define RWR_LIMIT
INCLUDES ///.
Definition: rwr.h:45
static ABC_NAMESPACE_IMPL_START Rwr_Node_t * Rwr_ManTryNode(Rwr_Man_t *p, Rwr_Node_t *p0, Rwr_Node_t *p1, int fExor, int Level, int Volume)
DECLARATIONS ///.
Definition: rwrLib.c:135
if(last==0)
Definition: sparse_int.h:34
void Rwr_ManIncTravId(Rwr_Man_t *p)
Definition: rwrLib.c:350
int nClasses
Definition: rwr.h:70
static Rwr_Node_t * Rwr_Not(Rwr_Node_t *p)
Definition: rwr.h:118
Vec_Ptr_t * vForest
Definition: rwr.h:62
void Rwr_ManPreprocess ( Rwr_Man_t p)

MACRO DEFINITIONS ///.

FUNCTION DECLARATIONS ///

MACRO DEFINITIONS ///.

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

Synopsis [Preprocesses computed library of subgraphs.]

Description []

SideEffects []

SeeAlso []

Definition at line 49 of file rwrDec.c.

50 {
51  Dec_Graph_t * pGraph;
52  Rwr_Node_t * pNode;
53  int i, k;
54  // put the nodes into the structure
55  p->pMapInv = ABC_ALLOC( unsigned short, 222 );
56  memset( p->pMapInv, 0, sizeof(unsigned short) * 222 );
57  p->vClasses = Vec_VecStart( 222 );
58  for ( i = 0; i < p->nFuncs; i++ )
59  {
60  if ( p->pTable[i] == NULL )
61  continue;
62  // consider all implementations of this function
63  for ( pNode = p->pTable[i]; pNode; pNode = pNode->pNext )
64  {
65  assert( pNode->uTruth == p->pTable[i]->uTruth );
66  assert( p->pMap[pNode->uTruth] < 222 ); // Guaranteed to be >=0 b/c unsigned
67  Vec_VecPush( p->vClasses, p->pMap[pNode->uTruth], pNode );
68  p->pMapInv[ p->pMap[pNode->uTruth] ] = p->puCanons[pNode->uTruth];
69  }
70  }
71  // compute decomposition forms for each node and verify them
72  Vec_VecForEachEntry( Rwr_Node_t *, p->vClasses, pNode, i, k )
73  {
74  pGraph = Rwr_NodePreprocess( p, pNode );
75  pNode->pNext = (Rwr_Node_t *)pGraph;
76  assert( pNode->uTruth == (Dec_GraphDeriveTruth(pGraph) & 0xFFFF) );
77  }
78 }
char * memset()
static void Vec_VecPush(Vec_Vec_t *p, int Level, void *Entry)
Definition: vecVec.h:456
unsigned char * pMap
Definition: rwr.h:57
#define Vec_VecForEachEntry(Type, vGlob, pEntry, i, k)
Definition: vecVec.h:87
unsigned short * puCanons
Definition: rwr.h:54
unsigned uTruth
Definition: rwr.h:105
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Vec_Vec_t * vClasses
Definition: rwr.h:64
unsigned Dec_GraphDeriveTruth(Dec_Graph_t *pGraph)
Definition: decUtil.c:95
static Vec_Vec_t * Vec_VecStart(int nSize)
Definition: vecVec.h:168
unsigned short * pMapInv
Definition: rwr.h:58
static ABC_NAMESPACE_IMPL_START Dec_Graph_t * Rwr_NodePreprocess(Rwr_Man_t *p, Rwr_Node_t *pNode)
DECLARATIONS ///.
Definition: rwrDec.c:91
Rwr_Node_t ** pTable
Definition: rwr.h:63
#define assert(ex)
Definition: util_old.h:213
Rwr_Node_t * pNext
Definition: rwr.h:112
int nFuncs
Definition: rwr.h:53
void Rwr_ManPrint ( Rwr_Man_t p)

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

Synopsis [Prints one rwr node.]

Description []

SideEffects []

SeeAlso []

Definition at line 237 of file rwrPrint.c.

238 {
239  FILE * pFile;
240  Rwr_Node_t * pNode;
241  unsigned uTruth;
242  int Limit, Counter, Volume, nFuncs, i;
243  pFile = fopen( "graph_lib.txt", "w" );
244  Counter = 0;
245  Limit = (1 << 16);
246  for ( i = 0; i < Limit; i++ )
247  {
248  if ( p->pTable[i] == NULL )
249  continue;
250  if ( i != p->puCanons[i] )
251  continue;
252  fprintf( pFile, "\nClass %3d. Func %6d. ", p->pMap[i], Counter++ );
253  Rwr_GetBushVolume( p, i, &Volume, &nFuncs );
254  fprintf( pFile, "Roots = %3d. Vol = %3d. Sum = %3d. ", nFuncs, Volume, Rwr_GetBushSumOfVolumes(p, i) );
255  uTruth = i;
256  Extra_PrintBinary( pFile, &uTruth, 16 );
257  fprintf( pFile, "\n" );
258  for ( pNode = p->pTable[i]; pNode; pNode = pNode->pNext )
259  if ( pNode->uTruth == p->puCanons[pNode->uTruth] )
260  Rwr_NodePrint( pFile, p, pNode );
261  }
262  fclose( pFile );
263 }
unsigned char * pMap
Definition: rwr.h:57
unsigned short * puCanons
Definition: rwr.h:54
void Rwr_NodePrint(FILE *pFile, Rwr_Man_t *p, Rwr_Node_t *pNode)
Definition: rwrPrint.c:208
unsigned uTruth
Definition: rwr.h:105
void Rwr_GetBushVolume(Rwr_Man_t *p, int Entry, int *pVolume, int *pnFuncs)
Definition: rwrPrint.c:66
static int Counter
int Rwr_GetBushSumOfVolumes(Rwr_Man_t *p, int Entry)
Definition: rwrPrint.c:94
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
Rwr_Node_t ** pTable
Definition: rwr.h:63
Rwr_Node_t * pNext
Definition: rwr.h:112
void Rwr_ManPrintStats ( Rwr_Man_t p)

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 143 of file rwrMan.c.

144 {
145  int i, Counter = 0;
146  for ( i = 0; i < 222; i++ )
147  Counter += (p->nScores[i] > 0);
148 
149  printf( "Rewriting statistics:\n" );
150  printf( "Total cuts tries = %8d.\n", p->nCutsGood );
151  printf( "Bad cuts found = %8d.\n", p->nCutsBad );
152  printf( "Total subgraphs = %8d.\n", p->nSubgraphs );
153  printf( "Used NPN classes = %8d.\n", Counter );
154  printf( "Nodes considered = %8d.\n", p->nNodesConsidered );
155  printf( "Nodes rewritten = %8d.\n", p->nNodesRewritten );
156  printf( "Gain = %8d. (%6.2f %%).\n", p->nNodesBeg-p->nNodesEnd, 100.0*(p->nNodesBeg-p->nNodesEnd)/p->nNodesBeg );
157  ABC_PRT( "Start ", p->timeStart );
158  ABC_PRT( "Cuts ", p->timeCut );
159  ABC_PRT( "Resynthesis ", p->timeRes );
160  ABC_PRT( " Mffc ", p->timeMffc );
161  ABC_PRT( " Eval ", p->timeEval );
162  ABC_PRT( "Update ", p->timeUpdate );
163  ABC_PRT( "TOTAL ", p->timeTotal );
164 
165 /*
166  printf( "The scores are:\n" );
167  for ( i = 0; i < 222; i++ )
168  if ( p->nScores[i] > 0 )
169  {
170  extern void Ivy_TruthDsdComputePrint( unsigned uTruth );
171  printf( "%3d = %8d canon = %5d ", i, p->nScores[i], p->pMapInv[i] );
172  Ivy_TruthDsdComputePrint( (unsigned)p->pMapInv[i] | ((unsigned)p->pMapInv[i] << 16) );
173  }
174 */
175  printf( "\n" );
176 
177 }
abctime timeTotal
Definition: rwr.h:95
abctime timeEval
Definition: rwr.h:92
abctime timeStart
Definition: rwr.h:89
int nNodesEnd
Definition: rwr.h:83
int nNodesBeg
Definition: rwr.h:82
abctime timeCut
Definition: rwr.h:90
static int Counter
int nSubgraphs
Definition: rwr.h:87
int nCutsGood
Definition: rwr.h:85
#define ABC_PRT(a, t)
Definition: abc_global.h:220
int nCutsBad
Definition: rwr.h:86
int nNodesRewritten
Definition: rwr.h:80
int nNodesConsidered
Definition: rwr.h:79
abctime timeMffc
Definition: rwr.h:93
abctime timeUpdate
Definition: rwr.h:94
abctime timeRes
Definition: rwr.h:91
int nScores[222]
Definition: rwr.h:84
void Rwr_ManPrintStatsFile ( Rwr_Man_t p)

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 190 of file rwrMan.c.

191 {
192  FILE * pTable;
193  pTable = fopen( "stats.txt", "a+" );
194  fprintf( pTable, "%d ", p->nCutsGood );
195  fprintf( pTable, "%d ", p->nSubgraphs );
196  fprintf( pTable, "%d ", p->nNodesRewritten );
197  fprintf( pTable, "%d", p->nNodesGained );
198  fprintf( pTable, "\n" );
199  fclose( pTable );
200 }
int nNodesGained
Definition: rwr.h:81
int nSubgraphs
Definition: rwr.h:87
int nCutsGood
Definition: rwr.h:85
int nNodesRewritten
Definition: rwr.h:80
int Rwr_ManReadCompl ( Rwr_Man_t p)

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 245 of file rwrMan.c.

246 {
247  return p->fCompl;
248 }
int fCompl
Definition: rwr.h:72
void* Rwr_ManReadDecs ( Rwr_Man_t p)

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 213 of file rwrMan.c.

214 {
215  return p->pGraph;
216 }
void * pGraph
Definition: rwr.h:73
Vec_Ptr_t* Rwr_ManReadLeaves ( Rwr_Man_t p)

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 229 of file rwrMan.c.

230 {
231  return p->vFanins;
232 }
Vec_Ptr_t * vFanins
Definition: rwr.h:74
Rwr_Man_t* Rwr_ManStart ( int  fPrecompute)

DECLARATIONS ///.

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

FileName [rwrMan.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [DAG-aware AIG rewriting package.]

Synopsis [Rewriting manager.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

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

Synopsis [Starts rewriting manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 47 of file rwrMan.c.

48 {
49  Dec_Man_t * pManDec;
50  Rwr_Man_t * p;
51  abctime clk = Abc_Clock();
52 clk = Abc_Clock();
53  p = ABC_ALLOC( Rwr_Man_t, 1 );
54  memset( p, 0, sizeof(Rwr_Man_t) );
55  p->nFuncs = (1<<16);
56  pManDec = (Dec_Man_t *)Abc_FrameReadManDec();
57  p->puCanons = pManDec->puCanons;
58  p->pPhases = pManDec->pPhases;
59  p->pPerms = pManDec->pPerms;
60  p->pMap = pManDec->pMap;
61  // initialize practical NPN classes
63  // create the table
64  p->pTable = ABC_ALLOC( Rwr_Node_t *, p->nFuncs );
65  memset( p->pTable, 0, sizeof(Rwr_Node_t *) * p->nFuncs );
66  // create the elementary nodes
67  p->pMmNode = Extra_MmFixedStart( sizeof(Rwr_Node_t) );
68  p->vForest = Vec_PtrAlloc( 100 );
69  Rwr_ManAddVar( p, 0x0000, fPrecompute ); // constant 0
70  Rwr_ManAddVar( p, 0xAAAA, fPrecompute ); // var A
71  Rwr_ManAddVar( p, 0xCCCC, fPrecompute ); // var B
72  Rwr_ManAddVar( p, 0xF0F0, fPrecompute ); // var C
73  Rwr_ManAddVar( p, 0xFF00, fPrecompute ); // var D
74  p->nClasses = 5;
75  // other stuff
76  p->nTravIds = 1;
77  p->pPerms4 = Extra_Permutations( 4 );
78  p->vLevNums = Vec_IntAlloc( 50 );
79  p->vFanins = Vec_PtrAlloc( 50 );
80  p->vFaninsCur = Vec_PtrAlloc( 50 );
81  p->vNodesTemp = Vec_PtrAlloc( 50 );
82  if ( fPrecompute )
83  { // precompute subgraphs
84  Rwr_ManPrecompute( p );
85 // Rwr_ManPrint( p );
87  }
88  else
89  { // load saved subgraphs
90  Rwr_ManLoadFromArray( p, 0 );
91 // Rwr_ManPrint( p );
92  Rwr_ManPreprocess( p );
93  }
94 p->timeStart = Abc_Clock() - clk;
95  return p;
96 }
char * memset()
char * Rwr_ManGetPractical(Rwr_Man_t *p)
Definition: rwrUtil.c:640
abctime timeStart
Definition: rwr.h:89
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Rwr_Node_t * Rwr_ManAddVar(Rwr_Man_t *p, unsigned uTruth, int fPrecompute)
Definition: rwrLib.c:253
void Rwr_ManPrecompute(Rwr_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: rwrLib.c:48
unsigned char * pMap
Definition: rwr.h:57
Definition: rwr.h:50
void Rwr_ManWriteToArray(Rwr_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: rwrUtil.c:426
unsigned short * puCanons
Definition: rwr.h:54
void Rwr_ManPreprocess(Rwr_Man_t *p)
MACRO DEFINITIONS ///.
Definition: rwrDec.c:49
char ** pPerms4
Definition: rwr.h:60
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * pPhases
Definition: dec.h:87
Vec_Ptr_t * vNodesTemp
Definition: rwr.h:77
Vec_Int_t * vLevNums
Definition: rwr.h:76
unsigned char * pMap
Definition: dec.h:89
static abctime Abc_Clock()
Definition: abc_global.h:279
Extra_MmFixed_t * pMmNode
Definition: rwr.h:65
int nTravIds
Definition: rwr.h:67
ABC_DLL void * Abc_FrameReadManDec()
Definition: mainFrame.c:61
char ** Extra_Permutations(int n)
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
Vec_Ptr_t * vFanins
Definition: rwr.h:74
Extra_MmFixed_t * Extra_MmFixedStart(int nEntrySize)
Vec_Ptr_t * vFaninsCur
Definition: rwr.h:75
unsigned short * puCanons
Definition: dec.h:86
char * pPhases
Definition: rwr.h:55
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
int nClasses
Definition: rwr.h:70
Rwr_Node_t ** pTable
Definition: rwr.h:63
void Rwr_ManLoadFromArray(Rwr_Man_t *p, int fVerbose)
Definition: rwrUtil.c:472
char * pPractical
Definition: rwr.h:59
Definition: dec.h:80
ABC_INT64_T abctime
Definition: abc_global.h:278
char * pPerms
Definition: dec.h:88
Vec_Ptr_t * vForest
Definition: rwr.h:62
int nFuncs
Definition: rwr.h:53
char * pPerms
Definition: rwr.h:56
void Rwr_ManStop ( Rwr_Man_t p)

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

Synopsis [Stops rewriting manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 109 of file rwrMan.c.

110 {
111  if ( p->vClasses )
112  {
113  Rwr_Node_t * pNode;
114  int i, k;
115  Vec_VecForEachEntry( Rwr_Node_t *, p->vClasses, pNode, i, k )
116  Dec_GraphFree( (Dec_Graph_t *)pNode->pNext );
117  }
118  if ( p->vClasses ) Vec_VecFree( p->vClasses );
119  Vec_PtrFree( p->vNodesTemp );
120  Vec_PtrFree( p->vForest );
121  Vec_IntFree( p->vLevNums );
122  Vec_PtrFree( p->vFanins );
123  Vec_PtrFree( p->vFaninsCur );
124  Extra_MmFixedStop( p->pMmNode );
125  ABC_FREE( p->pMapInv );
126  ABC_FREE( p->pTable );
127  ABC_FREE( p->pPractical );
128  ABC_FREE( p->pPerms4 );
129  ABC_FREE( p );
130 }
#define Vec_VecForEachEntry(Type, vGlob, pEntry, i, k)
Definition: vecVec.h:87
void Extra_MmFixedStop(Extra_MmFixed_t *p)
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
Vec_Vec_t * vClasses
Definition: rwr.h:64
if(last==0)
Definition: sparse_int.h:34
#define ABC_FREE(obj)
Definition: abc_global.h:232
static void Dec_GraphFree(Dec_Graph_t *pGraph)
Definition: dec.h:307
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
void Rwr_ManWriteToArray ( Rwr_Man_t p)

FUNCTION DEFINITIONS ///.

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

Synopsis [Writes data.]

Description []

SideEffects []

SeeAlso []

Definition at line 426 of file rwrUtil.c.

427 {
428  FILE * pFile;
429  Rwr_Node_t * pNode;
430  unsigned Entry0, Entry1;
431  int i, nEntries;
432  abctime clk = Abc_Clock();
433  // prepare the buffer
434  nEntries = p->vForest->nSize - 5;
435  pFile = fopen( "npn4_aig_array.txt", "w" );
436  fprintf( pFile, "static unsigned short s_RwtAigSubgraphs[] = \n{" );
437  for ( i = 0; i < nEntries; i++ )
438  {
439  if ( i % 5 == 0 )
440  fprintf( pFile, "\n " );
441  pNode = (Rwr_Node_t *)p->vForest->pArray[i+5];
442  Entry0 = (Rwr_Regular(pNode->p0)->Id << 1) | Rwr_IsComplement(pNode->p0);
443  Entry1 = (Rwr_Regular(pNode->p1)->Id << 1) | Rwr_IsComplement(pNode->p1);
444  Entry0 = (Entry0 << 1) | pNode->fExor;
445  Extra_PrintHex( pFile, &Entry0, 4 );
446  fprintf( pFile, "," );
447  Extra_PrintHex( pFile, &Entry1, 4 );
448  fprintf( pFile, ", " );
449  }
450  if ( i % 5 == 0 )
451  fprintf( pFile, "\n " );
452  Entry0 = 0;
453  Extra_PrintHex( pFile, &Entry0, 4 );
454  fprintf( pFile, "," );
455  Extra_PrintHex( pFile, &Entry0, 4 );
456  fprintf( pFile, " \n};\n" );
457  fclose( pFile );
458  printf( "The number of nodes saved = %d. ", nEntries ); ABC_PRT( "Saving", Abc_Clock() - clk );
459 }
int Id
Definition: rwr.h:100
static int Rwr_IsComplement(Rwr_Node_t *p)
Definition: rwr.h:116
Rwr_Node_t * p0
Definition: rwr.h:110
static abctime Abc_Clock()
Definition: abc_global.h:279
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
unsigned fExor
Definition: rwr.h:109
#define ABC_PRT(a, t)
Definition: abc_global.h:220
Rwr_Node_t * p1
Definition: rwr.h:111
ABC_INT64_T abctime
Definition: abc_global.h:278
static Rwr_Node_t * Rwr_Regular(Rwr_Node_t *p)
Definition: rwr.h:117
Vec_Ptr_t * vForest
Definition: rwr.h:62
void Rwr_ManWriteToFile ( Rwr_Man_t p,
char *  pFileName 
)

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

Synopsis [Writes.]

Description []

SideEffects []

SeeAlso []

Definition at line 524 of file rwrUtil.c.

525 {
526  FILE * pFile;
527  Rwr_Node_t * pNode;
528  unsigned * pBuffer;
529  int i, nEntries;
530  abctime clk = Abc_Clock();
531  // prepare the buffer
532  nEntries = p->vForest->nSize - 5;
533  pBuffer = ABC_ALLOC( unsigned, nEntries * 2 );
534  for ( i = 0; i < nEntries; i++ )
535  {
536  pNode = (Rwr_Node_t *)p->vForest->pArray[i+5];
537  pBuffer[2*i + 0] = (Rwr_Regular(pNode->p0)->Id << 1) | Rwr_IsComplement(pNode->p0);
538  pBuffer[2*i + 1] = (Rwr_Regular(pNode->p1)->Id << 1) | Rwr_IsComplement(pNode->p1);
539  // save EXOR flag
540  pBuffer[2*i + 0] = (pBuffer[2*i + 0] << 1) | pNode->fExor;
541 
542  }
543  pFile = fopen( pFileName, "wb" );
544  fwrite( &nEntries, sizeof(int), 1, pFile );
545  fwrite( pBuffer, sizeof(unsigned), nEntries * 2, pFile );
546  ABC_FREE( pBuffer );
547  fclose( pFile );
548  printf( "The number of nodes saved = %d. ", nEntries ); ABC_PRT( "Saving", Abc_Clock() - clk );
549 }
int Id
Definition: rwr.h:100
static int Rwr_IsComplement(Rwr_Node_t *p)
Definition: rwr.h:116
Rwr_Node_t * p0
Definition: rwr.h:110
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static abctime Abc_Clock()
Definition: abc_global.h:279
unsigned fExor
Definition: rwr.h:109
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_PRT(a, t)
Definition: abc_global.h:220
Rwr_Node_t * p1
Definition: rwr.h:111
ABC_INT64_T abctime
Definition: abc_global.h:278
static Rwr_Node_t * Rwr_Regular(Rwr_Node_t *p)
Definition: rwr.h:117
Vec_Ptr_t * vForest
Definition: rwr.h:62
int Rwr_NodeRewrite ( Rwr_Man_t p,
Cut_Man_t pManCut,
Abc_Obj_t pNode,
int  fUpdateLevel,
int  fUseZeros,
int  fPlaceEnable 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Performs rewriting for one node.]

Description [This procedure considers all the cuts computed for the node and tries to rewrite each of them using the "forest" of different AIG structures precomputed and stored in the RWR manager. Determines the best rewriting and computes the gain in the number of AIG nodes in the final network. In the end, p->vFanins contains information about the best cut that can be used for rewriting, while p->pGraph gives the decomposition dag (represented using decomposition graph data structure). Returns gain in the number of nodes or -1 if node cannot be rewritten.]

SideEffects []

SeeAlso []

Definition at line 59 of file rwrEva.c.

60 {
61  int fVeryVerbose = 0;
62  Dec_Graph_t * pGraph;
63  Cut_Cut_t * pCut;//, * pTemp;
64  Abc_Obj_t * pFanin;
65  unsigned uPhase;
66  unsigned uTruthBest = 0; // Suppress "might be used uninitialized"
67  unsigned uTruth;
68  char * pPerm;
69  int Required, nNodesSaved;
70  int nNodesSaveCur = -1; // Suppress "might be used uninitialized"
71  int i, GainCur = -1, GainBest = -1;
72  abctime clk, clk2;//, Counter;
73 
74  p->nNodesConsidered++;
75  // get the required times
76  Required = fUpdateLevel? Abc_ObjRequiredLevel(pNode) : ABC_INFINITY;
77 
78  // get the node's cuts
79 clk = Abc_Clock();
80  pCut = (Cut_Cut_t *)Abc_NodeGetCutsRecursive( pManCut, pNode, 0, 0 );
81  assert( pCut != NULL );
82 p->timeCut += Abc_Clock() - clk;
83 
84 //printf( " %d", Rwr_CutCountNumNodes(pNode, pCut) );
85 /*
86  Counter = 0;
87  for ( pTemp = pCut->pNext; pTemp; pTemp = pTemp->pNext )
88  Counter++;
89  printf( "%d ", Counter );
90 */
91  // go through the cuts
92 clk = Abc_Clock();
93  for ( pCut = pCut->pNext; pCut; pCut = pCut->pNext )
94  {
95  // consider only 4-input cuts
96  if ( pCut->nLeaves < 4 )
97  continue;
98 // Cut_CutPrint( pCut, 0 ), printf( "\n" );
99 
100  // get the fanin permutation
101  uTruth = 0xFFFF & *Cut_CutReadTruth(pCut);
102  pPerm = p->pPerms4[ (int)p->pPerms[uTruth] ];
103  uPhase = p->pPhases[uTruth];
104  // collect fanins with the corresponding permutation/phase
105  Vec_PtrClear( p->vFaninsCur );
106  Vec_PtrFill( p->vFaninsCur, (int)pCut->nLeaves, 0 );
107  for ( i = 0; i < (int)pCut->nLeaves; i++ )
108  {
109  pFanin = Abc_NtkObj( pNode->pNtk, pCut->pLeaves[(int)pPerm[i]] );
110  if ( pFanin == NULL )
111  break;
112  pFanin = Abc_ObjNotCond(pFanin, ((uPhase & (1<<i)) > 0) );
113  Vec_PtrWriteEntry( p->vFaninsCur, i, pFanin );
114  }
115  if ( i != (int)pCut->nLeaves )
116  {
117  p->nCutsBad++;
118  continue;
119  }
120  p->nCutsGood++;
121 
122  {
123  int Counter = 0;
124  Vec_PtrForEachEntry( Abc_Obj_t *, p->vFaninsCur, pFanin, i )
125  if ( Abc_ObjFanoutNum(Abc_ObjRegular(pFanin)) == 1 )
126  Counter++;
127  if ( Counter > 2 )
128  continue;
129  }
130 
131 clk2 = Abc_Clock();
132 /*
133  printf( "Considering: (" );
134  Vec_PtrForEachEntry( Abc_Obj_t *, p->vFaninsCur, pFanin, i )
135  printf( "%d ", Abc_ObjFanoutNum(Abc_ObjRegular(pFanin)) );
136  printf( ")\n" );
137 */
138  // mark the fanin boundary
139  Vec_PtrForEachEntry( Abc_Obj_t *, p->vFaninsCur, pFanin, i )
140  Abc_ObjRegular(pFanin)->vFanouts.nSize++;
141 
142  // label MFFC with current ID
143  Abc_NtkIncrementTravId( pNode->pNtk );
144  nNodesSaved = Abc_NodeMffcLabelAig( pNode );
145  // unmark the fanin boundary
146  Vec_PtrForEachEntry( Abc_Obj_t *, p->vFaninsCur, pFanin, i )
147  Abc_ObjRegular(pFanin)->vFanouts.nSize--;
148 p->timeMffc += Abc_Clock() - clk2;
149 
150  // evaluate the cut
151 clk2 = Abc_Clock();
152  pGraph = Rwr_CutEvaluate( p, pNode, pCut, p->vFaninsCur, nNodesSaved, Required, &GainCur, fPlaceEnable );
153 p->timeEval += Abc_Clock() - clk2;
154 
155  // check if the cut is better than the current best one
156  if ( pGraph != NULL && GainBest < GainCur )
157  {
158  // save this form
159  nNodesSaveCur = nNodesSaved;
160  GainBest = GainCur;
161  p->pGraph = pGraph;
162  p->fCompl = ((uPhase & (1<<4)) > 0);
163  uTruthBest = 0xFFFF & *Cut_CutReadTruth(pCut);
164  // collect fanins in the
165  Vec_PtrClear( p->vFanins );
166  Vec_PtrForEachEntry( Abc_Obj_t *, p->vFaninsCur, pFanin, i )
167  Vec_PtrPush( p->vFanins, pFanin );
168  }
169  }
170 p->timeRes += Abc_Clock() - clk;
171 
172  if ( GainBest == -1 )
173  return -1;
174 /*
175  if ( GainBest > 0 )
176  {
177  printf( "Class %d ", p->pMap[uTruthBest] );
178  printf( "Gain = %d. Node %d : ", GainBest, pNode->Id );
179  Vec_PtrForEachEntry( Abc_Obj_t *, p->vFanins, pFanin, i )
180  printf( "%d ", Abc_ObjRegular(pFanin)->Id );
181  Dec_GraphPrint( stdout, p->pGraph, NULL, NULL );
182  printf( "\n" );
183  }
184 */
185 
186 // printf( "%d", nNodesSaveCur - GainBest );
187 /*
188  if ( GainBest > 0 )
189  {
190  if ( Rwr_CutIsBoolean( pNode, p->vFanins ) )
191  printf( "b" );
192  else
193  {
194  printf( "Node %d : ", pNode->Id );
195  Vec_PtrForEachEntry( Abc_Obj_t *, p->vFanins, pFanin, i )
196  printf( "%d ", Abc_ObjRegular(pFanin)->Id );
197  printf( "a" );
198  }
199  }
200 */
201 /*
202  if ( GainBest > 0 )
203  if ( p->fCompl )
204  printf( "c" );
205  else
206  printf( "." );
207 */
208 
209  // copy the leaves
210  Vec_PtrForEachEntry( Abc_Obj_t *, p->vFanins, pFanin, i )
211  Dec_GraphNode((Dec_Graph_t *)p->pGraph, i)->pFunc = pFanin;
212 /*
213  printf( "(" );
214  Vec_PtrForEachEntry( Abc_Obj_t *, p->vFanins, pFanin, i )
215  printf( " %d", Abc_ObjRegular(pFanin)->vFanouts.nSize - 1 );
216  printf( " ) " );
217 */
218 // printf( "%d ", Rwr_NodeGetDepth_rec( pNode, p->vFanins ) );
219 
220  p->nScores[p->pMap[uTruthBest]]++;
221  p->nNodesGained += GainBest;
222  if ( fUseZeros || GainBest > 0 )
223  {
224  p->nNodesRewritten++;
225  }
226 
227  // report the progress
228  if ( fVeryVerbose && GainBest > 0 )
229  {
230  printf( "Node %6s : ", Abc_ObjName(pNode) );
231  printf( "Fanins = %d. ", p->vFanins->nSize );
232  printf( "Save = %d. ", nNodesSaveCur );
233  printf( "Add = %d. ", nNodesSaveCur-GainBest );
234  printf( "GAIN = %d. ", GainBest );
235  printf( "Cone = %d. ", p->pGraph? Dec_GraphNodeNum((Dec_Graph_t *)p->pGraph) : 0 );
236  printf( "Class = %d. ", p->pMap[uTruthBest] );
237  printf( "\n" );
238  }
239  return GainBest;
240 }
static int Dec_GraphNodeNum(Dec_Graph_t *pGraph)
Definition: dec.h:421
static void Vec_PtrFill(Vec_Ptr_t *p, int nSize, void *Entry)
Definition: vecPtr.h:449
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
static unsigned * Cut_CutReadTruth(Cut_Cut_t *p)
Definition: cut.h:94
Cut_Cut_t * pNext
Definition: cut.h:88
char ** pPerms4
Definition: rwr.h:60
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
ABC_DLL int Abc_NodeMffcLabelAig(Abc_Obj_t *pNode)
Definition: abcRefs.c:100
static abctime Abc_Clock()
Definition: abc_global.h:279
static Abc_Obj_t * Abc_NtkObj(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:314
abctime timeCut
Definition: rwr.h:90
int pLeaves[0]
Definition: cut.h:89
unsigned nLeaves
Definition: cut.h:84
ABC_DLL int Abc_ObjRequiredLevel(Abc_Obj_t *pObj)
Definition: abcTiming.c:1102
static ABC_NAMESPACE_IMPL_START Dec_Graph_t * Rwr_CutEvaluate(Rwr_Man_t *p, Abc_Obj_t *pRoot, Cut_Cut_t *pCut, Vec_Ptr_t *vFaninsCur, int nNodesSaved, int LevelMax, int *pGainBest, int fPlaceEnable)
DECLARATIONS ///.
Definition: rwrEva.c:253
Vec_Ptr_t * vFaninsCur
Definition: rwr.h:75
if(last==0)
Definition: sparse_int.h:34
ABC_DLL void * Abc_NodeGetCutsRecursive(void *p, Abc_Obj_t *pObj, int fDag, int fTree)
static int Counter
char * pPhases
Definition: rwr.h:55
static int pPerm[13719]
Definition: rwrTemp.c:32
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
int nCutsGood
Definition: rwr.h:85
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
Definition: abc.h:323
Abc_Ntk_t * pNtk
Definition: abc.h:130
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
int nCutsBad
Definition: rwr.h:86
static void Abc_NtkIncrementTravId(Abc_Ntk_t *p)
Definition: abc.h:406
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition: abc_global.h:216
int nNodesConsidered
Definition: rwr.h:79
static Abc_Obj_t * Abc_ObjNotCond(Abc_Obj_t *p, int c)
Definition: abc.h:325
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
static Dec_Node_t * Dec_GraphNode(Dec_Graph_t *pGraph, int i)
Definition: dec.h:437
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
ABC_INT64_T abctime
Definition: abc_global.h:278
char * pPerms
Definition: rwr.h:56
static Rwr_Node_t* Rwr_Not ( Rwr_Node_t p)
inlinestatic

Definition at line 118 of file rwr.h.

118 { return (Rwr_Node_t *)((ABC_PTRUINT_T)(p) ^ 01); }
static Rwr_Node_t* Rwr_NotCond ( Rwr_Node_t p,
int  c 
)
inlinestatic

Definition at line 119 of file rwr.h.

119 { return (Rwr_Node_t *)((ABC_PTRUINT_T)(p) ^ (c)); }
static Rwr_Node_t* Rwr_Regular ( Rwr_Node_t p)
inlinestatic

Definition at line 117 of file rwr.h.

117 { return (Rwr_Node_t *)((ABC_PTRUINT_T)(p) & ~01); }
void Rwr_ScoresClean ( Rwr_Man_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 504 of file rwrEva.c.

505 {
506  Vec_Ptr_t * vSubgraphs;
507  Rwr_Node_t * pNode;
508  int i, k;
509  for ( i = 0; i < p->vClasses->nSize; i++ )
510  {
511  vSubgraphs = Vec_VecEntry( p->vClasses, i );
512  Vec_PtrForEachEntry( Rwr_Node_t *, vSubgraphs, pNode, k )
513  pNode->nScore = pNode->nGain = pNode->nAdded = 0;
514  }
515 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Vec_Vec_t * vClasses
Definition: rwr.h:64
static Vec_Ptr_t * Vec_VecEntry(Vec_Vec_t *p, int i)
Definition: vecVec.h:271
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
void Rwr_ScoresReport ( Rwr_Man_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 550 of file rwrEva.c.

551 {
552  extern void Ivy_TruthDsdComputePrint( unsigned uTruth );
553  int Perm[222];
554  Vec_Ptr_t * vSubgraphs;
555  Rwr_Node_t * pNode;
556  int i, iNew, k;
557  unsigned uTruth;
558  // collect total gains
559  assert( p->vClasses->nSize == 222 );
560  for ( i = 0; i < p->vClasses->nSize; i++ )
561  {
562  Perm[i] = i;
563  Gains[i] = 0;
564  vSubgraphs = Vec_VecEntry( p->vClasses, i );
565  Vec_PtrForEachEntry( Rwr_Node_t *, vSubgraphs, pNode, k )
566  Gains[i] += pNode->nGain;
567  }
568  // sort the gains
569  qsort( Perm, 222, sizeof(int), (int (*)(const void *, const void *))Rwr_ScoresCompare );
570 
571  // print classes
572  for ( i = 0; i < p->vClasses->nSize; i++ )
573  {
574  iNew = Perm[i];
575  if ( Gains[iNew] == 0 )
576  break;
577  vSubgraphs = Vec_VecEntry( p->vClasses, iNew );
578  printf( "CLASS %3d: Subgr = %3d. Total gain = %6d. ", iNew, Vec_PtrSize(vSubgraphs), Gains[iNew] );
579  uTruth = (unsigned)p->pMapInv[iNew];
580  Extra_PrintBinary( stdout, &uTruth, 16 );
581  printf( " " );
582  Ivy_TruthDsdComputePrint( (unsigned)p->pMapInv[iNew] | ((unsigned)p->pMapInv[iNew] << 16) );
583  Vec_PtrForEachEntry( Rwr_Node_t *, vSubgraphs, pNode, k )
584  {
585  if ( pNode->nScore == 0 )
586  continue;
587  printf( " %2d: S=%5d. A=%5d. G=%6d. ", k, pNode->nScore, pNode->nAdded, pNode->nGain );
588  Dec_GraphPrint( stdout, (Dec_Graph_t *)pNode->pNext, NULL, NULL );
589  }
590  }
591 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
short nScore
Definition: rwr.h:102
int Rwr_ScoresCompare(int *pNum1, int *pNum2)
Definition: rwrEva.c:530
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
for(p=first;p->value< newval;p=p->next)
Vec_Vec_t * vClasses
Definition: rwr.h:64
short nGain
Definition: rwr.h:103
void Dec_GraphPrint(FILE *pFile, Dec_Graph_t *pGraph, char *pNamesIn[], char *pNameOut)
FUNCTION DEFINITIONS ///.
Definition: decPrint.c:49
static int Gains[222]
Definition: rwrEva.c:517
void Ivy_TruthDsdComputePrint(unsigned uTruth)
Definition: ivyDsd.c:678
unsigned short * pMapInv
Definition: rwr.h:58
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
#define assert(ex)
Definition: util_old.h:213
#define const
Definition: zconf.h:196
static Vec_Ptr_t * Vec_VecEntry(Vec_Vec_t *p, int i)
Definition: vecVec.h:271
short nAdded
Definition: rwr.h:104
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
Rwr_Node_t * pNext
Definition: rwr.h:112