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

Go to the source code of this file.

Functions

void Rwt_ListAddToTail (Rwt_Node_t **ppList, Rwt_Node_t *pNode)
 FUNCTION DEFINITIONS ///. More...
 
Rwt_Node_tRwt_ManAddVar (Rwt_Man_t *p, unsigned uTruth, int fPrecompute)
 
Rwt_Node_tRwt_ManAddNode (Rwt_Man_t *p, Rwt_Node_t *p0, Rwt_Node_t *p1, int fExor, int Level, int Volume)
 
void Rwt_Trav_rec (Rwt_Man_t *p, Rwt_Node_t *pNode, int *pVolume)
 
void Rwt_ManIncTravId (Rwt_Man_t *p)
 
int Rwt_ManNodeVolume (Rwt_Man_t *p, Rwt_Node_t *p0, Rwt_Node_t *p1)
 
void Rwt_ManLoadFromArray (Rwt_Man_t *p, int fVerbose)
 
char * Rwt_ManGetPractical (Rwt_Man_t *p)
 

Variables

static
ABC_NAMESPACE_IMPL_START
unsigned short 
s_RwtAigSubgraphs []
 DECLARATIONS ///. More...
 
static unsigned short s_RwtPracticalClasses []
 

Function Documentation

void Rwt_ListAddToTail ( Rwt_Node_t **  ppList,
Rwt_Node_t pNode 
)

FUNCTION DEFINITIONS ///.

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 425 of file rwtUtil.c.

426 {
427  Rwt_Node_t * pTemp;
428  // find the last one
429  for ( pTemp = *ppList; pTemp; pTemp = pTemp->pNext )
430  ppList = &pTemp->pNext;
431  // attach at the end
432  *ppList = pNode;
433 }
Rwt_Node_t * pNext
Definition: rwt.h:118
Rwt_Node_t* Rwt_ManAddNode ( Rwt_Man_t p,
Rwt_Node_t p0,
Rwt_Node_t p1,
int  fExor,
int  Level,
int  Volume 
)

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

