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;