ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcXsim.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22#include "aig/gia/gia.h"
23
25
29
30#define XVS0 ABC_INIT_ZERO
31#define XVS1 ABC_INIT_ONE
32#define XVSX ABC_INIT_DC
33
34static inline void Abc_ObjSetXsim( Abc_Obj_t * pObj, int Value ) { pObj->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)Value; }
35static inline int Abc_ObjGetXsim( Abc_Obj_t * pObj ) { return (int)(ABC_PTRINT_T)pObj->pCopy; }
36static 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}
45static 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}
54static inline int Abc_XsimRand2()
55{
56// return (rand() & 1) ? XVS1 : XVS0;
57 return (Gia_ManRandom(0) & 1) ? XVS1 : XVS0;
58}
59static 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}
68static 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}
74static 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}
80static 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
99
111void 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
119 Abc_ObjSetXsim( Abc_AigConst1(pNtk), XVS1 );
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 )
133 Abc_ObjSetXsim( Abc_ObjFanout0(pObj), XVSX );
134 }
135 else
136 {
137 Abc_NtkForEachLatch( pNtk, pObj, i )
138 Abc_ObjSetXsim( Abc_ObjFanout0(pObj), Abc_LatchInit(pObj) );
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 )
145 Abc_ObjSetXsim( pObj, Abc_XsimAnd(Abc_ObjGetXsimFanin0(pObj), Abc_ObjGetXsimFanin1(pObj)) );
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 )
176 Abc_ObjSetXsim( Abc_ObjFanout0(pObj), Abc_ObjGetXsim(Abc_ObjFanin0(pObj)) );
177 }
178}
179
192void 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
200 Abc_ObjSetXsim( Abc_AigConst1(pNtk), XVS1 );
201 Abc_NtkForEachLatch( pNtk, pObj, i )
202 Abc_ObjSetXsim( Abc_ObjFanout0(pObj), Abc_LatchInit(pObj) );
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 )
210 Abc_ObjSetXsim( pObj, Abc_XsimAnd(Abc_ObjGetXsimFanin0(pObj), Abc_ObjGetXsimFanin1(pObj)) );
211 Abc_NtkForEachCo( pNtk, pObj, i )
212 Abc_ObjSetXsim( pObj, Abc_ObjGetXsimFanin0(pObj) );
213 Abc_NtkForEachLatch( pNtk, pObj, i )
214 Abc_ObjSetXsim( Abc_ObjFanout0(pObj), Abc_ObjGetXsim(Abc_ObjFanin0(pObj)) );
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
228
229
231
void Abc_NtkCycleInitState(Abc_Ntk_t *pNtk, int nFrames, int fUseXval, int fVerbose)
Definition abcXsim.c:192
#define XVS1
Definition abcXsim.c:31
#define XVS0
DECLARATIONS ///.
Definition abcXsim.c:30
#define XVSX
Definition abcXsim.c:32
void Abc_NtkXValueSimulate(Abc_Ntk_t *pNtk, int nFrames, int fXInputs, int fXState, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition abcXsim.c:111
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
#define Abc_AigForEachAnd(pNtk, pNode, i)
Definition abc.h:488
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition abc.h:520
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition abc.h:500
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
@ ABC_INIT_DC
Definition abc.h:106
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition abc.h:516
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition abcAig.c:683
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
Definition giaUtil.c:49
void * pData
Definition abc.h:145
Abc_Obj_t * pCopy
Definition abc.h:148
#define assert(ex)
Definition util_old.h:213