From patchwork Fri Apr 13 14:03:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 133378 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp766337ljb; Fri, 13 Apr 2018 07:04:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+kDnELMB4otypuwUwK/4H/3N77/zNT3Eca1OvEQDME5fgTinYgOPCIW4y30ZR+XEzcw6Mi X-Received: by 10.55.120.197 with SMTP id t188mr4370997qkc.344.1523628291019; Fri, 13 Apr 2018 07:04:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523628291; cv=none; d=google.com; s=arc-20160816; b=LvmnGJ9mPDxOzqYwgcg6IrXVSnUicD+W6DG2NO2QbD/ia9DlwqLXYW7bV7H6a+fS8R NiJp0iFDccdBnjU/RZ+ZkifKWtqIos7vFJVTkXYbEuFDu+KtDWOBB3bJbv7A4iPHSLjH XLPoVdw+qKVk3C91h+S/jdwZCbgzF0GBGPAykB6G1DoAMzdK4sQs8ZEzRhiVYyx6GtBx 3dPO4y79DAOSW9ZNmhJbgT3ejHsZfPt6XkvdoLSbz/WL/ZRlKW5KYTcO6tEwGsKwxrb4 0BqK8dfhPvlB773l76tWkCqDRmg+OF2CL+Frg/BKxP4XacTBTZzfnu/EN7E2TyL/b0u0 8raA== 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=coFQ2xswQsFEuLwdZm8aY7T7ZboMuDSq8UFNZ8FMz/8=; b=q2vANDIOy9Tyg94E1zn92bIrPfeMbPCvcxyKhUAs/5/IUex/vBq3O/I4dqOW66IK+p AJEqdUcgrdUW+drTkYAzcealPBHVbIsMd7+cc9gtd1aqdZbRhg/wU7+stJo4l2Q3aHay DX8XVv+fzHrT7W2PsKZj5jEubghA/uKshgvJw2eKGpFcEPhuGSV4V785wTr24MEXKSGl 4debfkg86+pHm9gTKvoSwbndoRbV67DO5HQ5jS9pZczd3HhVX/VaIbUTyjsf02mU+oSa YJMYStBzaCLpByX5mzlbpIHJid2JpSXfzQf/KnKXmrxlUGbcVktrPRIrcKmX5d4E+lia LMZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RM71Dfla; 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 z11si230058qti.256.2018.04.13.07.04.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 13 Apr 2018 07:04:51 -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=RM71Dfla; 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]:55944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6zJq-0003ka-GP for patch@linaro.org; Fri, 13 Apr 2018 10:04:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6zIl-000372-8F for qemu-devel@nongnu.org; Fri, 13 Apr 2018 10:03:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6zIg-0000bi-SI for qemu-devel@nongnu.org; Fri, 13 Apr 2018 10:03:43 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:36467) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6zIg-0000bT-LE for qemu-devel@nongnu.org; Fri, 13 Apr 2018 10:03:38 -0400 Received: by mail-wr0-x243.google.com with SMTP id q13so4996193wre.3 for ; Fri, 13 Apr 2018 07:03:38 -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=coFQ2xswQsFEuLwdZm8aY7T7ZboMuDSq8UFNZ8FMz/8=; b=RM71DflaqJFQVrf5lMV94dD25QxBCnjDzVtaCh/vNMwBXnXP4hYq9zGXvqVLH3ar20 65S1x+Q43HFMqyr8+bxnQXv9WO+FzRvxo096tCfcT+PQdRZbGNlaY9352oOHH+FHbdcO L3EuM80e3RcsF9PaAajmaF4qVHIVQ6rHlKVYw= 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=coFQ2xswQsFEuLwdZm8aY7T7ZboMuDSq8UFNZ8FMz/8=; b=XiF8s5JsmDe2OM4Lz1YSJWobgkEDJLodZvRl5G3nedGs9uQuwueH5bxMJi4nGReNmF LjPCDU214ilHAJvqiNMQIqV/faBWveX2fScZkOj6qIcX98UwQmOyOcbG34fl0pCWnuUP QKH+UBQxGUgFYiySXygwXKCZbeHliB0Nppnv3IpeQ55MRKWRqTqrWSVTvG8FkfgRD8p/ ebaDbRImXtak+JzsRDeDuLr/EEs7sdvAY80k7yG7svF/dHgvY1iax947sIGvV45rSYtr pB6vijJeJRoFKLdferWeSZ+Xq4Dnpx+Gd88q1CrfLbcTvalgaaLtW/5AerHFTaXE+kvg 26yw== X-Gm-Message-State: ALQs6tBeGYBGHdQLtW95HkOW2avGQozkTZKhr7CfTXUYTHyOrFB5DYN2 ixjyq1UUgiSsU9B/Nc0R3/NVxMBJDuw= X-Received: by 10.28.113.22 with SMTP id m22mr3714130wmc.115.1523628217483; Fri, 13 Apr 2018 07:03:37 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l34sm5550517wre.14.2018.04.13.07.03.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Apr 2018 07:03:35 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 2BCB93E0619; Fri, 13 Apr 2018 15:03:34 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Fri, 13 Apr 2018 15:03:33 +0100 Message-Id: <20180413140334.26622-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180413140334.26622-1-alex.bennee@linaro.org> References: <20180413140334.26622-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PATCH v2 1/2] softfloat: fix {min, max}nummag for same-abs-value inputs 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: "Emilio G. Cota" , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Before 8936006 ("fpu/softfloat: re-factor minmax", 2018-02-21), we used to return +Zero for maxnummag(-Zero,+Zero); after that commit, we return -Zero. Fix it by making {min,max}nummag consistent with {min,max}num, deferring to the latter when the absolute value of the operands is the same. With this fix we now pass fp-test. Reviewed-by: Alex Bennée Signed-off-by: Emilio G. Cota Signed-off-by: Alex Bennée --- fpu/softfloat.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) -- 2.17.0 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index b46dccc63e..9b99aa6ec8 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1704,7 +1704,6 @@ static FloatParts minmax_floats(FloatParts a, FloatParts b, bool ismin, return pick_nan(a, b, s); } else { int a_exp, b_exp; - bool a_sign, b_sign; switch (a.cls) { case float_class_normal: @@ -1735,20 +1734,22 @@ static FloatParts minmax_floats(FloatParts a, FloatParts b, bool ismin, break; } - a_sign = a.sign; - b_sign = b.sign; - if (ismag) { - a_sign = b_sign = 0; + if (ismag && (a_exp != b_exp || a.frac != b.frac)) { + bool a_less = a_exp < b_exp; + if (a_exp == b_exp) { + a_less = a.frac < b.frac; + } + return a_less ^ ismin ? b : a; } - if (a_sign == b_sign) { + if (a.sign == b.sign) { bool a_less = a_exp < b_exp; if (a_exp == b_exp) { a_less = a.frac < b.frac; } - return a_sign ^ a_less ^ ismin ? b : a; + return a.sign ^ a_less ^ ismin ? b : a; } else { - return a_sign ^ ismin ? b : a; + return a.sign ^ ismin ? b : a; } } } From patchwork Fri Apr 13 14:03:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 133377 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp765454ljb; Fri, 13 Apr 2018 07:04:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/QPe5c8aQgrcogWwQCHpfcLa9XD0ABuqhN5c/OvoRTdUGasv/XDB/9QHKvcuqFzbzHGg3I X-Received: by 10.233.225.10 with SMTP id g10mr4650610qkm.263.1523628249534; Fri, 13 Apr 2018 07:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523628249; cv=none; d=google.com; s=arc-20160816; b=MWs2AOq/6QEOyZb38QmTHj3016qAI3Xsa9gm6O7Mycnpcx3f3ePkj5hYNqed8inluS dprqRB3otQuf9Jmu6sB+876+VzaDZ4zwmHxfNPrHyrDfybmXUZ/quckdPHOZChf0wF3B xIyPx5gev+H4nAO0Ptbkw2IN6mKJHxJK+LXhI2LMpMzh4MZKfVk09w6ua9Cs3hK3swT6 QXXbXs+cU1dKmkChoE9cRWT73+FjejPidLEOnIAltd4Gqh1SZ98BDfpom6pyLQDM5ZSa xVs0daYHWfy9hlTpnT5oUzNGsGeatv7tokzmcAFmOS38Oy1vQAloSLckDpRypKgEUsFO tRlQ== 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=7EujjhTl4udGdJbhRHyWMrTYrxgmGjapgU23kkosbxs=; b=fqTQyYiWfRrHix7XRA0oZ/B8137XJV81JPr00g6mnXB4IGWJBKluFOXJHwJVd2SGXx JLRXiDArToAZJ20gYkT15gS6ZBVjp0evsMvHtQ94o9cUk8Mn7bRN9czFlUwwcyjzdvOB 9Aqex2kD8R0suWag7cCGSmi6yLl6NpMivxxXBbOzbl+7xNU1UFWCtoFphGPcyI2cMDxr 9FELfr8+KIiLawoj1M8m3VXwPAsVTyF3ra/ioXFSrQv/utCDqIfCp6AtgH4ZMbK3/GhF 9lsCwPfOR1w2FOujQWTdPp3kbr09puEK4HgAMQqZpOOZkzdheSMy3iHhOxCXrzMe2o18 RAkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=d1uzxxYZ; 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 j130si1223599qkj.78.2018.04.13.07.04.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 13 Apr 2018 07:04:09 -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=d1uzxxYZ; 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]:55906 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6zJA-0003CK-TW for patch@linaro.org; Fri, 13 Apr 2018 10:04:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6zIl-00037P-PH for qemu-devel@nongnu.org; Fri, 13 Apr 2018 10:03:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6zIf-0000bO-Vc for qemu-devel@nongnu.org; Fri, 13 Apr 2018 10:03:43 -0400 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:35317) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6zIf-0000b6-Or for qemu-devel@nongnu.org; Fri, 13 Apr 2018 10:03:37 -0400 Received: by mail-wr0-x241.google.com with SMTP id o3so8435937wri.2 for ; Fri, 13 Apr 2018 07:03: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 :mime-version:content-transfer-encoding; bh=7EujjhTl4udGdJbhRHyWMrTYrxgmGjapgU23kkosbxs=; b=d1uzxxYZyizcYgh4AATAqFktEWXqN95tRaokTxI/lE93ee+aJg3lysJd92QIYxSv1o H7VVYDPEno1fvttamO/X4D7ptsLpadbWUJs4Nzb9BKUcuPKpCjlC6FwAuxk0JQ1hgUCQ LEYD1diO2s6UkskT+zXwA5uWEPjBm9xZLSsRc= 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=7EujjhTl4udGdJbhRHyWMrTYrxgmGjapgU23kkosbxs=; b=VoWRzKrJcGpeuWJYq8vCUpts2nj2tSoj3vUccxagqh+j63Gh04EFtmUWufWe47XFxy Jm4J4jHeYEvrAblNWQb1rjaIvHPZD3Z8Fu26sHf2pBLReceix6a+SpeI+pnfdq6TPQoI 2Hi6DtYK+0ikD6gLuGqfS58OBi859GZSciSFCW/aWqZGxbEkZ75T/Km76jK3SmdTDo0x 1dZwdmkqHHi8jUbW3txeML0hCkH+qXYuJfWaANG2rRa8OcmKAUjBqXl+fQkzp4Haelab NWn87GHS3yN8hO96DHu8tIbOG2AoRu1tlGyOb3DDlvLcRl7jcCyefYnrycOBnSej1Snk hGwg== X-Gm-Message-State: ALQs6tAAjvnsO/e8b848WJ7A/Fsx+Y2xPv6rPffuoHHs5K7RmlMecNcA zTzgDLanA4htREgYixPw3DTxIg== X-Received: by 10.223.146.69 with SMTP id 63mr142067wrj.156.1523628216620; Fri, 13 Apr 2018 07:03:36 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l131sm3623179wmb.36.2018.04.13.07.03.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Apr 2018 07:03:35 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 3E4873E061C; Fri, 13 Apr 2018 15:03:34 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Fri, 13 Apr 2018 15:03:34 +0100 Message-Id: <20180413140334.26622-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180413140334.26622-1-alex.bennee@linaro.org> References: <20180413140334.26622-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PATCH v2 2/2] fpu/softfloat: raise float_invalid for NaN/Inf in round_to_int_and_pack 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: Bastian Koppelmann , =?utf-8?q?Alex_Be?= =?utf-8?b?bm7DqWU=?= , qemu-devel@nongnu.org, Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The re-factor broke the raising of INVALID when NaN/Inf is passed to the float_to_int conversion functions. round_to_uint_and_pack got this right for NaN but also missed out the Inf handling. Fixes https://bugs.launchpad.net/qemu/+bug/1759264 Signed-off-by: Alex Bennée Cc: Bastian Koppelmann --- fpu/softfloat.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.17.0 Reviewed-by: Bastian Koppelmann Reviewed-by: Peter Maydell Tested-by: Bastian Koppelmann diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 9b99aa6ec8..fb8663f59e 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1344,8 +1344,10 @@ static int64_t round_to_int_and_pack(FloatParts in, int rmode, case float_class_qnan: case float_class_dnan: case float_class_msnan: + s->float_exception_flags = orig_flags | float_flag_invalid; return max; case float_class_inf: + s->float_exception_flags = orig_flags | float_flag_invalid; return p.sign ? min : max; case float_class_zero: return 0; @@ -1437,6 +1439,7 @@ static uint64_t round_to_uint_and_pack(FloatParts in, int rmode, uint64_t max, s->float_exception_flags = orig_flags | float_flag_invalid; return max; case float_class_inf: + s->float_exception_flags = orig_flags | float_flag_invalid; return p.sign ? 0 : max; case float_class_zero: return 0;