root / target-i386 / ops_template.h @ 07ce05ea
History | View | Annotate | Download (14.5 kB)
1 | 2c0262af | bellard | /*
|
---|---|---|---|
2 | 2c0262af | bellard | * i386 micro operations (included several times to generate
|
3 | 2c0262af | bellard | * different operand sizes)
|
4 | 2c0262af | bellard | *
|
5 | 2c0262af | bellard | * Copyright (c) 2003 Fabrice Bellard
|
6 | 2c0262af | bellard | *
|
7 | 2c0262af | bellard | * This library is free software; you can redistribute it and/or
|
8 | 2c0262af | bellard | * modify it under the terms of the GNU Lesser General Public
|
9 | 2c0262af | bellard | * License as published by the Free Software Foundation; either
|
10 | 2c0262af | bellard | * version 2 of the License, or (at your option) any later version.
|
11 | 2c0262af | bellard | *
|
12 | 2c0262af | bellard | * This library is distributed in the hope that it will be useful,
|
13 | 2c0262af | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | 2c0262af | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15 | 2c0262af | bellard | * Lesser General Public License for more details.
|
16 | 2c0262af | bellard | *
|
17 | 2c0262af | bellard | * You should have received a copy of the GNU Lesser General Public
|
18 | 2c0262af | bellard | * License along with this library; if not, write to the Free Software
|
19 | 2c0262af | bellard | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20 | 2c0262af | bellard | */
|
21 | 2c0262af | bellard | #define DATA_BITS (1 << (3 + SHIFT)) |
22 | 2c0262af | bellard | #define SHIFT_MASK (DATA_BITS - 1) |
23 | 2c0262af | bellard | #define SIGN_MASK (1 << (DATA_BITS - 1)) |
24 | 2c0262af | bellard | |
25 | 2c0262af | bellard | #if DATA_BITS == 8 |
26 | 2c0262af | bellard | #define SUFFIX b
|
27 | 2c0262af | bellard | #define DATA_TYPE uint8_t
|
28 | 2c0262af | bellard | #define DATA_STYPE int8_t
|
29 | 2c0262af | bellard | #define DATA_MASK 0xff |
30 | 2c0262af | bellard | #elif DATA_BITS == 16 |
31 | 2c0262af | bellard | #define SUFFIX w
|
32 | 2c0262af | bellard | #define DATA_TYPE uint16_t
|
33 | 2c0262af | bellard | #define DATA_STYPE int16_t
|
34 | 2c0262af | bellard | #define DATA_MASK 0xffff |
35 | 2c0262af | bellard | #elif DATA_BITS == 32 |
36 | 2c0262af | bellard | #define SUFFIX l
|
37 | 2c0262af | bellard | #define DATA_TYPE uint32_t
|
38 | 2c0262af | bellard | #define DATA_STYPE int32_t
|
39 | 2c0262af | bellard | #define DATA_MASK 0xffffffff |
40 | 2c0262af | bellard | #else
|
41 | 2c0262af | bellard | #error unhandled operand size
|
42 | 2c0262af | bellard | #endif
|
43 | 2c0262af | bellard | |
44 | 2c0262af | bellard | /* dynamic flags computation */
|
45 | 2c0262af | bellard | |
46 | 2c0262af | bellard | static int glue(compute_all_add, SUFFIX)(void) |
47 | 2c0262af | bellard | { |
48 | 2c0262af | bellard | int cf, pf, af, zf, sf, of;
|
49 | 2c0262af | bellard | int src1, src2;
|
50 | 2c0262af | bellard | src1 = CC_SRC; |
51 | 2c0262af | bellard | src2 = CC_DST - CC_SRC; |
52 | 2c0262af | bellard | cf = (DATA_TYPE)CC_DST < (DATA_TYPE)src1; |
53 | 2c0262af | bellard | pf = parity_table[(uint8_t)CC_DST]; |
54 | 2c0262af | bellard | af = (CC_DST ^ src1 ^ src2) & 0x10;
|
55 | 2c0262af | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
56 | 2c0262af | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
57 | 2c0262af | bellard | of = lshift((src1 ^ src2 ^ -1) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O; |
58 | 2c0262af | bellard | return cf | pf | af | zf | sf | of;
|
59 | 2c0262af | bellard | } |
60 | 2c0262af | bellard | |
61 | 2c0262af | bellard | static int glue(compute_c_add, SUFFIX)(void) |
62 | 2c0262af | bellard | { |
63 | 2c0262af | bellard | int src1, cf;
|
64 | 2c0262af | bellard | src1 = CC_SRC; |
65 | 2c0262af | bellard | cf = (DATA_TYPE)CC_DST < (DATA_TYPE)src1; |
66 | 2c0262af | bellard | return cf;
|
67 | 2c0262af | bellard | } |
68 | 2c0262af | bellard | |
69 | 2c0262af | bellard | static int glue(compute_all_adc, SUFFIX)(void) |
70 | 2c0262af | bellard | { |
71 | 2c0262af | bellard | int cf, pf, af, zf, sf, of;
|
72 | 2c0262af | bellard | int src1, src2;
|
73 | 2c0262af | bellard | src1 = CC_SRC; |
74 | 2c0262af | bellard | src2 = CC_DST - CC_SRC - 1;
|
75 | 2c0262af | bellard | cf = (DATA_TYPE)CC_DST <= (DATA_TYPE)src1; |
76 | 2c0262af | bellard | pf = parity_table[(uint8_t)CC_DST]; |
77 | 2c0262af | bellard | af = (CC_DST ^ src1 ^ src2) & 0x10;
|
78 | 2c0262af | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
79 | 2c0262af | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
80 | 2c0262af | bellard | of = lshift((src1 ^ src2 ^ -1) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O; |
81 | 2c0262af | bellard | return cf | pf | af | zf | sf | of;
|
82 | 2c0262af | bellard | } |
83 | 2c0262af | bellard | |
84 | 2c0262af | bellard | static int glue(compute_c_adc, SUFFIX)(void) |
85 | 2c0262af | bellard | { |
86 | 2c0262af | bellard | int src1, cf;
|
87 | 2c0262af | bellard | src1 = CC_SRC; |
88 | 2c0262af | bellard | cf = (DATA_TYPE)CC_DST <= (DATA_TYPE)src1; |
89 | 2c0262af | bellard | return cf;
|
90 | 2c0262af | bellard | } |
91 | 2c0262af | bellard | |
92 | 2c0262af | bellard | static int glue(compute_all_sub, SUFFIX)(void) |
93 | 2c0262af | bellard | { |
94 | 2c0262af | bellard | int cf, pf, af, zf, sf, of;
|
95 | 2c0262af | bellard | int src1, src2;
|
96 | 2c0262af | bellard | src1 = CC_DST + CC_SRC; |
97 | 2c0262af | bellard | src2 = CC_SRC; |
98 | 2c0262af | bellard | cf = (DATA_TYPE)src1 < (DATA_TYPE)src2; |
99 | 2c0262af | bellard | pf = parity_table[(uint8_t)CC_DST]; |
100 | 2c0262af | bellard | af = (CC_DST ^ src1 ^ src2) & 0x10;
|
101 | 2c0262af | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
102 | 2c0262af | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
103 | 2c0262af | bellard | of = lshift((src1 ^ src2) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O;
|
104 | 2c0262af | bellard | return cf | pf | af | zf | sf | of;
|
105 | 2c0262af | bellard | } |
106 | 2c0262af | bellard | |
107 | 2c0262af | bellard | static int glue(compute_c_sub, SUFFIX)(void) |
108 | 2c0262af | bellard | { |
109 | 2c0262af | bellard | int src1, src2, cf;
|
110 | 2c0262af | bellard | src1 = CC_DST + CC_SRC; |
111 | 2c0262af | bellard | src2 = CC_SRC; |
112 | 2c0262af | bellard | cf = (DATA_TYPE)src1 < (DATA_TYPE)src2; |
113 | 2c0262af | bellard | return cf;
|
114 | 2c0262af | bellard | } |
115 | 2c0262af | bellard | |
116 | 2c0262af | bellard | static int glue(compute_all_sbb, SUFFIX)(void) |
117 | 2c0262af | bellard | { |
118 | 2c0262af | bellard | int cf, pf, af, zf, sf, of;
|
119 | 2c0262af | bellard | int src1, src2;
|
120 | 2c0262af | bellard | src1 = CC_DST + CC_SRC + 1;
|
121 | 2c0262af | bellard | src2 = CC_SRC; |
122 | 2c0262af | bellard | cf = (DATA_TYPE)src1 <= (DATA_TYPE)src2; |
123 | 2c0262af | bellard | pf = parity_table[(uint8_t)CC_DST]; |
124 | 2c0262af | bellard | af = (CC_DST ^ src1 ^ src2) & 0x10;
|
125 | 2c0262af | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
126 | 2c0262af | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
127 | 2c0262af | bellard | of = lshift((src1 ^ src2) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O;
|
128 | 2c0262af | bellard | return cf | pf | af | zf | sf | of;
|
129 | 2c0262af | bellard | } |
130 | 2c0262af | bellard | |
131 | 2c0262af | bellard | static int glue(compute_c_sbb, SUFFIX)(void) |
132 | 2c0262af | bellard | { |
133 | 2c0262af | bellard | int src1, src2, cf;
|
134 | 2c0262af | bellard | src1 = CC_DST + CC_SRC + 1;
|
135 | 2c0262af | bellard | src2 = CC_SRC; |
136 | 2c0262af | bellard | cf = (DATA_TYPE)src1 <= (DATA_TYPE)src2; |
137 | 2c0262af | bellard | return cf;
|
138 | 2c0262af | bellard | } |
139 | 2c0262af | bellard | |
140 | 2c0262af | bellard | static int glue(compute_all_logic, SUFFIX)(void) |
141 | 2c0262af | bellard | { |
142 | 2c0262af | bellard | int cf, pf, af, zf, sf, of;
|
143 | 2c0262af | bellard | cf = 0;
|
144 | 2c0262af | bellard | pf = parity_table[(uint8_t)CC_DST]; |
145 | 2c0262af | bellard | af = 0;
|
146 | 2c0262af | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
147 | 2c0262af | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
148 | 2c0262af | bellard | of = 0;
|
149 | 2c0262af | bellard | return cf | pf | af | zf | sf | of;
|
150 | 2c0262af | bellard | } |
151 | 2c0262af | bellard | |
152 | 2c0262af | bellard | static int glue(compute_c_logic, SUFFIX)(void) |
153 | 2c0262af | bellard | { |
154 | 2c0262af | bellard | return 0; |
155 | 2c0262af | bellard | } |
156 | 2c0262af | bellard | |
157 | 2c0262af | bellard | static int glue(compute_all_inc, SUFFIX)(void) |
158 | 2c0262af | bellard | { |
159 | 2c0262af | bellard | int cf, pf, af, zf, sf, of;
|
160 | 2c0262af | bellard | int src1, src2;
|
161 | 2c0262af | bellard | src1 = CC_DST - 1;
|
162 | 2c0262af | bellard | src2 = 1;
|
163 | 2c0262af | bellard | cf = CC_SRC; |
164 | 2c0262af | bellard | pf = parity_table[(uint8_t)CC_DST]; |
165 | 2c0262af | bellard | af = (CC_DST ^ src1 ^ src2) & 0x10;
|
166 | 2c0262af | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
167 | 2c0262af | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
168 | 2c0262af | bellard | of = ((CC_DST & DATA_MASK) == SIGN_MASK) << 11;
|
169 | 2c0262af | bellard | return cf | pf | af | zf | sf | of;
|
170 | 2c0262af | bellard | } |
171 | 2c0262af | bellard | |
172 | 2c0262af | bellard | #if DATA_BITS == 32 |
173 | 2c0262af | bellard | static int glue(compute_c_inc, SUFFIX)(void) |
174 | 2c0262af | bellard | { |
175 | 2c0262af | bellard | return CC_SRC;
|
176 | 2c0262af | bellard | } |
177 | 2c0262af | bellard | #endif
|
178 | 2c0262af | bellard | |
179 | 2c0262af | bellard | static int glue(compute_all_dec, SUFFIX)(void) |
180 | 2c0262af | bellard | { |
181 | 2c0262af | bellard | int cf, pf, af, zf, sf, of;
|
182 | 2c0262af | bellard | int src1, src2;
|
183 | 2c0262af | bellard | src1 = CC_DST + 1;
|
184 | 2c0262af | bellard | src2 = 1;
|
185 | 2c0262af | bellard | cf = CC_SRC; |
186 | 2c0262af | bellard | pf = parity_table[(uint8_t)CC_DST]; |
187 | 2c0262af | bellard | af = (CC_DST ^ src1 ^ src2) & 0x10;
|
188 | 2c0262af | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
189 | 2c0262af | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
190 | 2c0262af | bellard | of = ((CC_DST & DATA_MASK) == ((uint32_t)SIGN_MASK - 1)) << 11; |
191 | 2c0262af | bellard | return cf | pf | af | zf | sf | of;
|
192 | 2c0262af | bellard | } |
193 | 2c0262af | bellard | |
194 | 2c0262af | bellard | static int glue(compute_all_shl, SUFFIX)(void) |
195 | 2c0262af | bellard | { |
196 | 2c0262af | bellard | int cf, pf, af, zf, sf, of;
|
197 | 2c0262af | bellard | cf = (CC_SRC >> (DATA_BITS - 1)) & CC_C;
|
198 | 2c0262af | bellard | pf = parity_table[(uint8_t)CC_DST]; |
199 | 2c0262af | bellard | af = 0; /* undefined */ |
200 | 2c0262af | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
201 | 2c0262af | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
202 | 2c0262af | bellard | /* of is defined if shift count == 1 */
|
203 | 2c0262af | bellard | of = lshift(CC_SRC ^ CC_DST, 12 - DATA_BITS) & CC_O;
|
204 | 2c0262af | bellard | return cf | pf | af | zf | sf | of;
|
205 | 2c0262af | bellard | } |
206 | 2c0262af | bellard | |
207 | 2c0262af | bellard | static int glue(compute_c_shl, SUFFIX)(void) |
208 | 2c0262af | bellard | { |
209 | 2c0262af | bellard | return (CC_SRC >> (DATA_BITS - 1)) & CC_C; |
210 | 2c0262af | bellard | } |
211 | 2c0262af | bellard | |
212 | 2c0262af | bellard | #if DATA_BITS == 32 |
213 | 2c0262af | bellard | static int glue(compute_c_sar, SUFFIX)(void) |
214 | 2c0262af | bellard | { |
215 | 2c0262af | bellard | return CC_SRC & 1; |
216 | 2c0262af | bellard | } |
217 | 2c0262af | bellard | #endif
|
218 | 2c0262af | bellard | |
219 | 2c0262af | bellard | static int glue(compute_all_sar, SUFFIX)(void) |
220 | 2c0262af | bellard | { |
221 | 2c0262af | bellard | int cf, pf, af, zf, sf, of;
|
222 | 2c0262af | bellard | cf = CC_SRC & 1;
|
223 | 2c0262af | bellard | pf = parity_table[(uint8_t)CC_DST]; |
224 | 2c0262af | bellard | af = 0; /* undefined */ |
225 | 2c0262af | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
226 | 2c0262af | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
227 | 2c0262af | bellard | /* of is defined if shift count == 1 */
|
228 | 2c0262af | bellard | of = lshift(CC_SRC ^ CC_DST, 12 - DATA_BITS) & CC_O;
|
229 | 2c0262af | bellard | return cf | pf | af | zf | sf | of;
|
230 | 2c0262af | bellard | } |
231 | 2c0262af | bellard | |
232 | d36cd60e | bellard | #if DATA_BITS == 32 |
233 | d36cd60e | bellard | static int glue(compute_c_mul, SUFFIX)(void) |
234 | d36cd60e | bellard | { |
235 | d36cd60e | bellard | int cf;
|
236 | d36cd60e | bellard | cf = (CC_SRC != 0);
|
237 | d36cd60e | bellard | return cf;
|
238 | d36cd60e | bellard | } |
239 | d36cd60e | bellard | #endif
|
240 | d36cd60e | bellard | |
241 | d36cd60e | bellard | /* NOTE: we compute the flags like the P4. On olders CPUs, only OF and
|
242 | d36cd60e | bellard | CF are modified and it is slower to do that. */
|
243 | d36cd60e | bellard | static int glue(compute_all_mul, SUFFIX)(void) |
244 | d36cd60e | bellard | { |
245 | d36cd60e | bellard | int cf, pf, af, zf, sf, of;
|
246 | d36cd60e | bellard | cf = (CC_SRC != 0);
|
247 | d36cd60e | bellard | pf = parity_table[(uint8_t)CC_DST]; |
248 | d36cd60e | bellard | af = 0; /* undefined */ |
249 | d36cd60e | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
250 | d36cd60e | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
251 | d36cd60e | bellard | of = cf << 11;
|
252 | d36cd60e | bellard | return cf | pf | af | zf | sf | of;
|
253 | d36cd60e | bellard | } |
254 | d36cd60e | bellard | |
255 | 2c0262af | bellard | /* various optimized jumps cases */
|
256 | 2c0262af | bellard | |
257 | 2c0262af | bellard | void OPPROTO glue(op_jb_sub, SUFFIX)(void) |
258 | 2c0262af | bellard | { |
259 | 2c0262af | bellard | int src1, src2;
|
260 | 2c0262af | bellard | src1 = CC_DST + CC_SRC; |
261 | 2c0262af | bellard | src2 = CC_SRC; |
262 | 2c0262af | bellard | |
263 | 2c0262af | bellard | if ((DATA_TYPE)src1 < (DATA_TYPE)src2)
|
264 | 2c0262af | bellard | JUMP_TB(glue(op_jb_sub, SUFFIX), PARAM1, 0, PARAM2);
|
265 | 2c0262af | bellard | else
|
266 | 2c0262af | bellard | JUMP_TB(glue(op_jb_sub, SUFFIX), PARAM1, 1, PARAM3);
|
267 | 2c0262af | bellard | FORCE_RET(); |
268 | 2c0262af | bellard | } |
269 | 2c0262af | bellard | |
270 | 2c0262af | bellard | void OPPROTO glue(op_jz_sub, SUFFIX)(void) |
271 | 2c0262af | bellard | { |
272 | 2c0262af | bellard | if ((DATA_TYPE)CC_DST == 0) |
273 | 2c0262af | bellard | JUMP_TB(glue(op_jz_sub, SUFFIX), PARAM1, 0, PARAM2);
|
274 | 2c0262af | bellard | else
|
275 | 2c0262af | bellard | JUMP_TB(glue(op_jz_sub, SUFFIX), PARAM1, 1, PARAM3);
|
276 | 2c0262af | bellard | FORCE_RET(); |
277 | 2c0262af | bellard | } |
278 | 2c0262af | bellard | |
279 | 2c0262af | bellard | void OPPROTO glue(op_jbe_sub, SUFFIX)(void) |
280 | 2c0262af | bellard | { |
281 | 2c0262af | bellard | int src1, src2;
|
282 | 2c0262af | bellard | src1 = CC_DST + CC_SRC; |
283 | 2c0262af | bellard | src2 = CC_SRC; |
284 | 2c0262af | bellard | |
285 | 2c0262af | bellard | if ((DATA_TYPE)src1 <= (DATA_TYPE)src2)
|
286 | 2c0262af | bellard | JUMP_TB(glue(op_jbe_sub, SUFFIX), PARAM1, 0, PARAM2);
|
287 | 2c0262af | bellard | else
|
288 | 2c0262af | bellard | JUMP_TB(glue(op_jbe_sub, SUFFIX), PARAM1, 1, PARAM3);
|
289 | 2c0262af | bellard | FORCE_RET(); |
290 | 2c0262af | bellard | } |
291 | 2c0262af | bellard | |
292 | 2c0262af | bellard | void OPPROTO glue(op_js_sub, SUFFIX)(void) |
293 | 2c0262af | bellard | { |
294 | 2c0262af | bellard | if (CC_DST & SIGN_MASK)
|
295 | 2c0262af | bellard | JUMP_TB(glue(op_js_sub, SUFFIX), PARAM1, 0, PARAM2);
|
296 | 2c0262af | bellard | else
|
297 | 2c0262af | bellard | JUMP_TB(glue(op_js_sub, SUFFIX), PARAM1, 1, PARAM3);
|
298 | 2c0262af | bellard | FORCE_RET(); |
299 | 2c0262af | bellard | } |
300 | 2c0262af | bellard | |
301 | 2c0262af | bellard | void OPPROTO glue(op_jl_sub, SUFFIX)(void) |
302 | 2c0262af | bellard | { |
303 | 2c0262af | bellard | int src1, src2;
|
304 | 2c0262af | bellard | src1 = CC_DST + CC_SRC; |
305 | 2c0262af | bellard | src2 = CC_SRC; |
306 | 2c0262af | bellard | |
307 | 2c0262af | bellard | if ((DATA_STYPE)src1 < (DATA_STYPE)src2)
|
308 | 2c0262af | bellard | JUMP_TB(glue(op_jl_sub, SUFFIX), PARAM1, 0, PARAM2);
|
309 | 2c0262af | bellard | else
|
310 | 2c0262af | bellard | JUMP_TB(glue(op_jl_sub, SUFFIX), PARAM1, 1, PARAM3);
|
311 | 2c0262af | bellard | FORCE_RET(); |
312 | 2c0262af | bellard | } |
313 | 2c0262af | bellard | |
314 | 2c0262af | bellard | void OPPROTO glue(op_jle_sub, SUFFIX)(void) |
315 | 2c0262af | bellard | { |
316 | 2c0262af | bellard | int src1, src2;
|
317 | 2c0262af | bellard | src1 = CC_DST + CC_SRC; |
318 | 2c0262af | bellard | src2 = CC_SRC; |
319 | 2c0262af | bellard | |
320 | 2c0262af | bellard | if ((DATA_STYPE)src1 <= (DATA_STYPE)src2)
|
321 | 2c0262af | bellard | JUMP_TB(glue(op_jle_sub, SUFFIX), PARAM1, 0, PARAM2);
|
322 | 2c0262af | bellard | else
|
323 | 2c0262af | bellard | JUMP_TB(glue(op_jle_sub, SUFFIX), PARAM1, 1, PARAM3);
|
324 | 2c0262af | bellard | FORCE_RET(); |
325 | 2c0262af | bellard | } |
326 | 2c0262af | bellard | |
327 | 2c0262af | bellard | /* oldies */
|
328 | 2c0262af | bellard | |
329 | 2c0262af | bellard | #if DATA_BITS >= 16 |
330 | 2c0262af | bellard | |
331 | 2c0262af | bellard | void OPPROTO glue(op_loopnz, SUFFIX)(void) |
332 | 2c0262af | bellard | { |
333 | 2c0262af | bellard | unsigned int tmp; |
334 | 2c0262af | bellard | int eflags;
|
335 | 2c0262af | bellard | eflags = cc_table[CC_OP].compute_all(); |
336 | 2c0262af | bellard | tmp = (ECX - 1) & DATA_MASK;
|
337 | 2c0262af | bellard | ECX = (ECX & ~DATA_MASK) | tmp; |
338 | 2c0262af | bellard | if (tmp != 0 && !(eflags & CC_Z)) |
339 | 2c0262af | bellard | EIP = PARAM1; |
340 | 2c0262af | bellard | else
|
341 | 2c0262af | bellard | EIP = PARAM2; |
342 | 2c0262af | bellard | FORCE_RET(); |
343 | 2c0262af | bellard | } |
344 | 2c0262af | bellard | |
345 | 2c0262af | bellard | void OPPROTO glue(op_loopz, SUFFIX)(void) |
346 | 2c0262af | bellard | { |
347 | 2c0262af | bellard | unsigned int tmp; |
348 | 2c0262af | bellard | int eflags;
|
349 | 2c0262af | bellard | eflags = cc_table[CC_OP].compute_all(); |
350 | 2c0262af | bellard | tmp = (ECX - 1) & DATA_MASK;
|
351 | 2c0262af | bellard | ECX = (ECX & ~DATA_MASK) | tmp; |
352 | 2c0262af | bellard | if (tmp != 0 && (eflags & CC_Z)) |
353 | 2c0262af | bellard | EIP = PARAM1; |
354 | 2c0262af | bellard | else
|
355 | 2c0262af | bellard | EIP = PARAM2; |
356 | 2c0262af | bellard | FORCE_RET(); |
357 | 2c0262af | bellard | } |
358 | 2c0262af | bellard | |
359 | 2c0262af | bellard | void OPPROTO glue(op_loop, SUFFIX)(void) |
360 | 2c0262af | bellard | { |
361 | 2c0262af | bellard | unsigned int tmp; |
362 | 2c0262af | bellard | tmp = (ECX - 1) & DATA_MASK;
|
363 | 2c0262af | bellard | ECX = (ECX & ~DATA_MASK) | tmp; |
364 | 2c0262af | bellard | if (tmp != 0) |
365 | 2c0262af | bellard | EIP = PARAM1; |
366 | 2c0262af | bellard | else
|
367 | 2c0262af | bellard | EIP = PARAM2; |
368 | 2c0262af | bellard | FORCE_RET(); |
369 | 2c0262af | bellard | } |
370 | 2c0262af | bellard | |
371 | 2c0262af | bellard | void OPPROTO glue(op_jecxz, SUFFIX)(void) |
372 | 2c0262af | bellard | { |
373 | 2c0262af | bellard | if ((DATA_TYPE)ECX == 0) |
374 | 2c0262af | bellard | EIP = PARAM1; |
375 | 2c0262af | bellard | else
|
376 | 2c0262af | bellard | EIP = PARAM2; |
377 | 2c0262af | bellard | FORCE_RET(); |
378 | 2c0262af | bellard | } |
379 | 2c0262af | bellard | |
380 | 2c0262af | bellard | #endif
|
381 | 2c0262af | bellard | |
382 | 2c0262af | bellard | /* various optimized set cases */
|
383 | 2c0262af | bellard | |
384 | 2c0262af | bellard | void OPPROTO glue(op_setb_T0_sub, SUFFIX)(void) |
385 | 2c0262af | bellard | { |
386 | 2c0262af | bellard | int src1, src2;
|
387 | 2c0262af | bellard | src1 = CC_DST + CC_SRC; |
388 | 2c0262af | bellard | src2 = CC_SRC; |
389 | 2c0262af | bellard | |
390 | 2c0262af | bellard | T0 = ((DATA_TYPE)src1 < (DATA_TYPE)src2); |
391 | 2c0262af | bellard | } |
392 | 2c0262af | bellard | |
393 | 2c0262af | bellard | void OPPROTO glue(op_setz_T0_sub, SUFFIX)(void) |
394 | 2c0262af | bellard | { |
395 | 2c0262af | bellard | T0 = ((DATA_TYPE)CC_DST == 0);
|
396 | 2c0262af | bellard | } |
397 | 2c0262af | bellard | |
398 | 2c0262af | bellard | void OPPROTO glue(op_setbe_T0_sub, SUFFIX)(void) |
399 | 2c0262af | bellard | { |
400 | 2c0262af | bellard | int src1, src2;
|
401 | 2c0262af | bellard | src1 = CC_DST + CC_SRC; |
402 | 2c0262af | bellard | src2 = CC_SRC; |
403 | 2c0262af | bellard | |
404 | 2c0262af | bellard | T0 = ((DATA_TYPE)src1 <= (DATA_TYPE)src2); |
405 | 2c0262af | bellard | } |
406 | 2c0262af | bellard | |
407 | 2c0262af | bellard | void OPPROTO glue(op_sets_T0_sub, SUFFIX)(void) |
408 | 2c0262af | bellard | { |
409 | 2c0262af | bellard | T0 = lshift(CC_DST, -(DATA_BITS - 1)) & 1; |
410 | 2c0262af | bellard | } |
411 | 2c0262af | bellard | |
412 | 2c0262af | bellard | void OPPROTO glue(op_setl_T0_sub, SUFFIX)(void) |
413 | 2c0262af | bellard | { |
414 | 2c0262af | bellard | int src1, src2;
|
415 | 2c0262af | bellard | src1 = CC_DST + CC_SRC; |
416 | 2c0262af | bellard | src2 = CC_SRC; |
417 | 2c0262af | bellard | |
418 | 2c0262af | bellard | T0 = ((DATA_STYPE)src1 < (DATA_STYPE)src2); |
419 | 2c0262af | bellard | } |
420 | 2c0262af | bellard | |
421 | 2c0262af | bellard | void OPPROTO glue(op_setle_T0_sub, SUFFIX)(void) |
422 | 2c0262af | bellard | { |
423 | 2c0262af | bellard | int src1, src2;
|
424 | 2c0262af | bellard | src1 = CC_DST + CC_SRC; |
425 | 2c0262af | bellard | src2 = CC_SRC; |
426 | 2c0262af | bellard | |
427 | 2c0262af | bellard | T0 = ((DATA_STYPE)src1 <= (DATA_STYPE)src2); |
428 | 2c0262af | bellard | } |
429 | 2c0262af | bellard | |
430 | 2c0262af | bellard | /* shifts */
|
431 | 2c0262af | bellard | |
432 | 2c0262af | bellard | void OPPROTO glue(glue(op_shl, SUFFIX), _T0_T1)(void) |
433 | 2c0262af | bellard | { |
434 | 2c0262af | bellard | int count;
|
435 | 2c0262af | bellard | count = T1 & 0x1f;
|
436 | 2c0262af | bellard | T0 = T0 << count; |
437 | 2c0262af | bellard | FORCE_RET(); |
438 | 2c0262af | bellard | } |
439 | 2c0262af | bellard | |
440 | 2c0262af | bellard | void OPPROTO glue(glue(op_shr, SUFFIX), _T0_T1)(void) |
441 | 2c0262af | bellard | { |
442 | 2c0262af | bellard | int count;
|
443 | 2c0262af | bellard | count = T1 & 0x1f;
|
444 | 2c0262af | bellard | T0 &= DATA_MASK; |
445 | 2c0262af | bellard | T0 = T0 >> count; |
446 | 2c0262af | bellard | FORCE_RET(); |
447 | 2c0262af | bellard | } |
448 | 2c0262af | bellard | |
449 | 2c0262af | bellard | void OPPROTO glue(glue(op_sar, SUFFIX), _T0_T1)(void) |
450 | 2c0262af | bellard | { |
451 | 2c0262af | bellard | int count, src;
|
452 | 2c0262af | bellard | count = T1 & 0x1f;
|
453 | 2c0262af | bellard | src = (DATA_STYPE)T0; |
454 | 2c0262af | bellard | T0 = src >> count; |
455 | 2c0262af | bellard | FORCE_RET(); |
456 | 2c0262af | bellard | } |
457 | 2c0262af | bellard | |
458 | 2c0262af | bellard | #undef MEM_WRITE
|
459 | 2c0262af | bellard | #include "ops_template_mem.h" |
460 | 2c0262af | bellard | |
461 | 34e01bbf | bellard | #define MEM_WRITE 0 |
462 | 2c0262af | bellard | #include "ops_template_mem.h" |
463 | 2c0262af | bellard | |
464 | 34e01bbf | bellard | #if !defined(CONFIG_USER_ONLY)
|
465 | 34e01bbf | bellard | #define MEM_WRITE 1 |
466 | 34e01bbf | bellard | #include "ops_template_mem.h" |
467 | 34e01bbf | bellard | |
468 | 34e01bbf | bellard | #define MEM_WRITE 2 |
469 | 34e01bbf | bellard | #include "ops_template_mem.h" |
470 | 34e01bbf | bellard | #endif
|
471 | 34e01bbf | bellard | |
472 | 2c0262af | bellard | /* bit operations */
|
473 | 2c0262af | bellard | #if DATA_BITS >= 16 |
474 | 2c0262af | bellard | |
475 | 2c0262af | bellard | void OPPROTO glue(glue(op_bt, SUFFIX), _T0_T1_cc)(void) |
476 | 2c0262af | bellard | { |
477 | 2c0262af | bellard | int count;
|
478 | 2c0262af | bellard | count = T1 & SHIFT_MASK; |
479 | 2c0262af | bellard | CC_SRC = T0 >> count; |
480 | 2c0262af | bellard | } |
481 | 2c0262af | bellard | |
482 | 2c0262af | bellard | void OPPROTO glue(glue(op_bts, SUFFIX), _T0_T1_cc)(void) |
483 | 2c0262af | bellard | { |
484 | 2c0262af | bellard | int count;
|
485 | 2c0262af | bellard | count = T1 & SHIFT_MASK; |
486 | 2c0262af | bellard | T1 = T0 >> count; |
487 | 2c0262af | bellard | T0 |= (1 << count);
|
488 | 2c0262af | bellard | } |
489 | 2c0262af | bellard | |
490 | 2c0262af | bellard | void OPPROTO glue(glue(op_btr, SUFFIX), _T0_T1_cc)(void) |
491 | 2c0262af | bellard | { |
492 | 2c0262af | bellard | int count;
|
493 | 2c0262af | bellard | count = T1 & SHIFT_MASK; |
494 | 2c0262af | bellard | T1 = T0 >> count; |
495 | 2c0262af | bellard | T0 &= ~(1 << count);
|
496 | 2c0262af | bellard | } |
497 | 2c0262af | bellard | |
498 | 2c0262af | bellard | void OPPROTO glue(glue(op_btc, SUFFIX), _T0_T1_cc)(void) |
499 | 2c0262af | bellard | { |
500 | 2c0262af | bellard | int count;
|
501 | 2c0262af | bellard | count = T1 & SHIFT_MASK; |
502 | 2c0262af | bellard | T1 = T0 >> count; |
503 | 2c0262af | bellard | T0 ^= (1 << count);
|
504 | 2c0262af | bellard | } |
505 | 2c0262af | bellard | |
506 | 2c0262af | bellard | void OPPROTO glue(glue(op_bsf, SUFFIX), _T0_cc)(void) |
507 | 2c0262af | bellard | { |
508 | 2c0262af | bellard | int res, count;
|
509 | 2c0262af | bellard | res = T0 & DATA_MASK; |
510 | 2c0262af | bellard | if (res != 0) { |
511 | 2c0262af | bellard | count = 0;
|
512 | 2c0262af | bellard | while ((res & 1) == 0) { |
513 | 2c0262af | bellard | count++; |
514 | 2c0262af | bellard | res >>= 1;
|
515 | 2c0262af | bellard | } |
516 | 2c0262af | bellard | T0 = count; |
517 | debf7a7c | bellard | CC_DST = 1; /* ZF = 0 */ |
518 | 2c0262af | bellard | } else {
|
519 | 2c0262af | bellard | CC_DST = 0; /* ZF = 1 */ |
520 | 2c0262af | bellard | } |
521 | 2c0262af | bellard | FORCE_RET(); |
522 | 2c0262af | bellard | } |
523 | 2c0262af | bellard | |
524 | 2c0262af | bellard | void OPPROTO glue(glue(op_bsr, SUFFIX), _T0_cc)(void) |
525 | 2c0262af | bellard | { |
526 | 2c0262af | bellard | int res, count;
|
527 | 2c0262af | bellard | res = T0 & DATA_MASK; |
528 | 2c0262af | bellard | if (res != 0) { |
529 | 2c0262af | bellard | count = DATA_BITS - 1;
|
530 | 2c0262af | bellard | while ((res & SIGN_MASK) == 0) { |
531 | 2c0262af | bellard | count--; |
532 | 2c0262af | bellard | res <<= 1;
|
533 | 2c0262af | bellard | } |
534 | 2c0262af | bellard | T0 = count; |
535 | debf7a7c | bellard | CC_DST = 1; /* ZF = 0 */ |
536 | 2c0262af | bellard | } else {
|
537 | 2c0262af | bellard | CC_DST = 0; /* ZF = 1 */ |
538 | 2c0262af | bellard | } |
539 | 2c0262af | bellard | FORCE_RET(); |
540 | 2c0262af | bellard | } |
541 | 2c0262af | bellard | |
542 | 2c0262af | bellard | #endif
|
543 | 2c0262af | bellard | |
544 | 2c0262af | bellard | #if DATA_BITS == 32 |
545 | 2c0262af | bellard | void OPPROTO op_update_bt_cc(void) |
546 | 2c0262af | bellard | { |
547 | 2c0262af | bellard | CC_SRC = T1; |
548 | 2c0262af | bellard | } |
549 | 2c0262af | bellard | #endif
|
550 | 2c0262af | bellard | |
551 | 2c0262af | bellard | /* string operations */
|
552 | 2c0262af | bellard | |
553 | 2c0262af | bellard | void OPPROTO glue(op_movl_T0_Dshift, SUFFIX)(void) |
554 | 2c0262af | bellard | { |
555 | 2c0262af | bellard | T0 = DF << SHIFT; |
556 | 2c0262af | bellard | } |
557 | 2c0262af | bellard | |
558 | 2c0262af | bellard | void OPPROTO glue(op_string_jz_sub, SUFFIX)(void) |
559 | 2c0262af | bellard | { |
560 | 2c0262af | bellard | if ((DATA_TYPE)CC_DST == 0) |
561 | 34e01bbf | bellard | JUMP_TB2(glue(op_string_jz_sub, SUFFIX), PARAM1, 3);
|
562 | 2c0262af | bellard | FORCE_RET(); |
563 | 2c0262af | bellard | } |
564 | 2c0262af | bellard | |
565 | 2c0262af | bellard | void OPPROTO glue(op_string_jnz_sub, SUFFIX)(void) |
566 | 2c0262af | bellard | { |
567 | 2c0262af | bellard | if ((DATA_TYPE)CC_DST != 0) |
568 | 34e01bbf | bellard | JUMP_TB2(glue(op_string_jnz_sub, SUFFIX), PARAM1, 3);
|
569 | 2c0262af | bellard | FORCE_RET(); |
570 | 2c0262af | bellard | } |
571 | 2c0262af | bellard | |
572 | 2c0262af | bellard | void OPPROTO glue(glue(op_string_jz_sub, SUFFIX), _im)(void) |
573 | 2c0262af | bellard | { |
574 | 2c0262af | bellard | if ((DATA_TYPE)CC_DST == 0) { |
575 | 2c0262af | bellard | EIP = PARAM1; |
576 | 2c0262af | bellard | if (env->eflags & TF_MASK) {
|
577 | 2c0262af | bellard | raise_exception(EXCP01_SSTP); |
578 | 2c0262af | bellard | } |
579 | 2c0262af | bellard | T0 = 0;
|
580 | 2c0262af | bellard | EXIT_TB(); |
581 | 2c0262af | bellard | } |
582 | 2c0262af | bellard | FORCE_RET(); |
583 | 2c0262af | bellard | } |
584 | 2c0262af | bellard | |
585 | 2c0262af | bellard | void OPPROTO glue(glue(op_string_jnz_sub, SUFFIX), _im)(void) |
586 | 2c0262af | bellard | { |
587 | 2c0262af | bellard | if ((DATA_TYPE)CC_DST != 0) { |
588 | 2c0262af | bellard | EIP = PARAM1; |
589 | 2c0262af | bellard | if (env->eflags & TF_MASK) {
|
590 | 2c0262af | bellard | raise_exception(EXCP01_SSTP); |
591 | 2c0262af | bellard | } |
592 | 2c0262af | bellard | T0 = 0;
|
593 | 2c0262af | bellard | EXIT_TB(); |
594 | 2c0262af | bellard | } |
595 | 2c0262af | bellard | FORCE_RET(); |
596 | 2c0262af | bellard | } |
597 | 2c0262af | bellard | |
598 | 2c0262af | bellard | #if DATA_BITS >= 16 |
599 | 2c0262af | bellard | void OPPROTO glue(op_jz_ecx, SUFFIX)(void) |
600 | 2c0262af | bellard | { |
601 | 2c0262af | bellard | if ((DATA_TYPE)ECX == 0) |
602 | 2c0262af | bellard | JUMP_TB(glue(op_jz_ecx, SUFFIX), PARAM1, 1, PARAM2);
|
603 | 2c0262af | bellard | FORCE_RET(); |
604 | 2c0262af | bellard | } |
605 | 2c0262af | bellard | |
606 | 2c0262af | bellard | void OPPROTO glue(glue(op_jz_ecx, SUFFIX), _im)(void) |
607 | 2c0262af | bellard | { |
608 | 2c0262af | bellard | if ((DATA_TYPE)ECX == 0) { |
609 | 2c0262af | bellard | EIP = PARAM1; |
610 | 2c0262af | bellard | if (env->eflags & TF_MASK) {
|
611 | 2c0262af | bellard | raise_exception(EXCP01_SSTP); |
612 | 2c0262af | bellard | } |
613 | 2c0262af | bellard | T0 = 0;
|
614 | 2c0262af | bellard | EXIT_TB(); |
615 | 2c0262af | bellard | } |
616 | 2c0262af | bellard | FORCE_RET(); |
617 | 2c0262af | bellard | } |
618 | 2c0262af | bellard | #endif
|
619 | 2c0262af | bellard | |
620 | 2c0262af | bellard | /* port I/O */
|
621 | 2c0262af | bellard | |
622 | 2c0262af | bellard | void OPPROTO glue(glue(op_out, SUFFIX), _T0_T1)(void) |
623 | 2c0262af | bellard | { |
624 | 4487d0ac | bellard | glue(cpu_out, SUFFIX)(env, T0, T1 & DATA_MASK); |
625 | 2c0262af | bellard | } |
626 | 2c0262af | bellard | |
627 | 2c0262af | bellard | void OPPROTO glue(glue(op_in, SUFFIX), _T0_T1)(void) |
628 | 2c0262af | bellard | { |
629 | 4487d0ac | bellard | T1 = glue(cpu_in, SUFFIX)(env, T0); |
630 | 2c0262af | bellard | } |
631 | 2c0262af | bellard | |
632 | 2c0262af | bellard | void OPPROTO glue(glue(op_in, SUFFIX), _DX_T0)(void) |
633 | 2c0262af | bellard | { |
634 | 4487d0ac | bellard | T0 = glue(cpu_in, SUFFIX)(env, EDX & 0xffff);
|
635 | 2c0262af | bellard | } |
636 | 2c0262af | bellard | |
637 | 2c0262af | bellard | void OPPROTO glue(glue(op_out, SUFFIX), _DX_T0)(void) |
638 | 2c0262af | bellard | { |
639 | 4487d0ac | bellard | glue(cpu_out, SUFFIX)(env, EDX & 0xffff, T0);
|
640 | 2c0262af | bellard | } |
641 | 2c0262af | bellard | |
642 | 3e25f951 | bellard | void OPPROTO glue(glue(op_check_io, SUFFIX), _T0)(void) |
643 | 3e25f951 | bellard | { |
644 | 3e25f951 | bellard | glue(glue(check_io, SUFFIX), _T0)(); |
645 | 3e25f951 | bellard | } |
646 | 3e25f951 | bellard | |
647 | 3e25f951 | bellard | void OPPROTO glue(glue(op_check_io, SUFFIX), _DX)(void) |
648 | 3e25f951 | bellard | { |
649 | 3e25f951 | bellard | glue(glue(check_io, SUFFIX), _DX)(); |
650 | 3e25f951 | bellard | } |
651 | 3e25f951 | bellard | |
652 | 2c0262af | bellard | #undef DATA_BITS
|
653 | 2c0262af | bellard | #undef SHIFT_MASK
|
654 | 2c0262af | bellard | #undef SIGN_MASK
|
655 | 2c0262af | bellard | #undef DATA_TYPE
|
656 | 2c0262af | bellard | #undef DATA_STYPE
|
657 | 2c0262af | bellard | #undef DATA_MASK
|
658 | 2c0262af | bellard | #undef SUFFIX |