From c9dc750058f17bd21a9b8b0a87853e721dd9471c Mon Sep 17 00:00:00 2001 From: Stephen Long Date: Mon, 1 Mar 2021 18:04:37 -0500 Subject: [PATCH] tcg: Fix tcg gen for vectorized absolute value The fallback inline expansion for vectorized absolute value, when the host doesn't support such an insn was flawed. E.g. when a vector of bytes has all elements negative, mask will be 0xffff_ffff_ffff_ffff. Subtracting mask only adds 1 to the low element instead of all elements becase -mask is 1 and not 0x0101_0101_0101_0101. Backports commit e7e8f33fb603c3bfa0479d7d924f2ad676a84317 --- qemu/tcg/tcg-op-gvec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qemu/tcg/tcg-op-gvec.c b/qemu/tcg/tcg-op-gvec.c index 1fca16aa..1e6ace72 100644 --- a/qemu/tcg/tcg-op-gvec.c +++ b/qemu/tcg/tcg-op-gvec.c @@ -2270,7 +2270,8 @@ static void gen_absv_mask(TCGContext *s, TCGv_i64 d, TCGv_i64 b, unsigned vece) * so we never have carry into the next element. */ tcg_gen_xor_i64(s, d, b, t); - tcg_gen_sub_i64(s, d, d, t); + tcg_gen_andi_i64(s, t, t, dup_const(vece, 1)); + tcg_gen_add_i64(s, d, d, t); tcg_temp_free_i64(s, t); }