[PATCH for-6.2 07/34] target/arm: Fix calculation of LTP mask when LR is 0

Peter Maydell posted 34 patches 4 years, 7 months ago
Maintainers: Peter Maydell <peter.maydell@linaro.org>
[PATCH for-6.2 07/34] target/arm: Fix calculation of LTP mask when LR is 0
Posted by Peter Maydell 4 years, 7 months ago
In mve_element_mask(), we calculate a mask for tail predication which
should have a number of 1 bits based on the value of LR.  However,
our MAKE_64BIT_MASK() macro has undefined behaviour when passed a
zero length.  Special case this to give the all-zeroes mask we
require.

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

diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c
index f17e5a413fd..c75432c5fef 100644
--- a/target/arm/mve_helper.c
+++ b/target/arm/mve_helper.c
@@ -64,7 +64,8 @@ static uint16_t mve_element_mask(CPUARMState *env)
          */
         int masklen = env->regs[14] << env->v7m.ltpsize;
         assert(masklen <= 16);
-        mask &= MAKE_64BIT_MASK(0, masklen);
+        uint16_t ltpmask = masklen ? MAKE_64BIT_MASK(0, masklen) : 0;
+        mask &= ltpmask;
     }
 
     if ((env->condexec_bits & 0xf) == 0) {
-- 
2.20.1


Re: [PATCH for-6.2 07/34] target/arm: Fix calculation of LTP mask when LR is 0
Posted by Richard Henderson 4 years, 6 months ago
On 7/13/21 6:36 AM, Peter Maydell wrote:
> In mve_element_mask(), we calculate a mask for tail predication which
> should have a number of 1 bits based on the value of LR.  However,
> our MAKE_64BIT_MASK() macro has undefined behaviour when passed a
> zero length.  Special case this to give the all-zeroes mask we
> require.
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   target/arm/mve_helper.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)

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

r~