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 #ifdef CONFIG_DYNGEN_OP
27 /* legacy dyngen operations */
31 int gen_new_label(void);
33 static inline void tcg_gen_op1_i32(int opc
, TCGv_i32 arg1
)
36 *gen_opparam_ptr
++ = GET_TCGV_I32(arg1
);
39 static inline void tcg_gen_op1_i64(int opc
, TCGv_i64 arg1
)
42 *gen_opparam_ptr
++ = GET_TCGV_I64(arg1
);
45 static inline void tcg_gen_op1i(int opc
, TCGArg arg1
)
48 *gen_opparam_ptr
++ = arg1
;
51 static inline void tcg_gen_op2_i32(int opc
, TCGv_i32 arg1
, TCGv_i32 arg2
)
54 *gen_opparam_ptr
++ = GET_TCGV_I32(arg1
);
55 *gen_opparam_ptr
++ = GET_TCGV_I32(arg2
);
58 static inline void tcg_gen_op2_i64(int opc
, TCGv_i64 arg1
, TCGv_i64 arg2
)
61 *gen_opparam_ptr
++ = GET_TCGV_I64(arg1
);
62 *gen_opparam_ptr
++ = GET_TCGV_I64(arg2
);
65 static inline void tcg_gen_op2i_i32(int opc
, TCGv_i32 arg1
, TCGArg arg2
)
68 *gen_opparam_ptr
++ = GET_TCGV_I32(arg1
);
69 *gen_opparam_ptr
++ = arg2
;
72 static inline void tcg_gen_op2i_i64(int opc
, TCGv_i64 arg1
, TCGArg arg2
)
75 *gen_opparam_ptr
++ = GET_TCGV_I64(arg1
);
76 *gen_opparam_ptr
++ = arg2
;
79 static inline void tcg_gen_op2ii(int opc
, TCGArg arg1
, TCGArg arg2
)
82 *gen_opparam_ptr
++ = arg1
;
83 *gen_opparam_ptr
++ = arg2
;
86 static inline void tcg_gen_op3_i32(int opc
, TCGv_i32 arg1
, TCGv_i32 arg2
,
90 *gen_opparam_ptr
++ = GET_TCGV_I32(arg1
);
91 *gen_opparam_ptr
++ = GET_TCGV_I32(arg2
);
92 *gen_opparam_ptr
++ = GET_TCGV_I32(arg3
);
95 static inline void tcg_gen_op3_i64(int opc
, TCGv_i64 arg1
, TCGv_i64 arg2
,
99 *gen_opparam_ptr
++ = GET_TCGV_I64(arg1
);
100 *gen_opparam_ptr
++ = GET_TCGV_I64(arg2
);
101 *gen_opparam_ptr
++ = GET_TCGV_I64(arg3
);
104 static inline void tcg_gen_op3i_i32(int opc
, TCGv_i32 arg1
, TCGv_i32 arg2
,
107 *gen_opc_ptr
++ = opc
;
108 *gen_opparam_ptr
++ = GET_TCGV_I32(arg1
);
109 *gen_opparam_ptr
++ = GET_TCGV_I32(arg2
);
110 *gen_opparam_ptr
++ = arg3
;
113 static inline void tcg_gen_op3i_i64(int opc
, TCGv_i64 arg1
, TCGv_i64 arg2
,
116 *gen_opc_ptr
++ = opc
;
117 *gen_opparam_ptr
++ = GET_TCGV_I64(arg1
);
118 *gen_opparam_ptr
++ = GET_TCGV_I64(arg2
);
119 *gen_opparam_ptr
++ = arg3
;
122 static inline void tcg_gen_ldst_op_i32(int opc
, TCGv_i32 val
, TCGv_ptr base
,
125 *gen_opc_ptr
++ = opc
;
126 *gen_opparam_ptr
++ = GET_TCGV_I32(val
);
127 *gen_opparam_ptr
++ = GET_TCGV_PTR(base
);
128 *gen_opparam_ptr
++ = offset
;
131 static inline void tcg_gen_ldst_op_i64(int opc
, TCGv_i64 val
, TCGv_ptr base
,
134 *gen_opc_ptr
++ = opc
;
135 *gen_opparam_ptr
++ = GET_TCGV_I32(val
);
136 *gen_opparam_ptr
++ = GET_TCGV_PTR(base
);
137 *gen_opparam_ptr
++ = offset
;
140 static inline void tcg_gen_qemu_ldst_op_i64_i32(int opc
, TCGv_i64 val
, TCGv_i32 addr
,
143 *gen_opc_ptr
++ = opc
;
144 *gen_opparam_ptr
++ = GET_TCGV_I64(val
);
145 *gen_opparam_ptr
++ = GET_TCGV_I32(addr
);
146 *gen_opparam_ptr
++ = mem_index
;
149 static inline void tcg_gen_qemu_ldst_op_i64_i64(int opc
, TCGv_i64 val
, TCGv_i64 addr
,
152 *gen_opc_ptr
++ = opc
;
153 *gen_opparam_ptr
++ = GET_TCGV_I64(val
);
154 *gen_opparam_ptr
++ = GET_TCGV_I64(addr
);
155 *gen_opparam_ptr
++ = mem_index
;
158 static inline void tcg_gen_op4_i32(int opc
, TCGv_i32 arg1
, TCGv_i32 arg2
,
159 TCGv_i32 arg3
, TCGv_i32 arg4
)
161 *gen_opc_ptr
++ = opc
;
162 *gen_opparam_ptr
++ = GET_TCGV_I32(arg1
);
163 *gen_opparam_ptr
++ = GET_TCGV_I32(arg2
);
164 *gen_opparam_ptr
++ = GET_TCGV_I32(arg3
);
165 *gen_opparam_ptr
++ = GET_TCGV_I32(arg4
);
168 static inline void tcg_gen_op4_i64(int opc
, TCGv_i64 arg1
, TCGv_i64 arg2
,
169 TCGv_i64 arg3
, TCGv_i32 arg4
)
171 *gen_opc_ptr
++ = opc
;
172 *gen_opparam_ptr
++ = GET_TCGV_I64(arg1
);
173 *gen_opparam_ptr
++ = GET_TCGV_I64(arg2
);
174 *gen_opparam_ptr
++ = GET_TCGV_I64(arg3
);
175 *gen_opparam_ptr
++ = GET_TCGV_I64(arg4
);
178 static inline void tcg_gen_op4i_i32(int opc
, TCGv_i32 arg1
, TCGv_i32 arg2
,
179 TCGv_i32 arg3
, TCGArg arg4
)
181 *gen_opc_ptr
++ = opc
;
182 *gen_opparam_ptr
++ = GET_TCGV_I32(arg1
);
183 *gen_opparam_ptr
++ = GET_TCGV_I32(arg2
);
184 *gen_opparam_ptr
++ = GET_TCGV_I32(arg3
);
185 *gen_opparam_ptr
++ = arg4
;
188 static inline void tcg_gen_op4i_i64(int opc
, TCGv_i64 arg1
, TCGv_i64 arg2
,
189 TCGv_i64 arg3
, TCGArg arg4
)
191 *gen_opc_ptr
++ = opc
;
192 *gen_opparam_ptr
++ = GET_TCGV_I64(arg1
);
193 *gen_opparam_ptr
++ = GET_TCGV_I64(arg2
);
194 *gen_opparam_ptr
++ = GET_TCGV_I64(arg3
);
195 *gen_opparam_ptr
++ = arg4
;
198 static inline void tcg_gen_op4ii_i32(int opc
, TCGv_i32 arg1
, TCGv_i32 arg2
,
199 TCGArg arg3
, TCGArg arg4
)
201 *gen_opc_ptr
++ = opc
;
202 *gen_opparam_ptr
++ = GET_TCGV_I32(arg1
);
203 *gen_opparam_ptr
++ = GET_TCGV_I32(arg2
);
204 *gen_opparam_ptr
++ = arg3
;
205 *gen_opparam_ptr
++ = arg4
;
208 static inline void tcg_gen_op4ii_i64(int opc
, TCGv_i64 arg1
, TCGv_i64 arg2
,
209 TCGArg arg3
, TCGArg arg4
)
211 *gen_opc_ptr
++ = opc
;
212 *gen_opparam_ptr
++ = GET_TCGV_I64(arg1
);
213 *gen_opparam_ptr
++ = GET_TCGV_I64(arg2
);
214 *gen_opparam_ptr
++ = arg3
;
215 *gen_opparam_ptr
++ = arg4
;
218 static inline void tcg_gen_op5_i32(int opc
, TCGv_i32 arg1
, TCGv_i32 arg2
,
219 TCGv_i32 arg3
, TCGv_i32 arg4
, TCGv_i32 arg5
)
221 *gen_opc_ptr
++ = opc
;
222 *gen_opparam_ptr
++ = GET_TCGV_I32(arg1
);
223 *gen_opparam_ptr
++ = GET_TCGV_I32(arg2
);
224 *gen_opparam_ptr
++ = GET_TCGV_I32(arg3
);
225 *gen_opparam_ptr
++ = GET_TCGV_I32(arg4
);
226 *gen_opparam_ptr
++ = GET_TCGV_I32(arg5
);
229 static inline void tcg_gen_op5_i64(int opc
, TCGv_i64 arg1
, TCGv_i64 arg2
,
230 TCGv_i64 arg3
, TCGv_i64 arg4
, TCGv_i64 arg5
)
232 *gen_opc_ptr
++ = opc
;
233 *gen_opparam_ptr
++ = GET_TCGV_I64(arg1
);
234 *gen_opparam_ptr
++ = GET_TCGV_I64(arg2
);
235 *gen_opparam_ptr
++ = GET_TCGV_I64(arg3
);
236 *gen_opparam_ptr
++ = GET_TCGV_I64(arg4
);
237 *gen_opparam_ptr
++ = GET_TCGV_I64(arg5
);
240 static inline void tcg_gen_op5i_i32(int opc
, TCGv_i32 arg1
, TCGv_i32 arg2
,
241 TCGv_i32 arg3
, TCGv_i32 arg4
, TCGArg arg5
)
243 *gen_opc_ptr
++ = opc
;
244 *gen_opparam_ptr
++ = GET_TCGV_I32(arg1
);
245 *gen_opparam_ptr
++ = GET_TCGV_I32(arg2
);
246 *gen_opparam_ptr
++ = GET_TCGV_I32(arg3
);
247 *gen_opparam_ptr
++ = GET_TCGV_I32(arg4
);
248 *gen_opparam_ptr
++ = arg5
;
251 static inline void tcg_gen_op5i_i64(int opc
, TCGv_i64 arg1
, TCGv_i64 arg2
,
252 TCGv_i64 arg3
, TCGv_i64 arg4
, TCGArg arg5
)
254 *gen_opc_ptr
++ = opc
;
255 *gen_opparam_ptr
++ = GET_TCGV_I64(arg1
);
256 *gen_opparam_ptr
++ = GET_TCGV_I64(arg2
);
257 *gen_opparam_ptr
++ = GET_TCGV_I64(arg3
);
258 *gen_opparam_ptr
++ = GET_TCGV_I64(arg4
);
259 *gen_opparam_ptr
++ = arg5
;
262 static inline void tcg_gen_op6_i32(int opc
, TCGv_i32 arg1
, TCGv_i32 arg2
,
263 TCGv_i32 arg3
, TCGv_i32 arg4
, TCGv_i32 arg5
,
266 *gen_opc_ptr
++ = opc
;
267 *gen_opparam_ptr
++ = GET_TCGV_I32(arg1
);
268 *gen_opparam_ptr
++ = GET_TCGV_I32(arg2
);
269 *gen_opparam_ptr
++ = GET_TCGV_I32(arg3
);
270 *gen_opparam_ptr
++ = GET_TCGV_I32(arg4
);
271 *gen_opparam_ptr
++ = GET_TCGV_I32(arg5
);
272 *gen_opparam_ptr
++ = GET_TCGV_I32(arg6
);
275 static inline void tcg_gen_op6_i64(int opc
, TCGv_i64 arg1
, TCGv_i64 arg2
,
276 TCGv_i64 arg3
, TCGv_i64 arg4
, TCGv_i64 arg5
,
279 *gen_opc_ptr
++ = opc
;
280 *gen_opparam_ptr
++ = GET_TCGV_I64(arg1
);
281 *gen_opparam_ptr
++ = GET_TCGV_I64(arg2
);
282 *gen_opparam_ptr
++ = GET_TCGV_I64(arg3
);
283 *gen_opparam_ptr
++ = GET_TCGV_I64(arg4
);
284 *gen_opparam_ptr
++ = GET_TCGV_I64(arg5
);
285 *gen_opparam_ptr
++ = GET_TCGV_I64(arg6
);
288 static inline void tcg_gen_op6ii_i32(int opc
, TCGv_i32 arg1
, TCGv_i32 arg2
,
289 TCGv_i32 arg3
, TCGv_i32 arg4
, TCGArg arg5
,
292 *gen_opc_ptr
++ = opc
;
293 *gen_opparam_ptr
++ = GET_TCGV_I32(arg1
);
294 *gen_opparam_ptr
++ = GET_TCGV_I32(arg2
);
295 *gen_opparam_ptr
++ = GET_TCGV_I32(arg3
);
296 *gen_opparam_ptr
++ = GET_TCGV_I32(arg4
);
297 *gen_opparam_ptr
++ = arg5
;
298 *gen_opparam_ptr
++ = arg6
;
301 static inline void tcg_gen_op6ii_i64(int opc
, TCGv_i64 arg1
, TCGv_i64 arg2
,
302 TCGv_i64 arg3
, TCGv_i64 arg4
, TCGArg arg5
,
305 *gen_opc_ptr
++ = opc
;
306 *gen_opparam_ptr
++ = GET_TCGV_I64(arg1
);
307 *gen_opparam_ptr
++ = GET_TCGV_I64(arg2
);
308 *gen_opparam_ptr
++ = GET_TCGV_I64(arg3
);
309 *gen_opparam_ptr
++ = GET_TCGV_I64(arg4
);
310 *gen_opparam_ptr
++ = arg5
;
311 *gen_opparam_ptr
++ = arg6
;
314 static inline void gen_set_label(int n
)
316 tcg_gen_op1i(INDEX_op_set_label
, n
);
319 static inline void tcg_gen_br(int label
)
321 tcg_gen_op1i(INDEX_op_br
, label
);
324 static inline void tcg_gen_mov_i32(TCGv_i32 ret
, TCGv_i32 arg
)
326 if (GET_TCGV_I32(ret
) != GET_TCGV_I32(arg
))
327 tcg_gen_op2_i32(INDEX_op_mov_i32
, ret
, arg
);
330 static inline void tcg_gen_movi_i32(TCGv_i32 ret
, int32_t arg
)
332 tcg_gen_op2i_i32(INDEX_op_movi_i32
, ret
, arg
);
336 static inline void tcg_gen_helperN(void *func
, int flags
, int sizemask
,
337 TCGArg ret
, int nargs
, TCGArg
*args
)
340 fn
= tcg_const_ptr((tcg_target_long
)func
);
341 tcg_gen_callN(&tcg_ctx
, fn
, flags
, sizemask
, ret
,
343 tcg_temp_free_ptr(fn
);
346 /* FIXME: Should this be pure? */
347 static inline void tcg_gen_helper64(void *func
, TCGv_i64 ret
,
348 TCGv_i64 a
, TCGv_i64 b
)
352 fn
= tcg_const_ptr((tcg_target_long
)func
);
353 args
[0] = GET_TCGV_I64(a
);
354 args
[1] = GET_TCGV_I64(b
);
355 tcg_gen_callN(&tcg_ctx
, fn
, 0, 7, GET_TCGV_I64(ret
), 2, args
);
356 tcg_temp_free_ptr(fn
);
361 static inline void tcg_gen_ld8u_i32(TCGv_i32 ret
, TCGv_ptr arg2
, tcg_target_long offset
)
363 tcg_gen_ldst_op_i32(INDEX_op_ld8u_i32
, ret
, arg2
, offset
);
366 static inline void tcg_gen_ld8s_i32(TCGv_i32 ret
, TCGv_ptr arg2
, tcg_target_long offset
)
368 tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32
, ret
, arg2
, offset
);
371 static inline void tcg_gen_ld16u_i32(TCGv_i32 ret
, TCGv_ptr arg2
, tcg_target_long offset
)
373 tcg_gen_ldst_op_i32(INDEX_op_ld16u_i32
, ret
, arg2
, offset
);
376 static inline void tcg_gen_ld16s_i32(TCGv_i32 ret
, TCGv_ptr arg2
, tcg_target_long offset
)
378 tcg_gen_ldst_op_i32(INDEX_op_ld16s_i32
, ret
, arg2
, offset
);
381 static inline void tcg_gen_ld_i32(TCGv_i32 ret
, TCGv_ptr arg2
, tcg_target_long offset
)
383 tcg_gen_ldst_op_i32(INDEX_op_ld_i32
, ret
, arg2
, offset
);
386 static inline void tcg_gen_st8_i32(TCGv_i32 arg1
, TCGv_ptr arg2
, tcg_target_long offset
)
388 tcg_gen_ldst_op_i32(INDEX_op_st8_i32
, arg1
, arg2
, offset
);
391 static inline void tcg_gen_st16_i32(TCGv_i32 arg1
, TCGv_ptr arg2
, tcg_target_long offset
)
393 tcg_gen_ldst_op_i32(INDEX_op_st16_i32
, arg1
, arg2
, offset
);
396 static inline void tcg_gen_st_i32(TCGv_i32 arg1
, TCGv_ptr arg2
, tcg_target_long offset
)
398 tcg_gen_ldst_op_i32(INDEX_op_st_i32
, arg1
, arg2
, offset
);
401 static inline void tcg_gen_add_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
403 tcg_gen_op3_i32(INDEX_op_add_i32
, ret
, arg1
, arg2
);
406 static inline void tcg_gen_addi_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
408 /* some cases can be optimized here */
410 tcg_gen_mov_i32(ret
, arg1
);
412 TCGv_i32 t0
= tcg_const_i32(arg2
);
413 tcg_gen_add_i32(ret
, arg1
, t0
);
414 tcg_temp_free_i32(t0
);
418 static inline void tcg_gen_sub_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
420 tcg_gen_op3_i32(INDEX_op_sub_i32
, ret
, arg1
, arg2
);
423 static inline void tcg_gen_subfi_i32(TCGv_i32 ret
, int32_t arg1
, TCGv_i32 arg2
)
425 TCGv_i32 t0
= tcg_const_i32(arg1
);
426 tcg_gen_sub_i32(ret
, t0
, arg2
);
427 tcg_temp_free_i32(t0
);
430 static inline void tcg_gen_subi_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
432 /* some cases can be optimized here */
434 tcg_gen_mov_i32(ret
, arg1
);
436 TCGv_i32 t0
= tcg_const_i32(arg2
);
437 tcg_gen_sub_i32(ret
, arg1
, t0
);
438 tcg_temp_free_i32(t0
);
442 static inline void tcg_gen_and_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
444 tcg_gen_op3_i32(INDEX_op_and_i32
, ret
, arg1
, arg2
);
447 static inline void tcg_gen_andi_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
449 /* some cases can be optimized here */
451 tcg_gen_movi_i32(ret
, 0);
452 } else if (arg2
== 0xffffffff) {
453 tcg_gen_mov_i32(ret
, arg1
);
455 TCGv_i32 t0
= tcg_const_i32(arg2
);
456 tcg_gen_and_i32(ret
, arg1
, t0
);
457 tcg_temp_free_i32(t0
);
461 static inline void tcg_gen_or_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
463 tcg_gen_op3_i32(INDEX_op_or_i32
, ret
, arg1
, arg2
);
466 static inline void tcg_gen_ori_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
468 /* some cases can be optimized here */
469 if (arg2
== 0xffffffff) {
470 tcg_gen_movi_i32(ret
, 0xffffffff);
471 } else if (arg2
== 0) {
472 tcg_gen_mov_i32(ret
, arg1
);
474 TCGv_i32 t0
= tcg_const_i32(arg2
);
475 tcg_gen_or_i32(ret
, arg1
, t0
);
476 tcg_temp_free_i32(t0
);
480 static inline void tcg_gen_xor_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
482 tcg_gen_op3_i32(INDEX_op_xor_i32
, ret
, arg1
, arg2
);
485 static inline void tcg_gen_xori_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
487 /* some cases can be optimized here */
489 tcg_gen_mov_i32(ret
, arg1
);
491 TCGv_i32 t0
= tcg_const_i32(arg2
);
492 tcg_gen_xor_i32(ret
, arg1
, t0
);
493 tcg_temp_free_i32(t0
);
497 static inline void tcg_gen_shl_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
499 tcg_gen_op3_i32(INDEX_op_shl_i32
, ret
, arg1
, arg2
);
502 static inline void tcg_gen_shli_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
505 tcg_gen_mov_i32(ret
, arg1
);
507 TCGv_i32 t0
= tcg_const_i32(arg2
);
508 tcg_gen_shl_i32(ret
, arg1
, t0
);
509 tcg_temp_free_i32(t0
);
513 static inline void tcg_gen_shr_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
515 tcg_gen_op3_i32(INDEX_op_shr_i32
, ret
, arg1
, arg2
);
518 static inline void tcg_gen_shri_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
521 tcg_gen_mov_i32(ret
, arg1
);
523 TCGv_i32 t0
= tcg_const_i32(arg2
);
524 tcg_gen_shr_i32(ret
, arg1
, t0
);
525 tcg_temp_free_i32(t0
);
529 static inline void tcg_gen_sar_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
531 tcg_gen_op3_i32(INDEX_op_sar_i32
, ret
, arg1
, arg2
);
534 static inline void tcg_gen_sari_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
537 tcg_gen_mov_i32(ret
, arg1
);
539 TCGv_i32 t0
= tcg_const_i32(arg2
);
540 tcg_gen_sar_i32(ret
, arg1
, t0
);
541 tcg_temp_free_i32(t0
);
545 static inline void tcg_gen_brcond_i32(int cond
, TCGv_i32 arg1
, TCGv_i32 arg2
,
548 tcg_gen_op4ii_i32(INDEX_op_brcond_i32
, arg1
, arg2
, cond
, label_index
);
551 static inline void tcg_gen_brcondi_i32(int cond
, TCGv_i32 arg1
, int32_t arg2
,
554 TCGv_i32 t0
= tcg_const_i32(arg2
);
555 tcg_gen_brcond_i32(cond
, arg1
, t0
, label_index
);
556 tcg_temp_free_i32(t0
);
559 static inline void tcg_gen_mul_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
561 tcg_gen_op3_i32(INDEX_op_mul_i32
, ret
, arg1
, arg2
);
564 static inline void tcg_gen_muli_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
566 TCGv_i32 t0
= tcg_const_i32(arg2
);
567 tcg_gen_mul_i32(ret
, arg1
, t0
);
568 tcg_temp_free_i32(t0
);
571 #ifdef TCG_TARGET_HAS_div_i32
572 static inline void tcg_gen_div_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
574 tcg_gen_op3_i32(INDEX_op_div_i32
, ret
, arg1
, arg2
);
577 static inline void tcg_gen_rem_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
579 tcg_gen_op3_i32(INDEX_op_rem_i32
, ret
, arg1
, arg2
);
582 static inline void tcg_gen_divu_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
584 tcg_gen_op3_i32(INDEX_op_divu_i32
, ret
, arg1
, arg2
);
587 static inline void tcg_gen_remu_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
589 tcg_gen_op3_i32(INDEX_op_remu_i32
, ret
, arg1
, arg2
);
592 static inline void tcg_gen_div_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
595 t0
= tcg_temp_new_i32();
596 tcg_gen_sari_i32(t0
, arg1
, 31);
597 tcg_gen_op5_i32(INDEX_op_div2_i32
, ret
, t0
, arg1
, t0
, arg2
);
598 tcg_temp_free_i32(t0
);
601 static inline void tcg_gen_rem_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
604 t0
= tcg_temp_new_i32();
605 tcg_gen_sari_i32(t0
, arg1
, 31);
606 tcg_gen_op5_i32(INDEX_op_div2_i32
, t0
, ret
, arg1
, t0
, arg2
);
607 tcg_temp_free_i32(t0
);
610 static inline void tcg_gen_divu_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
613 t0
= tcg_temp_new_i32();
614 tcg_gen_movi_i32(t0
, 0);
615 tcg_gen_op5_i32(INDEX_op_divu2_i32
, ret
, t0
, arg1
, t0
, arg2
);
616 tcg_temp_free_i32(t0
);
619 static inline void tcg_gen_remu_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
622 t0
= tcg_temp_new_i32();
623 tcg_gen_movi_i32(t0
, 0);
624 tcg_gen_op5_i32(INDEX_op_divu2_i32
, t0
, ret
, arg1
, t0
, arg2
);
625 tcg_temp_free_i32(t0
);
629 #if TCG_TARGET_REG_BITS == 32
631 static inline void tcg_gen_mov_i64(TCGv_i64 ret
, TCGv_i64 arg
)
633 if (GET_TCGV_I64(ret
) != GET_TCGV_I64(arg
)) {
634 tcg_gen_mov_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
635 tcg_gen_mov_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg
));
639 static inline void tcg_gen_movi_i64(TCGv_i64 ret
, int64_t arg
)
641 tcg_gen_movi_i32(TCGV_LOW(ret
), arg
);
642 tcg_gen_movi_i32(TCGV_HIGH(ret
), arg
>> 32);
645 static inline void tcg_gen_ld8u_i64(TCGv_i64 ret
, TCGv_ptr arg2
,
646 tcg_target_long offset
)
648 tcg_gen_ld8u_i32(TCGV_LOW(ret
), arg2
, offset
);
649 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
652 static inline void tcg_gen_ld8s_i64(TCGv_i64 ret
, TCGv_ptr arg2
,
653 tcg_target_long offset
)
655 tcg_gen_ld8s_i32(TCGV_LOW(ret
), arg2
, offset
);
656 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_HIGH(ret
), 31);
659 static inline void tcg_gen_ld16u_i64(TCGv_i64 ret
, TCGv_ptr arg2
,
660 tcg_target_long offset
)
662 tcg_gen_ld16u_i32(TCGV_LOW(ret
), TCGV_LOW(arg2
), offset
);
663 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
666 static inline void tcg_gen_ld16s_i64(TCGv_i64 ret
, TCGv_ptr arg2
,
667 tcg_target_long offset
)
669 tcg_gen_ld16s_i32(TCGV_LOW(ret
), arg2
, offset
);
670 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
673 static inline void tcg_gen_ld32u_i64(TCGv_i64 ret
, TCGv_ptr arg2
,
674 tcg_target_long offset
)
676 tcg_gen_ld_i32(TCGV_LOW(ret
), arg2
, offset
);
677 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
680 static inline void tcg_gen_ld32s_i64(TCGv_i64 ret
, TCGv_ptr arg2
,
681 tcg_target_long offset
)
683 tcg_gen_ld_i32(TCGV_LOW(ret
), arg2
, offset
);
684 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
687 static inline void tcg_gen_ld_i64(TCGv_i64 ret
, TCGv_ptr arg2
,
688 tcg_target_long offset
)
690 /* since arg2 and ret have different types, they cannot be the
692 #ifdef TCG_TARGET_WORDS_BIGENDIAN
693 tcg_gen_ld_i32(TCGV_HIGH(ret
), arg2
, offset
);
694 tcg_gen_ld_i32(TCGV_LOW(ret
), arg2
, offset
+ 4);
696 tcg_gen_ld_i32(TCGV_LOW(ret
), arg2
, offset
);
697 tcg_gen_ld_i32(TCGV_HIGH(ret
), arg2
, offset
+ 4);
701 static inline void tcg_gen_st8_i64(TCGv_i64 arg1
, TCGv_ptr arg2
,
702 tcg_target_long offset
)
704 tcg_gen_st8_i32(TCGV_LOW(arg1
), arg2
, offset
);
707 static inline void tcg_gen_st16_i64(TCGv_i64 arg1
, TCGv_ptr arg2
,
708 tcg_target_long offset
)
710 tcg_gen_st16_i32(TCGV_LOW(arg1
), arg2
, offset
);
713 static inline void tcg_gen_st32_i64(TCGv_i64 arg1
, TCGv_ptr arg2
,
714 tcg_target_long offset
)
716 tcg_gen_st_i32(TCGV_LOW(arg1
), arg2
, offset
);
719 static inline void tcg_gen_st_i64(TCGv_i64 arg1
, TCGv_ptr arg2
,
720 tcg_target_long offset
)
722 #ifdef TCG_TARGET_WORDS_BIGENDIAN
723 tcg_gen_st_i32(TCGV_HIGH(arg1
), arg2
, offset
);
724 tcg_gen_st_i32(TCGV_LOW(arg1
), arg2
, offset
+ 4);
726 tcg_gen_st_i32(TCGV_LOW(arg1
), arg2
, offset
);
727 tcg_gen_st_i32(TCGV_HIGH(arg1
), arg2
, offset
+ 4);
731 static inline void tcg_gen_add_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
733 tcg_gen_op6_i32(INDEX_op_add2_i32
, TCGV_LOW(ret
), TCGV_HIGH(ret
),
734 TCGV_LOW(arg1
), TCGV_HIGH(arg1
), TCGV_LOW(arg2
),
738 static inline void tcg_gen_sub_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
740 tcg_gen_op6_i32(INDEX_op_sub2_i32
, TCGV_LOW(ret
), TCGV_HIGH(ret
),
741 TCGV_LOW(arg1
), TCGV_HIGH(arg1
), TCGV_LOW(arg2
),
745 static inline void tcg_gen_and_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
747 tcg_gen_and_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), TCGV_LOW(arg2
));
748 tcg_gen_and_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), TCGV_HIGH(arg2
));
751 static inline void tcg_gen_andi_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
753 tcg_gen_andi_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), arg2
);
754 tcg_gen_andi_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), arg2
>> 32);
757 static inline void tcg_gen_or_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
759 tcg_gen_or_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), TCGV_LOW(arg2
));
760 tcg_gen_or_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), TCGV_HIGH(arg2
));
763 static inline void tcg_gen_ori_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
765 tcg_gen_ori_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), arg2
);
766 tcg_gen_ori_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), arg2
>> 32);
769 static inline void tcg_gen_xor_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
771 tcg_gen_xor_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), TCGV_LOW(arg2
));
772 tcg_gen_xor_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), TCGV_HIGH(arg2
));
775 static inline void tcg_gen_xori_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
777 tcg_gen_xori_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), arg2
);
778 tcg_gen_xori_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), arg2
>> 32);
781 /* XXX: use generic code when basic block handling is OK or CPU
782 specific code (x86) */
783 static inline void tcg_gen_shl_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
785 tcg_gen_helper64(tcg_helper_shl_i64
, ret
, arg1
, arg2
);
788 static inline void tcg_gen_shli_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
790 tcg_gen_shifti_i64(ret
, arg1
, arg2
, 0, 0);
793 static inline void tcg_gen_shr_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
795 tcg_gen_helper64(tcg_helper_shr_i64
, ret
, arg1
, arg2
);
798 static inline void tcg_gen_shri_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
800 tcg_gen_shifti_i64(ret
, arg1
, arg2
, 1, 0);
803 static inline void tcg_gen_sar_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
805 tcg_gen_helper64(tcg_helper_sar_i64
, ret
, arg1
, arg2
);
808 static inline void tcg_gen_sari_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
810 tcg_gen_shifti_i64(ret
, arg1
, arg2
, 1, 1);
813 static inline void tcg_gen_brcond_i64(int cond
, TCGv_i64 arg1
, TCGv_i64 arg2
,
816 tcg_gen_op6ii_i32(INDEX_op_brcond2_i32
,
817 TCGV_LOW(arg1
), TCGV_HIGH(arg1
), TCGV_LOW(arg2
),
818 TCGV_HIGH(arg2
), cond
, label_index
);
821 static inline void tcg_gen_mul_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
826 t0
= tcg_temp_new_i64();
827 t1
= tcg_temp_new_i32();
829 tcg_gen_op4_i32(INDEX_op_mulu2_i32
, TCGV_LOW(t0
), TCGV_HIGH(t0
),
830 TCGV_LOW(arg1
), TCGV_LOW(arg2
));
832 tcg_gen_mul_i32(t1
, TCGV_LOW(arg1
), TCGV_HIGH(arg2
));
833 tcg_gen_add_i32(TCGV_HIGH(t0
), TCGV_HIGH(t0
), t1
);
834 tcg_gen_mul_i32(t1
, TCGV_HIGH(arg1
), TCGV_LOW(arg2
));
835 tcg_gen_add_i32(TCGV_HIGH(t0
), TCGV_HIGH(t0
), t1
);
837 tcg_gen_mov_i64(ret
, t0
);
838 tcg_temp_free_i64(t0
);
839 tcg_temp_free_i32(t1
);
842 static inline void tcg_gen_div_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
844 tcg_gen_helper64(tcg_helper_div_i64
, ret
, arg1
, arg2
);
847 static inline void tcg_gen_rem_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
849 tcg_gen_helper64(tcg_helper_rem_i64
, ret
, arg1
, arg2
);
852 static inline void tcg_gen_divu_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
854 tcg_gen_helper64(tcg_helper_divu_i64
, ret
, arg1
, arg2
);
857 static inline void tcg_gen_remu_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
859 tcg_gen_helper64(tcg_helper_remu_i64
, ret
, arg1
, arg2
);
864 static inline void tcg_gen_mov_i64(TCGv_i64 ret
, TCGv_i64 arg
)
866 if (GET_TCGV_I64(ret
) != GET_TCGV_I64(arg
))
867 tcg_gen_op2_i64(INDEX_op_mov_i64
, ret
, arg
);
870 static inline void tcg_gen_movi_i64(TCGv_i64 ret
, int64_t arg
)
872 tcg_gen_op2i_i64(INDEX_op_movi_i64
, ret
, arg
);
875 static inline void tcg_gen_ld8u_i64(TCGv_i64 ret
, TCGv_i64 arg2
,
876 tcg_target_long offset
)
878 tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64
, ret
, arg2
, offset
);
881 static inline void tcg_gen_ld8s_i64(TCGv_i64 ret
, TCGv_i64 arg2
,
882 tcg_target_long offset
)
884 tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64
, ret
, arg2
, offset
);
887 static inline void tcg_gen_ld16u_i64(TCGv_i64 ret
, TCGv_i64 arg2
,
888 tcg_target_long offset
)
890 tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64
, ret
, arg2
, offset
);
893 static inline void tcg_gen_ld16s_i64(TCGv_i64 ret
, TCGv_i64 arg2
,
894 tcg_target_long offset
)
896 tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64
, ret
, arg2
, offset
);
899 static inline void tcg_gen_ld32u_i64(TCGv_i64 ret
, TCGv_i64 arg2
,
900 tcg_target_long offset
)
902 tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64
, ret
, arg2
, offset
);
905 static inline void tcg_gen_ld32s_i64(TCGv_i64 ret
, TCGv_i64 arg2
,
906 tcg_target_long offset
)
908 tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64
, ret
, arg2
, offset
);
911 static inline void tcg_gen_ld_i64(TCGv_i64 ret
, TCGv_i64 arg2
, tcg_target_long offset
)
913 tcg_gen_ldst_op_i64(INDEX_op_ld_i64
, ret
, arg2
, offset
);
916 static inline void tcg_gen_st8_i64(TCGv_i64 arg1
, TCGv_i64 arg2
,
917 tcg_target_long offset
)
919 tcg_gen_ldst_op_i64(INDEX_op_st8_i64
, arg1
, arg2
, offset
);
922 static inline void tcg_gen_st16_i64(TCGv_i64 arg1
, TCGv_i64 arg2
,
923 tcg_target_long offset
)
925 tcg_gen_ldst_op_i64(INDEX_op_st16_i64
, arg1
, arg2
, offset
);
928 static inline void tcg_gen_st32_i64(TCGv_i64 arg1
, TCGv_i64 arg2
,
929 tcg_target_long offset
)
931 tcg_gen_ldst_op_i64(INDEX_op_st32_i64
, arg1
, arg2
, offset
);
934 static inline void tcg_gen_st_i64(TCGv_i64 arg1
, TCGv_i64 arg2
, tcg_target_long offset
)
936 tcg_gen_ldst_op_i64(INDEX_op_st_i64
, arg1
, arg2
, offset
);
939 static inline void tcg_gen_add_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
941 tcg_gen_op3_i64(INDEX_op_add_i64
, ret
, arg1
, arg2
);
944 static inline void tcg_gen_sub_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
946 tcg_gen_op3_i64(INDEX_op_sub_i64
, ret
, arg1
, arg2
);
949 static inline void tcg_gen_and_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
951 tcg_gen_op3_i64(INDEX_op_and_i64
, ret
, arg1
, arg2
);
954 static inline void tcg_gen_andi_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
956 TCGv_i64 t0
= tcg_const_i64(arg2
);
957 tcg_gen_and_i64(ret
, arg1
, t0
);
958 tcg_temp_free_i64(t0
);
961 static inline void tcg_gen_or_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
963 tcg_gen_op3_i64(INDEX_op_or_i64
, ret
, arg1
, arg2
);
966 static inline void tcg_gen_ori_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
968 TCGv_i64 t0
= tcg_const_i64(arg2
);
969 tcg_gen_or_i64(ret
, arg1
, t0
);
970 tcg_temp_free_i64(t0
);
973 static inline void tcg_gen_xor_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
975 tcg_gen_op3_i64(INDEX_op_xor_i64
, ret
, arg1
, arg2
);
978 static inline void tcg_gen_xori_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
980 TCGv_i64 t0
= tcg_const_i64(arg2
);
981 tcg_gen_xor_i64(ret
, arg1
, t0
);
982 tcg_temp_free_i64(t0
);
985 static inline void tcg_gen_shl_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
987 tcg_gen_op3_i64(INDEX_op_shl_i64
, ret
, arg1
, arg2
);
990 static inline void tcg_gen_shli_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
993 tcg_gen_mov_i64(ret
, arg1
);
995 TCGv_i64 t0
= tcg_const_i64(arg2
);
996 tcg_gen_shl_i64(ret
, arg1
, t0
);
997 tcg_temp_free_i64(t0
);
1001 static inline void tcg_gen_shr_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1003 tcg_gen_op3_i64(INDEX_op_shr_i64
, ret
, arg1
, arg2
);
1006 static inline void tcg_gen_shri_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1009 tcg_gen_mov_i64(ret
, arg1
);
1011 TCGv_i64 t0
= tcg_const_i64(arg2
);
1012 tcg_gen_shr_i64(ret
, arg1
, t0
);
1013 tcg_temp_free_i64(t0
);
1017 static inline void tcg_gen_sar_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1019 tcg_gen_op3_i64(INDEX_op_sar_i64
, ret
, arg1
, arg2
);
1022 static inline void tcg_gen_sari_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1025 tcg_gen_mov_i64(ret
, arg1
);
1027 TCGv_i64 t0
= tcg_const_i64(arg2
);
1028 tcg_gen_sar_i64(ret
, arg1
, t0
);
1029 tcg_temp_free_i64(t0
);
1033 static inline void tcg_gen_brcond_i64(int cond
, TCGv_i64 arg1
, TCGv_i64 arg2
,
1036 tcg_gen_op4ii_i64(INDEX_op_brcond_i64
, arg1
, arg2
, cond
, label_index
);
1039 static inline void tcg_gen_mul_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1041 tcg_gen_op3_i64(INDEX_op_mul_i64
, ret
, arg1
, arg2
);
1044 #ifdef TCG_TARGET_HAS_div_i64
1045 static inline void tcg_gen_div_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1047 tcg_gen_op3_i64(INDEX_op_div_i64
, ret
, arg1
, arg2
);
1050 static inline void tcg_gen_rem_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1052 tcg_gen_op3_i64(INDEX_op_rem_i64
, ret
, arg1
, arg2
);
1055 static inline void tcg_gen_divu_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1057 tcg_gen_op3_i64(INDEX_op_divu_i64
, ret
, arg1
, arg2
);
1060 static inline void tcg_gen_remu_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1062 tcg_gen_op3_i64(INDEX_op_remu_i64
, ret
, arg1
, arg2
);
1065 static inline void tcg_gen_div_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1068 t0
= tcg_temp_new_i64();
1069 tcg_gen_sari_i64(t0
, arg1
, 63);
1070 tcg_gen_op5_i64(INDEX_op_div2_i64
, ret
, t0
, arg1
, t0
, arg2
);
1071 tcg_temp_free_i64(t0
);
1074 static inline void tcg_gen_rem_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1077 t0
= tcg_temp_new_i64();
1078 tcg_gen_sari_i64(t0
, arg1
, 63);
1079 tcg_gen_op5_i64(INDEX_op_div2_i64
, t0
, ret
, arg1
, t0
, arg2
);
1080 tcg_temp_free_i64(t0
);
1083 static inline void tcg_gen_divu_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1086 t0
= tcg_temp_new_i64();
1087 tcg_gen_movi_i64(t0
, 0);
1088 tcg_gen_op5_i64(INDEX_op_divu2_i64
, ret
, t0
, arg1
, t0
, arg2
);
1089 tcg_temp_free_i64(t0
);
1092 static inline void tcg_gen_remu_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1095 t0
= tcg_temp_new_i64();
1096 tcg_gen_movi_i64(t0
, 0);
1097 tcg_gen_op5_i64(INDEX_op_divu2_i64
, t0
, ret
, arg1
, t0
, arg2
);
1098 tcg_temp_free_i64(t0
);
1104 static inline void tcg_gen_addi_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1106 /* some cases can be optimized here */
1108 tcg_gen_mov_i64(ret
, arg1
);
1110 TCGv_i64 t0
= tcg_const_i64(arg2
);
1111 tcg_gen_add_i64(ret
, arg1
, t0
);
1112 tcg_temp_free_i64(t0
);
1116 static inline void tcg_gen_subfi_i64(TCGv_i64 ret
, int64_t arg1
, TCGv_i64 arg2
)
1118 TCGv_i64 t0
= tcg_const_i64(arg1
);
1119 tcg_gen_sub_i64(ret
, t0
, arg2
);
1120 tcg_temp_free_i64(t0
);
1123 static inline void tcg_gen_subi_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1125 /* some cases can be optimized here */
1127 tcg_gen_mov_i64(ret
, arg1
);
1129 TCGv_i64 t0
= tcg_const_i64(arg2
);
1130 tcg_gen_sub_i64(ret
, arg1
, t0
);
1131 tcg_temp_free_i64(t0
);
1134 static inline void tcg_gen_brcondi_i64(int cond
, TCGv_i64 arg1
, int64_t arg2
,
1137 TCGv_i64 t0
= tcg_const_i64(arg2
);
1138 tcg_gen_brcond_i64(cond
, arg1
, t0
, label_index
);
1139 tcg_temp_free_i64(t0
);
1142 static inline void tcg_gen_muli_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1144 TCGv_i64 t0
= tcg_const_i64(arg2
);
1145 tcg_gen_mul_i64(ret
, arg1
, t0
);
1146 tcg_temp_free_i64(t0
);
1150 /***************************************/
1151 /* optional operations */
1153 static inline void tcg_gen_ext8s_i32(TCGv_i32 ret
, TCGv_i32 arg
)
1155 #ifdef TCG_TARGET_HAS_ext8s_i32
1156 tcg_gen_op2_i32(INDEX_op_ext8s_i32
, ret
, arg
);
1158 tcg_gen_shli_i32(ret
, arg
, 24);
1159 tcg_gen_sari_i32(ret
, ret
, 24);
1163 static inline void tcg_gen_ext16s_i32(TCGv_i32 ret
, TCGv_i32 arg
)
1165 #ifdef TCG_TARGET_HAS_ext16s_i32
1166 tcg_gen_op2_i32(INDEX_op_ext16s_i32
, ret
, arg
);
1168 tcg_gen_shli_i32(ret
, arg
, 16);
1169 tcg_gen_sari_i32(ret
, ret
, 16);
1173 /* These are currently just for convenience.
1174 We assume a target will recognise these automatically . */
1175 static inline void tcg_gen_ext8u_i32(TCGv_i32 ret
, TCGv_i32 arg
)
1177 tcg_gen_andi_i32(ret
, arg
, 0xffu
);
1180 static inline void tcg_gen_ext16u_i32(TCGv_i32 ret
, TCGv_i32 arg
)
1182 tcg_gen_andi_i32(ret
, arg
, 0xffffu
);
1185 /* Note: we assume the two high bytes are set to zero */
1186 static inline void tcg_gen_bswap16_i32(TCGv_i32 ret
, TCGv_i32 arg
)
1188 #ifdef TCG_TARGET_HAS_bswap16_i32
1189 tcg_gen_op2_i32(INDEX_op_bswap16_i32
, ret
, arg
);
1192 t0
= tcg_temp_new_i32();
1193 t1
= tcg_temp_new_i32();
1195 tcg_gen_shri_i32(t0
, arg
, 8);
1196 tcg_gen_andi_i32(t1
, arg
, 0x000000ff);
1197 tcg_gen_shli_i32(t1
, t1
, 8);
1198 tcg_gen_or_i32(ret
, t0
, t1
);
1199 tcg_temp_free_i32(t0
);
1200 tcg_temp_free_i32(t1
);
1204 static inline void tcg_gen_bswap_i32(TCGv_i32 ret
, TCGv_i32 arg
)
1206 #ifdef TCG_TARGET_HAS_bswap_i32
1207 tcg_gen_op2_i32(INDEX_op_bswap_i32
, ret
, arg
);
1210 t0
= tcg_temp_new_i32();
1211 t1
= tcg_temp_new_i32();
1213 tcg_gen_shli_i32(t0
, arg
, 24);
1215 tcg_gen_andi_i32(t1
, arg
, 0x0000ff00);
1216 tcg_gen_shli_i32(t1
, t1
, 8);
1217 tcg_gen_or_i32(t0
, t0
, t1
);
1219 tcg_gen_shri_i32(t1
, arg
, 8);
1220 tcg_gen_andi_i32(t1
, t1
, 0x0000ff00);
1221 tcg_gen_or_i32(t0
, t0
, t1
);
1223 tcg_gen_shri_i32(t1
, arg
, 24);
1224 tcg_gen_or_i32(ret
, t0
, t1
);
1225 tcg_temp_free_i32(t0
);
1226 tcg_temp_free_i32(t1
);
1230 #if TCG_TARGET_REG_BITS == 32
1231 static inline void tcg_gen_ext8s_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1233 tcg_gen_ext8s_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1234 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
1237 static inline void tcg_gen_ext16s_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1239 tcg_gen_ext16s_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1240 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
1243 static inline void tcg_gen_ext32s_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1245 tcg_gen_mov_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1246 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
1249 static inline void tcg_gen_ext8u_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1251 tcg_gen_ext8u_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1252 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1255 static inline void tcg_gen_ext16u_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1257 tcg_gen_ext16u_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1258 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1261 static inline void tcg_gen_ext32u_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1263 tcg_gen_mov_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1264 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1267 static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret
, TCGv_i64 arg
)
1269 tcg_gen_mov_i32(ret
, TCGV_LOW(arg
));
1272 static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret
, TCGv_i32 arg
)
1274 tcg_gen_mov_i32(TCGV_LOW(ret
), arg
);
1275 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1278 static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret
, TCGv_i32 arg
)
1280 tcg_gen_mov_i32(TCGV_LOW(ret
), arg
);
1281 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
1284 static inline void tcg_gen_bswap_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1287 t0
= tcg_temp_new_i32();
1288 t1
= tcg_temp_new_i32();
1290 tcg_gen_bswap_i32(t0
, TCGV_LOW(arg
));
1291 tcg_gen_bswap_i32(t1
, TCGV_HIGH(arg
));
1292 tcg_gen_mov_i32(TCGV_LOW(ret
), t1
);
1293 tcg_gen_mov_i32(TCGV_HIGH(ret
), t0
);
1294 tcg_temp_free_i32(t0
);
1295 tcg_temp_free_i32(t1
);
1299 static inline void tcg_gen_ext8s_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1301 #ifdef TCG_TARGET_HAS_ext8s_i64
1302 tcg_gen_op2_i64(INDEX_op_ext8s_i64
, ret
, arg
);
1304 tcg_gen_shli_i64(ret
, arg
, 56);
1305 tcg_gen_sari_i64(ret
, ret
, 56);
1309 static inline void tcg_gen_ext16s_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1311 #ifdef TCG_TARGET_HAS_ext16s_i64
1312 tcg_gen_op2_i64(INDEX_op_ext16s_i64
, ret
, arg
);
1314 tcg_gen_shli_i64(ret
, arg
, 48);
1315 tcg_gen_sari_i64(ret
, ret
, 48);
1319 static inline void tcg_gen_ext32s_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1321 #ifdef TCG_TARGET_HAS_ext32s_i64
1322 tcg_gen_op2_i64(INDEX_op_ext32s_i64
, ret
, arg
);
1324 tcg_gen_shli_i64(ret
, arg
, 32);
1325 tcg_gen_sari_i64(ret
, ret
, 32);
1329 static inline void tcg_gen_ext8u_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1331 tcg_gen_andi_i64(ret
, arg
, 0xffu
);
1334 static inline void tcg_gen_ext16u_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1336 tcg_gen_andi_i64(ret
, arg
, 0xffffu
);
1339 static inline void tcg_gen_ext32u_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1341 tcg_gen_andi_i64(ret
, arg
, 0xffffffffu
);
1344 /* Note: we assume the target supports move between 32 and 64 bit
1345 registers. This will probably break MIPS64 targets. */
1346 static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret
, TCGv_i64 arg
)
1348 tcg_gen_mov_i32(ret
, MAKE_TCGV_I32(GET_TCGV_I64(arg
)));
1351 /* Note: we assume the target supports move between 32 and 64 bit
1353 static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret
, TCGv_i32 arg
)
1355 tcg_gen_andi_i64(ret
, MAKE_TCGV_I64(GET_TCGV_I32(arg
)), 0xffffffffu
);
1358 /* Note: we assume the target supports move between 32 and 64 bit
1360 static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret
, TCGv_i32 arg
)
1362 tcg_gen_ext32s_i64(ret
, MAKE_TCGV_I64(GET_TCGV_I32(arg
)));
1365 static inline void tcg_gen_bswap_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1367 #ifdef TCG_TARGET_HAS_bswap_i64
1368 tcg_gen_op2_i64(INDEX_op_bswap_i64
, ret
, arg
);
1371 t0
= tcg_temp_new_i32();
1372 t1
= tcg_temp_new_i32();
1374 tcg_gen_shli_i64(t0
, arg
, 56);
1376 tcg_gen_andi_i64(t1
, arg
, 0x0000ff00);
1377 tcg_gen_shli_i64(t1
, t1
, 40);
1378 tcg_gen_or_i64(t0
, t0
, t1
);
1380 tcg_gen_andi_i64(t1
, arg
, 0x00ff0000);
1381 tcg_gen_shli_i64(t1
, t1
, 24);
1382 tcg_gen_or_i64(t0
, t0
, t1
);
1384 tcg_gen_andi_i64(t1
, arg
, 0xff000000);
1385 tcg_gen_shli_i64(t1
, t1
, 8);
1386 tcg_gen_or_i64(t0
, t0
, t1
);
1388 tcg_gen_shri_i64(t1
, arg
, 8);
1389 tcg_gen_andi_i64(t1
, t1
, 0xff000000);
1390 tcg_gen_or_i64(t0
, t0
, t1
);
1392 tcg_gen_shri_i64(t1
, arg
, 24);
1393 tcg_gen_andi_i64(t1
, t1
, 0x00ff0000);
1394 tcg_gen_or_i64(t0
, t0
, t1
);
1396 tcg_gen_shri_i64(t1
, arg
, 40);
1397 tcg_gen_andi_i64(t1
, t1
, 0x0000ff00);
1398 tcg_gen_or_i64(t0
, t0
, t1
);
1400 tcg_gen_shri_i64(t1
, arg
, 56);
1401 tcg_gen_or_i64(ret
, t0
, t1
);
1402 tcg_temp_free_i32(t0
);
1403 tcg_temp_free_i32(t1
);
1409 static inline void tcg_gen_neg_i32(TCGv_i32 ret
, TCGv_i32 arg
)
1411 #ifdef TCG_TARGET_HAS_neg_i32
1412 tcg_gen_op2_i32(INDEX_op_neg_i32
, ret
, arg
);
1414 TCGv_i32 t0
= tcg_const_i32(0);
1415 tcg_gen_sub_i32(ret
, t0
, arg
);
1416 tcg_temp_free_i32(t0
);
1420 static inline void tcg_gen_neg_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1422 #ifdef TCG_TARGET_HAS_neg_i64
1423 tcg_gen_op2_i64(INDEX_op_neg_i64
, ret
, arg
);
1425 TCGv_i64 t0
= tcg_const_i64(0);
1426 tcg_gen_sub_i64(ret
, t0
, arg
);
1427 tcg_temp_free_i64(t0
);
1431 static inline void tcg_gen_not_i32(TCGv_i32 ret
, TCGv_i32 arg
)
1433 tcg_gen_xori_i32(ret
, arg
, -1);
1436 static inline void tcg_gen_not_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1438 tcg_gen_xori_i64(ret
, arg
, -1);
1441 static inline void tcg_gen_discard_i32(TCGv_i32 arg
)
1443 tcg_gen_op1_i32(INDEX_op_discard
, arg
);
1446 #if TCG_TARGET_REG_BITS == 32
1447 static inline void tcg_gen_discard_i64(TCGv_i64 arg
)
1449 tcg_gen_discard_i32(TCGV_LOW(arg
));
1450 tcg_gen_discard_i32(TCGV_HIGH(arg
));
1453 static inline void tcg_gen_discard_i64(TCGv_i64 arg
)
1455 tcg_gen_op1_i64(INDEX_op_discard
, arg
);
1459 static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest
, TCGv_i32 low
, TCGv_i32 high
)
1461 #if TCG_TARGET_REG_BITS == 32
1462 tcg_gen_mov_i32(TCGV_LOW(dest
), low
);
1463 tcg_gen_mov_i32(TCGV_HIGH(dest
), high
);
1465 TCGv_i64 tmp
= tcg_temp_new_i64();
1466 /* This extension is only needed for type correctness.
1467 We may be able to do better given target specific information. */
1468 tcg_gen_extu_i32_i64(tmp
, high
);
1469 tcg_gen_shli_i64(tmp
, tmp
, 32);
1470 tcg_gen_extu_i32_i64(dest
, low
);
1471 tcg_gen_or_i64(dest
, dest
, tmp
);
1472 tcg_temp_free_i64(tmp
);
1476 static inline void tcg_gen_concat32_i64(TCGv_i64 dest
, TCGv_i64 low
, TCGv_i64 high
)
1478 #if TCG_TARGET_REG_BITS == 32
1479 tcg_gen_concat_i32_i64(dest
, TCGV_LOW(low
), TCGV_LOW(high
));
1481 TCGv_i64 tmp
= tcg_temp_new_i64();
1482 tcg_gen_ext32u_i64(dest
, low
);
1483 tcg_gen_shli_i64(tmp
, high
, 32);
1484 tcg_gen_or_i64(dest
, dest
, tmp
);
1485 tcg_temp_free_i64(tmp
);
1489 static inline void tcg_gen_andc_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
1492 t0
= tcg_temp_new_i32();
1493 tcg_gen_not_i32(t0
, arg2
);
1494 tcg_gen_and_i32(ret
, arg1
, t0
);
1495 tcg_temp_free_i32(t0
);
1498 static inline void tcg_gen_andc_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1501 t0
= tcg_temp_new_i64();
1502 tcg_gen_not_i64(t0
, arg2
);
1503 tcg_gen_and_i64(ret
, arg1
, t0
);
1504 tcg_temp_free_i64(t0
);
1507 static inline void tcg_gen_eqv_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
1510 t0
= tcg_temp_new_i32();
1511 tcg_gen_xor_i32(t0
, arg1
, arg2
);
1512 tcg_gen_not_i32(ret
, t0
);
1513 tcg_temp_free_i32(t0
);
1516 static inline void tcg_gen_eqv_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1519 t0
= tcg_temp_new_i64();
1520 tcg_gen_xor_i64(t0
, arg1
, arg2
);
1521 tcg_gen_not_i64(ret
, t0
);
1522 tcg_temp_free_i64(t0
);
1525 static inline void tcg_gen_nand_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
1528 t0
= tcg_temp_new_i32();
1529 tcg_gen_and_i32(t0
, arg1
, arg2
);
1530 tcg_gen_not_i32(ret
, t0
);
1531 tcg_temp_free_i32(t0
);
1534 static inline void tcg_gen_nand_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1537 t0
= tcg_temp_new_i64();
1538 tcg_gen_and_i64(t0
, arg1
, arg2
);
1539 tcg_gen_not_i64(ret
, t0
);
1540 tcg_temp_free_i64(t0
);
1543 static inline void tcg_gen_nor_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
1546 t0
= tcg_temp_new_i32();
1547 tcg_gen_or_i32(t0
, arg1
, arg2
);
1548 tcg_gen_not_i32(ret
, t0
);
1549 tcg_temp_free_i32(t0
);
1552 static inline void tcg_gen_nor_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1555 t0
= tcg_temp_new_i64();
1556 tcg_gen_or_i64(t0
, arg1
, arg2
);
1557 tcg_gen_not_i64(ret
, t0
);
1558 tcg_temp_free_i64(t0
);
1561 static inline void tcg_gen_orc_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
1564 t0
= tcg_temp_new_i32();
1565 tcg_gen_not_i32(t0
, arg2
);
1566 tcg_gen_or_i32(ret
, arg1
, t0
);
1567 tcg_temp_free_i32(t0
);
1570 static inline void tcg_gen_orc_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1573 t0
= tcg_temp_new_i64();
1574 tcg_gen_not_i64(t0
, arg2
);
1575 tcg_gen_or_i64(ret
, arg1
, t0
);
1576 tcg_temp_free_i64(t0
);
1579 static inline void tcg_gen_rotl_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
1583 t0
= tcg_temp_new_i32();
1584 t1
= tcg_temp_new_i32();
1585 tcg_gen_shl_i32(t0
, arg1
, arg2
);
1586 tcg_gen_subfi_i32(t1
, 32, arg2
);
1587 tcg_gen_shr_i32(t1
, arg1
, t1
);
1588 tcg_gen_or_i32(ret
, t0
, t1
);
1589 tcg_temp_free_i32(t0
);
1590 tcg_temp_free_i32(t1
);
1593 static inline void tcg_gen_rotl_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1597 t0
= tcg_temp_new_i64();
1598 t1
= tcg_temp_new_i64();
1599 tcg_gen_shl_i64(t0
, arg1
, arg2
);
1600 tcg_gen_subfi_i64(t1
, 64, arg2
);
1601 tcg_gen_shr_i64(t1
, arg1
, t1
);
1602 tcg_gen_or_i64(ret
, t0
, t1
);
1603 tcg_temp_free_i64(t0
);
1604 tcg_temp_free_i64(t1
);
1607 static inline void tcg_gen_rotli_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
1609 /* some cases can be optimized here */
1611 tcg_gen_mov_i32(ret
, arg1
);
1614 t0
= tcg_temp_new_i32();
1615 t1
= tcg_temp_new_i32();
1616 tcg_gen_shli_i32(t0
, arg1
, arg2
);
1617 tcg_gen_shri_i32(t1
, arg1
, 32 - arg2
);
1618 tcg_gen_or_i32(ret
, t0
, t1
);
1619 tcg_temp_free_i32(t0
);
1620 tcg_temp_free_i32(t1
);
1624 static inline void tcg_gen_rotli_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1626 /* some cases can be optimized here */
1628 tcg_gen_mov_i64(ret
, arg1
);
1631 t0
= tcg_temp_new_i64();
1632 t1
= tcg_temp_new_i64();
1633 tcg_gen_shli_i64(t0
, arg1
, arg2
);
1634 tcg_gen_shri_i64(t1
, arg1
, 64 - arg2
);
1635 tcg_gen_or_i64(ret
, t0
, t1
);
1636 tcg_temp_free_i64(t0
);
1637 tcg_temp_free_i64(t1
);
1641 static inline void tcg_gen_rotr_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
1645 t0
= tcg_temp_new_i32();
1646 t1
= tcg_temp_new_i32();
1647 tcg_gen_shr_i32(t0
, arg1
, arg2
);
1648 tcg_gen_subfi_i32(t1
, 32, arg2
);
1649 tcg_gen_shl_i32(t1
, arg1
, t1
);
1650 tcg_gen_or_i32(ret
, t0
, t1
);
1651 tcg_temp_free_i32(t0
);
1652 tcg_temp_free_i32(t1
);
1655 static inline void tcg_gen_rotr_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1659 t0
= tcg_temp_new_i64();
1660 t1
= tcg_temp_new_i64();
1661 tcg_gen_shl_i64(t0
, arg1
, arg2
);
1662 tcg_gen_subfi_i64(t1
, 64, arg2
);
1663 tcg_gen_shl_i64(t1
, arg1
, t1
);
1664 tcg_gen_or_i64(ret
, t0
, t1
);
1665 tcg_temp_free_i64(t0
);
1666 tcg_temp_free_i64(t1
);
1669 static inline void tcg_gen_rotri_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
1671 /* some cases can be optimized here */
1673 tcg_gen_mov_i32(ret
, arg1
);
1675 tcg_gen_rotli_i32(ret
, arg1
, 32 - arg2
);
1679 static inline void tcg_gen_rotri_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1681 /* some cases can be optimized here */
1683 tcg_gen_mov_i64(ret
, arg1
);
1685 tcg_gen_rotli_i64(ret
, arg1
, 64 - arg2
);
1689 /***************************************/
1690 /* QEMU specific operations. Their type depend on the QEMU CPU
1692 #ifndef TARGET_LONG_BITS
1693 #error must include QEMU headers
1696 #if TARGET_LONG_BITS == 32
1697 #define TCGv TCGv_i32
1698 #define tcg_temp_new() tcg_temp_new_i32()
1699 #define tcg_global_reg_new tcg_global_reg_new_i32
1700 #define tcg_global_mem_new tcg_global_mem_new_i32
1701 #define tcg_temp_local_new(t) tcg_temp_local_new_i32()
1702 #define tcg_temp_free tcg_temp_free_i32
1703 #define tcg_gen_qemu_ldst_op tcg_gen_op3i_i32
1704 #define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i32
1705 #define TCGV_UNUSED(x) TCGV_UNUSED_I32(x)
1706 #define TCGV_EQUAL(a, b) (GET_TCGV_I32(a) == GET_TCGV_I32(b))
1708 #define TCGv TCGv_i64
1709 #define tcg_temp_new() tcg_temp_new_i64()
1710 #define tcg_global_reg_new tcg_global_reg_new_i64
1711 #define tcg_global_mem_new tcg_global_mem_new_i64
1712 #define tcg_temp_local_new(t) tcg_temp_local_new_i64()
1713 #define tcg_temp_free tcg_temp_free_i64
1714 #define tcg_gen_qemu_ldst_op tcg_gen_op3i_i64
1715 #define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i64
1716 #define TCGV_UNUSED(x) TCGV_UNUSED_I64(x)
1717 #define TCGV_EQUAL(a, b) (GET_TCGV_I64(a) == GET_TCGV_I64(b))
1720 /* debug info: write the PC of the corresponding QEMU CPU instruction */
1721 static inline void tcg_gen_debug_insn_start(uint64_t pc
)
1723 /* XXX: must really use a 32 bit size for TCGArg in all cases */
1724 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
1725 tcg_gen_op2ii(INDEX_op_debug_insn_start
,
1726 (uint32_t)(pc
), (uint32_t)(pc
>> 32));
1728 tcg_gen_op1i(INDEX_op_debug_insn_start
, pc
);
1732 static inline void tcg_gen_exit_tb(tcg_target_long val
)
1734 tcg_gen_op1i(INDEX_op_exit_tb
, val
);
1737 static inline void tcg_gen_goto_tb(int idx
)
1739 tcg_gen_op1i(INDEX_op_goto_tb
, idx
);
1742 #if TCG_TARGET_REG_BITS == 32
1743 static inline void tcg_gen_qemu_ld8u(TCGv ret
, TCGv addr
, int mem_index
)
1745 #if TARGET_LONG_BITS == 32
1746 tcg_gen_op3i_i32(INDEX_op_qemu_ld8u
, ret
, addr
, mem_index
);
1748 tcg_gen_op4i_i32(INDEX_op_qemu_ld8u
, TCGV_LOW(ret
), TCGV_LOW(addr
),
1749 TCGV_HIGH(addr
), mem_index
);
1750 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1754 static inline void tcg_gen_qemu_ld8s(TCGv ret
, TCGv addr
, int mem_index
)
1756 #if TARGET_LONG_BITS == 32
1757 tcg_gen_op3i_i32(INDEX_op_qemu_ld8s
, ret
, addr
, mem_index
);
1759 tcg_gen_op4i_i32(INDEX_op_qemu_ld8s
, TCGV_LOW(ret
), TCGV_LOW(addr
),
1760 TCGV_HIGH(addr
), mem_index
);
1761 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
1765 static inline void tcg_gen_qemu_ld16u(TCGv ret
, TCGv addr
, int mem_index
)
1767 #if TARGET_LONG_BITS == 32
1768 tcg_gen_op3i_i32(INDEX_op_qemu_ld16u
, ret
, addr
, mem_index
);
1770 tcg_gen_op4i_i32(INDEX_op_qemu_ld16u
, TCGV_LOW(ret
), TCGV_LOW(addr
),
1771 TCGV_HIGH(addr
), mem_index
);
1772 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1776 static inline void tcg_gen_qemu_ld16s(TCGv ret
, TCGv addr
, int mem_index
)
1778 #if TARGET_LONG_BITS == 32
1779 tcg_gen_op3i_i32(INDEX_op_qemu_ld16s
, ret
, addr
, mem_index
);
1781 tcg_gen_op4i_i32(INDEX_op_qemu_ld16s
, TCGV_LOW(ret
), TCGV_LOW(addr
),
1782 TCGV_HIGH(addr
), mem_index
);
1783 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
1787 static inline void tcg_gen_qemu_ld32u(TCGv ret
, TCGv addr
, int mem_index
)
1789 #if TARGET_LONG_BITS == 32
1790 tcg_gen_op3i_i32(INDEX_op_qemu_ld32u
, ret
, addr
, mem_index
);
1792 tcg_gen_op4i_i32(INDEX_op_qemu_ld32u
, TCGV_LOW(ret
), TCGV_LOW(addr
),
1793 TCGV_HIGH(addr
), mem_index
);
1794 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1798 static inline void tcg_gen_qemu_ld32s(TCGv ret
, TCGv addr
, int mem_index
)
1800 #if TARGET_LONG_BITS == 32
1801 tcg_gen_op3i_i32(INDEX_op_qemu_ld32u
, ret
, addr
, mem_index
);
1803 tcg_gen_op4i_i32(INDEX_op_qemu_ld32u
, TCGV_LOW(ret
), TCGV_LOW(addr
),
1804 TCGV_HIGH(addr
), mem_index
);
1805 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
1809 static inline void tcg_gen_qemu_ld64(TCGv_i64 ret
, TCGv addr
, int mem_index
)
1811 #if TARGET_LONG_BITS == 32
1812 tcg_gen_op4i_i32(INDEX_op_qemu_ld64
, TCGV_LOW(ret
), TCGV_HIGH(ret
), addr
, mem_index
);
1814 tcg_gen_op5i_i32(INDEX_op_qemu_ld64
, TCGV_LOW(ret
), TCGV_HIGH(ret
),
1815 TCGV_LOW(addr
), TCGV_HIGH(addr
), mem_index
);
1819 static inline void tcg_gen_qemu_st8(TCGv arg
, TCGv addr
, int mem_index
)
1821 #if TARGET_LONG_BITS == 32
1822 tcg_gen_op3i_i32(INDEX_op_qemu_st8
, arg
, addr
, mem_index
);
1824 tcg_gen_op4i_i32(INDEX_op_qemu_st8
, TCGV_LOW(arg
), TCGV_LOW(addr
),
1825 TCGV_HIGH(addr
), mem_index
);
1829 static inline void tcg_gen_qemu_st16(TCGv arg
, TCGv addr
, int mem_index
)
1831 #if TARGET_LONG_BITS == 32
1832 tcg_gen_op3i_i32(INDEX_op_qemu_st16
, arg
, addr
, mem_index
);
1834 tcg_gen_op4i_i32(INDEX_op_qemu_st16
, TCGV_LOW(arg
), TCGV_LOW(addr
),
1835 TCGV_HIGH(addr
), mem_index
);
1839 static inline void tcg_gen_qemu_st32(TCGv arg
, TCGv addr
, int mem_index
)
1841 #if TARGET_LONG_BITS == 32
1842 tcg_gen_op3i_i32(INDEX_op_qemu_st32
, arg
, addr
, mem_index
);
1844 tcg_gen_op4i_i32(INDEX_op_qemu_st32
, TCGV_LOW(arg
), TCGV_LOW(addr
),
1845 TCGV_HIGH(addr
), mem_index
);
1849 static inline void tcg_gen_qemu_st64(TCGv_i64 arg
, TCGv addr
, int mem_index
)
1851 #if TARGET_LONG_BITS == 32
1852 tcg_gen_op4i_i32(INDEX_op_qemu_st64
, TCGV_LOW(arg
), TCGV_HIGH(arg
), addr
,
1855 tcg_gen_op5i_i32(INDEX_op_qemu_st64
, TCGV_LOW(arg
), TCGV_HIGH(arg
),
1856 TCGV_LOW(addr
), TCGV_HIGH(addr
), mem_index
);
1860 #define tcg_gen_ld_ptr tcg_gen_ld_i32
1861 #define tcg_gen_discard_ptr tcg_gen_discard_i32
1863 #else /* TCG_TARGET_REG_BITS == 32 */
1865 static inline void tcg_gen_qemu_ld8u(TCGv ret
, TCGv addr
, int mem_index
)
1867 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u
, ret
, addr
, mem_index
);
1870 static inline void tcg_gen_qemu_ld8s(TCGv ret
, TCGv addr
, int mem_index
)
1872 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s
, ret
, addr
, mem_index
);
1875 static inline void tcg_gen_qemu_ld16u(TCGv ret
, TCGv addr
, int mem_index
)
1877 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u
, ret
, addr
, mem_index
);
1880 static inline void tcg_gen_qemu_ld16s(TCGv ret
, TCGv addr
, int mem_index
)
1882 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s
, ret
, addr
, mem_index
);
1885 static inline void tcg_gen_qemu_ld32u(TCGv ret
, TCGv addr
, int mem_index
)
1887 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u
, ret
, addr
, mem_index
);
1890 static inline void tcg_gen_qemu_ld32s(TCGv ret
, TCGv addr
, int mem_index
)
1892 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s
, ret
, addr
, mem_index
);
1895 static inline void tcg_gen_qemu_ld64(TCGv_i64 ret
, TCGv addr
, int mem_index
)
1897 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64
, ret
, addr
, mem_index
);
1900 static inline void tcg_gen_qemu_st8(TCGv arg
, TCGv addr
, int mem_index
)
1902 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8
, arg
, addr
, mem_index
);
1905 static inline void tcg_gen_qemu_st16(TCGv arg
, TCGv addr
, int mem_index
)
1907 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16
, arg
, addr
, mem_index
);
1910 static inline void tcg_gen_qemu_st32(TCGv arg
, TCGv addr
, int mem_index
)
1912 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32
, arg
, addr
, mem_index
);
1915 static inline void tcg_gen_qemu_st64(TCGv_i64 arg
, TCGv addr
, int mem_index
)
1917 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64
, arg
, addr
, mem_index
);
1920 #define tcg_gen_ld_ptr tcg_gen_ld_i64
1921 #define tcg_gen_discard_ptr tcg_gen_discard_i64
1923 #endif /* TCG_TARGET_REG_BITS != 32 */
1925 #if TARGET_LONG_BITS == 64
1926 #define TCG_TYPE_TL TCG_TYPE_I64
1927 #define tcg_gen_movi_tl tcg_gen_movi_i64
1928 #define tcg_gen_mov_tl tcg_gen_mov_i64
1929 #define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
1930 #define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
1931 #define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
1932 #define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
1933 #define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
1934 #define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
1935 #define tcg_gen_ld_tl tcg_gen_ld_i64
1936 #define tcg_gen_st8_tl tcg_gen_st8_i64
1937 #define tcg_gen_st16_tl tcg_gen_st16_i64
1938 #define tcg_gen_st32_tl tcg_gen_st32_i64
1939 #define tcg_gen_st_tl tcg_gen_st_i64
1940 #define tcg_gen_add_tl tcg_gen_add_i64
1941 #define tcg_gen_addi_tl tcg_gen_addi_i64
1942 #define tcg_gen_sub_tl tcg_gen_sub_i64
1943 #define tcg_gen_neg_tl tcg_gen_neg_i64
1944 #define tcg_gen_subfi_tl tcg_gen_subfi_i64
1945 #define tcg_gen_subi_tl tcg_gen_subi_i64
1946 #define tcg_gen_and_tl tcg_gen_and_i64
1947 #define tcg_gen_andi_tl tcg_gen_andi_i64
1948 #define tcg_gen_or_tl tcg_gen_or_i64
1949 #define tcg_gen_ori_tl tcg_gen_ori_i64
1950 #define tcg_gen_xor_tl tcg_gen_xor_i64
1951 #define tcg_gen_xori_tl tcg_gen_xori_i64
1952 #define tcg_gen_not_tl tcg_gen_not_i64
1953 #define tcg_gen_shl_tl tcg_gen_shl_i64
1954 #define tcg_gen_shli_tl tcg_gen_shli_i64
1955 #define tcg_gen_shr_tl tcg_gen_shr_i64
1956 #define tcg_gen_shri_tl tcg_gen_shri_i64
1957 #define tcg_gen_sar_tl tcg_gen_sar_i64
1958 #define tcg_gen_sari_tl tcg_gen_sari_i64
1959 #define tcg_gen_brcond_tl tcg_gen_brcond_i64
1960 #define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
1961 #define tcg_gen_mul_tl tcg_gen_mul_i64
1962 #define tcg_gen_muli_tl tcg_gen_muli_i64
1963 #define tcg_gen_discard_tl tcg_gen_discard_i64
1964 #define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
1965 #define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
1966 #define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
1967 #define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
1968 #define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
1969 #define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
1970 #define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
1971 #define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
1972 #define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
1973 #define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
1974 #define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
1975 #define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
1976 #define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
1977 #define tcg_gen_andc_tl tcg_gen_andc_i64
1978 #define tcg_gen_eqv_tl tcg_gen_eqv_i64
1979 #define tcg_gen_nand_tl tcg_gen_nand_i64
1980 #define tcg_gen_nor_tl tcg_gen_nor_i64
1981 #define tcg_gen_orc_tl tcg_gen_orc_i64
1982 #define tcg_gen_rotl_tl tcg_gen_rotl_i64
1983 #define tcg_gen_rotli_tl tcg_gen_rotli_i64
1984 #define tcg_gen_rotr_tl tcg_gen_rotr_i64
1985 #define tcg_gen_rotri_tl tcg_gen_rotri_i64
1986 #define tcg_const_tl tcg_const_i64
1987 #define tcg_const_local_tl tcg_const_local_i64
1989 #define TCG_TYPE_TL TCG_TYPE_I32
1990 #define tcg_gen_movi_tl tcg_gen_movi_i32
1991 #define tcg_gen_mov_tl tcg_gen_mov_i32
1992 #define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
1993 #define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
1994 #define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
1995 #define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
1996 #define tcg_gen_ld32u_tl tcg_gen_ld_i32
1997 #define tcg_gen_ld32s_tl tcg_gen_ld_i32
1998 #define tcg_gen_ld_tl tcg_gen_ld_i32
1999 #define tcg_gen_st8_tl tcg_gen_st8_i32
2000 #define tcg_gen_st16_tl tcg_gen_st16_i32
2001 #define tcg_gen_st32_tl tcg_gen_st_i32
2002 #define tcg_gen_st_tl tcg_gen_st_i32
2003 #define tcg_gen_add_tl tcg_gen_add_i32
2004 #define tcg_gen_addi_tl tcg_gen_addi_i32
2005 #define tcg_gen_sub_tl tcg_gen_sub_i32
2006 #define tcg_gen_neg_tl tcg_gen_neg_i32
2007 #define tcg_gen_subfi_tl tcg_gen_subfi_i32
2008 #define tcg_gen_subi_tl tcg_gen_subi_i32
2009 #define tcg_gen_and_tl tcg_gen_and_i32
2010 #define tcg_gen_andi_tl tcg_gen_andi_i32
2011 #define tcg_gen_or_tl tcg_gen_or_i32
2012 #define tcg_gen_ori_tl tcg_gen_ori_i32
2013 #define tcg_gen_xor_tl tcg_gen_xor_i32
2014 #define tcg_gen_xori_tl tcg_gen_xori_i32
2015 #define tcg_gen_not_tl tcg_gen_not_i32
2016 #define tcg_gen_shl_tl tcg_gen_shl_i32
2017 #define tcg_gen_shli_tl tcg_gen_shli_i32
2018 #define tcg_gen_shr_tl tcg_gen_shr_i32
2019 #define tcg_gen_shri_tl tcg_gen_shri_i32
2020 #define tcg_gen_sar_tl tcg_gen_sar_i32
2021 #define tcg_gen_sari_tl tcg_gen_sari_i32
2022 #define tcg_gen_brcond_tl tcg_gen_brcond_i32
2023 #define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
2024 #define tcg_gen_mul_tl tcg_gen_mul_i32
2025 #define tcg_gen_muli_tl tcg_gen_muli_i32
2026 #define tcg_gen_discard_tl tcg_gen_discard_i32
2027 #define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
2028 #define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
2029 #define tcg_gen_extu_i32_tl tcg_gen_mov_i32
2030 #define tcg_gen_ext_i32_tl tcg_gen_mov_i32
2031 #define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
2032 #define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
2033 #define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
2034 #define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
2035 #define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
2036 #define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
2037 #define tcg_gen_ext32u_tl tcg_gen_mov_i32
2038 #define tcg_gen_ext32s_tl tcg_gen_mov_i32
2039 #define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
2040 #define tcg_gen_andc_tl tcg_gen_andc_i32
2041 #define tcg_gen_eqv_tl tcg_gen_eqv_i32
2042 #define tcg_gen_nand_tl tcg_gen_nand_i32
2043 #define tcg_gen_nor_tl tcg_gen_nor_i32
2044 #define tcg_gen_orc_tl tcg_gen_orc_i32
2045 #define tcg_gen_rotl_tl tcg_gen_rotl_i32
2046 #define tcg_gen_rotli_tl tcg_gen_rotli_i32
2047 #define tcg_gen_rotr_tl tcg_gen_rotr_i32
2048 #define tcg_gen_rotri_tl tcg_gen_rotri_i32
2049 #define tcg_const_tl tcg_const_i32
2050 #define tcg_const_local_tl tcg_const_local_i32
2053 #if TCG_TARGET_REG_BITS == 32
2054 #define tcg_gen_add_ptr tcg_gen_add_i32
2055 #define tcg_gen_addi_ptr tcg_gen_addi_i32
2056 #define tcg_gen_ext_i32_ptr tcg_gen_mov_i32
2057 #else /* TCG_TARGET_REG_BITS == 32 */
2058 #define tcg_gen_add_ptr tcg_gen_add_i64
2059 #define tcg_gen_addi_ptr tcg_gen_addi_i64
2060 #define tcg_gen_ext_i32_ptr tcg_gen_ext_i32_i64
2061 #endif /* TCG_TARGET_REG_BITS != 32 */