From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYpQU-0006Xl-4M for qemu-devel@nongnu.org; Fri, 29 Jun 2018 05:10:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYpQS-0006VE-VD for qemu-devel@nongnu.org; Fri, 29 Jun 2018 05:10:46 -0400 Received: from mail-ot0-x242.google.com ([2607:f8b0:4003:c0f::242]:38609) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYpQS-0006Tr-PO for qemu-devel@nongnu.org; Fri, 29 Jun 2018 05:10:44 -0400 Received: by mail-ot0-x242.google.com with SMTP id w22-v6so9215588otk.5 for ; Fri, 29 Jun 2018 02:10:44 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <20180629001538.11415-1-richard.henderson@linaro.org> <20180629001538.11415-2-richard.henderson@linaro.org> From: Peter Maydell Date: Fri, 29 Jun 2018 10:10:23 +0100 Message-ID: Content-Type: text/plain; charset="UTF-8" Subject: Re: [Qemu-devel] [PATCH 1/6] target/arm: Fix SVE signed division vs x86 overflow exception List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson Cc: QEMU Developers On 29 June 2018 at 09:29, Peter Maydell wrote: > On 29 June 2018 at 01:15, Richard Henderson > wrote: >> We already check for the same condition within the normal integer >> sdiv and sdiv64 helpers. Use a slightly different formation that >> does not require deducing the expression type. >> >> Fixes: f97cfd596ed >> Signed-off-by: Richard Henderson >> --- >> target/arm/sve_helper.c | 16 +++++++++++----- >> 1 file changed, 11 insertions(+), 5 deletions(-) >> >> diff --git a/target/arm/sve_helper.c b/target/arm/sve_helper.c >> index 790cbacd14..7d7fc90566 100644 >> --- a/target/arm/sve_helper.c >> +++ b/target/arm/sve_helper.c >> @@ -369,7 +369,13 @@ void HELPER(NAME)(void *vd, void *vn, void *vm, void *vg, uint32_t desc) \ >> #define DO_MIN(N, M) ((N) >= (M) ? (M) : (N)) >> #define DO_ABD(N, M) ((N) >= (M) ? (N) - (M) : (M) - (N)) >> #define DO_MUL(N, M) (N * M) >> -#define DO_DIV(N, M) (M ? N / M : 0) >> + >> +/* The zero divisor case is architectural; the -1 divisor case works >> + * around the x86 INT_MIN / -1 overflow exception without having to >> + * deduce the minimum integer for the type of the expression. >> + */ > > It works around INT_MIN / -1 being C undefined behaviour: the > need to special-case this is not x86-specific... The required > answer for Arm is just as architectural as the required answer > for division-by-zero (which is also C UB). Suggested revised comment text: /* We must avoid the C undefined behaviour cases: division by * zero and signed division of INT_MIN by -1. Both of these * have architecturally defined required results for Arm. * We special case all signed divisions by -1 to avoid having * to deduce the minimum integer for the type involved. */ ? thanks -- PMM