root / ops_template.h @ 2a29ca73
History | View | Annotate | Download (19.3 kB)
1 | 66fb9763 | bellard | /*
|
---|---|---|---|
2 | 66fb9763 | bellard | * i386 micro operations (included several times to generate
|
3 | 66fb9763 | bellard | * different operand sizes)
|
4 | 66fb9763 | bellard | *
|
5 | 66fb9763 | bellard | * Copyright (c) 2003 Fabrice Bellard
|
6 | 66fb9763 | bellard | *
|
7 | d691f669 | bellard | * This library is free software; you can redistribute it and/or
|
8 | d691f669 | bellard | * modify it under the terms of the GNU Lesser General Public
|
9 | d691f669 | bellard | * License as published by the Free Software Foundation; either
|
10 | d691f669 | bellard | * version 2 of the License, or (at your option) any later version.
|
11 | 66fb9763 | bellard | *
|
12 | d691f669 | bellard | * This library is distributed in the hope that it will be useful,
|
13 | d691f669 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | d691f669 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15 | d691f669 | bellard | * Lesser General Public License for more details.
|
16 | 66fb9763 | bellard | *
|
17 | d691f669 | bellard | * You should have received a copy of the GNU Lesser General Public
|
18 | d691f669 | bellard | * License along with this library; if not, write to the Free Software
|
19 | d691f669 | bellard | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20 | 66fb9763 | bellard | */
|
21 | 367e86e8 | bellard | #define DATA_BITS (1 << (3 + SHIFT)) |
22 | 367e86e8 | bellard | #define SHIFT_MASK (DATA_BITS - 1) |
23 | 367e86e8 | bellard | #define SIGN_MASK (1 << (DATA_BITS - 1)) |
24 | 367e86e8 | bellard | |
25 | 367e86e8 | bellard | #if DATA_BITS == 8 |
26 | 367e86e8 | bellard | #define SUFFIX b
|
27 | 367e86e8 | bellard | #define DATA_TYPE uint8_t
|
28 | 367e86e8 | bellard | #define DATA_STYPE int8_t
|
29 | 367e86e8 | bellard | #define DATA_MASK 0xff |
30 | 367e86e8 | bellard | #elif DATA_BITS == 16 |
31 | 367e86e8 | bellard | #define SUFFIX w
|
32 | 367e86e8 | bellard | #define DATA_TYPE uint16_t
|
33 | 367e86e8 | bellard | #define DATA_STYPE int16_t
|
34 | 367e86e8 | bellard | #define DATA_MASK 0xffff |
35 | 367e86e8 | bellard | #elif DATA_BITS == 32 |
36 | 367e86e8 | bellard | #define SUFFIX l
|
37 | 367e86e8 | bellard | #define DATA_TYPE uint32_t
|
38 | 367e86e8 | bellard | #define DATA_STYPE int32_t
|
39 | 367e86e8 | bellard | #define DATA_MASK 0xffffffff |
40 | 367e86e8 | bellard | #else
|
41 | 367e86e8 | bellard | #error unhandled operand size
|
42 | 367e86e8 | bellard | #endif
|
43 | 367e86e8 | bellard | |
44 | 367e86e8 | bellard | /* dynamic flags computation */
|
45 | 367e86e8 | bellard | |
46 | 367e86e8 | bellard | static int glue(compute_all_add, SUFFIX)(void) |
47 | 367e86e8 | bellard | { |
48 | 367e86e8 | bellard | int cf, pf, af, zf, sf, of;
|
49 | 367e86e8 | bellard | int src1, src2;
|
50 | 367e86e8 | bellard | src1 = CC_SRC; |
51 | 367e86e8 | bellard | src2 = CC_DST - CC_SRC; |
52 | 367e86e8 | bellard | cf = (DATA_TYPE)CC_DST < (DATA_TYPE)src1; |
53 | 367e86e8 | bellard | pf = parity_table[(uint8_t)CC_DST]; |
54 | 367e86e8 | bellard | af = (CC_DST ^ src1 ^ src2) & 0x10;
|
55 | 4b74fe1f | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
56 | 367e86e8 | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
57 | 367e86e8 | bellard | of = lshift((src1 ^ src2 ^ -1) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O; |
58 | 367e86e8 | bellard | return cf | pf | af | zf | sf | of;
|
59 | 367e86e8 | bellard | } |
60 | 367e86e8 | bellard | |
61 | 367e86e8 | bellard | static int glue(compute_c_add, SUFFIX)(void) |
62 | 367e86e8 | bellard | { |
63 | 367e86e8 | bellard | int src1, cf;
|
64 | 367e86e8 | bellard | src1 = CC_SRC; |
65 | 367e86e8 | bellard | cf = (DATA_TYPE)CC_DST < (DATA_TYPE)src1; |
66 | 367e86e8 | bellard | return cf;
|
67 | 367e86e8 | bellard | } |
68 | 367e86e8 | bellard | |
69 | 4b74fe1f | bellard | static int glue(compute_all_adc, SUFFIX)(void) |
70 | 4b74fe1f | bellard | { |
71 | 4b74fe1f | bellard | int cf, pf, af, zf, sf, of;
|
72 | 4b74fe1f | bellard | int src1, src2;
|
73 | 4b74fe1f | bellard | src1 = CC_SRC; |
74 | 4b74fe1f | bellard | src2 = CC_DST - CC_SRC - 1;
|
75 | 4b74fe1f | bellard | cf = (DATA_TYPE)CC_DST <= (DATA_TYPE)src1; |
76 | 4b74fe1f | bellard | pf = parity_table[(uint8_t)CC_DST]; |
77 | 4b74fe1f | bellard | af = (CC_DST ^ src1 ^ src2) & 0x10;
|
78 | 4b74fe1f | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
79 | 4b74fe1f | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
80 | 4b74fe1f | bellard | of = lshift((src1 ^ src2 ^ -1) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O; |
81 | 4b74fe1f | bellard | return cf | pf | af | zf | sf | of;
|
82 | 4b74fe1f | bellard | } |
83 | 4b74fe1f | bellard | |
84 | 4b74fe1f | bellard | static int glue(compute_c_adc, SUFFIX)(void) |
85 | 4b74fe1f | bellard | { |
86 | 4b74fe1f | bellard | int src1, cf;
|
87 | 4b74fe1f | bellard | src1 = CC_SRC; |
88 | 4b74fe1f | bellard | cf = (DATA_TYPE)CC_DST <= (DATA_TYPE)src1; |
89 | 4b74fe1f | bellard | return cf;
|
90 | 4b74fe1f | bellard | } |
91 | 4b74fe1f | bellard | |
92 | 367e86e8 | bellard | static int glue(compute_all_sub, SUFFIX)(void) |
93 | 367e86e8 | bellard | { |
94 | 367e86e8 | bellard | int cf, pf, af, zf, sf, of;
|
95 | 367e86e8 | bellard | int src1, src2;
|
96 | 367e86e8 | bellard | src1 = CC_SRC; |
97 | 367e86e8 | bellard | src2 = CC_SRC - CC_DST; |
98 | 367e86e8 | bellard | cf = (DATA_TYPE)src1 < (DATA_TYPE)src2; |
99 | 367e86e8 | bellard | pf = parity_table[(uint8_t)CC_DST]; |
100 | 367e86e8 | bellard | af = (CC_DST ^ src1 ^ src2) & 0x10;
|
101 | 4b74fe1f | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
102 | 367e86e8 | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
103 | 4b74fe1f | bellard | of = lshift((src1 ^ src2) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O;
|
104 | 367e86e8 | bellard | return cf | pf | af | zf | sf | of;
|
105 | 367e86e8 | bellard | } |
106 | 367e86e8 | bellard | |
107 | 367e86e8 | bellard | static int glue(compute_c_sub, SUFFIX)(void) |
108 | 367e86e8 | bellard | { |
109 | 367e86e8 | bellard | int src1, src2, cf;
|
110 | 367e86e8 | bellard | src1 = CC_SRC; |
111 | 367e86e8 | bellard | src2 = CC_SRC - CC_DST; |
112 | 4b74fe1f | bellard | cf = (DATA_TYPE)src1 < (DATA_TYPE)src2; |
113 | 4b74fe1f | bellard | return cf;
|
114 | 4b74fe1f | bellard | } |
115 | 4b74fe1f | bellard | |
116 | 4b74fe1f | bellard | static int glue(compute_all_sbb, SUFFIX)(void) |
117 | 4b74fe1f | bellard | { |
118 | 4b74fe1f | bellard | int cf, pf, af, zf, sf, of;
|
119 | 4b74fe1f | bellard | int src1, src2;
|
120 | 4b74fe1f | bellard | src1 = CC_SRC; |
121 | 4b74fe1f | bellard | src2 = CC_SRC - CC_DST - 1;
|
122 | 4b74fe1f | bellard | cf = (DATA_TYPE)src1 <= (DATA_TYPE)src2; |
123 | 4b74fe1f | bellard | pf = parity_table[(uint8_t)CC_DST]; |
124 | 4b74fe1f | bellard | af = (CC_DST ^ src1 ^ src2) & 0x10;
|
125 | 4b74fe1f | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
126 | 4b74fe1f | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
127 | 4b74fe1f | bellard | of = lshift((src1 ^ src2) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O;
|
128 | 4b74fe1f | bellard | return cf | pf | af | zf | sf | of;
|
129 | 4b74fe1f | bellard | } |
130 | 4b74fe1f | bellard | |
131 | 4b74fe1f | bellard | static int glue(compute_c_sbb, SUFFIX)(void) |
132 | 4b74fe1f | bellard | { |
133 | 4b74fe1f | bellard | int src1, src2, cf;
|
134 | 4b74fe1f | bellard | src1 = CC_SRC; |
135 | 4b74fe1f | bellard | src2 = CC_SRC - CC_DST - 1;
|
136 | 4b74fe1f | bellard | cf = (DATA_TYPE)src1 <= (DATA_TYPE)src2; |
137 | 367e86e8 | bellard | return cf;
|
138 | 367e86e8 | bellard | } |
139 | 367e86e8 | bellard | |
140 | 367e86e8 | bellard | static int glue(compute_all_logic, SUFFIX)(void) |
141 | 367e86e8 | bellard | { |
142 | 367e86e8 | bellard | int cf, pf, af, zf, sf, of;
|
143 | 367e86e8 | bellard | cf = 0;
|
144 | 367e86e8 | bellard | pf = parity_table[(uint8_t)CC_DST]; |
145 | 367e86e8 | bellard | af = 0;
|
146 | 4b74fe1f | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
147 | 367e86e8 | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
148 | 367e86e8 | bellard | of = 0;
|
149 | 367e86e8 | bellard | return cf | pf | af | zf | sf | of;
|
150 | 367e86e8 | bellard | } |
151 | 367e86e8 | bellard | |
152 | 367e86e8 | bellard | static int glue(compute_c_logic, SUFFIX)(void) |
153 | 367e86e8 | bellard | { |
154 | 367e86e8 | bellard | return 0; |
155 | 367e86e8 | bellard | } |
156 | 367e86e8 | bellard | |
157 | 367e86e8 | bellard | static int glue(compute_all_inc, SUFFIX)(void) |
158 | 367e86e8 | bellard | { |
159 | 367e86e8 | bellard | int cf, pf, af, zf, sf, of;
|
160 | 367e86e8 | bellard | int src1, src2;
|
161 | 367e86e8 | bellard | src1 = CC_DST - 1;
|
162 | 367e86e8 | bellard | src2 = 1;
|
163 | 367e86e8 | bellard | cf = CC_SRC; |
164 | 367e86e8 | bellard | pf = parity_table[(uint8_t)CC_DST]; |
165 | 367e86e8 | bellard | af = (CC_DST ^ src1 ^ src2) & 0x10;
|
166 | 4b74fe1f | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
167 | 367e86e8 | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
168 | 4b74fe1f | bellard | of = ((CC_DST & DATA_MASK) == SIGN_MASK) << 11;
|
169 | 367e86e8 | bellard | return cf | pf | af | zf | sf | of;
|
170 | 367e86e8 | bellard | } |
171 | 367e86e8 | bellard | |
172 | 4b74fe1f | bellard | #if DATA_BITS == 32 |
173 | 367e86e8 | bellard | static int glue(compute_c_inc, SUFFIX)(void) |
174 | 367e86e8 | bellard | { |
175 | 367e86e8 | bellard | return CC_SRC;
|
176 | 367e86e8 | bellard | } |
177 | 4b74fe1f | bellard | #endif
|
178 | 367e86e8 | bellard | |
179 | 367e86e8 | bellard | static int glue(compute_all_dec, SUFFIX)(void) |
180 | 367e86e8 | bellard | { |
181 | 367e86e8 | bellard | int cf, pf, af, zf, sf, of;
|
182 | 367e86e8 | bellard | int src1, src2;
|
183 | 367e86e8 | bellard | src1 = CC_DST + 1;
|
184 | 367e86e8 | bellard | src2 = 1;
|
185 | 367e86e8 | bellard | cf = CC_SRC; |
186 | 367e86e8 | bellard | pf = parity_table[(uint8_t)CC_DST]; |
187 | 367e86e8 | bellard | af = (CC_DST ^ src1 ^ src2) & 0x10;
|
188 | 4b74fe1f | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
189 | 367e86e8 | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
190 | 4b74fe1f | bellard | of = ((CC_DST & DATA_MASK) == ((uint32_t)SIGN_MASK - 1)) << 11; |
191 | 367e86e8 | bellard | return cf | pf | af | zf | sf | of;
|
192 | 367e86e8 | bellard | } |
193 | 367e86e8 | bellard | |
194 | 367e86e8 | bellard | static int glue(compute_all_shl, SUFFIX)(void) |
195 | 367e86e8 | bellard | { |
196 | 367e86e8 | bellard | int cf, pf, af, zf, sf, of;
|
197 | d57c4e01 | bellard | cf = (CC_SRC >> (DATA_BITS - 1)) & CC_C;
|
198 | 367e86e8 | bellard | pf = parity_table[(uint8_t)CC_DST]; |
199 | 367e86e8 | bellard | af = 0; /* undefined */ |
200 | 4b74fe1f | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
201 | 367e86e8 | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
202 | d57c4e01 | bellard | /* of is defined if shift count == 1 */
|
203 | d57c4e01 | bellard | of = lshift(CC_SRC ^ CC_DST, 12 - DATA_BITS) & CC_O;
|
204 | 367e86e8 | bellard | return cf | pf | af | zf | sf | of;
|
205 | 367e86e8 | bellard | } |
206 | 367e86e8 | bellard | |
207 | 367e86e8 | bellard | static int glue(compute_c_shl, SUFFIX)(void) |
208 | 367e86e8 | bellard | { |
209 | 72cc3881 | bellard | return (CC_SRC >> (DATA_BITS - 1)) & CC_C; |
210 | 72cc3881 | bellard | } |
211 | 72cc3881 | bellard | |
212 | 72cc3881 | bellard | #if DATA_BITS == 32 |
213 | 72cc3881 | bellard | static int glue(compute_c_sar, SUFFIX)(void) |
214 | 72cc3881 | bellard | { |
215 | 367e86e8 | bellard | return CC_SRC & 1; |
216 | 367e86e8 | bellard | } |
217 | 4b74fe1f | bellard | #endif
|
218 | 4b74fe1f | bellard | |
219 | 4b74fe1f | bellard | static int glue(compute_all_sar, SUFFIX)(void) |
220 | 4b74fe1f | bellard | { |
221 | 4b74fe1f | bellard | int cf, pf, af, zf, sf, of;
|
222 | 4b74fe1f | bellard | cf = CC_SRC & 1;
|
223 | 4b74fe1f | bellard | pf = parity_table[(uint8_t)CC_DST]; |
224 | 4b74fe1f | bellard | af = 0; /* undefined */ |
225 | 4b74fe1f | bellard | zf = ((DATA_TYPE)CC_DST == 0) << 6; |
226 | 4b74fe1f | bellard | sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80; |
227 | d57c4e01 | bellard | /* of is defined if shift count == 1 */
|
228 | d57c4e01 | bellard | of = lshift(CC_SRC ^ CC_DST, 12 - DATA_BITS) & CC_O;
|
229 | 4b74fe1f | bellard | return cf | pf | af | zf | sf | of;
|
230 | 4b74fe1f | bellard | } |
231 | 367e86e8 | bellard | |
232 | 367e86e8 | bellard | /* various optimized jumps cases */
|
233 | 367e86e8 | bellard | |
234 | 367e86e8 | bellard | void OPPROTO glue(op_jb_sub, SUFFIX)(void) |
235 | 367e86e8 | bellard | { |
236 | 367e86e8 | bellard | int src1, src2;
|
237 | 367e86e8 | bellard | src1 = CC_SRC; |
238 | 367e86e8 | bellard | src2 = CC_SRC - CC_DST; |
239 | 367e86e8 | bellard | |
240 | 367e86e8 | bellard | if ((DATA_TYPE)src1 < (DATA_TYPE)src2)
|
241 | dab2ed99 | bellard | EIP = PARAM1; |
242 | 367e86e8 | bellard | else
|
243 | dab2ed99 | bellard | EIP = PARAM2; |
244 | 367e86e8 | bellard | FORCE_RET(); |
245 | 367e86e8 | bellard | } |
246 | 367e86e8 | bellard | |
247 | 367e86e8 | bellard | void OPPROTO glue(op_jz_sub, SUFFIX)(void) |
248 | 367e86e8 | bellard | { |
249 | 4b74fe1f | bellard | if ((DATA_TYPE)CC_DST == 0) |
250 | dab2ed99 | bellard | EIP = PARAM1; |
251 | 367e86e8 | bellard | else
|
252 | dab2ed99 | bellard | EIP = PARAM2; |
253 | 367e86e8 | bellard | FORCE_RET(); |
254 | 367e86e8 | bellard | } |
255 | 367e86e8 | bellard | |
256 | 367e86e8 | bellard | void OPPROTO glue(op_jbe_sub, SUFFIX)(void) |
257 | 367e86e8 | bellard | { |
258 | 367e86e8 | bellard | int src1, src2;
|
259 | 367e86e8 | bellard | src1 = CC_SRC; |
260 | 367e86e8 | bellard | src2 = CC_SRC - CC_DST; |
261 | 367e86e8 | bellard | |
262 | 367e86e8 | bellard | if ((DATA_TYPE)src1 <= (DATA_TYPE)src2)
|
263 | dab2ed99 | bellard | EIP = PARAM1; |
264 | 367e86e8 | bellard | else
|
265 | dab2ed99 | bellard | EIP = PARAM2; |
266 | 367e86e8 | bellard | FORCE_RET(); |
267 | 367e86e8 | bellard | } |
268 | 367e86e8 | bellard | |
269 | 367e86e8 | bellard | void OPPROTO glue(op_js_sub, SUFFIX)(void) |
270 | 367e86e8 | bellard | { |
271 | 367e86e8 | bellard | if (CC_DST & SIGN_MASK)
|
272 | dab2ed99 | bellard | EIP = PARAM1; |
273 | 367e86e8 | bellard | else
|
274 | dab2ed99 | bellard | EIP = PARAM2; |
275 | 367e86e8 | bellard | FORCE_RET(); |
276 | 367e86e8 | bellard | } |
277 | 367e86e8 | bellard | |
278 | 367e86e8 | bellard | void OPPROTO glue(op_jl_sub, SUFFIX)(void) |
279 | 367e86e8 | bellard | { |
280 | 367e86e8 | bellard | int src1, src2;
|
281 | 367e86e8 | bellard | src1 = CC_SRC; |
282 | 367e86e8 | bellard | src2 = CC_SRC - CC_DST; |
283 | 367e86e8 | bellard | |
284 | 367e86e8 | bellard | if ((DATA_STYPE)src1 < (DATA_STYPE)src2)
|
285 | dab2ed99 | bellard | EIP = PARAM1; |
286 | 367e86e8 | bellard | else
|
287 | dab2ed99 | bellard | EIP = PARAM2; |
288 | 367e86e8 | bellard | FORCE_RET(); |
289 | 367e86e8 | bellard | } |
290 | 367e86e8 | bellard | |
291 | 367e86e8 | bellard | void OPPROTO glue(op_jle_sub, SUFFIX)(void) |
292 | 367e86e8 | bellard | { |
293 | 367e86e8 | bellard | int src1, src2;
|
294 | 367e86e8 | bellard | src1 = CC_SRC; |
295 | 367e86e8 | bellard | src2 = CC_SRC - CC_DST; |
296 | 367e86e8 | bellard | |
297 | 367e86e8 | bellard | if ((DATA_STYPE)src1 <= (DATA_STYPE)src2)
|
298 | dab2ed99 | bellard | EIP = PARAM1; |
299 | 367e86e8 | bellard | else
|
300 | dab2ed99 | bellard | EIP = PARAM2; |
301 | 367e86e8 | bellard | FORCE_RET(); |
302 | 367e86e8 | bellard | } |
303 | 367e86e8 | bellard | |
304 | 1a9353d2 | bellard | /* oldies */
|
305 | 1a9353d2 | bellard | |
306 | 1a9353d2 | bellard | #if DATA_BITS >= 16 |
307 | 1a9353d2 | bellard | |
308 | 1a9353d2 | bellard | void OPPROTO glue(op_loopnz, SUFFIX)(void) |
309 | 1a9353d2 | bellard | { |
310 | 1a9353d2 | bellard | unsigned int tmp; |
311 | 1a9353d2 | bellard | int eflags;
|
312 | 1a9353d2 | bellard | eflags = cc_table[CC_OP].compute_all(); |
313 | 1a9353d2 | bellard | tmp = (ECX - 1) & DATA_MASK;
|
314 | 1a9353d2 | bellard | ECX = (ECX & ~DATA_MASK) | tmp; |
315 | 1a9353d2 | bellard | if (tmp != 0 && !(eflags & CC_Z)) |
316 | dab2ed99 | bellard | EIP = PARAM1; |
317 | 1a9353d2 | bellard | else
|
318 | dab2ed99 | bellard | EIP = PARAM2; |
319 | 1a9353d2 | bellard | FORCE_RET(); |
320 | 1a9353d2 | bellard | } |
321 | 1a9353d2 | bellard | |
322 | 1a9353d2 | bellard | void OPPROTO glue(op_loopz, SUFFIX)(void) |
323 | 1a9353d2 | bellard | { |
324 | 1a9353d2 | bellard | unsigned int tmp; |
325 | 1a9353d2 | bellard | int eflags;
|
326 | 1a9353d2 | bellard | eflags = cc_table[CC_OP].compute_all(); |
327 | 1a9353d2 | bellard | tmp = (ECX - 1) & DATA_MASK;
|
328 | 1a9353d2 | bellard | ECX = (ECX & ~DATA_MASK) | tmp; |
329 | 1a9353d2 | bellard | if (tmp != 0 && (eflags & CC_Z)) |
330 | dab2ed99 | bellard | EIP = PARAM1; |
331 | 1a9353d2 | bellard | else
|
332 | dab2ed99 | bellard | EIP = PARAM2; |
333 | 1a9353d2 | bellard | FORCE_RET(); |
334 | 1a9353d2 | bellard | } |
335 | 1a9353d2 | bellard | |
336 | 1a9353d2 | bellard | void OPPROTO glue(op_loop, SUFFIX)(void) |
337 | 1a9353d2 | bellard | { |
338 | 1a9353d2 | bellard | unsigned int tmp; |
339 | 1a9353d2 | bellard | tmp = (ECX - 1) & DATA_MASK;
|
340 | 1a9353d2 | bellard | ECX = (ECX & ~DATA_MASK) | tmp; |
341 | 1a9353d2 | bellard | if (tmp != 0) |
342 | dab2ed99 | bellard | EIP = PARAM1; |
343 | 1a9353d2 | bellard | else
|
344 | dab2ed99 | bellard | EIP = PARAM2; |
345 | 1a9353d2 | bellard | FORCE_RET(); |
346 | 1a9353d2 | bellard | } |
347 | 1a9353d2 | bellard | |
348 | 1a9353d2 | bellard | void OPPROTO glue(op_jecxz, SUFFIX)(void) |
349 | 1a9353d2 | bellard | { |
350 | 1a9353d2 | bellard | if ((DATA_TYPE)ECX == 0) |
351 | dab2ed99 | bellard | EIP = PARAM1; |
352 | 1a9353d2 | bellard | else
|
353 | dab2ed99 | bellard | EIP = PARAM2; |
354 | 1a9353d2 | bellard | FORCE_RET(); |
355 | 1a9353d2 | bellard | } |
356 | 1a9353d2 | bellard | |
357 | 1a9353d2 | bellard | #endif
|
358 | 1a9353d2 | bellard | |
359 | 367e86e8 | bellard | /* various optimized set cases */
|
360 | 367e86e8 | bellard | |
361 | 367e86e8 | bellard | void OPPROTO glue(op_setb_T0_sub, SUFFIX)(void) |
362 | 367e86e8 | bellard | { |
363 | 367e86e8 | bellard | int src1, src2;
|
364 | 367e86e8 | bellard | src1 = CC_SRC; |
365 | 367e86e8 | bellard | src2 = CC_SRC - CC_DST; |
366 | 367e86e8 | bellard | |
367 | 367e86e8 | bellard | T0 = ((DATA_TYPE)src1 < (DATA_TYPE)src2); |
368 | 367e86e8 | bellard | } |
369 | 367e86e8 | bellard | |
370 | 367e86e8 | bellard | void OPPROTO glue(op_setz_T0_sub, SUFFIX)(void) |
371 | 367e86e8 | bellard | { |
372 | 4b74fe1f | bellard | T0 = ((DATA_TYPE)CC_DST == 0);
|
373 | 367e86e8 | bellard | } |
374 | 367e86e8 | bellard | |
375 | 367e86e8 | bellard | void OPPROTO glue(op_setbe_T0_sub, SUFFIX)(void) |
376 | 367e86e8 | bellard | { |
377 | 367e86e8 | bellard | int src1, src2;
|
378 | 367e86e8 | bellard | src1 = CC_SRC; |
379 | 367e86e8 | bellard | src2 = CC_SRC - CC_DST; |
380 | 367e86e8 | bellard | |
381 | 367e86e8 | bellard | T0 = ((DATA_TYPE)src1 <= (DATA_TYPE)src2); |
382 | 367e86e8 | bellard | } |
383 | 367e86e8 | bellard | |
384 | 367e86e8 | bellard | void OPPROTO glue(op_sets_T0_sub, SUFFIX)(void) |
385 | 367e86e8 | bellard | { |
386 | 367e86e8 | bellard | T0 = lshift(CC_DST, -(DATA_BITS - 1)) & 1; |
387 | 367e86e8 | bellard | } |
388 | 367e86e8 | bellard | |
389 | 367e86e8 | bellard | void OPPROTO glue(op_setl_T0_sub, SUFFIX)(void) |
390 | 367e86e8 | bellard | { |
391 | 367e86e8 | bellard | int src1, src2;
|
392 | 367e86e8 | bellard | src1 = CC_SRC; |
393 | 367e86e8 | bellard | src2 = CC_SRC - CC_DST; |
394 | 367e86e8 | bellard | |
395 | 367e86e8 | bellard | T0 = ((DATA_STYPE)src1 < (DATA_STYPE)src2); |
396 | 367e86e8 | bellard | } |
397 | 367e86e8 | bellard | |
398 | 367e86e8 | bellard | void OPPROTO glue(op_setle_T0_sub, SUFFIX)(void) |
399 | 367e86e8 | bellard | { |
400 | 367e86e8 | bellard | int src1, src2;
|
401 | 367e86e8 | bellard | src1 = CC_SRC; |
402 | 367e86e8 | bellard | src2 = CC_SRC - CC_DST; |
403 | 367e86e8 | bellard | |
404 | 367e86e8 | bellard | T0 = ((DATA_STYPE)src1 <= (DATA_STYPE)src2); |
405 | 367e86e8 | bellard | } |
406 | 367e86e8 | bellard | |
407 | 367e86e8 | bellard | /* shifts */
|
408 | 367e86e8 | bellard | |
409 | 367e86e8 | bellard | void OPPROTO glue(glue(op_rol, SUFFIX), _T0_T1_cc)(void) |
410 | 367e86e8 | bellard | { |
411 | 367e86e8 | bellard | int count, src;
|
412 | 367e86e8 | bellard | count = T1 & SHIFT_MASK; |
413 | 367e86e8 | bellard | if (count) {
|
414 | 367e86e8 | bellard | CC_SRC = cc_table[CC_OP].compute_all() & ~(CC_O | CC_C); |
415 | 367e86e8 | bellard | src = T0; |
416 | 367e86e8 | bellard | T0 &= DATA_MASK; |
417 | 367e86e8 | bellard | T0 = (T0 << count) | (T0 >> (DATA_BITS - count)); |
418 | 367e86e8 | bellard | CC_SRC |= (lshift(src ^ T0, 11 - (DATA_BITS - 1)) & CC_O) | |
419 | 367e86e8 | bellard | (T0 & CC_C); |
420 | 367e86e8 | bellard | CC_OP = CC_OP_EFLAGS; |
421 | 367e86e8 | bellard | } |
422 | 4b74fe1f | bellard | FORCE_RET(); |
423 | 367e86e8 | bellard | } |
424 | 367e86e8 | bellard | |
425 | dc99065b | bellard | void OPPROTO glue(glue(op_rol, SUFFIX), _T0_T1)(void) |
426 | dc99065b | bellard | { |
427 | dc99065b | bellard | int count;
|
428 | dc99065b | bellard | count = T1 & SHIFT_MASK; |
429 | dc99065b | bellard | if (count) {
|
430 | dc99065b | bellard | T0 &= DATA_MASK; |
431 | dc99065b | bellard | T0 = (T0 << count) | (T0 >> (DATA_BITS - count)); |
432 | dc99065b | bellard | } |
433 | dc99065b | bellard | FORCE_RET(); |
434 | dc99065b | bellard | } |
435 | dc99065b | bellard | |
436 | 367e86e8 | bellard | void OPPROTO glue(glue(op_ror, SUFFIX), _T0_T1_cc)(void) |
437 | 367e86e8 | bellard | { |
438 | 367e86e8 | bellard | int count, src;
|
439 | 367e86e8 | bellard | count = T1 & SHIFT_MASK; |
440 | 367e86e8 | bellard | if (count) {
|
441 | 367e86e8 | bellard | CC_SRC = cc_table[CC_OP].compute_all() & ~(CC_O | CC_C); |
442 | 367e86e8 | bellard | src = T0; |
443 | 367e86e8 | bellard | T0 &= DATA_MASK; |
444 | 367e86e8 | bellard | T0 = (T0 >> count) | (T0 << (DATA_BITS - count)); |
445 | 367e86e8 | bellard | CC_SRC |= (lshift(src ^ T0, 11 - (DATA_BITS - 1)) & CC_O) | |
446 | 367e86e8 | bellard | ((T0 >> (DATA_BITS - 1)) & CC_C);
|
447 | 367e86e8 | bellard | CC_OP = CC_OP_EFLAGS; |
448 | 367e86e8 | bellard | } |
449 | 4b74fe1f | bellard | FORCE_RET(); |
450 | 367e86e8 | bellard | } |
451 | 367e86e8 | bellard | |
452 | dc99065b | bellard | void OPPROTO glue(glue(op_ror, SUFFIX), _T0_T1)(void) |
453 | dc99065b | bellard | { |
454 | dc99065b | bellard | int count;
|
455 | dc99065b | bellard | count = T1 & SHIFT_MASK; |
456 | dc99065b | bellard | if (count) {
|
457 | dc99065b | bellard | T0 &= DATA_MASK; |
458 | dc99065b | bellard | T0 = (T0 >> count) | (T0 << (DATA_BITS - count)); |
459 | dc99065b | bellard | } |
460 | dc99065b | bellard | FORCE_RET(); |
461 | dc99065b | bellard | } |
462 | dc99065b | bellard | |
463 | 367e86e8 | bellard | void OPPROTO glue(glue(op_rcl, SUFFIX), _T0_T1_cc)(void) |
464 | 367e86e8 | bellard | { |
465 | 367e86e8 | bellard | int count, res, eflags;
|
466 | 367e86e8 | bellard | unsigned int src; |
467 | 367e86e8 | bellard | |
468 | 367e86e8 | bellard | count = T1 & 0x1f;
|
469 | 367e86e8 | bellard | #if DATA_BITS == 16 |
470 | 367e86e8 | bellard | count = rclw_table[count]; |
471 | 367e86e8 | bellard | #elif DATA_BITS == 8 |
472 | 367e86e8 | bellard | count = rclb_table[count]; |
473 | 367e86e8 | bellard | #endif
|
474 | 367e86e8 | bellard | if (count) {
|
475 | 367e86e8 | bellard | eflags = cc_table[CC_OP].compute_all(); |
476 | 4b74fe1f | bellard | T0 &= DATA_MASK; |
477 | 367e86e8 | bellard | src = T0; |
478 | 367e86e8 | bellard | res = (T0 << count) | ((eflags & CC_C) << (count - 1));
|
479 | 367e86e8 | bellard | if (count > 1) |
480 | 367e86e8 | bellard | res |= T0 >> (DATA_BITS + 1 - count);
|
481 | 367e86e8 | bellard | T0 = res; |
482 | 367e86e8 | bellard | CC_SRC = (eflags & ~(CC_C | CC_O)) | |
483 | 367e86e8 | bellard | (lshift(src ^ T0, 11 - (DATA_BITS - 1)) & CC_O) | |
484 | 367e86e8 | bellard | ((src >> (DATA_BITS - count)) & CC_C); |
485 | 367e86e8 | bellard | CC_OP = CC_OP_EFLAGS; |
486 | 367e86e8 | bellard | } |
487 | 4b74fe1f | bellard | FORCE_RET(); |
488 | 367e86e8 | bellard | } |
489 | 367e86e8 | bellard | |
490 | 367e86e8 | bellard | void OPPROTO glue(glue(op_rcr, SUFFIX), _T0_T1_cc)(void) |
491 | 367e86e8 | bellard | { |
492 | 367e86e8 | bellard | int count, res, eflags;
|
493 | 367e86e8 | bellard | unsigned int src; |
494 | 367e86e8 | bellard | |
495 | 367e86e8 | bellard | count = T1 & 0x1f;
|
496 | 367e86e8 | bellard | #if DATA_BITS == 16 |
497 | 367e86e8 | bellard | count = rclw_table[count]; |
498 | 367e86e8 | bellard | #elif DATA_BITS == 8 |
499 | 367e86e8 | bellard | count = rclb_table[count]; |
500 | 367e86e8 | bellard | #endif
|
501 | 367e86e8 | bellard | if (count) {
|
502 | 367e86e8 | bellard | eflags = cc_table[CC_OP].compute_all(); |
503 | 4b74fe1f | bellard | T0 &= DATA_MASK; |
504 | 367e86e8 | bellard | src = T0; |
505 | 367e86e8 | bellard | res = (T0 >> count) | ((eflags & CC_C) << (DATA_BITS - count)); |
506 | 367e86e8 | bellard | if (count > 1) |
507 | 367e86e8 | bellard | res |= T0 << (DATA_BITS + 1 - count);
|
508 | 367e86e8 | bellard | T0 = res; |
509 | 367e86e8 | bellard | CC_SRC = (eflags & ~(CC_C | CC_O)) | |
510 | 367e86e8 | bellard | (lshift(src ^ T0, 11 - (DATA_BITS - 1)) & CC_O) | |
511 | 367e86e8 | bellard | ((src >> (count - 1)) & CC_C);
|
512 | 367e86e8 | bellard | CC_OP = CC_OP_EFLAGS; |
513 | 367e86e8 | bellard | } |
514 | 4b74fe1f | bellard | FORCE_RET(); |
515 | 367e86e8 | bellard | } |
516 | 367e86e8 | bellard | |
517 | 367e86e8 | bellard | void OPPROTO glue(glue(op_shl, SUFFIX), _T0_T1_cc)(void) |
518 | 367e86e8 | bellard | { |
519 | 367e86e8 | bellard | int count;
|
520 | 367e86e8 | bellard | count = T1 & 0x1f;
|
521 | d57c4e01 | bellard | if (count) {
|
522 | d57c4e01 | bellard | CC_SRC = (DATA_TYPE)T0 << (count - 1);
|
523 | 367e86e8 | bellard | T0 = T0 << count; |
524 | 367e86e8 | bellard | CC_DST = T0; |
525 | 367e86e8 | bellard | CC_OP = CC_OP_SHLB + SHIFT; |
526 | 367e86e8 | bellard | } |
527 | 4b74fe1f | bellard | FORCE_RET(); |
528 | 367e86e8 | bellard | } |
529 | 367e86e8 | bellard | |
530 | dc99065b | bellard | void OPPROTO glue(glue(op_shl, SUFFIX), _T0_T1)(void) |
531 | dc99065b | bellard | { |
532 | dc99065b | bellard | int count;
|
533 | dc99065b | bellard | count = T1 & 0x1f;
|
534 | dc99065b | bellard | T0 = T0 << count; |
535 | dc99065b | bellard | FORCE_RET(); |
536 | dc99065b | bellard | } |
537 | dc99065b | bellard | |
538 | 367e86e8 | bellard | void OPPROTO glue(glue(op_shr, SUFFIX), _T0_T1_cc)(void) |
539 | 367e86e8 | bellard | { |
540 | 367e86e8 | bellard | int count;
|
541 | 367e86e8 | bellard | count = T1 & 0x1f;
|
542 | 367e86e8 | bellard | if (count) {
|
543 | 367e86e8 | bellard | T0 &= DATA_MASK; |
544 | 367e86e8 | bellard | CC_SRC = T0 >> (count - 1);
|
545 | 367e86e8 | bellard | T0 = T0 >> count; |
546 | 367e86e8 | bellard | CC_DST = T0; |
547 | d57c4e01 | bellard | CC_OP = CC_OP_SARB + SHIFT; |
548 | 367e86e8 | bellard | } |
549 | 4b74fe1f | bellard | FORCE_RET(); |
550 | 367e86e8 | bellard | } |
551 | 367e86e8 | bellard | |
552 | dc99065b | bellard | void OPPROTO glue(glue(op_shr, SUFFIX), _T0_T1)(void) |
553 | dc99065b | bellard | { |
554 | dc99065b | bellard | int count;
|
555 | dc99065b | bellard | count = T1 & 0x1f;
|
556 | dc99065b | bellard | T0 &= DATA_MASK; |
557 | dc99065b | bellard | T0 = T0 >> count; |
558 | dc99065b | bellard | FORCE_RET(); |
559 | dc99065b | bellard | } |
560 | dc99065b | bellard | |
561 | 367e86e8 | bellard | void OPPROTO glue(glue(op_sar, SUFFIX), _T0_T1_cc)(void) |
562 | 367e86e8 | bellard | { |
563 | 367e86e8 | bellard | int count, src;
|
564 | 367e86e8 | bellard | count = T1 & 0x1f;
|
565 | 367e86e8 | bellard | if (count) {
|
566 | 367e86e8 | bellard | src = (DATA_STYPE)T0; |
567 | d57c4e01 | bellard | CC_SRC = src >> (count - 1);
|
568 | 367e86e8 | bellard | T0 = src >> count; |
569 | 367e86e8 | bellard | CC_DST = T0; |
570 | 4b74fe1f | bellard | CC_OP = CC_OP_SARB + SHIFT; |
571 | 367e86e8 | bellard | } |
572 | 4b74fe1f | bellard | FORCE_RET(); |
573 | 367e86e8 | bellard | } |
574 | 367e86e8 | bellard | |
575 | dc99065b | bellard | void OPPROTO glue(glue(op_sar, SUFFIX), _T0_T1)(void) |
576 | dc99065b | bellard | { |
577 | dc99065b | bellard | int count, src;
|
578 | dc99065b | bellard | count = T1 & 0x1f;
|
579 | dc99065b | bellard | src = (DATA_STYPE)T0; |
580 | dc99065b | bellard | T0 = src >> count; |
581 | dc99065b | bellard | FORCE_RET(); |
582 | dc99065b | bellard | } |
583 | dc99065b | bellard | |
584 | d57c4e01 | bellard | #if DATA_BITS == 16 |
585 | d57c4e01 | bellard | /* XXX: overflow flag might be incorrect in some cases in shldw */
|
586 | d57c4e01 | bellard | void OPPROTO glue(glue(op_shld, SUFFIX), _T0_T1_im_cc)(void) |
587 | d57c4e01 | bellard | { |
588 | d57c4e01 | bellard | int count;
|
589 | d57c4e01 | bellard | unsigned int res; |
590 | d57c4e01 | bellard | count = PARAM1; |
591 | d57c4e01 | bellard | T1 &= 0xffff;
|
592 | d57c4e01 | bellard | res = T1 | (T0 << 16);
|
593 | d57c4e01 | bellard | CC_SRC = res >> (32 - count);
|
594 | d57c4e01 | bellard | res <<= count; |
595 | d57c4e01 | bellard | if (count > 16) |
596 | d57c4e01 | bellard | res |= T1 << (count - 16);
|
597 | d57c4e01 | bellard | T0 = res >> 16;
|
598 | d57c4e01 | bellard | CC_DST = T0; |
599 | d57c4e01 | bellard | } |
600 | d57c4e01 | bellard | |
601 | d57c4e01 | bellard | void OPPROTO glue(glue(op_shld, SUFFIX), _T0_T1_ECX_cc)(void) |
602 | d57c4e01 | bellard | { |
603 | d57c4e01 | bellard | int count;
|
604 | d57c4e01 | bellard | unsigned int res; |
605 | d57c4e01 | bellard | count = ECX & 0x1f;
|
606 | d57c4e01 | bellard | if (count) {
|
607 | d57c4e01 | bellard | T1 &= 0xffff;
|
608 | d57c4e01 | bellard | res = T1 | (T0 << 16);
|
609 | d57c4e01 | bellard | CC_SRC = res >> (32 - count);
|
610 | d57c4e01 | bellard | res <<= count; |
611 | d57c4e01 | bellard | if (count > 16) |
612 | d57c4e01 | bellard | res |= T1 << (count - 16);
|
613 | d57c4e01 | bellard | T0 = res >> 16;
|
614 | d57c4e01 | bellard | CC_DST = T0; |
615 | d57c4e01 | bellard | CC_OP = CC_OP_SARB + SHIFT; |
616 | d57c4e01 | bellard | } |
617 | 7fe70ecc | bellard | FORCE_RET(); |
618 | d57c4e01 | bellard | } |
619 | d57c4e01 | bellard | |
620 | d57c4e01 | bellard | void OPPROTO glue(glue(op_shrd, SUFFIX), _T0_T1_im_cc)(void) |
621 | d57c4e01 | bellard | { |
622 | d57c4e01 | bellard | int count;
|
623 | d57c4e01 | bellard | unsigned int res; |
624 | d57c4e01 | bellard | |
625 | d57c4e01 | bellard | count = PARAM1; |
626 | d57c4e01 | bellard | res = (T0 & 0xffff) | (T1 << 16); |
627 | d57c4e01 | bellard | CC_SRC = res >> (count - 1);
|
628 | d57c4e01 | bellard | res >>= count; |
629 | d57c4e01 | bellard | if (count > 16) |
630 | d57c4e01 | bellard | res |= T1 << (32 - count);
|
631 | d57c4e01 | bellard | T0 = res; |
632 | d57c4e01 | bellard | CC_DST = T0; |
633 | d57c4e01 | bellard | } |
634 | d57c4e01 | bellard | |
635 | d57c4e01 | bellard | |
636 | d57c4e01 | bellard | void OPPROTO glue(glue(op_shrd, SUFFIX), _T0_T1_ECX_cc)(void) |
637 | d57c4e01 | bellard | { |
638 | d57c4e01 | bellard | int count;
|
639 | d57c4e01 | bellard | unsigned int res; |
640 | d57c4e01 | bellard | |
641 | d57c4e01 | bellard | count = ECX & 0x1f;
|
642 | d57c4e01 | bellard | if (count) {
|
643 | d57c4e01 | bellard | res = (T0 & 0xffff) | (T1 << 16); |
644 | d57c4e01 | bellard | CC_SRC = res >> (count - 1);
|
645 | d57c4e01 | bellard | res >>= count; |
646 | d57c4e01 | bellard | if (count > 16) |
647 | d57c4e01 | bellard | res |= T1 << (32 - count);
|
648 | d57c4e01 | bellard | T0 = res; |
649 | d57c4e01 | bellard | CC_DST = T0; |
650 | d57c4e01 | bellard | CC_OP = CC_OP_SARB + SHIFT; |
651 | d57c4e01 | bellard | } |
652 | 7fe70ecc | bellard | FORCE_RET(); |
653 | d57c4e01 | bellard | } |
654 | d57c4e01 | bellard | #endif
|
655 | d57c4e01 | bellard | |
656 | d57c4e01 | bellard | #if DATA_BITS == 32 |
657 | d57c4e01 | bellard | void OPPROTO glue(glue(op_shld, SUFFIX), _T0_T1_im_cc)(void) |
658 | d57c4e01 | bellard | { |
659 | d57c4e01 | bellard | int count;
|
660 | d57c4e01 | bellard | count = PARAM1; |
661 | d57c4e01 | bellard | T0 &= DATA_MASK; |
662 | d57c4e01 | bellard | T1 &= DATA_MASK; |
663 | d57c4e01 | bellard | CC_SRC = T0 << (count - 1);
|
664 | d57c4e01 | bellard | T0 = (T0 << count) | (T1 >> (DATA_BITS - count)); |
665 | d57c4e01 | bellard | CC_DST = T0; |
666 | d57c4e01 | bellard | } |
667 | d57c4e01 | bellard | |
668 | d57c4e01 | bellard | void OPPROTO glue(glue(op_shld, SUFFIX), _T0_T1_ECX_cc)(void) |
669 | d57c4e01 | bellard | { |
670 | d57c4e01 | bellard | int count;
|
671 | d57c4e01 | bellard | count = ECX & 0x1f;
|
672 | d57c4e01 | bellard | if (count) {
|
673 | d57c4e01 | bellard | T0 &= DATA_MASK; |
674 | d57c4e01 | bellard | T1 &= DATA_MASK; |
675 | d57c4e01 | bellard | CC_SRC = T0 << (count - 1);
|
676 | d57c4e01 | bellard | T0 = (T0 << count) | (T1 >> (DATA_BITS - count)); |
677 | d57c4e01 | bellard | CC_DST = T0; |
678 | d57c4e01 | bellard | CC_OP = CC_OP_SHLB + SHIFT; |
679 | d57c4e01 | bellard | } |
680 | 7fe70ecc | bellard | FORCE_RET(); |
681 | d57c4e01 | bellard | } |
682 | d57c4e01 | bellard | |
683 | d57c4e01 | bellard | void OPPROTO glue(glue(op_shrd, SUFFIX), _T0_T1_im_cc)(void) |
684 | d57c4e01 | bellard | { |
685 | d57c4e01 | bellard | int count;
|
686 | d57c4e01 | bellard | count = PARAM1; |
687 | d57c4e01 | bellard | T0 &= DATA_MASK; |
688 | d57c4e01 | bellard | T1 &= DATA_MASK; |
689 | d57c4e01 | bellard | CC_SRC = T0 >> (count - 1);
|
690 | d57c4e01 | bellard | T0 = (T0 >> count) | (T1 << (DATA_BITS - count)); |
691 | d57c4e01 | bellard | CC_DST = T0; |
692 | d57c4e01 | bellard | } |
693 | d57c4e01 | bellard | |
694 | d57c4e01 | bellard | |
695 | d57c4e01 | bellard | void OPPROTO glue(glue(op_shrd, SUFFIX), _T0_T1_ECX_cc)(void) |
696 | d57c4e01 | bellard | { |
697 | d57c4e01 | bellard | int count;
|
698 | d57c4e01 | bellard | count = ECX & 0x1f;
|
699 | d57c4e01 | bellard | if (count) {
|
700 | d57c4e01 | bellard | T0 &= DATA_MASK; |
701 | d57c4e01 | bellard | T1 &= DATA_MASK; |
702 | d57c4e01 | bellard | CC_SRC = T0 >> (count - 1);
|
703 | d57c4e01 | bellard | T0 = (T0 >> count) | (T1 << (DATA_BITS - count)); |
704 | d57c4e01 | bellard | CC_DST = T0; |
705 | d57c4e01 | bellard | CC_OP = CC_OP_SARB + SHIFT; |
706 | d57c4e01 | bellard | } |
707 | 7fe70ecc | bellard | FORCE_RET(); |
708 | d57c4e01 | bellard | } |
709 | d57c4e01 | bellard | #endif
|
710 | d57c4e01 | bellard | |
711 | 4b74fe1f | bellard | /* carry add/sub (we only need to set CC_OP differently) */
|
712 | 4b74fe1f | bellard | |
713 | 4b74fe1f | bellard | void OPPROTO glue(glue(op_adc, SUFFIX), _T0_T1_cc)(void) |
714 | 4b74fe1f | bellard | { |
715 | 4b74fe1f | bellard | int cf;
|
716 | 4b74fe1f | bellard | cf = cc_table[CC_OP].compute_c(); |
717 | 4b74fe1f | bellard | CC_SRC = T0; |
718 | 4b74fe1f | bellard | T0 = T0 + T1 + cf; |
719 | 4b74fe1f | bellard | CC_DST = T0; |
720 | 4b74fe1f | bellard | CC_OP = CC_OP_ADDB + SHIFT + cf * 3;
|
721 | 4b74fe1f | bellard | } |
722 | 4b74fe1f | bellard | |
723 | 4b74fe1f | bellard | void OPPROTO glue(glue(op_sbb, SUFFIX), _T0_T1_cc)(void) |
724 | 4b74fe1f | bellard | { |
725 | 4b74fe1f | bellard | int cf;
|
726 | 4b74fe1f | bellard | cf = cc_table[CC_OP].compute_c(); |
727 | 4b74fe1f | bellard | CC_SRC = T0; |
728 | 4b74fe1f | bellard | T0 = T0 - T1 - cf; |
729 | 4b74fe1f | bellard | CC_DST = T0; |
730 | 4b74fe1f | bellard | CC_OP = CC_OP_SUBB + SHIFT + cf * 3;
|
731 | 4b74fe1f | bellard | } |
732 | 4b74fe1f | bellard | |
733 | 1a9353d2 | bellard | void OPPROTO glue(glue(op_cmpxchg, SUFFIX), _T0_T1_EAX_cc)(void) |
734 | 1a9353d2 | bellard | { |
735 | 1a9353d2 | bellard | CC_SRC = EAX; |
736 | 1a9353d2 | bellard | CC_DST = EAX - T0; |
737 | 1a9353d2 | bellard | if ((DATA_TYPE)CC_DST == 0) { |
738 | 1a9353d2 | bellard | T0 = T1; |
739 | 1a9353d2 | bellard | } else {
|
740 | 1a9353d2 | bellard | EAX = (EAX & ~DATA_MASK) | (T0 & DATA_MASK); |
741 | 1a9353d2 | bellard | } |
742 | 1a9353d2 | bellard | FORCE_RET(); |
743 | 1a9353d2 | bellard | } |
744 | 1a9353d2 | bellard | |
745 | 4b74fe1f | bellard | /* bit operations */
|
746 | 4b74fe1f | bellard | #if DATA_BITS >= 16 |
747 | 4b74fe1f | bellard | |
748 | 4b74fe1f | bellard | void OPPROTO glue(glue(op_bt, SUFFIX), _T0_T1_cc)(void) |
749 | 4b74fe1f | bellard | { |
750 | 4b74fe1f | bellard | int count;
|
751 | 4b74fe1f | bellard | count = T1 & SHIFT_MASK; |
752 | 4b74fe1f | bellard | CC_SRC = T0 >> count; |
753 | 4b74fe1f | bellard | } |
754 | 4b74fe1f | bellard | |
755 | 4b74fe1f | bellard | void OPPROTO glue(glue(op_bts, SUFFIX), _T0_T1_cc)(void) |
756 | 4b74fe1f | bellard | { |
757 | 4b74fe1f | bellard | int count;
|
758 | 4b74fe1f | bellard | count = T1 & SHIFT_MASK; |
759 | 4b74fe1f | bellard | CC_SRC = T0 >> count; |
760 | 4b74fe1f | bellard | T0 |= (1 << count);
|
761 | 4b74fe1f | bellard | } |
762 | 4b74fe1f | bellard | |
763 | 4b74fe1f | bellard | void OPPROTO glue(glue(op_btr, SUFFIX), _T0_T1_cc)(void) |
764 | 4b74fe1f | bellard | { |
765 | 4b74fe1f | bellard | int count;
|
766 | 4b74fe1f | bellard | count = T1 & SHIFT_MASK; |
767 | 4b74fe1f | bellard | CC_SRC = T0 >> count; |
768 | 4b74fe1f | bellard | T0 &= ~(1 << count);
|
769 | 4b74fe1f | bellard | } |
770 | 4b74fe1f | bellard | |
771 | 4b74fe1f | bellard | void OPPROTO glue(glue(op_btc, SUFFIX), _T0_T1_cc)(void) |
772 | 4b74fe1f | bellard | { |
773 | 4b74fe1f | bellard | int count;
|
774 | 4b74fe1f | bellard | count = T1 & SHIFT_MASK; |
775 | 4b74fe1f | bellard | CC_SRC = T0 >> count; |
776 | 4b74fe1f | bellard | T0 ^= (1 << count);
|
777 | 4b74fe1f | bellard | } |
778 | 4b74fe1f | bellard | |
779 | 77f8dd5a | bellard | void OPPROTO glue(glue(op_bsf, SUFFIX), _T0_cc)(void) |
780 | 77f8dd5a | bellard | { |
781 | 77f8dd5a | bellard | int res, count;
|
782 | 77f8dd5a | bellard | res = T0 & DATA_MASK; |
783 | 77f8dd5a | bellard | if (res != 0) { |
784 | 77f8dd5a | bellard | count = 0;
|
785 | 77f8dd5a | bellard | while ((res & 1) == 0) { |
786 | 77f8dd5a | bellard | count++; |
787 | 77f8dd5a | bellard | res >>= 1;
|
788 | 77f8dd5a | bellard | } |
789 | 77f8dd5a | bellard | T0 = count; |
790 | 77f8dd5a | bellard | CC_DST = 1; /* ZF = 1 */ |
791 | 77f8dd5a | bellard | } else {
|
792 | 77f8dd5a | bellard | CC_DST = 0; /* ZF = 1 */ |
793 | 77f8dd5a | bellard | } |
794 | 77f8dd5a | bellard | FORCE_RET(); |
795 | 77f8dd5a | bellard | } |
796 | 77f8dd5a | bellard | |
797 | 77f8dd5a | bellard | void OPPROTO glue(glue(op_bsr, SUFFIX), _T0_cc)(void) |
798 | 77f8dd5a | bellard | { |
799 | 77f8dd5a | bellard | int res, count;
|
800 | 77f8dd5a | bellard | res = T0 & DATA_MASK; |
801 | 77f8dd5a | bellard | if (res != 0) { |
802 | 77f8dd5a | bellard | count = DATA_BITS - 1;
|
803 | 77f8dd5a | bellard | while ((res & SIGN_MASK) == 0) { |
804 | 77f8dd5a | bellard | count--; |
805 | 77f8dd5a | bellard | res <<= 1;
|
806 | 77f8dd5a | bellard | } |
807 | 77f8dd5a | bellard | T0 = count; |
808 | 77f8dd5a | bellard | CC_DST = 1; /* ZF = 1 */ |
809 | 77f8dd5a | bellard | } else {
|
810 | 77f8dd5a | bellard | CC_DST = 0; /* ZF = 1 */ |
811 | 77f8dd5a | bellard | } |
812 | 77f8dd5a | bellard | FORCE_RET(); |
813 | 77f8dd5a | bellard | } |
814 | 77f8dd5a | bellard | |
815 | 4b74fe1f | bellard | #endif
|
816 | 4b74fe1f | bellard | |
817 | 367e86e8 | bellard | /* string operations */
|
818 | 24f9e90b | bellard | /* XXX: maybe use lower level instructions to ease 16 bit / segment handling */
|
819 | 24f9e90b | bellard | |
820 | 24f9e90b | bellard | #define STRING_SUFFIX _fast
|
821 | 24f9e90b | bellard | #define SI_ADDR (void *)ESI |
822 | 24f9e90b | bellard | #define DI_ADDR (void *)EDI |
823 | 24f9e90b | bellard | #define INC_SI() ESI += inc
|
824 | 24f9e90b | bellard | #define INC_DI() EDI += inc
|
825 | 24f9e90b | bellard | #define CX ECX
|
826 | 24f9e90b | bellard | #define DEC_CX() ECX--
|
827 | 24f9e90b | bellard | #include "op_string.h" |
828 | 24f9e90b | bellard | |
829 | 24f9e90b | bellard | #define STRING_SUFFIX _a32
|
830 | 24f9e90b | bellard | #define SI_ADDR (uint8_t *)A0 + ESI
|
831 | 24f9e90b | bellard | #define DI_ADDR env->seg_cache[R_ES].base + EDI
|
832 | 24f9e90b | bellard | #define INC_SI() ESI += inc
|
833 | 24f9e90b | bellard | #define INC_DI() EDI += inc
|
834 | 24f9e90b | bellard | #define CX ECX
|
835 | 24f9e90b | bellard | #define DEC_CX() ECX--
|
836 | 24f9e90b | bellard | #include "op_string.h" |
837 | 24f9e90b | bellard | |
838 | 24f9e90b | bellard | #define STRING_SUFFIX _a16
|
839 | 24f9e90b | bellard | #define SI_ADDR (uint8_t *)A0 + (ESI & 0xffff) |
840 | 24f9e90b | bellard | #define DI_ADDR env->seg_cache[R_ES].base + (EDI & 0xffff) |
841 | 24f9e90b | bellard | #define INC_SI() ESI = (ESI & ~0xffff) | ((ESI + inc) & 0xffff) |
842 | 24f9e90b | bellard | #define INC_DI() EDI = (EDI & ~0xffff) | ((EDI + inc) & 0xffff) |
843 | 24f9e90b | bellard | #define CX (ECX & 0xffff) |
844 | 24f9e90b | bellard | #define DEC_CX() ECX = (ECX & ~0xffff) | ((ECX - 1) & 0xffff) |
845 | 24f9e90b | bellard | #include "op_string.h" |
846 | 367e86e8 | bellard | |
847 | ba1c6e37 | bellard | /* port I/O */
|
848 | ba1c6e37 | bellard | |
849 | ba1c6e37 | bellard | void OPPROTO glue(glue(op_out, SUFFIX), _T0_T1)(void) |
850 | ba1c6e37 | bellard | { |
851 | bf7c65bd | bellard | glue(cpu_x86_out, SUFFIX)(env, T0 & 0xffff, T1 & DATA_MASK);
|
852 | ba1c6e37 | bellard | } |
853 | ba1c6e37 | bellard | |
854 | ba1c6e37 | bellard | void OPPROTO glue(glue(op_in, SUFFIX), _T0_T1)(void) |
855 | ba1c6e37 | bellard | { |
856 | bf7c65bd | bellard | T1 = glue(cpu_x86_in, SUFFIX)(env, T0 & 0xffff);
|
857 | ba1c6e37 | bellard | } |
858 | ba1c6e37 | bellard | |
859 | 367e86e8 | bellard | #undef DATA_BITS
|
860 | 367e86e8 | bellard | #undef SHIFT_MASK
|
861 | 367e86e8 | bellard | #undef SIGN_MASK
|
862 | 367e86e8 | bellard | #undef DATA_TYPE
|
863 | 367e86e8 | bellard | #undef DATA_STYPE
|
864 | 367e86e8 | bellard | #undef DATA_MASK
|
865 | 367e86e8 | bellard | #undef SUFFIX |