Synopsis [Adds one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 477 of file rwtUtil.c.

478 {
479  Rwt_Node_t * pNew;
480  unsigned uTruth;
481  // compute truth table, leve, volume
482  p->nConsidered++;
483  if ( fExor )
484  uTruth = (p0->uTruth ^ p1->uTruth);
485  else
486  uTruth = (Rwt_IsComplement(p0)? ~Rwt_Regular(p0)->uTruth : Rwt_Regular(p0)->uTruth) &
487  (Rwt_IsComplement(p1)? ~Rwt_Regular(p1)->uTruth : Rwt_Regular(p1)->uTruth) & 0xFFFF;
488  // create the new node
489  pNew = (Rwt_Node_t *)Mem_FixedEntryFetch( p->pMmNode );
490  pNew->Id = p->vForest->nSize;
491  pNew->TravId = 0;
492  pNew->uTruth = uTruth;
493  pNew->Level = Level;
494  pNew->Volume = Volume;
495  pNew->fUsed = 0;
496  pNew->fExor = fExor;
497  pNew->p0 = p0;
498  pNew->p1 = p1;
499  pNew->pNext = NULL;
500  Vec_PtrPush( p->vForest, pNew );
501  // do not add if the node is not essential
502  if ( uTruth != p->puCanons[uTruth] )
503  return pNew;
504 
505  // add to the list
506  p->nAdded++;
507  if ( p->pTable[uTruth] == NULL )
508  p->nClasses++;
509  Rwt_ListAddToTail( p->pTable + uTruth, pNew );
510  return pNew;
511 }
int Id
Definition: rwt.h:109
int nAdded
Definition: rwt.h:77
Rwt_Node_t * p1
Definition: rwt.h:117
Rwt_Node_t * pNext
Definition: rwt.h:118
int nConsidered
Definition: rwt.h:76
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
unsigned uTruth
Definition: rwt.h:111
Rwt_Node_t ** pTable
Definition: rwt.h:71
Mem_Fixed_t * pMmNode
Definition: rwt.h:73
unsigned Level
Definition: rwt.h:113
static int Rwt_IsComplement(Rwt_Node_t *p)
Definition: rwt.h:122
unsigned Volume
Definition: rwt.h:112
void Rwt_ListAddToTail(Rwt_Node_t **ppList, Rwt_Node_t *pNode)
FUNCTION DEFINITIONS ///.
Definition: rwtUtil.c:425
Rwt_Node_t * p0
Definition: rwt.h:116
unsigned fExor
Definition: rwt.h:115
unsigned fUsed
Definition: rwt.h:114
int nClasses
Definition: rwt.h:78
int TravId
Definition: rwt.h:110
static Rwt_Node_t * Rwt_Regular(Rwt_Node_t *p)
Definition: rwt.h:123
char * Mem_FixedEntryFetch(Mem_Fixed_t *p)
Definition: mem.c:168
Vec_Ptr_t * vForest
Definition: rwt.h:70
unsigned short * puCanons
Definition: rwt.h:62
Rwt_Node_t* Rwt_ManAddVar ( Rwt_Man_t p,
unsigned  uTruth,
int  fPrecompute 
)

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

Synopsis [Adds one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 446 of file rwtUtil.c.

447 {
448  Rwt_Node_t * pNew;
449  pNew = (Rwt_Node_t *)Mem_FixedEntryFetch( p->pMmNode );
450  pNew->Id = p->vForest->nSize;
451  pNew->TravId = 0;
452  pNew->uTruth = uTruth;
453  pNew->Level = 0;
454  pNew->Volume = 0;
455  pNew->fUsed = 1;
456  pNew->fExor = 0;
457  pNew->p0 = NULL;
458  pNew->p1 = NULL;
459  pNew->pNext = NULL;
460  Vec_PtrPush( p->vForest, pNew );
461  if ( fPrecompute )
462  Rwt_ListAddToTail( p->pTable + uTruth, pNew );
463  return pNew;
464 }
int Id
Definition: rwt.h:109
Rwt_Node_t * p1
Definition: rwt.h:117
Rwt_Node_t * pNext
Definition: rwt.h:118
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
unsigned uTruth
Definition: rwt.h:111
Rwt_Node_t ** pTable
Definition: rwt.h:71
Mem_Fixed_t * pMmNode
Definition: rwt.h:73
unsigned Level
Definition: rwt.h:113
unsigned Volume
Definition: rwt.h:112
void Rwt_ListAddToTail(Rwt_Node_t **ppList, Rwt_Node_t *pNode)
FUNCTION DEFINITIONS ///.
Definition: rwtUtil.c:425
Rwt_Node_t * p0
Definition: rwt.h:116
unsigned fExor
Definition: rwt.h:115
unsigned fUsed
Definition: rwt.h:114
int TravId
Definition: rwt.h:110
char * Mem_FixedEntryFetch(Mem_Fixed_t *p)
Definition: mem.c:168
Vec_Ptr_t * vForest
Definition: rwt.h:70
char* Rwt_ManGetPractical ( Rwt_Man_t p)

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

Synopsis [Create practical classes.]

Description []

SideEffects []

SeeAlso []

Definition at line 640 of file rwtUtil.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_RwtPracticalClasses[i] == 0 )
650  break;
651  pPractical[ s_RwtPracticalClasses[i] ] = 1;
652  }
653  return pPractical;
654 }
char * memset()
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int nFuncs
Definition: rwt.h:61
static unsigned short s_RwtPracticalClasses[]
Definition: rwtUtil.c:393
void Rwt_ManIncTravId ( Rwt_Man_t p)

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

