1 /**CFile****************************************************************
2 
3   FileName    [sim.h]
4 
5   SystemName  [ABC: Logic synthesis and verification system.]
6 
7   PackageName [Simulation package.]
8 
9   Synopsis    [External declarations.]
10 
11   Author      [Alan Mishchenko]
12 
13   Affiliation [UC Berkeley]
14 
15   Date        [Ver. 1.0. Started - June 20, 2005.]
16 
17   Revision    [$Id: sim.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__opt__sim__sim_h
22 #define ABC__opt__sim__sim_h
23 
24 
25 /*
26     The ideas realized in this package are described in the paper:
27     "Detecting Symmetries in Boolean Functions using Circuit Representation,
28     Simulation, and Satisfiability".
29 */
30 
31 ////////////////////////////////////////////////////////////////////////
32 ///                          INCLUDES                                ///
33 ////////////////////////////////////////////////////////////////////////
34 
35 ////////////////////////////////////////////////////////////////////////
36 ///                         PARAMETERS                               ///
37 ////////////////////////////////////////////////////////////////////////
38 
39 
40 
41 ABC_NAMESPACE_HEADER_START
42 
43 
44 ////////////////////////////////////////////////////////////////////////
45 ///                         BASIC TYPES                              ///
46 ////////////////////////////////////////////////////////////////////////
47 
48 typedef struct Sym_Man_t_ Sym_Man_t;
49 struct Sym_Man_t_
50 {
51     // info about the network
52     Abc_Ntk_t *       pNtk;          // the network
53     Vec_Ptr_t *       vNodes;        // internal nodes in topological order
54     int               nInputs;
55     int               nOutputs;
56     // internal simulation information
57     int               nSimWords;     // the number of bits in simulation info
58     Vec_Ptr_t *       vSim;          // simulation info
59     // support information
60     Vec_Ptr_t *       vSuppFun;      // bit representation
61     Vec_Vec_t *       vSupports;     // integer representation
62     // symmetry info for each output
63     Vec_Ptr_t *       vMatrSymms;    // symmetric pairs
64     Vec_Ptr_t *       vMatrNonSymms; // non-symmetric pairs
65     Vec_Int_t *       vPairsTotal;   // total pairs
66     Vec_Int_t *       vPairsSym;     // symmetric pairs
67     Vec_Int_t *       vPairsNonSym;  // non-symmetric pairs
68     // temporary simulation info
69     unsigned *        uPatRand;
70     unsigned *        uPatCol;
71     unsigned *        uPatRow;
72     // temporary
73     Vec_Int_t *       vVarsU;
74     Vec_Int_t *       vVarsV;
75     int               iOutput;
76     int               iVar1;
77     int               iVar2;
78     int               iVar1Old;
79     int               iVar2Old;
80     // internal data structures
81     int               nSatRuns;
82     int               nSatRunsSat;
83     int               nSatRunsUnsat;
84     // pairs
85     int               nPairsSymm;
86     int               nPairsSymmStr;
87     int               nPairsNonSymm;
88     int               nPairsRem;
89     int               nPairsTotal;
90     // runtime statistics
91     abctime           timeStruct;
92     abctime           timeCount;
93     abctime           timeMatr;
94     abctime           timeSim;
95     abctime           timeFraig;
96     abctime           timeSat;
97     abctime           timeTotal;
98 };
99 
100 typedef struct Sim_Man_t_ Sim_Man_t;
101 struct Sim_Man_t_
102 {
103     // info about the network
104     Abc_Ntk_t *       pNtk;
105     int               nInputs;
106     int               nOutputs;
107     int               fLightweight;
108     // internal simulation information
109     int               nSimBits;      // the number of bits in simulation info
110     int               nSimWords;     // the number of words in simulation info
111     Vec_Ptr_t *       vSim0;         // simulation info 1
112     Vec_Ptr_t *       vSim1;         // simulation info 2
113     // support information
114     int               nSuppBits;     // the number of bits in support info
115     int               nSuppWords;    // the number of words in support info
116     Vec_Ptr_t *       vSuppStr;      // structural supports
117     Vec_Ptr_t *       vSuppFun;      // functional supports
118     // simulation targets
119     Vec_Vec_t *       vSuppTargs;    // support targets
120     int               iInput;        // the input current processed
121     // internal data structures
122     Extra_MmFixed_t * pMmPat;
123     Vec_Ptr_t *       vFifo;
124     Vec_Int_t *       vDiffs;
125     int               nSatRuns;
126     int               nSatRunsSat;
127     int               nSatRunsUnsat;
128     // runtime statistics
129     abctime           timeSim;
130     abctime           timeTrav;
131     abctime           timeFraig;
132     abctime           timeSat;
133     abctime           timeTotal;
134 };
135 
136 typedef struct Sim_Pat_t_ Sim_Pat_t;
137 struct Sim_Pat_t_
138 {
139     int              Input;         // the input which it has detected
140     int              Output;        // the output for which it was collected
141     unsigned *       pData;         // the simulation data
142 };
143 
144 ////////////////////////////////////////////////////////////////////////
145 ///                      MACRO DEFINITIONS                           ///
146 ////////////////////////////////////////////////////////////////////////
147 
148 #define SIM_NUM_WORDS(n)      (((n)>>5) + (((n)&31) > 0))
149 #define SIM_LAST_BITS(n)      ((((n)&31) > 0)? (n)&31 : 32)
150 
151 #define SIM_MASK_FULL         (0xFFFFFFFF)
152 #define SIM_MASK_BEG(n)       (SIM_MASK_FULL >> (32-n))
153 #define SIM_MASK_END(n)       (SIM_MASK_FULL << (n))
154 #define SIM_SET_0_FROM(m,n)   ((m) & ~SIM_MASK_BEG(n))
155 #define SIM_SET_1_FROM(m,n)   ((m) |  SIM_MASK_END(n))
156 
157 // generating random unsigned (#define RAND_MAX 0x7fff)
158 #define SIM_RANDOM_UNSIGNED   ((((unsigned)rand()) << 24) ^ (((unsigned)rand()) << 12) ^ ((unsigned)rand()))
159 
160 // macros to get hold of bits in a bit string
161 #define Sim_SetBit(p,i)       ((p)[(i)>>5] |= (1<<((i) & 31)))
162 #define Sim_XorBit(p,i)       ((p)[(i)>>5] ^= (1<<((i) & 31)))
163 #define Sim_HasBit(p,i)      (((p)[(i)>>5]  & (1<<((i) & 31))) > 0)
164 
165 // macros to get hold of the support info
166 #define Sim_SuppStrSetVar(vSupps,pNode,v)     Sim_SetBit((unsigned*)(vSupps)->pArray[(pNode)->Id],(v))
167 #define Sim_SuppStrHasVar(vSupps,pNode,v)     Sim_HasBit((unsigned*)(vSupps)->pArray[(pNode)->Id],(v))
168 #define Sim_SuppFunSetVar(vSupps,Output,v)    Sim_SetBit((unsigned*)(vSupps)->pArray[Output],(v))
169 #define Sim_SuppFunHasVar(vSupps,Output,v)    Sim_HasBit((unsigned*)(vSupps)->pArray[Output],(v))
170 #define Sim_SimInfoSetVar(vSupps,pNode,v)     Sim_SetBit((unsigned*)(vSupps)->pArray[(pNode)->Id],(v))
171 #define Sim_SimInfoHasVar(vSupps,pNode,v)     Sim_HasBit((unsigned*)(vSupps)->pArray[(pNode)->Id],(v))
172 #define Sim_SimInfoGet(vInfo,pNode)           ((unsigned *)((vInfo)->pArray[(pNode)->Id]))
173 
174 ////////////////////////////////////////////////////////////////////////
175 ///                    FUNCTION DECLARATIONS                         ///
176 ////////////////////////////////////////////////////////////////////////
177 
178 /*=== simMan.c ==========================================================*/
179 extern Sym_Man_t *     Sym_ManStart( Abc_Ntk_t * pNtk, int fVerbose );
180 extern void            Sym_ManStop( Sym_Man_t * p );
181 extern void            Sym_ManPrintStats( Sym_Man_t * p );
182 extern Sim_Man_t *     Sim_ManStart( Abc_Ntk_t * pNtk, int fLightweight );
183 extern void            Sim_ManStop( Sim_Man_t * p );
184 extern void            Sim_ManPrintStats( Sim_Man_t * p );
185 extern Sim_Pat_t *     Sim_ManPatAlloc( Sim_Man_t * p );
186 extern void            Sim_ManPatFree( Sim_Man_t * p, Sim_Pat_t * pPat );
187 /*=== simSeq.c ==========================================================*/
188 extern Vec_Ptr_t *     Sim_SimulateSeqRandom( Abc_Ntk_t * pNtk, int nFrames, int nWords );
189 extern Vec_Ptr_t *     Sim_SimulateSeqModel( Abc_Ntk_t * pNtk, int nFrames, int * pModel );
190 /*=== simSupp.c ==========================================================*/
191 extern Vec_Ptr_t *     Sim_ComputeStrSupp( Abc_Ntk_t * pNtk );
192 extern Vec_Ptr_t *     Sim_ComputeFunSupp( Abc_Ntk_t * pNtk, int fVerbose );
193 /*=== simSym.c ==========================================================*/
194 extern int             Sim_ComputeTwoVarSymms( Abc_Ntk_t * pNtk, int fVerbose );
195 /*=== simSymSat.c ==========================================================*/
196 extern int             Sim_SymmsGetPatternUsingSat( Sym_Man_t * p, unsigned * pPattern );
197 /*=== simSymStr.c ==========================================================*/
198 extern void            Sim_SymmsStructCompute( Abc_Ntk_t * pNtk, Vec_Ptr_t * vMatrs, Vec_Ptr_t * vSuppFun );
199 /*=== simSymSim.c ==========================================================*/
200 extern void            Sim_SymmsSimulate( Sym_Man_t * p, unsigned * pPatRand, Vec_Ptr_t * vMatrsNonSym );
201 /*=== simUtil.c ==========================================================*/
202 extern Vec_Ptr_t *     Sim_UtilInfoAlloc( int nSize, int nWords, int  fClean );
203 extern void            Sim_UtilInfoFree( Vec_Ptr_t * p );
204 extern void            Sim_UtilInfoAdd( unsigned * pInfo1, unsigned * pInfo2, int nWords );
205 extern void            Sim_UtilInfoDetectDiffs( unsigned * pInfo1, unsigned * pInfo2, int nWords, Vec_Int_t * vDiffs );
206 extern void            Sim_UtilInfoDetectNews( unsigned * pInfo1, unsigned * pInfo2, int nWords, Vec_Int_t * vDiffs );
207 extern void            Sim_UtilInfoFlip( Sim_Man_t * p, Abc_Obj_t * pNode );
208 extern int             Sim_UtilInfoCompare( Sim_Man_t * p, Abc_Obj_t * pNode );
209 extern void            Sim_UtilSimulate( Sim_Man_t * p, int  fFirst );
210 extern void            Sim_UtilSimulateNode( Sim_Man_t * p, Abc_Obj_t * pNode, int  fType, int  fType1, int  fType2 );
211 extern void            Sim_UtilSimulateNodeOne( Abc_Obj_t * pNode, Vec_Ptr_t * vSimInfo, int nSimWords, int nOffset );
212 extern void            Sim_UtilTransferNodeOne( Abc_Obj_t * pNode, Vec_Ptr_t * vSimInfo, int nSimWords, int nOffset, int fShift );
213 extern int             Sim_UtilCountSuppSizes( Sim_Man_t * p, int fStruct );
214 extern int             Sim_UtilCountOnes( unsigned * pSimInfo, int nSimWords );
215 extern Vec_Int_t *     Sim_UtilCountOnesArray( Vec_Ptr_t * vInfo, int nSimWords );
216 extern void            Sim_UtilSetRandom( unsigned * pPatRand, int nSimWords );
217 extern void            Sim_UtilSetCompl( unsigned * pPatRand, int nSimWords );
218 extern void            Sim_UtilSetConst( unsigned * pPatRand, int nSimWords, int fConst1 );
219 extern int             Sim_UtilInfoIsEqual( unsigned * pPats1, unsigned * pPats2, int nSimWords );
220 extern int             Sim_UtilInfoIsImp( unsigned * pPats1, unsigned * pPats2, int nSimWords );
221 extern int             Sim_UtilInfoIsClause( unsigned * pPats1, unsigned * pPats2, int nSimWords );
222 extern int             Sim_UtilCountAllPairs( Vec_Ptr_t * vSuppFun, int nSimWords, Vec_Int_t * vCounters );
223 extern void            Sim_UtilCountPairsAll( Sym_Man_t * p );
224 extern int             Sim_UtilMatrsAreDisjoint( Sym_Man_t * p );
225 
226 
227 
228 ABC_NAMESPACE_HEADER_END
229 
230 
231 
232 #endif
233 
234 ////////////////////////////////////////////////////////////////////////
235 ///                       END OF FILE                                ///
236 ////////////////////////////////////////////////////////////////////////
237 
238