rwr.h 7.86 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**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 $]

***********************************************************************/
 
21 22
#ifndef ABC__opt__rwr__rwr_h
#define ABC__opt__rwr__rwr_h
Alan Mishchenko committed
23

24

Alan Mishchenko committed
25 26 27 28
////////////////////////////////////////////////////////////////////////
///                          INCLUDES                                ///
////////////////////////////////////////////////////////////////////////

29 30
#include "base/abc/abc.h"
#include "opt/cut/cut.h"
Alan Mishchenko committed
31 32 33 34 35

////////////////////////////////////////////////////////////////////////
///                         PARAMETERS                               ///
////////////////////////////////////////////////////////////////////////

36 37 38 39


ABC_NAMESPACE_HEADER_START

Alan Mishchenko committed
40

Alan Mishchenko committed
41 42 43 44 45 46
////////////////////////////////////////////////////////////////////////
///                         BASIC TYPES                              ///
////////////////////////////////////////////////////////////////////////
 
#define RWR_LIMIT  1048576/4  // ((1 << 20) 

Alan Mishchenko committed
47
typedef struct Rwr_Man_t_   Rwr_Man_t;
Alan Mishchenko committed
48 49
typedef struct Rwr_Node_t_  Rwr_Node_t;

Alan Mishchenko committed
50
struct Rwr_Man_t_
Alan Mishchenko committed
51 52
{
    // internal lookups
Alan Mishchenko committed
53
    int                nFuncs;           // number of four var functions
Alan Mishchenko committed
54
    unsigned short *   puCanons;         // canonical forms
Alan Mishchenko committed
55 56 57
    char *             pPhases;          // canonical phases
    char *             pPerms;           // canonical permutations
    unsigned char *    pMap;             // mapping of functions into class numbers
Alan Mishchenko committed
58
    unsigned short *   pMapInv;          // mapping of classes into functions
Alan Mishchenko committed
59
    char *             pPractical;       // practical NPN classes
Alan Mishchenko committed
60
    char **            pPerms4;          // four-var permutations
Alan Mishchenko committed
61 62 63
    // node space
    Vec_Ptr_t *        vForest;          // all the nodes
    Rwr_Node_t **      pTable;           // the hash table of nodes by their canonical form
Alan Mishchenko committed
64
    Vec_Vec_t *        vClasses;         // the nodes of the equivalence classes
Alan Mishchenko committed
65
    Extra_MmFixed_t *  pMmNode;          // memory for nodes and cuts
Alan Mishchenko committed
66
    // statistical variables
Alan Mishchenko committed
67 68 69 70 71
    int                nTravIds;         // the counter of traversal IDs
    int                nConsidered;      // the number of nodes considered
    int                nAdded;           // the number of nodes added to lists
    int                nClasses;         // the number of NN classes
    // the result of resynthesis
Alan Mishchenko committed
72
    int                fCompl;           // indicates if the output of FF should be complemented
Alan Mishchenko committed
73
    void *             pGraph;           // the decomposition tree (temporary)
Alan Mishchenko committed
74
    Vec_Ptr_t *        vFanins;          // the fanins array (temporary)
Alan Mishchenko committed
75 76
    Vec_Ptr_t *        vFaninsCur;       // the fanins array (temporary)
    Vec_Int_t *        vLevNums;         // the array of levels (temporary)
Alan Mishchenko committed
77
    Vec_Ptr_t *        vNodesTemp;       // the nodes in MFFC (temporary)
Alan Mishchenko committed
78 79 80 81
    // node statistics
    int                nNodesConsidered;
    int                nNodesRewritten;
    int                nNodesGained;
Alan Mishchenko committed
82 83
    int                nNodesBeg;
    int                nNodesEnd;
Alan Mishchenko committed
84 85 86 87
    int                nScores[222];
    int                nCutsGood;
    int                nCutsBad;
    int                nSubgraphs;
Alan Mishchenko committed
88
    // runtime statistics
89 90 91 92 93 94 95
    abctime            timeStart;
    abctime            timeCut;
    abctime            timeRes;
    abctime            timeEval;
    abctime            timeMffc;
    abctime            timeUpdate;
    abctime            timeTotal;
Alan Mishchenko committed
96 97
};

Alan Mishchenko committed
98 99 100 101
struct Rwr_Node_t_ // 24 bytes
{
    int                Id;               // ID 
    int                TravId;           // traversal ID
Alan Mishchenko committed
102 103 104
    short              nScore;
    short              nGain;
    short              nAdded;
Alan Mishchenko committed
105 106
    unsigned           uTruth : 16;      // truth table
    unsigned           Volume :  8;      // volume
Alan Mishchenko committed
107
    unsigned           Level  :  6;      // level
Alan Mishchenko committed
108 109 110 111 112 113 114
    unsigned           fUsed  :  1;      // mark
    unsigned           fExor  :  1;      // mark
    Rwr_Node_t *       p0;               // first child
    Rwr_Node_t *       p1;               // second child
    Rwr_Node_t *       pNext;            // next in the table
};

