2 * Tiny Code Generator for QEMU
4 * Copyright (c) 2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 int gen_new_label(void);
28 static inline void tcg_gen_op1_i32(TCGOpcode opc, TCGv_i32 arg1)
31 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
34 static inline void tcg_gen_op1_i64(TCGOpcode opc, TCGv_i64 arg1)
37 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
40 static inline void tcg_gen_op1i(TCGOpcode opc, TCGArg arg1)
43 *gen_opparam_ptr++ = arg1;
46 static inline void tcg_gen_op2_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2)
49 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
50 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
53 static inline void tcg_gen_op2_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2)
56 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
57 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
60 static inline void tcg_gen_op2i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGArg arg2)
63 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
64 *gen_opparam_ptr++ = arg2;
67 static inline void tcg_gen_op2i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGArg arg2)
70 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
71 *gen_opparam_ptr++ = arg2;
74 static inline void tcg_gen_op2ii(TCGOpcode opc, TCGArg arg1, TCGArg arg2)
77 *gen_opparam_ptr++ = arg1;
78 *gen_opparam_ptr++ = arg2;
81 static inline void tcg_gen_op3_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
85 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
86 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
87 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
90 static inline void tcg_gen_op3_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
94 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
95 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
96 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
99 static inline void tcg_gen_op3i_i32(TCGOpcode opc, TCGv_i32 arg1,
100 TCGv_i32 arg2, TCGArg arg3)
102 *gen_opc_ptr++ = opc;
103 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
104 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
105 *gen_opparam_ptr++ = arg3;
108 static inline void tcg_gen_op3i_i64(TCGOpcode opc, TCGv_i64 arg1,
109 TCGv_i64 arg2, TCGArg arg3)
111 *gen_opc_ptr++ = opc;
112 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
113 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
114 *gen_opparam_ptr++ = arg3;
117 static inline void tcg_gen_ldst_op_i32(TCGOpcode opc, TCGv_i32 val,
118 TCGv_ptr base, TCGArg offset)
120 *gen_opc_ptr++ = opc;
121 *gen_opparam_ptr++ = GET_TCGV_I32(val);
122 *gen_opparam_ptr++ = GET_TCGV_PTR(base);
123 *gen_opparam_ptr++ = offset;
126 static inline void tcg_gen_ldst_op_i64(TCGOpcode opc, TCGv_i64 val,
127 TCGv_ptr base, TCGArg offset)
129 *gen_opc_ptr++ = opc;
130 *gen_opparam_ptr++ = GET_TCGV_I64(val);
131 *gen_opparam_ptr++ = GET_TCGV_PTR(base);
132 *gen_opparam_ptr++ = offset;
135 static inline void tcg_gen_qemu_ldst_op_i64_i32(TCGOpcode opc, TCGv_i64 val,
136 TCGv_i32 addr, TCGArg mem_index)
138 *gen_opc_ptr++ = opc;
139 *gen_opparam_ptr++ = GET_TCGV_I64(val);
140 *gen_opparam_ptr++ = GET_TCGV_I32(addr);
141 *gen_opparam_ptr++ = mem_index;
144 static inline void tcg_gen_qemu_ldst_op_i64_i64(TCGOpcode opc, TCGv_i64 val,
145 TCGv_i64 addr, TCGArg mem_index)
147 *gen_opc_ptr++ = opc;
148 *gen_opparam_ptr++ = GET_TCGV_I64(val);
149 *gen_opparam_ptr++ = GET_TCGV_I64(addr);
150 *gen_opparam_ptr++ = mem_index;
153 static inline void tcg_gen_op4_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
154 TCGv_i32 arg3, TCGv_i32 arg4)
156 *gen_opc_ptr++ = opc;
157 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
158 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
159 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
160 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
163 static inline void tcg_gen_op4_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
164 TCGv_i64 arg3, TCGv_i64 arg4)
166 *gen_opc_ptr++ = opc;
167 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
168 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
169 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
170 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
173 static inline void tcg_gen_op4i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
174 TCGv_i32 arg3, TCGArg arg4)
176 *gen_opc_ptr++ = opc;
177 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
178 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
179 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
180 *gen_opparam_ptr++ = arg4;
183 static inline void tcg_gen_op4i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
184 TCGv_i64 arg3, TCGArg arg4)
186 *gen_opc_ptr++ = opc;
187 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
188 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
189 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
190 *gen_opparam_ptr++ = arg4;
193 static inline void tcg_gen_op4ii_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
194 TCGArg arg3, TCGArg arg4)
196 *gen_opc_ptr++ = opc;
197 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
198 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
199 *gen_opparam_ptr++ = arg3;
200 *gen_opparam_ptr++ = arg4;
203 static inline void tcg_gen_op4ii_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
204 TCGArg arg3, TCGArg arg4)
206 *gen_opc_ptr++ = opc;
207 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
208 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
209 *gen_opparam_ptr++ = arg3;
210 *gen_opparam_ptr++ = arg4;
213 static inline void tcg_gen_op5_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
214 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5)
216 *gen_opc_ptr++ = opc;
217 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
218 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
219 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
220 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
221 *gen_opparam_ptr++ = GET_TCGV_I32(arg5);
224 static inline void tcg_gen_op5_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
225 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5)
227 *gen_opc_ptr++ = opc;
228 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
229 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
230 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
231 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
232 *gen_opparam_ptr++ = GET_TCGV_I64(arg5);
235 static inline void tcg_gen_op5i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
236 TCGv_i32 arg3, TCGv_i32 arg4, TCGArg arg5)
238 *gen_opc_ptr++ = opc;
239 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
240 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
241 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
242 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
243 *gen_opparam_ptr++ = arg5;
246 static inline void tcg_gen_op5i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
247 TCGv_i64 arg3, TCGv_i64 arg4, TCGArg arg5)
249 *gen_opc_ptr++ = opc;
250 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
251 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
252 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
253 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
254 *gen_opparam_ptr++ = arg5;
257 static inline void tcg_gen_op5ii_i32(TCGOpcode opc, TCGv_i32 arg1,
258 TCGv_i32 arg2, TCGv_i32 arg3,
259 TCGArg arg4, TCGArg arg5)
261 *gen_opc_ptr++ = opc;
262 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
263 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
264 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
265 *gen_opparam_ptr++ = arg4;
266 *gen_opparam_ptr++ = arg5;
269 static inline void tcg_gen_op5ii_i64(TCGOpcode opc, TCGv_i64 arg1,
270 TCGv_i64 arg2, TCGv_i64 arg3,
271 TCGArg arg4, TCGArg arg5)
273 *gen_opc_ptr++ = opc;
274 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
275 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
276 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
277 *gen_opparam_ptr++ = arg4;
278 *gen_opparam_ptr++ = arg5;
281 static inline void tcg_gen_op6_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
282 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5,
285 *gen_opc_ptr++ = opc;
286 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
287 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
288 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
289 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
290 *gen_opparam_ptr++ = GET_TCGV_I32(arg5);
291 *gen_opparam_ptr++ = GET_TCGV_I32(arg6);
294 static inline void tcg_gen_op6_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
295 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5,
298 *gen_opc_ptr++ = opc;
299 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
300 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
301 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
302 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
303 *gen_opparam_ptr++ = GET_TCGV_I64(arg5);
304 *gen_opparam_ptr++ = GET_TCGV_I64(arg6);
307 static inline void tcg_gen_op6i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
308 TCGv_i32 arg3, TCGv_i32 arg4,
309 TCGv_i32 arg5, TCGArg arg6)
311 *gen_opc_ptr++ = opc;
312 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
313 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
314 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
315 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
316 *gen_opparam_ptr++ = GET_TCGV_I32(arg5);
317 *gen_opparam_ptr++ = arg6;
320 static inline void tcg_gen_op6i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
321 TCGv_i64 arg3, TCGv_i64 arg4,
322 TCGv_i64 arg5, TCGArg arg6)
324 *gen_opc_ptr++ = opc;
325 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
326 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
327 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
328 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
329 *gen_opparam_ptr++ = GET_TCGV_I64(arg5);
330 *gen_opparam_ptr++ = arg6;
333 static inline void tcg_gen_op6ii_i32(TCGOpcode opc, TCGv_i32 arg1,
334 TCGv_i32 arg2, TCGv_i32 arg3,
335 TCGv_i32 arg4, TCGArg arg5, TCGArg arg6)
337 *gen_opc_ptr++ = opc;
338 *gen_opparam_ptr++ = GET_TCGV_I32(arg1);
339 *gen_opparam_ptr++ = GET_TCGV_I32(arg2);
340 *gen_opparam_ptr++ = GET_TCGV_I32(arg3);
341 *gen_opparam_ptr++ = GET_TCGV_I32(arg4);
342 *gen_opparam_ptr++ = arg5;
343 *gen_opparam_ptr++ = arg6;
346 static inline void tcg_gen_op6ii_i64(TCGOpcode opc, TCGv_i64 arg1,
347 TCGv_i64 arg2, TCGv_i64 arg3,
348 TCGv_i64 arg4, TCGArg arg5, TCGArg arg6)
350 *gen_opc_ptr++ = opc;
351 *gen_opparam_ptr++ = GET_TCGV_I64(arg1);
352 *gen_opparam_ptr++ = GET_TCGV_I64(arg2);
353 *gen_opparam_ptr++ = GET_TCGV_I64(arg3);
354 *gen_opparam_ptr++ = GET_TCGV_I64(arg4);
355 *gen_opparam_ptr++ = arg5;
356 *gen_opparam_ptr++ = arg6;
359 static inline void gen_set_label(int n)
361 tcg_gen_op1i(INDEX_op_set_label, n);
364 static inline void tcg_gen_br(int label)
366 tcg_gen_op1i(INDEX_op_br, label);
369 static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
371 if (!TCGV_EQUAL_I32(ret, arg))
372 tcg_gen_op2_i32(INDEX_op_mov_i32, ret, arg);
375 static inline void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
377 tcg_gen_op2i_i32(INDEX_op_movi_i32, ret, arg);
380 /* A version of dh_sizemask from def-helper.h that doesn't rely on
381 preprocessor magic. */
382 static inline int tcg_gen_sizemask(int n, int is_64bit, int is_signed)
384 return (is_64bit << n*2) | (is_signed << (n*2 + 1));
388 static inline void tcg_gen_helperN(void *func, int flags, int sizemask,
389 TCGArg ret, int nargs, TCGArg *args)
392 fn = tcg_const_ptr(func);
393 tcg_gen_callN(&tcg_ctx, fn, flags, sizemask, ret,
395 tcg_temp_free_ptr(fn);
398 /* Note: Both tcg_gen_helper32() and tcg_gen_helper64() are currently
399 reserved for helpers in tcg-runtime.c. These helpers are all const
400 and pure, hence the call to tcg_gen_callN() with TCG_CALL_CONST |
401 TCG_CALL_PURE. This may need to be adjusted if these functions
402 start to be used with other helpers. */
403 static inline void tcg_gen_helper32(void *func, int sizemask, TCGv_i32 ret,
404 TCGv_i32 a, TCGv_i32 b)
408 fn = tcg_const_ptr(func);
409 args[0] = GET_TCGV_I32(a);
410 args[1] = GET_TCGV_I32(b);
411 tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE, sizemask,
412 GET_TCGV_I32(ret), 2, args);
413 tcg_temp_free_ptr(fn);
416 static inline void tcg_gen_helper64(void *func, int sizemask, TCGv_i64 ret,
417 TCGv_i64 a, TCGv_i64 b)
421 fn = tcg_const_ptr(func);
422 args[0] = GET_TCGV_I64(a);
423 args[1] = GET_TCGV_I64(b);
424 tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE, sizemask,
425 GET_TCGV_I64(ret), 2, args);
426 tcg_temp_free_ptr(fn);
431 static inline void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
433 tcg_gen_ldst_op_i32(INDEX_op_ld8u_i32, ret, arg2, offset);
436 static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
438 tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
441 static inline void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
443 tcg_gen_ldst_op_i32(INDEX_op_ld16u_i32, ret, arg2, offset);
446 static inline void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
448 tcg_gen_ldst_op_i32(INDEX_op_ld16s_i32, ret, arg2, offset);
451 static inline void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
453 tcg_gen_ldst_op_i32(INDEX_op_ld_i32, ret, arg2, offset);
456 static inline void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
458 tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
461 static inline void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
463 tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
466 static inline void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
468 tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
471 static inline void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
473 tcg_gen_op3_i32(INDEX_op_add_i32, ret, arg1, arg2);
476 static inline void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
478 /* some cases can be optimized here */
480 tcg_gen_mov_i32(ret, arg1);
482 TCGv_i32 t0 = tcg_const_i32(arg2);
483 tcg_gen_add_i32(ret, arg1, t0);
484 tcg_temp_free_i32(t0);
488 static inline void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
490 tcg_gen_op3_i32(INDEX_op_sub_i32, ret, arg1, arg2);
493 static inline void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
495 TCGv_i32 t0 = tcg_const_i32(arg1);
496 tcg_gen_sub_i32(ret, t0, arg2);
497 tcg_temp_free_i32(t0);
500 static inline void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
502 /* some cases can be optimized here */
504 tcg_gen_mov_i32(ret, arg1);
506 TCGv_i32 t0 = tcg_const_i32(arg2);
507 tcg_gen_sub_i32(ret, arg1, t0);
508 tcg_temp_free_i32(t0);
512 static inline void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
514 if (TCGV_EQUAL_I32(arg1, arg2)) {
515 tcg_gen_mov_i32(ret, arg1);
517 tcg_gen_op3_i32(INDEX_op_and_i32, ret, arg1, arg2);
521 static inline void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
523 /* some cases can be optimized here */
525 tcg_gen_movi_i32(ret, 0);
526 } else if (arg2 == 0xffffffff) {
527 tcg_gen_mov_i32(ret, arg1);
529 TCGv_i32 t0 = tcg_const_i32(arg2);
530 tcg_gen_and_i32(ret, arg1, t0);
531 tcg_temp_free_i32(t0);
535 static inline void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
537 if (TCGV_EQUAL_I32(arg1, arg2)) {
538 tcg_gen_mov_i32(ret, arg1);
540 tcg_gen_op3_i32(INDEX_op_or_i32, ret, arg1, arg2);
544 static inline void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
546 /* some cases can be optimized here */
547 if (arg2 == 0xffffffff) {
548 tcg_gen_movi_i32(ret, 0xffffffff);
549 } else if (arg2 == 0) {
550 tcg_gen_mov_i32(ret, arg1);
552 TCGv_i32 t0 = tcg_const_i32(arg2);
553 tcg_gen_or_i32(ret, arg1, t0);
554 tcg_temp_free_i32(t0);
558 static inline void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
560 if (TCGV_EQUAL_I32(arg1, arg2)) {
561 tcg_gen_movi_i32(ret, 0);
563 tcg_gen_op3_i32(INDEX_op_xor_i32, ret, arg1, arg2);
567 static inline void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
569 /* some cases can be optimized here */
571 tcg_gen_mov_i32(ret, arg1);
573 TCGv_i32 t0 = tcg_const_i32(arg2);
574 tcg_gen_xor_i32(ret, arg1, t0);
575 tcg_temp_free_i32(t0);
579 static inline void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
581 tcg_gen_op3_i32(INDEX_op_shl_i32, ret, arg1, arg2);
584 static inline void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
587 tcg_gen_mov_i32(ret, arg1);
589 TCGv_i32 t0 = tcg_const_i32(arg2);
590 tcg_gen_shl_i32(ret, arg1, t0);
591 tcg_temp_free_i32(t0);
595 static inline void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
597 tcg_gen_op3_i32(INDEX_op_shr_i32, ret, arg1, arg2);
600 static inline void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
603 tcg_gen_mov_i32(ret, arg1);
605 TCGv_i32 t0 = tcg_const_i32(arg2);
606 tcg_gen_shr_i32(ret, arg1, t0);
607 tcg_temp_free_i32(t0);
611 static inline void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
613 tcg_gen_op3_i32(INDEX_op_sar_i32, ret, arg1, arg2);
616 static inline void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
619 tcg_gen_mov_i32(ret, arg1);
621 TCGv_i32 t0 = tcg_const_i32(arg2);
622 tcg_gen_sar_i32(ret, arg1, t0);
623 tcg_temp_free_i32(t0);
627 static inline void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1,
628 TCGv_i32 arg2, int label_index)
630 tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
633 static inline void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1,
634 int32_t arg2, int label_index)
636 TCGv_i32 t0 = tcg_const_i32(arg2);
637 tcg_gen_brcond_i32(cond, arg1, t0, label_index);
638 tcg_temp_free_i32(t0);
641 static inline void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
642 TCGv_i32 arg1, TCGv_i32 arg2)
644 tcg_gen_op4i_i32(INDEX_op_setcond_i32, ret, arg1, arg2, cond);
647 static inline void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
648 TCGv_i32 arg1, int32_t arg2)
650 TCGv_i32 t0 = tcg_const_i32(arg2);
651 tcg_gen_setcond_i32(cond, ret, arg1, t0);
652 tcg_temp_free_i32(t0);
655 static inline void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
657 tcg_gen_op3_i32(INDEX_op_mul_i32, ret, arg1, arg2);
660 static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
662 TCGv_i32 t0 = tcg_const_i32(arg2);
663 tcg_gen_mul_i32(ret, arg1, t0);
664 tcg_temp_free_i32(t0);
667 static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
669 if (TCG_TARGET_HAS_div_i32) {
670 tcg_gen_op3_i32(INDEX_op_div_i32, ret, arg1, arg2);
671 } else if (TCG_TARGET_HAS_div2_i32) {
672 TCGv_i32 t0 = tcg_temp_new_i32();
673 tcg_gen_sari_i32(t0, arg1, 31);
674 tcg_gen_op5_i32(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
675 tcg_temp_free_i32(t0);
678 /* Return value and both arguments are 32-bit and signed. */
679 sizemask |= tcg_gen_sizemask(0, 0, 1);
680 sizemask |= tcg_gen_sizemask(1, 0, 1);
681 sizemask |= tcg_gen_sizemask(2, 0, 1);
682 tcg_gen_helper32(tcg_helper_div_i32, sizemask, ret, arg1, arg2);
686 static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
688 if (TCG_TARGET_HAS_div_i32) {
689 tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2);
690 } else if (TCG_TARGET_HAS_div2_i32) {
691 TCGv_i32 t0 = tcg_temp_new_i32();
692 tcg_gen_sari_i32(t0, arg1, 31);
693 tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
694 tcg_temp_free_i32(t0);
697 /* Return value and both arguments are 32-bit and signed. */
698 sizemask |= tcg_gen_sizemask(0, 0, 1);
699 sizemask |= tcg_gen_sizemask(1, 0, 1);
700 sizemask |= tcg_gen_sizemask(2, 0, 1);
701 tcg_gen_helper32(tcg_helper_rem_i32, sizemask, ret, arg1, arg2);
705 static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
707 if (TCG_TARGET_HAS_div_i32) {
708 tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2);
709 } else if (TCG_TARGET_HAS_div2_i32) {
710 TCGv_i32 t0 = tcg_temp_new_i32();
711 tcg_gen_movi_i32(t0, 0);
712 tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
713 tcg_temp_free_i32(t0);
716 /* Return value and both arguments are 32-bit and unsigned. */
717 sizemask |= tcg_gen_sizemask(0, 0, 0);
718 sizemask |= tcg_gen_sizemask(1, 0, 0);
719 sizemask |= tcg_gen_sizemask(2, 0, 0);
720 tcg_gen_helper32(tcg_helper_divu_i32, sizemask, ret, arg1, arg2);
724 static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
726 if (TCG_TARGET_HAS_div_i32) {
727 tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2);
728 } else if (TCG_TARGET_HAS_div2_i32) {
729 TCGv_i32 t0 = tcg_temp_new_i32();
730 tcg_gen_movi_i32(t0, 0);
731 tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
732 tcg_temp_free_i32(t0);
735 /* Return value and both arguments are 32-bit and unsigned. */
736 sizemask |= tcg_gen_sizemask(0, 0, 0);
737 sizemask |= tcg_gen_sizemask(1, 0, 0);
738 sizemask |= tcg_gen_sizemask(2, 0, 0);
739 tcg_gen_helper32(tcg_helper_remu_i32, sizemask, ret, arg1, arg2);
743 #if TCG_TARGET_REG_BITS == 32
745 static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
747 if (!TCGV_EQUAL_I64(ret, arg)) {
748 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
749 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
753 static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
755 tcg_gen_movi_i32(TCGV_LOW(ret), arg);
756 tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
759 static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
760 tcg_target_long offset)
762 tcg_gen_ld8u_i32(TCGV_LOW(ret), arg2, offset);
763 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
766 static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
767 tcg_target_long offset)
769 tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
770 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
773 static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
774 tcg_target_long offset)
776 tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
777 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
780 static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
781 tcg_target_long offset)
783 tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
784 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
787 static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
788 tcg_target_long offset)
790 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
791 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
794 static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
795 tcg_target_long offset)
797 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
798 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
801 static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
802 tcg_target_long offset)
804 /* since arg2 and ret have different types, they cannot be the
806 #ifdef TCG_TARGET_WORDS_BIGENDIAN
807 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
808 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
810 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
811 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
815 static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
816 tcg_target_long offset)
818 tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
821 static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
822 tcg_target_long offset)
824 tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
827 static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
828 tcg_target_long offset)
830 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
833 static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
834 tcg_target_long offset)
836 #ifdef TCG_TARGET_WORDS_BIGENDIAN
837 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
838 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
840 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
841 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
845 static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
847 tcg_gen_op6_i32(INDEX_op_add2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
848 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
852 static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
854 tcg_gen_op6_i32(INDEX_op_sub2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
855 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
859 static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
861 tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
862 tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
865 static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
867 tcg_gen_andi_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
868 tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
871 static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
873 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
874 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
877 static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
879 tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
880 tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
883 static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
885 tcg_gen_xor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
886 tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
889 static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
891 tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
892 tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
895 /* XXX: use generic code when basic block handling is OK or CPU
896 specific code (x86) */
897 static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
900 /* Return value and both arguments are 64-bit and signed. */
901 sizemask |= tcg_gen_sizemask(0, 1, 1);
902 sizemask |= tcg_gen_sizemask(1, 1, 1);
903 sizemask |= tcg_gen_sizemask(2, 1, 1);
905 tcg_gen_helper64(tcg_helper_shl_i64, sizemask, ret, arg1, arg2);
908 static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
910 tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
913 static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
916 /* Return value and both arguments are 64-bit and signed. */
917 sizemask |= tcg_gen_sizemask(0, 1, 1);
918 sizemask |= tcg_gen_sizemask(1, 1, 1);
919 sizemask |= tcg_gen_sizemask(2, 1, 1);
921 tcg_gen_helper64(tcg_helper_shr_i64, sizemask, ret, arg1, arg2);
924 static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
926 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
929 static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
932 /* Return value and both arguments are 64-bit and signed. */
933 sizemask |= tcg_gen_sizemask(0, 1, 1);
934 sizemask |= tcg_gen_sizemask(1, 1, 1);
935 sizemask |= tcg_gen_sizemask(2, 1, 1);
937 tcg_gen_helper64(tcg_helper_sar_i64, sizemask, ret, arg1, arg2);
940 static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
942 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
945 static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
946 TCGv_i64 arg2, int label_index)
948 tcg_gen_op6ii_i32(INDEX_op_brcond2_i32,
949 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
950 TCGV_HIGH(arg2), cond, label_index);
953 static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
954 TCGv_i64 arg1, TCGv_i64 arg2)
956 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, TCGV_LOW(ret),
957 TCGV_LOW(arg1), TCGV_HIGH(arg1),
958 TCGV_LOW(arg2), TCGV_HIGH(arg2), cond);
959 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
962 static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
967 t0 = tcg_temp_new_i64();
968 t1 = tcg_temp_new_i32();
970 tcg_gen_op4_i32(INDEX_op_mulu2_i32, TCGV_LOW(t0), TCGV_HIGH(t0),
971 TCGV_LOW(arg1), TCGV_LOW(arg2));
973 tcg_gen_mul_i32(t1, TCGV_LOW(arg1), TCGV_HIGH(arg2));
974 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
975 tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
976 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
978 tcg_gen_mov_i64(ret, t0);
979 tcg_temp_free_i64(t0);
980 tcg_temp_free_i32(t1);
983 static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
986 /* Return value and both arguments are 64-bit and signed. */
987 sizemask |= tcg_gen_sizemask(0, 1, 1);
988 sizemask |= tcg_gen_sizemask(1, 1, 1);
989 sizemask |= tcg_gen_sizemask(2, 1, 1);
991 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
994 static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
997 /* Return value and both arguments are 64-bit and signed. */
998 sizemask |= tcg_gen_sizemask(0, 1, 1);
999 sizemask |= tcg_gen_sizemask(1, 1, 1);
1000 sizemask |= tcg_gen_sizemask(2, 1, 1);
1002 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
1005 static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1008 /* Return value and both arguments are 64-bit and unsigned. */
1009 sizemask |= tcg_gen_sizemask(0, 1, 0);
1010 sizemask |= tcg_gen_sizemask(1, 1, 0);
1011 sizemask |= tcg_gen_sizemask(2, 1, 0);
1013 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
1016 static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1019 /* Return value and both arguments are 64-bit and unsigned. */
1020 sizemask |= tcg_gen_sizemask(0, 1, 0);
1021 sizemask |= tcg_gen_sizemask(1, 1, 0);
1022 sizemask |= tcg_gen_sizemask(2, 1, 0);
1024 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
1029 static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
1031 if (!TCGV_EQUAL_I64(ret, arg))
1032 tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
1035 static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
1037 tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
1040 static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
1041 tcg_target_long offset)
1043 tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
1046 static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
1047 tcg_target_long offset)
1049 tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
1052 static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
1053 tcg_target_long offset)
1055 tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
1058 static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
1059 tcg_target_long offset)
1061 tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
1064 static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
1065 tcg_target_long offset)
1067 tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
1070 static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
1071 tcg_target_long offset)
1073 tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64, ret, arg2, offset);
1076 static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
1078 tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
1081 static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
1082 tcg_target_long offset)
1084 tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
1087 static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
1088 tcg_target_long offset)
1090 tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
1093 static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
1094 tcg_target_long offset)
1096 tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
1099 static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
1101 tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
1104 static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1106 tcg_gen_op3_i64(INDEX_op_add_i64, ret, arg1, arg2);
1109 static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1111 tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
1114 static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1116 if (TCGV_EQUAL_I64(arg1, arg2)) {
1117 tcg_gen_mov_i64(ret, arg1);
1119 tcg_gen_op3_i64(INDEX_op_and_i64, ret, arg1, arg2);
1123 static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1125 TCGv_i64 t0 = tcg_const_i64(arg2);
1126 tcg_gen_and_i64(ret, arg1, t0);
1127 tcg_temp_free_i64(t0);
1130 static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1132 if (TCGV_EQUAL_I64(arg1, arg2)) {
1133 tcg_gen_mov_i64(ret, arg1);
1135 tcg_gen_op3_i64(INDEX_op_or_i64, ret, arg1, arg2);
1139 static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1141 TCGv_i64 t0 = tcg_const_i64(arg2);
1142 tcg_gen_or_i64(ret, arg1, t0);
1143 tcg_temp_free_i64(t0);
1146 static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1148 if (TCGV_EQUAL_I64(arg1, arg2)) {
1149 tcg_gen_movi_i64(ret, 0);
1151 tcg_gen_op3_i64(INDEX_op_xor_i64, ret, arg1, arg2);
1155 static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1157 TCGv_i64 t0 = tcg_const_i64(arg2);
1158 tcg_gen_xor_i64(ret, arg1, t0);
1159 tcg_temp_free_i64(t0);
1162 static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1164 tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
1167 static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1170 tcg_gen_mov_i64(ret, arg1);
1172 TCGv_i64 t0 = tcg_const_i64(arg2);
1173 tcg_gen_shl_i64(ret, arg1, t0);
1174 tcg_temp_free_i64(t0);
1178 static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1180 tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
1183 static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1186 tcg_gen_mov_i64(ret, arg1);
1188 TCGv_i64 t0 = tcg_const_i64(arg2);
1189 tcg_gen_shr_i64(ret, arg1, t0);
1190 tcg_temp_free_i64(t0);
1194 static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1196 tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
1199 static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1202 tcg_gen_mov_i64(ret, arg1);
1204 TCGv_i64 t0 = tcg_const_i64(arg2);
1205 tcg_gen_sar_i64(ret, arg1, t0);
1206 tcg_temp_free_i64(t0);
1210 static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
1211 TCGv_i64 arg2, int label_index)
1213 tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
1216 static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
1217 TCGv_i64 arg1, TCGv_i64 arg2)
1219 tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
1222 static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1224 tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
1227 static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1229 if (TCG_TARGET_HAS_div_i64) {
1230 tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2);
1231 } else if (TCG_TARGET_HAS_div2_i64) {
1232 TCGv_i64 t0 = tcg_temp_new_i64();
1233 tcg_gen_sari_i64(t0, arg1, 63);
1234 tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
1235 tcg_temp_free_i64(t0);
1238 /* Return value and both arguments are 64-bit and signed. */
1239 sizemask |= tcg_gen_sizemask(0, 1, 1);
1240 sizemask |= tcg_gen_sizemask(1, 1, 1);
1241 sizemask |= tcg_gen_sizemask(2, 1, 1);
1242 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
1246 static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1248 if (TCG_TARGET_HAS_div_i64) {
1249 tcg_gen_op3_i64(INDEX_op_rem_i64, ret, arg1, arg2);
1250 } else if (TCG_TARGET_HAS_div2_i64) {
1251 TCGv_i64 t0 = tcg_temp_new_i64();
1252 tcg_gen_sari_i64(t0, arg1, 63);
1253 tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
1254 tcg_temp_free_i64(t0);
1257 /* Return value and both arguments are 64-bit and signed. */
1258 sizemask |= tcg_gen_sizemask(0, 1, 1);
1259 sizemask |= tcg_gen_sizemask(1, 1, 1);
1260 sizemask |= tcg_gen_sizemask(2, 1, 1);
1261 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
1265 static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1267 if (TCG_TARGET_HAS_div_i64) {
1268 tcg_gen_op3_i64(INDEX_op_divu_i64, ret, arg1, arg2);
1269 } else if (TCG_TARGET_HAS_div2_i64) {
1270 TCGv_i64 t0 = tcg_temp_new_i64();
1271 tcg_gen_movi_i64(t0, 0);
1272 tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
1273 tcg_temp_free_i64(t0);
1276 /* Return value and both arguments are 64-bit and unsigned. */
1277 sizemask |= tcg_gen_sizemask(0, 1, 0);
1278 sizemask |= tcg_gen_sizemask(1, 1, 0);
1279 sizemask |= tcg_gen_sizemask(2, 1, 0);
1280 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
1284 static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1286 if (TCG_TARGET_HAS_div_i64) {
1287 tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2);
1288 } else if (TCG_TARGET_HAS_div2_i64) {
1289 TCGv_i64 t0 = tcg_temp_new_i64();
1290 tcg_gen_movi_i64(t0, 0);
1291 tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
1292 tcg_temp_free_i64(t0);
1295 /* Return value and both arguments are 64-bit and unsigned. */
1296 sizemask |= tcg_gen_sizemask(0, 1, 0);
1297 sizemask |= tcg_gen_sizemask(1, 1, 0);
1298 sizemask |= tcg_gen_sizemask(2, 1, 0);
1299 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
1302 #endif /* TCG_TARGET_REG_BITS == 32 */
1304 static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1306 /* some cases can be optimized here */
1308 tcg_gen_mov_i64(ret, arg1);
1310 TCGv_i64 t0 = tcg_const_i64(arg2);
1311 tcg_gen_add_i64(ret, arg1, t0);
1312 tcg_temp_free_i64(t0);
1316 static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
1318 TCGv_i64 t0 = tcg_const_i64(arg1);
1319 tcg_gen_sub_i64(ret, t0, arg2);
1320 tcg_temp_free_i64(t0);
1323 static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1325 /* some cases can be optimized here */
1327 tcg_gen_mov_i64(ret, arg1);
1329 TCGv_i64 t0 = tcg_const_i64(arg2);
1330 tcg_gen_sub_i64(ret, arg1, t0);
1331 tcg_temp_free_i64(t0);
1334 static inline void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1,
1335 int64_t arg2, int label_index)
1337 TCGv_i64 t0 = tcg_const_i64(arg2);
1338 tcg_gen_brcond_i64(cond, arg1, t0, label_index);
1339 tcg_temp_free_i64(t0);
1342 static inline void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
1343 TCGv_i64 arg1, int64_t arg2)
1345 TCGv_i64 t0 = tcg_const_i64(arg2);
1346 tcg_gen_setcond_i64(cond, ret, arg1, t0);
1347 tcg_temp_free_i64(t0);
1350 static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1352 TCGv_i64 t0 = tcg_const_i64(arg2);
1353 tcg_gen_mul_i64(ret, arg1, t0);
1354 tcg_temp_free_i64(t0);
1358 /***************************************/
1359 /* optional operations */
1361 static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
1363 if (TCG_TARGET_HAS_ext8s_i32) {
1364 tcg_gen_op2_i32(INDEX_op_ext8s_i32, ret, arg);
1366 tcg_gen_shli_i32(ret, arg, 24);
1367 tcg_gen_sari_i32(ret, ret, 24);
1371 static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
1373 if (TCG_TARGET_HAS_ext16s_i32) {
1374 tcg_gen_op2_i32(INDEX_op_ext16s_i32, ret, arg);
1376 tcg_gen_shli_i32(ret, arg, 16);
1377 tcg_gen_sari_i32(ret, ret, 16);
1381 static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
1383 if (TCG_TARGET_HAS_ext8u_i32) {
1384 tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg);
1386 tcg_gen_andi_i32(ret, arg, 0xffu);
1390 static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
1392 if (TCG_TARGET_HAS_ext16u_i32) {
1393 tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg);
1395 tcg_gen_andi_i32(ret, arg, 0xffffu);
1399 /* Note: we assume the two high bytes are set to zero */
1400 static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
1402 if (TCG_TARGET_HAS_bswap16_i32) {
1403 tcg_gen_op2_i32(INDEX_op_bswap16_i32, ret, arg);
1405 TCGv_i32 t0 = tcg_temp_new_i32();
1407 tcg_gen_ext8u_i32(t0, arg);
1408 tcg_gen_shli_i32(t0, t0, 8);
1409 tcg_gen_shri_i32(ret, arg, 8);
1410 tcg_gen_or_i32(ret, ret, t0);
1411 tcg_temp_free_i32(t0);
1415 static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
1417 if (TCG_TARGET_HAS_bswap32_i32) {
1418 tcg_gen_op2_i32(INDEX_op_bswap32_i32, ret, arg);
1421 t0 = tcg_temp_new_i32();
1422 t1 = tcg_temp_new_i32();
1424 tcg_gen_shli_i32(t0, arg, 24);
1426 tcg_gen_andi_i32(t1, arg, 0x0000ff00);
1427 tcg_gen_shli_i32(t1, t1, 8);
1428 tcg_gen_or_i32(t0, t0, t1);
1430 tcg_gen_shri_i32(t1, arg, 8);
1431 tcg_gen_andi_i32(t1, t1, 0x0000ff00);
1432 tcg_gen_or_i32(t0, t0, t1);
1434 tcg_gen_shri_i32(t1, arg, 24);
1435 tcg_gen_or_i32(ret, t0, t1);
1436 tcg_temp_free_i32(t0);
1437 tcg_temp_free_i32(t1);
1441 #if TCG_TARGET_REG_BITS == 32
1442 static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
1444 tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1445 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
1448 static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
1450 tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1451 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
1454 static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
1456 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1457 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
1460 static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
1462 tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1463 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1466 static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
1468 tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1469 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1472 static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
1474 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1475 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1478 static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
1480 tcg_gen_mov_i32(ret, TCGV_LOW(arg));
1483 static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
1485 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
1486 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1489 static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
1491 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
1492 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
1495 /* Note: we assume the six high bytes are set to zero */
1496 static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1498 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1499 tcg_gen_bswap16_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1502 /* Note: we assume the four high bytes are set to zero */
1503 static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1505 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1506 tcg_gen_bswap32_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1509 static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
1512 t0 = tcg_temp_new_i32();
1513 t1 = tcg_temp_new_i32();
1515 tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
1516 tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
1517 tcg_gen_mov_i32(TCGV_LOW(ret), t1);
1518 tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
1519 tcg_temp_free_i32(t0);
1520 tcg_temp_free_i32(t1);
1524 static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
1526 if (TCG_TARGET_HAS_ext8s_i64) {
1527 tcg_gen_op2_i64(INDEX_op_ext8s_i64, ret, arg);
1529 tcg_gen_shli_i64(ret, arg, 56);
1530 tcg_gen_sari_i64(ret, ret, 56);
1534 static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
1536 if (TCG_TARGET_HAS_ext16s_i64) {
1537 tcg_gen_op2_i64(INDEX_op_ext16s_i64, ret, arg);
1539 tcg_gen_shli_i64(ret, arg, 48);
1540 tcg_gen_sari_i64(ret, ret, 48);
1544 static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
1546 if (TCG_TARGET_HAS_ext32s_i64) {
1547 tcg_gen_op2_i64(INDEX_op_ext32s_i64, ret, arg);
1549 tcg_gen_shli_i64(ret, arg, 32);
1550 tcg_gen_sari_i64(ret, ret, 32);
1554 static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
1556 if (TCG_TARGET_HAS_ext8u_i64) {
1557 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg);
1559 tcg_gen_andi_i64(ret, arg, 0xffu);
1563 static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
1565 if (TCG_TARGET_HAS_ext16u_i64) {
1566 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg);
1568 tcg_gen_andi_i64(ret, arg, 0xffffu);
1572 static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
1574 if (TCG_TARGET_HAS_ext32u_i64) {
1575 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg);
1577 tcg_gen_andi_i64(ret, arg, 0xffffffffu);
1581 /* Note: we assume the target supports move between 32 and 64 bit
1582 registers. This will probably break MIPS64 targets. */
1583 static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
1585 tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
1588 /* Note: we assume the target supports move between 32 and 64 bit
1590 static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
1592 tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
1595 /* Note: we assume the target supports move between 32 and 64 bit
1597 static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
1599 tcg_gen_ext32s_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
1602 /* Note: we assume the six high bytes are set to zero */
1603 static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1605 if (TCG_TARGET_HAS_bswap16_i64) {
1606 tcg_gen_op2_i64(INDEX_op_bswap16_i64, ret, arg);
1608 TCGv_i64 t0 = tcg_temp_new_i64();
1610 tcg_gen_ext8u_i64(t0, arg);
1611 tcg_gen_shli_i64(t0, t0, 8);
1612 tcg_gen_shri_i64(ret, arg, 8);
1613 tcg_gen_or_i64(ret, ret, t0);
1614 tcg_temp_free_i64(t0);
1618 /* Note: we assume the four high bytes are set to zero */
1619 static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1621 if (TCG_TARGET_HAS_bswap32_i64) {
1622 tcg_gen_op2_i64(INDEX_op_bswap32_i64, ret, arg);
1625 t0 = tcg_temp_new_i64();
1626 t1 = tcg_temp_new_i64();
1628 tcg_gen_shli_i64(t0, arg, 24);
1629 tcg_gen_ext32u_i64(t0, t0);
1631 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1632 tcg_gen_shli_i64(t1, t1, 8);
1633 tcg_gen_or_i64(t0, t0, t1);
1635 tcg_gen_shri_i64(t1, arg, 8);
1636 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1637 tcg_gen_or_i64(t0, t0, t1);
1639 tcg_gen_shri_i64(t1, arg, 24);
1640 tcg_gen_or_i64(ret, t0, t1);
1641 tcg_temp_free_i64(t0);
1642 tcg_temp_free_i64(t1);
1646 static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
1648 if (TCG_TARGET_HAS_bswap64_i64) {
1649 tcg_gen_op2_i64(INDEX_op_bswap64_i64, ret, arg);
1651 TCGv_i64 t0 = tcg_temp_new_i64();
1652 TCGv_i64 t1 = tcg_temp_new_i64();
1654 tcg_gen_shli_i64(t0, arg, 56);
1656 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1657 tcg_gen_shli_i64(t1, t1, 40);
1658 tcg_gen_or_i64(t0, t0, t1);
1660 tcg_gen_andi_i64(t1, arg, 0x00ff0000);
1661 tcg_gen_shli_i64(t1, t1, 24);
1662 tcg_gen_or_i64(t0, t0, t1);
1664 tcg_gen_andi_i64(t1, arg, 0xff000000);
1665 tcg_gen_shli_i64(t1, t1, 8);
1666 tcg_gen_or_i64(t0, t0, t1);
1668 tcg_gen_shri_i64(t1, arg, 8);
1669 tcg_gen_andi_i64(t1, t1, 0xff000000);
1670 tcg_gen_or_i64(t0, t0, t1);
1672 tcg_gen_shri_i64(t1, arg, 24);
1673 tcg_gen_andi_i64(t1, t1, 0x00ff0000);
1674 tcg_gen_or_i64(t0, t0, t1);
1676 tcg_gen_shri_i64(t1, arg, 40);
1677 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1678 tcg_gen_or_i64(t0, t0, t1);
1680 tcg_gen_shri_i64(t1, arg, 56);
1681 tcg_gen_or_i64(ret, t0, t1);
1682 tcg_temp_free_i64(t0);
1683 tcg_temp_free_i64(t1);
1689 static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
1691 if (TCG_TARGET_HAS_neg_i32) {
1692 tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg);
1694 TCGv_i32 t0 = tcg_const_i32(0);
1695 tcg_gen_sub_i32(ret, t0, arg);
1696 tcg_temp_free_i32(t0);
1700 static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
1702 if (TCG_TARGET_HAS_neg_i64) {
1703 tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg);
1705 TCGv_i64 t0 = tcg_const_i64(0);
1706 tcg_gen_sub_i64(ret, t0, arg);
1707 tcg_temp_free_i64(t0);
1711 static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
1713 if (TCG_TARGET_HAS_not_i32) {
1714 tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg);
1716 tcg_gen_xori_i32(ret, arg, -1);
1720 static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
1722 #if TCG_TARGET_REG_BITS == 64
1723 if (TCG_TARGET_HAS_not_i64) {
1724 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg);
1726 tcg_gen_xori_i64(ret, arg, -1);
1729 tcg_gen_not_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1730 tcg_gen_not_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1734 static inline void tcg_gen_discard_i32(TCGv_i32 arg)
1736 tcg_gen_op1_i32(INDEX_op_discard, arg);
1739 static inline void tcg_gen_discard_i64(TCGv_i64 arg)
1741 #if TCG_TARGET_REG_BITS == 32
1742 tcg_gen_discard_i32(TCGV_LOW(arg));
1743 tcg_gen_discard_i32(TCGV_HIGH(arg));
1745 tcg_gen_op1_i64(INDEX_op_discard, arg);
1749 static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low, TCGv_i32 high)
1751 #if TCG_TARGET_REG_BITS == 32
1752 tcg_gen_mov_i32(TCGV_LOW(dest), low);
1753 tcg_gen_mov_i32(TCGV_HIGH(dest), high);
1755 TCGv_i64 tmp = tcg_temp_new_i64();
1756 /* This extension is only needed for type correctness.
1757 We may be able to do better given target specific information. */
1758 tcg_gen_extu_i32_i64(tmp, high);
1759 tcg_gen_shli_i64(tmp, tmp, 32);
1760 tcg_gen_extu_i32_i64(dest, low);
1761 tcg_gen_or_i64(dest, dest, tmp);
1762 tcg_temp_free_i64(tmp);
1766 static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low, TCGv_i64 high)
1768 #if TCG_TARGET_REG_BITS == 32
1769 tcg_gen_concat_i32_i64(dest, TCGV_LOW(low), TCGV_LOW(high));
1771 TCGv_i64 tmp = tcg_temp_new_i64();
1772 tcg_gen_ext32u_i64(dest, low);
1773 tcg_gen_shli_i64(tmp, high, 32);
1774 tcg_gen_or_i64(dest, dest, tmp);
1775 tcg_temp_free_i64(tmp);
1779 static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1781 if (TCG_TARGET_HAS_andc_i32) {
1782 tcg_gen_op3_i32(INDEX_op_andc_i32, ret, arg1, arg2);
1784 TCGv_i32 t0 = tcg_temp_new_i32();
1785 tcg_gen_not_i32(t0, arg2);
1786 tcg_gen_and_i32(ret, arg1, t0);
1787 tcg_temp_free_i32(t0);
1791 static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1793 #if TCG_TARGET_REG_BITS == 64
1794 if (TCG_TARGET_HAS_andc_i64) {
1795 tcg_gen_op3_i64(INDEX_op_andc_i64, ret, arg1, arg2);
1797 TCGv_i64 t0 = tcg_temp_new_i64();
1798 tcg_gen_not_i64(t0, arg2);
1799 tcg_gen_and_i64(ret, arg1, t0);
1800 tcg_temp_free_i64(t0);
1803 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1804 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1808 static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1810 if (TCG_TARGET_HAS_eqv_i32) {
1811 tcg_gen_op3_i32(INDEX_op_eqv_i32, ret, arg1, arg2);
1813 tcg_gen_xor_i32(ret, arg1, arg2);
1814 tcg_gen_not_i32(ret, ret);
1818 static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1820 #if TCG_TARGET_REG_BITS == 64
1821 if (TCG_TARGET_HAS_eqv_i64) {
1822 tcg_gen_op3_i64(INDEX_op_eqv_i64, ret, arg1, arg2);
1824 tcg_gen_xor_i64(ret, arg1, arg2);
1825 tcg_gen_not_i64(ret, ret);
1828 tcg_gen_eqv_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1829 tcg_gen_eqv_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1833 static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1835 if (TCG_TARGET_HAS_nand_i32) {
1836 tcg_gen_op3_i32(INDEX_op_nand_i32, ret, arg1, arg2);
1838 tcg_gen_and_i32(ret, arg1, arg2);
1839 tcg_gen_not_i32(ret, ret);
1843 static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1845 #if TCG_TARGET_REG_BITS == 64
1846 if (TCG_TARGET_HAS_nand_i64) {
1847 tcg_gen_op3_i64(INDEX_op_nand_i64, ret, arg1, arg2);
1849 tcg_gen_and_i64(ret, arg1, arg2);
1850 tcg_gen_not_i64(ret, ret);
1853 tcg_gen_nand_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1854 tcg_gen_nand_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1858 static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1860 if (TCG_TARGET_HAS_nor_i32) {
1861 tcg_gen_op3_i32(INDEX_op_nor_i32, ret, arg1, arg2);
1863 tcg_gen_or_i32(ret, arg1, arg2);
1864 tcg_gen_not_i32(ret, ret);
1868 static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1870 #if TCG_TARGET_REG_BITS == 64
1871 if (TCG_TARGET_HAS_nor_i64) {
1872 tcg_gen_op3_i64(INDEX_op_nor_i64, ret, arg1, arg2);
1874 tcg_gen_or_i64(ret, arg1, arg2);
1875 tcg_gen_not_i64(ret, ret);
1878 tcg_gen_nor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1879 tcg_gen_nor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1883 static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1885 if (TCG_TARGET_HAS_orc_i32) {
1886 tcg_gen_op3_i32(INDEX_op_orc_i32, ret, arg1, arg2);
1888 TCGv_i32 t0 = tcg_temp_new_i32();
1889 tcg_gen_not_i32(t0, arg2);
1890 tcg_gen_or_i32(ret, arg1, t0);
1891 tcg_temp_free_i32(t0);
1895 static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1897 #if TCG_TARGET_REG_BITS == 64
1898 if (TCG_TARGET_HAS_orc_i64) {
1899 tcg_gen_op3_i64(INDEX_op_orc_i64, ret, arg1, arg2);
1901 TCGv_i64 t0 = tcg_temp_new_i64();
1902 tcg_gen_not_i64(t0, arg2);
1903 tcg_gen_or_i64(ret, arg1, t0);
1904 tcg_temp_free_i64(t0);
1907 tcg_gen_orc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1908 tcg_gen_orc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
1912 static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1914 if (TCG_TARGET_HAS_rot_i32) {
1915 tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
1919 t0 = tcg_temp_new_i32();
1920 t1 = tcg_temp_new_i32();
1921 tcg_gen_shl_i32(t0, arg1, arg2);
1922 tcg_gen_subfi_i32(t1, 32, arg2);
1923 tcg_gen_shr_i32(t1, arg1, t1);
1924 tcg_gen_or_i32(ret, t0, t1);
1925 tcg_temp_free_i32(t0);
1926 tcg_temp_free_i32(t1);
1930 static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
1932 if (TCG_TARGET_HAS_rot_i64) {
1933 tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2);
1936 t0 = tcg_temp_new_i64();
1937 t1 = tcg_temp_new_i64();
1938 tcg_gen_shl_i64(t0, arg1, arg2);
1939 tcg_gen_subfi_i64(t1, 64, arg2);
1940 tcg_gen_shr_i64(t1, arg1, t1);
1941 tcg_gen_or_i64(ret, t0, t1);
1942 tcg_temp_free_i64(t0);
1943 tcg_temp_free_i64(t1);
1947 static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
1949 /* some cases can be optimized here */
1951 tcg_gen_mov_i32(ret, arg1);
1952 } else if (TCG_TARGET_HAS_rot_i32) {
1953 TCGv_i32 t0 = tcg_const_i32(arg2);
1954 tcg_gen_rotl_i32(ret, arg1, t0);
1955 tcg_temp_free_i32(t0);
1958 t0 = tcg_temp_new_i32();
1959 t1 = tcg_temp_new_i32();
1960 tcg_gen_shli_i32(t0, arg1, arg2);
1961 tcg_gen_shri_i32(t1, arg1, 32 - arg2);
1962 tcg_gen_or_i32(ret, t0, t1);
1963 tcg_temp_free_i32(t0);
1964 tcg_temp_free_i32(t1);
1968 static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
1970 /* some cases can be optimized here */
1972 tcg_gen_mov_i64(ret, arg1);
1973 } else if (TCG_TARGET_HAS_rot_i64) {
1974 TCGv_i64 t0 = tcg_const_i64(arg2);
1975 tcg_gen_rotl_i64(ret, arg1, t0);
1976 tcg_temp_free_i64(t0);
1979 t0 = tcg_temp_new_i64();
1980 t1 = tcg_temp_new_i64();
1981 tcg_gen_shli_i64(t0, arg1, arg2);
1982 tcg_gen_shri_i64(t1, arg1, 64 - arg2);
1983 tcg_gen_or_i64(ret, t0, t1);
1984 tcg_temp_free_i64(t0);
1985 tcg_temp_free_i64(t1);
1989 static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
1991 if (TCG_TARGET_HAS_rot_i32) {
1992 tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
1996 t0 = tcg_temp_new_i32();
1997 t1 = tcg_temp_new_i32();
1998 tcg_gen_shr_i32(t0, arg1, arg2);
1999 tcg_gen_subfi_i32(t1, 32, arg2);
2000 tcg_gen_shl_i32(t1, arg1, t1);
2001 tcg_gen_or_i32(ret, t0, t1);
2002 tcg_temp_free_i32(t0);
2003 tcg_temp_free_i32(t1);
2007 static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
2009 if (TCG_TARGET_HAS_rot_i64) {
2010 tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2);
2013 t0 = tcg_temp_new_i64();
2014 t1 = tcg_temp_new_i64();
2015 tcg_gen_shr_i64(t0, arg1, arg2);
2016 tcg_gen_subfi_i64(t1, 64, arg2);
2017 tcg_gen_shl_i64(t1, arg1, t1);
2018 tcg_gen_or_i64(ret, t0, t1);
2019 tcg_temp_free_i64(t0);
2020 tcg_temp_free_i64(t1);
2024 static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
2026 /* some cases can be optimized here */
2028 tcg_gen_mov_i32(ret, arg1);
2030 tcg_gen_rotli_i32(ret, arg1, 32 - arg2);
2034 static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
2036 /* some cases can be optimized here */
2038 tcg_gen_mov_i64(ret, arg1);
2040 tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
2044 static inline void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1,
2045 TCGv_i32 arg2, unsigned int ofs,
2051 if (ofs == 0 && len == 32) {
2052 tcg_gen_mov_i32(ret, arg2);
2055 if (TCG_TARGET_HAS_deposit_i32 && TCG_TARGET_deposit_i32_valid(ofs, len)) {
2056 tcg_gen_op5ii_i32(INDEX_op_deposit_i32, ret, arg1, arg2, ofs, len);
2060 mask = (1u << len) - 1;
2061 t1 = tcg_temp_new_i32();
2063 if (ofs + len < 32) {
2064 tcg_gen_andi_i32(t1, arg2, mask);
2065 tcg_gen_shli_i32(t1, t1, ofs);
2067 tcg_gen_shli_i32(t1, arg2, ofs);
2069 tcg_gen_andi_i32(ret, arg1, ~(mask << ofs));
2070 tcg_gen_or_i32(ret, ret, t1);
2072 tcg_temp_free_i32(t1);
2075 static inline void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1,
2076 TCGv_i64 arg2, unsigned int ofs,
2082 if (ofs == 0 && len == 64) {
2083 tcg_gen_mov_i64(ret, arg2);
2086 if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(ofs, len)) {
2087 tcg_gen_op5ii_i64(INDEX_op_deposit_i64, ret, arg1, arg2, ofs, len);
2091 #if TCG_TARGET_REG_BITS == 32
2093 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg1));
2094 tcg_gen_deposit_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1),
2095 TCGV_LOW(arg2), ofs - 32, len);
2098 if (ofs + len <= 32) {
2099 tcg_gen_deposit_i32(TCGV_LOW(ret), TCGV_LOW(arg1),
2100 TCGV_LOW(arg2), ofs, len);
2101 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1));
2106 mask = (1ull << len) - 1;
2107 t1 = tcg_temp_new_i64();
2109 if (ofs + len < 64) {
2110 tcg_gen_andi_i64(t1, arg2, mask);
2111 tcg_gen_shli_i64(t1, t1, ofs);
2113 tcg_gen_shli_i64(t1, arg2, ofs);
2115 tcg_gen_andi_i64(ret, arg1, ~(mask << ofs));
2116 tcg_gen_or_i64(ret, ret, t1);
2118 tcg_temp_free_i64(t1);
2121 /***************************************/
2122 /* QEMU specific operations. Their type depend on the QEMU CPU
2124 #ifndef TARGET_LONG_BITS
2125 #error must include QEMU headers
2128 #if TARGET_LONG_BITS == 32
2129 #define TCGv TCGv_i32
2130 #define tcg_temp_new() tcg_temp_new_i32()
2131 #define tcg_global_reg_new tcg_global_reg_new_i32
2132 #define tcg_global_mem_new tcg_global_mem_new_i32
2133 #define tcg_temp_local_new() tcg_temp_local_new_i32()
2134 #define tcg_temp_free tcg_temp_free_i32
2135 #define tcg_gen_qemu_ldst_op tcg_gen_op3i_i32
2136 #define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i32
2137 #define TCGV_UNUSED(x) TCGV_UNUSED_I32(x)
2138 #define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
2140 #define TCGv TCGv_i64
2141 #define tcg_temp_new() tcg_temp_new_i64()
2142 #define tcg_global_reg_new tcg_global_reg_new_i64
2143 #define tcg_global_mem_new tcg_global_mem_new_i64
2144 #define tcg_temp_local_new() tcg_temp_local_new_i64()
2145 #define tcg_temp_free tcg_temp_free_i64
2146 #define tcg_gen_qemu_ldst_op tcg_gen_op3i_i64
2147 #define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i64
2148 #define TCGV_UNUSED(x) TCGV_UNUSED_I64(x)
2149 #define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
2152 /* debug info: write the PC of the corresponding QEMU CPU instruction */
2153 static inline void tcg_gen_debug_insn_start(uint64_t pc)
2155 /* XXX: must really use a 32 bit size for TCGArg in all cases */
2156 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
2157 tcg_gen_op2ii(INDEX_op_debug_insn_start,
2158 (uint32_t)(pc), (uint32_t)(pc >> 32));
2160 tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
2164 static inline void tcg_gen_exit_tb(tcg_target_long val)
2166 tcg_gen_op1i(INDEX_op_exit_tb, val);
2169 static inline void tcg_gen_goto_tb(int idx)
2171 tcg_gen_op1i(INDEX_op_goto_tb, idx);
2174 #if TCG_TARGET_REG_BITS == 32
2175 static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
2177 #if TARGET_LONG_BITS == 32
2178 tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
2180 tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
2181 TCGV_HIGH(addr), mem_index);
2182 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
2186 static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
2188 #if TARGET_LONG_BITS == 32
2189 tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
2191 tcg_gen_op4i_i32(INDEX_op_qemu_ld8s, TCGV_LOW(ret), TCGV_LOW(addr),
2192 TCGV_HIGH(addr), mem_index);
2193 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
2197 static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
2199 #if TARGET_LONG_BITS == 32
2200 tcg_gen_op3i_i32(INDEX_op_qemu_ld16u, ret, addr, mem_index);
2202 tcg_gen_op4i_i32(INDEX_op_qemu_ld16u, TCGV_LOW(ret), TCGV_LOW(addr),
2203 TCGV_HIGH(addr), mem_index);
2204 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
2208 static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
2210 #if TARGET_LONG_BITS == 32
2211 tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
2213 tcg_gen_op4i_i32(INDEX_op_qemu_ld16s, TCGV_LOW(ret), TCGV_LOW(addr),
2214 TCGV_HIGH(addr), mem_index);
2215 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
2219 static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
2221 #if TARGET_LONG_BITS == 32
2222 tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
2224 tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
2225 TCGV_HIGH(addr), mem_index);
2226 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
2230 static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
2232 #if TARGET_LONG_BITS == 32
2233 tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
2235 tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
2236 TCGV_HIGH(addr), mem_index);
2237 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
2241 static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
2243 #if TARGET_LONG_BITS == 32
2244 tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
2246 tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
2247 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
2251 static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
2253 #if TARGET_LONG_BITS == 32
2254 tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index);
2256 tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr),
2257 TCGV_HIGH(addr), mem_index);
2261 static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
2263 #if TARGET_LONG_BITS == 32
2264 tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
2266 tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
2267 TCGV_HIGH(addr), mem_index);
2271 static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
2273 #if TARGET_LONG_BITS == 32
2274 tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
2276 tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
2277 TCGV_HIGH(addr), mem_index);
2281 static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
2283 #if TARGET_LONG_BITS == 32
2284 tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
2287 tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
2288 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
2292 #define tcg_gen_ld_ptr(R, A, O) tcg_gen_ld_i32(TCGV_PTR_TO_NAT(R), (A), (O))
2293 #define tcg_gen_discard_ptr(A) tcg_gen_discard_i32(TCGV_PTR_TO_NAT(A))
2295 #else /* TCG_TARGET_REG_BITS == 32 */
2297 static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
2299 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u, ret, addr, mem_index);
2302 static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
2304 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
2307 static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
2309 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
2312 static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
2314 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
2317 static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
2319 #if TARGET_LONG_BITS == 32
2320 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
2322 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
2326 static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
2328 #if TARGET_LONG_BITS == 32
2329 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
2331 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
2335 static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
2337 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
2340 static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
2342 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
2345 static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
2347 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
2350 static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
2352 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
2355 static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
2357 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
2360 #define tcg_gen_ld_ptr(R, A, O) tcg_gen_ld_i64(TCGV_PTR_TO_NAT(R), (A), (O))
2361 #define tcg_gen_discard_ptr(A) tcg_gen_discard_i64(TCGV_PTR_TO_NAT(A))
2363 #endif /* TCG_TARGET_REG_BITS != 32 */
2365 #if TARGET_LONG_BITS == 64
2366 #define tcg_gen_movi_tl tcg_gen_movi_i64
2367 #define tcg_gen_mov_tl tcg_gen_mov_i64
2368 #define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
2369 #define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
2370 #define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
2371 #define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
2372 #define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
2373 #define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
2374 #define tcg_gen_ld_tl tcg_gen_ld_i64
2375 #define tcg_gen_st8_tl tcg_gen_st8_i64
2376 #define tcg_gen_st16_tl tcg_gen_st16_i64
2377 #define tcg_gen_st32_tl tcg_gen_st32_i64
2378 #define tcg_gen_st_tl tcg_gen_st_i64
2379 #define tcg_gen_add_tl tcg_gen_add_i64
2380 #define tcg_gen_addi_tl tcg_gen_addi_i64
2381 #define tcg_gen_sub_tl tcg_gen_sub_i64
2382 #define tcg_gen_neg_tl tcg_gen_neg_i64
2383 #define tcg_gen_subfi_tl tcg_gen_subfi_i64
2384 #define tcg_gen_subi_tl tcg_gen_subi_i64
2385 #define tcg_gen_and_tl tcg_gen_and_i64
2386 #define tcg_gen_andi_tl tcg_gen_andi_i64
2387 #define tcg_gen_or_tl tcg_gen_or_i64
2388 #define tcg_gen_ori_tl tcg_gen_ori_i64
2389 #define tcg_gen_xor_tl tcg_gen_xor_i64
2390 #define tcg_gen_xori_tl tcg_gen_xori_i64
2391 #define tcg_gen_not_tl tcg_gen_not_i64
2392 #define tcg_gen_shl_tl tcg_gen_shl_i64
2393 #define tcg_gen_shli_tl tcg_gen_shli_i64
2394 #define tcg_gen_shr_tl tcg_gen_shr_i64
2395 #define tcg_gen_shri_tl tcg_gen_shri_i64
2396 #define tcg_gen_sar_tl tcg_gen_sar_i64
2397 #define tcg_gen_sari_tl tcg_gen_sari_i64
2398 #define tcg_gen_brcond_tl tcg_gen_brcond_i64
2399 #define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
2400 #define tcg_gen_setcond_tl tcg_gen_setcond_i64
2401 #define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
2402 #define tcg_gen_mul_tl tcg_gen_mul_i64
2403 #define tcg_gen_muli_tl tcg_gen_muli_i64
2404 #define tcg_gen_div_tl tcg_gen_div_i64
2405 #define tcg_gen_rem_tl tcg_gen_rem_i64
2406 #define tcg_gen_divu_tl tcg_gen_divu_i64
2407 #define tcg_gen_remu_tl tcg_gen_remu_i64
2408 #define tcg_gen_discard_tl tcg_gen_discard_i64
2409 #define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
2410 #define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
2411 #define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
2412 #define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
2413 #define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
2414 #define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
2415 #define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
2416 #define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
2417 #define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
2418 #define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
2419 #define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
2420 #define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
2421 #define tcg_gen_bswap16_tl tcg_gen_bswap16_i64
2422 #define tcg_gen_bswap32_tl tcg_gen_bswap32_i64
2423 #define tcg_gen_bswap64_tl tcg_gen_bswap64_i64
2424 #define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
2425 #define tcg_gen_andc_tl tcg_gen_andc_i64
2426 #define tcg_gen_eqv_tl tcg_gen_eqv_i64
2427 #define tcg_gen_nand_tl tcg_gen_nand_i64
2428 #define tcg_gen_nor_tl tcg_gen_nor_i64
2429 #define tcg_gen_orc_tl tcg_gen_orc_i64
2430 #define tcg_gen_rotl_tl tcg_gen_rotl_i64
2431 #define tcg_gen_rotli_tl tcg_gen_rotli_i64
2432 #define tcg_gen_rotr_tl tcg_gen_rotr_i64
2433 #define tcg_gen_rotri_tl tcg_gen_rotri_i64
2434 #define tcg_gen_deposit_tl tcg_gen_deposit_i64
2435 #define tcg_const_tl tcg_const_i64
2436 #define tcg_const_local_tl tcg_const_local_i64
2438 #define tcg_gen_movi_tl tcg_gen_movi_i32
2439 #define tcg_gen_mov_tl tcg_gen_mov_i32
2440 #define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
2441 #define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
2442 #define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
2443 #define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
2444 #define tcg_gen_ld32u_tl tcg_gen_ld_i32
2445 #define tcg_gen_ld32s_tl tcg_gen_ld_i32
2446 #define tcg_gen_ld_tl tcg_gen_ld_i32
2447 #define tcg_gen_st8_tl tcg_gen_st8_i32
2448 #define tcg_gen_st16_tl tcg_gen_st16_i32
2449 #define tcg_gen_st32_tl tcg_gen_st_i32
2450 #define tcg_gen_st_tl tcg_gen_st_i32
2451 #define tcg_gen_add_tl tcg_gen_add_i32
2452 #define tcg_gen_addi_tl tcg_gen_addi_i32
2453 #define tcg_gen_sub_tl tcg_gen_sub_i32
2454 #define tcg_gen_neg_tl tcg_gen_neg_i32
2455 #define tcg_gen_subfi_tl tcg_gen_subfi_i32
2456 #define tcg_gen_subi_tl tcg_gen_subi_i32
2457 #define tcg_gen_and_tl tcg_gen_and_i32
2458 #define tcg_gen_andi_tl tcg_gen_andi_i32
2459 #define tcg_gen_or_tl tcg_gen_or_i32
2460 #define tcg_gen_ori_tl tcg_gen_ori_i32
2461 #define tcg_gen_xor_tl tcg_gen_xor_i32
2462 #define tcg_gen_xori_tl tcg_gen_xori_i32
2463 #define tcg_gen_not_tl tcg_gen_not_i32
2464 #define tcg_gen_shl_tl tcg_gen_shl_i32
2465 #define tcg_gen_shli_tl tcg_gen_shli_i32
2466 #define tcg_gen_shr_tl tcg_gen_shr_i32
2467 #define tcg_gen_shri_tl tcg_gen_shri_i32
2468 #define tcg_gen_sar_tl tcg_gen_sar_i32
2469 #define tcg_gen_sari_tl tcg_gen_sari_i32
2470 #define tcg_gen_brcond_tl tcg_gen_brcond_i32
2471 #define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
2472 #define tcg_gen_setcond_tl tcg_gen_setcond_i32
2473 #define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
2474 #define tcg_gen_mul_tl tcg_gen_mul_i32
2475 #define tcg_gen_muli_tl tcg_gen_muli_i32
2476 #define tcg_gen_div_tl tcg_gen_div_i32
2477 #define tcg_gen_rem_tl tcg_gen_rem_i32
2478 #define tcg_gen_divu_tl tcg_gen_divu_i32
2479 #define tcg_gen_remu_tl tcg_gen_remu_i32
2480 #define tcg_gen_discard_tl tcg_gen_discard_i32
2481 #define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
2482 #define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
2483 #define tcg_gen_extu_i32_tl tcg_gen_mov_i32
2484 #define tcg_gen_ext_i32_tl tcg_gen_mov_i32
2485 #define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
2486 #define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
2487 #define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
2488 #define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
2489 #define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
2490 #define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
2491 #define tcg_gen_ext32u_tl tcg_gen_mov_i32
2492 #define tcg_gen_ext32s_tl tcg_gen_mov_i32
2493 #define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
2494 #define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
2495 #define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
2496 #define tcg_gen_andc_tl tcg_gen_andc_i32
2497 #define tcg_gen_eqv_tl tcg_gen_eqv_i32
2498 #define tcg_gen_nand_tl tcg_gen_nand_i32
2499 #define tcg_gen_nor_tl tcg_gen_nor_i32
2500 #define tcg_gen_orc_tl tcg_gen_orc_i32
2501 #define tcg_gen_rotl_tl tcg_gen_rotl_i32
2502 #define tcg_gen_rotli_tl tcg_gen_rotli_i32
2503 #define tcg_gen_rotr_tl tcg_gen_rotr_i32
2504 #define tcg_gen_rotri_tl tcg_gen_rotri_i32
2505 #define tcg_gen_deposit_tl tcg_gen_deposit_i32
2506 #define tcg_const_tl tcg_const_i32
2507 #define tcg_const_local_tl tcg_const_local_i32
2510 #if TCG_TARGET_REG_BITS == 32
2511 #define tcg_gen_add_ptr(R, A, B) tcg_gen_add_i32(TCGV_PTR_TO_NAT(R), \
2512 TCGV_PTR_TO_NAT(A), \
2514 #define tcg_gen_addi_ptr(R, A, B) tcg_gen_addi_i32(TCGV_PTR_TO_NAT(R), \
2515 TCGV_PTR_TO_NAT(A), (B))
2516 #define tcg_gen_ext_i32_ptr(R, A) tcg_gen_mov_i32(TCGV_PTR_TO_NAT(R), (A))
2517 #else /* TCG_TARGET_REG_BITS == 32 */
2518 #define tcg_gen_add_ptr(R, A, B) tcg_gen_add_i64(TCGV_PTR_TO_NAT(R), \
2519 TCGV_PTR_TO_NAT(A), \
2521 #define tcg_gen_addi_ptr(R, A, B) tcg_gen_addi_i64(TCGV_PTR_TO_NAT(R), \
2522 TCGV_PTR_TO_NAT(A), (B))
2523 #define tcg_gen_ext_i32_ptr(R, A) tcg_gen_ext_i32_i64(TCGV_PTR_TO_NAT(R), (A))
2524 #endif /* TCG_TARGET_REG_BITS != 32 */