From patchwork Tue May 25 15:06:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 447290 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp4413259jac; Tue, 25 May 2021 09:11:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwE5Ip1Ijljuc3H2Mh/lu8sBSZV4VWh8/c7jS8Iq4cwzjNWMSv7g9QEihzBsRYRYiIk6xPH X-Received: by 2002:a7b:c3d4:: with SMTP id t20mr24001579wmj.13.1621959085091; Tue, 25 May 2021 09:11:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621959085; cv=none; d=google.com; s=arc-20160816; b=UjKquE4MZOLYLAYrbxGIIBbIWBr8cJFGE2hnjSe4zJX7H/6pIHYEfEelS8/oLmKukz lyoOBc5jH1SajmuDKsVBQyUTnmXFeIDYEyGsasRPPk8D88j2ZFDqdJ8nk8Oks0vtwPlC y46t0D1BHVb7U31QAdKBPenakRo3LStsdCjpVnFsNcNNz6HhwIE5uwHkfh53TE5T/Oo1 QcPFsBH+FDStAX639ugWN+JD4iPOLepTzzCITJ20kGqRVsAn6JKCZiGKXQfwQybQtBGX jldACRxIaTynNSe6A9ech9ukikzwX4tgh0PqPz3ib64W8DJSGyWNo/E4biJtGOKaUUtm JihQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=hRoARebbIM30+5QjLTpQyHKZOtTassCJ5Yf1wssASeE=; b=M9XFDxnXe0YWFUf3898Q90NLu9HrxQTh5QfcvK1UpOpm3ftff1cTv0yyinMzH4nVSu nrXoDkFBkANb2MwVt1Z9fLHaoVA3p2/aTabKQQBR5y4RAWZrBYZfl886ORYIjcNND3bM bNcNZOujNZaEKjFtOHoc+DmWHH2Q9P12KxsnRBtCg/KSR4Ljut+gNZ/47IbeTJTkDKkA s521xFJCup+3oPoz7hw1nWjnXh3drg7uSSiaaN/ev+r3sfwP9y8KUGGBDL/X1I2yzPPp 9qOr3gLIQBWoi+x5i0mghnlMKPyUKkpmTLnGj5QE+f8NXak9B5uS61TZ4Pwdj76CZreE H4MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="bAAI/GPx"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y15si14086223ejw.484.2021.05.25.09.11.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 May 2021 09:11:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="bAAI/GPx"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llZeN-00028E-Tr for patch@linaro.org; Tue, 25 May 2021 12:11:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llYeR-0001go-Mj for qemu-devel@nongnu.org; Tue, 25 May 2021 11:07:23 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:42880) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1llYeK-0006go-3m for qemu-devel@nongnu.org; Tue, 25 May 2021 11:07:23 -0400 Received: by mail-pl1-x62c.google.com with SMTP id v13so16483479ple.9 for ; Tue, 25 May 2021 08:07:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hRoARebbIM30+5QjLTpQyHKZOtTassCJ5Yf1wssASeE=; b=bAAI/GPx7i7Cv+CE5CxC9LxUX8N/E9378LDG81oB7pd0dn6kFP9IgLTvbi4s07JwSj vsPsfGa2d6M4jK8m03e/rp9DqUeeMGD8houhXP7CEzFiSi0yJWx0CNVyGnZS7R9tyWhG ITxNpt98GmxRLuHw7yHjXWtqnh5Q+pchncHNl9MkMWDEaGJApXbbwdzyQOV97h+v1Qx3 +TTU0IAqxFeMxxZvT92zD5cpeLY7eajYxMSvZrtBkizxjrCq4bBLeHLlj+o0v9QneW5n iSXJ6ogjIKQuxn+pp+Qmp5wA0jC1K0J+iTvVEP958vul+g88/L3+yJ9vwkwOSNPhPwRG pdDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hRoARebbIM30+5QjLTpQyHKZOtTassCJ5Yf1wssASeE=; b=EF6M0D/IgvNpJhoSgZG/Efwtm/S5YuOt0x5OB65gk9WEGZxPjWJlIfZh47PBpp9OLF C0U/tUDdU8N/lQZ63iGneb1nduHsy8iEaI7SQvsvQsCTTDDAWFKfG309BSqQRHgUuMJ0 PNzAOOuE/KwyxBX2N80kA477VLnXJ6uQ5b0/BhKJ228flm2Nyrkk9su9KTVS/1W4Z5rL cRKdgljfcL2qFoBcTM6/KM7+12EKYCGLN2xKuN9hztMmfqc5lmn0kIefEduFO55gXKuW jUI9Akqvl4S2WMytb80qxtV2g+VEHxg/mqy07JcWVJ1sSe1megZQQwTC6lEU57BZelih UE3Q== X-Gm-Message-State: AOAM533RmKfrBd0yvYugfS/eR+umS3YNrGTFHlewqrfYOlGZSvMVe4VJ R9JpWqVJ7NMtC7hZPJnPWM+5BGF+sepkoQ== X-Received: by 2002:a17:90a:4a89:: with SMTP id f9mr5324280pjh.50.1621955234822; Tue, 25 May 2021 08:07:14 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id z19sm2231943pjq.11.2021.05.25.08.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 08:07:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 11/28] softfloat: Adjust parts_uncanon_normal for floatx80 Date: Tue, 25 May 2021 08:06:49 -0700 Message-Id: <20210525150706.294968-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210525150706.294968-1-richard.henderson@linaro.org> References: <20210525150706.294968-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.bennee@linaro.org, david@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" With floatx80_precision_x, the rounding happens across the break between words. Notice this case with frac_lsb = round_mask + 1 -> 0 and check the bits in frac_hi as needed. In addition, since frac_shift == 0, we won't implicitly clear round_mask via the right-shift, so explicitly clear those bits. This fixes rounding for floatx80_precision_[sd]. Signed-off-by: Richard Henderson --- fpu/softfloat-parts.c.inc | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) -- 2.25.1 Reviewed-by: Alex Bennée diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index b456c1c30c..8a7f22d6b5 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -156,7 +156,13 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s, switch (s->float_rounding_mode) { case float_round_nearest_even: overflow_norm = false; - inc = ((p->frac_lo & roundeven_mask) != frac_lsbm1 ? frac_lsbm1 : 0); + if (N > 64 && frac_lsb == 0) { + inc = ((p->frac_hi & 1) || (p->frac_lo & round_mask) != frac_lsbm1 + ? frac_lsbm1 : 0); + } else { + inc = ((p->frac_lo & roundeven_mask) != frac_lsbm1 + ? frac_lsbm1 : 0); + } break; case float_round_ties_away: overflow_norm = false; @@ -176,7 +182,11 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s, break; case float_round_to_odd: overflow_norm = true; - inc = p->frac_lo & frac_lsb ? 0 : round_mask; + if (N > 64 && frac_lsb == 0) { + inc = p->frac_hi & 1 ? 0 : round_mask; + } else { + inc = p->frac_lo & frac_lsb ? 0 : round_mask; + } break; default: g_assert_not_reached(); @@ -191,8 +201,8 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s, p->frac_hi |= DECOMPOSED_IMPLICIT_BIT; exp++; } + p->frac_lo &= ~round_mask; } - frac_shr(p, frac_shift); if (fmt->arm_althp) { /* ARM Alt HP eschews Inf and NaN for a wider exponent. */ @@ -201,18 +211,21 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s, flags = float_flag_invalid; exp = exp_max; frac_allones(p); + p->frac_lo &= ~round_mask; } } else if (unlikely(exp >= exp_max)) { flags |= float_flag_overflow | float_flag_inexact; if (overflow_norm) { exp = exp_max - 1; frac_allones(p); + p->frac_lo &= ~round_mask; } else { p->cls = float_class_inf; exp = exp_max; frac_clear(p); } } + frac_shr(p, frac_shift); } else if (s->flush_to_zero) { flags |= float_flag_output_denormal; p->cls = float_class_zero; @@ -232,17 +245,28 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s, /* Need to recompute round-to-even/round-to-odd. */ switch (s->float_rounding_mode) { case float_round_nearest_even: - inc = ((p->frac_lo & roundeven_mask) != frac_lsbm1 - ? frac_lsbm1 : 0); + if (N > 64 && frac_lsb == 0) { + inc = ((p->frac_hi & 1) || + (p->frac_lo & round_mask) != frac_lsbm1 + ? frac_lsbm1 : 0); + } else { + inc = ((p->frac_lo & roundeven_mask) != frac_lsbm1 + ? frac_lsbm1 : 0); + } break; case float_round_to_odd: - inc = p->frac_lo & frac_lsb ? 0 : round_mask; + if (N > 64 && frac_lsb == 0) { + inc = p->frac_hi & 1 ? 0 : round_mask; + } else { + inc = p->frac_lo & frac_lsb ? 0 : round_mask; + } break; default: break; } flags |= float_flag_inexact; frac_addi(p, p, inc); + p->frac_lo &= ~round_mask; } exp = (p->frac_hi & DECOMPOSED_IMPLICIT_BIT) != 0;