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
25 #include "qemu/osdep.h"
26 #include "qemu-common.h"
28 #include "exec/exec-all.h"
32 #include "trace-tcg.h"
33 #include "trace/mem.h"
35 /* Reduce the number of ifdefs below. This assumes that all uses of
36 TCGV_HIGH and TCGV_LOW are properly protected by a conditional that
37 the compiler can eliminate. */
38 #if TCG_TARGET_REG_BITS == 64
39 extern TCGv_i32
TCGV_LOW_link_error(TCGv_i64
);
40 extern TCGv_i32
TCGV_HIGH_link_error(TCGv_i64
);
41 #define TCGV_LOW TCGV_LOW_link_error
42 #define TCGV_HIGH TCGV_HIGH_link_error
45 void tcg_gen_op1(TCGOpcode opc
, TCGArg a1
)
47 TCGOp
*op
= tcg_emit_op(opc
);
51 void tcg_gen_op2(TCGOpcode opc
, TCGArg a1
, TCGArg a2
)
53 TCGOp
*op
= tcg_emit_op(opc
);
58 void tcg_gen_op3(TCGOpcode opc
, TCGArg a1
, TCGArg a2
, TCGArg a3
)
60 TCGOp
*op
= tcg_emit_op(opc
);
66 void tcg_gen_op4(TCGOpcode opc
, TCGArg a1
, TCGArg a2
, TCGArg a3
, TCGArg a4
)
68 TCGOp
*op
= tcg_emit_op(opc
);
75 void tcg_gen_op5(TCGOpcode opc
, TCGArg a1
, TCGArg a2
, TCGArg a3
,
78 TCGOp
*op
= tcg_emit_op(opc
);
86 void tcg_gen_op6(TCGOpcode opc
, TCGArg a1
, TCGArg a2
, TCGArg a3
,
87 TCGArg a4
, TCGArg a5
, TCGArg a6
)
89 TCGOp
*op
= tcg_emit_op(opc
);
98 void tcg_gen_mb(TCGBar mb_type
)
100 if (tcg_ctx
->tb_cflags
& CF_PARALLEL
) {
101 tcg_gen_op1(INDEX_op_mb
, mb_type
);
107 void tcg_gen_addi_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
109 /* some cases can be optimized here */
111 tcg_gen_mov_i32(ret
, arg1
);
113 TCGv_i32 t0
= tcg_const_i32(arg2
);
114 tcg_gen_add_i32(ret
, arg1
, t0
);
115 tcg_temp_free_i32(t0
);
119 void tcg_gen_subfi_i32(TCGv_i32 ret
, int32_t arg1
, TCGv_i32 arg2
)
121 if (arg1
== 0 && TCG_TARGET_HAS_neg_i32
) {
122 /* Don't recurse with tcg_gen_neg_i32. */
123 tcg_gen_op2_i32(INDEX_op_neg_i32
, ret
, arg2
);
125 TCGv_i32 t0
= tcg_const_i32(arg1
);
126 tcg_gen_sub_i32(ret
, t0
, arg2
);
127 tcg_temp_free_i32(t0
);
131 void tcg_gen_subi_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
133 /* some cases can be optimized here */
135 tcg_gen_mov_i32(ret
, arg1
);
137 TCGv_i32 t0
= tcg_const_i32(arg2
);
138 tcg_gen_sub_i32(ret
, arg1
, t0
);
139 tcg_temp_free_i32(t0
);
143 void tcg_gen_andi_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
146 /* Some cases can be optimized here. */
149 tcg_gen_movi_i32(ret
, 0);
152 tcg_gen_mov_i32(ret
, arg1
);
155 /* Don't recurse with tcg_gen_ext8u_i32. */
156 if (TCG_TARGET_HAS_ext8u_i32
) {
157 tcg_gen_op2_i32(INDEX_op_ext8u_i32
, ret
, arg1
);
162 if (TCG_TARGET_HAS_ext16u_i32
) {
163 tcg_gen_op2_i32(INDEX_op_ext16u_i32
, ret
, arg1
);
168 t0
= tcg_const_i32(arg2
);
169 tcg_gen_and_i32(ret
, arg1
, t0
);
170 tcg_temp_free_i32(t0
);
173 void tcg_gen_ori_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
175 /* Some cases can be optimized here. */
177 tcg_gen_movi_i32(ret
, -1);
178 } else if (arg2
== 0) {
179 tcg_gen_mov_i32(ret
, arg1
);
181 TCGv_i32 t0
= tcg_const_i32(arg2
);
182 tcg_gen_or_i32(ret
, arg1
, t0
);
183 tcg_temp_free_i32(t0
);
187 void tcg_gen_xori_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
189 /* Some cases can be optimized here. */
191 tcg_gen_mov_i32(ret
, arg1
);
192 } else if (arg2
== -1 && TCG_TARGET_HAS_not_i32
) {
193 /* Don't recurse with tcg_gen_not_i32. */
194 tcg_gen_op2_i32(INDEX_op_not_i32
, ret
, arg1
);
196 TCGv_i32 t0
= tcg_const_i32(arg2
);
197 tcg_gen_xor_i32(ret
, arg1
, t0
);
198 tcg_temp_free_i32(t0
);
202 void tcg_gen_shli_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
204 tcg_debug_assert(arg2
>= 0 && arg2
< 32);
206 tcg_gen_mov_i32(ret
, arg1
);
208 TCGv_i32 t0
= tcg_const_i32(arg2
);
209 tcg_gen_shl_i32(ret
, arg1
, t0
);
210 tcg_temp_free_i32(t0
);
214 void tcg_gen_shri_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
216 tcg_debug_assert(arg2
>= 0 && arg2
< 32);
218 tcg_gen_mov_i32(ret
, arg1
);
220 TCGv_i32 t0
= tcg_const_i32(arg2
);
221 tcg_gen_shr_i32(ret
, arg1
, t0
);
222 tcg_temp_free_i32(t0
);
226 void tcg_gen_sari_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
228 tcg_debug_assert(arg2
>= 0 && arg2
< 32);
230 tcg_gen_mov_i32(ret
, arg1
);
232 TCGv_i32 t0
= tcg_const_i32(arg2
);
233 tcg_gen_sar_i32(ret
, arg1
, t0
);
234 tcg_temp_free_i32(t0
);
238 void tcg_gen_brcond_i32(TCGCond cond
, TCGv_i32 arg1
, TCGv_i32 arg2
, TCGLabel
*l
)
240 if (cond
== TCG_COND_ALWAYS
) {
242 } else if (cond
!= TCG_COND_NEVER
) {
244 tcg_gen_op4ii_i32(INDEX_op_brcond_i32
, arg1
, arg2
, cond
, label_arg(l
));
248 void tcg_gen_brcondi_i32(TCGCond cond
, TCGv_i32 arg1
, int32_t arg2
, TCGLabel
*l
)
250 if (cond
== TCG_COND_ALWAYS
) {
252 } else if (cond
!= TCG_COND_NEVER
) {
253 TCGv_i32 t0
= tcg_const_i32(arg2
);
254 tcg_gen_brcond_i32(cond
, arg1
, t0
, l
);
255 tcg_temp_free_i32(t0
);
259 void tcg_gen_setcond_i32(TCGCond cond
, TCGv_i32 ret
,
260 TCGv_i32 arg1
, TCGv_i32 arg2
)
262 if (cond
== TCG_COND_ALWAYS
) {
263 tcg_gen_movi_i32(ret
, 1);
264 } else if (cond
== TCG_COND_NEVER
) {
265 tcg_gen_movi_i32(ret
, 0);
267 tcg_gen_op4i_i32(INDEX_op_setcond_i32
, ret
, arg1
, arg2
, cond
);
271 void tcg_gen_setcondi_i32(TCGCond cond
, TCGv_i32 ret
,
272 TCGv_i32 arg1
, int32_t arg2
)
274 TCGv_i32 t0
= tcg_const_i32(arg2
);
275 tcg_gen_setcond_i32(cond
, ret
, arg1
, t0
);
276 tcg_temp_free_i32(t0
);
279 void tcg_gen_muli_i32(TCGv_i32 ret
, TCGv_i32 arg1
, int32_t arg2
)
282 tcg_gen_movi_i32(ret
, 0);
283 } else if (is_power_of_2(arg2
)) {
284 tcg_gen_shli_i32(ret
, arg1
, ctz32(arg2
));
286 TCGv_i32 t0
= tcg_const_i32(arg2
);
287 tcg_gen_mul_i32(ret
, arg1
, t0
);
288 tcg_temp_free_i32(t0
);
292 void tcg_gen_div_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
294 if (TCG_TARGET_HAS_div_i32
) {
295 tcg_gen_op3_i32(INDEX_op_div_i32
, ret
, arg1
, arg2
);
296 } else if (TCG_TARGET_HAS_div2_i32
) {
297 TCGv_i32 t0
= tcg_temp_new_i32();
298 tcg_gen_sari_i32(t0
, arg1
, 31);
299 tcg_gen_op5_i32(INDEX_op_div2_i32
, ret
, t0
, arg1
, t0
, arg2
);
300 tcg_temp_free_i32(t0
);
302 gen_helper_div_i32(ret
, arg1
, arg2
);
306 void tcg_gen_rem_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
308 if (TCG_TARGET_HAS_rem_i32
) {
309 tcg_gen_op3_i32(INDEX_op_rem_i32
, ret
, arg1
, arg2
);
310 } else if (TCG_TARGET_HAS_div_i32
) {
311 TCGv_i32 t0
= tcg_temp_new_i32();
312 tcg_gen_op3_i32(INDEX_op_div_i32
, t0
, arg1
, arg2
);
313 tcg_gen_mul_i32(t0
, t0
, arg2
);
314 tcg_gen_sub_i32(ret
, arg1
, t0
);
315 tcg_temp_free_i32(t0
);
316 } else if (TCG_TARGET_HAS_div2_i32
) {
317 TCGv_i32 t0
= tcg_temp_new_i32();
318 tcg_gen_sari_i32(t0
, arg1
, 31);
319 tcg_gen_op5_i32(INDEX_op_div2_i32
, t0
, ret
, arg1
, t0
, arg2
);
320 tcg_temp_free_i32(t0
);
322 gen_helper_rem_i32(ret
, arg1
, arg2
);
326 void tcg_gen_divu_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
328 if (TCG_TARGET_HAS_div_i32
) {
329 tcg_gen_op3_i32(INDEX_op_divu_i32
, ret
, arg1
, arg2
);
330 } else if (TCG_TARGET_HAS_div2_i32
) {
331 TCGv_i32 t0
= tcg_temp_new_i32();
332 tcg_gen_movi_i32(t0
, 0);
333 tcg_gen_op5_i32(INDEX_op_divu2_i32
, ret
, t0
, arg1
, t0
, arg2
);
334 tcg_temp_free_i32(t0
);
336 gen_helper_divu_i32(ret
, arg1
, arg2
);
340 void tcg_gen_remu_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
342 if (TCG_TARGET_HAS_rem_i32
) {
343 tcg_gen_op3_i32(INDEX_op_remu_i32
, ret
, arg1
, arg2
);
344 } else if (TCG_TARGET_HAS_div_i32
) {
345 TCGv_i32 t0
= tcg_temp_new_i32();
346 tcg_gen_op3_i32(INDEX_op_divu_i32
, t0
, arg1
, arg2
);
347 tcg_gen_mul_i32(t0
, t0
, arg2
);
348 tcg_gen_sub_i32(ret
, arg1
, t0
);
349 tcg_temp_free_i32(t0
);
350 } else if (TCG_TARGET_HAS_div2_i32
) {
351 TCGv_i32 t0
= tcg_temp_new_i32();
352 tcg_gen_movi_i32(t0
, 0);
353 tcg_gen_op5_i32(INDEX_op_divu2_i32
, t0
, ret
, arg1
, t0
, arg2
);
354 tcg_temp_free_i32(t0
);
356 gen_helper_remu_i32(ret
, arg1
, arg2
);
360 void tcg_gen_andc_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
362 if (TCG_TARGET_HAS_andc_i32
) {
363 tcg_gen_op3_i32(INDEX_op_andc_i32
, ret
, arg1
, arg2
);
365 TCGv_i32 t0
= tcg_temp_new_i32();
366 tcg_gen_not_i32(t0
, arg2
);
367 tcg_gen_and_i32(ret
, arg1
, t0
);
368 tcg_temp_free_i32(t0
);
372 void tcg_gen_eqv_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
374 if (TCG_TARGET_HAS_eqv_i32
) {
375 tcg_gen_op3_i32(INDEX_op_eqv_i32
, ret
, arg1
, arg2
);
377 tcg_gen_xor_i32(ret
, arg1
, arg2
);
378 tcg_gen_not_i32(ret
, ret
);
382 void tcg_gen_nand_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
384 if (TCG_TARGET_HAS_nand_i32
) {
385 tcg_gen_op3_i32(INDEX_op_nand_i32
, ret
, arg1
, arg2
);
387 tcg_gen_and_i32(ret
, arg1
, arg2
);
388 tcg_gen_not_i32(ret
, ret
);
392 void tcg_gen_nor_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
394 if (TCG_TARGET_HAS_nor_i32
) {
395 tcg_gen_op3_i32(INDEX_op_nor_i32
, ret
, arg1
, arg2
);
397 tcg_gen_or_i32(ret
, arg1
, arg2
);
398 tcg_gen_not_i32(ret
, ret
);
402 void tcg_gen_orc_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
404 if (TCG_TARGET_HAS_orc_i32
) {
405 tcg_gen_op3_i32(INDEX_op_orc_i32
, ret
, arg1
, arg2
);
407 TCGv_i32 t0
= tcg_temp_new_i32();
408 tcg_gen_not_i32(t0
, arg2
);
409 tcg_gen_or_i32(ret
, arg1
, t0
);
410 tcg_temp_free_i32(t0
);
414 void tcg_gen_clz_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
416 if (TCG_TARGET_HAS_clz_i32
) {
417 tcg_gen_op3_i32(INDEX_op_clz_i32
, ret
, arg1
, arg2
);
418 } else if (TCG_TARGET_HAS_clz_i64
) {
419 TCGv_i64 t1
= tcg_temp_new_i64();
420 TCGv_i64 t2
= tcg_temp_new_i64();
421 tcg_gen_extu_i32_i64(t1
, arg1
);
422 tcg_gen_extu_i32_i64(t2
, arg2
);
423 tcg_gen_addi_i64(t2
, t2
, 32);
424 tcg_gen_clz_i64(t1
, t1
, t2
);
425 tcg_gen_extrl_i64_i32(ret
, t1
);
426 tcg_temp_free_i64(t1
);
427 tcg_temp_free_i64(t2
);
428 tcg_gen_subi_i32(ret
, ret
, 32);
430 gen_helper_clz_i32(ret
, arg1
, arg2
);
434 void tcg_gen_clzi_i32(TCGv_i32 ret
, TCGv_i32 arg1
, uint32_t arg2
)
436 TCGv_i32 t
= tcg_const_i32(arg2
);
437 tcg_gen_clz_i32(ret
, arg1
, t
);
438 tcg_temp_free_i32(t
);
441 void tcg_gen_ctz_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
443 if (TCG_TARGET_HAS_ctz_i32
) {
444 tcg_gen_op3_i32(INDEX_op_ctz_i32
, ret
, arg1
, arg2
);
445 } else if (TCG_TARGET_HAS_ctz_i64
) {
446 TCGv_i64 t1
= tcg_temp_new_i64();
447 TCGv_i64 t2
= tcg_temp_new_i64();
448 tcg_gen_extu_i32_i64(t1
, arg1
);
449 tcg_gen_extu_i32_i64(t2
, arg2
);
450 tcg_gen_ctz_i64(t1
, t1
, t2
);
451 tcg_gen_extrl_i64_i32(ret
, t1
);
452 tcg_temp_free_i64(t1
);
453 tcg_temp_free_i64(t2
);
454 } else if (TCG_TARGET_HAS_ctpop_i32
455 || TCG_TARGET_HAS_ctpop_i64
456 || TCG_TARGET_HAS_clz_i32
457 || TCG_TARGET_HAS_clz_i64
) {
458 TCGv_i32 z
, t
= tcg_temp_new_i32();
460 if (TCG_TARGET_HAS_ctpop_i32
|| TCG_TARGET_HAS_ctpop_i64
) {
461 tcg_gen_subi_i32(t
, arg1
, 1);
462 tcg_gen_andc_i32(t
, t
, arg1
);
463 tcg_gen_ctpop_i32(t
, t
);
465 /* Since all non-x86 hosts have clz(0) == 32, don't fight it. */
466 tcg_gen_neg_i32(t
, arg1
);
467 tcg_gen_and_i32(t
, t
, arg1
);
468 tcg_gen_clzi_i32(t
, t
, 32);
469 tcg_gen_xori_i32(t
, t
, 31);
471 z
= tcg_const_i32(0);
472 tcg_gen_movcond_i32(TCG_COND_EQ
, ret
, arg1
, z
, arg2
, t
);
473 tcg_temp_free_i32(t
);
474 tcg_temp_free_i32(z
);
476 gen_helper_ctz_i32(ret
, arg1
, arg2
);
480 void tcg_gen_ctzi_i32(TCGv_i32 ret
, TCGv_i32 arg1
, uint32_t arg2
)
482 if (!TCG_TARGET_HAS_ctz_i32
&& TCG_TARGET_HAS_ctpop_i32
&& arg2
== 32) {
483 /* This equivalence has the advantage of not requiring a fixup. */
484 TCGv_i32 t
= tcg_temp_new_i32();
485 tcg_gen_subi_i32(t
, arg1
, 1);
486 tcg_gen_andc_i32(t
, t
, arg1
);
487 tcg_gen_ctpop_i32(ret
, t
);
488 tcg_temp_free_i32(t
);
490 TCGv_i32 t
= tcg_const_i32(arg2
);
491 tcg_gen_ctz_i32(ret
, arg1
, t
);
492 tcg_temp_free_i32(t
);
496 void tcg_gen_clrsb_i32(TCGv_i32 ret
, TCGv_i32 arg
)
498 if (TCG_TARGET_HAS_clz_i32
) {
499 TCGv_i32 t
= tcg_temp_new_i32();
500 tcg_gen_sari_i32(t
, arg
, 31);
501 tcg_gen_xor_i32(t
, t
, arg
);
502 tcg_gen_clzi_i32(t
, t
, 32);
503 tcg_gen_subi_i32(ret
, t
, 1);
504 tcg_temp_free_i32(t
);
506 gen_helper_clrsb_i32(ret
, arg
);
510 void tcg_gen_ctpop_i32(TCGv_i32 ret
, TCGv_i32 arg1
)
512 if (TCG_TARGET_HAS_ctpop_i32
) {
513 tcg_gen_op2_i32(INDEX_op_ctpop_i32
, ret
, arg1
);
514 } else if (TCG_TARGET_HAS_ctpop_i64
) {
515 TCGv_i64 t
= tcg_temp_new_i64();
516 tcg_gen_extu_i32_i64(t
, arg1
);
517 tcg_gen_ctpop_i64(t
, t
);
518 tcg_gen_extrl_i64_i32(ret
, t
);
519 tcg_temp_free_i64(t
);
521 gen_helper_ctpop_i32(ret
, arg1
);
525 void tcg_gen_rotl_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
527 if (TCG_TARGET_HAS_rot_i32
) {
528 tcg_gen_op3_i32(INDEX_op_rotl_i32
, ret
, arg1
, arg2
);
532 t0
= tcg_temp_new_i32();
533 t1
= tcg_temp_new_i32();
534 tcg_gen_shl_i32(t0
, arg1
, arg2
);
535 tcg_gen_subfi_i32(t1
, 32, arg2
);
536 tcg_gen_shr_i32(t1
, arg1
, t1
);
537 tcg_gen_or_i32(ret
, t0
, t1
);
538 tcg_temp_free_i32(t0
);
539 tcg_temp_free_i32(t1
);
543 void tcg_gen_rotli_i32(TCGv_i32 ret
, TCGv_i32 arg1
, unsigned arg2
)
545 tcg_debug_assert(arg2
< 32);
546 /* some cases can be optimized here */
548 tcg_gen_mov_i32(ret
, arg1
);
549 } else if (TCG_TARGET_HAS_rot_i32
) {
550 TCGv_i32 t0
= tcg_const_i32(arg2
);
551 tcg_gen_rotl_i32(ret
, arg1
, t0
);
552 tcg_temp_free_i32(t0
);
555 t0
= tcg_temp_new_i32();
556 t1
= tcg_temp_new_i32();
557 tcg_gen_shli_i32(t0
, arg1
, arg2
);
558 tcg_gen_shri_i32(t1
, arg1
, 32 - arg2
);
559 tcg_gen_or_i32(ret
, t0
, t1
);
560 tcg_temp_free_i32(t0
);
561 tcg_temp_free_i32(t1
);
565 void tcg_gen_rotr_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
567 if (TCG_TARGET_HAS_rot_i32
) {
568 tcg_gen_op3_i32(INDEX_op_rotr_i32
, ret
, arg1
, arg2
);
572 t0
= tcg_temp_new_i32();
573 t1
= tcg_temp_new_i32();
574 tcg_gen_shr_i32(t0
, arg1
, arg2
);
575 tcg_gen_subfi_i32(t1
, 32, arg2
);
576 tcg_gen_shl_i32(t1
, arg1
, t1
);
577 tcg_gen_or_i32(ret
, t0
, t1
);
578 tcg_temp_free_i32(t0
);
579 tcg_temp_free_i32(t1
);
583 void tcg_gen_rotri_i32(TCGv_i32 ret
, TCGv_i32 arg1
, unsigned arg2
)
585 tcg_debug_assert(arg2
< 32);
586 /* some cases can be optimized here */
588 tcg_gen_mov_i32(ret
, arg1
);
590 tcg_gen_rotli_i32(ret
, arg1
, 32 - arg2
);
594 void tcg_gen_deposit_i32(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
,
595 unsigned int ofs
, unsigned int len
)
600 tcg_debug_assert(ofs
< 32);
601 tcg_debug_assert(len
> 0);
602 tcg_debug_assert(len
<= 32);
603 tcg_debug_assert(ofs
+ len
<= 32);
606 tcg_gen_mov_i32(ret
, arg2
);
609 if (TCG_TARGET_HAS_deposit_i32
&& TCG_TARGET_deposit_i32_valid(ofs
, len
)) {
610 tcg_gen_op5ii_i32(INDEX_op_deposit_i32
, ret
, arg1
, arg2
, ofs
, len
);
614 t1
= tcg_temp_new_i32();
616 if (TCG_TARGET_HAS_extract2_i32
) {
617 if (ofs
+ len
== 32) {
618 tcg_gen_shli_i32(t1
, arg1
, len
);
619 tcg_gen_extract2_i32(ret
, t1
, arg2
, len
);
623 tcg_gen_extract2_i32(ret
, arg1
, arg2
, len
);
624 tcg_gen_rotli_i32(ret
, ret
, len
);
629 mask
= (1u << len
) - 1;
630 if (ofs
+ len
< 32) {
631 tcg_gen_andi_i32(t1
, arg2
, mask
);
632 tcg_gen_shli_i32(t1
, t1
, ofs
);
634 tcg_gen_shli_i32(t1
, arg2
, ofs
);
636 tcg_gen_andi_i32(ret
, arg1
, ~(mask
<< ofs
));
637 tcg_gen_or_i32(ret
, ret
, t1
);
639 tcg_temp_free_i32(t1
);
642 void tcg_gen_deposit_z_i32(TCGv_i32 ret
, TCGv_i32 arg
,
643 unsigned int ofs
, unsigned int len
)
645 tcg_debug_assert(ofs
< 32);
646 tcg_debug_assert(len
> 0);
647 tcg_debug_assert(len
<= 32);
648 tcg_debug_assert(ofs
+ len
<= 32);
650 if (ofs
+ len
== 32) {
651 tcg_gen_shli_i32(ret
, arg
, ofs
);
652 } else if (ofs
== 0) {
653 tcg_gen_andi_i32(ret
, arg
, (1u << len
) - 1);
654 } else if (TCG_TARGET_HAS_deposit_i32
655 && TCG_TARGET_deposit_i32_valid(ofs
, len
)) {
656 TCGv_i32 zero
= tcg_const_i32(0);
657 tcg_gen_op5ii_i32(INDEX_op_deposit_i32
, ret
, zero
, arg
, ofs
, len
);
658 tcg_temp_free_i32(zero
);
660 /* To help two-operand hosts we prefer to zero-extend first,
661 which allows ARG to stay live. */
664 if (TCG_TARGET_HAS_ext16u_i32
) {
665 tcg_gen_ext16u_i32(ret
, arg
);
666 tcg_gen_shli_i32(ret
, ret
, ofs
);
671 if (TCG_TARGET_HAS_ext8u_i32
) {
672 tcg_gen_ext8u_i32(ret
, arg
);
673 tcg_gen_shli_i32(ret
, ret
, ofs
);
678 /* Otherwise prefer zero-extension over AND for code size. */
681 if (TCG_TARGET_HAS_ext16u_i32
) {
682 tcg_gen_shli_i32(ret
, arg
, ofs
);
683 tcg_gen_ext16u_i32(ret
, ret
);
688 if (TCG_TARGET_HAS_ext8u_i32
) {
689 tcg_gen_shli_i32(ret
, arg
, ofs
);
690 tcg_gen_ext8u_i32(ret
, ret
);
695 tcg_gen_andi_i32(ret
, arg
, (1u << len
) - 1);
696 tcg_gen_shli_i32(ret
, ret
, ofs
);
700 void tcg_gen_extract_i32(TCGv_i32 ret
, TCGv_i32 arg
,
701 unsigned int ofs
, unsigned int len
)
703 tcg_debug_assert(ofs
< 32);
704 tcg_debug_assert(len
> 0);
705 tcg_debug_assert(len
<= 32);
706 tcg_debug_assert(ofs
+ len
<= 32);
708 /* Canonicalize certain special cases, even if extract is supported. */
709 if (ofs
+ len
== 32) {
710 tcg_gen_shri_i32(ret
, arg
, 32 - len
);
714 tcg_gen_andi_i32(ret
, arg
, (1u << len
) - 1);
718 if (TCG_TARGET_HAS_extract_i32
719 && TCG_TARGET_extract_i32_valid(ofs
, len
)) {
720 tcg_gen_op4ii_i32(INDEX_op_extract_i32
, ret
, arg
, ofs
, len
);
724 /* Assume that zero-extension, if available, is cheaper than a shift. */
727 if (TCG_TARGET_HAS_ext16u_i32
) {
728 tcg_gen_ext16u_i32(ret
, arg
);
729 tcg_gen_shri_i32(ret
, ret
, ofs
);
734 if (TCG_TARGET_HAS_ext8u_i32
) {
735 tcg_gen_ext8u_i32(ret
, arg
);
736 tcg_gen_shri_i32(ret
, ret
, ofs
);
742 /* ??? Ideally we'd know what values are available for immediate AND.
743 Assume that 8 bits are available, plus the special case of 16,
744 so that we get ext8u, ext16u. */
746 case 1 ... 8: case 16:
747 tcg_gen_shri_i32(ret
, arg
, ofs
);
748 tcg_gen_andi_i32(ret
, ret
, (1u << len
) - 1);
751 tcg_gen_shli_i32(ret
, arg
, 32 - len
- ofs
);
752 tcg_gen_shri_i32(ret
, ret
, 32 - len
);
757 void tcg_gen_sextract_i32(TCGv_i32 ret
, TCGv_i32 arg
,
758 unsigned int ofs
, unsigned int len
)
760 tcg_debug_assert(ofs
< 32);
761 tcg_debug_assert(len
> 0);
762 tcg_debug_assert(len
<= 32);
763 tcg_debug_assert(ofs
+ len
<= 32);
765 /* Canonicalize certain special cases, even if extract is supported. */
766 if (ofs
+ len
== 32) {
767 tcg_gen_sari_i32(ret
, arg
, 32 - len
);
773 tcg_gen_ext16s_i32(ret
, arg
);
776 tcg_gen_ext8s_i32(ret
, arg
);
781 if (TCG_TARGET_HAS_sextract_i32
782 && TCG_TARGET_extract_i32_valid(ofs
, len
)) {
783 tcg_gen_op4ii_i32(INDEX_op_sextract_i32
, ret
, arg
, ofs
, len
);
787 /* Assume that sign-extension, if available, is cheaper than a shift. */
790 if (TCG_TARGET_HAS_ext16s_i32
) {
791 tcg_gen_ext16s_i32(ret
, arg
);
792 tcg_gen_sari_i32(ret
, ret
, ofs
);
797 if (TCG_TARGET_HAS_ext8s_i32
) {
798 tcg_gen_ext8s_i32(ret
, arg
);
799 tcg_gen_sari_i32(ret
, ret
, ofs
);
806 if (TCG_TARGET_HAS_ext16s_i32
) {
807 tcg_gen_shri_i32(ret
, arg
, ofs
);
808 tcg_gen_ext16s_i32(ret
, ret
);
813 if (TCG_TARGET_HAS_ext8s_i32
) {
814 tcg_gen_shri_i32(ret
, arg
, ofs
);
815 tcg_gen_ext8s_i32(ret
, ret
);
821 tcg_gen_shli_i32(ret
, arg
, 32 - len
- ofs
);
822 tcg_gen_sari_i32(ret
, ret
, 32 - len
);
826 * Extract 32-bits from a 64-bit input, ah:al, starting from ofs.
827 * Unlike tcg_gen_extract_i32 above, len is fixed at 32.
829 void tcg_gen_extract2_i32(TCGv_i32 ret
, TCGv_i32 al
, TCGv_i32 ah
,
832 tcg_debug_assert(ofs
<= 32);
834 tcg_gen_mov_i32(ret
, al
);
835 } else if (ofs
== 32) {
836 tcg_gen_mov_i32(ret
, ah
);
837 } else if (al
== ah
) {
838 tcg_gen_rotri_i32(ret
, al
, ofs
);
839 } else if (TCG_TARGET_HAS_extract2_i32
) {
840 tcg_gen_op4i_i32(INDEX_op_extract2_i32
, ret
, al
, ah
, ofs
);
842 TCGv_i32 t0
= tcg_temp_new_i32();
843 tcg_gen_shri_i32(t0
, al
, ofs
);
844 tcg_gen_deposit_i32(ret
, t0
, ah
, 32 - ofs
, ofs
);
845 tcg_temp_free_i32(t0
);
849 void tcg_gen_movcond_i32(TCGCond cond
, TCGv_i32 ret
, TCGv_i32 c1
,
850 TCGv_i32 c2
, TCGv_i32 v1
, TCGv_i32 v2
)
852 if (cond
== TCG_COND_ALWAYS
) {
853 tcg_gen_mov_i32(ret
, v1
);
854 } else if (cond
== TCG_COND_NEVER
) {
855 tcg_gen_mov_i32(ret
, v2
);
856 } else if (TCG_TARGET_HAS_movcond_i32
) {
857 tcg_gen_op6i_i32(INDEX_op_movcond_i32
, ret
, c1
, c2
, v1
, v2
, cond
);
859 TCGv_i32 t0
= tcg_temp_new_i32();
860 TCGv_i32 t1
= tcg_temp_new_i32();
861 tcg_gen_setcond_i32(cond
, t0
, c1
, c2
);
862 tcg_gen_neg_i32(t0
, t0
);
863 tcg_gen_and_i32(t1
, v1
, t0
);
864 tcg_gen_andc_i32(ret
, v2
, t0
);
865 tcg_gen_or_i32(ret
, ret
, t1
);
866 tcg_temp_free_i32(t0
);
867 tcg_temp_free_i32(t1
);
871 void tcg_gen_add2_i32(TCGv_i32 rl
, TCGv_i32 rh
, TCGv_i32 al
,
872 TCGv_i32 ah
, TCGv_i32 bl
, TCGv_i32 bh
)
874 if (TCG_TARGET_HAS_add2_i32
) {
875 tcg_gen_op6_i32(INDEX_op_add2_i32
, rl
, rh
, al
, ah
, bl
, bh
);
877 TCGv_i64 t0
= tcg_temp_new_i64();
878 TCGv_i64 t1
= tcg_temp_new_i64();
879 tcg_gen_concat_i32_i64(t0
, al
, ah
);
880 tcg_gen_concat_i32_i64(t1
, bl
, bh
);
881 tcg_gen_add_i64(t0
, t0
, t1
);
882 tcg_gen_extr_i64_i32(rl
, rh
, t0
);
883 tcg_temp_free_i64(t0
);
884 tcg_temp_free_i64(t1
);
888 void tcg_gen_sub2_i32(TCGv_i32 rl
, TCGv_i32 rh
, TCGv_i32 al
,
889 TCGv_i32 ah
, TCGv_i32 bl
, TCGv_i32 bh
)
891 if (TCG_TARGET_HAS_sub2_i32
) {
892 tcg_gen_op6_i32(INDEX_op_sub2_i32
, rl
, rh
, al
, ah
, bl
, bh
);
894 TCGv_i64 t0
= tcg_temp_new_i64();
895 TCGv_i64 t1
= tcg_temp_new_i64();
896 tcg_gen_concat_i32_i64(t0
, al
, ah
);
897 tcg_gen_concat_i32_i64(t1
, bl
, bh
);
898 tcg_gen_sub_i64(t0
, t0
, t1
);
899 tcg_gen_extr_i64_i32(rl
, rh
, t0
);
900 tcg_temp_free_i64(t0
);
901 tcg_temp_free_i64(t1
);
905 void tcg_gen_mulu2_i32(TCGv_i32 rl
, TCGv_i32 rh
, TCGv_i32 arg1
, TCGv_i32 arg2
)
907 if (TCG_TARGET_HAS_mulu2_i32
) {
908 tcg_gen_op4_i32(INDEX_op_mulu2_i32
, rl
, rh
, arg1
, arg2
);
909 } else if (TCG_TARGET_HAS_muluh_i32
) {
910 TCGv_i32 t
= tcg_temp_new_i32();
911 tcg_gen_op3_i32(INDEX_op_mul_i32
, t
, arg1
, arg2
);
912 tcg_gen_op3_i32(INDEX_op_muluh_i32
, rh
, arg1
, arg2
);
913 tcg_gen_mov_i32(rl
, t
);
914 tcg_temp_free_i32(t
);
916 TCGv_i64 t0
= tcg_temp_new_i64();
917 TCGv_i64 t1
= tcg_temp_new_i64();
918 tcg_gen_extu_i32_i64(t0
, arg1
);
919 tcg_gen_extu_i32_i64(t1
, arg2
);
920 tcg_gen_mul_i64(t0
, t0
, t1
);
921 tcg_gen_extr_i64_i32(rl
, rh
, t0
);
922 tcg_temp_free_i64(t0
);
923 tcg_temp_free_i64(t1
);
927 void tcg_gen_muls2_i32(TCGv_i32 rl
, TCGv_i32 rh
, TCGv_i32 arg1
, TCGv_i32 arg2
)
929 if (TCG_TARGET_HAS_muls2_i32
) {
930 tcg_gen_op4_i32(INDEX_op_muls2_i32
, rl
, rh
, arg1
, arg2
);
931 } else if (TCG_TARGET_HAS_mulsh_i32
) {
932 TCGv_i32 t
= tcg_temp_new_i32();
933 tcg_gen_op3_i32(INDEX_op_mul_i32
, t
, arg1
, arg2
);
934 tcg_gen_op3_i32(INDEX_op_mulsh_i32
, rh
, arg1
, arg2
);
935 tcg_gen_mov_i32(rl
, t
);
936 tcg_temp_free_i32(t
);
937 } else if (TCG_TARGET_REG_BITS
== 32) {
938 TCGv_i32 t0
= tcg_temp_new_i32();
939 TCGv_i32 t1
= tcg_temp_new_i32();
940 TCGv_i32 t2
= tcg_temp_new_i32();
941 TCGv_i32 t3
= tcg_temp_new_i32();
942 tcg_gen_mulu2_i32(t0
, t1
, arg1
, arg2
);
943 /* Adjust for negative inputs. */
944 tcg_gen_sari_i32(t2
, arg1
, 31);
945 tcg_gen_sari_i32(t3
, arg2
, 31);
946 tcg_gen_and_i32(t2
, t2
, arg2
);
947 tcg_gen_and_i32(t3
, t3
, arg1
);
948 tcg_gen_sub_i32(rh
, t1
, t2
);
949 tcg_gen_sub_i32(rh
, rh
, t3
);
950 tcg_gen_mov_i32(rl
, t0
);
951 tcg_temp_free_i32(t0
);
952 tcg_temp_free_i32(t1
);
953 tcg_temp_free_i32(t2
);
954 tcg_temp_free_i32(t3
);
956 TCGv_i64 t0
= tcg_temp_new_i64();
957 TCGv_i64 t1
= tcg_temp_new_i64();
958 tcg_gen_ext_i32_i64(t0
, arg1
);
959 tcg_gen_ext_i32_i64(t1
, arg2
);
960 tcg_gen_mul_i64(t0
, t0
, t1
);
961 tcg_gen_extr_i64_i32(rl
, rh
, t0
);
962 tcg_temp_free_i64(t0
);
963 tcg_temp_free_i64(t1
);
967 void tcg_gen_mulsu2_i32(TCGv_i32 rl
, TCGv_i32 rh
, TCGv_i32 arg1
, TCGv_i32 arg2
)
969 if (TCG_TARGET_REG_BITS
== 32) {
970 TCGv_i32 t0
= tcg_temp_new_i32();
971 TCGv_i32 t1
= tcg_temp_new_i32();
972 TCGv_i32 t2
= tcg_temp_new_i32();
973 tcg_gen_mulu2_i32(t0
, t1
, arg1
, arg2
);
974 /* Adjust for negative input for the signed arg1. */
975 tcg_gen_sari_i32(t2
, arg1
, 31);
976 tcg_gen_and_i32(t2
, t2
, arg2
);
977 tcg_gen_sub_i32(rh
, t1
, t2
);
978 tcg_gen_mov_i32(rl
, t0
);
979 tcg_temp_free_i32(t0
);
980 tcg_temp_free_i32(t1
);
981 tcg_temp_free_i32(t2
);
983 TCGv_i64 t0
= tcg_temp_new_i64();
984 TCGv_i64 t1
= tcg_temp_new_i64();
985 tcg_gen_ext_i32_i64(t0
, arg1
);
986 tcg_gen_extu_i32_i64(t1
, arg2
);
987 tcg_gen_mul_i64(t0
, t0
, t1
);
988 tcg_gen_extr_i64_i32(rl
, rh
, t0
);
989 tcg_temp_free_i64(t0
);
990 tcg_temp_free_i64(t1
);
994 void tcg_gen_ext8s_i32(TCGv_i32 ret
, TCGv_i32 arg
)
996 if (TCG_TARGET_HAS_ext8s_i32
) {
997 tcg_gen_op2_i32(INDEX_op_ext8s_i32
, ret
, arg
);
999 tcg_gen_shli_i32(ret
, arg
, 24);
1000 tcg_gen_sari_i32(ret
, ret
, 24);
1004 void tcg_gen_ext16s_i32(TCGv_i32 ret
, TCGv_i32 arg
)
1006 if (TCG_TARGET_HAS_ext16s_i32
) {
1007 tcg_gen_op2_i32(INDEX_op_ext16s_i32
, ret
, arg
);
1009 tcg_gen_shli_i32(ret
, arg
, 16);
1010 tcg_gen_sari_i32(ret
, ret
, 16);
1014 void tcg_gen_ext8u_i32(TCGv_i32 ret
, TCGv_i32 arg
)
1016 if (TCG_TARGET_HAS_ext8u_i32
) {
1017 tcg_gen_op2_i32(INDEX_op_ext8u_i32
, ret
, arg
);
1019 tcg_gen_andi_i32(ret
, arg
, 0xffu
);
1023 void tcg_gen_ext16u_i32(TCGv_i32 ret
, TCGv_i32 arg
)
1025 if (TCG_TARGET_HAS_ext16u_i32
) {
1026 tcg_gen_op2_i32(INDEX_op_ext16u_i32
, ret
, arg
);
1028 tcg_gen_andi_i32(ret
, arg
, 0xffffu
);
1032 /* Note: we assume the two high bytes are set to zero */
1033 void tcg_gen_bswap16_i32(TCGv_i32 ret
, TCGv_i32 arg
)
1035 if (TCG_TARGET_HAS_bswap16_i32
) {
1036 tcg_gen_op2_i32(INDEX_op_bswap16_i32
, ret
, arg
);
1038 TCGv_i32 t0
= tcg_temp_new_i32();
1040 tcg_gen_ext8u_i32(t0
, arg
);
1041 tcg_gen_shli_i32(t0
, t0
, 8);
1042 tcg_gen_shri_i32(ret
, arg
, 8);
1043 tcg_gen_or_i32(ret
, ret
, t0
);
1044 tcg_temp_free_i32(t0
);
1048 void tcg_gen_bswap32_i32(TCGv_i32 ret
, TCGv_i32 arg
)
1050 if (TCG_TARGET_HAS_bswap32_i32
) {
1051 tcg_gen_op2_i32(INDEX_op_bswap32_i32
, ret
, arg
);
1053 TCGv_i32 t0
= tcg_temp_new_i32();
1054 TCGv_i32 t1
= tcg_temp_new_i32();
1055 TCGv_i32 t2
= tcg_const_i32(0x00ff00ff);
1058 tcg_gen_shri_i32(t0
, arg
, 8); /* t0 = .abc */
1059 tcg_gen_and_i32(t1
, arg
, t2
); /* t1 = .b.d */
1060 tcg_gen_and_i32(t0
, t0
, t2
); /* t0 = .a.c */
1061 tcg_gen_shli_i32(t1
, t1
, 8); /* t1 = b.d. */
1062 tcg_gen_or_i32(ret
, t0
, t1
); /* ret = badc */
1064 tcg_gen_shri_i32(t0
, ret
, 16); /* t0 = ..ba */
1065 tcg_gen_shli_i32(t1
, ret
, 16); /* t1 = dc.. */
1066 tcg_gen_or_i32(ret
, t0
, t1
); /* ret = dcba */
1068 tcg_temp_free_i32(t0
);
1069 tcg_temp_free_i32(t1
);
1070 tcg_temp_free_i32(t2
);
1074 void tcg_gen_smin_i32(TCGv_i32 ret
, TCGv_i32 a
, TCGv_i32 b
)
1076 tcg_gen_movcond_i32(TCG_COND_LT
, ret
, a
, b
, a
, b
);
1079 void tcg_gen_umin_i32(TCGv_i32 ret
, TCGv_i32 a
, TCGv_i32 b
)
1081 tcg_gen_movcond_i32(TCG_COND_LTU
, ret
, a
, b
, a
, b
);
1084 void tcg_gen_smax_i32(TCGv_i32 ret
, TCGv_i32 a
, TCGv_i32 b
)
1086 tcg_gen_movcond_i32(TCG_COND_LT
, ret
, a
, b
, b
, a
);
1089 void tcg_gen_umax_i32(TCGv_i32 ret
, TCGv_i32 a
, TCGv_i32 b
)
1091 tcg_gen_movcond_i32(TCG_COND_LTU
, ret
, a
, b
, b
, a
);
1096 #if TCG_TARGET_REG_BITS == 32
1097 /* These are all inline for TCG_TARGET_REG_BITS == 64. */
1099 void tcg_gen_discard_i64(TCGv_i64 arg
)
1101 tcg_gen_discard_i32(TCGV_LOW(arg
));
1102 tcg_gen_discard_i32(TCGV_HIGH(arg
));
1105 void tcg_gen_mov_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1107 tcg_gen_mov_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1108 tcg_gen_mov_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg
));
1111 void tcg_gen_movi_i64(TCGv_i64 ret
, int64_t arg
)
1113 tcg_gen_movi_i32(TCGV_LOW(ret
), arg
);
1114 tcg_gen_movi_i32(TCGV_HIGH(ret
), arg
>> 32);
1117 void tcg_gen_ld8u_i64(TCGv_i64 ret
, TCGv_ptr arg2
, tcg_target_long offset
)
1119 tcg_gen_ld8u_i32(TCGV_LOW(ret
), arg2
, offset
);
1120 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1123 void tcg_gen_ld8s_i64(TCGv_i64 ret
, TCGv_ptr arg2
, tcg_target_long offset
)
1125 tcg_gen_ld8s_i32(TCGV_LOW(ret
), arg2
, offset
);
1126 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
1129 void tcg_gen_ld16u_i64(TCGv_i64 ret
, TCGv_ptr arg2
, tcg_target_long offset
)
1131 tcg_gen_ld16u_i32(TCGV_LOW(ret
), arg2
, offset
);
1132 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1135 void tcg_gen_ld16s_i64(TCGv_i64 ret
, TCGv_ptr arg2
, tcg_target_long offset
)
1137 tcg_gen_ld16s_i32(TCGV_LOW(ret
), arg2
, offset
);
1138 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
1141 void tcg_gen_ld32u_i64(TCGv_i64 ret
, TCGv_ptr arg2
, tcg_target_long offset
)
1143 tcg_gen_ld_i32(TCGV_LOW(ret
), arg2
, offset
);
1144 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1147 void tcg_gen_ld32s_i64(TCGv_i64 ret
, TCGv_ptr arg2
, tcg_target_long offset
)
1149 tcg_gen_ld_i32(TCGV_LOW(ret
), arg2
, offset
);
1150 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
1153 void tcg_gen_ld_i64(TCGv_i64 ret
, TCGv_ptr arg2
, tcg_target_long offset
)
1155 /* Since arg2 and ret have different types,
1156 they cannot be the same temporary */
1157 #ifdef HOST_WORDS_BIGENDIAN
1158 tcg_gen_ld_i32(TCGV_HIGH(ret
), arg2
, offset
);
1159 tcg_gen_ld_i32(TCGV_LOW(ret
), arg2
, offset
+ 4);
1161 tcg_gen_ld_i32(TCGV_LOW(ret
), arg2
, offset
);
1162 tcg_gen_ld_i32(TCGV_HIGH(ret
), arg2
, offset
+ 4);
1166 void tcg_gen_st_i64(TCGv_i64 arg1
, TCGv_ptr arg2
, tcg_target_long offset
)
1168 #ifdef HOST_WORDS_BIGENDIAN
1169 tcg_gen_st_i32(TCGV_HIGH(arg1
), arg2
, offset
);
1170 tcg_gen_st_i32(TCGV_LOW(arg1
), arg2
, offset
+ 4);
1172 tcg_gen_st_i32(TCGV_LOW(arg1
), arg2
, offset
);
1173 tcg_gen_st_i32(TCGV_HIGH(arg1
), arg2
, offset
+ 4);
1177 void tcg_gen_and_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1179 tcg_gen_and_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), TCGV_LOW(arg2
));
1180 tcg_gen_and_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), TCGV_HIGH(arg2
));
1183 void tcg_gen_or_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1185 tcg_gen_or_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), TCGV_LOW(arg2
));
1186 tcg_gen_or_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), TCGV_HIGH(arg2
));
1189 void tcg_gen_xor_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1191 tcg_gen_xor_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), TCGV_LOW(arg2
));
1192 tcg_gen_xor_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), TCGV_HIGH(arg2
));
1195 void tcg_gen_shl_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1197 gen_helper_shl_i64(ret
, arg1
, arg2
);
1200 void tcg_gen_shr_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1202 gen_helper_shr_i64(ret
, arg1
, arg2
);
1205 void tcg_gen_sar_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1207 gen_helper_sar_i64(ret
, arg1
, arg2
);
1210 void tcg_gen_mul_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1215 t0
= tcg_temp_new_i64();
1216 t1
= tcg_temp_new_i32();
1218 tcg_gen_mulu2_i32(TCGV_LOW(t0
), TCGV_HIGH(t0
),
1219 TCGV_LOW(arg1
), TCGV_LOW(arg2
));
1221 tcg_gen_mul_i32(t1
, TCGV_LOW(arg1
), TCGV_HIGH(arg2
));
1222 tcg_gen_add_i32(TCGV_HIGH(t0
), TCGV_HIGH(t0
), t1
);
1223 tcg_gen_mul_i32(t1
, TCGV_HIGH(arg1
), TCGV_LOW(arg2
));
1224 tcg_gen_add_i32(TCGV_HIGH(t0
), TCGV_HIGH(t0
), t1
);
1226 tcg_gen_mov_i64(ret
, t0
);
1227 tcg_temp_free_i64(t0
);
1228 tcg_temp_free_i32(t1
);
1230 #endif /* TCG_TARGET_REG_SIZE == 32 */
1232 void tcg_gen_addi_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1234 /* some cases can be optimized here */
1236 tcg_gen_mov_i64(ret
, arg1
);
1238 TCGv_i64 t0
= tcg_const_i64(arg2
);
1239 tcg_gen_add_i64(ret
, arg1
, t0
);
1240 tcg_temp_free_i64(t0
);
1244 void tcg_gen_subfi_i64(TCGv_i64 ret
, int64_t arg1
, TCGv_i64 arg2
)
1246 if (arg1
== 0 && TCG_TARGET_HAS_neg_i64
) {
1247 /* Don't recurse with tcg_gen_neg_i64. */
1248 tcg_gen_op2_i64(INDEX_op_neg_i64
, ret
, arg2
);
1250 TCGv_i64 t0
= tcg_const_i64(arg1
);
1251 tcg_gen_sub_i64(ret
, t0
, arg2
);
1252 tcg_temp_free_i64(t0
);
1256 void tcg_gen_subi_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1258 /* some cases can be optimized here */
1260 tcg_gen_mov_i64(ret
, arg1
);
1262 TCGv_i64 t0
= tcg_const_i64(arg2
);
1263 tcg_gen_sub_i64(ret
, arg1
, t0
);
1264 tcg_temp_free_i64(t0
);
1268 void tcg_gen_andi_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1272 if (TCG_TARGET_REG_BITS
== 32) {
1273 tcg_gen_andi_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), arg2
);
1274 tcg_gen_andi_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), arg2
>> 32);
1278 /* Some cases can be optimized here. */
1281 tcg_gen_movi_i64(ret
, 0);
1284 tcg_gen_mov_i64(ret
, arg1
);
1287 /* Don't recurse with tcg_gen_ext8u_i64. */
1288 if (TCG_TARGET_HAS_ext8u_i64
) {
1289 tcg_gen_op2_i64(INDEX_op_ext8u_i64
, ret
, arg1
);
1294 if (TCG_TARGET_HAS_ext16u_i64
) {
1295 tcg_gen_op2_i64(INDEX_op_ext16u_i64
, ret
, arg1
);
1300 if (TCG_TARGET_HAS_ext32u_i64
) {
1301 tcg_gen_op2_i64(INDEX_op_ext32u_i64
, ret
, arg1
);
1306 t0
= tcg_const_i64(arg2
);
1307 tcg_gen_and_i64(ret
, arg1
, t0
);
1308 tcg_temp_free_i64(t0
);
1311 void tcg_gen_ori_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1313 if (TCG_TARGET_REG_BITS
== 32) {
1314 tcg_gen_ori_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), arg2
);
1315 tcg_gen_ori_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), arg2
>> 32);
1318 /* Some cases can be optimized here. */
1320 tcg_gen_movi_i64(ret
, -1);
1321 } else if (arg2
== 0) {
1322 tcg_gen_mov_i64(ret
, arg1
);
1324 TCGv_i64 t0
= tcg_const_i64(arg2
);
1325 tcg_gen_or_i64(ret
, arg1
, t0
);
1326 tcg_temp_free_i64(t0
);
1330 void tcg_gen_xori_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1332 if (TCG_TARGET_REG_BITS
== 32) {
1333 tcg_gen_xori_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), arg2
);
1334 tcg_gen_xori_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), arg2
>> 32);
1337 /* Some cases can be optimized here. */
1339 tcg_gen_mov_i64(ret
, arg1
);
1340 } else if (arg2
== -1 && TCG_TARGET_HAS_not_i64
) {
1341 /* Don't recurse with tcg_gen_not_i64. */
1342 tcg_gen_op2_i64(INDEX_op_not_i64
, ret
, arg1
);
1344 TCGv_i64 t0
= tcg_const_i64(arg2
);
1345 tcg_gen_xor_i64(ret
, arg1
, t0
);
1346 tcg_temp_free_i64(t0
);
1350 static inline void tcg_gen_shifti_i64(TCGv_i64 ret
, TCGv_i64 arg1
,
1351 unsigned c
, bool right
, bool arith
)
1353 tcg_debug_assert(c
< 64);
1355 tcg_gen_mov_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
));
1356 tcg_gen_mov_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
));
1357 } else if (c
>= 32) {
1361 tcg_gen_sari_i32(TCGV_LOW(ret
), TCGV_HIGH(arg1
), c
);
1362 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), 31);
1364 tcg_gen_shri_i32(TCGV_LOW(ret
), TCGV_HIGH(arg1
), c
);
1365 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1368 tcg_gen_shli_i32(TCGV_HIGH(ret
), TCGV_LOW(arg1
), c
);
1369 tcg_gen_movi_i32(TCGV_LOW(ret
), 0);
1372 if (TCG_TARGET_HAS_extract2_i32
) {
1373 tcg_gen_extract2_i32(TCGV_LOW(ret
),
1374 TCGV_LOW(arg1
), TCGV_HIGH(arg1
), c
);
1376 tcg_gen_shri_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), c
);
1377 tcg_gen_deposit_i32(TCGV_LOW(ret
), TCGV_LOW(ret
),
1378 TCGV_HIGH(arg1
), 32 - c
, c
);
1381 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), c
);
1383 tcg_gen_shri_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), c
);
1386 if (TCG_TARGET_HAS_extract2_i32
) {
1387 tcg_gen_extract2_i32(TCGV_HIGH(ret
),
1388 TCGV_LOW(arg1
), TCGV_HIGH(arg1
), 32 - c
);
1390 TCGv_i32 t0
= tcg_temp_new_i32();
1391 tcg_gen_shri_i32(t0
, TCGV_LOW(arg1
), 32 - c
);
1392 tcg_gen_deposit_i32(TCGV_HIGH(ret
), t0
,
1393 TCGV_HIGH(arg1
), c
, 32 - c
);
1394 tcg_temp_free_i32(t0
);
1396 tcg_gen_shli_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), c
);
1400 void tcg_gen_shli_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1402 tcg_debug_assert(arg2
>= 0 && arg2
< 64);
1403 if (TCG_TARGET_REG_BITS
== 32) {
1404 tcg_gen_shifti_i64(ret
, arg1
, arg2
, 0, 0);
1405 } else if (arg2
== 0) {
1406 tcg_gen_mov_i64(ret
, arg1
);
1408 TCGv_i64 t0
= tcg_const_i64(arg2
);
1409 tcg_gen_shl_i64(ret
, arg1
, t0
);
1410 tcg_temp_free_i64(t0
);
1414 void tcg_gen_shri_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1416 tcg_debug_assert(arg2
>= 0 && arg2
< 64);
1417 if (TCG_TARGET_REG_BITS
== 32) {
1418 tcg_gen_shifti_i64(ret
, arg1
, arg2
, 1, 0);
1419 } else if (arg2
== 0) {
1420 tcg_gen_mov_i64(ret
, arg1
);
1422 TCGv_i64 t0
= tcg_const_i64(arg2
);
1423 tcg_gen_shr_i64(ret
, arg1
, t0
);
1424 tcg_temp_free_i64(t0
);
1428 void tcg_gen_sari_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1430 tcg_debug_assert(arg2
>= 0 && arg2
< 64);
1431 if (TCG_TARGET_REG_BITS
== 32) {
1432 tcg_gen_shifti_i64(ret
, arg1
, arg2
, 1, 1);
1433 } else if (arg2
== 0) {
1434 tcg_gen_mov_i64(ret
, arg1
);
1436 TCGv_i64 t0
= tcg_const_i64(arg2
);
1437 tcg_gen_sar_i64(ret
, arg1
, t0
);
1438 tcg_temp_free_i64(t0
);
1442 void tcg_gen_brcond_i64(TCGCond cond
, TCGv_i64 arg1
, TCGv_i64 arg2
, TCGLabel
*l
)
1444 if (cond
== TCG_COND_ALWAYS
) {
1446 } else if (cond
!= TCG_COND_NEVER
) {
1448 if (TCG_TARGET_REG_BITS
== 32) {
1449 tcg_gen_op6ii_i32(INDEX_op_brcond2_i32
, TCGV_LOW(arg1
),
1450 TCGV_HIGH(arg1
), TCGV_LOW(arg2
),
1451 TCGV_HIGH(arg2
), cond
, label_arg(l
));
1453 tcg_gen_op4ii_i64(INDEX_op_brcond_i64
, arg1
, arg2
, cond
,
1459 void tcg_gen_brcondi_i64(TCGCond cond
, TCGv_i64 arg1
, int64_t arg2
, TCGLabel
*l
)
1461 if (cond
== TCG_COND_ALWAYS
) {
1463 } else if (cond
!= TCG_COND_NEVER
) {
1464 TCGv_i64 t0
= tcg_const_i64(arg2
);
1465 tcg_gen_brcond_i64(cond
, arg1
, t0
, l
);
1466 tcg_temp_free_i64(t0
);
1470 void tcg_gen_setcond_i64(TCGCond cond
, TCGv_i64 ret
,
1471 TCGv_i64 arg1
, TCGv_i64 arg2
)
1473 if (cond
== TCG_COND_ALWAYS
) {
1474 tcg_gen_movi_i64(ret
, 1);
1475 } else if (cond
== TCG_COND_NEVER
) {
1476 tcg_gen_movi_i64(ret
, 0);
1478 if (TCG_TARGET_REG_BITS
== 32) {
1479 tcg_gen_op6i_i32(INDEX_op_setcond2_i32
, TCGV_LOW(ret
),
1480 TCGV_LOW(arg1
), TCGV_HIGH(arg1
),
1481 TCGV_LOW(arg2
), TCGV_HIGH(arg2
), cond
);
1482 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1484 tcg_gen_op4i_i64(INDEX_op_setcond_i64
, ret
, arg1
, arg2
, cond
);
1489 void tcg_gen_setcondi_i64(TCGCond cond
, TCGv_i64 ret
,
1490 TCGv_i64 arg1
, int64_t arg2
)
1492 TCGv_i64 t0
= tcg_const_i64(arg2
);
1493 tcg_gen_setcond_i64(cond
, ret
, arg1
, t0
);
1494 tcg_temp_free_i64(t0
);
1497 void tcg_gen_muli_i64(TCGv_i64 ret
, TCGv_i64 arg1
, int64_t arg2
)
1500 tcg_gen_movi_i64(ret
, 0);
1501 } else if (is_power_of_2(arg2
)) {
1502 tcg_gen_shli_i64(ret
, arg1
, ctz64(arg2
));
1504 TCGv_i64 t0
= tcg_const_i64(arg2
);
1505 tcg_gen_mul_i64(ret
, arg1
, t0
);
1506 tcg_temp_free_i64(t0
);
1510 void tcg_gen_div_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1512 if (TCG_TARGET_HAS_div_i64
) {
1513 tcg_gen_op3_i64(INDEX_op_div_i64
, ret
, arg1
, arg2
);
1514 } else if (TCG_TARGET_HAS_div2_i64
) {
1515 TCGv_i64 t0
= tcg_temp_new_i64();
1516 tcg_gen_sari_i64(t0
, arg1
, 63);
1517 tcg_gen_op5_i64(INDEX_op_div2_i64
, ret
, t0
, arg1
, t0
, arg2
);
1518 tcg_temp_free_i64(t0
);
1520 gen_helper_div_i64(ret
, arg1
, arg2
);
1524 void tcg_gen_rem_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1526 if (TCG_TARGET_HAS_rem_i64
) {
1527 tcg_gen_op3_i64(INDEX_op_rem_i64
, ret
, arg1
, arg2
);
1528 } else if (TCG_TARGET_HAS_div_i64
) {
1529 TCGv_i64 t0
= tcg_temp_new_i64();
1530 tcg_gen_op3_i64(INDEX_op_div_i64
, t0
, arg1
, arg2
);
1531 tcg_gen_mul_i64(t0
, t0
, arg2
);
1532 tcg_gen_sub_i64(ret
, arg1
, t0
);
1533 tcg_temp_free_i64(t0
);
1534 } else if (TCG_TARGET_HAS_div2_i64
) {
1535 TCGv_i64 t0
= tcg_temp_new_i64();
1536 tcg_gen_sari_i64(t0
, arg1
, 63);
1537 tcg_gen_op5_i64(INDEX_op_div2_i64
, t0
, ret
, arg1
, t0
, arg2
);
1538 tcg_temp_free_i64(t0
);
1540 gen_helper_rem_i64(ret
, arg1
, arg2
);
1544 void tcg_gen_divu_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1546 if (TCG_TARGET_HAS_div_i64
) {
1547 tcg_gen_op3_i64(INDEX_op_divu_i64
, ret
, arg1
, arg2
);
1548 } else if (TCG_TARGET_HAS_div2_i64
) {
1549 TCGv_i64 t0
= tcg_temp_new_i64();
1550 tcg_gen_movi_i64(t0
, 0);
1551 tcg_gen_op5_i64(INDEX_op_divu2_i64
, ret
, t0
, arg1
, t0
, arg2
);
1552 tcg_temp_free_i64(t0
);
1554 gen_helper_divu_i64(ret
, arg1
, arg2
);
1558 void tcg_gen_remu_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1560 if (TCG_TARGET_HAS_rem_i64
) {
1561 tcg_gen_op3_i64(INDEX_op_remu_i64
, ret
, arg1
, arg2
);
1562 } else if (TCG_TARGET_HAS_div_i64
) {
1563 TCGv_i64 t0
= tcg_temp_new_i64();
1564 tcg_gen_op3_i64(INDEX_op_divu_i64
, t0
, arg1
, arg2
);
1565 tcg_gen_mul_i64(t0
, t0
, arg2
);
1566 tcg_gen_sub_i64(ret
, arg1
, t0
);
1567 tcg_temp_free_i64(t0
);
1568 } else if (TCG_TARGET_HAS_div2_i64
) {
1569 TCGv_i64 t0
= tcg_temp_new_i64();
1570 tcg_gen_movi_i64(t0
, 0);
1571 tcg_gen_op5_i64(INDEX_op_divu2_i64
, t0
, ret
, arg1
, t0
, arg2
);
1572 tcg_temp_free_i64(t0
);
1574 gen_helper_remu_i64(ret
, arg1
, arg2
);
1578 void tcg_gen_ext8s_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1580 if (TCG_TARGET_REG_BITS
== 32) {
1581 tcg_gen_ext8s_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1582 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
1583 } else if (TCG_TARGET_HAS_ext8s_i64
) {
1584 tcg_gen_op2_i64(INDEX_op_ext8s_i64
, ret
, arg
);
1586 tcg_gen_shli_i64(ret
, arg
, 56);
1587 tcg_gen_sari_i64(ret
, ret
, 56);
1591 void tcg_gen_ext16s_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1593 if (TCG_TARGET_REG_BITS
== 32) {
1594 tcg_gen_ext16s_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1595 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
1596 } else if (TCG_TARGET_HAS_ext16s_i64
) {
1597 tcg_gen_op2_i64(INDEX_op_ext16s_i64
, ret
, arg
);
1599 tcg_gen_shli_i64(ret
, arg
, 48);
1600 tcg_gen_sari_i64(ret
, ret
, 48);
1604 void tcg_gen_ext32s_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1606 if (TCG_TARGET_REG_BITS
== 32) {
1607 tcg_gen_mov_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1608 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
1609 } else if (TCG_TARGET_HAS_ext32s_i64
) {
1610 tcg_gen_op2_i64(INDEX_op_ext32s_i64
, ret
, arg
);
1612 tcg_gen_shli_i64(ret
, arg
, 32);
1613 tcg_gen_sari_i64(ret
, ret
, 32);
1617 void tcg_gen_ext8u_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1619 if (TCG_TARGET_REG_BITS
== 32) {
1620 tcg_gen_ext8u_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1621 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1622 } else if (TCG_TARGET_HAS_ext8u_i64
) {
1623 tcg_gen_op2_i64(INDEX_op_ext8u_i64
, ret
, arg
);
1625 tcg_gen_andi_i64(ret
, arg
, 0xffu
);
1629 void tcg_gen_ext16u_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1631 if (TCG_TARGET_REG_BITS
== 32) {
1632 tcg_gen_ext16u_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1633 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1634 } else if (TCG_TARGET_HAS_ext16u_i64
) {
1635 tcg_gen_op2_i64(INDEX_op_ext16u_i64
, ret
, arg
);
1637 tcg_gen_andi_i64(ret
, arg
, 0xffffu
);
1641 void tcg_gen_ext32u_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1643 if (TCG_TARGET_REG_BITS
== 32) {
1644 tcg_gen_mov_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1645 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1646 } else if (TCG_TARGET_HAS_ext32u_i64
) {
1647 tcg_gen_op2_i64(INDEX_op_ext32u_i64
, ret
, arg
);
1649 tcg_gen_andi_i64(ret
, arg
, 0xffffffffu
);
1653 /* Note: we assume the six high bytes are set to zero */
1654 void tcg_gen_bswap16_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1656 if (TCG_TARGET_REG_BITS
== 32) {
1657 tcg_gen_bswap16_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1658 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1659 } else if (TCG_TARGET_HAS_bswap16_i64
) {
1660 tcg_gen_op2_i64(INDEX_op_bswap16_i64
, ret
, arg
);
1662 TCGv_i64 t0
= tcg_temp_new_i64();
1664 tcg_gen_ext8u_i64(t0
, arg
);
1665 tcg_gen_shli_i64(t0
, t0
, 8);
1666 tcg_gen_shri_i64(ret
, arg
, 8);
1667 tcg_gen_or_i64(ret
, ret
, t0
);
1668 tcg_temp_free_i64(t0
);
1672 /* Note: we assume the four high bytes are set to zero */
1673 void tcg_gen_bswap32_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1675 if (TCG_TARGET_REG_BITS
== 32) {
1676 tcg_gen_bswap32_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1677 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1678 } else if (TCG_TARGET_HAS_bswap32_i64
) {
1679 tcg_gen_op2_i64(INDEX_op_bswap32_i64
, ret
, arg
);
1681 TCGv_i64 t0
= tcg_temp_new_i64();
1682 TCGv_i64 t1
= tcg_temp_new_i64();
1683 TCGv_i64 t2
= tcg_const_i64(0x00ff00ff);
1685 /* arg = ....abcd */
1686 tcg_gen_shri_i64(t0
, arg
, 8); /* t0 = .....abc */
1687 tcg_gen_and_i64(t1
, arg
, t2
); /* t1 = .....b.d */
1688 tcg_gen_and_i64(t0
, t0
, t2
); /* t0 = .....a.c */
1689 tcg_gen_shli_i64(t1
, t1
, 8); /* t1 = ....b.d. */
1690 tcg_gen_or_i64(ret
, t0
, t1
); /* ret = ....badc */
1692 tcg_gen_shli_i64(t1
, ret
, 48); /* t1 = dc...... */
1693 tcg_gen_shri_i64(t0
, ret
, 16); /* t0 = ......ba */
1694 tcg_gen_shri_i64(t1
, t1
, 32); /* t1 = ....dc.. */
1695 tcg_gen_or_i64(ret
, t0
, t1
); /* ret = ....dcba */
1697 tcg_temp_free_i64(t0
);
1698 tcg_temp_free_i64(t1
);
1699 tcg_temp_free_i64(t2
);
1703 void tcg_gen_bswap64_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1705 if (TCG_TARGET_REG_BITS
== 32) {
1707 t0
= tcg_temp_new_i32();
1708 t1
= tcg_temp_new_i32();
1710 tcg_gen_bswap32_i32(t0
, TCGV_LOW(arg
));
1711 tcg_gen_bswap32_i32(t1
, TCGV_HIGH(arg
));
1712 tcg_gen_mov_i32(TCGV_LOW(ret
), t1
);
1713 tcg_gen_mov_i32(TCGV_HIGH(ret
), t0
);
1714 tcg_temp_free_i32(t0
);
1715 tcg_temp_free_i32(t1
);
1716 } else if (TCG_TARGET_HAS_bswap64_i64
) {
1717 tcg_gen_op2_i64(INDEX_op_bswap64_i64
, ret
, arg
);
1719 TCGv_i64 t0
= tcg_temp_new_i64();
1720 TCGv_i64 t1
= tcg_temp_new_i64();
1721 TCGv_i64 t2
= tcg_temp_new_i64();
1723 /* arg = abcdefgh */
1724 tcg_gen_movi_i64(t2
, 0x00ff00ff00ff00ffull
);
1725 tcg_gen_shri_i64(t0
, arg
, 8); /* t0 = .abcdefg */
1726 tcg_gen_and_i64(t1
, arg
, t2
); /* t1 = .b.d.f.h */
1727 tcg_gen_and_i64(t0
, t0
, t2
); /* t0 = .a.c.e.g */
1728 tcg_gen_shli_i64(t1
, t1
, 8); /* t1 = b.d.f.h. */
1729 tcg_gen_or_i64(ret
, t0
, t1
); /* ret = badcfehg */
1731 tcg_gen_movi_i64(t2
, 0x0000ffff0000ffffull
);
1732 tcg_gen_shri_i64(t0
, ret
, 16); /* t0 = ..badcfe */
1733 tcg_gen_and_i64(t1
, ret
, t2
); /* t1 = ..dc..hg */
1734 tcg_gen_and_i64(t0
, t0
, t2
); /* t0 = ..ba..fe */
1735 tcg_gen_shli_i64(t1
, t1
, 16); /* t1 = dc..hg.. */
1736 tcg_gen_or_i64(ret
, t0
, t1
); /* ret = dcbahgfe */
1738 tcg_gen_shri_i64(t0
, ret
, 32); /* t0 = ....dcba */
1739 tcg_gen_shli_i64(t1
, ret
, 32); /* t1 = hgfe.... */
1740 tcg_gen_or_i64(ret
, t0
, t1
); /* ret = hgfedcba */
1742 tcg_temp_free_i64(t0
);
1743 tcg_temp_free_i64(t1
);
1744 tcg_temp_free_i64(t2
);
1748 void tcg_gen_not_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1750 if (TCG_TARGET_REG_BITS
== 32) {
1751 tcg_gen_not_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
1752 tcg_gen_not_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg
));
1753 } else if (TCG_TARGET_HAS_not_i64
) {
1754 tcg_gen_op2_i64(INDEX_op_not_i64
, ret
, arg
);
1756 tcg_gen_xori_i64(ret
, arg
, -1);
1760 void tcg_gen_andc_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1762 if (TCG_TARGET_REG_BITS
== 32) {
1763 tcg_gen_andc_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), TCGV_LOW(arg2
));
1764 tcg_gen_andc_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), TCGV_HIGH(arg2
));
1765 } else if (TCG_TARGET_HAS_andc_i64
) {
1766 tcg_gen_op3_i64(INDEX_op_andc_i64
, ret
, arg1
, arg2
);
1768 TCGv_i64 t0
= tcg_temp_new_i64();
1769 tcg_gen_not_i64(t0
, arg2
);
1770 tcg_gen_and_i64(ret
, arg1
, t0
);
1771 tcg_temp_free_i64(t0
);
1775 void tcg_gen_eqv_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1777 if (TCG_TARGET_REG_BITS
== 32) {
1778 tcg_gen_eqv_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), TCGV_LOW(arg2
));
1779 tcg_gen_eqv_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), TCGV_HIGH(arg2
));
1780 } else if (TCG_TARGET_HAS_eqv_i64
) {
1781 tcg_gen_op3_i64(INDEX_op_eqv_i64
, ret
, arg1
, arg2
);
1783 tcg_gen_xor_i64(ret
, arg1
, arg2
);
1784 tcg_gen_not_i64(ret
, ret
);
1788 void tcg_gen_nand_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1790 if (TCG_TARGET_REG_BITS
== 32) {
1791 tcg_gen_nand_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), TCGV_LOW(arg2
));
1792 tcg_gen_nand_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), TCGV_HIGH(arg2
));
1793 } else if (TCG_TARGET_HAS_nand_i64
) {
1794 tcg_gen_op3_i64(INDEX_op_nand_i64
, ret
, arg1
, arg2
);
1796 tcg_gen_and_i64(ret
, arg1
, arg2
);
1797 tcg_gen_not_i64(ret
, ret
);
1801 void tcg_gen_nor_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1803 if (TCG_TARGET_REG_BITS
== 32) {
1804 tcg_gen_nor_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), TCGV_LOW(arg2
));
1805 tcg_gen_nor_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), TCGV_HIGH(arg2
));
1806 } else if (TCG_TARGET_HAS_nor_i64
) {
1807 tcg_gen_op3_i64(INDEX_op_nor_i64
, ret
, arg1
, arg2
);
1809 tcg_gen_or_i64(ret
, arg1
, arg2
);
1810 tcg_gen_not_i64(ret
, ret
);
1814 void tcg_gen_orc_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1816 if (TCG_TARGET_REG_BITS
== 32) {
1817 tcg_gen_orc_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), TCGV_LOW(arg2
));
1818 tcg_gen_orc_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
), TCGV_HIGH(arg2
));
1819 } else if (TCG_TARGET_HAS_orc_i64
) {
1820 tcg_gen_op3_i64(INDEX_op_orc_i64
, ret
, arg1
, arg2
);
1822 TCGv_i64 t0
= tcg_temp_new_i64();
1823 tcg_gen_not_i64(t0
, arg2
);
1824 tcg_gen_or_i64(ret
, arg1
, t0
);
1825 tcg_temp_free_i64(t0
);
1829 void tcg_gen_clz_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1831 if (TCG_TARGET_HAS_clz_i64
) {
1832 tcg_gen_op3_i64(INDEX_op_clz_i64
, ret
, arg1
, arg2
);
1834 gen_helper_clz_i64(ret
, arg1
, arg2
);
1838 void tcg_gen_clzi_i64(TCGv_i64 ret
, TCGv_i64 arg1
, uint64_t arg2
)
1840 if (TCG_TARGET_REG_BITS
== 32
1841 && TCG_TARGET_HAS_clz_i32
1842 && arg2
<= 0xffffffffu
) {
1843 TCGv_i32 t
= tcg_const_i32((uint32_t)arg2
- 32);
1844 tcg_gen_clz_i32(t
, TCGV_LOW(arg1
), t
);
1845 tcg_gen_addi_i32(t
, t
, 32);
1846 tcg_gen_clz_i32(TCGV_LOW(ret
), TCGV_HIGH(arg1
), t
);
1847 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1848 tcg_temp_free_i32(t
);
1850 TCGv_i64 t
= tcg_const_i64(arg2
);
1851 tcg_gen_clz_i64(ret
, arg1
, t
);
1852 tcg_temp_free_i64(t
);
1856 void tcg_gen_ctz_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1858 if (TCG_TARGET_HAS_ctz_i64
) {
1859 tcg_gen_op3_i64(INDEX_op_ctz_i64
, ret
, arg1
, arg2
);
1860 } else if (TCG_TARGET_HAS_ctpop_i64
|| TCG_TARGET_HAS_clz_i64
) {
1861 TCGv_i64 z
, t
= tcg_temp_new_i64();
1863 if (TCG_TARGET_HAS_ctpop_i64
) {
1864 tcg_gen_subi_i64(t
, arg1
, 1);
1865 tcg_gen_andc_i64(t
, t
, arg1
);
1866 tcg_gen_ctpop_i64(t
, t
);
1868 /* Since all non-x86 hosts have clz(0) == 64, don't fight it. */
1869 tcg_gen_neg_i64(t
, arg1
);
1870 tcg_gen_and_i64(t
, t
, arg1
);
1871 tcg_gen_clzi_i64(t
, t
, 64);
1872 tcg_gen_xori_i64(t
, t
, 63);
1874 z
= tcg_const_i64(0);
1875 tcg_gen_movcond_i64(TCG_COND_EQ
, ret
, arg1
, z
, arg2
, t
);
1876 tcg_temp_free_i64(t
);
1877 tcg_temp_free_i64(z
);
1879 gen_helper_ctz_i64(ret
, arg1
, arg2
);
1883 void tcg_gen_ctzi_i64(TCGv_i64 ret
, TCGv_i64 arg1
, uint64_t arg2
)
1885 if (TCG_TARGET_REG_BITS
== 32
1886 && TCG_TARGET_HAS_ctz_i32
1887 && arg2
<= 0xffffffffu
) {
1888 TCGv_i32 t32
= tcg_const_i32((uint32_t)arg2
- 32);
1889 tcg_gen_ctz_i32(t32
, TCGV_HIGH(arg1
), t32
);
1890 tcg_gen_addi_i32(t32
, t32
, 32);
1891 tcg_gen_ctz_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
), t32
);
1892 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1893 tcg_temp_free_i32(t32
);
1894 } else if (!TCG_TARGET_HAS_ctz_i64
1895 && TCG_TARGET_HAS_ctpop_i64
1897 /* This equivalence has the advantage of not requiring a fixup. */
1898 TCGv_i64 t
= tcg_temp_new_i64();
1899 tcg_gen_subi_i64(t
, arg1
, 1);
1900 tcg_gen_andc_i64(t
, t
, arg1
);
1901 tcg_gen_ctpop_i64(ret
, t
);
1902 tcg_temp_free_i64(t
);
1904 TCGv_i64 t64
= tcg_const_i64(arg2
);
1905 tcg_gen_ctz_i64(ret
, arg1
, t64
);
1906 tcg_temp_free_i64(t64
);
1910 void tcg_gen_clrsb_i64(TCGv_i64 ret
, TCGv_i64 arg
)
1912 if (TCG_TARGET_HAS_clz_i64
|| TCG_TARGET_HAS_clz_i32
) {
1913 TCGv_i64 t
= tcg_temp_new_i64();
1914 tcg_gen_sari_i64(t
, arg
, 63);
1915 tcg_gen_xor_i64(t
, t
, arg
);
1916 tcg_gen_clzi_i64(t
, t
, 64);
1917 tcg_gen_subi_i64(ret
, t
, 1);
1918 tcg_temp_free_i64(t
);
1920 gen_helper_clrsb_i64(ret
, arg
);
1924 void tcg_gen_ctpop_i64(TCGv_i64 ret
, TCGv_i64 arg1
)
1926 if (TCG_TARGET_HAS_ctpop_i64
) {
1927 tcg_gen_op2_i64(INDEX_op_ctpop_i64
, ret
, arg1
);
1928 } else if (TCG_TARGET_REG_BITS
== 32 && TCG_TARGET_HAS_ctpop_i32
) {
1929 tcg_gen_ctpop_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
));
1930 tcg_gen_ctpop_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
));
1931 tcg_gen_add_i32(TCGV_LOW(ret
), TCGV_LOW(ret
), TCGV_HIGH(ret
));
1932 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
1934 gen_helper_ctpop_i64(ret
, arg1
);
1938 void tcg_gen_rotl_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1940 if (TCG_TARGET_HAS_rot_i64
) {
1941 tcg_gen_op3_i64(INDEX_op_rotl_i64
, ret
, arg1
, arg2
);
1944 t0
= tcg_temp_new_i64();
1945 t1
= tcg_temp_new_i64();
1946 tcg_gen_shl_i64(t0
, arg1
, arg2
);
1947 tcg_gen_subfi_i64(t1
, 64, arg2
);
1948 tcg_gen_shr_i64(t1
, arg1
, t1
);
1949 tcg_gen_or_i64(ret
, t0
, t1
);
1950 tcg_temp_free_i64(t0
);
1951 tcg_temp_free_i64(t1
);
1955 void tcg_gen_rotli_i64(TCGv_i64 ret
, TCGv_i64 arg1
, unsigned arg2
)
1957 tcg_debug_assert(arg2
< 64);
1958 /* some cases can be optimized here */
1960 tcg_gen_mov_i64(ret
, arg1
);
1961 } else if (TCG_TARGET_HAS_rot_i64
) {
1962 TCGv_i64 t0
= tcg_const_i64(arg2
);
1963 tcg_gen_rotl_i64(ret
, arg1
, t0
);
1964 tcg_temp_free_i64(t0
);
1967 t0
= tcg_temp_new_i64();
1968 t1
= tcg_temp_new_i64();
1969 tcg_gen_shli_i64(t0
, arg1
, arg2
);
1970 tcg_gen_shri_i64(t1
, arg1
, 64 - arg2
);
1971 tcg_gen_or_i64(ret
, t0
, t1
);
1972 tcg_temp_free_i64(t0
);
1973 tcg_temp_free_i64(t1
);
1977 void tcg_gen_rotr_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
)
1979 if (TCG_TARGET_HAS_rot_i64
) {
1980 tcg_gen_op3_i64(INDEX_op_rotr_i64
, ret
, arg1
, arg2
);
1983 t0
= tcg_temp_new_i64();
1984 t1
= tcg_temp_new_i64();
1985 tcg_gen_shr_i64(t0
, arg1
, arg2
);
1986 tcg_gen_subfi_i64(t1
, 64, arg2
);
1987 tcg_gen_shl_i64(t1
, arg1
, t1
);
1988 tcg_gen_or_i64(ret
, t0
, t1
);
1989 tcg_temp_free_i64(t0
);
1990 tcg_temp_free_i64(t1
);
1994 void tcg_gen_rotri_i64(TCGv_i64 ret
, TCGv_i64 arg1
, unsigned arg2
)
1996 tcg_debug_assert(arg2
< 64);
1997 /* some cases can be optimized here */
1999 tcg_gen_mov_i64(ret
, arg1
);
2001 tcg_gen_rotli_i64(ret
, arg1
, 64 - arg2
);
2005 void tcg_gen_deposit_i64(TCGv_i64 ret
, TCGv_i64 arg1
, TCGv_i64 arg2
,
2006 unsigned int ofs
, unsigned int len
)
2011 tcg_debug_assert(ofs
< 64);
2012 tcg_debug_assert(len
> 0);
2013 tcg_debug_assert(len
<= 64);
2014 tcg_debug_assert(ofs
+ len
<= 64);
2017 tcg_gen_mov_i64(ret
, arg2
);
2020 if (TCG_TARGET_HAS_deposit_i64
&& TCG_TARGET_deposit_i64_valid(ofs
, len
)) {
2021 tcg_gen_op5ii_i64(INDEX_op_deposit_i64
, ret
, arg1
, arg2
, ofs
, len
);
2025 if (TCG_TARGET_REG_BITS
== 32) {
2027 tcg_gen_deposit_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
),
2028 TCGV_LOW(arg2
), ofs
- 32, len
);
2029 tcg_gen_mov_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
));
2032 if (ofs
+ len
<= 32) {
2033 tcg_gen_deposit_i32(TCGV_LOW(ret
), TCGV_LOW(arg1
),
2034 TCGV_LOW(arg2
), ofs
, len
);
2035 tcg_gen_mov_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg1
));
2040 t1
= tcg_temp_new_i64();
2042 if (TCG_TARGET_HAS_extract2_i64
) {
2043 if (ofs
+ len
== 64) {
2044 tcg_gen_shli_i64(t1
, arg1
, len
);
2045 tcg_gen_extract2_i64(ret
, t1
, arg2
, len
);
2049 tcg_gen_extract2_i64(ret
, arg1
, arg2
, len
);
2050 tcg_gen_rotli_i64(ret
, ret
, len
);
2055 mask
= (1ull << len
) - 1;
2056 if (ofs
+ len
< 64) {
2057 tcg_gen_andi_i64(t1
, arg2
, mask
);
2058 tcg_gen_shli_i64(t1
, t1
, ofs
);
2060 tcg_gen_shli_i64(t1
, arg2
, ofs
);
2062 tcg_gen_andi_i64(ret
, arg1
, ~(mask
<< ofs
));
2063 tcg_gen_or_i64(ret
, ret
, t1
);
2065 tcg_temp_free_i64(t1
);
2068 void tcg_gen_deposit_z_i64(TCGv_i64 ret
, TCGv_i64 arg
,
2069 unsigned int ofs
, unsigned int len
)
2071 tcg_debug_assert(ofs
< 64);
2072 tcg_debug_assert(len
> 0);
2073 tcg_debug_assert(len
<= 64);
2074 tcg_debug_assert(ofs
+ len
<= 64);
2076 if (ofs
+ len
== 64) {
2077 tcg_gen_shli_i64(ret
, arg
, ofs
);
2078 } else if (ofs
== 0) {
2079 tcg_gen_andi_i64(ret
, arg
, (1ull << len
) - 1);
2080 } else if (TCG_TARGET_HAS_deposit_i64
2081 && TCG_TARGET_deposit_i64_valid(ofs
, len
)) {
2082 TCGv_i64 zero
= tcg_const_i64(0);
2083 tcg_gen_op5ii_i64(INDEX_op_deposit_i64
, ret
, zero
, arg
, ofs
, len
);
2084 tcg_temp_free_i64(zero
);
2086 if (TCG_TARGET_REG_BITS
== 32) {
2088 tcg_gen_deposit_z_i32(TCGV_HIGH(ret
), TCGV_LOW(arg
),
2090 tcg_gen_movi_i32(TCGV_LOW(ret
), 0);
2093 if (ofs
+ len
<= 32) {
2094 tcg_gen_deposit_z_i32(TCGV_LOW(ret
), TCGV_LOW(arg
), ofs
, len
);
2095 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
2099 /* To help two-operand hosts we prefer to zero-extend first,
2100 which allows ARG to stay live. */
2103 if (TCG_TARGET_HAS_ext32u_i64
) {
2104 tcg_gen_ext32u_i64(ret
, arg
);
2105 tcg_gen_shli_i64(ret
, ret
, ofs
);
2110 if (TCG_TARGET_HAS_ext16u_i64
) {
2111 tcg_gen_ext16u_i64(ret
, arg
);
2112 tcg_gen_shli_i64(ret
, ret
, ofs
);
2117 if (TCG_TARGET_HAS_ext8u_i64
) {
2118 tcg_gen_ext8u_i64(ret
, arg
);
2119 tcg_gen_shli_i64(ret
, ret
, ofs
);
2124 /* Otherwise prefer zero-extension over AND for code size. */
2125 switch (ofs
+ len
) {
2127 if (TCG_TARGET_HAS_ext32u_i64
) {
2128 tcg_gen_shli_i64(ret
, arg
, ofs
);
2129 tcg_gen_ext32u_i64(ret
, ret
);
2134 if (TCG_TARGET_HAS_ext16u_i64
) {
2135 tcg_gen_shli_i64(ret
, arg
, ofs
);
2136 tcg_gen_ext16u_i64(ret
, ret
);
2141 if (TCG_TARGET_HAS_ext8u_i64
) {
2142 tcg_gen_shli_i64(ret
, arg
, ofs
);
2143 tcg_gen_ext8u_i64(ret
, ret
);
2148 tcg_gen_andi_i64(ret
, arg
, (1ull << len
) - 1);
2149 tcg_gen_shli_i64(ret
, ret
, ofs
);
2153 void tcg_gen_extract_i64(TCGv_i64 ret
, TCGv_i64 arg
,
2154 unsigned int ofs
, unsigned int len
)
2156 tcg_debug_assert(ofs
< 64);
2157 tcg_debug_assert(len
> 0);
2158 tcg_debug_assert(len
<= 64);
2159 tcg_debug_assert(ofs
+ len
<= 64);
2161 /* Canonicalize certain special cases, even if extract is supported. */
2162 if (ofs
+ len
== 64) {
2163 tcg_gen_shri_i64(ret
, arg
, 64 - len
);
2167 tcg_gen_andi_i64(ret
, arg
, (1ull << len
) - 1);
2171 if (TCG_TARGET_REG_BITS
== 32) {
2172 /* Look for a 32-bit extract within one of the two words. */
2174 tcg_gen_extract_i32(TCGV_LOW(ret
), TCGV_HIGH(arg
), ofs
- 32, len
);
2175 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
2178 if (ofs
+ len
<= 32) {
2179 tcg_gen_extract_i32(TCGV_LOW(ret
), TCGV_LOW(arg
), ofs
, len
);
2180 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
2183 /* The field is split across two words. One double-word
2184 shift is better than two double-word shifts. */
2188 if (TCG_TARGET_HAS_extract_i64
2189 && TCG_TARGET_extract_i64_valid(ofs
, len
)) {
2190 tcg_gen_op4ii_i64(INDEX_op_extract_i64
, ret
, arg
, ofs
, len
);
2194 /* Assume that zero-extension, if available, is cheaper than a shift. */
2195 switch (ofs
+ len
) {
2197 if (TCG_TARGET_HAS_ext32u_i64
) {
2198 tcg_gen_ext32u_i64(ret
, arg
);
2199 tcg_gen_shri_i64(ret
, ret
, ofs
);
2204 if (TCG_TARGET_HAS_ext16u_i64
) {
2205 tcg_gen_ext16u_i64(ret
, arg
);
2206 tcg_gen_shri_i64(ret
, ret
, ofs
);
2211 if (TCG_TARGET_HAS_ext8u_i64
) {
2212 tcg_gen_ext8u_i64(ret
, arg
);
2213 tcg_gen_shri_i64(ret
, ret
, ofs
);
2219 /* ??? Ideally we'd know what values are available for immediate AND.
2220 Assume that 8 bits are available, plus the special cases of 16 and 32,
2221 so that we get ext8u, ext16u, and ext32u. */
2223 case 1 ... 8: case 16: case 32:
2225 tcg_gen_shri_i64(ret
, arg
, ofs
);
2226 tcg_gen_andi_i64(ret
, ret
, (1ull << len
) - 1);
2229 tcg_gen_shli_i64(ret
, arg
, 64 - len
- ofs
);
2230 tcg_gen_shri_i64(ret
, ret
, 64 - len
);
2235 void tcg_gen_sextract_i64(TCGv_i64 ret
, TCGv_i64 arg
,
2236 unsigned int ofs
, unsigned int len
)
2238 tcg_debug_assert(ofs
< 64);
2239 tcg_debug_assert(len
> 0);
2240 tcg_debug_assert(len
<= 64);
2241 tcg_debug_assert(ofs
+ len
<= 64);
2243 /* Canonicalize certain special cases, even if sextract is supported. */
2244 if (ofs
+ len
== 64) {
2245 tcg_gen_sari_i64(ret
, arg
, 64 - len
);
2251 tcg_gen_ext32s_i64(ret
, arg
);
2254 tcg_gen_ext16s_i64(ret
, arg
);
2257 tcg_gen_ext8s_i64(ret
, arg
);
2262 if (TCG_TARGET_REG_BITS
== 32) {
2263 /* Look for a 32-bit extract within one of the two words. */
2265 tcg_gen_sextract_i32(TCGV_LOW(ret
), TCGV_HIGH(arg
), ofs
- 32, len
);
2266 } else if (ofs
+ len
<= 32) {
2267 tcg_gen_sextract_i32(TCGV_LOW(ret
), TCGV_LOW(arg
), ofs
, len
);
2268 } else if (ofs
== 0) {
2269 tcg_gen_mov_i32(TCGV_LOW(ret
), TCGV_LOW(arg
));
2270 tcg_gen_sextract_i32(TCGV_HIGH(ret
), TCGV_HIGH(arg
), 0, len
- 32);
2272 } else if (len
> 32) {
2273 TCGv_i32 t
= tcg_temp_new_i32();
2274 /* Extract the bits for the high word normally. */
2275 tcg_gen_sextract_i32(t
, TCGV_HIGH(arg
), ofs
+ 32, len
- 32);
2276 /* Shift the field down for the low part. */
2277 tcg_gen_shri_i64(ret
, arg
, ofs
);
2278 /* Overwrite the shift into the high part. */
2279 tcg_gen_mov_i32(TCGV_HIGH(ret
), t
);
2280 tcg_temp_free_i32(t
);
2283 /* Shift the field down for the low part, such that the
2284 field sits at the MSB. */
2285 tcg_gen_shri_i64(ret
, arg
, ofs
+ len
- 32);
2286 /* Shift the field down from the MSB, sign extending. */
2287 tcg_gen_sari_i32(TCGV_LOW(ret
), TCGV_LOW(ret
), 32 - len
);
2289 /* Sign-extend the field from 32 bits. */
2290 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
2294 if (TCG_TARGET_HAS_sextract_i64
2295 && TCG_TARGET_extract_i64_valid(ofs
, len
)) {
2296 tcg_gen_op4ii_i64(INDEX_op_sextract_i64
, ret
, arg
, ofs
, len
);
2300 /* Assume that sign-extension, if available, is cheaper than a shift. */
2301 switch (ofs
+ len
) {
2303 if (TCG_TARGET_HAS_ext32s_i64
) {
2304 tcg_gen_ext32s_i64(ret
, arg
);
2305 tcg_gen_sari_i64(ret
, ret
, ofs
);
2310 if (TCG_TARGET_HAS_ext16s_i64
) {
2311 tcg_gen_ext16s_i64(ret
, arg
);
2312 tcg_gen_sari_i64(ret
, ret
, ofs
);
2317 if (TCG_TARGET_HAS_ext8s_i64
) {
2318 tcg_gen_ext8s_i64(ret
, arg
);
2319 tcg_gen_sari_i64(ret
, ret
, ofs
);
2326 if (TCG_TARGET_HAS_ext32s_i64
) {
2327 tcg_gen_shri_i64(ret
, arg
, ofs
);
2328 tcg_gen_ext32s_i64(ret
, ret
);
2333 if (TCG_TARGET_HAS_ext16s_i64
) {
2334 tcg_gen_shri_i64(ret
, arg
, ofs
);
2335 tcg_gen_ext16s_i64(ret
, ret
);
2340 if (TCG_TARGET_HAS_ext8s_i64
) {
2341 tcg_gen_shri_i64(ret
, arg
, ofs
);
2342 tcg_gen_ext8s_i64(ret
, ret
);
2347 tcg_gen_shli_i64(ret
, arg
, 64 - len
- ofs
);
2348 tcg_gen_sari_i64(ret
, ret
, 64 - len
);
2352 * Extract 64 bits from a 128-bit input, ah:al, starting from ofs.
2353 * Unlike tcg_gen_extract_i64 above, len is fixed at 64.
2355 void tcg_gen_extract2_i64(TCGv_i64 ret
, TCGv_i64 al
, TCGv_i64 ah
,
2358 tcg_debug_assert(ofs
<= 64);
2360 tcg_gen_mov_i64(ret
, al
);
2361 } else if (ofs
== 64) {
2362 tcg_gen_mov_i64(ret
, ah
);
2363 } else if (al
== ah
) {
2364 tcg_gen_rotri_i64(ret
, al
, ofs
);
2365 } else if (TCG_TARGET_HAS_extract2_i64
) {
2366 tcg_gen_op4i_i64(INDEX_op_extract2_i64
, ret
, al
, ah
, ofs
);
2368 TCGv_i64 t0
= tcg_temp_new_i64();
2369 tcg_gen_shri_i64(t0
, al
, ofs
);
2370 tcg_gen_deposit_i64(ret
, t0
, ah
, 64 - ofs
, ofs
);
2371 tcg_temp_free_i64(t0
);
2375 void tcg_gen_movcond_i64(TCGCond cond
, TCGv_i64 ret
, TCGv_i64 c1
,
2376 TCGv_i64 c2
, TCGv_i64 v1
, TCGv_i64 v2
)
2378 if (cond
== TCG_COND_ALWAYS
) {
2379 tcg_gen_mov_i64(ret
, v1
);
2380 } else if (cond
== TCG_COND_NEVER
) {
2381 tcg_gen_mov_i64(ret
, v2
);
2382 } else if (TCG_TARGET_REG_BITS
== 32) {
2383 TCGv_i32 t0
= tcg_temp_new_i32();
2384 TCGv_i32 t1
= tcg_temp_new_i32();
2385 tcg_gen_op6i_i32(INDEX_op_setcond2_i32
, t0
,
2386 TCGV_LOW(c1
), TCGV_HIGH(c1
),
2387 TCGV_LOW(c2
), TCGV_HIGH(c2
), cond
);
2389 if (TCG_TARGET_HAS_movcond_i32
) {
2390 tcg_gen_movi_i32(t1
, 0);
2391 tcg_gen_movcond_i32(TCG_COND_NE
, TCGV_LOW(ret
), t0
, t1
,
2392 TCGV_LOW(v1
), TCGV_LOW(v2
));
2393 tcg_gen_movcond_i32(TCG_COND_NE
, TCGV_HIGH(ret
), t0
, t1
,
2394 TCGV_HIGH(v1
), TCGV_HIGH(v2
));
2396 tcg_gen_neg_i32(t0
, t0
);
2398 tcg_gen_and_i32(t1
, TCGV_LOW(v1
), t0
);
2399 tcg_gen_andc_i32(TCGV_LOW(ret
), TCGV_LOW(v2
), t0
);
2400 tcg_gen_or_i32(TCGV_LOW(ret
), TCGV_LOW(ret
), t1
);
2402 tcg_gen_and_i32(t1
, TCGV_HIGH(v1
), t0
);
2403 tcg_gen_andc_i32(TCGV_HIGH(ret
), TCGV_HIGH(v2
), t0
);
2404 tcg_gen_or_i32(TCGV_HIGH(ret
), TCGV_HIGH(ret
), t1
);
2406 tcg_temp_free_i32(t0
);
2407 tcg_temp_free_i32(t1
);
2408 } else if (TCG_TARGET_HAS_movcond_i64
) {
2409 tcg_gen_op6i_i64(INDEX_op_movcond_i64
, ret
, c1
, c2
, v1
, v2
, cond
);
2411 TCGv_i64 t0
= tcg_temp_new_i64();
2412 TCGv_i64 t1
= tcg_temp_new_i64();
2413 tcg_gen_setcond_i64(cond
, t0
, c1
, c2
);
2414 tcg_gen_neg_i64(t0
, t0
);
2415 tcg_gen_and_i64(t1
, v1
, t0
);
2416 tcg_gen_andc_i64(ret
, v2
, t0
);
2417 tcg_gen_or_i64(ret
, ret
, t1
);
2418 tcg_temp_free_i64(t0
);
2419 tcg_temp_free_i64(t1
);
2423 void tcg_gen_add2_i64(TCGv_i64 rl
, TCGv_i64 rh
, TCGv_i64 al
,
2424 TCGv_i64 ah
, TCGv_i64 bl
, TCGv_i64 bh
)
2426 if (TCG_TARGET_HAS_add2_i64
) {
2427 tcg_gen_op6_i64(INDEX_op_add2_i64
, rl
, rh
, al
, ah
, bl
, bh
);
2429 TCGv_i64 t0
= tcg_temp_new_i64();
2430 TCGv_i64 t1
= tcg_temp_new_i64();
2431 tcg_gen_add_i64(t0
, al
, bl
);
2432 tcg_gen_setcond_i64(TCG_COND_LTU
, t1
, t0
, al
);
2433 tcg_gen_add_i64(rh
, ah
, bh
);
2434 tcg_gen_add_i64(rh
, rh
, t1
);
2435 tcg_gen_mov_i64(rl
, t0
);
2436 tcg_temp_free_i64(t0
);
2437 tcg_temp_free_i64(t1
);
2441 void tcg_gen_sub2_i64(TCGv_i64 rl
, TCGv_i64 rh
, TCGv_i64 al
,
2442 TCGv_i64 ah
, TCGv_i64 bl
, TCGv_i64 bh
)
2444 if (TCG_TARGET_HAS_sub2_i64
) {
2445 tcg_gen_op6_i64(INDEX_op_sub2_i64
, rl
, rh
, al
, ah
, bl
, bh
);
2447 TCGv_i64 t0
= tcg_temp_new_i64();
2448 TCGv_i64 t1
= tcg_temp_new_i64();
2449 tcg_gen_sub_i64(t0
, al
, bl
);
2450 tcg_gen_setcond_i64(TCG_COND_LTU
, t1
, al
, bl
);
2451 tcg_gen_sub_i64(rh
, ah
, bh
);
2452 tcg_gen_sub_i64(rh
, rh
, t1
);
2453 tcg_gen_mov_i64(rl
, t0
);
2454 tcg_temp_free_i64(t0
);
2455 tcg_temp_free_i64(t1
);
2459 void tcg_gen_mulu2_i64(TCGv_i64 rl
, TCGv_i64 rh
, TCGv_i64 arg1
, TCGv_i64 arg2
)
2461 if (TCG_TARGET_HAS_mulu2_i64
) {
2462 tcg_gen_op4_i64(INDEX_op_mulu2_i64
, rl
, rh
, arg1
, arg2
);
2463 } else if (TCG_TARGET_HAS_muluh_i64
) {
2464 TCGv_i64 t
= tcg_temp_new_i64();
2465 tcg_gen_op3_i64(INDEX_op_mul_i64
, t
, arg1
, arg2
);
2466 tcg_gen_op3_i64(INDEX_op_muluh_i64
, rh
, arg1
, arg2
);
2467 tcg_gen_mov_i64(rl
, t
);
2468 tcg_temp_free_i64(t
);
2470 TCGv_i64 t0
= tcg_temp_new_i64();
2471 tcg_gen_mul_i64(t0
, arg1
, arg2
);
2472 gen_helper_muluh_i64(rh
, arg1
, arg2
);
2473 tcg_gen_mov_i64(rl
, t0
);
2474 tcg_temp_free_i64(t0
);
2478 void tcg_gen_muls2_i64(TCGv_i64 rl
, TCGv_i64 rh
, TCGv_i64 arg1
, TCGv_i64 arg2
)
2480 if (TCG_TARGET_HAS_muls2_i64
) {
2481 tcg_gen_op4_i64(INDEX_op_muls2_i64
, rl
, rh
, arg1
, arg2
);
2482 } else if (TCG_TARGET_HAS_mulsh_i64
) {
2483 TCGv_i64 t
= tcg_temp_new_i64();
2484 tcg_gen_op3_i64(INDEX_op_mul_i64
, t
, arg1
, arg2
);
2485 tcg_gen_op3_i64(INDEX_op_mulsh_i64
, rh
, arg1
, arg2
);
2486 tcg_gen_mov_i64(rl
, t
);
2487 tcg_temp_free_i64(t
);
2488 } else if (TCG_TARGET_HAS_mulu2_i64
|| TCG_TARGET_HAS_muluh_i64
) {
2489 TCGv_i64 t0
= tcg_temp_new_i64();
2490 TCGv_i64 t1
= tcg_temp_new_i64();
2491 TCGv_i64 t2
= tcg_temp_new_i64();
2492 TCGv_i64 t3
= tcg_temp_new_i64();
2493 tcg_gen_mulu2_i64(t0
, t1
, arg1
, arg2
);
2494 /* Adjust for negative inputs. */
2495 tcg_gen_sari_i64(t2
, arg1
, 63);
2496 tcg_gen_sari_i64(t3
, arg2
, 63);
2497 tcg_gen_and_i64(t2
, t2
, arg2
);
2498 tcg_gen_and_i64(t3
, t3
, arg1
);
2499 tcg_gen_sub_i64(rh
, t1
, t2
);
2500 tcg_gen_sub_i64(rh
, rh
, t3
);
2501 tcg_gen_mov_i64(rl
, t0
);
2502 tcg_temp_free_i64(t0
);
2503 tcg_temp_free_i64(t1
);
2504 tcg_temp_free_i64(t2
);
2505 tcg_temp_free_i64(t3
);
2507 TCGv_i64 t0
= tcg_temp_new_i64();
2508 tcg_gen_mul_i64(t0
, arg1
, arg2
);
2509 gen_helper_mulsh_i64(rh
, arg1
, arg2
);
2510 tcg_gen_mov_i64(rl
, t0
);
2511 tcg_temp_free_i64(t0
);
2515 void tcg_gen_mulsu2_i64(TCGv_i64 rl
, TCGv_i64 rh
, TCGv_i64 arg1
, TCGv_i64 arg2
)
2517 TCGv_i64 t0
= tcg_temp_new_i64();
2518 TCGv_i64 t1
= tcg_temp_new_i64();
2519 TCGv_i64 t2
= tcg_temp_new_i64();
2520 tcg_gen_mulu2_i64(t0
, t1
, arg1
, arg2
);
2521 /* Adjust for negative input for the signed arg1. */
2522 tcg_gen_sari_i64(t2
, arg1
, 63);
2523 tcg_gen_and_i64(t2
, t2
, arg2
);
2524 tcg_gen_sub_i64(rh
, t1
, t2
);
2525 tcg_gen_mov_i64(rl
, t0
);
2526 tcg_temp_free_i64(t0
);
2527 tcg_temp_free_i64(t1
);
2528 tcg_temp_free_i64(t2
);
2531 void tcg_gen_smin_i64(TCGv_i64 ret
, TCGv_i64 a
, TCGv_i64 b
)
2533 tcg_gen_movcond_i64(TCG_COND_LT
, ret
, a
, b
, a
, b
);
2536 void tcg_gen_umin_i64(TCGv_i64 ret
, TCGv_i64 a
, TCGv_i64 b
)
2538 tcg_gen_movcond_i64(TCG_COND_LTU
, ret
, a
, b
, a
, b
);
2541 void tcg_gen_smax_i64(TCGv_i64 ret
, TCGv_i64 a
, TCGv_i64 b
)
2543 tcg_gen_movcond_i64(TCG_COND_LT
, ret
, a
, b
, b
, a
);
2546 void tcg_gen_umax_i64(TCGv_i64 ret
, TCGv_i64 a
, TCGv_i64 b
)
2548 tcg_gen_movcond_i64(TCG_COND_LTU
, ret
, a
, b
, b
, a
);
2551 /* Size changing operations. */
2553 void tcg_gen_extrl_i64_i32(TCGv_i32 ret
, TCGv_i64 arg
)
2555 if (TCG_TARGET_REG_BITS
== 32) {
2556 tcg_gen_mov_i32(ret
, TCGV_LOW(arg
));
2557 } else if (TCG_TARGET_HAS_extrl_i64_i32
) {
2558 tcg_gen_op2(INDEX_op_extrl_i64_i32
,
2559 tcgv_i32_arg(ret
), tcgv_i64_arg(arg
));
2561 tcg_gen_mov_i32(ret
, (TCGv_i32
)arg
);
2565 void tcg_gen_extrh_i64_i32(TCGv_i32 ret
, TCGv_i64 arg
)
2567 if (TCG_TARGET_REG_BITS
== 32) {
2568 tcg_gen_mov_i32(ret
, TCGV_HIGH(arg
));
2569 } else if (TCG_TARGET_HAS_extrh_i64_i32
) {
2570 tcg_gen_op2(INDEX_op_extrh_i64_i32
,
2571 tcgv_i32_arg(ret
), tcgv_i64_arg(arg
));
2573 TCGv_i64 t
= tcg_temp_new_i64();
2574 tcg_gen_shri_i64(t
, arg
, 32);
2575 tcg_gen_mov_i32(ret
, (TCGv_i32
)t
);
2576 tcg_temp_free_i64(t
);
2580 void tcg_gen_extu_i32_i64(TCGv_i64 ret
, TCGv_i32 arg
)
2582 if (TCG_TARGET_REG_BITS
== 32) {
2583 tcg_gen_mov_i32(TCGV_LOW(ret
), arg
);
2584 tcg_gen_movi_i32(TCGV_HIGH(ret
), 0);
2586 tcg_gen_op2(INDEX_op_extu_i32_i64
,
2587 tcgv_i64_arg(ret
), tcgv_i32_arg(arg
));
2591 void tcg_gen_ext_i32_i64(TCGv_i64 ret
, TCGv_i32 arg
)
2593 if (TCG_TARGET_REG_BITS
== 32) {
2594 tcg_gen_mov_i32(TCGV_LOW(ret
), arg
);
2595 tcg_gen_sari_i32(TCGV_HIGH(ret
), TCGV_LOW(ret
), 31);
2597 tcg_gen_op2(INDEX_op_ext_i32_i64
,
2598 tcgv_i64_arg(ret
), tcgv_i32_arg(arg
));
2602 void tcg_gen_concat_i32_i64(TCGv_i64 dest
, TCGv_i32 low
, TCGv_i32 high
)
2606 if (TCG_TARGET_REG_BITS
== 32) {
2607 tcg_gen_mov_i32(TCGV_LOW(dest
), low
);
2608 tcg_gen_mov_i32(TCGV_HIGH(dest
), high
);
2612 tmp
= tcg_temp_new_i64();
2613 /* These extensions are only needed for type correctness.
2614 We may be able to do better given target specific information. */
2615 tcg_gen_extu_i32_i64(tmp
, high
);
2616 tcg_gen_extu_i32_i64(dest
, low
);
2617 /* If deposit is available, use it. Otherwise use the extra
2618 knowledge that we have of the zero-extensions above. */
2619 if (TCG_TARGET_HAS_deposit_i64
&& TCG_TARGET_deposit_i64_valid(32, 32)) {
2620 tcg_gen_deposit_i64(dest
, dest
, tmp
, 32, 32);
2622 tcg_gen_shli_i64(tmp
, tmp
, 32);
2623 tcg_gen_or_i64(dest
, dest
, tmp
);
2625 tcg_temp_free_i64(tmp
);
2628 void tcg_gen_extr_i64_i32(TCGv_i32 lo
, TCGv_i32 hi
, TCGv_i64 arg
)
2630 if (TCG_TARGET_REG_BITS
== 32) {
2631 tcg_gen_mov_i32(lo
, TCGV_LOW(arg
));
2632 tcg_gen_mov_i32(hi
, TCGV_HIGH(arg
));
2634 tcg_gen_extrl_i64_i32(lo
, arg
);
2635 tcg_gen_extrh_i64_i32(hi
, arg
);
2639 void tcg_gen_extr32_i64(TCGv_i64 lo
, TCGv_i64 hi
, TCGv_i64 arg
)
2641 tcg_gen_ext32u_i64(lo
, arg
);
2642 tcg_gen_shri_i64(hi
, arg
, 32);
2645 /* QEMU specific operations. */
2647 void tcg_gen_exit_tb(TranslationBlock
*tb
, unsigned idx
)
2649 uintptr_t val
= (uintptr_t)tb
+ idx
;
2652 tcg_debug_assert(idx
== 0);
2653 } else if (idx
<= TB_EXIT_IDXMAX
) {
2654 #ifdef CONFIG_DEBUG_TCG
2655 /* This is an exit following a goto_tb. Verify that we have
2656 seen this numbered exit before, via tcg_gen_goto_tb. */
2657 tcg_debug_assert(tcg_ctx
->goto_tb_issue_mask
& (1 << idx
));
2659 /* When not chaining, exit without indicating a link. */
2660 if (qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN
)) {
2664 /* This is an exit via the exitreq label. */
2665 tcg_debug_assert(idx
== TB_EXIT_REQUESTED
);
2668 tcg_gen_op1i(INDEX_op_exit_tb
, val
);
2671 void tcg_gen_goto_tb(unsigned idx
)
2673 /* We only support two chained exits. */
2674 tcg_debug_assert(idx
<= TB_EXIT_IDXMAX
);
2675 #ifdef CONFIG_DEBUG_TCG
2676 /* Verify that we havn't seen this numbered exit before. */
2677 tcg_debug_assert((tcg_ctx
->goto_tb_issue_mask
& (1 << idx
)) == 0);
2678 tcg_ctx
->goto_tb_issue_mask
|= 1 << idx
;
2680 /* When not chaining, we simply fall through to the "fallback" exit. */
2681 if (!qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN
)) {
2682 tcg_gen_op1i(INDEX_op_goto_tb
, idx
);
2686 void tcg_gen_lookup_and_goto_ptr(void)
2688 if (TCG_TARGET_HAS_goto_ptr
&& !qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN
)) {
2689 TCGv_ptr ptr
= tcg_temp_new_ptr();
2690 gen_helper_lookup_tb_ptr(ptr
, cpu_env
);
2691 tcg_gen_op1i(INDEX_op_goto_ptr
, tcgv_ptr_arg(ptr
));
2692 tcg_temp_free_ptr(ptr
);
2694 tcg_gen_exit_tb(NULL
, 0);
2698 static inline TCGMemOp
tcg_canonicalize_memop(TCGMemOp op
, bool is64
, bool st
)
2700 /* Trigger the asserts within as early as possible. */
2701 (void)get_alignment_bits(op
);
2703 switch (op
& MO_SIZE
) {
2726 static void gen_ldst_i32(TCGOpcode opc
, TCGv_i32 val
, TCGv addr
,
2727 TCGMemOp memop
, TCGArg idx
)
2729 TCGMemOpIdx oi
= make_memop_idx(memop
, idx
);
2730 #if TARGET_LONG_BITS == 32
2731 tcg_gen_op3i_i32(opc
, val
, addr
, oi
);
2733 if (TCG_TARGET_REG_BITS
== 32) {
2734 tcg_gen_op4i_i32(opc
, val
, TCGV_LOW(addr
), TCGV_HIGH(addr
), oi
);
2736 tcg_gen_op3(opc
, tcgv_i32_arg(val
), tcgv_i64_arg(addr
), oi
);
2741 static void gen_ldst_i64(TCGOpcode opc
, TCGv_i64 val
, TCGv addr
,
2742 TCGMemOp memop
, TCGArg idx
)
2744 TCGMemOpIdx oi
= make_memop_idx(memop
, idx
);
2745 #if TARGET_LONG_BITS == 32
2746 if (TCG_TARGET_REG_BITS
== 32) {
2747 tcg_gen_op4i_i32(opc
, TCGV_LOW(val
), TCGV_HIGH(val
), addr
, oi
);
2749 tcg_gen_op3(opc
, tcgv_i64_arg(val
), tcgv_i32_arg(addr
), oi
);
2752 if (TCG_TARGET_REG_BITS
== 32) {
2753 tcg_gen_op5i_i32(opc
, TCGV_LOW(val
), TCGV_HIGH(val
),
2754 TCGV_LOW(addr
), TCGV_HIGH(addr
), oi
);
2756 tcg_gen_op3i_i64(opc
, val
, addr
, oi
);
2761 static void tcg_gen_req_mo(TCGBar type
)
2763 #ifdef TCG_GUEST_DEFAULT_MO
2764 type
&= TCG_GUEST_DEFAULT_MO
;
2766 type
&= ~TCG_TARGET_DEFAULT_MO
;
2768 tcg_gen_mb(type
| TCG_BAR_SC
);
2772 void tcg_gen_qemu_ld_i32(TCGv_i32 val
, TCGv addr
, TCGArg idx
, TCGMemOp memop
)
2774 TCGMemOp orig_memop
;
2776 tcg_gen_req_mo(TCG_MO_LD_LD
| TCG_MO_ST_LD
);
2777 memop
= tcg_canonicalize_memop(memop
, 0, 0);
2778 trace_guest_mem_before_tcg(tcg_ctx
->cpu
, cpu_env
,
2779 addr
, trace_mem_get_info(memop
, 0));
2782 if (!TCG_TARGET_HAS_MEMORY_BSWAP
&& (memop
& MO_BSWAP
)) {
2784 /* The bswap primitive requires zero-extended input. */
2785 if ((memop
& MO_SSIZE
) == MO_SW
) {
2790 gen_ldst_i32(INDEX_op_qemu_ld_i32
, val
, addr
, memop
, idx
);
2792 if ((orig_memop
^ memop
) & MO_BSWAP
) {
2793 switch (orig_memop
& MO_SIZE
) {
2795 tcg_gen_bswap16_i32(val
, val
);
2796 if (orig_memop
& MO_SIGN
) {
2797 tcg_gen_ext16s_i32(val
, val
);
2801 tcg_gen_bswap32_i32(val
, val
);
2804 g_assert_not_reached();
2809 void tcg_gen_qemu_st_i32(TCGv_i32 val
, TCGv addr
, TCGArg idx
, TCGMemOp memop
)
2811 TCGv_i32 swap
= NULL
;
2813 tcg_gen_req_mo(TCG_MO_LD_ST
| TCG_MO_ST_ST
);
2814 memop
= tcg_canonicalize_memop(memop
, 0, 1);
2815 trace_guest_mem_before_tcg(tcg_ctx
->cpu
, cpu_env
,
2816 addr
, trace_mem_get_info(memop
, 1));
2818 if (!TCG_TARGET_HAS_MEMORY_BSWAP
&& (memop
& MO_BSWAP
)) {
2819 swap
= tcg_temp_new_i32();
2820 switch (memop
& MO_SIZE
) {
2822 tcg_gen_ext16u_i32(swap
, val
);
2823 tcg_gen_bswap16_i32(swap
, swap
);
2826 tcg_gen_bswap32_i32(swap
, val
);
2829 g_assert_not_reached();
2835 gen_ldst_i32(INDEX_op_qemu_st_i32
, val
, addr
, memop
, idx
);
2838 tcg_temp_free_i32(swap
);
2842 void tcg_gen_qemu_ld_i64(TCGv_i64 val
, TCGv addr
, TCGArg idx
, TCGMemOp memop
)
2844 TCGMemOp orig_memop
;
2846 if (TCG_TARGET_REG_BITS
== 32 && (memop
& MO_SIZE
) < MO_64
) {
2847 tcg_gen_qemu_ld_i32(TCGV_LOW(val
), addr
, idx
, memop
);
2848 if (memop
& MO_SIGN
) {
2849 tcg_gen_sari_i32(TCGV_HIGH(val
), TCGV_LOW(val
), 31);
2851 tcg_gen_movi_i32(TCGV_HIGH(val
), 0);
2856 tcg_gen_req_mo(TCG_MO_LD_LD
| TCG_MO_ST_LD
);
2857 memop
= tcg_canonicalize_memop(memop
, 1, 0);
2858 trace_guest_mem_before_tcg(tcg_ctx
->cpu
, cpu_env
,
2859 addr
, trace_mem_get_info(memop
, 0));
2862 if (!TCG_TARGET_HAS_MEMORY_BSWAP
&& (memop
& MO_BSWAP
)) {
2864 /* The bswap primitive requires zero-extended input. */
2865 if ((memop
& MO_SIGN
) && (memop
& MO_SIZE
) < MO_64
) {
2870 gen_ldst_i64(INDEX_op_qemu_ld_i64
, val
, addr
, memop
, idx
);
2872 if ((orig_memop
^ memop
) & MO_BSWAP
) {
2873 switch (orig_memop
& MO_SIZE
) {
2875 tcg_gen_bswap16_i64(val
, val
);
2876 if (orig_memop
& MO_SIGN
) {
2877 tcg_gen_ext16s_i64(val
, val
);
2881 tcg_gen_bswap32_i64(val
, val
);
2882 if (orig_memop
& MO_SIGN
) {
2883 tcg_gen_ext32s_i64(val
, val
);
2887 tcg_gen_bswap64_i64(val
, val
);
2890 g_assert_not_reached();
2895 void tcg_gen_qemu_st_i64(TCGv_i64 val
, TCGv addr
, TCGArg idx
, TCGMemOp memop
)
2897 TCGv_i64 swap
= NULL
;
2899 if (TCG_TARGET_REG_BITS
== 32 && (memop
& MO_SIZE
) < MO_64
) {
2900 tcg_gen_qemu_st_i32(TCGV_LOW(val
), addr
, idx
, memop
);
2904 tcg_gen_req_mo(TCG_MO_LD_ST
| TCG_MO_ST_ST
);
2905 memop
= tcg_canonicalize_memop(memop
, 1, 1);
2906 trace_guest_mem_before_tcg(tcg_ctx
->cpu
, cpu_env
,
2907 addr
, trace_mem_get_info(memop
, 1));
2909 if (!TCG_TARGET_HAS_MEMORY_BSWAP
&& (memop
& MO_BSWAP
)) {
2910 swap
= tcg_temp_new_i64();
2911 switch (memop
& MO_SIZE
) {
2913 tcg_gen_ext16u_i64(swap
, val
);
2914 tcg_gen_bswap16_i64(swap
, swap
);
2917 tcg_gen_ext32u_i64(swap
, val
);
2918 tcg_gen_bswap32_i64(swap
, swap
);
2921 tcg_gen_bswap64_i64(swap
, val
);
2924 g_assert_not_reached();
2930 gen_ldst_i64(INDEX_op_qemu_st_i64
, val
, addr
, memop
, idx
);
2933 tcg_temp_free_i64(swap
);
2937 static void tcg_gen_ext_i32(TCGv_i32 ret
, TCGv_i32 val
, TCGMemOp opc
)
2939 switch (opc
& MO_SSIZE
) {
2941 tcg_gen_ext8s_i32(ret
, val
);
2944 tcg_gen_ext8u_i32(ret
, val
);
2947 tcg_gen_ext16s_i32(ret
, val
);
2950 tcg_gen_ext16u_i32(ret
, val
);
2953 tcg_gen_mov_i32(ret
, val
);
2958 static void tcg_gen_ext_i64(TCGv_i64 ret
, TCGv_i64 val
, TCGMemOp opc
)
2960 switch (opc
& MO_SSIZE
) {
2962 tcg_gen_ext8s_i64(ret
, val
);
2965 tcg_gen_ext8u_i64(ret
, val
);
2968 tcg_gen_ext16s_i64(ret
, val
);
2971 tcg_gen_ext16u_i64(ret
, val
);
2974 tcg_gen_ext32s_i64(ret
, val
);
2977 tcg_gen_ext32u_i64(ret
, val
);
2980 tcg_gen_mov_i64(ret
, val
);
2985 #ifdef CONFIG_SOFTMMU
2986 typedef void (*gen_atomic_cx_i32
)(TCGv_i32
, TCGv_env
, TCGv
,
2987 TCGv_i32
, TCGv_i32
, TCGv_i32
);
2988 typedef void (*gen_atomic_cx_i64
)(TCGv_i64
, TCGv_env
, TCGv
,
2989 TCGv_i64
, TCGv_i64
, TCGv_i32
);
2990 typedef void (*gen_atomic_op_i32
)(TCGv_i32
, TCGv_env
, TCGv
,
2991 TCGv_i32
, TCGv_i32
);
2992 typedef void (*gen_atomic_op_i64
)(TCGv_i64
, TCGv_env
, TCGv
,
2993 TCGv_i64
, TCGv_i32
);
2995 typedef void (*gen_atomic_cx_i32
)(TCGv_i32
, TCGv_env
, TCGv
, TCGv_i32
, TCGv_i32
);
2996 typedef void (*gen_atomic_cx_i64
)(TCGv_i64
, TCGv_env
, TCGv
, TCGv_i64
, TCGv_i64
);
2997 typedef void (*gen_atomic_op_i32
)(TCGv_i32
, TCGv_env
, TCGv
, TCGv_i32
);
2998 typedef void (*gen_atomic_op_i64
)(TCGv_i64
, TCGv_env
, TCGv
, TCGv_i64
);
3001 #ifdef CONFIG_ATOMIC64
3002 # define WITH_ATOMIC64(X) X,
3004 # define WITH_ATOMIC64(X)
3007 static void * const table_cmpxchg
[16] = {
3008 [MO_8
] = gen_helper_atomic_cmpxchgb
,
3009 [MO_16
| MO_LE
] = gen_helper_atomic_cmpxchgw_le
,
3010 [MO_16
| MO_BE
] = gen_helper_atomic_cmpxchgw_be
,
3011 [MO_32
| MO_LE
] = gen_helper_atomic_cmpxchgl_le
,
3012 [MO_32
| MO_BE
] = gen_helper_atomic_cmpxchgl_be
,
3013 WITH_ATOMIC64([MO_64
| MO_LE
] = gen_helper_atomic_cmpxchgq_le
)
3014 WITH_ATOMIC64([MO_64
| MO_BE
] = gen_helper_atomic_cmpxchgq_be
)
3017 void tcg_gen_atomic_cmpxchg_i32(TCGv_i32 retv
, TCGv addr
, TCGv_i32 cmpv
,
3018 TCGv_i32 newv
, TCGArg idx
, TCGMemOp memop
)
3020 memop
= tcg_canonicalize_memop(memop
, 0, 0);
3022 if (!(tcg_ctx
->tb_cflags
& CF_PARALLEL
)) {
3023 TCGv_i32 t1
= tcg_temp_new_i32();
3024 TCGv_i32 t2
= tcg_temp_new_i32();
3026 tcg_gen_ext_i32(t2
, cmpv
, memop
& MO_SIZE
);
3028 tcg_gen_qemu_ld_i32(t1
, addr
, idx
, memop
& ~MO_SIGN
);
3029 tcg_gen_movcond_i32(TCG_COND_EQ
, t2
, t1
, t2
, newv
, t1
);
3030 tcg_gen_qemu_st_i32(t2
, addr
, idx
, memop
);
3031 tcg_temp_free_i32(t2
);
3033 if (memop
& MO_SIGN
) {
3034 tcg_gen_ext_i32(retv
, t1
, memop
);
3036 tcg_gen_mov_i32(retv
, t1
);
3038 tcg_temp_free_i32(t1
);
3040 gen_atomic_cx_i32 gen
;
3042 gen
= table_cmpxchg
[memop
& (MO_SIZE
| MO_BSWAP
)];
3043 tcg_debug_assert(gen
!= NULL
);
3045 #ifdef CONFIG_SOFTMMU
3047 TCGv_i32 oi
= tcg_const_i32(make_memop_idx(memop
& ~MO_SIGN
, idx
));
3048 gen(retv
, cpu_env
, addr
, cmpv
, newv
, oi
);
3049 tcg_temp_free_i32(oi
);
3052 gen(retv
, cpu_env
, addr
, cmpv
, newv
);
3055 if (memop
& MO_SIGN
) {
3056 tcg_gen_ext_i32(retv
, retv
, memop
);
3061 void tcg_gen_atomic_cmpxchg_i64(TCGv_i64 retv
, TCGv addr
, TCGv_i64 cmpv
,
3062 TCGv_i64 newv
, TCGArg idx
, TCGMemOp memop
)
3064 memop
= tcg_canonicalize_memop(memop
, 1, 0);
3066 if (!(tcg_ctx
->tb_cflags
& CF_PARALLEL
)) {
3067 TCGv_i64 t1
= tcg_temp_new_i64();
3068 TCGv_i64 t2
= tcg_temp_new_i64();
3070 tcg_gen_ext_i64(t2
, cmpv
, memop
& MO_SIZE
);
3072 tcg_gen_qemu_ld_i64(t1
, addr
, idx
, memop
& ~MO_SIGN
);
3073 tcg_gen_movcond_i64(TCG_COND_EQ
, t2
, t1
, t2
, newv
, t1
);
3074 tcg_gen_qemu_st_i64(t2
, addr
, idx
, memop
);
3075 tcg_temp_free_i64(t2
);
3077 if (memop
& MO_SIGN
) {
3078 tcg_gen_ext_i64(retv
, t1
, memop
);
3080 tcg_gen_mov_i64(retv
, t1
);
3082 tcg_temp_free_i64(t1
);
3083 } else if ((memop
& MO_SIZE
) == MO_64
) {
3084 #ifdef CONFIG_ATOMIC64
3085 gen_atomic_cx_i64 gen
;
3087 gen
= table_cmpxchg
[memop
& (MO_SIZE
| MO_BSWAP
)];
3088 tcg_debug_assert(gen
!= NULL
);
3090 #ifdef CONFIG_SOFTMMU
3092 TCGv_i32 oi
= tcg_const_i32(make_memop_idx(memop
, idx
));
3093 gen(retv
, cpu_env
, addr
, cmpv
, newv
, oi
);
3094 tcg_temp_free_i32(oi
);
3097 gen(retv
, cpu_env
, addr
, cmpv
, newv
);
3100 gen_helper_exit_atomic(cpu_env
);
3101 /* Produce a result, so that we have a well-formed opcode stream
3102 with respect to uses of the result in the (dead) code following. */
3103 tcg_gen_movi_i64(retv
, 0);
3104 #endif /* CONFIG_ATOMIC64 */
3106 TCGv_i32 c32
= tcg_temp_new_i32();
3107 TCGv_i32 n32
= tcg_temp_new_i32();
3108 TCGv_i32 r32
= tcg_temp_new_i32();
3110 tcg_gen_extrl_i64_i32(c32
, cmpv
);
3111 tcg_gen_extrl_i64_i32(n32
, newv
);
3112 tcg_gen_atomic_cmpxchg_i32(r32
, addr
, c32
, n32
, idx
, memop
& ~MO_SIGN
);
3113 tcg_temp_free_i32(c32
);
3114 tcg_temp_free_i32(n32
);
3116 tcg_gen_extu_i32_i64(retv
, r32
);
3117 tcg_temp_free_i32(r32
);
3119 if (memop
& MO_SIGN
) {
3120 tcg_gen_ext_i64(retv
, retv
, memop
);
3125 static void do_nonatomic_op_i32(TCGv_i32 ret
, TCGv addr
, TCGv_i32 val
,
3126 TCGArg idx
, TCGMemOp memop
, bool new_val
,
3127 void (*gen
)(TCGv_i32
, TCGv_i32
, TCGv_i32
))
3129 TCGv_i32 t1
= tcg_temp_new_i32();
3130 TCGv_i32 t2
= tcg_temp_new_i32();
3132 memop
= tcg_canonicalize_memop(memop
, 0, 0);
3134 tcg_gen_qemu_ld_i32(t1
, addr
, idx
, memop
& ~MO_SIGN
);
3136 tcg_gen_qemu_st_i32(t2
, addr
, idx
, memop
);
3138 tcg_gen_ext_i32(ret
, (new_val
? t2
: t1
), memop
);
3139 tcg_temp_free_i32(t1
);
3140 tcg_temp_free_i32(t2
);
3143 static void do_atomic_op_i32(TCGv_i32 ret
, TCGv addr
, TCGv_i32 val
,
3144 TCGArg idx
, TCGMemOp memop
, void * const table
[])
3146 gen_atomic_op_i32 gen
;
3148 memop
= tcg_canonicalize_memop(memop
, 0, 0);
3150 gen
= table
[memop
& (MO_SIZE
| MO_BSWAP
)];
3151 tcg_debug_assert(gen
!= NULL
);
3153 #ifdef CONFIG_SOFTMMU
3155 TCGv_i32 oi
= tcg_const_i32(make_memop_idx(memop
& ~MO_SIGN
, idx
));
3156 gen(ret
, cpu_env
, addr
, val
, oi
);
3157 tcg_temp_free_i32(oi
);
3160 gen(ret
, cpu_env
, addr
, val
);
3163 if (memop
& MO_SIGN
) {
3164 tcg_gen_ext_i32(ret
, ret
, memop
);
3168 static void do_nonatomic_op_i64(TCGv_i64 ret
, TCGv addr
, TCGv_i64 val
,
3169 TCGArg idx
, TCGMemOp memop
, bool new_val
,
3170 void (*gen
)(TCGv_i64
, TCGv_i64
, TCGv_i64
))
3172 TCGv_i64 t1
= tcg_temp_new_i64();
3173 TCGv_i64 t2
= tcg_temp_new_i64();
3175 memop
= tcg_canonicalize_memop(memop
, 1, 0);
3177 tcg_gen_qemu_ld_i64(t1
, addr
, idx
, memop
& ~MO_SIGN
);
3179 tcg_gen_qemu_st_i64(t2
, addr
, idx
, memop
);
3181 tcg_gen_ext_i64(ret
, (new_val
? t2
: t1
), memop
);
3182 tcg_temp_free_i64(t1
);
3183 tcg_temp_free_i64(t2
);
3186 static void do_atomic_op_i64(TCGv_i64 ret
, TCGv addr
, TCGv_i64 val
,
3187 TCGArg idx
, TCGMemOp memop
, void * const table
[])
3189 memop
= tcg_canonicalize_memop(memop
, 1, 0);
3191 if ((memop
& MO_SIZE
) == MO_64
) {
3192 #ifdef CONFIG_ATOMIC64
3193 gen_atomic_op_i64 gen
;
3195 gen
= table
[memop
& (MO_SIZE
| MO_BSWAP
)];
3196 tcg_debug_assert(gen
!= NULL
);
3198 #ifdef CONFIG_SOFTMMU
3200 TCGv_i32 oi
= tcg_const_i32(make_memop_idx(memop
& ~MO_SIGN
, idx
));
3201 gen(ret
, cpu_env
, addr
, val
, oi
);
3202 tcg_temp_free_i32(oi
);
3205 gen(ret
, cpu_env
, addr
, val
);
3208 gen_helper_exit_atomic(cpu_env
);
3209 /* Produce a result, so that we have a well-formed opcode stream
3210 with respect to uses of the result in the (dead) code following. */
3211 tcg_gen_movi_i64(ret
, 0);
3212 #endif /* CONFIG_ATOMIC64 */
3214 TCGv_i32 v32
= tcg_temp_new_i32();
3215 TCGv_i32 r32
= tcg_temp_new_i32();
3217 tcg_gen_extrl_i64_i32(v32
, val
);
3218 do_atomic_op_i32(r32
, addr
, v32
, idx
, memop
& ~MO_SIGN
, table
);
3219 tcg_temp_free_i32(v32
);
3221 tcg_gen_extu_i32_i64(ret
, r32
);
3222 tcg_temp_free_i32(r32
);
3224 if (memop
& MO_SIGN
) {
3225 tcg_gen_ext_i64(ret
, ret
, memop
);
3230 #define GEN_ATOMIC_HELPER(NAME, OP, NEW) \
3231 static void * const table_##NAME[16] = { \
3232 [MO_8] = gen_helper_atomic_##NAME##b, \
3233 [MO_16 | MO_LE] = gen_helper_atomic_##NAME##w_le, \
3234 [MO_16 | MO_BE] = gen_helper_atomic_##NAME##w_be, \
3235 [MO_32 | MO_LE] = gen_helper_atomic_##NAME##l_le, \
3236 [MO_32 | MO_BE] = gen_helper_atomic_##NAME##l_be, \
3237 WITH_ATOMIC64([MO_64 | MO_LE] = gen_helper_atomic_##NAME##q_le) \
3238 WITH_ATOMIC64([MO_64 | MO_BE] = gen_helper_atomic_##NAME##q_be) \
3240 void tcg_gen_atomic_##NAME##_i32 \
3241 (TCGv_i32 ret, TCGv addr, TCGv_i32 val, TCGArg idx, TCGMemOp memop) \
3243 if (tcg_ctx->tb_cflags & CF_PARALLEL) { \
3244 do_atomic_op_i32(ret, addr, val, idx, memop, table_##NAME); \
3246 do_nonatomic_op_i32(ret, addr, val, idx, memop, NEW, \
3247 tcg_gen_##OP##_i32); \
3250 void tcg_gen_atomic_##NAME##_i64 \
3251 (TCGv_i64 ret, TCGv addr, TCGv_i64 val, TCGArg idx, TCGMemOp memop) \
3253 if (tcg_ctx->tb_cflags & CF_PARALLEL) { \
3254 do_atomic_op_i64(ret, addr, val, idx, memop, table_##NAME); \
3256 do_nonatomic_op_i64(ret, addr, val, idx, memop, NEW, \
3257 tcg_gen_##OP##_i64); \
3261 GEN_ATOMIC_HELPER(fetch_add
, add
, 0)
3262 GEN_ATOMIC_HELPER(fetch_and
, and, 0)
3263 GEN_ATOMIC_HELPER(fetch_or
, or, 0)
3264 GEN_ATOMIC_HELPER(fetch_xor
, xor, 0)
3265 GEN_ATOMIC_HELPER(fetch_smin
, smin
, 0)
3266 GEN_ATOMIC_HELPER(fetch_umin
, umin
, 0)
3267 GEN_ATOMIC_HELPER(fetch_smax
, smax
, 0)
3268 GEN_ATOMIC_HELPER(fetch_umax
, umax
, 0)
3270 GEN_ATOMIC_HELPER(add_fetch
, add
, 1)
3271 GEN_ATOMIC_HELPER(and_fetch
, and, 1)
3272 GEN_ATOMIC_HELPER(or_fetch
, or, 1)
3273 GEN_ATOMIC_HELPER(xor_fetch
, xor, 1)
3274 GEN_ATOMIC_HELPER(smin_fetch
, smin
, 1)
3275 GEN_ATOMIC_HELPER(umin_fetch
, umin
, 1)
3276 GEN_ATOMIC_HELPER(smax_fetch
, smax
, 1)
3277 GEN_ATOMIC_HELPER(umax_fetch
, umax
, 1)
3279 static void tcg_gen_mov2_i32(TCGv_i32 r
, TCGv_i32 a
, TCGv_i32 b
)
3281 tcg_gen_mov_i32(r
, b
);
3284 static void tcg_gen_mov2_i64(TCGv_i64 r
, TCGv_i64 a
, TCGv_i64 b
)
3286 tcg_gen_mov_i64(r
, b
);
3289 GEN_ATOMIC_HELPER(xchg
, mov2
, 0)
3291 #undef GEN_ATOMIC_HELPER