6 |
|
* Copyright 1996 Bernd Schmidt |
7 |
|
*/ |
8 |
|
|
9 |
+ |
#ifndef M68K_FLAGS_H |
10 |
+ |
#define M68K_FLAGS_H |
11 |
+ |
|
12 |
+ |
#ifdef OPTIMIZED_FLAGS |
13 |
+ |
|
14 |
|
#if defined(__i386__) && defined(X86_ASSEMBLY) |
15 |
|
|
16 |
+ |
#ifndef SAHF_SETO_PROFITABLE |
17 |
+ |
|
18 |
|
struct flag_struct { |
19 |
< |
unsigned int cznv; |
20 |
< |
unsigned int x; |
19 |
> |
uae_u32 cznv; |
20 |
> |
uae_u32 x; |
21 |
|
}; |
22 |
|
|
23 |
< |
#define SET_ZFLG(y) (regflags.cznv = (regflags.cznv & ~0x40) | (((y) & 1) << 6)) |
24 |
< |
#define SET_CFLG(y) (regflags.cznv = (regflags.cznv & ~1) | ((y) & 1)) |
25 |
< |
#define SET_VFLG(y) (regflags.cznv = (regflags.cznv & ~0x800) | (((y) & 1) << 11)) |
26 |
< |
#define SET_NFLG(y) (regflags.cznv = (regflags.cznv & ~0x80) | (((y) & 1) << 7)) |
27 |
< |
#define SET_XFLG(y) (regflags.x = (y)) |
28 |
< |
|
29 |
< |
#define GET_ZFLG ((regflags.cznv >> 6) & 1) |
30 |
< |
#define GET_CFLG (regflags.cznv & 1) |
31 |
< |
#define GET_VFLG ((regflags.cznv >> 11) & 1) |
32 |
< |
#define GET_NFLG ((regflags.cznv >> 7) & 1) |
33 |
< |
#define GET_XFLG (regflags.x & 1) |
23 |
> |
#define FLAGVAL_Z 0x40 |
24 |
> |
#define FLAGVAL_N 0x80 |
25 |
> |
|
26 |
> |
#define SET_ZFLG(y) (regflags.cznv = (regflags.cznv & ~0x40) | (((y) & 1) << 6)) |
27 |
> |
#define SET_CFLG(y) (regflags.cznv = (regflags.cznv & ~1) | ((y) & 1)) |
28 |
> |
#define SET_VFLG(y) (regflags.cznv = (regflags.cznv & ~0x800) | (((y) & 1) << 11)) |
29 |
> |
#define SET_NFLG(y) (regflags.cznv = (regflags.cznv & ~0x80) | (((y) & 1) << 7)) |
30 |
> |
#define SET_XFLG(y) (regflags.x = (y)) |
31 |
> |
|
32 |
> |
#define GET_ZFLG ((regflags.cznv >> 6) & 1) |
33 |
> |
#define GET_CFLG (regflags.cznv & 1) |
34 |
> |
#define GET_VFLG ((regflags.cznv >> 11) & 1) |
35 |
> |
#define GET_NFLG ((regflags.cznv >> 7) & 1) |
36 |
> |
#define GET_XFLG (regflags.x & 1) |
37 |
> |
|
38 |
> |
#define CLEAR_CZNV (regflags.cznv = 0) |
39 |
> |
#define GET_CZNV (regflags.cznv) |
40 |
> |
#define IOR_CZNV(X) (regflags.cznv |= (X)) |
41 |
> |
#define SET_CZNV(X) (regflags.cznv = (X)) |
42 |
|
|
43 |
< |
#define CLEAR_CZNV (regflags.cznv = 0) |
29 |
< |
#define COPY_CARRY (regflags.x = regflags.cznv) |
43 |
> |
#define COPY_CARRY (regflags.x = regflags.cznv) |
44 |
|
|
45 |
|
extern struct flag_struct regflags __asm__ ("regflags"); |
46 |
|
|
72 |
|
return 0; |
73 |
|
} |
74 |
|
|
75 |
< |
#define x86_flag_testl(v) \ |
76 |
< |
__asm__ __volatile__ ("testl %1,%1\n\t" \ |
75 |
> |
#define optflag_testl(v) \ |
76 |
> |
__asm__ __volatile__ ("andl %1,%1\n\t" \ |
77 |
|
"pushfl\n\t" \ |
78 |
|
"popl %0\n\t" \ |
79 |
|
: "=r" (regflags.cznv) : "r" (v) : "cc") |
80 |
|
|
81 |
< |
#define x86_flag_testw(v) \ |
82 |
< |
__asm__ __volatile__ ("testw %w1,%w1\n\t" \ |
81 |
> |
#define optflag_testw(v) \ |
82 |
> |
__asm__ __volatile__ ("andw %w1,%w1\n\t" \ |
83 |
|
"pushfl\n\t" \ |
84 |
|
"popl %0\n\t" \ |
85 |
|
: "=r" (regflags.cznv) : "r" (v) : "cc") |
86 |
|
|
87 |
< |
#define x86_flag_testb(v) \ |
88 |
< |
__asm__ __volatile__ ("testb %b1,%b1\n\t" \ |
87 |
> |
#define optflag_testb(v) \ |
88 |
> |
__asm__ __volatile__ ("andb %b1,%b1\n\t" \ |
89 |
|
"pushfl\n\t" \ |
90 |
|
"popl %0\n\t" \ |
91 |
|
: "=r" (regflags.cznv) : "q" (v) : "cc") |
92 |
|
|
93 |
< |
#define x86_flag_addl(v, s, d) do { \ |
93 |
> |
#define optflag_addl(v, s, d) do { \ |
94 |
|
__asm__ __volatile__ ("addl %k2,%k1\n\t" \ |
95 |
|
"pushfl\n\t" \ |
96 |
|
"popl %0\n\t" \ |
98 |
|
COPY_CARRY; \ |
99 |
|
} while (0) |
100 |
|
|
101 |
< |
#define x86_flag_addw(v, s, d) do { \ |
101 |
> |
#define optflag_addw(v, s, d) do { \ |
102 |
|
__asm__ __volatile__ ("addw %w2,%w1\n\t" \ |
103 |
|
"pushfl\n\t" \ |
104 |
|
"popl %0\n\t" \ |
106 |
|
COPY_CARRY; \ |
107 |
|
} while (0) |
108 |
|
|
109 |
< |
#define x86_flag_addb(v, s, d) do { \ |
109 |
> |
#define optflag_addb(v, s, d) do { \ |
110 |
|
__asm__ __volatile__ ("addb %b2,%b1\n\t" \ |
111 |
|
"pushfl\n\t" \ |
112 |
|
"popl %0\n\t" \ |
114 |
|
COPY_CARRY; \ |
115 |
|
} while (0) |
116 |
|
|
117 |
< |
#define x86_flag_subl(v, s, d) do { \ |
117 |
> |
#define optflag_subl(v, s, d) do { \ |
118 |
|
__asm__ __volatile__ ("subl %k2,%k1\n\t" \ |
119 |
|
"pushfl\n\t" \ |
120 |
|
"popl %0\n\t" \ |
122 |
|
COPY_CARRY; \ |
123 |
|
} while (0) |
124 |
|
|
125 |
< |
#define x86_flag_subw(v, s, d) do { \ |
125 |
> |
#define optflag_subw(v, s, d) do { \ |
126 |
|
__asm__ __volatile__ ("subw %w2,%w1\n\t" \ |
127 |
|
"pushfl\n\t" \ |
128 |
|
"popl %0\n\t" \ |
130 |
|
COPY_CARRY; \ |
131 |
|
} while (0) |
132 |
|
|
133 |
< |
#define x86_flag_subb(v, s, d) do { \ |
133 |
> |
#define optflag_subb(v, s, d) do { \ |
134 |
|
__asm__ __volatile__ ("subb %b2,%b1\n\t" \ |
135 |
|
"pushfl\n\t" \ |
136 |
|
"popl %0\n\t" \ |
138 |
|
COPY_CARRY; \ |
139 |
|
} while (0) |
140 |
|
|
141 |
< |
#define x86_flag_cmpl(s, d) \ |
141 |
> |
#define optflag_cmpl(s, d) \ |
142 |
|
__asm__ __volatile__ ("cmpl %k1,%k2\n\t" \ |
143 |
|
"pushfl\n\t" \ |
144 |
|
"popl %0\n\t" \ |
145 |
|
: "=r" (regflags.cznv) : "rmi" (s), "r" (d) : "cc") |
146 |
|
|
147 |
< |
#define x86_flag_cmpw(s, d) \ |
147 |
> |
#define optflag_cmpw(s, d) \ |
148 |
|
__asm__ __volatile__ ("cmpw %w1,%w2\n\t" \ |
149 |
|
"pushfl\n\t" \ |
150 |
|
"popl %0\n\t" \ |
151 |
|
: "=r" (regflags.cznv) : "rmi" (s), "r" (d) : "cc") |
152 |
|
|
153 |
< |
#define x86_flag_cmpb(s, d) \ |
153 |
> |
#define optflag_cmpb(s, d) \ |
154 |
|
__asm__ __volatile__ ("cmpb %b1,%b2\n\t" \ |
155 |
|
"pushfl\n\t" \ |
156 |
|
"popl %0\n\t" \ |
157 |
|
: "=r" (regflags.cznv) : "qmi" (s), "q" (d) : "cc") |
158 |
|
|
159 |
< |
#elif defined(__sparc__) && (defined(SPARC_V8_ASSEMBLY) || defined(SPARC_V9_ASSEMBLY)) |
159 |
> |
#else |
160 |
|
|
161 |
|
struct flag_struct { |
162 |
< |
union { |
163 |
< |
unsigned short all; |
150 |
< |
unsigned char bytes[2]; |
151 |
< |
}; |
162 |
> |
uae_u32 cznv; |
163 |
> |
uae_u32 x; |
164 |
|
}; |
165 |
|
|
166 |
< |
typedef unsigned short * flags_addr; |
167 |
< |
extern struct flag_struct regflags; |
156 |
< |
#define M68K_FLAGS_ADDR ((flags_addr)(®flags.all)) |
157 |
< |
#define M68K_FLAGS_NZVC regflags.bytes[1] |
158 |
< |
#define M68K_FLAGS_X regflags.bytes[0] |
166 |
> |
#define FLAGVAL_Z 0x4000 |
167 |
> |
#define FLAGVAL_N 0x8000 |
168 |
|
|
169 |
< |
#if 0 |
169 |
> |
#define SET_ZFLG(y) (regflags.cznv = (regflags.cznv & ~0x4000) | (((y) & 1) << 14)) |
170 |
> |
#define SET_CFLG(y) (regflags.cznv = (regflags.cznv & ~0x100) | (((y) & 1) << 8)) |
171 |
> |
#define SET_VFLG(y) (regflags.cznv = (regflags.cznv & ~0x1) | (((y) & 1))) |
172 |
> |
#define SET_NFLG(y) (regflags.cznv = (regflags.cznv & ~0x8000) | (((y) & 1) << 15)) |
173 |
> |
#define SET_XFLG(y) (regflags.x = (y)) |
174 |
> |
|
175 |
> |
#define GET_ZFLG ((regflags.cznv >> 14) & 1) |
176 |
> |
#define GET_CFLG ((regflags.cznv >> 8) & 1) |
177 |
> |
#define GET_VFLG ((regflags.cznv >> 0) & 1) |
178 |
> |
#define GET_NFLG ((regflags.cznv >> 15) & 1) |
179 |
> |
#define GET_XFLG (regflags.x & 1) |
180 |
> |
|
181 |
> |
#define CLEAR_CZNV (regflags.cznv = 0) |
182 |
> |
#define GET_CZNV (regflags.cznv) |
183 |
> |
#define IOR_CZNV(X) (regflags.cznv |= (X)) |
184 |
> |
#define SET_CZNV(X) (regflags.cznv = (X)) |
185 |
|
|
186 |
< |
#define SET_ZFLG(y) (M68K_FLAGS_NZVC = (M68K_FLAGS_NZVC & ~0x01) | ((y) & 1)) |
163 |
< |
#define SET_CFLG(y) (M68K_FLAGS_NZVC = (M68K_FLAGS_NZVC & ~0x02) | (((y) & 1) << 1)) |
164 |
< |
#define SET_XFLG(y) (M68K_FLAGS_X = ((y) & 1) << 1) |
165 |
< |
#define SET_VFLG(y) (M68K_FLAGS_NZVC = (M68K_FLAGS_NZVC & ~0x10) | (((y) & 1) << 4)) |
166 |
< |
#define SET_NFLG(y) (M68K_FLAGS_NZVC = (M68K_FLAGS_NZVC & ~0x80) | (((y) & 1) << 7)) |
167 |
< |
|
168 |
< |
#define GET_ZFLG (M68K_FLAGS_NZVC & 1) |
169 |
< |
#define GET_CFLG ((M68K_FLAGS_NZVC >> 1) & 1) |
170 |
< |
#define GET_XFLG ((M68K_FLAGS_X >> 1) & 1) |
171 |
< |
#define GET_VFLG ((M68K_FLAGS_NZVC >> 4) & 1) |
172 |
< |
#define GET_NFLG ((M68K_FLAGS_NZVC >> 7) & 1) |
186 |
> |
#define COPY_CARRY (regflags.x = (regflags.cznv)>>8) |
187 |
|
|
188 |
< |
#define CLEAR_CZNV (M68K_FLAGS_NZVC = 0) |
175 |
< |
#define COPY_CARRY (M68K_FLAGS_X = M68K_FLAGS_NZVC) |
188 |
> |
extern struct flag_struct regflags __asm__ ("regflags"); |
189 |
|
|
190 |
< |
#else |
190 |
> |
static __inline__ int cctrue(int cc) |
191 |
> |
{ |
192 |
> |
uae_u32 cznv = regflags.cznv; |
193 |
> |
switch(cc){ |
194 |
> |
case 0: return 1; /* T */ |
195 |
> |
case 1: return 0; /* F */ |
196 |
> |
case 2: return (cznv & 0x4100) == 0; /* !GET_CFLG && !GET_ZFLG; HI */ |
197 |
> |
case 3: return (cznv & 0x4100) != 0; /* GET_CFLG || GET_ZFLG; LS */ |
198 |
> |
case 4: return (cznv & 0x100) == 0; /* !GET_CFLG; CC */ |
199 |
> |
case 5: return (cznv & 0x100) != 0; /* GET_CFLG; CS */ |
200 |
> |
case 6: return (cznv & 0x4000) == 0; /* !GET_ZFLG; NE */ |
201 |
> |
case 7: return (cznv & 0x4000) != 0; /* GET_ZFLG; EQ */ |
202 |
> |
case 8: return (cznv & 0x01) == 0; /* !GET_VFLG; VC */ |
203 |
> |
case 9: return (cznv & 0x01) != 0; /* GET_VFLG; VS */ |
204 |
> |
case 10:return (cznv & 0x8000) == 0; /* !GET_NFLG; PL */ |
205 |
> |
case 11:return (cznv & 0x8000) != 0; /* GET_NFLG; MI */ |
206 |
> |
case 12:return (((cznv << 15) ^ cznv) & 0x8000) == 0; /* GET_NFLG == GET_VFLG; GE */ |
207 |
> |
case 13:return (((cznv << 15) ^ cznv) & 0x8000) != 0;/* GET_NFLG != GET_VFLG; LT */ |
208 |
> |
case 14: |
209 |
> |
cznv &= 0xc001; |
210 |
> |
return (((cznv << 15) ^ cznv) & 0xc000) == 0; /* !GET_ZFLG && (GET_NFLG == GET_VFLG); GT */ |
211 |
> |
case 15: |
212 |
> |
cznv &= 0xc001; |
213 |
> |
return (((cznv << 15) ^ cznv) & 0xc000) != 0; /* GET_ZFLG || (GET_NFLG != GET_VFLG); LE */ |
214 |
> |
} |
215 |
> |
abort(); |
216 |
> |
return 0; |
217 |
> |
} |
218 |
> |
|
219 |
> |
/* Is there any way to do this without declaring *all* memory clobbered? |
220 |
> |
I.e. any way to tell gcc that some byte-sized value is in %al? */ |
221 |
> |
#define optflag_testl(v) \ |
222 |
> |
__asm__ __volatile__ ("andl %0,%0\n\t" \ |
223 |
> |
"lahf\n\t" \ |
224 |
> |
"seto %%al\n\t" \ |
225 |
> |
"movb %%al,regflags\n\t" \ |
226 |
> |
"movb %%ah,regflags+1\n\t" \ |
227 |
> |
: : "r" (v) : "%eax","cc","memory") |
228 |
> |
|
229 |
> |
#define optflag_testw(v) \ |
230 |
> |
__asm__ __volatile__ ("andw %w0,%w0\n\t" \ |
231 |
> |
"lahf\n\t" \ |
232 |
> |
"seto %%al\n\t" \ |
233 |
> |
"movb %%al,regflags\n\t" \ |
234 |
> |
"movb %%ah,regflags+1\n\t" \ |
235 |
> |
: : "r" (v) : "%eax","cc","memory") |
236 |
> |
|
237 |
> |
#define optflag_testb(v) \ |
238 |
> |
__asm__ __volatile__ ("andb %b0,%b0\n\t" \ |
239 |
> |
"lahf\n\t" \ |
240 |
> |
"seto %%al\n\t" \ |
241 |
> |
"movb %%al,regflags\n\t" \ |
242 |
> |
"movb %%ah,regflags+1\n\t" \ |
243 |
> |
: : "q" (v) : "%eax","cc","memory") |
244 |
> |
|
245 |
> |
#define optflag_addl(v, s, d) do { \ |
246 |
> |
__asm__ __volatile__ ("addl %k1,%k0\n\t" \ |
247 |
> |
"lahf\n\t" \ |
248 |
> |
"seto %%al\n\t" \ |
249 |
> |
"movb %%al,regflags\n\t" \ |
250 |
> |
"movb %%ah,regflags+1\n\t" \ |
251 |
> |
: "=r" (v) : "rmi" (s), "0" (d) : "%eax","cc","memory"); \ |
252 |
> |
COPY_CARRY; \ |
253 |
> |
} while (0) |
254 |
> |
|
255 |
> |
#define optflag_addw(v, s, d) do { \ |
256 |
> |
__asm__ __volatile__ ("addw %w1,%w0\n\t" \ |
257 |
> |
"lahf\n\t" \ |
258 |
> |
"seto %%al\n\t" \ |
259 |
> |
"movb %%al,regflags\n\t" \ |
260 |
> |
"movb %%ah,regflags+1\n\t" \ |
261 |
> |
: "=r" (v) : "rmi" (s), "0" (d) : "%eax","cc","memory"); \ |
262 |
> |
COPY_CARRY; \ |
263 |
> |
} while (0) |
264 |
> |
|
265 |
> |
#define optflag_addb(v, s, d) do { \ |
266 |
> |
__asm__ __volatile__ ("addb %b1,%b0\n\t" \ |
267 |
> |
"lahf\n\t" \ |
268 |
> |
"seto %%al\n\t" \ |
269 |
> |
"movb %%al,regflags\n\t" \ |
270 |
> |
"movb %%ah,regflags+1\n\t" \ |
271 |
> |
: "=q" (v) : "qmi" (s), "0" (d) : "%eax","cc","memory"); \ |
272 |
> |
COPY_CARRY; \ |
273 |
> |
} while (0) |
274 |
> |
|
275 |
> |
#define optflag_subl(v, s, d) do { \ |
276 |
> |
__asm__ __volatile__ ("subl %k1,%k0\n\t" \ |
277 |
> |
"lahf\n\t" \ |
278 |
> |
"seto %%al\n\t" \ |
279 |
> |
"movb %%al,regflags\n\t" \ |
280 |
> |
"movb %%ah,regflags+1\n\t" \ |
281 |
> |
: "=r" (v) : "rmi" (s), "0" (d) : "%eax","cc","memory"); \ |
282 |
> |
COPY_CARRY; \ |
283 |
> |
} while (0) |
284 |
|
|
285 |
< |
#define M68K_FLAGS_ALL regflags.all |
285 |
> |
#define optflag_subw(v, s, d) do { \ |
286 |
> |
__asm__ __volatile__ ("subw %w1,%w0\n\t" \ |
287 |
> |
"lahf\n\t" \ |
288 |
> |
"seto %%al\n\t" \ |
289 |
> |
"movb %%al,regflags\n\t" \ |
290 |
> |
"movb %%ah,regflags+1\n\t" \ |
291 |
> |
: "=r" (v) : "rmi" (s), "0" (d) : "%eax","cc","memory"); \ |
292 |
> |
COPY_CARRY; \ |
293 |
> |
} while (0) |
294 |
|
|
295 |
< |
#define SET_ZFLG(y) (M68K_FLAGS_ALL = (M68K_FLAGS_ALL & ~0x01) | ((y) & 1)) |
296 |
< |
#define SET_CFLG(y) (M68K_FLAGS_ALL = (M68K_FLAGS_ALL & ~0x02) | (((y) & 1) << 1)) |
297 |
< |
#define SET_XFLG(y) (M68K_FLAGS_ALL = (M68K_FLAGS_ALL & ~0x200)| (((y) & 1) << 9)) |
298 |
< |
#define SET_VFLG(y) (M68K_FLAGS_ALL = (M68K_FLAGS_ALL & ~0x10) | (((y) & 1) << 4)) |
299 |
< |
#define SET_NFLG(y) (M68K_FLAGS_ALL = (M68K_FLAGS_ALL & ~0x80) | (((y) & 1) << 7)) |
300 |
< |
|
301 |
< |
#define GET_ZFLG (M68K_FLAGS_ALL & 1) |
302 |
< |
#define GET_CFLG ((M68K_FLAGS_ALL >> 1) & 1) |
303 |
< |
#define GET_XFLG ((M68K_FLAGS_ALL >> 9) & 1) |
190 |
< |
#define GET_VFLG ((M68K_FLAGS_ALL >> 4) & 1) |
191 |
< |
#define GET_NFLG ((M68K_FLAGS_ALL >> 7) & 1) |
295 |
> |
#define optflag_subb(v, s, d) do { \ |
296 |
> |
__asm__ __volatile__ ("subb %b1,%b0\n\t" \ |
297 |
> |
"lahf\n\t" \ |
298 |
> |
"seto %%al\n\t" \ |
299 |
> |
"movb %%al,regflags\n\t" \ |
300 |
> |
"movb %%ah,regflags+1\n\t" \ |
301 |
> |
: "=q" (v) : "qmi" (s), "0" (d) : "%eax","cc","memory"); \ |
302 |
> |
COPY_CARRY; \ |
303 |
> |
} while (0) |
304 |
|
|
305 |
< |
#define CLEAR_CZNV (M68K_FLAGS_NZVC = 0) |
306 |
< |
#define COPY_CARRY (M68K_FLAGS_X = M68K_FLAGS_NZVC) |
305 |
> |
#define optflag_cmpl(s, d) \ |
306 |
> |
__asm__ __volatile__ ("cmpl %k0,%k1\n\t" \ |
307 |
> |
"lahf\n\t" \ |
308 |
> |
"seto %%al\n\t" \ |
309 |
> |
"movb %%al,regflags\n\t" \ |
310 |
> |
"movb %%ah,regflags+1\n\t" \ |
311 |
> |
: : "rmi" (s), "r" (d) : "%eax","cc","memory") |
312 |
> |
|
313 |
> |
#define optflag_cmpw(s, d) \ |
314 |
> |
__asm__ __volatile__ ("cmpw %w0,%w1\n\t" \ |
315 |
> |
"lahf\n\t" \ |
316 |
> |
"seto %%al\n\t" \ |
317 |
> |
"movb %%al,regflags\n\t" \ |
318 |
> |
"movb %%ah,regflags+1\n\t" \ |
319 |
> |
: : "rmi" (s), "r" (d) : "%eax","cc","memory"); |
320 |
> |
|
321 |
> |
#define optflag_cmpb(s, d) \ |
322 |
> |
__asm__ __volatile__ ("cmpb %b0,%b1\n\t" \ |
323 |
> |
"lahf\n\t" \ |
324 |
> |
"seto %%al\n\t" \ |
325 |
> |
"movb %%al,regflags\n\t" \ |
326 |
> |
"movb %%ah,regflags+1\n\t" \ |
327 |
> |
: : "qmi" (s), "q" (d) : "%eax","cc","memory") |
328 |
|
|
329 |
|
#endif |
330 |
|
|
331 |
+ |
#elif defined(__sparc__) && (defined(SPARC_V8_ASSEMBLY) || defined(SPARC_V9_ASSEMBLY)) |
332 |
+ |
|
333 |
+ |
struct flag_struct { |
334 |
+ |
unsigned char nzvc; |
335 |
+ |
unsigned char x; |
336 |
+ |
}; |
337 |
+ |
|
338 |
+ |
extern struct flag_struct regflags; |
339 |
+ |
|
340 |
+ |
#define FLAGVAL_Z 0x04 |
341 |
+ |
#define FLAGVAL_N 0x08 |
342 |
+ |
|
343 |
+ |
#define SET_ZFLG(y) (regflags.nzvc = (regflags.nzvc & ~0x04) | (((y) & 1) << 2)) |
344 |
+ |
#define SET_CFLG(y) (regflags.nzvc = (regflags.nzvc & ~1) | ((y) & 1)) |
345 |
+ |
#define SET_VFLG(y) (regflags.nzvc = (regflags.nzvc & ~0x02) | (((y) & 1) << 1)) |
346 |
+ |
#define SET_NFLG(y) (regflags.nzvc = (regflags.nzvc & ~0x08) | (((y) & 1) << 3)) |
347 |
+ |
#define SET_XFLG(y) (regflags.x = (y)) |
348 |
+ |
|
349 |
+ |
#define GET_ZFLG ((regflags.nzvc >> 2) & 1) |
350 |
+ |
#define GET_CFLG (regflags.nzvc & 1) |
351 |
+ |
#define GET_VFLG ((regflags.nzvc >> 1) & 1) |
352 |
+ |
#define GET_NFLG ((regflags.nzvc >> 3) & 1) |
353 |
+ |
#define GET_XFLG (regflags.x & 1) |
354 |
+ |
|
355 |
+ |
#define CLEAR_CZNV (regflags.nzvc = 0) |
356 |
+ |
#define GET_CZNV (reflags.nzvc) |
357 |
+ |
#define IOR_CZNV(X) (refglags.nzvc |= (X)) |
358 |
+ |
#define SET_CZNV(X) (regflags.nzvc = (X)) |
359 |
+ |
|
360 |
+ |
#define COPY_CARRY (regflags.x = regflags.nzvc) |
361 |
+ |
|
362 |
|
static __inline__ int cctrue(int cc) |
363 |
|
{ |
364 |
< |
uae_u32 nzvc = M68K_FLAGS_NZVC; |
364 |
> |
uae_u32 nzvc = regflags.nzvc; |
365 |
|
switch(cc){ |
366 |
< |
case 0: return 1; /* T */ |
367 |
< |
case 1: return 0; /* F */ |
368 |
< |
case 2: return (nzvc & 0x03) == 0; /* !GET_CFLG && !GET_ZFLG; HI */ |
369 |
< |
case 3: return (nzvc & 0x03) != 0; /* GET_CFLG || GET_ZFLG; LS */ |
370 |
< |
case 4: return (nzvc & 0x02) == 0; /* !GET_CFLG; CC */ |
371 |
< |
case 5: return (nzvc & 0x02) != 0; /* GET_CFLG; CS */ |
372 |
< |
case 6: return (nzvc & 0x01) == 0; /* !GET_ZFLG; NE */ |
373 |
< |
case 7: return (nzvc & 0x01) != 0; /* GET_ZFLG; EQ */ |
374 |
< |
case 8: return (nzvc & 0x10) == 0; /* !GET_VFLG; VC */ |
375 |
< |
case 9: return (nzvc & 0x10) != 0; /* GET_VFLG; VS */ |
376 |
< |
case 10:return (nzvc & 0x80) == 0; /* !GET_NFLG; PL */ |
377 |
< |
case 11:return (nzvc & 0x80) != 0; /* GET_NFLG; MI */ |
378 |
< |
case 12:return (((nzvc << 3) ^ nzvc) & 0x80) == 0; /* GET_NFLG == GET_VFLG; GE */ |
379 |
< |
case 13:return (((nzvc << 3) ^ nzvc) & 0x80) != 0; /* GET_NFLG != GET_VFLG; LT */ |
366 |
> |
case 0: return 1; /* T */ |
367 |
> |
case 1: return 0; /* F */ |
368 |
> |
case 2: return (nzvc & 0x05) == 0; /* !GET_CFLG && !GET_ZFLG; HI */ |
369 |
> |
case 3: return (nzvc & 0x05) != 0; /* GET_CFLG || GET_ZFLG; LS */ |
370 |
> |
case 4: return (nzvc & 1) == 0; /* !GET_CFLG; CC */ |
371 |
> |
case 5: return (nzvc & 1) != 0; /* GET_CFLG; CS */ |
372 |
> |
case 6: return (nzvc & 0x04) == 0; /* !GET_ZFLG; NE */ |
373 |
> |
case 7: return (nzvc & 0x04) != 0; /* GET_ZFLG; EQ */ |
374 |
> |
case 8: return (nzvc & 0x02) == 0;/* !GET_VFLG; VC */ |
375 |
> |
case 9: return (nzvc & 0x02) != 0;/* GET_VFLG; VS */ |
376 |
> |
case 10:return (nzvc & 0x08) == 0; /* !GET_NFLG; PL */ |
377 |
> |
case 11:return (nzvc & 0x08) != 0; /* GET_NFLG; MI */ |
378 |
> |
case 12:return (((nzvc << 2) ^ nzvc) & 0x08) == 0; /* GET_NFLG == GET_VFLG; GE */ |
379 |
> |
case 13:return (((nzvc << 2) ^ nzvc) & 0x08) != 0;/* GET_NFLG != GET_VFLG; LT */ |
380 |
|
case 14: |
381 |
< |
/* N--V--CZ shifted by 3 leads to V--CZ--- */ |
382 |
< |
return (((nzvc << 3) ^ nzvc) & 0x88) == 0; /* !GET_ZFLG && (GET_NFLG == GET_VFLG); GT */ |
381 |
> |
nzvc &= 0x0e; |
382 |
> |
return (((nzvc << 2) ^ nzvc) & 0x0c) == 0; /* !GET_ZFLG && (GET_NFLG == GET_VFLG); GT */ |
383 |
|
case 15: |
384 |
< |
return (((nzvc << 3) ^ nzvc) & 0x88) != 0; /* GET_ZFLG || (GET_NFLG != GET_VFLG); LE */ |
384 |
> |
nzvc &= 0x0e; |
385 |
> |
return (((nzvc << 2) ^ nzvc) & 0x0c) != 0; /* GET_ZFLG || (GET_NFLG != GET_VFLG); LE */ |
386 |
|
} |
387 |
|
return 0; |
388 |
|
} |
389 |
|
|
390 |
|
#ifdef SPARC_V8_ASSEMBLY |
391 |
|
|
392 |
< |
static inline char *str_flags(void) |
228 |
< |
{ |
229 |
< |
static char str[8]; |
230 |
< |
sprintf(str, "%c%c%c%c%c", |
231 |
< |
GET_XFLG ? 'X' : '-', |
232 |
< |
GET_NFLG ? 'N' : '-', |
233 |
< |
GET_ZFLG ? 'Z' : '-', |
234 |
< |
GET_VFLG ? 'V' : '-', |
235 |
< |
GET_CFLG ? 'C' : '-' |
236 |
< |
); |
237 |
< |
return str; |
238 |
< |
} |
239 |
< |
|
240 |
< |
static inline uae_u32 sparc_v8_flag_add_8(flags_addr pflags, uae_u32 src, uae_u32 dst) |
392 |
> |
static inline uae_u32 sparc_v8_flag_add_8(flag_struct *flags, uae_u32 src, uae_u32 dst) |
393 |
|
{ |
394 |
|
uae_u32 value; |
395 |
|
__asm__ ("\n" |
396 |
|
" sll %2, 24, %%o0\n" |
397 |
|
" sll %3, 24, %%o1\n" |
398 |
|
" addcc %%o0, %%o1, %%o0\n" |
399 |
< |
" subx %%g0, %%g0, %%o1\n" |
400 |
< |
" srl %%o0, 24, %0 ! 8-bit result\n" |
401 |
< |
" and %%o1, 0x202, %%o1 ! X, C flags\n" |
402 |
< |
" and %0, 0x80, %%o0\n" |
403 |
< |
" or %%o1, %%o0, %%o1 ! N flag\n" |
404 |
< |
" subcc %%g0, %0, %%g0\n" |
405 |
< |
" subx %%o1, -1, %%o1 ! Z flag\n" |
399 |
> |
" addx %%g0, %%g0, %%o1 ! X,C flags\n" |
400 |
> |
" srl %%o0, 24, %0\n" |
401 |
> |
" stb %%o1, [%1 + 1]\n" |
402 |
> |
" bl,a .+8\n" |
403 |
> |
" or %%o1, 0x08, %%o1 ! N flag\n" |
404 |
> |
" bz,a .+8\n" |
405 |
> |
" or %%o1, 0x04, %%o1 ! Z flag\n" |
406 |
|
" bvs,a .+8\n" |
407 |
< |
" or %%o1, 0x10, %%o1 ! V flag\n" |
408 |
< |
" sth %%o1, [%1]\n" |
407 |
> |
" or %%o1, 0x02, %%o1 ! V flag\n" |
408 |
> |
" stb %%o1, [%1]\n" |
409 |
|
: "=&r" (value) |
410 |
< |
: "r" (pflags), "r" (dst), "r" (src), "0" (value) |
410 |
> |
: "r" (flags), "r" (dst), "r" (src) |
411 |
|
: "cc", "o0", "o1" |
412 |
|
); |
261 |
– |
|
262 |
– |
// printf("%d + %d = %d (flags = %s)\n", dst, src, value, str_flags()); |
413 |
|
return value; |
414 |
|
} |
415 |
|
|
416 |
< |
static inline uae_u32 sparc_v8_flag_add_16(flags_addr pflags, uae_u32 src, uae_u32 dst) |
416 |
> |
static inline uae_u32 sparc_v8_flag_add_16(flag_struct *flags, uae_u32 src, uae_u32 dst) |
417 |
|
{ |
418 |
|
uae_u32 value; |
419 |
|
__asm__ ("\n" |
420 |
|
" sll %2, 16, %%o0\n" |
421 |
|
" sll %3, 16, %%o1\n" |
422 |
|
" addcc %%o0, %%o1, %%o0\n" |
423 |
< |
" subx %%g0, %%g0, %%o1\n" |
424 |
< |
" srl %%o0, 16, %0 ! 16-bit result\n" |
425 |
< |
" and %%o1, 0x202, %%o1 ! X, C flags\n" |
426 |
< |
" sra %%o0, 24, %%o0\n" |
427 |
< |
" and %%o0, 0x80, %%o0\n" |
428 |
< |
" or %%o1, %%o0, %%o1 ! N flag\n" |
429 |
< |
" subcc %%g0, %0, %%g0\n" |
280 |
< |
" subx %%o1, -1, %%o1 ! Z flag\n" |
423 |
> |
" addx %%g0, %%g0, %%o1 ! X,C flags\n" |
424 |
> |
" srl %%o0, 16, %0\n" |
425 |
> |
" stb %%o1, [%1 + 1]\n" |
426 |
> |
" bl,a .+8\n" |
427 |
> |
" or %%o1, 0x08, %%o1 ! N flag\n" |
428 |
> |
" bz,a .+8\n" |
429 |
> |
" or %%o1, 0x04, %%o1 ! Z flag\n" |
430 |
|
" bvs,a .+8\n" |
431 |
< |
" or %%o1, 0x10, %%o1 ! V flag\n" |
432 |
< |
" sth %%o1, [%1]\n" |
431 |
> |
" or %%o1, 0x02, %%o1 ! V flag\n" |
432 |
> |
" stb %%o1, [%1]\n" |
433 |
|
: "=&r" (value) |
434 |
< |
: "r" (pflags), "r" (dst), "r" (src), "0" (value) |
434 |
> |
: "r" (flags), "r" (dst), "r" (src) |
435 |
|
: "cc", "o0", "o1" |
436 |
|
); |
437 |
|
return value; |
438 |
|
} |
439 |
|
|
440 |
< |
static inline uae_u32 sparc_v8_flag_add_32(flags_addr pflags, uae_u32 src, uae_u32 dst) |
440 |
> |
static inline uae_u32 sparc_v8_flag_add_32(flag_struct *flags, uae_u32 src, uae_u32 dst) |
441 |
|
{ |
442 |
|
uae_u32 value; |
443 |
|
__asm__ ("\n" |
444 |
|
" addcc %2, %3, %0\n" |
445 |
< |
" subx %%g0, %%g0, %%o0\n" |
446 |
< |
" sra %0, 24, %%o1\n" |
447 |
< |
" and %%o0, 0x202, %%o0 ! X, C flags\n" |
448 |
< |
" and %%o1, 0x80, %%o1\n" |
449 |
< |
" or %%o0, %%o1, %%o0 ! N flag\n" |
450 |
< |
" subcc %%g0, %0, %%g0\n" |
302 |
< |
" subx %%o0, -1, %%o0 ! Z flag\n" |
445 |
> |
" addx %%g0, %%g0, %%o0 ! X,C flags\n" |
446 |
> |
" stb %%o0, [%1 + 1]\n" |
447 |
> |
" bl,a .+8\n" |
448 |
> |
" or %%o0, 0x08, %%o0 ! N flag\n" |
449 |
> |
" bz,a .+8\n" |
450 |
> |
" or %%o0, 0x04, %%o0 ! Z flag\n" |
451 |
|
" bvs,a .+8\n" |
452 |
< |
" or %%o0, 0x10, %%o0 ! V flag\n" |
453 |
< |
" sth %%o0, [%1]\n" |
452 |
> |
" or %%o0, 0x02, %%o0 ! V flag\n" |
453 |
> |
" stb %%o0, [%1]\n" |
454 |
|
: "=&r" (value) |
455 |
< |
: "r" (pflags), "r" (dst), "r" (src), "0" (value) |
456 |
< |
: "cc", "o0", "o1" |
455 |
> |
: "r" (flags), "r" (dst), "r" (src) |
456 |
> |
: "cc", "o0" |
457 |
|
); |
458 |
|
return value; |
459 |
|
} |
587 |
|
); |
588 |
|
} |
589 |
|
|
590 |
+ |
static inline uae_u32 sparc_v8_flag_addx_8(flag_struct *flags, uae_u32 src, uae_u32 dst) |
591 |
+ |
{ |
592 |
+ |
uae_u32 value; |
593 |
+ |
__asm__ ("\n" |
594 |
+ |
" ldub [%1 + 1], %%o1 ! Get the X Flag\n" |
595 |
+ |
" subcc %%g0, %%o1, %%g0 ! Set the SPARC carry flag, if X set\n" |
596 |
+ |
" addxcc %2, %3, %0\n" |
597 |
+ |
: "=&r" (value) |
598 |
+ |
: "r" (flags), "r" (dst), "r" (src) |
599 |
+ |
: "cc", "o0", "o1" |
600 |
+ |
); |
601 |
+ |
return value; |
602 |
+ |
} |
603 |
+ |
|
604 |
+ |
#if 0 |
605 |
+ |
VERY SLOW... |
606 |
+ |
static inline uae_u32 sparc_v8_flag_addx_8(flag_struct *flags, uae_u32 src, uae_u32 dst) |
607 |
+ |
{ |
608 |
+ |
uae_u32 value; |
609 |
+ |
__asm__ ("\n" |
610 |
+ |
" sll %2, 24, %%o0\n" |
611 |
+ |
" sll %3, 24, %%o1\n" |
612 |
+ |
" addcc %%o0, %%o1, %%o0\n" |
613 |
+ |
" addx %%g0, %%g0, %%o1 ! X,C flags\n" |
614 |
+ |
" bvs,a .+8\n" |
615 |
+ |
" or %%o1, 0x02, %%o1 ! V flag\n" |
616 |
+ |
" ldub [%1 + 1], %%o2\n" |
617 |
+ |
" subcc %%g0, %%o2, %%g0\n" |
618 |
+ |
" addx %%g0, %%g0, %%o2\n" |
619 |
+ |
" sll %%o2, 24, %%o2\n" |
620 |
+ |
" addcc %%o0, %%o2, %%o0\n" |
621 |
+ |
" srl %%o0, 24, %0\n" |
622 |
+ |
" addx %%g0, %%g0, %%o2\n" |
623 |
+ |
" or %%o1, %%o2, %%o1 ! update X,C flags\n" |
624 |
+ |
" bl,a .+8\n" |
625 |
+ |
" or %%o1, 0x08, %%o1 ! N flag\n" |
626 |
+ |
" ldub [%1], %%o0 ! retreive the old NZVC flags (XXX)\n" |
627 |
+ |
" bvs,a .+8\n" |
628 |
+ |
" or %%o1, 0x02, %%o1 ! update V flag\n" |
629 |
+ |
" and %%o0, 0x04, %%o0 ! (XXX) but keep only Z flag\n" |
630 |
+ |
" and %%o1, 1, %%o2 ! keep C flag in %%o2\n" |
631 |
+ |
" bnz,a .+8\n" |
632 |
+ |
" or %%g0, %%g0, %%o0 ! Z flag cleared if non-zero result\n" |
633 |
+ |
" stb %%o2, [%1 + 1] ! store the X flag\n" |
634 |
+ |
" or %%o1, %%o0, %%o1\n" |
635 |
+ |
" stb %%o1, [%1]\n" |
636 |
+ |
: "=&r" (value) |
637 |
+ |
: "r" (flags), "r" (dst), "r" (src) |
638 |
+ |
: "cc", "o0", "o1", "o2" |
639 |
+ |
); |
640 |
+ |
return value; |
641 |
+ |
} |
642 |
+ |
#endif |
643 |
+ |
|
644 |
+ |
static inline uae_u32 sparc_v8_flag_addx_32(flag_struct *flags, uae_u32 src, uae_u32 dst) |
645 |
+ |
{ |
646 |
+ |
uae_u32 value; |
647 |
+ |
__asm__ ("\n" |
648 |
+ |
" ldub [%1 + 1], %%o0 ! Get the X Flag\n" |
649 |
+ |
" subcc %%g0, %%o0, %%g0 ! Set the SPARC carry flag, if X set\n" |
650 |
+ |
" addxcc %2, %3, %0\n" |
651 |
+ |
" ldub [%1], %%o0 ! retreive the old NZVC flags\n" |
652 |
+ |
" and %%o0, 0x04, %%o0 ! but keep only Z flag\n" |
653 |
+ |
" addx %%o0, %%g0, %%o0 ! X,C flags\n" |
654 |
+ |
" bl,a .+8\n" |
655 |
+ |
" or %%o0, 0x08, %%o0 ! N flag\n" |
656 |
+ |
" bvs,a .+8\n" |
657 |
+ |
" or %%o0, 0x02, %%o0 ! V flag\n" |
658 |
+ |
" bnz,a .+8\n" |
659 |
+ |
" and %%o0, 0x0B, %%o0 ! Z flag cleared if result is non-zero\n" |
660 |
+ |
" stb %%o0, [%1]\n" |
661 |
+ |
" stb %%o0, [%1 + 1]\n" |
662 |
+ |
: "=&r" (value) |
663 |
+ |
: "r" (flags), "r" (dst), "r" (src) |
664 |
+ |
: "cc", "o0" |
665 |
+ |
); |
666 |
+ |
return value; |
667 |
+ |
} |
668 |
+ |
|
669 |
|
#endif /* SPARC_V8_ASSEMBLY */ |
670 |
|
|
671 |
|
#ifdef SPARC_V9_ASSEMBLY |
980 |
|
|
981 |
|
#endif /* SPARC_V9_ASSEMBLY */ |
982 |
|
|
983 |
+ |
#endif |
984 |
+ |
|
985 |
|
#else |
986 |
|
|
987 |
|
struct flag_struct { |
1000 |
|
#define VFLG (regflags.v) |
1001 |
|
#define XFLG (regflags.x) |
1002 |
|
|
1003 |
+ |
#define SET_CFLG(x) (CFLG = (x)) |
1004 |
+ |
#define SET_NFLG(x) (NFLG = (x)) |
1005 |
+ |
#define SET_VFLG(x) (VFLG = (x)) |
1006 |
+ |
#define SET_ZFLG(x) (ZFLG = (x)) |
1007 |
+ |
#define SET_XFLG(x) (XFLG = (x)) |
1008 |
+ |
|
1009 |
+ |
#define GET_CFLG CFLG |
1010 |
+ |
#define GET_NFLG NFLG |
1011 |
+ |
#define GET_VFLG VFLG |
1012 |
+ |
#define GET_ZFLG ZFLG |
1013 |
+ |
#define GET_XFLG XFLG |
1014 |
+ |
|
1015 |
+ |
#define CLEAR_CZNV do { \ |
1016 |
+ |
SET_CFLG (0); \ |
1017 |
+ |
SET_ZFLG (0); \ |
1018 |
+ |
SET_NFLG (0); \ |
1019 |
+ |
SET_VFLG (0); \ |
1020 |
+ |
} while (0) |
1021 |
+ |
|
1022 |
+ |
#define COPY_CARRY (SET_XFLG (GET_CFLG)) |
1023 |
+ |
|
1024 |
|
static __inline__ int cctrue(const int cc) |
1025 |
|
{ |
1026 |
|
switch(cc){ |
1044 |
|
return 0; |
1045 |
|
} |
1046 |
|
|
1047 |
< |
#endif |
1047 |
> |
#endif /* OPTIMIZED_FLAGS */ |
1048 |
> |
|
1049 |
> |
#endif /* M68K_FLAGS_H */ |