src/aig/rwt/rwt.h File Reference

#include "mem.h"
#include "extra.h"
#include "vec.h"
Include dependency graph for rwt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Rwt_Man_t_
struct  Rwt_Node_t_

Defines

#define RWT_LIMIT   1048576/4
#define RWT_MIN(a, b)   (((a) < (b))? (a) : (b))
#define RWT_MAX(a, b)   (((a) > (b))? (a) : (b))

Typedefs

typedef struct Rwt_Man_t_ Rwt_Man_t
typedef struct Rwt_Node_t_ Rwt_Node_t

Functions

static int Rwt_IsComplement (Rwt_Node_t *p)
static Rwt_Node_tRwt_Regular (Rwt_Node_t *p)
static Rwt_Node_tRwt_Not (Rwt_Node_t *p)
static Rwt_Node_tRwt_NotCond (Rwt_Node_t *p, int c)
void Rwt_ManPreprocess (Rwt_Man_t *p)
Rwt_Man_tRwt_ManStart (int fPrecompute)
void Rwt_ManStop (Rwt_Man_t *p)
void Rwt_ManPrintStats (Rwt_Man_t *p)
void Rwt_ManPrintStatsFile (Rwt_Man_t *p)
void * Rwt_ManReadDecs (Rwt_Man_t *p)
Vec_Ptr_tRwt_ManReadLeaves (Rwt_Man_t *p)
int Rwt_ManReadCompl (Rwt_Man_t *p)
void Rwt_ManAddTimeCuts (Rwt_Man_t *p, int Time)
void Rwt_ManAddTimeUpdate (Rwt_Man_t *p, int Time)
void Rwt_ManAddTimeTotal (Rwt_Man_t *p, int Time)
void Rwt_ManLoadFromArray (Rwt_Man_t *p, int fVerbose)
char * Rwt_ManGetPractical (Rwt_Man_t *p)
Rwt_Node_tRwt_ManAddVar (Rwt_Man_t *p, unsigned uTruth, int fPrecompute)
void Rwt_ManIncTravId (Rwt_Man_t *p)

Define Documentation

#define RWT_LIMIT   1048576/4

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

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

] INCLUDES /// PARAMETERS /// BASIC TYPES ///

Definition at line 44 of file rwt.h.

#define RWT_MAX ( a,
 )     (((a) > (b))? (a) : (b))

Definition at line 46 of file rwt.h.

#define RWT_MIN ( a,
 )     (((a) < (b))? (a) : (b))

Definition at line 45 of file rwt.h.


Typedef Documentation

typedef struct Rwt_Man_t_ Rwt_Man_t

Definition at line 48 of file rwt.h.

typedef struct Rwt_Node_t_ Rwt_Node_t

Definition at line 49 of file rwt.h.


Function Documentation

static int Rwt_IsComplement ( Rwt_Node_t p  )  [inline, static]

Definition at line 115 of file rwt.h.

00115 { return (int)(((unsigned long)p) & 01);            }

void Rwt_ManAddTimeCuts ( Rwt_Man_t p,
int  Time 
)

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 298 of file rwtMan.c.

00299 {
00300     p->timeCut += Time;
00301 }

void Rwt_ManAddTimeTotal ( Rwt_Man_t p,
int  Time 
)

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 330 of file rwtMan.c.

00331 {
00332     p->timeTotal += Time;
00333 }

void Rwt_ManAddTimeUpdate ( Rwt_Man_t p,
int  Time 
)

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 314 of file rwtMan.c.

00315 {
00316     p->timeUpdate += Time;
00317 }

Rwt_Node_t* Rwt_ManAddVar ( Rwt_Man_t p,
unsigned  uTruth,
int  fPrecompute 
)

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

