sim.h 10.8 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
/**CFile****************************************************************

  FileName    [sim.h]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Simulation package.]

  Synopsis    [External declarations.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

  Revision    [$Id: sim.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

***********************************************************************/
Alan Mishchenko committed
20

Alan Mishchenko committed
21 22 23
#ifndef __SIM_H__
#define __SIM_H__

Alan Mishchenko committed
24 25 26 27
#ifdef __cplusplus
extern "C" {
#endif

Alan Mishchenko committed
28 29 30 31 32 33
/*
    The ideas realized in this package are described in the paper:
    "Detecting Symmetries in Boolean Functions using Circuit Representation, 
    Simulation, and Satisfiability".
*/

Alan Mishchenko committed
34 35 36 37 38 39 40 41 42 43 44 45
////////////////////////////////////////////////////////////////////////
///                          INCLUDES                                ///
////////////////////////////////////////////////////////////////////////

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

////////////////////////////////////////////////////////////////////////
///                         BASIC TYPES                              ///
////////////////////////////////////////////////////////////////////////

Alan Mishchenko committed
46 47 48 49 50 51 52 53 54 55 56 57
typedef struct Sym_Man_t_ Sym_Man_t;
struct Sym_Man_t_
{
    // info about the network
    Abc_Ntk_t *       pNtk;          // the network 
    Vec_Ptr_t *       vNodes;        // internal nodes in topological order
    int               nInputs;
    int               nOutputs;
    // internal simulation information
    int               nSimWords;     // the number of bits in simulation info
    Vec_Ptr_t *       vSim;          // simulation info
    // support information
Alan Mishchenko committed
58 59
    Vec_Ptr_t *       vSuppFun;      // bit representation
    Vec_Vec_t *       vSupports;     // integer representation
Alan Mishchenko committed
60 61 62 63 64 65 66 67 68 69
    // symmetry info for each output
    Vec_Ptr_t *       vMatrSymms;    // symmetric pairs
    Vec_Ptr_t *       vMatrNonSymms; // non-symmetric pairs
    Vec_Int_t *       vPairsTotal;   // total pairs
    Vec_Int_t *       vPairsSym;     // symmetric pairs
    Vec_Int_t *       vPairsNonSym;  // non-symmetric pairs
    // temporary simulation info
    unsigned *        uPatRand;
    unsigned *        uPatCol;
    unsigned *        uPatRow;
Alan Mishchenko committed
70 71 72 73 74 75 76 77
    // temporary
    Vec_Int_t *       vVarsU;
    Vec_Int_t *       vVarsV;
    int               iOutput;
    int               iVar1;
    int               iVar2;
    int               iVar1Old;
    int               iVar2Old;
Alan Mishchenko committed
78 79 80 81 82 83 84 85
    // internal data structures
    int               nSatRuns;
    int               nSatRunsSat;
    int               nSatRunsUnsat;
    // pairs
    int               nPairsSymm;
    int               nPairsSymmStr;
    int               nPairsNonSymm;
Alan Mishchenko committed
86
    int               nPairsRem;
Alan Mishchenko committed
87 88
    int               nPairsTotal;
    // runtime statistics
Alan Mishchenko committed
89 90 91
    int               timeStruct;
    int               timeCount;
    int               timeMatr;
Alan Mishchenko committed
92 93 94 95 96 97
    int               timeSim;
    int               timeFraig;
    int               timeSat;
    int               timeTotal;
};

Alan Mishchenko committed
98 99 100
typedef struct Sim_Man_t_ Sim_Man_t;
struct Sim_Man_t_
{
Alan Mishchenko committed
101
    // info about the network
Alan Mishchenko committed
102
    Abc_Ntk_t *       pNtk;
Alan Mishchenko committed
103 104
    int               nInputs;
    int               nOutputs;
Alan Mishchenko committed
105
    int               fLightweight;
Alan Mishchenko committed
106 107 108 109 110 111 112 113 114 115 116
    // internal simulation information
    int               nSimBits;      // the number of bits in simulation info
    int               nSimWords;     // the number of words in simulation info
    Vec_Ptr_t *       vSim0;         // simulation info 1
    Vec_Ptr_t *       vSim1;         // simulation info 2
    // support information
    int               nSuppBits;     // the number of bits in support info
    int               nSuppWords;    // the number of words in support info
    Vec_Ptr_t *       vSuppStr;      // structural supports
    Vec_Ptr_t *       vSuppFun;      // functional supports
    // simulation targets
Alan Mishchenko committed
117
    Vec_Vec_t *       vSuppTargs;    // support targets
Alan Mishchenko committed
118
    int               iInput;        // the input current processed
Alan Mishchenko committed
119 120 121 122
    // internal data structures
    Extra_MmFixed_t * pMmPat;   
    Vec_Ptr_t *       vFifo;
    Vec_Int_t *       vDiffs;
Alan Mishchenko committed
123 124 125
    int               nSatRuns;
    int               nSatRunsSat;
    int               nSatRunsUnsat;
Alan Mishchenko committed
126
    // runtime statistics
Alan Mishchenko committed
127 128 129 130 131
    int               timeSim;
    int               timeTrav;
    int               timeFraig;
    int               timeSat;
    int               timeTotal;
Alan Mishchenko committed
132 133 134 135 136 137 138 139 140 141 142
};

typedef struct Sim_Pat_t_ Sim_Pat_t;
struct Sim_Pat_t_
{
    int              Input;         // the input which it has detected
    int              Output;        // the output for which it was collected
    unsigned *       pData;         // the simulation data
};

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
143
///                      MACRO DEFINITIONS                           ///
Alan Mishchenko committed
144 145
////////////////////////////////////////////////////////////////////////

Alan Mishchenko committed
146 147
#define SIM_NUM_WORDS(n)      (((n)>>5) + (((n)&31) > 0))
#define SIM_LAST_BITS(n)      ((((n)&31) > 0)? (n)&31 : 32)
Alan Mishchenko committed
148

Alan Mishchenko committed
149 150 151 152 153 154
#define SIM_MASK_FULL         (0xFFFFFFFF)
#define SIM_MASK_BEG(n)       (SIM_MASK_FULL >> (32-n))
#define SIM_MASK_END(n)       (SIM_MASK_FULL << (n))
#define SIM_SET_0_FROM(m,n)   ((m) & ~SIM_MASK_BEG(n))
#define SIM_SET_1_FROM(m,n)   ((m) |  SIM_MASK_END(n))

Alan Mishchenko committed
155 156 157 158 159 160 161 162 163
// generating random unsigned (#define RAND_MAX 0x7fff)
#define SIM_RANDOM_UNSIGNED   ((((unsigned)rand()) << 24) ^ (((unsigned)rand()) << 12) ^ ((unsigned)rand()))

// macros to get hold of bits in a bit string
#define Sim_SetBit(p,i)       ((p)[(i)>>5] |= (1<<((i) & 31)))
#define Sim_XorBit(p,i)       ((p)[(i)>>5] ^= (1<<((i) & 31)))
#define Sim_HasBit(p,i)      (((p)[(i)>>5]  & (1<<((i) & 31))) > 0)

// macros to get hold of the support info
Alan Mishchenko committed
164 165 166 167 168 169
#define Sim_SuppStrSetVar(vSupps,pNode,v)     Sim_SetBit((unsigned*)(vSupps)->pArray[(pNode)->Id],(v))
#define Sim_SuppStrHasVar(vSupps,pNode,v)     Sim_HasBit((unsigned*)(vSupps)->pArray[(pNode)->Id],(v))
#define Sim_SuppFunSetVar(vSupps,Output,v)    Sim_SetBit((unsigned*)(vSupps)->pArray[Output],(v))
#define Sim_SuppFunHasVar(vSupps,Output,v)    Sim_HasBit((unsigned*)(vSupps)->pArray[Output],(v))
#define Sim_SimInfoSetVar(vSupps,pNode,v)     Sim_SetBit((unsigned*)(vSupps)->pArray[(pNode)->Id],(v))
#define Sim_SimInfoHasVar(vSupps,pNode,v)     Sim_HasBit((unsigned*)(vSupps)->pArray[(pNode)->Id],(v))
Alan Mishchenko committed
170
#define Sim_SimInfoGet(vInfo,pNode)           ((unsigned *)((vInfo)->pArray[(pNode)->Id]))
Alan Mishchenko committed
171 172 173 174 175 176

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

/*=== simMan.c ==========================================================*/
Alan Mishchenko committed
177
extern Sym_Man_t *     Sym_ManStart( Abc_Ntk_t * pNtk, int fVerbose );
Alan Mishchenko committed
178 179
extern void            Sym_ManStop( Sym_Man_t * p );
extern void            Sym_ManPrintStats( Sym_Man_t * p );
Alan Mishchenko committed
180
extern Sim_Man_t *     Sim_ManStart( Abc_Ntk_t * pNtk, int fLightweight );
Alan Mishchenko committed
181
extern void            Sim_ManStop( Sim_Man_t * p );
Alan Mishchenko committed
182
extern void            Sim_ManPrintStats( Sim_Man_t * p );
Alan Mishchenko committed
183 184
extern Sim_Pat_t *     Sim_ManPatAlloc( Sim_Man_t * p );
extern void            Sim_ManPatFree( Sim_Man_t * p, Sim_Pat_t * pPat );
Alan Mishchenko committed
185 186 187
/*=== simSeq.c ==========================================================*/
extern Vec_Ptr_t *     Sim_SimulateSeqRandom( Abc_Ntk_t * pNtk, int nFrames, int nWords );
extern Vec_Ptr_t *     Sim_SimulateSeqModel( Abc_Ntk_t * pNtk, int nFrames, int * pModel );
Alan Mishchenko committed
188
/*=== simSupp.c ==========================================================*/
Alan Mishchenko committed
189
extern Vec_Ptr_t *     Sim_ComputeStrSupp( Abc_Ntk_t * pNtk );
Alan Mishchenko committed
190
extern Vec_Ptr_t *     Sim_ComputeFunSupp( Abc_Ntk_t * pNtk, int fVerbose );
Alan Mishchenko committed
191
/*=== simSym.c ==========================================================*/
Alan Mishchenko committed
192 193 194
extern int             Sim_ComputeTwoVarSymms( Abc_Ntk_t * pNtk, int fVerbose );
/*=== simSymSat.c ==========================================================*/
extern int             Sim_SymmsGetPatternUsingSat( Sym_Man_t * p, unsigned * pPattern );
Alan Mishchenko committed
195
/*=== simSymStr.c ==========================================================*/
Alan Mishchenko committed
196
extern void            Sim_SymmsStructCompute( Abc_Ntk_t * pNtk, Vec_Ptr_t * vMatrs, Vec_Ptr_t * vSuppFun );
Alan Mishchenko committed
197 198
/*=== simSymSim.c ==========================================================*/
extern void            Sim_SymmsSimulate( Sym_Man_t * p, unsigned * pPatRand, Vec_Ptr_t * vMatrsNonSym );
Alan Mishchenko committed
199 200 201 202 203 204
/*=== simUtil.c ==========================================================*/
extern Vec_Ptr_t *     Sim_UtilInfoAlloc( int nSize, int nWords, bool fClean );
extern void            Sim_UtilInfoFree( Vec_Ptr_t * p );
extern void            Sim_UtilInfoAdd( unsigned * pInfo1, unsigned * pInfo2, int nWords );
extern void            Sim_UtilInfoDetectDiffs( unsigned * pInfo1, unsigned * pInfo2, int nWords, Vec_Int_t * vDiffs );
extern void            Sim_UtilInfoDetectNews( unsigned * pInfo1, unsigned * pInfo2, int nWords, Vec_Int_t * vDiffs );
Alan Mishchenko committed
205 206
extern void            Sim_UtilInfoFlip( Sim_Man_t * p, Abc_Obj_t * pNode );
extern bool            Sim_UtilInfoCompare( Sim_Man_t * p, Abc_Obj_t * pNode );
Alan Mishchenko committed
207 208
extern void            Sim_UtilSimulate( Sim_Man_t * p, bool fFirst );
extern void            Sim_UtilSimulateNode( Sim_Man_t * p, Abc_Obj_t * pNode, bool fType, bool fType1, bool fType2 );
Alan Mishchenko committed
209 210
extern void            Sim_UtilSimulateNodeOne( Abc_Obj_t * pNode, Vec_Ptr_t * vSimInfo, int nSimWords, int nOffset );
extern void            Sim_UtilTransferNodeOne( Abc_Obj_t * pNode, Vec_Ptr_t * vSimInfo, int nSimWords, int nOffset, int fShift );
Alan Mishchenko committed
211
extern int             Sim_UtilCountSuppSizes( Sim_Man_t * p, int fStruct );
Alan Mishchenko committed
212
extern int             Sim_UtilCountOnes( unsigned * pSimInfo, int nSimWords );
Alan Mishchenko committed
213 214 215 216 217 218 219
extern Vec_Int_t *     Sim_UtilCountOnesArray( Vec_Ptr_t * vInfo, int nSimWords );
extern void            Sim_UtilSetRandom( unsigned * pPatRand, int nSimWords );
extern void            Sim_UtilSetCompl( unsigned * pPatRand, int nSimWords );
extern void            Sim_UtilSetConst( unsigned * pPatRand, int nSimWords, int fConst1 );
extern int             Sim_UtilInfoIsEqual( unsigned * pPats1, unsigned * pPats2, int nSimWords );
extern int             Sim_UtilInfoIsImp( unsigned * pPats1, unsigned * pPats2, int nSimWords );
extern int             Sim_UtilInfoIsClause( unsigned * pPats1, unsigned * pPats2, int nSimWords );
Alan Mishchenko committed
220
extern int             Sim_UtilCountAllPairs( Vec_Ptr_t * vSuppFun, int nSimWords, Vec_Int_t * vCounters );
Alan Mishchenko committed
221 222
extern void            Sim_UtilCountPairsAll( Sym_Man_t * p );
extern int             Sim_UtilMatrsAreDisjoint( Sym_Man_t * p );
Alan Mishchenko committed
223

Alan Mishchenko committed
224 225 226 227 228 229
#ifdef __cplusplus
}
#endif

#endif

Alan Mishchenko committed
230 231 232 233
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////