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; +}