From patchwork Fri May 15 18:47:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 186861 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp686961ilb; Fri, 15 May 2020 11:49:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznYQdAuAnzjjfMQqtn2GM1ed3SoSF1F6ZhZVZeW0m9NgyOcgVxjWNB2IvLqeFwZdnouUuF X-Received: by 2002:a37:490:: with SMTP id 138mr4795500qke.199.1589568592739; Fri, 15 May 2020 11:49:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589568592; cv=none; d=google.com; s=arc-20160816; b=DDQi8t8kxwBlLAtAIRfDowTShUzRUqKGYvFKbmkfmAhwD43CcPLTwJGAfq9Mk+4Qrm G0WCxdzNqp/qzqsdtkyDofPcBVNdF0/H3IBSROPhV806dqzf4nkloFmlMuzH0jo/ZGU9 nJ/ehg/c+YxiCXwFJevBBprjdz3bVHzIN52I9EhirfifvxW5EjYNfGu1nXzSwn/gi/JP I6Gcw1c0F1nfIETlrRCUykZ/6MN4KjKr19CoWDU0QqvJpnqlUUE9wdi84ne3iAh2bMSI Gd2mP/zEjc+3SgyLsucClrYgogs8k+8b7/c9/DdJmspRSlDjjGSa3tVboGSNJYcmm4WD PFCw== 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=sDsWd7cEdqbJ8T+RDdCYVYocOyGqUc9YgStV0gdweYI=; b=T/HlIvO5N1XesyGgNHWXzvxp9QzUphC27oCIiWS5mv2tPYWF4jLrAzc1gyhHapg1n4 Q5eAxSDgrkGPqLDgm+ZJoTepc/4trypbeCEwv6GM1cVN8GTb04V4nX2ELc0xM0T67iDP mGhOKYNJIb2Iag62zDp63gk8uJLqyaQXZAHdyfOLSORpTZN7bk/rP5KfEHjqHnT5xxe5 YZCasPmlp/oE/n/nCmGpfs78MPDhm5J4rjeuuX+3a8XdNTSN568m3vYg4TRYogJVUQkl jmaSUZANe3Erz7v1wyQqS/QKQ8nhEMUqDtFo5Zn1RHGrT+NSLclbLig6eqp+DvkNpHuR vSMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DlS++alC; 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 k69si1626514qke.211.2020.05.15.11.49.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 May 2020 11:49:52 -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=DlS++alC; 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]:48928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZfP6-0002ah-5Q for patch@linaro.org; Fri, 15 May 2020 14:49:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZfMm-00082g-Kp for qemu-devel@nongnu.org; Fri, 15 May 2020 14:47:28 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:40872) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jZfMl-0005sm-GV for qemu-devel@nongnu.org; Fri, 15 May 2020 14:47:28 -0400 Received: by mail-pj1-x1029.google.com with SMTP id fu13so1359464pjb.5 for ; Fri, 15 May 2020 11:47:27 -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=sDsWd7cEdqbJ8T+RDdCYVYocOyGqUc9YgStV0gdweYI=; b=DlS++alCxWWICHae4BiFLQEbLJqwsch8Ygr3J7ZNBbaAHoS33z3s4nT9FtgBG/YLug EEa/dpCTFFbNcoHEgxxRhxluwrknUhVi8Q0r+zP/oDcoBvsWrsTHrJQ4ztgarb4Y1S+B Cc4LsCTGYkbeNaaT05mA9NP0uDftlzet6icYKD5RKXZPWLPMRIF4FS2ifn4XNHeaadHD JCvwveCetQGy8Z6tVNDbh0BGtWltuccsux3zW6HhZ3HJQ5GNQbhobJ25hW4qmRSvDOVA /VNP02fAaa1uuevQ0nUGeD+NVIrRh4YENsg1ibltx6bLHgQEzUmB5oz46gtOStsMz3/X SjQQ== 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=sDsWd7cEdqbJ8T+RDdCYVYocOyGqUc9YgStV0gdweYI=; b=iuKo95WoBQKeWo0afrTNwdCCs9rjdFdYD0ZdGKaIb0pB3U6nvL6JC7BzMBMtCIpvlP e9rHHF84Czmfrnlw81sVn7dztNsKh5W9HBpnwRCf0mp/bYeHkzcyNintvlCmjdImW1iZ tr07QZU8sMpTeIr0G+bOkqlY6h5SpNhen4nnn63klH277JD5keabck/Pg7+eDY75yO7o acSZSMt2BBPuy7AlCcixkVfcJz8NNYDnNZ9StlgS9DNYsC4FzbuLInIUMrRz16+3QqNV 9f7st6IzMxIHfrgxymc5hH0AVGD6L3CPlnc9fx33Ijmy+fbr3idrZIBijFc56ESqUwIz wo0A== X-Gm-Message-State: AOAM531Z62X5/IcPJXmbqszUCR583MEAw8cLML0qNGhZmX81mtyw2iYt jzntu5f1yT2TpK7SROpJEackfmsUEQ0= X-Received: by 2002:a17:90a:c253:: with SMTP id d19mr5205958pjx.210.1589568445504; Fri, 15 May 2020 11:47:25 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id u73sm2743630pfc.0.2020.05.15.11.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2020 11:47:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 1/4] softfloat: silence sNaN for conversions to/from floatx80 Date: Fri, 15 May 2020 11:47:19 -0700 Message-Id: <20200515184722.31182-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200515184722.31182-1-richard.henderson@linaro.org> References: <20200515184722.31182-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, Joseph Myers Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Joseph Myers Conversions between IEEE floating-point formats should convert signaling NaNs to quiet NaNs. Most of those in QEMU's softfloat code do so, but those for floatx80 fail to. Fix those conversions to silence signaling NaNs as well. Signed-off-by: Joseph Myers Message-Id: Signed-off-by: Richard Henderson --- fpu/softfloat.c | 24 +++++++--- tests/tcg/i386/test-i386-snan-convert.c | 63 +++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 tests/tcg/i386/test-i386-snan-convert.c -- 2.20.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index ae6ba71854..ac116c70b8 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -4498,7 +4498,9 @@ floatx80 float32_to_floatx80(float32 a, float_status *status) aSign = extractFloat32Sign( a ); if ( aExp == 0xFF ) { if (aSig) { - return commonNaNToFloatx80(float32ToCommonNaN(a, status), status); + floatx80 res = commonNaNToFloatx80(float32ToCommonNaN(a, status), + status); + return floatx80_silence_nan(res, status); } return packFloatx80(aSign, floatx80_infinity_high, @@ -5016,7 +5018,9 @@ floatx80 float64_to_floatx80(float64 a, float_status *status) aSign = extractFloat64Sign( a ); if ( aExp == 0x7FF ) { if (aSig) { - return commonNaNToFloatx80(float64ToCommonNaN(a, status), status); + floatx80 res = commonNaNToFloatx80(float64ToCommonNaN(a, status), + status); + return floatx80_silence_nan(res, status); } return packFloatx80(aSign, floatx80_infinity_high, @@ -5618,7 +5622,9 @@ float32 floatx80_to_float32(floatx80 a, float_status *status) aSign = extractFloatx80Sign( a ); if ( aExp == 0x7FFF ) { if ( (uint64_t) ( aSig<<1 ) ) { - return commonNaNToFloat32(floatx80ToCommonNaN(a, status), status); + float32 res = commonNaNToFloat32(floatx80ToCommonNaN(a, status), + status); + return float32_silence_nan(res, status); } return packFloat32( aSign, 0xFF, 0 ); } @@ -5650,7 +5656,9 @@ float64 floatx80_to_float64(floatx80 a, float_status *status) aSign = extractFloatx80Sign( a ); if ( aExp == 0x7FFF ) { if ( (uint64_t) ( aSig<<1 ) ) { - return commonNaNToFloat64(floatx80ToCommonNaN(a, status), status); + float64 res = commonNaNToFloat64(floatx80ToCommonNaN(a, status), + status); + return float64_silence_nan(res, status); } return packFloat64( aSign, 0x7FF, 0 ); } @@ -5681,7 +5689,9 @@ float128 floatx80_to_float128(floatx80 a, float_status *status) aExp = extractFloatx80Exp( a ); aSign = extractFloatx80Sign( a ); if ( ( aExp == 0x7FFF ) && (uint64_t) ( aSig<<1 ) ) { - return commonNaNToFloat128(floatx80ToCommonNaN(a, status), status); + float128 res = commonNaNToFloat128(floatx80ToCommonNaN(a, status), + status); + return float128_silence_nan(res, status); } shift128Right( aSig<<1, 0, 16, &zSig0, &zSig1 ); return packFloat128( aSign, aExp, zSig0, zSig1 ); @@ -6959,7 +6969,9 @@ floatx80 float128_to_floatx80(float128 a, float_status *status) aSign = extractFloat128Sign( a ); if ( aExp == 0x7FFF ) { if ( aSig0 | aSig1 ) { - return commonNaNToFloatx80(float128ToCommonNaN(a, status), status); + floatx80 res = commonNaNToFloatx80(float128ToCommonNaN(a, status), + status); + return floatx80_silence_nan(res, status); } return packFloatx80(aSign, floatx80_infinity_high, floatx80_infinity_low); diff --git a/tests/tcg/i386/test-i386-snan-convert.c b/tests/tcg/i386/test-i386-snan-convert.c new file mode 100644 index 0000000000..ed6d535ce2 --- /dev/null +++ b/tests/tcg/i386/test-i386-snan-convert.c @@ -0,0 +1,63 @@ +/* Test conversions of signaling NaNs to and from long double. */ + +#include +#include + +volatile float f_res; +volatile double d_res; +volatile long double ld_res; + +volatile float f_snan = __builtin_nansf(""); +volatile double d_snan = __builtin_nans(""); +volatile long double ld_snan = __builtin_nansl(""); + +int issignaling_f(float x) +{ + union { float f; uint32_t u; } u = { .f = x }; + return (u.u & 0x7fffffff) > 0x7f800000 && (u.u & 0x400000) == 0; +} + +int issignaling_d(double x) +{ + union { double d; uint64_t u; } u = { .d = x }; + return (((u.u & UINT64_C(0x7fffffffffffffff)) > + UINT64_C(0x7ff0000000000000)) && + (u.u & UINT64_C(0x8000000000000)) == 0); +} + +int issignaling_ld(long double x) +{ + union { + long double ld; + struct { uint64_t sig; uint16_t sign_exp; } s; + } u = { .ld = x }; + return ((u.s.sign_exp & 0x7fff) == 0x7fff && + (u.s.sig >> 63) != 0 && + (u.s.sig & UINT64_C(0x4000000000000000)) == 0); +} + +int main(void) +{ + int ret = 0; + ld_res = f_snan; + if (issignaling_ld(ld_res)) { + printf("FAIL: float -> long double\n"); + ret = 1; + } + ld_res = d_snan; + if (issignaling_ld(ld_res)) { + printf("FAIL: double -> long double\n"); + ret = 1; + } + f_res = ld_snan; + if (issignaling_d(f_res)) { + printf("FAIL: long double -> float\n"); + ret = 1; + } + d_res = ld_snan; + if (issignaling_d(d_res)) { + printf("FAIL: long double -> double\n"); + ret = 1; + } + return ret; +} From patchwork Fri May 15 18:47:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 186858 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp685773ilb; Fri, 15 May 2020 11:47:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6vxcJQRPsoFIgOU1zC/VoBpCPRYREAgHisayYYXW8EkGMLR+9DTW96KKUNTQgbdf+zcba X-Received: by 2002:a05:620a:a93:: with SMTP id v19mr4846369qkg.416.1589568465993; Fri, 15 May 2020 11:47:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589568465; cv=none; d=google.com; s=arc-20160816; b=j2Jp037aX6Ki9w0QY8fnWpsPRcAZsR2SHsAYdBfsf/SliFqJRcjfVLaiyid+GJBVKH cwZN4iIEnNDsmyapzYF1aC+/MVh/82LE6YKdMjoyT7ktPh4iYX87yQwT4f54DMi7DCtJ n2DR8hQ/pdRyWi99qcpMsaLaojsh6Vemc9pfXollEp9NvZmG6n1fyRAIMPw/qz5icz5b fXs4KOx5kH8F3lNFfTfZCOhAKnkg5T6bX+YZCqqlETZpALjDPT/gZmuxkrdDcKlIPj5i s8RBcr8+vqymJpNNBiXzg7l4g5uq7ogntqpjyhQOtFI4I69IsVUlqqPcsL+hqxp88Qhy LLRw== 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=D5lfLUHd4lnaHSGz0Uzj+dw+p5eXn34OnzAvB/PRrwk=; b=Qye+HtflWresAve5nYlu4habhCB/JrHi8O7NMpBGpiqaGuZkWyAeZH2YuAFgfraESI AHLLjlTGAbs+TFQL/jBNBLroFwkyTrbJSrF17bOFvGPM/o9F72mIAiISZlKWKhGlyIcH yLSvMnsK1uSueoE6F/Yrr7wd1n8wnw5bn7DdV6yrb3Tmx8gIJ6ZaxSB8g4iqSdJGvXG1 IPe8z7qgWkB2EXuhZEsAeZYhhMRG1itctc3DqtBxZLgMGM1wHtGokLba+NRn6VDUek1R 7XIzDMdTHU0gC1QUVSyAC5agCMn93DQrVP4avDctlfCaOxVGv7klLEfEZfbVsFPsNCYa b1iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vAIj+qaY; 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 y16si1780608qto.337.2020.05.15.11.47.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 May 2020 11:47:45 -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=vAIj+qaY; 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]:41958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZfN3-000841-HN for patch@linaro.org; Fri, 15 May 2020 14:47:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZfMn-00082v-Vv for qemu-devel@nongnu.org; Fri, 15 May 2020 14:47:30 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:54226) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jZfMm-0005vf-ER for qemu-devel@nongnu.org; Fri, 15 May 2020 14:47:29 -0400 Received: by mail-pj1-x1033.google.com with SMTP id hi11so1294372pjb.3 for ; Fri, 15 May 2020 11:47:28 -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=D5lfLUHd4lnaHSGz0Uzj+dw+p5eXn34OnzAvB/PRrwk=; b=vAIj+qaYZmrkWNHCqy3TeRvftbE9jS4cYu6njMJpoxFgvGscx6HdkGmUaKJMgPPmqh ZIIZxjRN/TVHNijcjjYKqtr6i1G1XWi9Mn5qcGkf6LG7KgKmuWFpEXBfD14pjztgRgOx mY5w6Ma5RQtZm3Nukfscpp28ZEmEvI7bS0AoYvthvGcNelwh/jRtLSASTz5JCV6t7GyE kJya7irLY51v3TLc9oC1lVs+tdfQQPi2DW1ZqNmMSUf2bdDrXxZx2R9THaajNM8HqGif WnpB3qZf5Wfqhuj7ESiQKFozBUCRMCQUPqNUU4ZhXLNNLEsEtwy4J2GMFdR/KcYswyxE 7+6A== 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=D5lfLUHd4lnaHSGz0Uzj+dw+p5eXn34OnzAvB/PRrwk=; b=LO7U+MvwGYyrxb9qpth4RqF1cpG4ju+EIyqLmICdrc5LZtrG7KJulfURONMRy7AtPM ijcoV/053RC16rYv3i/Xbol5DyhBUtlGHFr/1o1pn2qpqAJSrcpudGaxbKIRMTV/CQHs TlpK8D7OYYcq6pAE4KWRnq43vnyO8XEbDnwXlMOz1GdRMQsgjk820V0yh6PUCvwvxUbj yR3KPGFtYg14pb4nhMm8ifYFoeBvnEUePFEas1tYnOFNgFhy4NbIncAS2VElegwO5i4c Xaal6HiY1lKGO0/Ket8lB4gEj7FBzZUF5recCt40oy9fE0PzL65z950c094Jvvm7RDH6 W1DQ== X-Gm-Message-State: AOAM530/jMSr/59VPWsXbUHsisXSJQDMwpZ7ILz0toZhitWfcwctPS4X Ps2zA1DQXH42soVZH4FlT779NVVOoJ8= X-Received: by 2002:a17:90a:154e:: with SMTP id y14mr5156293pja.180.1589568446764; Fri, 15 May 2020 11:47:26 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id u73sm2743630pfc.0.2020.05.15.11.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2020 11:47:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 2/4] softfloat: fix floatx80 pseudo-denormal addition / subtraction Date: Fri, 15 May 2020 11:47:20 -0700 Message-Id: <20200515184722.31182-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200515184722.31182-1-richard.henderson@linaro.org> References: <20200515184722.31182-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, Joseph Myers Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Joseph Myers The softfloat function addFloatx80Sigs, used for addition of values with the same sign and subtraction of values with opposite sign, fails to handle the case where the two values both have biased exponent zero and there is a carry resulting from adding the significands, which can occur if one or both values are pseudo-denormals (biased exponent zero, explicit integer bit 1). Add a check for that case, so making the results match those seen on x86 hardware for pseudo-denormals. Signed-off-by: Joseph Myers Message-Id: Signed-off-by: Richard Henderson --- fpu/softfloat.c | 6 ++++++ tests/tcg/i386/test-i386-pseudo-denormal.c | 24 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/tcg/i386/test-i386-pseudo-denormal.c -- 2.20.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index ac116c70b8..6094d267b5 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -5866,6 +5866,12 @@ static floatx80 addFloatx80Sigs(floatx80 a, floatx80 b, flag zSign, zSig1 = 0; zSig0 = aSig + bSig; if ( aExp == 0 ) { + if ((aSig | bSig) & UINT64_C(0x8000000000000000) && zSig0 < aSig) { + /* At least one of the values is a pseudo-denormal, + * and there is a carry out of the result. */ + zExp = 1; + goto shiftRight1; + } if (zSig0 == 0) { return packFloatx80(zSign, 0, 0); } diff --git a/tests/tcg/i386/test-i386-pseudo-denormal.c b/tests/tcg/i386/test-i386-pseudo-denormal.c new file mode 100644 index 0000000000..cfa2a500b0 --- /dev/null +++ b/tests/tcg/i386/test-i386-pseudo-denormal.c @@ -0,0 +1,24 @@ +/* Test pseudo-denormal operations. */ + +#include +#include + +union u { + struct { uint64_t sig; uint16_t sign_exp; } s; + long double ld; +}; + +volatile union u ld_pseudo_m16382 = { .s = { UINT64_C(1) << 63, 0 } }; + +volatile long double ld_res; + +int main(void) +{ + int ret = 0; + ld_res = ld_pseudo_m16382.ld + ld_pseudo_m16382.ld; + if (ld_res != 0x1p-16381L) { + printf("FAIL: pseudo-denormal add\n"); + ret = 1; + } + return ret; +} From patchwork Fri May 15 18:47:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 186860 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp686035ilb; Fri, 15 May 2020 11:48:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgh9eKvdIXsmg60O3Mcg2dLyPPsBQdtvOh+PU/xpanyhTWl0ugwozbyxn62UuooNgyCgMQ X-Received: by 2002:ac8:6f2f:: with SMTP id i15mr5041697qtv.53.1589568495459; Fri, 15 May 2020 11:48:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589568495; cv=none; d=google.com; s=arc-20160816; b=KEhI0q8wJ+2/p7sO03sJPrFbyXx01zaQDYNe/JV0G5TGb+3HqG6XKFtpXECv0QIqxx Nu/huMKQFNXkOAvymx2qItj0xx/7RpIgRXPpkU+X0kUjN9IwxKWstTWLO7aI5kzmc9n4 6gtAW54zyWl2r2YBJ30jbpgyt3lfrlC59/ikWcnAGRAV4S7cfo33NHpL4kbGJdgsj7BO xh02or3scv8CdgHVWC23m0h/TCsj6lnGTRKjBPH1w4hy73hm6QrkDWGjNrmIN718WF/y tsT3lphvCNXzHPKrn2yG5qMFjFlTCHnxkLgcD2vvwT4+MSL7luaS/i/O/3R83e37Pz1R C3AA== 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=cMmDD1w5euAwfTOHzuv67r0X2MSI19HIQQ5/Y6AnMtU=; b=xNJl4COZrvVAHYHlv7rgn5hZ0RF6+UNI9ZT3LBMkLflv+cOCpg+EUC30VK6PFmvZWp o8sIJpERq968Ywg0gZ/Dmrl0yMHUrRj2t0Z41rR6QbVFqsXmB9KUsiaRDnbD5ksbIlYV WUr/G+xpWgAX6QgLgwPwIR6OklWIDvAbyaNpHTDxvt54jdf9TWuSkS0CU41C8cAKrBJs RiIcgp6uOIuWBg9mTyP0hrKBxbf5CkU7ECqBWUlkxR7JouBYBq8Dhj7IeTliLW+bdxkS XwvoPPcfDm27lJpRAnx2XZ96Pxreb7rmkDtelgGMfroJoy/Nf4t2HBY6VHFomoF73biL erlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WMeP33kb; 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 l20si1548540qvz.198.2020.05.15.11.48.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 May 2020 11:48:15 -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=WMeP33kb; 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]:42026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZfNW-00086L-UF for patch@linaro.org; Fri, 15 May 2020 14:48:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54012) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZfMo-000839-No for qemu-devel@nongnu.org; Fri, 15 May 2020 14:47:31 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:36588) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jZfMn-0005xs-QT for qemu-devel@nongnu.org; Fri, 15 May 2020 14:47:30 -0400 Received: by mail-pg1-x542.google.com with SMTP id c75so393273pga.3 for ; Fri, 15 May 2020 11:47:29 -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=cMmDD1w5euAwfTOHzuv67r0X2MSI19HIQQ5/Y6AnMtU=; b=WMeP33kbglvSe6Z92DcVtJdWXUK7zTT51QmEKEhoOL/RppYemcNQR+0Mpm+NOfuftg +nV4DJfRT97m/sLsu6jjVNhGPQEmhHQS2xrCDhE57IYW/+VPEkCSEKsTRr5NlXAdlpDB H2ZeO0Z/kEmgcq2BHEdNFrAQxyzbJmLwTB2UoSbk4YDisE5CfXkLJORMQVxGBCIuTJ2V 8UNHWY2brM5m/ARpvQO1U/Cpn8YEhzR8xTjmx8Me7nI90RXE8to0PrWR/hN2rTyPUdwm lw/ijzK4+xJ202PTBWXVf1zm2Iz+M+bwv41+ho2PZB9WdE5mpVuBVmz8N7+5SLZLoANs BoYg== 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=cMmDD1w5euAwfTOHzuv67r0X2MSI19HIQQ5/Y6AnMtU=; b=q+jwCZtDkGTsWhic7hXSePpdcFm692j6VkUJpsohhgwygdUz74VwcCoKL318fGYvt4 S0WRcDLPHfDA1LRIkOWWqVCXcEP9/YuMqMxmM2qnvUKFSAwX9rlirElpCSVTbXYrpY3z 1+kR8i7s7avdecUyyuBMB1PgGr3VtPY5mv+RhabuFmGlvMB4uE0ZQexcBJe5OVdezngv BwUZONodXRkJ9VP+zYzv4fCCRNbcc6YS9fRPKNge6UBSaqTiOIwUFH+xBLinbGEypUlO cyysuo0ZYgPOWh7i1TFn9xFl01k6dbmcsDHS3udQ/8R9tuMr6tZe1JBIoYWXrkr8zx0e oiEg== X-Gm-Message-State: AOAM531ZQ5KPSZeSn/1laRA2T7BK3c/mm1JcDq1BgLmbgIWkk4zASnqF e7uiGX4dylsjFtsAHt2QsG6zaMXAnfE= X-Received: by 2002:a62:754f:: with SMTP id q76mr5428030pfc.14.1589568447897; Fri, 15 May 2020 11:47:27 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id u73sm2743630pfc.0.2020.05.15.11.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2020 11:47:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 3/4] softfloat: fix floatx80 pseudo-denormal comparisons Date: Fri, 15 May 2020 11:47:21 -0700 Message-Id: <20200515184722.31182-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200515184722.31182-1-richard.henderson@linaro.org> References: <20200515184722.31182-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::542; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x542.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, Joseph Myers Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Joseph Myers The softfloat floatx80 comparisons fail to allow for pseudo-denormals, which should compare equal to corresponding values with biased exponent 1 rather than 0. Add an adjustment for that case when comparing numbers with the same sign. Signed-off-by: Joseph Myers Message-Id: Signed-off-by: Richard Henderson --- fpu/softfloat.c | 7 +++++++ tests/tcg/i386/test-i386-pseudo-denormal.c | 4 ++++ 2 files changed, 11 insertions(+) -- 2.20.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 6094d267b5..c57f72e3a6 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -7966,6 +7966,13 @@ static inline int floatx80_compare_internal(floatx80 a, floatx80 b, return 1 - (2 * aSign); } } else { + /* Normalize pseudo-denormals before comparison. */ + if ((a.high & 0x7fff) == 0 && a.low & UINT64_C(0x8000000000000000)) { + ++a.high; + } + if ((b.high & 0x7fff) == 0 && b.low & UINT64_C(0x8000000000000000)) { + ++b.high; + } if (a.low == b.low && a.high == b.high) { return float_relation_equal; } else { diff --git a/tests/tcg/i386/test-i386-pseudo-denormal.c b/tests/tcg/i386/test-i386-pseudo-denormal.c index cfa2a500b0..acf2b9cf03 100644 --- a/tests/tcg/i386/test-i386-pseudo-denormal.c +++ b/tests/tcg/i386/test-i386-pseudo-denormal.c @@ -20,5 +20,9 @@ int main(void) printf("FAIL: pseudo-denormal add\n"); ret = 1; } + if (ld_pseudo_m16382.ld != 0x1p-16382L) { + printf("FAIL: pseudo-denormal compare\n"); + ret = 1; + } return ret; } From patchwork Fri May 15 18:47:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 186862 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp686977ilb; Fri, 15 May 2020 11:49:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3w7Iucjq5U9FPRKoBHsg4pTNQfCS1VhcCg8Agq4+Sv1yWd9HQFu8ykd2TTCG15KKwcGgi X-Received: by 2002:ac8:7249:: with SMTP id l9mr5140240qtp.224.1589568594640; Fri, 15 May 2020 11:49:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589568594; cv=none; d=google.com; s=arc-20160816; b=FJ17mMadcS/vsZM+l3lLqctm+K3j+4fLRHGCInprSPrStp8vCiZtKu0rvZUBeeaQoi +0zQe0yOpBYt3WEVixkqLV6bt+cdF04pQf44ypk2GcnhyWN1mJHQ/ayfyWZy3NvPzVPs D3skt8lZdsaEMzpKHorsOIht0Dlll6cchsD06xH7I8EjPRUvxDiP2dqAfHh7iJILiTH7 mYg1AGBdaBBsdoqmGui59pAO3y2snDMyvYYEJ4QAGS8yFdmFdlfnVXGhRuI2wjB2MQBI LdIkhwBUqcKFnlf3Tn5Wy1BCASvvhUqCazoTFu0K6S5mSrmVIVGlUWdABhcqjpjTPvHm JF6w== 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=KgLFINBGEx2VLJ3Ma6VyMCd7VNjG3xrKYeKQiYwUVWY=; b=zEllg5+9DEcIvwdXe4486kHdUhN3NIY2JF7e07cCI2urzcV84/+fG5UFEJ9WB3kV8c H39uDQFUyJK5X9S6t73s9FSu28nM7uZoCume0WIOXoW4ml2PK7UAJVoJ+XrOA/lNakj4 W58vMec5eVdjte/a4zqEbwCDIhQFDT9jjN1bfA5CtOFYYma7DRh/tRi33iG2gpBzyHew FcoTsFqmI0I2X3pCNufVkZ0dvHNP7U6Z/AciD2EB7UJVXshN+lhX1ymeTmaIkzapGC14 NWwVmvj7qLpEEWoSJxz54n3N+4BC4wowVr25eGn0HK+WTtm+3t2tBEUEFiVBk+M0XnQW vzow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YxjWsug9; 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 c75si1652654qkb.114.2020.05.15.11.49.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 May 2020 11:49:54 -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=YxjWsug9; 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]:49130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZfP8-0002g2-4p for patch@linaro.org; Fri, 15 May 2020 14:49:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54018) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZfMq-00083o-Hb for qemu-devel@nongnu.org; Fri, 15 May 2020 14:47:33 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:46821) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jZfMp-0005zW-HB for qemu-devel@nongnu.org; Fri, 15 May 2020 14:47:32 -0400 Received: by mail-pg1-x52e.google.com with SMTP id p21so1386122pgm.13 for ; Fri, 15 May 2020 11:47:30 -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=KgLFINBGEx2VLJ3Ma6VyMCd7VNjG3xrKYeKQiYwUVWY=; b=YxjWsug9donkIqf6gR6bbyFweBlsgZAoObZ/oxq2s9S4acMulNJ0R1VZyCpM84Y7Ak OQXMX/G/EbR1NHvreh8iH+7QmEfp/FSqC0+HDQuoyPypQmg4CeMPYQPEErY0PMvNHkXp zxP9/7eCg5wSIKHw1prHMnRQiQpODHzYd8mW7BIqUQ7l27vzSPUCTYOFOD6nTqF5TxL6 iQ1LlGAb3wEhW6nqFToWESLsP3hjB0UwRWTjdF8TkpfESCPHX1lk+upsee84usJgeMRJ jR7YFcZrow8A8TiiEhncxjcww05DO2efYBb/2+2oAWBhSvMu77RlgofSiG7/cn533WGf N0Pg== 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=KgLFINBGEx2VLJ3Ma6VyMCd7VNjG3xrKYeKQiYwUVWY=; b=GQdu3VFLr92+ZNGNzAx52tqrrIEqellZIziBByZRiSgBu1tjVfgLpoVteeYm+XHCcf VLxJQo/ARVT5RNvEc0lTTibhJaFKUP1Sbeu4sYd6hy2+tTW8lYdSQyrLlRwG1OYLp6Ta 7A257lX0DPD8HjanQSLkpcKBd9yd7LR493bBQRSdHePyBWWvGPDZjUWXtwcggz4JxhrQ QA4RSG6aEMVmR44Q12WdUsqc1sCRXXQO5TJUKHd7y/ARcP/WolzXsbOY9AAAWp2x+CKa DoVLb57gDznMqiLTOiXkJCafAqy6CIsdamE4EBOR57pp1MMkYwlg7iOK/CNY9AGLn8qQ 6Sdw== X-Gm-Message-State: AOAM531tV9FXajhbLEAV53Daf5rfKqcR6OUl6RR08wpna9P9Fzyfl5cw CH0IAGk6R9MjrNtU1t7wlABi+BsOrt8= X-Received: by 2002:aa7:9f5a:: with SMTP id h26mr5236902pfr.281.1589568449160; Fri, 15 May 2020 11:47:29 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id u73sm2743630pfc.0.2020.05.15.11.47.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2020 11:47:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 4/4] softfloat: fix floatx80 pseudo-denormal round to integer Date: Fri, 15 May 2020 11:47:22 -0700 Message-Id: <20200515184722.31182-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200515184722.31182-1-richard.henderson@linaro.org> References: <20200515184722.31182-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, Joseph Myers Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Joseph Myers The softfloat function floatx80_round_to_int incorrectly handles the case of a pseudo-denormal where only the high bit of the significand is set, ignoring that bit (treating the number as an exact zero) rather than treating the number as an alternative representation of +/- 2^-16382 (which may round to +/- 1 depending on the rounding mode) as hardware does. Fix this check (simplifying the code in the process). Signed-off-by: Joseph Myers Message-Id: Signed-off-by: Richard Henderson --- fpu/softfloat.c | 2 +- tests/tcg/i386/test-i386-pseudo-denormal.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) -- 2.20.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index c57f72e3a6..a362bf89ca 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -5741,7 +5741,7 @@ floatx80 floatx80_round_to_int(floatx80 a, float_status *status) } if ( aExp < 0x3FFF ) { if ( ( aExp == 0 ) - && ( (uint64_t) ( extractFloatx80Frac( a )<<1 ) == 0 ) ) { + && ( (uint64_t) ( extractFloatx80Frac( a ) ) == 0 ) ) { return a; } status->float_exception_flags |= float_flag_inexact; diff --git a/tests/tcg/i386/test-i386-pseudo-denormal.c b/tests/tcg/i386/test-i386-pseudo-denormal.c index acf2b9cf03..00d510cf4a 100644 --- a/tests/tcg/i386/test-i386-pseudo-denormal.c +++ b/tests/tcg/i386/test-i386-pseudo-denormal.c @@ -14,6 +14,7 @@ volatile long double ld_res; int main(void) { + short cw; int ret = 0; ld_res = ld_pseudo_m16382.ld + ld_pseudo_m16382.ld; if (ld_res != 0x1p-16381L) { @@ -24,5 +25,14 @@ int main(void) printf("FAIL: pseudo-denormal compare\n"); ret = 1; } + /* Set round-upward. */ + __asm__ volatile ("fnstcw %0" : "=m" (cw)); + cw = (cw & ~0xc00) | 0x800; + __asm__ volatile ("fldcw %0" : : "m" (cw)); + __asm__ ("frndint" : "=t" (ld_res) : "0" (ld_pseudo_m16382.ld)); + if (ld_res != 1.0L) { + printf("FAIL: pseudo-denormal round-to-integer\n"); + ret = 1; + } return ret; }