From patchwork Thu Feb 10 11:28:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 82597 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 954CFB70E3 for ; Thu, 10 Feb 2011 22:52:20 +1100 (EST) Received: from localhost ([127.0.0.1]:56024 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PnUuP-0002vI-K5 for incoming@patchwork.ozlabs.org; Thu, 10 Feb 2011 06:42:01 -0500 Received: from [140.186.70.92] (port=33430 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PnUtj-0002nO-2o for qemu-devel@nongnu.org; Thu, 10 Feb 2011 06:41:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PnUtP-0001PJ-0Q for qemu-devel@nongnu.org; Thu, 10 Feb 2011 06:41:00 -0500 Received: from mnementh.archaic.org.uk ([81.2.115.146]:15475) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PnUtO-0001PB-JZ for qemu-devel@nongnu.org; Thu, 10 Feb 2011 06:40:58 -0500 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.69) (envelope-from ) id 1PnUhp-0002oy-HK; Thu, 10 Feb 2011 11:29:01 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 10 Feb 2011 11:28:59 +0000 Message-Id: <1297337341-10815-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1297337341-10815-1-git-send-email-peter.maydell@linaro.org> References: <1297337341-10815-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 81.2.115.146 Cc: Christophe Lyon , patches@linaro.org Subject: [Qemu-devel] [PATCH v3 4/6] softfloat: Correctly handle NaNs in float16_to_float32() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.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 --- 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 1c0b12b..2d025bf 100644 --- a/fpu/softfloat-specialize.h +++ b/fpu/softfloat-specialize.h @@ -120,6 +120,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 = float16_val(a) >> 15; + z.low = 0; + z.high = ((bits64) float16_val(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 80d8cc4..3abd170 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -2761,9 +2761,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); }