From patchwork Mon Dec 6 17:00:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 74402 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 50A2FB6EED for ; Tue, 7 Dec 2010 04:17:51 +1100 (EST) Received: from localhost ([127.0.0.1]:39471 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPehA-0001Kq-B1 for incoming@patchwork.ozlabs.org; Mon, 06 Dec 2010 12:17:48 -0500 Received: from [140.186.70.92] (port=57001 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPeQG-0002Ph-LM for qemu-devel@nongnu.org; Mon, 06 Dec 2010 12:00:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPeQD-00063w-Vk for qemu-devel@nongnu.org; Mon, 06 Dec 2010 12:00:20 -0500 Received: from mnementh.archaic.org.uk ([81.2.115.146]:34388) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPeQD-00061v-K8 for qemu-devel@nongnu.org; Mon, 06 Dec 2010 12:00:17 -0500 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.69) (envelope-from ) id 1PPeQ7-0007mH-Tj for qemu-devel@nongnu.org; Mon, 06 Dec 2010 17:00:11 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 6 Dec 2010 17:00:07 +0000 Message-Id: <1291654811-29863-7-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1291654811-29863-1-git-send-email-peter.maydell@linaro.org> References: <1291654811-29863-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 06/10] softfloat: Add float*_maybe_silence_nan() functions 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 Add functions float*_maybe_silence_nan() which ensure that a value is not a signaling NaN by turning it into a quiet NaN. Signed-off-by: Peter Maydell Reviewed-by: Nathan Froyd --- fpu/softfloat-specialize.h | 38 ++++++++++++++++++++++++++++++++++++++ fpu/softfloat.h | 2 ++ 2 files changed, 40 insertions(+), 0 deletions(-) diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h index 8e6aceb..0746878 100644 --- a/fpu/softfloat-specialize.h +++ b/fpu/softfloat-specialize.h @@ -102,6 +102,25 @@ int float32_is_signaling_nan( float32 a_ ) } /*---------------------------------------------------------------------------- +| Returns a quiet NaN if the single-precision floating point value `a' is a +| signaling NaN; otherwise returns `a'. +*----------------------------------------------------------------------------*/ + +float32 float32_maybe_silence_nan( float32 a_ ) +{ + if (float32_is_signaling_nan(a_)) { + uint32_t a = float32_val(a_); +#if SNAN_BIT_IS_ONE + a &= ~(1 << 22); +#else + a |= (1 << 22); +#endif + return make_float32(a); + } + return a_; +} + +/*---------------------------------------------------------------------------- | Returns the result of converting the single-precision floating-point NaN | `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid | exception is raised. @@ -234,6 +253,25 @@ int float64_is_signaling_nan( float64 a_ ) } /*---------------------------------------------------------------------------- +| Returns a quiet NaN if the double-precision floating point value `a' is a +| signaling NaN; otherwise returns `a'. +*----------------------------------------------------------------------------*/ + +float64 float64_maybe_silence_nan( float64 a_ ) +{ + if (float64_is_signaling_nan(a_)) { + bits64 a = float64_val(a_); +#if SNAN_BIT_IS_ONE + a &= ~LIT64( 0x0008000000000000 ); +#else + a |= LIT64( 0x0008000000000000 ); +#endif + return make_float64(a); + } + return a_; +} + +/*---------------------------------------------------------------------------- | Returns the result of converting the double-precision floating-point NaN | `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid | exception is raised. diff --git a/fpu/softfloat.h b/fpu/softfloat.h index 9bece80..2e651e2 100644 --- a/fpu/softfloat.h +++ b/fpu/softfloat.h @@ -287,6 +287,7 @@ int float32_compare( float32, float32 STATUS_PARAM ); int float32_compare_quiet( float32, float32 STATUS_PARAM ); int float32_is_nan( float32 ); int float32_is_signaling_nan( float32 ); +float32 float32_maybe_silence_nan( float32 ); float32 float32_scalbn( float32, int STATUS_PARAM ); INLINE float32 float32_abs(float32 a) @@ -364,6 +365,7 @@ int float64_compare( float64, float64 STATUS_PARAM ); int float64_compare_quiet( float64, float64 STATUS_PARAM ); int float64_is_nan( float64 a ); int float64_is_signaling_nan( float64 ); +float64 float64_maybe_silence_nan( float64 ); float64 float64_scalbn( float64, int STATUS_PARAM ); INLINE float64 float64_abs(float64 a)