From patchwork Tue Nov 25 14:17:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 41467 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 43B4A25E72 for ; Tue, 25 Nov 2014 14:17:53 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf627433eek.9 for ; Tue, 25 Nov 2014 06:17:52 -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=peLRBitzTExeLvocNL3SlBiK6p3OssID3SyNXZJGDyU=; b=iUqvKUfQa0LlyjsdJzcpUyw0ypgugRAWeKAeZPYKzKZpgW8kRiOu1/5cAOy8d4KW18 TqAaxopKF9z6CiWTnq6RkiVtvhIGsXu7V3J/qrpwOI9wU3LOFUUMPk17AkE1A9e9Ac16 yAId9DyzgOwQWPahWKygphix75x4jLrEl0LFmOU6GWoG0v3SGQaSrCPLxocFLgZXj7q0 REtmjf2aFeX6eavJpSYLFO44uWpVibOdnEvbna701yDpKkmaA6+38RCWkhqkX5unXSEq iiRCRhsbNQNlbTHsiu1hOLppcDTgLNLQUk/yZ64TPNTJpqvNRyNyrsgJZ4NQ6SL0inei MLdg== X-Gm-Message-State: ALoCoQmyEN4Vn9bUjdfASoFiPTW007f5Y+g+E9B+xM/wkKYeCZfm0KYfDqqI8/pha4cnv9dGN2Sd X-Received: by 10.181.13.147 with SMTP id ey19mr5607808wid.2.1416925072550; Tue, 25 Nov 2014 06:17:52 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.11.163 with SMTP id ej3ls544195lad.94.gmail; Tue, 25 Nov 2014 06:17:52 -0800 (PST) X-Received: by 10.112.125.4 with SMTP id mm4mr18584050lbb.94.1416925072193; Tue, 25 Nov 2014 06:17:52 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id t15si1452933laz.105.2014.11.25.06.17.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Nov 2014 06:17:52 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id w7so606446lbi.19 for ; Tue, 25 Nov 2014 06:17:52 -0800 (PST) X-Received: by 10.112.189.10 with SMTP id ge10mr26867564lbc.23.1416925072087; Tue, 25 Nov 2014 06:17:52 -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.112.184.201 with SMTP id ew9csp441241lbc; Tue, 25 Nov 2014 06:17:51 -0800 (PST) X-Received: by 10.152.28.193 with SMTP id d1mr27052314lah.17.1416925070930; Tue, 25 Nov 2014 06:17:50 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id j1si1456789lam.100.2014.11.25.06.17.50 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 25 Nov 2014 06:17:50 -0800 (PST) Received-SPF: none (google.com: pm215@archaic.org.uk does not designate permitted sender hosts) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1XtGvy-0000Bx-3C; Tue, 25 Nov 2014 14:17:38 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Anthony Liguori , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Aurelien Jarno , Avi Kivity , Ben Taylor , Blue Swirl , Christophe Lyon , Fabrice Bellard , Guan Xuetao , Juan Quintela , Max Filippov , Paul Brook , Paolo Bonzini , Peter Maydell , Richard Henderson , Richard Sandiford , Stefan Weil Subject: [PATCH 5/6] softfloat: reimplement SNAN_BIT_IS_ONE support Date: Tue, 25 Nov 2014 14:17:36 +0000 Message-Id: <1416925057-692-6-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1416925057-692-1-git-send-email-peter.maydell@linaro.org> References: <1416925057-692-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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) 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: , Reimplement support for architectures where the most significant bit in the mantissa is 1 for a signaling NaN rather than a quiet NaN, by adding handling for SNAN_BIT_IS_ONE being set to the functions which test values for NaN-ness. This includes restoring the bugfixes lost in the reversion where some of the float*_is_quiet_nan() functions were returning true for both signaling and quiet NaNs. Signed-off-by: Peter Maydell --- fpu/softfloat-specialize.h | 74 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h index 187cdf6..6de66ce 100644 --- a/fpu/softfloat-specialize.h +++ b/fpu/softfloat-specialize.h @@ -33,6 +33,16 @@ this code that are retained. =============================================================================== */ +/* Does the target distinguish signaling NaNs from non-signaling NaNs + * by setting the most significant bit of the mantissa for a signaling NaN? + * (The more common choice is to have it be zero for SNaN and one for QNaN.) + */ +#if defined(TARGET_MIPS) || defined(TARGET_SH4) || defined(TARGET_UNICORE32) +#define SNAN_BIT_IS_ONE 1 +#else +#define SNAN_BIT_IS_ONE 0 +#endif + #if defined(TARGET_XTENSA) /* Define for architectures which deviate from IEEE in not supporting * signaling NaNs (so all NaNs are treated as quiet). @@ -59,6 +69,8 @@ const float32 float32_default_nan = const_float32(0x7FFFFFFF); #elif defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA) || \ defined(TARGET_XTENSA) const float32 float32_default_nan = const_float32(0x7FC00000); +#elif SNAN_BIT_IS_ONE +const float32 float32_default_nan = const_float32(0xFF800000); #else const float32 float32_default_nan = const_float32(0xFFC00000); #endif @@ -70,6 +82,8 @@ const float32 float32_default_nan = const_float32(0xFFC00000); const float64 float64_default_nan = const_float64(LIT64( 0x7FFFFFFFFFFFFFFF )); #elif defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA) const float64 float64_default_nan = const_float64(LIT64( 0x7FF8000000000000 )); +#elif SNAN_BIT_IS_ONE +const float64 float64_default_nan = const_float64(LIT64(0xFFF0000000000000)); #else const float64 float64_default_nan = const_float64(LIT64( 0xFFF8000000000000 )); #endif @@ -77,8 +91,13 @@ const float64 float64_default_nan = const_float64(LIT64( 0xFFF8000000000000 )); /*---------------------------------------------------------------------------- | The pattern for a default generated extended double-precision NaN. *----------------------------------------------------------------------------*/ +#if SNAN_BIT_IS_ONE +#define floatx80_default_nan_high 0xFFFF +#define floatx80_default_nan_low LIT64(0x8000000000000000) +#else #define floatx80_default_nan_high 0xFFFF #define floatx80_default_nan_low LIT64( 0xC000000000000000 ) +#endif const floatx80 floatx80_default_nan = make_floatx80_init(floatx80_default_nan_high, floatx80_default_nan_low); @@ -87,8 +106,13 @@ const floatx80 floatx80_default_nan | The pattern for a default generated quadruple-precision NaN. The `high' and | `low' values hold the most- and least-significant bits, respectively. *----------------------------------------------------------------------------*/ +#if SNAN_BIT_IS_ONE +#define float128_default_nan_high LIT64(0xFFFF000000000000) +#define float128_default_nan_low LIT64(0x0000000000000000) +#else #define float128_default_nan_high LIT64( 0xFFFF800000000000 ) #define float128_default_nan_low LIT64( 0x0000000000000000 ) +#endif const float128 float128_default_nan = make_float128_init(float128_default_nan_high, float128_default_nan_low); @@ -234,7 +258,11 @@ int float32_is_signaling_nan(float32 a_) int float32_is_quiet_nan( float32 a_ ) { uint32_t a = float32_val(a_); - return ( 0xFF000000 <= (uint32_t) ( a<<1 ) ); +#if SNAN_BIT_IS_ONE + return (((a >> 22) & 0x1ff) == 0x1fe) && (a & 0x003fffff); +#else + return ((uint32_t)(a << 1) >= 0xff800000); +#endif } /*---------------------------------------------------------------------------- @@ -245,7 +273,11 @@ int float32_is_quiet_nan( float32 a_ ) int float32_is_signaling_nan( float32 a_ ) { uint32_t a = float32_val(a_); +#if SNAN_BIT_IS_ONE + return ((uint32_t)(a << 1) >= 0xff800000); +#else return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF ); +#endif } #endif @@ -634,7 +666,12 @@ int float64_is_signaling_nan(float64 a_) int float64_is_quiet_nan( float64 a_ ) { uint64_t a = float64_val(a_); - return ( LIT64( 0xFFE0000000000000 ) <= (uint64_t) ( a<<1 ) ); +#if SNAN_BIT_IS_ONE + return (((a >> 51) & 0xfff) == 0xffe) + && (a & 0x0007ffffffffffffULL); +#else + return ((a << 1) >= 0xfff0000000000000ULL); +#endif } /*---------------------------------------------------------------------------- @@ -645,9 +682,13 @@ int float64_is_quiet_nan( float64 a_ ) int float64_is_signaling_nan( float64 a_ ) { uint64_t a = float64_val(a_); +#if SNAN_BIT_IS_ONE + return ((a << 1) >= 0xfff0000000000000ULL); +#else return ( ( ( a>>51 ) & 0xFFF ) == 0xFFE ) && ( a & LIT64( 0x0007FFFFFFFFFFFF ) ); +#endif } #endif @@ -823,8 +864,17 @@ int floatx80_is_signaling_nan(floatx80 a_) int floatx80_is_quiet_nan( floatx80 a ) { +#if SNAN_BIT_IS_ONE + uint64_t aLow; + + aLow = a.low & ~0x4000000000000000ULL; + return ((a.high & 0x7fff) == 0x7fff) + && (aLow << 1) + && (a.low == aLow); +#else return ( ( a.high & 0x7FFF ) == 0x7FFF ) && (LIT64( 0x8000000000000000 ) <= ((uint64_t) ( a.low<<1 ))); +#endif } /*---------------------------------------------------------------------------- @@ -835,6 +885,10 @@ int floatx80_is_quiet_nan( floatx80 a ) int floatx80_is_signaling_nan( floatx80 a ) { +#if SNAN_BIT_IS_ONE + return ((a.high & 0x7fff) == 0x7fff) + && ((a.low << 1) >= 0x8000000000000000ULL); +#else uint64_t aLow; aLow = a.low & ~ LIT64( 0x4000000000000000 ); @@ -842,6 +896,7 @@ int floatx80_is_signaling_nan( floatx80 a ) ( ( a.high & 0x7FFF ) == 0x7FFF ) && (uint64_t) ( aLow<<1 ) && ( a.low == aLow ); +#endif } #endif @@ -975,9 +1030,14 @@ int float128_is_signaling_nan(float128 a_) int float128_is_quiet_nan( float128 a ) { +#if SNAN_BIT_IS_ONE + return (((a.high >> 47) & 0xffff) == 0xfffe) + && (a.low || (a.high & 0x00007fffffffffffULL)); +#else return - ( LIT64( 0xFFFE000000000000 ) <= (uint64_t) ( a.high<<1 ) ) - && ( a.low || ( a.high & LIT64( 0x0000FFFFFFFFFFFF ) ) ); + ((a.high << 1) >= 0xffff000000000000) + && (a.low || (a.high & 0x0000ffffffffffffULL)); +#endif } /*---------------------------------------------------------------------------- @@ -987,9 +1047,15 @@ int float128_is_quiet_nan( float128 a ) int float128_is_signaling_nan( float128 a ) { +#if SNAN_BIT_IS_ONE + return + ((a.high << 1) >= 0xffff000000000000) + && (a.low || (a.high & 0x0000ffffffffffffULL)); +#else return ( ( ( a.high>>47 ) & 0xFFFF ) == 0xFFFE ) && ( a.low || ( a.high & LIT64( 0x00007FFFFFFFFFFF ) ) ); +#endif } #endif