tcg: Merge INDEX_op_bswap16_{i32,i64}

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2025-01-10 18:51:16 -08:00
parent 5fa8e13872
commit 0dd07ee112
7 changed files with 15 additions and 21 deletions

View file

@ -415,7 +415,7 @@ Misc
- | *t0* = *t1* - | *t0* = *t1*
| Move *t1* to *t0*. | Move *t1* to *t0*.
* - bswap16_i32/i64 *t0*, *t1*, *flags* * - bswap16 *t0*, *t1*, *flags*
- | 16 bit byte swap on the low bits of a 32/64 bit input. - | 16 bit byte swap on the low bits of a 32/64 bit input.
| |

View file

@ -43,6 +43,7 @@ DEF(mov, 1, 1, 0, TCG_OPF_INT | TCG_OPF_NOT_PRESENT)
DEF(add, 1, 2, 0, TCG_OPF_INT) DEF(add, 1, 2, 0, TCG_OPF_INT)
DEF(and, 1, 2, 0, TCG_OPF_INT) DEF(and, 1, 2, 0, TCG_OPF_INT)
DEF(andc, 1, 2, 0, TCG_OPF_INT) DEF(andc, 1, 2, 0, TCG_OPF_INT)
DEF(bswap16, 1, 1, 1, TCG_OPF_INT)
DEF(clz, 1, 2, 0, TCG_OPF_INT) DEF(clz, 1, 2, 0, TCG_OPF_INT)
DEF(ctpop, 1, 1, 0, TCG_OPF_INT) DEF(ctpop, 1, 1, 0, TCG_OPF_INT)
DEF(ctz, 1, 2, 0, TCG_OPF_INT) DEF(ctz, 1, 2, 0, TCG_OPF_INT)
@ -95,7 +96,6 @@ DEF(sub2_i32, 2, 4, 0, 0)
DEF(brcond2_i32, 0, 4, 2, TCG_OPF_BB_END | TCG_OPF_COND_BRANCH) DEF(brcond2_i32, 0, 4, 2, TCG_OPF_BB_END | TCG_OPF_COND_BRANCH)
DEF(setcond2_i32, 1, 4, 1, 0) DEF(setcond2_i32, 1, 4, 1, 0)
DEF(bswap16_i32, 1, 1, 1, 0)
DEF(bswap32_i32, 1, 1, 1, 0) DEF(bswap32_i32, 1, 1, 1, 0)
/* load/store */ /* load/store */
@ -122,7 +122,6 @@ DEF(extu_i32_i64, 1, 1, 0, 0)
DEF(extrl_i64_i32, 1, 1, 0, 0) DEF(extrl_i64_i32, 1, 1, 0, 0)
DEF(extrh_i64_i32, 1, 1, 0, 0) DEF(extrh_i64_i32, 1, 1, 0, 0)
DEF(bswap16_i64, 1, 1, 1, 0)
DEF(bswap32_i64, 1, 1, 1, 0) DEF(bswap32_i64, 1, 1, 1, 0)
DEF(bswap64_i64, 1, 1, 1, 0) DEF(bswap64_i64, 1, 1, 1, 0)

View file