Synopsis [Adds one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 547 of file rwtUtil.c.

548 {
549  Rwt_Node_t * pNode;
550  int i;
551  if ( p->nTravIds++ < 0x8FFFFFFF )
552  return;
553  Vec_PtrForEachEntry( Rwt_Node_t *, p->vForest, pNode, i )
554  pNode->TravId = 0;
555  p->nTravIds = 1;
556 }
int nTravIds
Definition: rwt.h:75
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
Vec_Ptr_t * vForest
Definition: rwt.h:70
void Rwt_ManLoadFromArray ( Rwt_Man_t p,
int  fVerbose 
)

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

Synopsis [Loads data.]

Description []

SideEffects []

SeeAlso []

Definition at line 589 of file rwtUtil.c.

590 {
591  unsigned short * pArray = s_RwtAigSubgraphs;
592  Rwt_Node_t * p0, * p1;
593  unsigned Entry0, Entry1;
594  int Level, Volume, nEntries, fExor;
595  int i;
596  abctime clk = Abc_Clock();
597 
598  // reconstruct the forest
599  for ( i = 0; ; i++ )
600  {
601  Entry0 = pArray[2*i + 0];
602  Entry1 = pArray[2*i + 1];
603  if ( Entry0 == 0 && Entry1 == 0 )
604  break;
605  // get EXOR flag
606  fExor = (Entry0 & 1);
607  Entry0 >>= 1;
608  // get the nodes
609  p0 = (Rwt_Node_t *)p->vForest->pArray[Entry0 >> 1];
610  p1 = (Rwt_Node_t *)p->vForest->pArray[Entry1 >> 1];
611  // compute the level and volume of the new nodes
612  Level = 1 + RWT_MAX( p0->Level, p1->Level );
613  Volume = 1 + Rwt_ManNodeVolume( p, p0, p1 );
614  // set the complemented attributes
615  p0 = Rwt_NotCond( p0, (Entry0 & 1) );
616  p1 = Rwt_NotCond( p1, (Entry1 & 1) );
617  // add the node
618 // Rwt_ManTryNode( p, p0, p1, Level, Volume );
619  Rwt_ManAddNode( p, p0, p1, fExor, Level, Volume + fExor );
620  }
621  nEntries = i - 1;
622  if ( fVerbose )
623  {
624  printf( "The number of classes = %d. Canonical nodes = %d.\n", p->nClasses, p->nAdded );
625  printf( "The number of nodes loaded = %d. ", nEntries ); ABC_PRT( "Loading", Abc_Clock() - clk );
626  }
627 }
int nAdded
Definition: rwt.h:77
#define RWT_MAX(a, b)
Definition: rwt.h:53
static ABC_NAMESPACE_IMPL_START unsigned short s_RwtAigSubgraphs[]
DECLARATIONS ///.
Definition: rwtUtil.c:31
static abctime Abc_Clock()
Definition: abc_global.h:279
unsigned Level
Definition: rwt.h:113
Rwt_Node_t * Rwt_ManAddNode(Rwt_Man_t *p, Rwt_Node_t *p0, Rwt_Node_t *p1, int fExor, int Level, int Volume)
Definition: rwtUtil.c:477
static Rwt_Node_t * Rwt_NotCond(Rwt_Node_t *p, int c)
Definition: rwt.h:125
#define ABC_PRT(a, t)
Definition: abc_global.h:220
int nClasses
Definition: rwt.h:78
int Rwt_ManNodeVolume(Rwt_Man_t *p, Rwt_Node_t *p0, Rwt_Node_t *p1)
Definition: rwtUtil.c:569
ABC_INT64_T abctime
Definition: abc_global.h:278
Vec_Ptr_t * vForest
Definition: rwt.h:70
int Rwt_ManNodeVolume ( Rwt_Man_t p,
Rwt_Node_t p0,
Rwt_Node_t p1 
)

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

Synopsis [Adds one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 569 of file rwtUtil.c.

570 {
571  int Volume = 0;
572  Rwt_ManIncTravId( p );
573  Rwt_Trav_rec( p, p0, &Volume );
574  Rwt_Trav_rec( p, p1, &Volume );
575  return Volume;
576 }
void Rwt_Trav_rec(Rwt_Man_t *p, Rwt_Node_t *pNode, int *pVolume)
Definition: rwtUtil.c:524
void Rwt_ManIncTravId(Rwt_Man_t *p)
Definition: rwtUtil.c:547
void Rwt_Trav_rec ( Rwt_Man_t p,
Rwt_Node_t pNode,
int *  pVolume 
)

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

Synopsis [Adds one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 524 of file rwtUtil.c.

525 {
526  if ( pNode->fUsed || pNode->TravId == p->nTravIds )
527  return;
528  pNode->TravId = p->nTravIds;
529  (*pVolume)++;
530  if ( pNode->fExor )
531  (*pVolume)++;
532  Rwt_Trav_rec( p, Rwt_Regular(pNode->p0), pVolume );
533  Rwt_Trav_rec( p, Rwt_Regular(pNode->p1), pVolume );
534 }
Rwt_Node_t * p1
Definition: rwt.h:117
void Rwt_Trav_rec(Rwt_Man_t *p, Rwt_Node_t *pNode, int *pVolume)
Definition: rwtUtil.c:524
int nTravIds
Definition: rwt.h:75
Rwt_Node_t * p0
Definition: rwt.h:116
unsigned fExor
Definition: rwt.h:115
unsigned fUsed
Definition: rwt.h:114
int TravId
Definition: rwt.h:110
static Rwt_Node_t * Rwt_Regular(Rwt_Node_t *p)
Definition: rwt.h:123

Variable Documentation

ABC_NAMESPACE_IMPL_START unsigned short s_RwtAigSubgraphs[]
static

DECLARATIONS ///.

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

FileName [rwtUtil.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [DAG-aware AIG rewriting package.]

Synopsis [Various utilities.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

]

Definition at line 31 of file rwtUtil.c.

unsigned short s_RwtPracticalClasses[]
static
Initial value:
=
{
0x0000, 0x0001, 0x0003, 0x0006, 0x0007, 0x000f, 0x0016, 0x0017, 0x0018, 0x0019, 0x001b,
0x001e, 0x001f, 0x003c, 0x003d, 0x003f, 0x0069, 0x006b, 0x006f, 0x007e, 0x007f, 0x00ff,
0x0116, 0x0118, 0x0119, 0x011a, 0x011b, 0x011e, 0x011f, 0x012c, 0x012d, 0x012f, 0x013c,
0x013d, 0x013e, 0x013f, 0x0168, 0x0169, 0x016f, 0x017f, 0x0180, 0x0181, 0x0182, 0x0183,
0x0186, 0x0189, 0x018b, 0x018f, 0x0198, 0x0199, 0x019b, 0x01a8, 0x01a9, 0x01aa, 0x01ab,
0x01ac, 0x01ad, 0x01ae, 0x01af, 0x01bf, 0x01e9, 0x01ea, 0x01eb, 0x01ee, 0x01ef, 0x01fe,
0x033c, 0x033d, 0x033f, 0x0356, 0x0357, 0x0358, 0x0359, 0x035a, 0x035b, 0x035f, 0x0368,
0x0369, 0x036c, 0x036e, 0x037d, 0x03c0, 0x03c1, 0x03c3, 0x03c7, 0x03cf, 0x03d4, 0x03d5,
0x03d7, 0x03d8, 0x03d9, 0x03dc, 0x03dd, 0x03de, 0x03fc, 0x0660, 0x0661, 0x0666, 0x0669,
0x066f, 0x0676, 0x067e, 0x0690, 0x0696, 0x0697, 0x069f, 0x06b1, 0x06b6, 0x06f0, 0x06f2,
0x06f6, 0x06f9, 0x0776, 0x0778, 0x07b0, 0x07b1, 0x07b4, 0x07bc, 0x07f0, 0x07f2, 0x07f8,
0x0ff0, 0x1683, 0x1696, 0x1698, 0x169e, 0x16e9, 0x178e, 0x17e8, 0x18e7, 0x19e6, 0x1be4,
0x1ee1, 0x3cc3, 0x6996, 0x0000
}

Definition at line 393 of file rwtUtil.c.