-
Notifications
You must be signed in to change notification settings - Fork 35
/
macro.h
288 lines (256 loc) · 9.3 KB
/
macro.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/***********************************************************************
Copyright (C) 1991,
Virginia Polytechnic Institute & State University
This program was originally written by Mr. Hyung K. Lee
under the supervision of Dr. Dong S. Ha, in the Bradley
Department of Electrical Engineering, VPI&SU, in 1991.
This program is released for research use only. This program,
or any derivative thereof, may not be reproduced nor used
for any commercial product without the written permission
of the authors.
For detailed information, please contact to
Dr. Dong S. Ha
Bradley Department of Electrical Engineering
Virginia Polytechnic Institute & State University
Blacksburg, VA 24061
Ph.: (540) 231-4942
Fax: (540) 231-3362
E-Mail: [email protected]
Web: http://www.ee.vt.edu/ha
REFERENCE:
H. K. Lee and D. S. Ha, "On the Generation of Test Patterns
for Combinational Circuits," Technical Report No. 12_93,
Dep't of Electrical Eng., Virginia Polytechnic Institute
and State University.
***********************************************************************/
/**************************** HISTORY **********************************
atalanta: version 1.1 H. K. Lee, 10/5/1992
atalanta: version 2.0 H. K. Lee, 6/30/1997
***********************************************************************/
/*----------------------------------------------------------------------
macro.h
Define macro functions for atalanta.
-----------------------------------------------------------------------*/
#ifndef __ATALANTA_MACRO_H__
#define __ATALANTA_MACRO_H__
/* character substitution */
#define EOS '\0' /* End of string */
#define CR '\n' /* carriage return */
#define TAB '\t' /* tab */
/* assignment & comparison */
#define set(var) (var=TRUE)
#define reset(var) (var=FALSE)
#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
#define MIN(X,Y) ((X) > (Y) ? (Y) : (X))
//#define max(a,b) ((a) > (b) ? (a) : (b))
//#define min(a,b) ((a) > (b) ? (b) : (a))
#define ABS(X) ( X >= 0 ? X : (-1)*X )
#define A_NOT(var) ((var==ONE) ? ZERO : \
(var==ZERO) ? ONE : \
(var==D) ? DBAR : \
(var==DBAR) ? D : X)
/* macros for LIFO stack operation */
#define EMPTY (-1)
#define push(s,ele) s.list[++(s.last)]=ele
#define pop(s) s.list[(s.last)--]
#define clear(s) s.last=EMPTY
#define is_empty(s) (s.last<0)
#define ptr_is_empty(s) (s->last<0)
#define delete_last(s) --(s.last)
#define delete(s,i) s.list[i]=s.list[(s.last)--]
#define copy(s1,s2,i) s2.last=s1.last;\
for(i=s1.last;i>=0;i--) s2.list[i]=s1.list[i]
/* macros for event queue operation */
#define pushevent(gate) \
if (!gate->changed) \
{ \
push(g_pEventListStack[gate->dpi], gate); \
set(gate->changed); \
}
#define popevent(depth) pop(g_pEventListStack[depth])
#define clearevent(depth) clear(g_pEventListStack[depth])
#define schedule_output(pGate) \
for (mac_i = 0; mac_i < pGate->outCount; mac_i++) \
pushevent(pGate->outList[mac_i])
#define schedule_input(gate,i) pushevent(gate->inList[i]) \
schedule_output(gate->inList[i])
#define pushGate(pGate) push(g_pEventListStack[pGate->dpi], pGate)
#define pushGateOutputs2(pGate, i, pOutGate) \
for (i = 0; i < pGate->outCount; i++) \
{ \
pOutGate = pGate->outList[i]; \
if (!pOutGate->changed) \
{ \
set(pOutGate->changed); \
pushGate(pOutGate); \
} \
}
#define is_head(line) (line->ltype==HEAD)
#define is_free(line) (line->ltype==LFREE)
#define is_bound(line) (line->ltype==BOUND)
#define is_fanout(line) (line->outCount>1)
#define is_reachable_from_fault(line) (line->freach)
#define is_unspecified(line) (line->output==X)
#define is_justified(line) (line->changed)
#define is_unjustified(line) ((!line->changed)&&(line->output!=X))
#define is_D_propagated(line) (line->output==D || line->output==DBAR)
#define is_undetected(fault) (fault->detected==UNDETECTED)
#define is_detected(fault) (fault->detected==DETECTED)
#define is_redundant(fault) (fault->detected==REDUNDANT)
/* macros for tree operation */
#define current_node g_tree.list[g_tree.last]
#define is_flagged(node) node.flag
/* macros for multiple backtrace */
#define setline(line,n0,n1) line->numzero=n0; \
line->numone=n1
#define resetline(line) setline(line,0,0)
#define is_conflict(line) (line->numzero>0 && line->numone>0)
/********** Macros for memory menagement **********/
//extern char *malloc(), *calloc(), *realloc(); for windows
extern char *calloc(), * realloc();
#define MALLOC(type,number) \
(type *)malloc((unsigned)(sizeof(type)*(number)))
#define CALLOC(type,number) (type *)calloc((unsigned)(sizeof(type)),(unsigned)(number))
#define REALLOC(pointer,type,number) \
pointer = (type *)realloc((char *)pointer,((unsigned)sizeof(type),(unsigned)(number)))
#define MFREE(pointer) \
{ if((pointer)!=NULL) free((char *)pointer); }
#define FREE(pointer) \
{ if((pointer)!=NULL) free((char *)pointer); }
#define ALLOCATE(pointer,type,number) \
if((pointer=MALLOC(type,number))==NULL) printFatalError(MEMORYERROR)
#define CALLOCATE(pointer,type,number) \
if((pointer=CALLOC(type,number))==NULL) printFatalError(MEMORYERROR)
/************ Macros for hope ***************************/
/* macros handling the event list */
#define initEventList(h,t) \
{ ALLOCATE(t,EVENTTYPE,1); t->next=NULL; h=t; }
#define reseteventlist(h,t,var1) \
{ while(h!=t) { var1=h; h=h->next; FREE(var1); }
#define remove(elist) \
{ \
g_tailEvent->next=elist; \
elist=NULL; \
while(g_tailEvent->next!=NULL) \
g_tailEvent=g_tailEvent->next; \
}
#define create(e) \
{ if(g_headEvent==g_tailEvent) {ALLOCATE(e,EVENTTYPE,1); } else { e=g_headEvent; g_headEvent=g_headEvent->next; }}
#define setBit(word, p) (word | BITMASK[p])
#define resetBit(word, p) (word & (~BITMASK[p]))
#define checkBitIs0(word, p) ((word & BITMASK[p]) == ALL0)
#define setPairTo0(V0, V1) V0=ALL1; V1=ALL0
#define setPairTo1(V0, V1) V0=ALL0; V1=ALL1
#define setPairToX(V0, V1) V0=V1=ALL0
#define setPairToZ(V0, V1) V0=V1=ALL1
#define checkPair(V0, V1) ((V0==ALL1 && V1==ALL0) ? ZERO : \
(V0==ALL0 && V1==ALL1) ? ONE : \
(V0==ALL0 && V1==ALL0) ? X : Z)
/* Gate Evaluation */
#define FEVAL(gut,Val,j,v,temp,GGID) \
switch(gut->type) { \
case NOT: \
if(gut->inList[0]->Gid==GGID) { \
Val[0]=gut->inList[0]->FV[1]; \
Val[1]=gut->inList[0]->FV[0]; \
} else { \
Val[0]=gut->inList[0]->GV[1]; \
Val[1]=gut->inList[0]->GV[0]; \
} \
break; \
case AND: \
if(gut->inList[0]->Gid==GGID) { \
twoBitsCopy(Val,gut->inList[0]->FV); \
} else { twoBitsCopy(Val,gut->inList[0]->GV); } \
for(j=1;j<gut->inCount;j++) \
if(gut->inList[j]->Gid==GGID) { \
Val[0] |= gut->inList[j]->FV[0]; \
Val[1] &= gut->inList[j]->FV[1]; \
} else { \
Val[0] |= gut->inList[j]->GV[0]; \
Val[1] &= gut->inList[j]->GV[1]; \
} \
break; \
case NAND: \
if(gut->inList[0]->Gid==GGID) { \
twoBitsCopy(Val,gut->inList[0]->FV); \
} else { twoBitsCopy(Val,gut->inList[0]->GV); } \
for(j=1;j<gut->inCount;j++) \
if(gut->inList[j]->Gid==GGID) { \
Val[0] |= gut->inList[j]->FV[0]; \
Val[1] &= gut->inList[j]->FV[1]; \
} else { \
Val[0] |= gut->inList[j]->GV[0]; \
Val[1] &= gut->inList[j]->GV[1]; \
} \
v=Val[0]; Val[0]=Val[1]; Val[1]=v; \
break; \
case OR: \
if(gut->inList[0]->Gid==GGID) { \
twoBitsCopy(Val,gut->inList[0]->FV); \
} else { twoBitsCopy(Val,gut->inList[0]->GV); } \
for(j=1;j<gut->inCount;j++) \
if(gut->inList[j]->Gid==GGID) { \
Val[0] &= gut->inList[j]->FV[0]; \
Val[1] |= gut->inList[j]->FV[1]; \
} else { \
Val[0] &= gut->inList[j]->GV[0]; \
Val[1] |= gut->inList[j]->GV[1]; \
} \
break; \
case NOR: \
if(gut->inList[0]->Gid==GGID) { \
twoBitsCopy(Val,gut->inList[0]->FV); \
} else { twoBitsCopy(Val,gut->inList[0]->GV); } \
for(j=1;j<gut->inCount;j++) \
if(gut->inList[j]->Gid==GGID) { \
Val[0] &= gut->inList[j]->FV[0]; \
Val[1] |= gut->inList[j]->FV[1]; \
} else { \
Val[0] &= gut->inList[j]->GV[0]; \
Val[1] |= gut->inList[j]->GV[1]; \
} \
v=Val[0]; Val[0]=Val[1]; Val[1]=v; \
break; \
case XOR: \
if(gut->inList[0]->Gid==GGID) { \
twoBitsCopy(Val,gut->inList[0]->FV); \
} else { twoBitsCopy(Val,gut->inList[0]->GV); } \
for(j=1;j<gut->inCount;j++) { \
temp=gut->inList[j]; \
v=Val[0]; \
if(temp->Gid==GGID) { \
Val[0] = (v&temp->FV[0])|(Val[1]&temp->FV[1]); \
Val[1] = (Val[1]&temp->FV[0])|(v&temp->FV[1]); \
} else { \
Val[0] = (v&temp->GV[0])|(Val[1]&temp->GV[1]); \
Val[1] = (Val[1]&temp->GV[0])|(v&temp->GV[1]); \
} \
} break; \
case XNOR: \
if(gut->inList[0]->Gid==GGID) { \
twoBitsCopy(Val,gut->inList[0]->FV); \
} else { twoBitsCopy(Val,gut->inList[0]->GV); } \
for(j=1;j<gut->inCount;j++) { \
temp=gut->inList[j]; \
v=Val[0]; \
if(temp->Gid==GGID) { \
Val[0] = (v&temp->FV[0])|(Val[1]&temp->FV[1]); \
Val[1] = (Val[1]&temp->FV[0])|(v&temp->FV[1]); \
} else { \
Val[0] = (v&temp->GV[0])|(Val[1]&temp->GV[1]); \
Val[1] = (Val[1]&temp->GV[0])|(v&temp->GV[1]); \
} \
} \
v=Val[0]; Val[0]=Val[1]; Val[1]=v; \
break; \
case DUMMY: case PO: case BUFF: \
if(gut->inList[0]->Gid==GGID) { \
twoBitsCopy(Val,gut->inList[0]->FV); \
} else { twoBitsCopy(Val,gut->inList[0]->GV); } \
break; \
default: \
Faulty_Gate_Eval(gut,Val); \
break; \
}
#endif /* __ATALANTA_MACRO_H__ */