abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcXsim.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcXsim.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Using X-valued simulation.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcXsim.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "aig/gia/gia.h"
23 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 #define XVS0 ABC_INIT_ZERO
31 #define XVS1 ABC_INIT_ONE
32 #define XVSX ABC_INIT_DC
33 
34 static inline void Abc_ObjSetXsim( Abc_Obj_t * pObj, int Value ) { pObj->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)Value; }
35 static inline int Abc_ObjGetXsim( Abc_Obj_t * pObj ) { return (int)(ABC_PTRINT_T)pObj->pCopy; }
36 static inline int Abc_XsimInv( int Value )
37 {
38  if ( Value == XVS0 )
39  return XVS1;
40  if ( Value == XVS1 )
41  return XVS0;
42  assert( Value == XVSX );
43  return XVSX;
44 }
45 static inline int Abc_XsimAnd( int Value0, int Value1 )
46 {
47  if ( Value0 == XVS0 || Value1 == XVS0 )
48  return XVS0;
49  if ( Value0 == XVSX || Value1 == XVSX )
50  return XVSX;
51  assert( Value0 == XVS1 && Value1 == XVS1 );
52  return XVS1;
53 }
54 static inline int Abc_XsimRand2()
55 {
56 // return (rand() & 1) ? XVS1 : XVS0;
57  return (Gia_ManRandom(0) & 1) ? XVS1 : XVS0;
58 }
59 static inline int Abc_XsimRand3()
60 {
61  int RetValue;
62  do {
63 // RetValue = rand() & 3;
64  RetValue = Gia_ManRandom(0) & 3;
65  } while ( RetValue == 0 );
66  return RetValue;
67 }
68 static inline int Abc_ObjGetXsimFanin0( Abc_Obj_t * pObj )
69 {
70  int RetValue;
71  RetValue = Abc_ObjGetXsim(Abc_ObjFanin0(pObj));
72  return Abc_ObjFaninC0(pObj)? Abc_XsimInv(RetValue) : RetValue;
73 }
74 static inline int Abc_ObjGetXsimFanin1( Abc_Obj_t * pObj )
75 {
76  int RetValue;
77  RetValue = Abc_ObjGetXsim(Abc_ObjFanin1(pObj));
78  return Abc_ObjFaninC1(pObj)? Abc_XsimInv(RetValue) : RetValue;
79 }
80 static inline void Abc_XsimPrint( FILE * pFile, int Value )
81 {
82  if ( Value == XVS0 )
83  {
84  fprintf( pFile, "0" );
85  return;
86  }
87  if ( Value == XVS1 )
88  {
89  fprintf( pFile, "1" );
90  return;
91  }
92  assert( Value == XVSX );
93  fprintf( pFile, "x" );
94 }
95 
96 ////////////////////////////////////////////////////////////////////////
97 /// FUNCTION DEFINITIONS ///
98 ////////////////////////////////////////////////////////////////////////
99 
100 /**Function*************************************************************
101 
102  Synopsis [Performs X-valued simulation of the sequential network.]
103 
104  Description []
105 
106  SideEffects []
107 
108  SeeAlso []
109 
110 ***********************************************************************/
111 void Abc_NtkXValueSimulate( Abc_Ntk_t * pNtk, int nFrames, int fXInputs, int fXState, int fVerbose )
112 {
113  Abc_Obj_t * pObj;
114  int i, f;
115  assert( Abc_NtkIsStrash(pNtk) );
116 // srand( 0x12341234 );
117  Gia_ManRandom( 1 );
118  // start simulation
120  if ( fXInputs )
121  {
122  Abc_NtkForEachPi( pNtk, pObj, i )
123  Abc_ObjSetXsim( pObj, XVSX );
124  }
125  else
126  {
127  Abc_NtkForEachPi( pNtk, pObj, i )
128  Abc_ObjSetXsim( pObj, Abc_XsimRand2() );
129  }
130  if ( fXState )
131  {
132  Abc_NtkForEachLatch( pNtk, pObj, i )
134  }
135  else
136  {
137  Abc_NtkForEachLatch( pNtk, pObj, i )
139  }
140  // simulate and print the result
141  fprintf( stdout, "Frame : Inputs : Latches : Outputs\n" );
142  for ( f = 0; f < nFrames; f++ )
143  {
144  Abc_AigForEachAnd( pNtk, pObj, i )
146  Abc_NtkForEachCo( pNtk, pObj, i )
147  Abc_ObjSetXsim( pObj, Abc_ObjGetXsimFanin0(pObj) );
148  // print out
149  fprintf( stdout, "%2d : ", f );
150  Abc_NtkForEachPi( pNtk, pObj, i )
151  Abc_XsimPrint( stdout, Abc_ObjGetXsim(pObj) );
152  fprintf( stdout, " : " );
153  Abc_NtkForEachLatch( pNtk, pObj, i )
154  {
155 // if ( Abc_ObjGetXsim(Abc_ObjFanout0(pObj)) != XVSX )
156 // printf( " %s=", Abc_ObjName(pObj) );
157  Abc_XsimPrint( stdout, Abc_ObjGetXsim(Abc_ObjFanout0(pObj)) );
158  }
159  fprintf( stdout, " : " );
160  Abc_NtkForEachPo( pNtk, pObj, i )
161  Abc_XsimPrint( stdout, Abc_ObjGetXsim(pObj) );
162  fprintf( stdout, "\n" );
163  // assign input values
164  if ( fXInputs )
165  {
166  Abc_NtkForEachPi( pNtk, pObj, i )
167  Abc_ObjSetXsim( pObj, XVSX );
168  }
169  else
170  {
171  Abc_NtkForEachPi( pNtk, pObj, i )
172  Abc_ObjSetXsim( pObj, Abc_XsimRand2() );
173  }
174  // transfer the latch values
175  Abc_NtkForEachLatch( pNtk, pObj, i )
177  }
178 }
179 
180 /**Function*************************************************************
181 
182  Synopsis [Cycles the circuit to create a new initial state.]
183 
184  Description [Simulates the circuit with random (or ternary) input
185  for the given number of timeframes to get a better initial state.]
186 
187  SideEffects []
188 
189  SeeAlso []
190 
191 ***********************************************************************/
192 void Abc_NtkCycleInitState( Abc_Ntk_t * pNtk, int nFrames, int fUseXval, int fVerbose )
193 {
194  Abc_Obj_t * pObj;
195  int i, f;
196  assert( Abc_NtkIsStrash(pNtk) );
197 // srand( 0x12341234 );
198  Gia_ManRandom( 1 );
199  // initialize the values
201  Abc_NtkForEachLatch( pNtk, pObj, i )
203  // simulate for the given number of timeframes
204  for ( f = 0; f < nFrames; f++ )
205  {
206  Abc_NtkForEachPi( pNtk, pObj, i )
207  Abc_ObjSetXsim( pObj, fUseXval? ABC_INIT_DC : Abc_XsimRand2() );
208 // Abc_ObjSetXsim( pObj, ABC_INIT_ONE );
209  Abc_AigForEachAnd( pNtk, pObj, i )
211  Abc_NtkForEachCo( pNtk, pObj, i )
212  Abc_ObjSetXsim( pObj, Abc_ObjGetXsimFanin0(pObj) );
213  Abc_NtkForEachLatch( pNtk, pObj, i )
215  }
216  // set the final values
217  Abc_NtkForEachLatch( pNtk, pObj, i )
218  {
219  pObj->pData = (void *)(ABC_PTRINT_T)Abc_ObjGetXsim(Abc_ObjFanout0(pObj));
220 // printf( "%d", Abc_LatchIsInit1(pObj) );
221  }
222 // printf( "\n" );
223 }
224 
225 ///////////////////////////////////////////////////////////////////////
226 /// END OF FILE ///
227 ////////////////////////////////////////////////////////////////////////
228 
229 
231 
static int Abc_NtkIsStrash(Abc_Ntk_t *pNtk)
Definition: abc.h:251
static int Abc_LatchInit(Abc_Obj_t *pLatch)
Definition: abc.h:425
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
void Abc_NtkXValueSimulate(Abc_Ntk_t *pNtk, int nFrames, int fXInputs, int fXState, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: abcXsim.c:111
#define XVS0
DECLARATIONS ///.
Definition: abcXsim.c:30
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition: abcAig.c:683
static int Abc_ObjFaninC1(Abc_Obj_t *pObj)
Definition: abc.h:378
static int Abc_ObjFaninC0(Abc_Obj_t *pObj)
Definition: abc.h:377
#define XVSX
Definition: abcXsim.c:32
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
static int Abc_XsimRand2()
Definition: abcXsim.c:54
static void Abc_XsimPrint(FILE *pFile, int Value)
Definition: abcXsim.c:80
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
Definition: giaUtil.c:49
static int Abc_ObjGetXsimFanin1(Abc_Obj_t *pObj)
Definition: abcXsim.c:74
#define Abc_AigForEachAnd(pNtk, pNode, i)
Definition: abc.h:485
Abc_Obj_t * pCopy
Definition: abc.h:148
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static int Abc_ObjGetXsim(Abc_Obj_t *pObj)
Definition: abcXsim.c:35
static void Abc_ObjSetXsim(Abc_Obj_t *pObj, int Value)
Definition: abcXsim.c:34
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition: abc.h:497
void Abc_NtkCycleInitState(Abc_Ntk_t *pNtk, int nFrames, int fUseXval, int fVerbose)
Definition: abcXsim.c:192
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Abc_XsimAnd(int Value0, int Value1)
Definition: abcXsim.c:45
#define XVS1
Definition: abcXsim.c:31
static int Abc_XsimRand3()
Definition: abcXsim.c:59
#define assert(ex)
Definition: util_old.h:213
static int Abc_ObjGetXsimFanin0(Abc_Obj_t *pObj)
Definition: abcXsim.c:68
void * pData
Definition: abc.h:145
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
static int Abc_XsimInv(int Value)
Definition: abcXsim.c:36
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513