From patchwork Wed Feb 9 16:27:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 99 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:39:57 -0000 Delivered-To: patches@linaro.org Received: by 10.147.124.5 with SMTP id b5cs149915yan; Wed, 9 Feb 2011 08:27:33 -0800 (PST) Received: by 10.103.165.4 with SMTP id s4mr14663646muo.25.1297268853006; Wed, 09 Feb 2011 08:27:33 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk [81.2.115.146]) by mx.google.com with ESMTPS id b40si938456wek.49.2011.02.09.08.27.32 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 09 Feb 2011 08:27:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.69) (envelope-from ) id 1PnCt8-0001Vi-Hi; Wed, 09 Feb 2011 16:27:30 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Christophe Lyon Subject: [PATCH v2 4/6] softfloat: Correctly handle NaNs in float16_to_float32() Date: Wed, 9 Feb 2011 16:27:28 +0000 Message-Id: <1297268850-5777-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1297268850-5777-1-git-send-email-peter.maydell@linaro.org> References: <1297268850-5777-1-git-send-email-peter.maydell@linaro.org> Correctly handle NaNs in float16_to_float32(), by defining and using a float16ToCommonNaN() function, as we do with the other formats. Signed-off-by: Peter Maydell Reviewed-by: Aurelien Jarno --- fpu/softfloat-specialize.h | 17 +++++++++++++++++ fpu/softfloat.c | 4 +--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h index 4907484..af82359 100644 --- a/fpu/softfloat-specialize.h +++ b/fpu/softfloat-specialize.h @@ -116,6 +116,23 @@ float16 float16_maybe_silence_nan(float16 a) } /*---------------------------------------------------------------------------- +| Returns the result of converting the half-precision floating-point NaN +| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid +| exception is raised. +*----------------------------------------------------------------------------*/ + +static commonNaNT float16ToCommonNaN( float16 a STATUS_PARAM ) +{ + commonNaNT z; + + if ( float16_is_signaling_nan( a ) ) float_raise( float_flag_invalid STATUS_VAR ); + z.sign = a >> 15; + z.low = 0; + z.high = ((bits64) a)<<54; + return z; +} + +/*---------------------------------------------------------------------------- | Returns the result of converting the canonical NaN `a' to the half- | precision floating-point format. *----------------------------------------------------------------------------*/ diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 4d51428..735db38 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -2733,9 +2733,7 @@ float32 float16_to_float32(float16 a, flag ieee STATUS_PARAM) if (aExp == 0x1f && ieee) { if (aSig) { - /* Make sure correct exceptions are raised. */ - float32ToCommonNaN(a STATUS_VAR); - aSig |= 0x200; + return commonNaNToFloat32(float16ToCommonNaN(a STATUS_VAR) STATUS_VAR); } return packFloat32(aSign, 0xff, aSig << 13); }