@ -518,7 +518,7 @@ static uint64_t do_constant_folding_2(TCGOpcode op, TCGType type,
case INDEX_op_ctpop: case INDEX_op_ctpop:
return type == TCG_TYPE_I32 ? ctpop32(x) : ctpop64(x); return type == TCG_TYPE_I32 ? ctpop32(x) : ctpop64(x);
CASE_OP_32_64(bswap16): case INDEX_op_bswap16:
x = bswap16(x); x = bswap16(x);
return y & TCG_BSWAP_OS ? (int16_t)x : x; return y & TCG_BSWAP_OS ? (int16_t)x : x;
@ -1572,8 +1572,7 @@ static bool fold_bswap(OptContext *ctx, TCGOp *op)
z_mask = t1->z_mask; z_mask = t1->z_mask;
switch (op->opc) { switch (op->opc) {
case INDEX_op_bswap16_i32: case INDEX_op_bswap16:
case INDEX_op_bswap16_i64:
z_mask = bswap16(z_mask); z_mask = bswap16(z_mask);
sign = INT16_MIN; sign = INT16_MIN;
break; break;
@ -2870,7 +2869,7 @@ void tcg_optimize(TCGContext *s)
case INDEX_op_brcond2_i32: case INDEX_op_brcond2_i32:
done = fold_brcond2(&ctx, op); done = fold_brcond2(&ctx, op);
break; break;
CASE_OP_32_64(bswap16): case INDEX_op_bswap16:
CASE_OP_32_64(bswap32): CASE_OP_32_64(bswap32):
case INDEX_op_bswap64_i64: case INDEX_op_bswap64_i64:
done = fold_bswap(&ctx, op); done = fold_bswap(&ctx, op);

View file

@ -1257,8 +1257,8 @@ void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags)
/* Only one extension flag may be present. */ /* Only one extension flag may be present. */
tcg_debug_assert(!(flags & TCG_BSWAP_OS) || !(flags & TCG_BSWAP_OZ)); tcg_debug_assert(!(flags & TCG_BSWAP_OS) || !(flags & TCG_BSWAP_OZ));
if (tcg_op_supported(INDEX_op_bswap16_i32, TCG_TYPE_I32, 0)) { if (tcg_op_supported(INDEX_op_bswap16, TCG_TYPE_I32, 0)) {
tcg_gen_op3i_i32(INDEX_op_bswap16_i32, ret, arg, flags); tcg_gen_op3i_i32(INDEX_op_bswap16, ret, arg, flags);
} else { } else {
TCGv_i32 t0 = tcg_temp_ebb_new_i32(); TCGv_i32 t0 = tcg_temp_ebb_new_i32();
TCGv_i32 t1 = tcg_temp_ebb_new_i32(); TCGv_i32 t1 = tcg_temp_ebb_new_i32();
@ -2087,8 +2087,8 @@ void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg, int flags)
} else { } else {
tcg_gen_movi_i32(TCGV_HIGH(ret), 0); tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
} }
} else if (tcg_op_supported(INDEX_op_bswap16_i64, TCG_TYPE_I64, 0)) { } else if (tcg_op_supported(INDEX_op_bswap16, TCG_TYPE_I64, 0)) {
tcg_gen_op3i_i64(INDEX_op_bswap16_i64, ret, arg, flags); tcg_gen_op3i_i64(INDEX_op_bswap16, ret, arg, flags);
} else { } else {
TCGv_i64 t0 = tcg_temp_ebb_new_i64(); TCGv_i64 t0 = tcg_temp_ebb_new_i64();
TCGv_i64 t1 = tcg_temp_ebb_new_i64(); TCGv_i64 t1 = tcg_temp_ebb_new_i64();

View file

@ -1075,8 +1075,7 @@ static const TCGOutOp * const all_outop[NB_OPS] = {
OUTOP(INDEX_op_and, TCGOutOpBinary, outop_and), OUTOP(INDEX_op_and, TCGOutOpBinary, outop_and),
OUTOP(INDEX_op_andc, TCGOutOpBinary, outop_andc), OUTOP(INDEX_op_andc, TCGOutOpBinary, outop_andc),
OUTOP(INDEX_op_brcond, TCGOutOpBrcond, outop_brcond), OUTOP(INDEX_op_brcond, TCGOutOpBrcond, outop_brcond),
OUTOP(INDEX_op_bswap16_i32, TCGOutOpBswap, outop_bswap16), OUTOP(INDEX_op_bswap16, TCGOutOpBswap, outop_bswap16),
OUTOP(INDEX_op_bswap16_i64, TCGOutOpBswap, outop_bswap16),
OUTOP(INDEX_op_clz, TCGOutOpBinary, outop_clz), OUTOP(INDEX_op_clz, TCGOutOpBinary, outop_clz),
OUTOP(INDEX_op_ctpop, TCGOutOpUnary, outop_ctpop), OUTOP(INDEX_op_ctpop, TCGOutOpUnary, outop_ctpop),
OUTOP(INDEX_op_ctz, TCGOutOpBinary, outop_ctz), OUTOP(INDEX_op_ctz, TCGOutOpBinary, outop_ctz),
@ -2941,8 +2940,7 @@ void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs)
i = 1; i = 1;
} }
break; break;
case INDEX_op_bswap16_i32: case INDEX_op_bswap16:
case INDEX_op_bswap16_i64:
case INDEX_op_bswap32_i32: case INDEX_op_bswap32_i32:
case INDEX_op_bswap32_i64: case INDEX_op_bswap32_i64:
case INDEX_op_bswap64_i64: case INDEX_op_bswap64_i64:
@ -5489,8 +5487,7 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)
} }
break; break;
case INDEX_op_bswap16_i32: case INDEX_op_bswap16:
case INDEX_op_bswap16_i64:
{ {
const TCGOutOpBswap *out = const TCGOutOpBswap *out =
container_of(all_outop[op->opc], TCGOutOpBswap, base); container_of(all_outop[op->opc], TCGOutOpBswap, base);

View file

@ -686,7 +686,7 @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env,
tci_write_reg64(regs, r1, r0, T1 - T2); tci_write_reg64(regs, r1, r0, T1 - T2);
break; break;
#endif #endif
CASE_32_64(bswap16) case INDEX_op_bswap16:
tci_args_rr(insn, &r0, &r1); tci_args_rr(insn, &r0, &r1);
regs[r0] = bswap16(regs[r1]); regs[r0] = bswap16(regs[r1]);
break; break;
@ -1005,14 +1005,13 @@ int print_insn_tci(bfd_vma addr, disassemble_info *info)
op_name, str_r(r0), str_r(r1), s2); op_name, str_r(r0), str_r(r1), s2);
break; break;
case INDEX_op_bswap16:
case INDEX_op_ctpop: case INDEX_op_ctpop:
case INDEX_op_mov: case INDEX_op_mov:
case INDEX_op_neg: case INDEX_op_neg:
case INDEX_op_not: case INDEX_op_not:
case INDEX_op_ext_i32_i64: case INDEX_op_ext_i32_i64:
case INDEX_op_extu_i32_i64: case INDEX_op_extu_i32_i64:
case INDEX_op_bswap16_i32:
case INDEX_op_bswap16_i64:
case INDEX_op_bswap32_i32: case INDEX_op_bswap32_i32:
case INDEX_op_bswap32_i64: case INDEX_op_bswap32_i64:
case INDEX_op_bswap64_i64: case INDEX_op_bswap64_i64:

View file

@ -905,7 +905,7 @@ static const TCGOutOpUnary outop_ctpop = {
static void tgen_bswap16(TCGContext *s, TCGType type, static void tgen_bswap16(TCGContext *s, TCGType type,
TCGReg a0, TCGReg a1, unsigned flags) TCGReg a0, TCGReg a1, unsigned flags)
{ {
tcg_out_op_rr(s, INDEX_op_bswap16_i32, a0, a1); tcg_out_op_rr(s, INDEX_op_bswap16, a0, a1);
if (flags & TCG_BSWAP_OS) { if (flags & TCG_BSWAP_OS) {
tcg_out_sextract(s, TCG_TYPE_REG, a0, a0, 0, 16); tcg_out_sextract(s, TCG_TYPE_REG, a0, a0, 0, 16);
} }