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

Go to the source code of this file.

Functions

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)
 

Variables

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

Function Documentation

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
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_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
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

Variable Documentation

ABC_NAMESPACE_IMPL_START unsigned short s_RwrPracticalClasses[]
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
}

DECLARATIONS ///.

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

FileName [rwrUtil.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:
rwrUtil.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 33 of file rwrUtil.c.

unsigned short s_RwtAigSubgraphs[]
static

Definition at line 50 of file rwrUtil.c.