src/opt/rwr/rwrUtil.c File Reference

#include "rwr.h"
Include dependency graph for rwrUtil.c:

Go to the source code of this file.

Functions

void Rwr_ManWriteToArray (Rwr_Man_t *p)
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 unsigned short s_RwrPracticalClasses []
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 238 of file rwrUtil.c.

00239 {
00240     Rwr_Node_t * pTemp;
00241     // find the last one
00242     for ( pTemp = *ppList; pTemp; pTemp = pTemp->pNext )
00243         ppList = &pTemp->pNext;
00244     // attach at the end
00245     *ppList = pNode;
00246 }

char* Rwr_ManGetPractical ( Rwr_Man_t p  ) 

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

Synopsis [Create practical classes.]

Description []

SideEffects []

SeeAlso []

Definition at line 259 of file rwrUtil.c.

00260 {
00261     char * pPractical;
00262     int i;
00263     pPractical = ALLOC( char, p->nFuncs );
00264     memset( pPractical, 0, sizeof(char) * p->nFuncs );
00265     pPractical[0] = 1;
00266     for ( i = 1; ; i++ )
00267     {
00268         if ( s_RwrPracticalClasses[i] == 0 )
00269             break;
00270         pPractical[ s_RwrPracticalClasses[i] ] = 1;
00271     }
00272     return pPractical;
00273 }

void Rwr_ManLoadFromArray ( Rwr_Man_t p,
int  fVerbose 
)

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

Synopsis [Loads data.]

Description []

SideEffects []

SeeAlso []

Definition at line 95 of file rwrUtil.c.

00096 {
00097     unsigned short * pArray = s_RwtAigSubgraphs;
00098     Rwr_Node_t * p0, * p1;
00099     unsigned Entry0, Entry1;
00100     int Level, Volume, nEntries, fExor;
00101     int i, clk = clock();
00102 
00103     // reconstruct the forest
00104     for ( i = 0; ; i++ )
00105     {
00106         Entry0 = pArray[2*i + 0];
00107         Entry1 = pArray[2*i + 1];
00108         if ( Entry0 == 0 && Entry1 == 0 )
00109             break;
00110         // get EXOR flag
00111         fExor = (Entry0 & 1);
00112         Entry0 >>= 1;
00113         // get the nodes
00114         p0 = p->vForest->pArray[Entry0 >> 1];
00115         p1 = p->vForest->pArray[Entry1 >> 1];
00116         // compute the level and volume of the new nodes
00117         Level  = 1 + ABC_MAX( p0->Level, p1->Level );
00118         Volume = 1 + Rwr_ManNodeVolume( p, p0, p1 );
00119         // set the complemented attributes
00120         p0 = Rwr_NotCond( p0, (Entry0 & 1) );
00121         p1 = Rwr_NotCond( p1, (Entry1 & 1) );
00122         // add the node
00123 //        Rwr_ManTryNode( p, p0, p1, Level, Volume );
00124         Rwr_ManAddNode( p, p0, p1, fExor, Level, Volume + fExor );
00125     }
00126     nEntries = i - 1;
00127     if ( fVerbose )
00128     {
00129         printf( "The number of classes = %d. Canonical nodes = %d.\n", p->nClasses, p->nAdded );
00130         printf( "The number of nodes loaded = %d.  ", nEntries );  PRT( "Loading", clock() - clk );
00131     }
00132 }

void Rwr_ManLoadFromFile ( Rwr_Man_t p,
char *  pFileName 
)

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

Synopsis [Loads data.]

Description []

SideEffects []

SeeAlso []

Definition at line 183 of file rwrUtil.c.

00184 {
00185     FILE * pFile;
00186     Rwr_Node_t * p0, * p1;
00187     unsigned * pBuffer;
00188     int Level, Volume, nEntries, fExor;
00189     int i, clk = clock();
00190 
00191     // load the data
00192     pFile = fopen( pFileName, "rb" );
00193     if ( pFile == NULL )
00194     {
00195         printf( "Rwr_ManLoadFromFile: Cannot open file \"%s\".\n", pFileName );
00196         return;
00197     }
00198     fread( &nEntries, sizeof(int), 1, pFile );
00199     pBuffer = ALLOC( unsigned, nEntries * 2 );
00200     fread( pBuffer, sizeof(unsigned), nEntries * 2, pFile );
00201     fclose( pFile );
00202     // reconstruct the forest
00203     for ( i = 0; i < nEntries; i++ )
00204     {
00205         // get EXOR flag
00206         fExor = (pBuffer[2*i + 0] & 1);
00207         pBuffer[2*i + 0] = (pBuffer[2*i + 0] >> 1);
00208         // get the nodes
00209         p0 = p->vForest->pArray[pBuffer[2*i + 0] >> 1];
00210         p1 = p->vForest->pArray[pBuffer[2*i + 1] >> 1];
00211         // compute the level and volume of the new nodes
00212         Level  = 1 + ABC_MAX( p0->Level, p1->Level );
00213         Volume = 1 + Rwr_ManNodeVolume( p, p0, p1 );
00214         // set the complemented attributes
00215         p0 = Rwr_NotCond( p0, (pBuffer[2*i + 0] & 1) );
00216         p1 = Rwr_NotCond( p1, (pBuffer[2*i + 1] & 1) );
00217         // add the node
00218 //        Rwr_ManTryNode( p, p0, p1, Level, Volume );
00219         Rwr_ManAddNode( p, p0, p1, fExor, Level, Volume + fExor );
00220     }
00221     free( pBuffer );
00222     printf( "The number of classes = %d. Canonical nodes = %d.\n", p->nClasses, p->nAdded );
00223     printf( "The number of nodes loaded = %d.   ", nEntries );  PRT( "Loading", clock() - clk );
00224 }

