From nobody Sun Apr 28 04:40:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523933733792192.84645183238797; Mon, 16 Apr 2018 19:55:33 -0700 (PDT) Received: from localhost ([::1]:34591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8GmC-0005SW-7a for importer@patchew.org; Mon, 16 Apr 2018 22:55:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8GkT-0004RH-UP for qemu-devel@nongnu.org; Mon, 16 Apr 2018 22:53:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8GkS-0007ab-CT for qemu-devel@nongnu.org; Mon, 16 Apr 2018 22:53:38 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:42579) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f8GkS-0007Z8-6p for qemu-devel@nongnu.org; Mon, 16 Apr 2018 22:53:36 -0400 Received: by mail-pf0-x241.google.com with SMTP id o16so11458307pfk.9 for ; Mon, 16 Apr 2018 19:53:36 -0700 (PDT) Received: from cloudburst.ASUS (cpe-66-75-76-48.hawaii.res.rr.com. [66.75.76.48]) by smtp.gmail.com with ESMTPSA id v63sm31759876pfk.8.2018.04.16.19.53.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Apr 2018 19:53:33 -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=aIrJdcd3Rlf4G6pjMgn7JXWzwVirCr0wwO7ntLRq2WM=; b=dgHUzS5GGx0qQUhjEXa8DHbd6K/HAftMqAVFeGuqMEEllJHHvECngeFEI2+eA65Ezo zCs0gWmuP9quULFJV0k/NXE/uqpZdBS21VA7izKrXjzrFJqvxOg/pYJ8inFpB9TnDm2s 6wziB2HRtpqP/9EzMvQVRFQl3S7kAjHyqtUYY= 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=aIrJdcd3Rlf4G6pjMgn7JXWzwVirCr0wwO7ntLRq2WM=; b=YtHEFy2rTCB99R732kZasAWQLfJky3kUh7c47/3AXdlCVi3ybDP5qG90vrjksrVGuW 0VbqzP4CTI2lvWS7HC+BnpCBTWYDLGSQIS7ZvCc0FxXIVDcJ/00gdPniok47jRAr1gQP Xu2DFnYOtFwx/hiCHjwZ5P88d5is3z85qgt7RzguBpQTPXx/4IcY8uQIpXZZuMeONppA HeGXZYYrJct7oLzl4Bz9CQIBakAj35QZeAt3OKn0JSjrA45xEH8Gyj9p5ykDtBD49eYi mMp593jODfXMf3ybSqzH/nPn4gjht+kCuJD7mxuoIUL7+Quclaj/UD3M1JX+/E190OAF 3epw== X-Gm-Message-State: ALQs6tAZrKjgPpQau0YFBbUWEZAy1Gwjsk789zUx0pPXJWT7t9tDlG0V lAge8JB2VbmnPg6U+B6wmL0sQQ5bXoY= X-Google-Smtp-Source: AIpwx484OswHEnyMXDERVjQoK8IyytqFqD1VFTz7x/XetQQ5gAsX+abC4RMSPg23VMsQD6p7qhYdgw== X-Received: by 10.99.147.20 with SMTP id b20mr272635pge.309.1523933614832; Mon, 16 Apr 2018 19:53:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 16 Apr 2018 16:53:27 -1000 Message-Id: <20180417025328.25431-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180417025328.25431-1-richard.henderson@linaro.org> References: <20180417025328.25431-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PATCH 1/2] fpu: Check for inf/x before x/0 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, alex.bennee@linaro.org, Bastian Koppelmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 The re-factoring of div_floats changed the order of checking meaning an operation like -inf/0 erroneously raises the divbyzero flag. IEEE-754 (2008) specifies this should only occur for operations on finite operands. We fix this by moving the check on the dividend being Inf/0 to before the divisor is zero check. Cc: Bastian Koppelmann Cc: Alex Benn=C3=A9e Cc: Peter Maydell Signed-off-by: Richard Henderson --- fpu/softfloat.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index fb8663f59e..ba6e654050 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1146,15 +1146,20 @@ static FloatParts div_floats(FloatParts a, FloatPar= ts b, float_status *s) a.cls =3D float_class_dnan; return a; } - /* Div 0 =3D> Inf */ + /* Inf / x */ + if (a.cls =3D=3D float_class_inf) { + a.sign =3D sign; + return a; + } + /* x / 0 =3D> Inf */ if (b.cls =3D=3D float_class_zero) { s->float_exception_flags |=3D float_flag_divbyzero; a.cls =3D float_class_inf; a.sign =3D sign; return a; } - /* Inf / x or 0 / x */ - if (a.cls =3D=3D float_class_inf || a.cls =3D=3D float_class_zero) { + /* 0 / x */ + if (a.cls =3D=3D float_class_zero) { a.sign =3D sign; return a; } --=20 2.14.3 From nobody Sun Apr 28 04:40:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1523933733747563.2940955385847; Mon, 16 Apr 2018 19:55:33 -0700 (PDT) Received: from localhost ([::1]:34593 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8GmC-0005Sx-9p for importer@patchew.org; Mon, 16 Apr 2018 22:55:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8GkU-0004RR-V4 for qemu-devel@nongnu.org; Mon, 16 Apr 2018 22:53:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8GkU-0007eC-8a for qemu-devel@nongnu.org; Mon, 16 Apr 2018 22:53:39 -0400 Received: from mail-pl0-x242.google.com ([2607:f8b0:400e:c01::242]:38657) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f8GkU-0007cr-2H for qemu-devel@nongnu.org; Mon, 16 Apr 2018 22:53:38 -0400 Received: by mail-pl0-x242.google.com with SMTP id c7-v6so11156769plr.5 for ; Mon, 16 Apr 2018 19:53:37 -0700 (PDT) Received: from cloudburst.ASUS (cpe-66-75-76-48.hawaii.res.rr.com. [66.75.76.48]) by smtp.gmail.com with ESMTPSA id v63sm31759876pfk.8.2018.04.16.19.53.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Apr 2018 19:53:36 -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; bh=t5V/IQAptYx23oK2IFpQU6J5Ud1YBq6Pkr09Y/TjDyg=; b=hGo8kSMRa0rVAqpDDW5WCTIblTmdQDWfyVGo9XgOEpm+Sp/ftgZ55x9mNdjnaPIS7l y/MQbebyfrUMGyal5juzCdEKdwpIfQWLUjyx2HJy1YpBpUrDOTimYxWZGX2f3dpN7kAX 7KGjfNcAZUlmAY3FZwUjB/xnPt8ewSxIE7wqI= 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; bh=t5V/IQAptYx23oK2IFpQU6J5Ud1YBq6Pkr09Y/TjDyg=; b=mZul+sHIrXlHAT12g8atj9jPzter/gCg/L5bLiTROwI7TMIpi90tx++q9vP/n3ZLOl tJ+oJ7bzPlxbY4AMSnC8BDieJlt9G2APRHD8Yr0EL0CPs0J2qxQ134h7S5hpH1F4XprI 21ha1ro6MpGkpt4IPv9tZUDtxcm5450Y9K/S2IM9eoAwKMJqhxKWjQ+YIURbYVQJcMLI RR/L2mTtnovMNgCci4/OqpnfYtPBf8jPpM/K5zS5QYRV6oGFwPYns/bvS2d65njCJCaM /yT2XHdWLIKMC/bLY/29voGY/mHgomhoG3VvAsHPCO5w632/EW5JoSLUxsg7wqJz2eBc /lLw== X-Gm-Message-State: ALQs6tBq8itWw8DA4NVqGLMnWCbtk6y3unO+RRuwYGJax3ktz7HqFf7q BCRWBFN2cL/6DcQHWJnWXGLiRZpw8Ns= X-Google-Smtp-Source: AIpwx49HGYhCQGId9Vw9uHPbJ0GlEa9QvwSjLVVCZ5ePdAcEnGk2Ln21ktJ1gDi/un0MVzIUB1c3kA== X-Received: by 2002:a17:902:9303:: with SMTP id bc3-v6mr348900plb.18.1523933616779; Mon, 16 Apr 2018 19:53:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 16 Apr 2018 16:53:28 -1000 Message-Id: <20180417025328.25431-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180417025328.25431-1-richard.henderson@linaro.org> References: <20180417025328.25431-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::242 Subject: [Qemu-devel] [PATCH 2/2] fpu: Bound increment for scalbn X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Without bounding the increment, we can overflow exp either here in scalbn_decomposed or when adding the bias in round_canonical. This can result in e.g. underflowing to 0 instead of overflowing to infinity. The old softfloat code did bound the increment. Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Peter Maydell Tested-by: Alex Benn=C3=A9e --- fpu/softfloat.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index ba6e654050..a589f328c9 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1883,6 +1883,12 @@ static FloatParts scalbn_decomposed(FloatParts a, in= t n, float_status *s) return return_nan(a, s); } if (a.cls =3D=3D float_class_normal) { + /* The largest float type (even though not supported by FloatParts) + * is float128, which has a 15 bit exponent. Bounding N to 16 bits + * still allows rounding to infinity, without allowing overflow + * within the int32_t that backs FloatParts.exp. + */ + n =3D MIN(MAX(n, -0x10000), 0x10000); a.exp +=3D n; } return a; --=20 2.14.3