From patchwork Tue Dec 31 13:35:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 22847 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f72.google.com (mail-qa0-f72.google.com [209.85.216.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 235CE218CC for ; Tue, 31 Dec 2013 13:36:55 +0000 (UTC) Received: by mail-qa0-f72.google.com with SMTP id f11sf16109204qae.11 for ; Tue, 31 Dec 2013 05:36:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=Hy5jYu03kV+GUWLEHZbcDHgPQfNecG7FqINaB7BkO7I=; b=HspVOJaqyne2MMNda05DpBayco/UoXPO5kandaLCtFxEbZNOJSGCH0Q19Lpa5E2Zln qBfSBjrBKi0v68nvwF6x2beDbwpgo7uGJBclWViIT7Q+AOI55rJgNQc9Ipn19bDy57xM ZBC88NsVHiUP1qJkqLznvcNQxDRSYyOmpN1HiCJtMaC2l29WMF6WNLDIyv1dwv2NgR7u n3OLNUqjFD0p01YNZgLmx4gf5DPrZyoiiIy52ztvoBdnJSJmk+M40DX94M5qIYiwTpJ/ 63Y9scZRGx2a4iunbgWtxd4nm2beu1WmSBPJ5cYDby5in58N9rbDYFXZz1wzCcBNA2Bb F1tA== X-Gm-Message-State: ALoCoQnXXRqEEZrSbu+cUks545gmqHjKqLFSaytAgsRE3p2lFkAn7zSvH2+HIAi0JqxQ4EXYw6cb X-Received: by 10.58.23.137 with SMTP id m9mr15257390vef.13.1388497014392; Tue, 31 Dec 2013 05:36:54 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.101.39 with SMTP id fd7ls3797204qeb.16.gmail; Tue, 31 Dec 2013 05:36:54 -0800 (PST) X-Received: by 10.58.181.165 with SMTP id dx5mr2748421vec.19.1388497014322; Tue, 31 Dec 2013 05:36:54 -0800 (PST) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id ec16si18611683veb.124.2013.12.31.05.36.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 31 Dec 2013 05:36:54 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id db12so6363032veb.22 for ; Tue, 31 Dec 2013 05:36:54 -0800 (PST) X-Received: by 10.58.172.130 with SMTP id bc2mr181800vec.71.1388497014242; Tue, 31 Dec 2013 05:36:54 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.59.13.131 with SMTP id ey3csp664863ved; Tue, 31 Dec 2013 05:36:53 -0800 (PST) X-Received: by 10.180.14.231 with SMTP id s7mr35290466wic.1.1388497013208; Tue, 31 Dec 2013 05:36:53 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id cu5si18519265wjc.50.2013.12.31.05.36.51 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 31 Dec 2013 05:36:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1VxzUE-0000w1-Ho; Tue, 31 Dec 2013 13:35:58 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Alexander Graf , Michael Matz , Claudio Fontana , Dirk Mueller , Laurent Desnogues , kvmarm@lists.cs.columbia.edu, Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Christoffer Dall , Will Newton , Peter Crosthwaite , Tom Musta , Aurelien Jarno Subject: [PATCH 06/22] softfloat: Fix factor 2 error for scalbn on denormal inputs Date: Tue, 31 Dec 2013 13:35:42 +0000 Message-Id: <1388496958-3542-7-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1388496958-3542-1-git-send-email-peter.maydell@linaro.org> References: <1388496958-3542-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , If the input to float*_scalbn() is denormal then it represents a number 0.[mantissabits] * 2^(1-exponentbias) (and the actual exponent field is all zeroes). This means that when we convert it to our unpacked encoding the unpacked exponent must be one greater than for a normal number, which represents 1.[mantissabits] * 2^(e-exponentbias) for an exponent field e. This meant we were giving answers too small by a factor of 2 for all denormal inputs. Note that the float-to-int routines also have this behaviour of not adjusting the exponent for denormals; however there it is harmless because denormals will all convert to integer zero anyway. Signed-off-by: Peter Maydell Reviewed-by: Aurelien Jarno Reviewed-by: Richard Henderson --- fpu/softfloat.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 41e4432..1af6ca5 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -6986,10 +6986,13 @@ float32 float32_scalbn( float32 a, int n STATUS_PARAM ) } return a; } - if ( aExp != 0 ) + if (aExp != 0) { aSig |= 0x00800000; - else if ( aSig == 0 ) + } else if (aSig == 0) { return a; + } else { + aExp++; + } if (n > 0x200) { n = 0x200; @@ -7019,10 +7022,13 @@ float64 float64_scalbn( float64 a, int n STATUS_PARAM ) } return a; } - if ( aExp != 0 ) + if (aExp != 0) { aSig |= LIT64( 0x0010000000000000 ); - else if ( aSig == 0 ) + } else if (aSig == 0) { return a; + } else { + aExp++; + } if (n > 0x1000) { n = 0x1000; @@ -7052,8 +7058,12 @@ floatx80 floatx80_scalbn( floatx80 a, int n STATUS_PARAM ) return a; } - if (aExp == 0 && aSig == 0) - return a; + if (aExp == 0) { + if (aSig == 0) { + return a; + } + aExp++; + } if (n > 0x10000) { n = 0x10000; @@ -7082,10 +7092,13 @@ float128 float128_scalbn( float128 a, int n STATUS_PARAM ) } return a; } - if ( aExp != 0 ) + if (aExp != 0) { aSig0 |= LIT64( 0x0001000000000000 ); - else if ( aSig0 == 0 && aSig1 == 0 ) + } else if (aSig0 == 0 && aSig1 == 0) { return a; + } else { + aExp++; + } if (n > 0x10000) { n = 0x10000;