2 * i386 micro operations (included several times to generate
3 * different operand sizes)
5 * Copyright (c) 2003 Fabrice Bellard
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.
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.
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
24 #define MEM_SUFFIX b_mem
26 #define MEM_SUFFIX w_mem
28 #define MEM_SUFFIX l_mem
33 #define MEM_SUFFIX SUFFIX
37 void OPPROTO glue(glue(op_rol, MEM_SUFFIX), _T0_T1_cc)(void)
40 count = T1 & SHIFT_MASK;
44 T0 = (T0 << count) | (T0 >> (DATA_BITS - count));
46 glue(st, SUFFIX)((uint8_t *)A0, T0);
48 /* gcc 3.2 workaround. This is really a bug in gcc. */
49 asm volatile("" : : "r" (T0));
51 CC_SRC = (cc_table[CC_OP].compute_all() & ~(CC_O | CC_C)) |
52 (lshift(src ^ T0, 11 - (DATA_BITS - 1)) & CC_O) |
59 void OPPROTO glue(glue(op_ror, MEM_SUFFIX), _T0_T1_cc)(void)
62 count = T1 & SHIFT_MASK;
66 T0 = (T0 >> count) | (T0 << (DATA_BITS - count));
68 glue(st, SUFFIX)((uint8_t *)A0, T0);
70 /* gcc 3.2 workaround. This is really a bug in gcc. */
71 asm volatile("" : : "r" (T0));
73 CC_SRC = (cc_table[CC_OP].compute_all() & ~(CC_O | CC_C)) |
74 (lshift(src ^ T0, 11 - (DATA_BITS - 1)) & CC_O) |
75 ((T0 >> (DATA_BITS - 1)) & CC_C);
81 void OPPROTO glue(glue(op_rol, MEM_SUFFIX), _T0_T1)(void)
84 count = T1 & SHIFT_MASK;
87 T0 = (T0 << count) | (T0 >> (DATA_BITS - count));
89 glue(st, SUFFIX)((uint8_t *)A0, T0);
95 void OPPROTO glue(glue(op_ror, MEM_SUFFIX), _T0_T1)(void)
98 count = T1 & SHIFT_MASK;
101 T0 = (T0 >> count) | (T0 << (DATA_BITS - count));
103 glue(st, SUFFIX)((uint8_t *)A0, T0);
109 void OPPROTO glue(glue(op_rcl, MEM_SUFFIX), _T0_T1_cc)(void)
111 int count, res, eflags;
116 count = rclw_table[count];
118 count = rclb_table[count];
121 eflags = cc_table[CC_OP].compute_all();
124 res = (T0 << count) | ((eflags & CC_C) << (count - 1));
126 res |= T0 >> (DATA_BITS + 1 - count);
129 glue(st, SUFFIX)((uint8_t *)A0, T0);
131 CC_SRC = (eflags & ~(CC_C | CC_O)) |
132 (lshift(src ^ T0, 11 - (DATA_BITS - 1)) & CC_O) |
133 ((src >> (DATA_BITS - count)) & CC_C);
134 CC_OP = CC_OP_EFLAGS;
139 void OPPROTO glue(glue(op_rcr, MEM_SUFFIX), _T0_T1_cc)(void)
141 int count, res, eflags;
146 count = rclw_table[count];
148 count = rclb_table[count];
151 eflags = cc_table[CC_OP].compute_all();
154 res = (T0 >> count) | ((eflags & CC_C) << (DATA_BITS - count));
156 res |= T0 << (DATA_BITS + 1 - count);
159 glue(st, SUFFIX)((uint8_t *)A0, T0);
161 CC_SRC = (eflags & ~(CC_C | CC_O)) |
162 (lshift(src ^ T0, 11 - (DATA_BITS - 1)) & CC_O) |
163 ((src >> (count - 1)) & CC_C);
164 CC_OP = CC_OP_EFLAGS;
169 void OPPROTO glue(glue(op_shl, MEM_SUFFIX), _T0_T1_cc)(void)
174 src = (DATA_TYPE)T0 << (count - 1);
177 glue(st, SUFFIX)((uint8_t *)A0, T0);
181 CC_OP = CC_OP_SHLB + SHIFT;
186 void OPPROTO glue(glue(op_shr, MEM_SUFFIX), _T0_T1_cc)(void)
192 src = T0 >> (count - 1);
195 glue(st, SUFFIX)((uint8_t *)A0, T0);
199 CC_OP = CC_OP_SARB + SHIFT;
204 void OPPROTO glue(glue(op_sar, MEM_SUFFIX), _T0_T1_cc)(void)
209 src = (DATA_STYPE)T0;
211 src = src >> (count - 1);
213 glue(st, SUFFIX)((uint8_t *)A0, T0);
217 CC_OP = CC_OP_SARB + SHIFT;
223 /* XXX: overflow flag might be incorrect in some cases in shldw */
224 void OPPROTO glue(glue(op_shld, MEM_SUFFIX), _T0_T1_im_cc)(void)
227 unsigned int res, tmp;
230 res = T1 | (T0 << 16);
231 tmp = res >> (32 - count);
234 res |= T1 << (count - 16);
237 glue(st, SUFFIX)((uint8_t *)A0, T0);
243 void OPPROTO glue(glue(op_shld, MEM_SUFFIX), _T0_T1_ECX_cc)(void)
246 unsigned int res, tmp;
250 res = T1 | (T0 << 16);
251 tmp = res >> (32 - count);
254 res |= T1 << (count - 16);
257 glue(st, SUFFIX)((uint8_t *)A0, T0);
261 CC_OP = CC_OP_SARB + SHIFT;
266 void OPPROTO glue(glue(op_shrd, MEM_SUFFIX), _T0_T1_im_cc)(void)
269 unsigned int res, tmp;
272 res = (T0 & 0xffff) | (T1 << 16);
273 tmp = res >> (count - 1);
276 res |= T1 << (32 - count);
279 glue(st, SUFFIX)((uint8_t *)A0, T0);
286 void OPPROTO glue(glue(op_shrd, MEM_SUFFIX), _T0_T1_ECX_cc)(void)
289 unsigned int res, tmp;
293 res = (T0 & 0xffff) | (T1 << 16);
294 tmp = res >> (count - 1);
297 res |= T1 << (32 - count);
300 glue(st, SUFFIX)((uint8_t *)A0, T0);
304 CC_OP = CC_OP_SARB + SHIFT;
311 void OPPROTO glue(glue(op_shld, MEM_SUFFIX), _T0_T1_im_cc)(void)
317 tmp = T0 << (count - 1);
318 T0 = (T0 << count) | (T1 >> (DATA_BITS - count));
320 glue(st, SUFFIX)((uint8_t *)A0, T0);
326 void OPPROTO glue(glue(op_shld, MEM_SUFFIX), _T0_T1_ECX_cc)(void)
333 tmp = T0 << (count - 1);
334 T0 = (T0 << count) | (T1 >> (DATA_BITS - count));
336 glue(st, SUFFIX)((uint8_t *)A0, T0);
340 CC_OP = CC_OP_SHLB + SHIFT;
345 void OPPROTO glue(glue(op_shrd, MEM_SUFFIX), _T0_T1_im_cc)(void)
351 tmp = T0 >> (count - 1);
352 T0 = (T0 >> count) | (T1 << (DATA_BITS - count));
354 glue(st, SUFFIX)((uint8_t *)A0, T0);
361 void OPPROTO glue(glue(op_shrd, MEM_SUFFIX), _T0_T1_ECX_cc)(void)
368 tmp = T0 >> (count - 1);
369 T0 = (T0 >> count) | (T1 << (DATA_BITS - count));
371 glue(st, SUFFIX)((uint8_t *)A0, T0);
375 CC_OP = CC_OP_SARB + SHIFT;
381 /* carry add/sub (we only need to set CC_OP differently) */
383 void OPPROTO glue(glue(op_adc, MEM_SUFFIX), _T0_T1_cc)(void)
386 cf = cc_table[CC_OP].compute_c();
389 glue(st, SUFFIX)((uint8_t *)A0, T0);
393 CC_OP = CC_OP_ADDB + SHIFT + cf * 3;
396 void OPPROTO glue(glue(op_sbb, MEM_SUFFIX), _T0_T1_cc)(void)
399 cf = cc_table[CC_OP].compute_c();
402 glue(st, SUFFIX)((uint8_t *)A0, T0);
406 CC_OP = CC_OP_SUBB + SHIFT + cf * 3;
409 void OPPROTO glue(glue(op_cmpxchg, MEM_SUFFIX), _T0_T1_EAX_cc)(void)
411 unsigned int src, dst;
415 if ((DATA_TYPE)dst == 0) {
418 EAX = (EAX & ~DATA_MASK) | (T0 & DATA_MASK);
421 glue(st, SUFFIX)((uint8_t *)A0, T0);