void Rwr_ManWriteToArray ( Rwr_Man_t p  ) 

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

Synopsis [Writes data.]

Description []

SideEffects []

SeeAlso []

Definition at line 51 of file rwrUtil.c.

00052 {
00053     FILE * pFile;
00054     Rwr_Node_t * pNode;
00055     unsigned Entry0, Entry1;
00056     int i, nEntries, clk = clock();
00057     // prepare the buffer
00058     nEntries = p->vForest->nSize - 5;
00059     pFile = fopen( "npn4_aig_array.txt", "w" );
00060     fprintf( pFile, "static unsigned short s_RwtAigSubgraphs[] = \n{" );
00061     for ( i = 0; i < nEntries; i++ )
00062     {
00063         if ( i % 5 == 0 )
00064             fprintf( pFile, "\n    " );
00065         pNode = p->vForest->pArray[i+5];
00066         Entry0 = (Rwr_Regular(pNode->p0)->Id << 1) | Rwr_IsComplement(pNode->p0);
00067         Entry1 = (Rwr_Regular(pNode->p1)->Id << 1) | Rwr_IsComplement(pNode->p1);
00068         Entry0 = (Entry0 << 1) | pNode->fExor;
00069         Extra_PrintHex( pFile, Entry0, 4 );
00070         fprintf( pFile, "," );
00071         Extra_PrintHex( pFile, Entry1, 4 );
00072         fprintf( pFile, ", " );
00073     }
00074     if ( i % 5 == 0 )
00075         fprintf( pFile, "\n    " );
00076     Extra_PrintHex( pFile, 0, 4 );
00077     fprintf( pFile, "," );
00078     Extra_PrintHex( pFile, 0, 4 );
00079     fprintf( pFile, " \n};\n" );
00080     fclose( pFile );
00081     printf( "The number of nodes saved = %d.   ", nEntries );  PRT( "Saving", clock() - clk );
00082 }

void Rwr_ManWriteToFile ( Rwr_Man_t p,
char *  pFileName 
)

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

Synopsis [Writes.]

Description []

SideEffects []

SeeAlso []

Definition at line 146 of file rwrUtil.c.

00147 {
00148     FILE * pFile;
00149     Rwr_Node_t * pNode;
00150     unsigned * pBuffer;
00151     int i, nEntries, clk = clock();
00152     // prepare the buffer
00153     nEntries = p->vForest->nSize - 5;
00154     pBuffer = ALLOC( unsigned, nEntries * 2 );
00155     for ( i = 0; i < nEntries; i++ )
00156     {
00157         pNode = p->vForest->pArray[i+5];
00158         pBuffer[2*i + 0] = (Rwr_Regular(pNode->p0)->Id << 1) | Rwr_IsComplement(pNode->p0);
00159         pBuffer[2*i + 1] = (Rwr_Regular(pNode->p1)->Id << 1) | Rwr_IsComplement(pNode->p1);
00160         // save EXOR flag
00161         pBuffer[2*i + 0] = (pBuffer[2*i + 0] << 1) | pNode->fExor;
00162 
00163     }
00164     pFile = fopen( pFileName, "wb" );
00165     fwrite( &nEntries, sizeof(int), 1, pFile );
00166     fwrite( pBuffer, sizeof(unsigned), nEntries * 2, pFile );
00167     free( pBuffer );
00168     fclose( pFile );
00169     printf( "The number of nodes saved = %d.   ", nEntries );  PRT( "Saving", clock() - clk );
00170 }


Variable Documentation

static 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
}

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

] DECLARATIONS ///

END OF FILE ///

Definition at line 32 of file rwrUtil.c.

static unsigned short s_RwtAigSubgraphs [static]

Definition at line 33 of file rwrUtil.c.


Generated on Tue Jan 5 12:19:34 2010 for abc70930 by  doxygen 1.6.1