[PATCH for-6.2 05/34] target/arm: Fix mask handling for MVE narrowing operations

Peter Maydell posted 34 patches 4 years, 7 months ago
Maintainers: Peter Maydell <peter.maydell@linaro.org>
[PATCH for-6.2 05/34] target/arm: Fix mask handling for MVE narrowing operations
Posted by Peter Maydell 4 years, 7 months ago
In the MVE helpers for the narrowing operations (DO_VSHRN and
DO_VSHRN_SAT) we were using the wrong bits of the predicate mask for
the 'top' versions of the insn.  This is because the loop works over
the double-sized input elements and shifts the predicate mask by that
many bits each time, but when we write out the half-sized output we
must look at the mask bits for whichever half of the element we are
writing to.

Correct this by shifting the whole mask right by ESIZE bits for the
'top' insns.  This allows us also to simplify the saturation bit
checking (where we had noticed that we needed to look at a different
mask bit for the 'top' insn.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/arm/mve_helper.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c
index 99b4801088f..8cbfd3a8c53 100644
--- a/target/arm/mve_helper.c
+++ b/target/arm/mve_helper.c
@@ -1361,6 +1361,7 @@ DO_VSHLL_ALL(vshllt, true)
         TYPE *d = vd;                                           \
         uint16_t mask = mve_element_mask(env);                  \
         unsigned le;                                            \
+        mask >>= ESIZE * TOP;                                   \
         for (le = 0; le < 16 / LESIZE; le++, mask >>= LESIZE) { \
             TYPE r = FN(m[H##LESIZE(le)], shift);               \
             mergemask(&d[H##ESIZE(le * 2 + TOP)], r, mask);     \
@@ -1422,11 +1423,12 @@ static inline int32_t do_sat_bhs(int64_t val, int64_t min, int64_t max,
         uint16_t mask = mve_element_mask(env);                  \
         bool qc = false;                                        \
         unsigned le;                                            \
+        mask >>= ESIZE * TOP;                                   \
         for (le = 0; le < 16 / LESIZE; le++, mask >>= LESIZE) { \
             bool sat = false;                                   \
             TYPE r = FN(m[H##LESIZE(le)], shift, &sat);         \
             mergemask(&d[H##ESIZE(le * 2 + TOP)], r, mask);     \
-            qc |= sat && (mask & 1 << (TOP * ESIZE));           \
+            qc |= sat & mask & 1;                               \
         }                                                       \
         if (qc) {                                               \
             env->vfp.qc[0] = qc;                                \
-- 
2.20.1


Re: [PATCH for-6.2 05/34] target/arm: Fix mask handling for MVE narrowing operations
Posted by Richard Henderson 4 years, 6 months ago
On 7/13/21 6:36 AM, Peter Maydell wrote:
> In the MVE helpers for the narrowing operations (DO_VSHRN and
> DO_VSHRN_SAT) we were using the wrong bits of the predicate mask for
> the 'top' versions of the insn.  This is because the loop works over
> the double-sized input elements and shifts the predicate mask by that
> many bits each time, but when we write out the half-sized output we
> must look at the mask bits for whichever half of the element we are
> writing to.
> 
> Correct this by shifting the whole mask right by ESIZE bits for the
> 'top' insns.  This allows us also to simplify the saturation bit
> checking (where we had noticed that we needed to look at a different
> mask bit for the 'top' insn.)
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   target/arm/mve_helper.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~