]> git.proxmox.com Git - mirror_qemu.git/commitdiff
tcg: Fix tcg gen for vectorized absolute value
authorStephen Long <steplong@quicinc.com>
Thu, 13 Aug 2020 16:18:18 +0000 (09:18 -0700)
committerRichard Henderson <richard.henderson@linaro.org>
Thu, 3 Sep 2020 20:13:58 +0000 (13:13 -0700)
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.

Signed-off-by: Stephen Long <steplong@quicinc.com>
Message-Id: <20200813161818.190-1-steplong@quicinc.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
tcg/tcg-op-gvec.c

index 3707c0effbcb445ed056b41a416220b03ae40b21..793d4ba64c3282b1c457e404ec99cf396d74693e 100644 (file)
@@ -2264,12 +2264,13 @@ static void gen_absv_mask(TCGv_i64 d, TCGv_i64 b, unsigned vece)
     tcg_gen_muli_i64(t, t, (1 << nbit) - 1);
 
     /*
-     * Invert (via xor -1) and add one (via sub -1).
+     * Invert (via xor -1) and add one.
      * Because of the ordering the msb is cleared,
      * so we never have carry into the next element.
      */
     tcg_gen_xor_i64(d, b, t);
-    tcg_gen_sub_i64(d, d, t);
+    tcg_gen_andi_i64(t, t, dup_const(vece, 1));
+    tcg_gen_add_i64(d, d, t);
 
     tcg_temp_free_i64(t);
 }