]> Git Repo - qemu.git/blame - target-i386/ops_template.h
converted condition code supprot to TCG - converted shift ops to TCG
[qemu.git] / target-i386 / ops_template.h
CommitLineData
2c0262af
FB
1/*
2 * i386 micro operations (included several times to generate
3 * different operand sizes)
5fafdf24 4 *
2c0262af
FB
5 * Copyright (c) 2003 Fabrice Bellard
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21#define DATA_BITS (1 << (3 + SHIFT))
22#define SHIFT_MASK (DATA_BITS - 1)
14ce26e7
FB
23#define SIGN_MASK (((target_ulong)1) << (DATA_BITS - 1))
24#if DATA_BITS <= 32
25#define SHIFT1_MASK 0x1f
26#else
27#define SHIFT1_MASK 0x3f
28#endif
2c0262af
FB
29
30#if DATA_BITS == 8
31#define SUFFIX b
32#define DATA_TYPE uint8_t
33#define DATA_STYPE int8_t
34#define DATA_MASK 0xff
35#elif DATA_BITS == 16
36#define SUFFIX w
37#define DATA_TYPE uint16_t
38#define DATA_STYPE int16_t
39#define DATA_MASK 0xffff
40#elif DATA_BITS == 32
41#define SUFFIX l
42#define DATA_TYPE uint32_t
43#define DATA_STYPE int32_t
44#define DATA_MASK 0xffffffff
14ce26e7
FB
45#elif DATA_BITS == 64
46#define SUFFIX q
47#define DATA_TYPE uint64_t
48#define DATA_STYPE int64_t
977d5710 49#define DATA_MASK 0xffffffffffffffffULL
2c0262af
FB
50#else
51#error unhandled operand size
52#endif
53
54/* dynamic flags computation */
55
56static int glue(compute_all_add, SUFFIX)(void)
57{
58 int cf, pf, af, zf, sf, of;
14ce26e7 59 target_long src1, src2;
2c0262af
FB
60 src1 = CC_SRC;
61 src2 = CC_DST - CC_SRC;
62 cf = (DATA_TYPE)CC_DST < (DATA_TYPE)src1;
63 pf = parity_table[(uint8_t)CC_DST];
64 af = (CC_DST ^ src1 ^ src2) & 0x10;
65 zf = ((DATA_TYPE)CC_DST == 0) << 6;
66 sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
67 of = lshift((src1 ^ src2 ^ -1) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O;
68 return cf | pf | af | zf | sf | of;
69}
70
71static int glue(compute_c_add, SUFFIX)(void)
72{
14ce26e7
FB
73 int cf;
74 target_long src1;
2c0262af
FB
75 src1 = CC_SRC;
76 cf = (DATA_TYPE)CC_DST < (DATA_TYPE)src1;
77 return cf;
78}
79
80static int glue(compute_all_adc, SUFFIX)(void)
81{
82 int cf, pf, af, zf, sf, of;
14ce26e7 83 target_long src1, src2;
2c0262af
FB
84 src1 = CC_SRC;
85 src2 = CC_DST - CC_SRC - 1;
86 cf = (DATA_TYPE)CC_DST <= (DATA_TYPE)src1;
87 pf = parity_table[(uint8_t)CC_DST];
88 af = (CC_DST ^ src1 ^ src2) & 0x10;
89 zf = ((DATA_TYPE)CC_DST == 0) << 6;
90 sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
91 of = lshift((src1 ^ src2 ^ -1) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O;
92 return cf | pf | af | zf | sf | of;
93}
94
95static int glue(compute_c_adc, SUFFIX)(void)
96{
14ce26e7
FB
97 int cf;
98 target_long src1;
2c0262af
FB
99 src1 = CC_SRC;
100 cf = (DATA_TYPE)CC_DST <= (DATA_TYPE)src1;
101 return cf;
102}
103
104static int glue(compute_all_sub, SUFFIX)(void)
105{
106 int cf, pf, af, zf, sf, of;
14ce26e7 107 target_long src1, src2;
2c0262af
FB
108 src1 = CC_DST + CC_SRC;
109 src2 = CC_SRC;
110 cf = (DATA_TYPE)src1 < (DATA_TYPE)src2;
111 pf = parity_table[(uint8_t)CC_DST];
112 af = (CC_DST ^ src1 ^ src2) & 0x10;
113 zf = ((DATA_TYPE)CC_DST == 0) << 6;
114 sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
115 of = lshift((src1 ^ src2) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O;
116 return cf | pf | af | zf | sf | of;
117}
118
119static int glue(compute_c_sub, SUFFIX)(void)
120{
14ce26e7
FB
121 int cf;
122 target_long src1, src2;
2c0262af
FB
123 src1 = CC_DST + CC_SRC;
124 src2 = CC_SRC;
125 cf = (DATA_TYPE)src1 < (DATA_TYPE)src2;
126 return cf;
127}
128
129static int glue(compute_all_sbb, SUFFIX)(void)
130{
131 int cf, pf, af, zf, sf, of;
14ce26e7 132 target_long src1, src2;
2c0262af
FB
133 src1 = CC_DST + CC_SRC + 1;
134 src2 = CC_SRC;
135 cf = (DATA_TYPE)src1 <= (DATA_TYPE)src2;
136 pf = parity_table[(uint8_t)CC_DST];
137 af = (CC_DST ^ src1 ^ src2) & 0x10;
138 zf = ((DATA_TYPE)CC_DST == 0) << 6;
139 sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
140 of = lshift((src1 ^ src2) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O;
141 return cf | pf | af | zf | sf | of;
142}
143
144static int glue(compute_c_sbb, SUFFIX)(void)
145{
14ce26e7
FB
146 int cf;
147 target_long src1, src2;
2c0262af
FB
148 src1 = CC_DST + CC_SRC + 1;
149 src2 = CC_SRC;
150 cf = (DATA_TYPE)src1 <= (DATA_TYPE)src2;
151 return cf;
152}
153
154static int glue(compute_all_logic, SUFFIX)(void)
155{
156 int cf, pf, af, zf, sf, of;
157 cf = 0;
158 pf = parity_table[(uint8_t)CC_DST];
159 af = 0;
160 zf = ((DATA_TYPE)CC_DST == 0) << 6;
161 sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
162 of = 0;
163 return cf | pf | af | zf | sf | of;
164}
165
166static int glue(compute_c_logic, SUFFIX)(void)
167{
168 return 0;
169}
170
171static int glue(compute_all_inc, SUFFIX)(void)
172{
173 int cf, pf, af, zf, sf, of;
14ce26e7 174 target_long src1, src2;
2c0262af
FB
175 src1 = CC_DST - 1;
176 src2 = 1;
177 cf = CC_SRC;
178 pf = parity_table[(uint8_t)CC_DST];
179 af = (CC_DST ^ src1 ^ src2) & 0x10;
180 zf = ((DATA_TYPE)CC_DST == 0) << 6;
181 sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
182 of = ((CC_DST & DATA_MASK) == SIGN_MASK) << 11;
183 return cf | pf | af | zf | sf | of;
184}
185
186#if DATA_BITS == 32
187static int glue(compute_c_inc, SUFFIX)(void)
188{
189 return CC_SRC;
190}
191#endif
192
193static int glue(compute_all_dec, SUFFIX)(void)
194{
195 int cf, pf, af, zf, sf, of;
14ce26e7 196 target_long src1, src2;
2c0262af
FB
197 src1 = CC_DST + 1;
198 src2 = 1;
199 cf = CC_SRC;
200 pf = parity_table[(uint8_t)CC_DST];
201 af = (CC_DST ^ src1 ^ src2) & 0x10;
202 zf = ((DATA_TYPE)CC_DST == 0) << 6;
203 sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
14ce26e7 204 of = ((CC_DST & DATA_MASK) == ((target_ulong)SIGN_MASK - 1)) << 11;
2c0262af
FB
205 return cf | pf | af | zf | sf | of;
206}
207
208static int glue(compute_all_shl, SUFFIX)(void)
209{
210 int cf, pf, af, zf, sf, of;
211 cf = (CC_SRC >> (DATA_BITS - 1)) & CC_C;
212 pf = parity_table[(uint8_t)CC_DST];
213 af = 0; /* undefined */
214 zf = ((DATA_TYPE)CC_DST == 0) << 6;
215 sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
216 /* of is defined if shift count == 1 */
217 of = lshift(CC_SRC ^ CC_DST, 12 - DATA_BITS) & CC_O;
218 return cf | pf | af | zf | sf | of;
219}
220
221static int glue(compute_c_shl, SUFFIX)(void)
222{
223 return (CC_SRC >> (DATA_BITS - 1)) & CC_C;
224}
225
226#if DATA_BITS == 32
227static int glue(compute_c_sar, SUFFIX)(void)
228{
229 return CC_SRC & 1;
230}
231#endif
232
233static int glue(compute_all_sar, SUFFIX)(void)
234{
235 int cf, pf, af, zf, sf, of;
236 cf = CC_SRC & 1;
237 pf = parity_table[(uint8_t)CC_DST];
238 af = 0; /* undefined */
239 zf = ((DATA_TYPE)CC_DST == 0) << 6;
240 sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
241 /* of is defined if shift count == 1 */
5fafdf24 242 of = lshift(CC_SRC ^ CC_DST, 12 - DATA_BITS) & CC_O;
2c0262af
FB
243 return cf | pf | af | zf | sf | of;
244}
245
d36cd60e
FB
246#if DATA_BITS == 32
247static int glue(compute_c_mul, SUFFIX)(void)
248{
249 int cf;
250 cf = (CC_SRC != 0);
251 return cf;
252}
253#endif
254
255/* NOTE: we compute the flags like the P4. On olders CPUs, only OF and
256 CF are modified and it is slower to do that. */
257static int glue(compute_all_mul, SUFFIX)(void)
258{
259 int cf, pf, af, zf, sf, of;
260 cf = (CC_SRC != 0);
261 pf = parity_table[(uint8_t)CC_DST];
262 af = 0; /* undefined */
263 zf = ((DATA_TYPE)CC_DST == 0) << 6;
264 sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
265 of = cf << 11;
266 return cf | pf | af | zf | sf | of;
267}
268
2c0262af
FB
269/* various optimized jumps cases */
270
271void OPPROTO glue(op_jb_sub, SUFFIX)(void)
272{
14ce26e7 273 target_long src1, src2;
2c0262af
FB
274 src1 = CC_DST + CC_SRC;
275 src2 = CC_SRC;
276
277 if ((DATA_TYPE)src1 < (DATA_TYPE)src2)
14ce26e7 278 GOTO_LABEL_PARAM(1);
2c0262af
FB
279 FORCE_RET();
280}
281
282void OPPROTO glue(op_jz_sub, SUFFIX)(void)
283{
284 if ((DATA_TYPE)CC_DST == 0)
14ce26e7
FB
285 GOTO_LABEL_PARAM(1);
286 FORCE_RET();
287}
288
289void OPPROTO glue(op_jnz_sub, SUFFIX)(void)
290{
291 if ((DATA_TYPE)CC_DST != 0)
292 GOTO_LABEL_PARAM(1);
2c0262af
FB
293 FORCE_RET();
294}
295
296void OPPROTO glue(op_jbe_sub, SUFFIX)(void)
297{
14ce26e7 298 target_long src1, src2;
2c0262af
FB
299 src1 = CC_DST + CC_SRC;
300 src2 = CC_SRC;
301
302 if ((DATA_TYPE)src1 <= (DATA_TYPE)src2)
14ce26e7 303 GOTO_LABEL_PARAM(1);
2c0262af
FB
304 FORCE_RET();
305}
306
307void OPPROTO glue(op_js_sub, SUFFIX)(void)
308{
309 if (CC_DST & SIGN_MASK)
14ce26e7 310 GOTO_LABEL_PARAM(1);
2c0262af
FB
311 FORCE_RET();
312}
313
314void OPPROTO glue(op_jl_sub, SUFFIX)(void)
315{
14ce26e7 316 target_long src1, src2;
2c0262af
FB
317 src1 = CC_DST + CC_SRC;
318 src2 = CC_SRC;
319
320 if ((DATA_STYPE)src1 < (DATA_STYPE)src2)
14ce26e7 321 GOTO_LABEL_PARAM(1);
2c0262af
FB
322 FORCE_RET();
323}
324
325void OPPROTO glue(op_jle_sub, SUFFIX)(void)
326{
14ce26e7 327 target_long src1, src2;
2c0262af
FB
328 src1 = CC_DST + CC_SRC;
329 src2 = CC_SRC;
330
331 if ((DATA_STYPE)src1 <= (DATA_STYPE)src2)
14ce26e7 332 GOTO_LABEL_PARAM(1);
2c0262af
FB
333 FORCE_RET();
334}
335
336/* oldies */
337
338#if DATA_BITS >= 16
339
340void OPPROTO glue(op_loopnz, SUFFIX)(void)
341{
0b9dc5e4 342 if ((DATA_TYPE)ECX != 0 && !(T0 & CC_Z))
14ce26e7 343 GOTO_LABEL_PARAM(1);
2c0262af
FB
344 FORCE_RET();
345}
346
347void OPPROTO glue(op_loopz, SUFFIX)(void)
348{
0b9dc5e4 349 if ((DATA_TYPE)ECX != 0 && (T0 & CC_Z))
14ce26e7 350 GOTO_LABEL_PARAM(1);
2c0262af
FB
351 FORCE_RET();
352}
353
14ce26e7 354void OPPROTO glue(op_jz_ecx, SUFFIX)(void)
2c0262af 355{
14ce26e7
FB
356 if ((DATA_TYPE)ECX == 0)
357 GOTO_LABEL_PARAM(1);
2c0262af
FB
358 FORCE_RET();
359}
360
14ce26e7 361void OPPROTO glue(op_jnz_ecx, SUFFIX)(void)
2c0262af 362{
14ce26e7
FB
363 if ((DATA_TYPE)ECX != 0)
364 GOTO_LABEL_PARAM(1);
2c0262af
FB
365 FORCE_RET();
366}
367
368#endif
369
370/* various optimized set cases */
371
372void OPPROTO glue(op_setb_T0_sub, SUFFIX)(void)
373{
14ce26e7 374 target_long src1, src2;
2c0262af
FB
375 src1 = CC_DST + CC_SRC;
376 src2 = CC_SRC;
377
378 T0 = ((DATA_TYPE)src1 < (DATA_TYPE)src2);
379}
380
381void OPPROTO glue(op_setz_T0_sub, SUFFIX)(void)
382{
383 T0 = ((DATA_TYPE)CC_DST == 0);
384}
385
386void OPPROTO glue(op_setbe_T0_sub, SUFFIX)(void)
387{
14ce26e7 388 target_long src1, src2;
2c0262af
FB
389 src1 = CC_DST + CC_SRC;
390 src2 = CC_SRC;
391
392 T0 = ((DATA_TYPE)src1 <= (DATA_TYPE)src2);
393}
394
395void OPPROTO glue(op_sets_T0_sub, SUFFIX)(void)
396{
397 T0 = lshift(CC_DST, -(DATA_BITS - 1)) & 1;
398}
399
400void OPPROTO glue(op_setl_T0_sub, SUFFIX)(void)
401{
14ce26e7 402 target_long src1, src2;
2c0262af
FB
403 src1 = CC_DST + CC_SRC;
404 src2 = CC_SRC;
405
406 T0 = ((DATA_STYPE)src1 < (DATA_STYPE)src2);
407}
408
409void OPPROTO glue(op_setle_T0_sub, SUFFIX)(void)
410{
14ce26e7 411 target_long src1, src2;
2c0262af
FB
412 src1 = CC_DST + CC_SRC;
413 src2 = CC_SRC;
414
415 T0 = ((DATA_STYPE)src1 <= (DATA_STYPE)src2);
416}
417
2c0262af
FB
418#undef MEM_WRITE
419#include "ops_template_mem.h"
420
34e01bbf 421#define MEM_WRITE 0
2c0262af
FB
422#include "ops_template_mem.h"
423
34e01bbf
FB
424#if !defined(CONFIG_USER_ONLY)
425#define MEM_WRITE 1
426#include "ops_template_mem.h"
427
428#define MEM_WRITE 2
429#include "ops_template_mem.h"
430#endif
431
2c0262af
FB
432/* bit operations */
433#if DATA_BITS >= 16
434
435void OPPROTO glue(glue(op_bt, SUFFIX), _T0_T1_cc)(void)
436{
437 int count;
438 count = T1 & SHIFT_MASK;
439 CC_SRC = T0 >> count;
440}
441
442void OPPROTO glue(glue(op_bts, SUFFIX), _T0_T1_cc)(void)
443{
444 int count;
445 count = T1 & SHIFT_MASK;
446 T1 = T0 >> count;
14ce26e7 447 T0 |= (((target_long)1) << count);
2c0262af
FB
448}
449
450void OPPROTO glue(glue(op_btr, SUFFIX), _T0_T1_cc)(void)
451{
452 int count;
453 count = T1 & SHIFT_MASK;
454 T1 = T0 >> count;
14ce26e7 455 T0 &= ~(((target_long)1) << count);
2c0262af
FB
456}
457
458void OPPROTO glue(glue(op_btc, SUFFIX), _T0_T1_cc)(void)
459{
460 int count;
461 count = T1 & SHIFT_MASK;
462 T1 = T0 >> count;
14ce26e7
FB
463 T0 ^= (((target_long)1) << count);
464}
465
466void OPPROTO glue(glue(op_add_bit, SUFFIX), _A0_T1)(void)
467{
468 A0 += ((DATA_STYPE)T1 >> (3 + SHIFT)) << SHIFT;
2c0262af
FB
469}
470
471void OPPROTO glue(glue(op_bsf, SUFFIX), _T0_cc)(void)
472{
14ce26e7
FB
473 int count;
474 target_long res;
3b46e624 475
2c0262af
FB
476 res = T0 & DATA_MASK;
477 if (res != 0) {
478 count = 0;
479 while ((res & 1) == 0) {
480 count++;
481 res >>= 1;
482 }
686f3f26 483 T1 = count;
debf7a7c 484 CC_DST = 1; /* ZF = 0 */
2c0262af
FB
485 } else {
486 CC_DST = 0; /* ZF = 1 */
487 }
488 FORCE_RET();
489}
490
491void OPPROTO glue(glue(op_bsr, SUFFIX), _T0_cc)(void)
492{
14ce26e7
FB
493 int count;
494 target_long res;
495
2c0262af
FB
496 res = T0 & DATA_MASK;
497 if (res != 0) {
498 count = DATA_BITS - 1;
499 while ((res & SIGN_MASK) == 0) {
500 count--;
501 res <<= 1;
502 }
686f3f26 503 T1 = count;
debf7a7c 504 CC_DST = 1; /* ZF = 0 */
2c0262af
FB
505 } else {
506 CC_DST = 0; /* ZF = 1 */
507 }
508 FORCE_RET();
509}
510
511#endif
512
513#if DATA_BITS == 32
514void OPPROTO op_update_bt_cc(void)
515{
516 CC_SRC = T1;
517}
518#endif
519
520/* string operations */
521
522void OPPROTO glue(op_movl_T0_Dshift, SUFFIX)(void)
523{
524 T0 = DF << SHIFT;
525}
526
2c0262af
FB
527#undef DATA_BITS
528#undef SHIFT_MASK
14ce26e7 529#undef SHIFT1_MASK
2c0262af
FB
530#undef SIGN_MASK
531#undef DATA_TYPE
532#undef DATA_STYPE
533#undef DATA_MASK
534#undef SUFFIX
This page took 0.226166 seconds and 4 git commands to generate.