From nobody Fri Nov 14 18:04:28 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1589568671; cv=none; d=zohomail.com; s=zohoarc; b=B07xIyfeepR9R2UDQHZmn73IoQar513nErqhAqEtz1AAxtOeCg3n2mgdxBsoZjJqOr09KSrOq5rUH2rCkGvO82RgQPJUFv1cMAGGKU2tPY2/o2DiVeSYVJHfbt4nQooC5IafhB9TXEsSYfr/dO7DoPwzEXExa6hp9nqi3DcJIBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589568671; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sDsWd7cEdqbJ8T+RDdCYVYocOyGqUc9YgStV0gdweYI=; b=ZUdLg5UU1xZQRLGGUFN2Bjs7hQix4lZXmVLnczuiogxc8NrDxvIh+EWFYpFoLDCKAWCpmm3bgqDiMe7vgHCxxifFW1sJ3Yrx2hz4xLiT1lUqVuFeXMeMCpwN/AJuS4+PQYYCAWwFhocS7XtJheWKc0yaXFovmowiFdDRgQCtht0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589568671048908.6960926102757; Fri, 15 May 2020 11:51:11 -0700 (PDT) Received: from localhost ([::1]:51228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZfQL-0003Zg-IH for importer@patchew.org; Fri, 15 May 2020 14:51:09 -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) 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) 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-Google-Smtp-Source: ABdhPJwQGgSEmMvUrPYV832IT7JiutGUAi4G5/oHd7rYGrFhIWEYhUXpT4RCPlPezRc9Eje06pxElA== X-Received: by 2002:a17:90a:c253:: with SMTP id d19mr5205958pjx.210.1589568445504; Fri, 15 May 2020 11:47:25 -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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" 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 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 =3D extractFloat32Sign( a ); if ( aExp =3D=3D 0xFF ) { if (aSig) { - return commonNaNToFloatx80(float32ToCommonNaN(a, status), stat= us); + floatx80 res =3D commonNaNToFloatx80(float32ToCommonNaN(a, sta= tus), + 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 =3D extractFloat64Sign( a ); if ( aExp =3D=3D 0x7FF ) { if (aSig) { - return commonNaNToFloatx80(float64ToCommonNaN(a, status), stat= us); + floatx80 res =3D commonNaNToFloatx80(float64ToCommonNaN(a, sta= tus), + 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 =3D extractFloatx80Sign( a ); if ( aExp =3D=3D 0x7FFF ) { if ( (uint64_t) ( aSig<<1 ) ) { - return commonNaNToFloat32(floatx80ToCommonNaN(a, status), stat= us); + float32 res =3D commonNaNToFloat32(floatx80ToCommonNaN(a, stat= us), + 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 =3D extractFloatx80Sign( a ); if ( aExp =3D=3D 0x7FFF ) { if ( (uint64_t) ( aSig<<1 ) ) { - return commonNaNToFloat64(floatx80ToCommonNaN(a, status), stat= us); + float64 res =3D commonNaNToFloat64(floatx80ToCommonNaN(a, stat= us), + status); + return float64_silence_nan(res, status); } return packFloat64( aSign, 0x7FF, 0 ); } @@ -5681,7 +5689,9 @@ float128 floatx80_to_float128(floatx80 a, float_statu= s *status) aExp =3D extractFloatx80Exp( a ); aSign =3D extractFloatx80Sign( a ); if ( ( aExp =3D=3D 0x7FFF ) && (uint64_t) ( aSig<<1 ) ) { - return commonNaNToFloat128(floatx80ToCommonNaN(a, status), status); + float128 res =3D 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_statu= s *status) aSign =3D extractFloat128Sign( a ); if ( aExp =3D=3D 0x7FFF ) { if ( aSig0 | aSig1 ) { - return commonNaNToFloatx80(float128ToCommonNaN(a, status), sta= tus); + floatx80 res =3D commonNaNToFloatx80(float128ToCommonNaN(a, st= atus), + 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 =3D __builtin_nansf(""); +volatile double d_snan =3D __builtin_nans(""); +volatile long double ld_snan =3D __builtin_nansl(""); + +int issignaling_f(float x) +{ + union { float f; uint32_t u; } u =3D { .f =3D x }; + return (u.u & 0x7fffffff) > 0x7f800000 && (u.u & 0x400000) =3D=3D 0; +} + +int issignaling_d(double x) +{ + union { double d; uint64_t u; } u =3D { .d =3D x }; + return (((u.u & UINT64_C(0x7fffffffffffffff)) > + UINT64_C(0x7ff0000000000000)) && + (u.u & UINT64_C(0x8000000000000)) =3D=3D 0); +} + +int issignaling_ld(long double x) +{ + union { + long double ld; + struct { uint64_t sig; uint16_t sign_exp; } s; + } u =3D { .ld =3D x }; + return ((u.s.sign_exp & 0x7fff) =3D=3D 0x7fff && + (u.s.sig >> 63) !=3D 0 && + (u.s.sig & UINT64_C(0x4000000000000000)) =3D=3D 0); +} + +int main(void) +{ + int ret =3D 0; + ld_res =3D f_snan; + if (issignaling_ld(ld_res)) { + printf("FAIL: float -> long double\n"); + ret =3D 1; + } + ld_res =3D d_snan; + if (issignaling_ld(ld_res)) { + printf("FAIL: double -> long double\n"); + ret =3D 1; + } + f_res =3D ld_snan; + if (issignaling_d(f_res)) { + printf("FAIL: long double -> float\n"); + ret =3D 1; + } + d_res =3D ld_snan; + if (issignaling_d(d_res)) { + printf("FAIL: long double -> double\n"); + ret =3D 1; + } + return ret; +} --=20 2.20.1 From nobody Fri Nov 14 18:04:28 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1589568532; cv=none; d=zohomail.com; s=zohoarc; b=Hqluv2guM+F0LkvNZJ9SFiUGkh2uoY/Ezz4gEbuoguWW/edqCIXfC1rieKo5i8KPQztSq3n0mwnDOhcyGAhAGgKKBa9GcYI+YFsIZVKp11xiWxFAj7mkLvDPm7SH0IIao2qYu7nmBr+YToBQ3vO4p5vx+Mv2Re8d9gvD9EfBSGU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589568532; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=D5lfLUHd4lnaHSGz0Uzj+dw+p5eXn34OnzAvB/PRrwk=; b=mR0x+PbIEn6xdfbuJ0X0GSesbSDj4RIF/gNfMymgTZNf1NX9BGrWMOkYqh6jqbcpkzU8GT5i7FO3U9WnX4P6GkXhUSmgCliBuF1tLhBcnySh0RvUYZETT3bplYCBOiE+/H4ANIrUAQjrPEEKhmRYTFYQPPLRC9ooIhyr9E4jNxw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589568532544638.2045098404947; Fri, 15 May 2020 11:48:52 -0700 (PDT) Received: from localhost ([::1]:45196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZfO7-0000yK-3b for importer@patchew.org; Fri, 15 May 2020 14:48:51 -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) 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) 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-Google-Smtp-Source: ABdhPJwnZM66H2hBOpoAXtb9B0+Ju2kP2OTb60YltkZfrh1dEQADXlkhGUrxta0r6O+GEPVuTDfDKw== X-Received: by 2002:a17:90a:154e:: with SMTP id y14mr5156293pja.180.1589568446764; 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" 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 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 =3D 0; zSig0 =3D aSig + bSig; if ( aExp =3D=3D 0 ) { + if ((aSig | bSig) & UINT64_C(0x8000000000000000) && zSig0 < aS= ig) { + /* At least one of the values is a pseudo-denormal, + * and there is a carry out of the result. */ + zExp =3D 1; + goto shiftRight1; + } if (zSig0 =3D=3D 0) { return packFloatx80(zSign, 0, 0); } diff --git a/tests/tcg/i386/test-i386-pseudo-denormal.c b/tests/tcg/i386/te= st-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 =3D { .s =3D { UINT64_C(1) << 63, 0 } }; + +volatile long double ld_res; + +int main(void) +{ + int ret =3D 0; + ld_res =3D ld_pseudo_m16382.ld + ld_pseudo_m16382.ld; + if (ld_res !=3D 0x1p-16381L) { + printf("FAIL: pseudo-denormal add\n"); + ret =3D 1; + } + return ret; +} --=20 2.20.1 From nobody Fri Nov 14 18:04:28 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1589568536; cv=none; d=zohomail.com; s=zohoarc; b=eHU9Pjwo19MrxEfkWdm5HbY3/5d4ezkQ5yXEE/lwWBtBftKsbOMPgHHCuUGZd8GJNX3NuUVfT6JHXl1J9+A1FAv2ARx/O++HW38vpXdVhJKT6iMXtag3J0eaI6aAZIl/ZvWRA8qFz9DfJywKfluGrSj3kpLmTNqwWUBSZ4e5haY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589568536; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cMmDD1w5euAwfTOHzuv67r0X2MSI19HIQQ5/Y6AnMtU=; b=HWf5pKHKaysLUeC5fj28Vcs6IXD4zYfSsUZQ4mfomIHepUs2pKnNRqPC35HTpNvbyqlPcX/1r+8C5DW188q5XpzCzuuxIPdBNPM5DOoADK+lx/anTEKPEoUQ1QLD8E7/ow2Oe9A0QhTGe4NO7XsF+IzHJPb0R2gjE4loobFzkB0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589568536483163.58726250702273; Fri, 15 May 2020 11:48:56 -0700 (PDT) Received: from localhost ([::1]:45376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZfOB-00012f-5x for importer@patchew.org; Fri, 15 May 2020 14:48:55 -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) 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) 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-Google-Smtp-Source: ABdhPJzjjdrPb3MCpUKaDtqPhd9hscA0JHAB9t/D/iRAyv1gSgDzLeGHtN1BTn63lPdDCnRGBcc8pw== X-Received: by 2002:a62:754f:: with SMTP id q76mr5428030pfc.14.1589568447897; 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" 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(+) 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) =3D=3D 0 && a.low & UINT64_C(0x8000000000000= 000)) { + ++a.high; + } + if ((b.high & 0x7fff) =3D=3D 0 && b.low & UINT64_C(0x8000000000000= 000)) { + ++b.high; + } if (a.low =3D=3D b.low && a.high =3D=3D b.high) { return float_relation_equal; } else { diff --git a/tests/tcg/i386/test-i386-pseudo-denormal.c b/tests/tcg/i386/te= st-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 =3D 1; } + if (ld_pseudo_m16382.ld !=3D 0x1p-16382L) { + printf("FAIL: pseudo-denormal compare\n"); + ret =3D 1; + } return ret; } --=20 2.20.1 From nobody Fri Nov 14 18:04:28 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1589568671; cv=none; d=zohomail.com; s=zohoarc; b=Q7Z+g/yDTVvb9tivLefuE8vIMGmnclpb7Hc3XZKrMxXp7nGGeeU8BWlHQpTlk91zRGK9z7Mmed6nQv6yqSpHsFV6yHj/C7sLnZfftmS5PJu/iGOJUn3AHbBe2oyBz18E8h3x4fAN4Lxn/oN8qurhI2VoYJbT7AyHRW31JtesZ0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589568671; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KgLFINBGEx2VLJ3Ma6VyMCd7VNjG3xrKYeKQiYwUVWY=; b=eHCBgWXGouafKT1I3UcDuLe0nr0k+Mv/DYq2clIsydbFMzAlpgCCaGbPyVBX8BVR2eo4ni2Q3ijj9PYq2lULGVFtBXuGD1F4HAqcODuMrL9E75/WWHtToYjn+avyKORKVr/YVCuxf9aDMnWhUTqHoN5gMS9wy1DHBVGaeeICnCk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589568671911998.9868882527346; Fri, 15 May 2020 11:51:11 -0700 (PDT) Received: from localhost ([::1]:51310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZfQM-0003fv-LA for importer@patchew.org; Fri, 15 May 2020 14:51:10 -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) 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) 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-Google-Smtp-Source: ABdhPJxwXnJ3uE0iM0axvWXnDZVSrX/DbRErXkkU8G5FTkUWR1DlegWEIK571cUdwsE10a6uQH4eTw== X-Received: by 2002:aa7:9f5a:: with SMTP id h26mr5236902pfr.281.1589568449160; Fri, 15 May 2020 11:47:29 -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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" 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(-) 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_stat= us *status) } if ( aExp < 0x3FFF ) { if ( ( aExp =3D=3D 0 ) - && ( (uint64_t) ( extractFloatx80Frac( a )<<1 ) =3D=3D 0 ) ) { + && ( (uint64_t) ( extractFloatx80Frac( a ) ) =3D=3D 0 ) ) { return a; } status->float_exception_flags |=3D float_flag_inexact; diff --git a/tests/tcg/i386/test-i386-pseudo-denormal.c b/tests/tcg/i386/te= st-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; =20 int main(void) { + short cw; int ret =3D 0; ld_res =3D ld_pseudo_m16382.ld + ld_pseudo_m16382.ld; if (ld_res !=3D 0x1p-16381L) { @@ -24,5 +25,14 @@ int main(void) printf("FAIL: pseudo-denormal compare\n"); ret =3D 1; } + /* Set round-upward. */ + __asm__ volatile ("fnstcw %0" : "=3Dm" (cw)); + cw =3D (cw & ~0xc00) | 0x800; + __asm__ volatile ("fldcw %0" : : "m" (cw)); + __asm__ ("frndint" : "=3Dt" (ld_res) : "0" (ld_pseudo_m16382.ld)); + if (ld_res !=3D 1.0L) { + printf("FAIL: pseudo-denormal round-to-integer\n"); + ret =3D 1; + } return ret; } --=20 2.20.1