Synopsis [Adds one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 72 of file rwtUtil.c.

00073 {
00074     Rwt_Node_t * pNew;
00075     pNew = (Rwt_Node_t *)Mem_FixedEntryFetch( p->pMmNode );
00076     pNew->Id     = p->vForest->nSize;
00077     pNew->TravId = 0;
00078     pNew->uTruth = uTruth;
00079     pNew->Level  = 0;
00080     pNew->Volume = 0;
00081     pNew->fUsed  = 1;
00082     pNew->fExor  = 0;
00083     pNew->p0     = NULL;
00084     pNew->p1     = NULL;    
00085     pNew->pNext  = NULL;
00086     Vec_PtrPush( p->vForest, pNew );
00087     if ( fPrecompute )
00088         Rwt_ListAddToTail( p->pTable + uTruth, pNew );
00089     return pNew;
00090 }

char* Rwt_ManGetPractical ( Rwt_Man_t p  ) 

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

Synopsis [Create practical classes.]

Description []

SideEffects []

SeeAlso []

Definition at line 265 of file rwtUtil.c.

00266 {
00267     char * pPractical;
00268     int i;
00269     pPractical = ALLOC( char, p->nFuncs );
00270     memset( pPractical, 0, sizeof(char) * p->nFuncs );
00271     pPractical[0] = 1;
00272     for ( i = 1; ; i++ )
00273     {
00274         if ( s_RwtPracticalClasses[i] == 0 )
00275             break;
00276         pPractical[ s_RwtPracticalClasses[i] ] = 1;
00277     }
00278     return pPractical;
00279 }

void Rwt_ManIncTravId ( Rwt_Man_t p  ) 

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

Synopsis [Adds one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 173 of file rwtUtil.c.

00174 {
00175     Rwt_Node_t * pNode;
00176     int i;
00177     if ( p->nTravIds++ < 0x8FFFFFFF )
00178         return;
00179     Vec_PtrForEachEntry( p->vForest, pNode, i )
00180         pNode->TravId = 0;
00181     p->nTravIds = 1;
00182 }

void Rwt_ManLoadFromArray ( Rwt_Man_t p,
int  fVerbose 
)

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

Synopsis [Loads data.]

Description []

SideEffects []

SeeAlso []

Definition at line 215 of file rwtUtil.c.

00216 {
00217     unsigned short * pArray = s_RwtAigSubgraphs;
00218     Rwt_Node_t * p0, * p1;
00219     unsigned Entry0, Entry1;
00220     int Level, Volume, nEntries, fExor;
00221     int i, clk = clock();
00222 
00223     // reconstruct the forest
00224     for ( i = 0; ; i++ )
00225     {
00226         Entry0 = pArray[2*i + 0];
00227         Entry1 = pArray[2*i + 1];
00228         if ( Entry0 == 0 && Entry1 == 0 )
00229             break;
00230         // get EXOR flag
00231         fExor = (Entry0 & 1);
00232         Entry0 >>= 1;
00233         // get the nodes
00234         p0 = p->vForest->pArray[Entry0 >> 1];
00235         p1 = p->vForest->pArray[Entry1 >> 1];
00236         // compute the level and volume of the new nodes
00237         Level  = 1 + RWT_MAX( p0->Level, p1->Level );
00238         Volume = 1 + Rwt_ManNodeVolume( p, p0, p1 );
00239         // set the complemented attributes
00240         p0 = Rwt_NotCond( p0, (Entry0 & 1) );
00241         p1 = Rwt_NotCond( p1, (Entry1 & 1) );
00242         // add the node
00243 //        Rwt_ManTryNode( p, p0, p1, Level, Volume );
00244         Rwt_ManAddNode( p, p0, p1, fExor, Level, Volume + fExor );
00245     }
00246     nEntries = i - 1;
00247     if ( fVerbose )
00248     {
00249         printf( "The number of classes = %d. Canonical nodes = %d.\n", p->nClasses, p->nAdded );
00250         printf( "The number of nodes loaded = %d.  ", nEntries );  PRT( "Loading", clock() - clk );
00251     }
00252 }

void Rwt_ManPreprocess ( Rwt_Man_t p  ) 

MACRO DEFINITIONS /// FUNCTION DECLARATIONS ///

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

Synopsis [Preprocesses computed library of subgraphs.]

Description []

SideEffects []

SeeAlso []

Definition at line 46 of file rwtDec.c.

00047 {
00048     Dec_Graph_t * pGraph;
00049     Rwt_Node_t * pNode;
00050     int i, k;
00051     // put the nodes into the structure
00052     p->pMapInv  = ALLOC( unsigned short, 222 );
00053     memset( p->pMapInv, 0, sizeof(unsigned short) * 222 );
00054     p->vClasses = Vec_VecStart( 222 );
00055     for ( i = 0; i < p->nFuncs; i++ )
00056     {
00057         if ( p->pTable[i] == NULL )
00058             continue;
00059         // consider all implementations of this function
00060         for ( pNode = p->pTable[i]; pNode; pNode = pNode->pNext )
00061         {
00062             assert( pNode->uTruth == p->pTable[i]->uTruth );
00063             assert( p->pMap[pNode->uTruth] >= 0 && p->pMap[pNode->uTruth] < 222 );
00064             Vec_VecPush( p->vClasses, p->pMap[pNode->uTruth], pNode );
00065             p->pMapInv[ p->pMap[pNode->uTruth] ] = p->puCanons[pNode->uTruth];
00066         }
00067     }
00068     // compute decomposition forms for each node and verify them
00069     Vec_VecForEachEntry( p->vClasses, pNode, i, k )
00070     {
00071         pGraph = Rwt_NodePreprocess( p, pNode );
00072         pNode->pNext = (Rwt_Node_t *)pGraph;
00073 //        assert( pNode->uTruth == (Dec_GraphDeriveTruth(pGraph) & 0xFFFF) );
00074     }
00075 }

void Rwt_ManPrintStats ( Rwt_Man_t p  ) 

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 180 of file rwtMan.c.

00181 {
00182     int i, Counter = 0;
00183     for ( i = 0; i < 222; i++ )
00184         Counter += (p->nScores[i] > 0);
00185 
00186     printf( "Rewriting statistics:\n" );
00187     printf( "Total cuts tries  = %8d.\n", p->nCutsGood );
00188     printf( "Bad cuts found    = %8d.\n", p->nCutsBad );
00189     printf( "Total subgraphs   = %8d.\n", p->nSubgraphs );
00190     printf( "Used NPN classes  = %8d.\n", Counter );
00191     printf( "Nodes considered  = %8d.\n", p->nNodesConsidered );
00192     printf( "Nodes rewritten   = %8d.\n", p->nNodesRewritten );
00193     printf( "Calculated gain   = %8d.\n", p->nNodesGained     );
00194     PRT( "Start       ", p->timeStart );
00195     PRT( "Cuts        ", p->timeCut );
00196     PRT( "Truth       ", p->timeTruth );
00197     PRT( "Resynthesis ", p->timeRes );
00198     PRT( "    Mffc    ", p->timeMffc );
00199     PRT( "    Eval    ", p->timeEval );
00200     PRT( "Update      ", p->timeUpdate );
00201     PRT( "TOTAL       ", p->timeTotal );
00202 
00203 /*
00204     printf( "The scores are:\n" );
00205     for ( i = 0; i < 222; i++ )
00206         if ( p->nScores[i] > 0 )
00207         {
00208             extern void Ivy_TruthDsdComputePrint( unsigned uTruth );
00209             printf( "%3d = %8d  canon = %5d  ", i, p->nScores[i], p->pMapInv[i] );
00210             Ivy_TruthDsdComputePrint( (unsigned)p->pMapInv[i] | ((unsigned)p->pMapInv[i] << 16) );
00211         }
00212     printf( "\n" );
00213 */
00214 }

void Rwt_ManPrintStatsFile ( Rwt_Man_t p  ) 

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 227 of file rwtMan.c.

00228 {
00229     FILE * pTable;
00230     pTable = fopen( "stats.txt", "a+" );
00231     fprintf( pTable, "%d ", p->nCutsGood );
00232     fprintf( pTable, "%d ", p->nSubgraphs );
00233     fprintf( pTable, "%d ", p->nNodesRewritten );
00234     fprintf( pTable, "%d", p->nNodesGained );
00235     fprintf( pTable, "\n" );
00236     fclose( pTable );
00237 }

int Rwt_ManReadCompl ( Rwt_Man_t p  ) 

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 282 of file rwtMan.c.

00283 {
00284     return p->fCompl;
00285 }

void* Rwt_ManReadDecs ( Rwt_Man_t p  ) 

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 250 of file rwtMan.c.

00251 {
00252     return p->pGraph;
00253 }

Vec_Ptr_t* Rwt_ManReadLeaves ( Rwt_Man_t p  ) 

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

Synopsis [Stops the resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 266 of file rwtMan.c.

00267 {
00268     return p->vFanins;
00269 }

Rwt_Man_t* Rwt_ManStart ( int  fPrecompute  ) 

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

Synopsis [Starts rewriting manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 84 of file rwtMan.c.

00085 {
00086     Rwt_Man_t * p;
00087     int clk = clock();
00088 clk = clock();
00089     p = ALLOC( Rwt_Man_t, 1 );
00090     memset( p, 0, sizeof(Rwt_Man_t) );
00091     p->nFuncs = (1<<16);
00092     // copy the global tables
00093     Rwt_ManGlobalStart();
00094     p->puCanons = s_puCanons; 
00095     p->pPhases  = s_pPhases; 
00096     p->pPerms   = s_pPerms; 
00097     p->pMap     = s_pMap; 
00098     // initialize practical NPN classes
00099     p->pPractical  = Rwt_ManGetPractical( p );
00100     // create the table
00101     p->pTable = ALLOC( Rwt_Node_t *, p->nFuncs );
00102     memset( p->pTable, 0, sizeof(Rwt_Node_t *) * p->nFuncs );
00103     // create the elementary nodes
00104     p->pMmNode  = Mem_FixedStart( sizeof(Rwt_Node_t) );
00105     p->vForest  = Vec_PtrAlloc( 100 );
00106     Rwt_ManAddVar( p, 0x0000, fPrecompute ); // constant 0
00107     Rwt_ManAddVar( p, 0xAAAA, fPrecompute ); // var A
00108     Rwt_ManAddVar( p, 0xCCCC, fPrecompute ); // var B
00109     Rwt_ManAddVar( p, 0xF0F0, fPrecompute ); // var C
00110     Rwt_ManAddVar( p, 0xFF00, fPrecompute ); // var D
00111     p->nClasses = 5;
00112     // other stuff
00113     p->nTravIds   = 1;
00114     p->pPerms4    = Extra_Permutations( 4 );
00115     p->vLevNums   = Vec_IntAlloc( 50 );
00116     p->vFanins    = Vec_PtrAlloc( 50 );
00117     p->vFaninsCur = Vec_PtrAlloc( 50 );
00118     p->vNodesTemp = Vec_PtrAlloc( 50 );
00119     if ( fPrecompute )
00120     {   // precompute subgraphs
00121 //        Rwt_ManPrecompute( p );
00122 //        Rwt_ManPrint( p );
00123 //        Rwt_ManWriteToArray( p );
00124     }
00125     else
00126     {   // load saved subgraphs
00127         Rwt_ManLoadFromArray( p, 0 );
00128 //        Rwt_ManPrint( p );
00129         Rwt_ManPreprocess( p );
00130     }
00131 p->timeStart = clock() - clk;
00132     return p;
00133 }

void Rwt_ManStop ( Rwt_Man_t p  ) 

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

Synopsis [Stops rewriting manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 146 of file rwtMan.c.

00147 {
00148     if ( p->vClasses )
00149     {
00150         Rwt_Node_t * pNode;
00151         int i, k;
00152         Vec_VecForEachEntry( p->vClasses, pNode, i, k )
00153             Dec_GraphFree( (Dec_Graph_t *)pNode->pNext );
00154     }
00155     if ( p->vClasses )  Vec_VecFree( p->vClasses );
00156     Vec_PtrFree( p->vNodesTemp );
00157     Vec_PtrFree( p->vForest );
00158     Vec_IntFree( p->vLevNums );
00159     Vec_PtrFree( p->vFanins );
00160     Vec_PtrFree( p->vFaninsCur );
00161     Mem_FixedStop( p->pMmNode, 0 );
00162     FREE( p->pMapInv );
00163     free( p->pTable );
00164     free( p->pPractical );
00165     free( p->pPerms4 );
00166     free( p );
00167 }

static Rwt_Node_t* Rwt_Not ( Rwt_Node_t p  )  [inline, static]

Definition at line 117 of file rwt.h.

00117 { return (Rwt_Node_t *)((unsigned long)(p) ^  01);  }

static Rwt_Node_t* Rwt_NotCond ( Rwt_Node_t p,
int  c 
) [inline, static]

Definition at line 118 of file rwt.h.

00118 { return (Rwt_Node_t *)((unsigned long)(p) ^ (c));  }

static Rwt_Node_t* Rwt_Regular ( Rwt_Node_t p  )  [inline, static]

Definition at line 116 of file rwt.h.

00116 { return (Rwt_Node_t *)((unsigned long)(p) & ~01);  }


Generated on Tue Jan 5 12:18:29 2010 for abc70930 by  doxygen 1.6.1