From patchwork Tue Apr 17 02:53:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 133501 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp4234505ljb; Mon, 16 Apr 2018 19:54:02 -0700 (PDT) X-Google-Smtp-Source: AIpwx48P/aGbxrwaw9eGtpItj3wCSyaovn7bMH0OVg9VtZMrARG4Udo0M7t7O2pZyyQ1wlfmzwPF X-Received: by 10.55.164.136 with SMTP id n130mr382237qke.13.1523933642501; Mon, 16 Apr 2018 19:54:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523933642; cv=none; d=google.com; s=arc-20160816; b=BQeooNCzofgojyH0I9AXJi4kevF4T5gazIgnBIWmtqyWEllZM62li6Nac84GnSKcgd YmlIkzP5CjrviBXB/+f3+QxQ95bf8o6lvmbPVjFdmTMjmYBFFpXRc8E8RQU3654RU4t+ JWdWVnwoRXXd5xuW+n8BaFYDglH1p3PxkhJL9VMRByVcXIe7ifLyrbv864nw7nXzIM/o XzFcH/4Xf1Zmvkxl+s02zBVHj6EEsS29D0y5DHYA1f5wKcUfJ+OY/NNLuFWOfJZL0T0L xAkKOihBekXVAcza4WYxhR2O0+IXAr8gSP4aTsVtux0lXdasf1TeX+sUiPbvSsF0V1uq uxVg== 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:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=aIrJdcd3Rlf4G6pjMgn7JXWzwVirCr0wwO7ntLRq2WM=; b=YFN1t2vSF/XZmIS6RDCGy2xBABcSGN6Fnk3j/u01BKm72+mMChJcv16eGsJlVFSBZW mouvnnbd7A9HKRgVkMQoi8XgYyvFHvwhgd2FTBCh2jgSd43FOqnlqcfXGqvTtepQG7fB cQUeoi6DK32Zmj26M6IfXG4e9NSpMU6KkTo8J1I9ghbNglwOkyLouDmOa99iDwOJG/mU iDxac2WkjmH0faFzVxYM3I8GqIamz8/scgEWj/Od8GO2no4B/AQQDtyDdekQZe4rfMK5 LGwNCgJtbbfIlIaiSzaSaLFMdQxxbMNQmR0OdAfqWwPdtLNOQ3ztk68S2ymJ2ojQlWYN zKZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dgHUzS5G; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e68si1719010qtb.72.2018.04.16.19.54.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 16 Apr 2018 19:54:02 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dgHUzS5G; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8Gkr-0004SO-VF for patch@linaro.org; Mon, 16 Apr 2018 22:54:02 -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) 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-Received: by 10.99.147.20 with SMTP id b20mr272635pge.309.1523933614832; Mon, 16 Apr 2018 19:53:34 -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) 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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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ée Cc: Peter Maydell Signed-off-by: Richard Henderson --- fpu/softfloat.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) -- 2.14.3 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, FloatParts b, float_status *s) a.cls = float_class_dnan; return a; } - /* Div 0 => Inf */ + /* Inf / x */ + if (a.cls == float_class_inf) { + a.sign = sign; + return a; + } + /* x / 0 => Inf */ if (b.cls == float_class_zero) { s->float_exception_flags |= float_flag_divbyzero; a.cls = float_class_inf; a.sign = sign; return a; } - /* Inf / x or 0 / x */ - if (a.cls == float_class_inf || a.cls == float_class_zero) { + /* 0 / x */ + if (a.cls == float_class_zero) { a.sign = sign; return a; } From patchwork Tue Apr 17 02:53:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 133502 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp4235572ljb; Mon, 16 Apr 2018 19:56:07 -0700 (PDT) X-Google-Smtp-Source: AIpwx48i5z8NyTfde/NXIhkjEusIJiOCuOupfr0XqERXWeUOiOPuUE7tiw15jET310zmyBcPOb3P X-Received: by 10.55.24.220 with SMTP id 89mr389274qky.49.1523933767688; Mon, 16 Apr 2018 19:56:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523933767; cv=none; d=google.com; s=arc-20160816; b=Bx4qDcg4wnucXVxhq0KU0K18/K51glbBmA5jVf++wVCkymrv401ii8CO62dX1pt/Z1 Ggjj+OLwk0b/HVRUEVa5C4MxlqaFjkBoZQcxxQVuoc+UuirEpwrko99lxdyFewsR6ZpY ku+1OkNiP+dI4//9cF6HNxirazlhaUnLOoVKbtROcgoD6JouqHzAeaeiMBMUPDKjz0oz tyRh3vtL4nesEQlXWkReUKqKaxvCFJbV4V1PQFQooBH/oPi0vLwWcJ/MPiut8vaE8nfv Gg6g9pT2oY4rDlukmUwoF2oRoEs03sSlPcAL3z+/nkiF2d2Q1uS9I+R0vhWi7XLcD5Em 5yLQ== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=t5V/IQAptYx23oK2IFpQU6J5Ud1YBq6Pkr09Y/TjDyg=; b=prHvrMwOVJjvt3OiIEkntCAPwi5wEbTDR15EgPox8PzQ6j7XQubRr4t6dmi4OAglgb e1oGkZFyqRMBapBlQ9anbHRjDbCgtHMi7eqlBSP1xr+AJsS7/24ImbP7NXb1vZmqkRax Xz33pLHU39JThI5WX1N/QgJkSqxutlQqtIIhlGbOMy/5hkQKE7METXPED8OuVPUAy6Y/ YozZ9WgE8KZn/paPPSOWkOw7lx8zu+NfWz9+24EZcZ15TuYm+wLU622wpXwVvig9Xjb2 gAGvVPiPU8+Kr6fwafcDrUCBUAYMwg7/8heeYdDGGTIOiJPizcXwdEsOkmJIaLoH6BWX 7v8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=hGo8kSMR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v127si189613qkc.165.2018.04.16.19.56.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 16 Apr 2018 19:56:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=hGo8kSMR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8Gmt-0006V4-73 for patch@linaro.org; Mon, 16 Apr 2018 22:56:07 -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) 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-Received: by 2002:a17:902:9303:: with SMTP id bc3-v6mr348900plb.18.1523933616779; 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.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- fpu/softfloat.c | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.14.3 Reviewed-by: Peter Maydell Reviewed-by: Alex Bennée Tested-by: Alex Bennée 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, int n, float_status *s) return return_nan(a, s); } if (a.cls == 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 = MIN(MAX(n, -0x10000), 0x10000); a.exp += n; } return a;