Alan Mishchenko committed
115
// manipulation of complemented attributes
116
static inline int          Rwr_IsComplement( Rwr_Node_t * p )    { return (int )(((ABC_PTRUINT_T)p) & 01);           }
Alan Mishchenko committed
117 118 119
static inline Rwr_Node_t * Rwr_Regular( Rwr_Node_t * p )         { return (Rwr_Node_t *)((ABC_PTRUINT_T)(p) & ~01);  }
static inline Rwr_Node_t * Rwr_Not( Rwr_Node_t * p )             { return (Rwr_Node_t *)((ABC_PTRUINT_T)(p) ^  01);  }
static inline Rwr_Node_t * Rwr_NotCond( Rwr_Node_t * p, int c )  { return (Rwr_Node_t *)((ABC_PTRUINT_T)(p) ^ (c));  }
Alan Mishchenko committed
120 121

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
122
///                      MACRO DEFINITIONS                           ///
Alan Mishchenko committed
123 124 125 126 127 128
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                    FUNCTION DECLARATIONS                         ///
////////////////////////////////////////////////////////////////////////

Alan Mishchenko committed
129
/*=== rwrDec.c ========================================================*/
Alan Mishchenko committed
130
extern void              Rwr_ManPreprocess( Rwr_Man_t * p );
Alan Mishchenko committed
131
/*=== rwrEva.c ========================================================*/
Alan Mishchenko committed
132 133 134
extern int               Rwr_NodeRewrite( Rwr_Man_t * p, Cut_Man_t * pManCut, Abc_Obj_t * pNode, int fUpdateLevel, int fUseZeros, int fPlaceEnable );
extern void              Rwr_ScoresClean( Rwr_Man_t * p );
extern void              Rwr_ScoresReport( Rwr_Man_t * p );
Alan Mishchenko committed
135 136
/*=== rwrLib.c ========================================================*/
extern void              Rwr_ManPrecompute( Rwr_Man_t * p );
Alan Mishchenko committed
137 138 139 140
extern Rwr_Node_t *      Rwr_ManAddVar( Rwr_Man_t * p, unsigned uTruth, int fPrecompute );
extern Rwr_Node_t *      Rwr_ManAddNode( Rwr_Man_t * p, Rwr_Node_t * p0, Rwr_Node_t * p1, int fExor, int Level, int Volume );
extern int               Rwr_ManNodeVolume( Rwr_Man_t * p, Rwr_Node_t * p0, Rwr_Node_t * p1 );
extern void              Rwr_ManIncTravId( Rwr_Man_t * p );
Alan Mishchenko committed
141
/*=== rwrMan.c ========================================================*/
142
extern Rwr_Man_t *       Rwr_ManStart( int  fPrecompute );
Alan Mishchenko committed
143
extern void              Rwr_ManStop( Rwr_Man_t * p );
Alan Mishchenko committed
144
extern void              Rwr_ManPrintStats( Rwr_Man_t * p );
Alan Mishchenko committed
145
extern void              Rwr_ManPrintStatsFile( Rwr_Man_t * p );
Alan Mishchenko committed
146
extern void *            Rwr_ManReadDecs( Rwr_Man_t * p );
Alan Mishchenko committed
147
extern Vec_Ptr_t *       Rwr_ManReadLeaves( Rwr_Man_t * p );
Alan Mishchenko committed
148
extern int               Rwr_ManReadCompl( Rwr_Man_t * p );
149 150 151
extern void              Rwr_ManAddTimeCuts( Rwr_Man_t * p, abctime Time );
extern void              Rwr_ManAddTimeUpdate( Rwr_Man_t * p, abctime Time );
extern void              Rwr_ManAddTimeTotal( Rwr_Man_t * p, abctime Time );
Alan Mishchenko committed
152 153
/*=== rwrPrint.c ========================================================*/
extern void              Rwr_ManPrint( Rwr_Man_t * p );
Alan Mishchenko committed
154
/*=== rwrUtil.c ========================================================*/
Alan Mishchenko committed
155
extern void              Rwr_ManWriteToArray( Rwr_Man_t * p );
Alan Mishchenko committed
156
extern void              Rwr_ManLoadFromArray( Rwr_Man_t * p, int fVerbose );
Alan Mishchenko committed
157 158 159 160
extern void              Rwr_ManWriteToFile( Rwr_Man_t * p, char * pFileName );
extern void              Rwr_ManLoadFromFile( Rwr_Man_t * p, char * pFileName );
extern void              Rwr_ListAddToTail( Rwr_Node_t ** ppList, Rwr_Node_t * pNode );
extern char *            Rwr_ManGetPractical( Rwr_Man_t * p );
Alan Mishchenko committed
161

162 163 164 165 166


ABC_NAMESPACE_HEADER_END


Alan Mishchenko committed
167 168 169

#endif

Alan Mishchenko committed
170 171 172 173
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////