From patchwork Sat Dec 21 21:08:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 22709 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 25AB4218D3 for ; Sat, 21 Dec 2013 21:08:24 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id gq1sf16447635obb.10 for ; Sat, 21 Dec 2013 13:08:24 -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:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=hry/nZz2eJIeXpEpV4mmH5sdKSoGpSumR23ui5z4PFQ=; b=gZgWr2hJ06YLwFMoFfp64oQaocw36fByFXrIvYpw1qRygMsnl19gCtww0aCD83visS iUOo9zxqS0m2RvuBoeV8MkkrrLr1886el4XaDvgLEkI1DsS4/WfWf9iUFp6cCef/N38h iEn8RBRcnNiDMntDlR8EdaZsYi12obPVEaxPmsKF6Q2loXMEhCufOl+r3xDxRa2P2+fA zML4IV72QZAsRykXpwc6vxbC84uV9NnoMAeQ2usOt5S+pfYxFtoCs9t/oREJHClQNDNc PeeR0JgjOiz5lrI7mrNgZt9rox0NcUcceIIb41f0+Jt1jVoYF0PrO0S5GVqQF3947Jxm DTAg== X-Gm-Message-State: ALoCoQnCc9fLCJOn6QNUZi4u+qMLWHe+goq3aM+eMigujZra82+11ovckJXf6v2pNbuYebMdiTB+ X-Received: by 10.42.197.136 with SMTP id ek8mr6196217icb.32.1387660103952; Sat, 21 Dec 2013 13:08:23 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.36.161 with SMTP id r1ls1092644qej.71.gmail; Sat, 21 Dec 2013 13:08:23 -0800 (PST) X-Received: by 10.220.199.5 with SMTP id eq5mr8835297vcb.16.1387660103831; Sat, 21 Dec 2013 13:08:23 -0800 (PST) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id v5si2894389ves.118.2013.12.21.13.08.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 21 Dec 2013 13:08:23 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.179 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.179; Received: by mail-ve0-f179.google.com with SMTP id jw12so2185251veb.38 for ; Sat, 21 Dec 2013 13:08:23 -0800 (PST) X-Received: by 10.220.58.1 with SMTP id e1mr8803957vch.0.1387660103591; Sat, 21 Dec 2013 13:08:23 -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 ey3csp143434ved; Sat, 21 Dec 2013 13:08:23 -0800 (PST) X-Received: by 10.180.95.162 with SMTP id dl2mr12844445wib.17.1387660102174; Sat, 21 Dec 2013 13:08:22 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id hp16si5161803wib.22.2013.12.21.13.08.21 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 21 Dec 2013 13:08:22 -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 1VuTmV-0005pb-K9; Sat, 21 Dec 2013 21:08:19 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Richard Henderson Subject: [PATCH v2] softfloat: Fix factor 2 error for scalbn on denormal inputs Date: Sat, 21 Dec 2013 21:08:19 +0000 Message-Id: <1387660099-22390-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 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.179 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 --- Changes v1->v2: propagated fix to 80 bit and 128 bit float functions. These function names remind me of Ken Thompson's reply to a question about what he'd do differently if he were redesigning UNIX: "I'd spell creat with an e." fpu/softfloat.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index dbda61b..7f5e8c7 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -6795,10 +6795,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; @@ -6828,10 +6831,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; @@ -6861,8 +6867,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; @@ -6891,10 +6901,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;