From patchwork Tue Dec 9 01:55:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 418934 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2C9981400DE for ; Tue, 9 Dec 2014 12:58:23 +1100 (AEDT) Received: from localhost ([::1]:37318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XyA4D-0004Aw-C4 for incoming@patchwork.ozlabs.org; Mon, 08 Dec 2014 20:58:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XyA1t-0000VP-1p for qemu-devel@nongnu.org; Mon, 08 Dec 2014 20:56:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XyA1k-0004xg-JQ for qemu-devel@nongnu.org; Mon, 08 Dec 2014 20:55:56 -0500 Received: from relay1.mentorg.com ([192.94.38.131]:48496) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XyA1k-0004x4-CF for qemu-devel@nongnu.org; Mon, 08 Dec 2014 20:55:48 -0500 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-03.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1XyA1j-0000br-FB from Maciej_Rozycki@mentor.com ; Mon, 08 Dec 2014 17:55:47 -0800 Received: from localhost (137.202.0.76) by SVR-IES-FEM-03.mgc.mentorg.com (137.202.0.108) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 9 Dec 2014 01:55:45 +0000 Date: Tue, 9 Dec 2014 01:55:41 +0000 From: "Maciej W. Rozycki" To: In-Reply-To: Message-ID: References: User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 Cc: Leon Alrae , Thomas Schwinge , Aurelien Jarno Subject: [Qemu-devel] [PATCH 5/7] softfloat: Rework `*_is_*_nan' functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Precompute the possible results, and then pick the suitable one. The calculation of the unused result will be optimized away by the compiler at any reasonable optimization level, so no run-time performance loss. Signed-off-by: Thomas Schwinge Signed-off-by: Maciej W. Rozycki --- qemu-softfloat-nan-precompute.diff Index: qemu-git-trunk/fpu/softfloat-specialize.h =================================================================== --- qemu-git-trunk.orig/fpu/softfloat-specialize.h 2014-12-01 21:58:05.937673826 +0000 +++ qemu-git-trunk/fpu/softfloat-specialize.h 2014-12-01 22:58:50.328200913 +0000 @@ -159,10 +159,13 @@ int float16_is_signaling_nan(float16 a_ int float16_is_quiet_nan(float16 a_ STATUS_PARAM) { uint16_t a = float16_val(a_); + int __attribute__ ((unused)) x, y; + x = (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF); + y = (a & ~0x8000) >= 0x7c80; #if SNAN_BIT_IS_ONE - return (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF); + return x; #else - return ((a & ~0x8000) >= 0x7c80); + return y; #endif } @@ -174,10 +177,13 @@ int float16_is_quiet_nan(float16 a_ STAT int float16_is_signaling_nan(float16 a_ STATUS_PARAM) { uint16_t a = float16_val(a_); + int __attribute__ ((unused)) x, y; + x = (a & ~0x8000) >= 0x7c80; + y = (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF); #if SNAN_BIT_IS_ONE - return ((a & ~0x8000) >= 0x7c80); + return x; #else - return (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF); + return y; #endif } #endif @@ -263,10 +269,13 @@ int float32_is_signaling_nan(float32 a_ int float32_is_quiet_nan(float32 a_ STATUS_PARAM) { uint32_t a = float32_val(a_); + int __attribute__ ((unused)) x, y; + x = (((a >> 22) & 0x1FF) == 0x1FE) && (a & 0x003FFFFF); + y = 0xFF800000 <= (uint32_t) (a << 1); #if SNAN_BIT_IS_ONE - return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF ); + return x; #else - return ( 0xFF800000 <= (uint32_t) ( a<<1 ) ); + return y; #endif } @@ -278,10 +287,13 @@ int float32_is_quiet_nan(float32 a_ STAT int float32_is_signaling_nan(float32 a_ STATUS_PARAM) { uint32_t a = float32_val(a_); + int __attribute__ ((unused)) x, y; + x = 0xFF800000 <= (uint32_t) (a << 1); + y = (((a >> 22) & 0x1FF) == 0x1FE) && (a & 0x003FFFFF); #if SNAN_BIT_IS_ONE - return ( 0xFF800000 <= (uint32_t) ( a<<1 ) ); + return x; #else - return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF ); + return y; #endif } #endif @@ -673,12 +685,13 @@ int float64_is_signaling_nan(float64 a_ int float64_is_quiet_nan(float64 a_ STATUS_PARAM) { uint64_t a = float64_val(a_); + int __attribute__ ((unused)) x, y; + x = (((a >> 51) & 0xFFF) == 0xFFE) && (a & LIT64(0x0007FFFFFFFFFFFF)); + y = LIT64(0xFFF0000000000000) <= (uint64_t) (a << 1); #if SNAN_BIT_IS_ONE - return - ( ( ( a>>51 ) & 0xFFF ) == 0xFFE ) - && ( a & LIT64( 0x0007FFFFFFFFFFFF ) ); + return x; #else - return ( LIT64( 0xFFF0000000000000 ) <= (uint64_t) ( a<<1 ) ); + return y; #endif } @@ -690,12 +703,13 @@ int float64_is_quiet_nan(float64 a_ STAT int float64_is_signaling_nan(float64 a_ STATUS_PARAM) { uint64_t a = float64_val(a_); + int __attribute__ ((unused)) x, y; + x = LIT64(0xFFF0000000000000) <= (uint64_t) (a << 1); + y = (((a >> 51) & 0xFFF) == 0xFFE) && (a & LIT64(0x0007FFFFFFFFFFFF)); #if SNAN_BIT_IS_ONE - return ( LIT64( 0xFFF0000000000000 ) <= (uint64_t) ( a<<1 ) ); + return x; #else - return - ( ( ( a>>51 ) & 0xFFF ) == 0xFFE ) - && ( a & LIT64( 0x0007FFFFFFFFFFFF ) ); + return y; #endif } #endif @@ -874,17 +888,18 @@ int floatx80_is_signaling_nan(floatx80 a int floatx80_is_quiet_nan(floatx80 a STATUS_PARAM) { -#if SNAN_BIT_IS_ONE uint64_t aLow; - - aLow = a.low & ~ LIT64( 0x4000000000000000 ); - return - ( ( a.high & 0x7FFF ) == 0x7FFF ) - && (uint64_t) ( aLow<<1 ) - && ( a.low == aLow ); + int __attribute__ ((unused)) x, y; + aLow = a.low & ~LIT64(0x4000000000000000); + x = (((a.high & 0x7FFF) == 0x7FFF) + && (uint64_t) (aLow << 1) + && (a.low == aLow)); + y = (((a.high & 0x7FFF) == 0x7FFF) + && (LIT64(0x8000000000000000) <= ((uint64_t) (a.low << 1)))); +#if SNAN_BIT_IS_ONE + return x; #else - return ( ( a.high & 0x7FFF ) == 0x7FFF ) - && (LIT64( 0x8000000000000000 ) <= ((uint64_t) ( a.low<<1 ))); + return y; #endif } @@ -896,17 +911,18 @@ int floatx80_is_quiet_nan(floatx80 a STA int floatx80_is_signaling_nan(floatx80 a STATUS_PARAM) { + uint64_t aLow; + int __attribute__ ((unused)) x, y; + aLow = a.low & ~LIT64(0x4000000000000000); + x = (((a.high & 0x7FFF) == 0x7FFF) + && (LIT64(0x8000000000000000) <= ((uint64_t) (a.low << 1)))); + y = (((a.high & 0x7FFF) == 0x7FFF) + && (uint64_t) (aLow << 1) + && (a.low == aLow)); #if SNAN_BIT_IS_ONE - return ( ( a.high & 0x7FFF ) == 0x7FFF ) - && (LIT64( 0x8000000000000000 ) <= ((uint64_t) ( a.low<<1 ))); + return x; #else - uint64_t aLow; - - aLow = a.low & ~ LIT64( 0x4000000000000000 ); - return - ( ( a.high & 0x7FFF ) == 0x7FFF ) - && (uint64_t) ( aLow<<1 ) - && ( a.low == aLow ); + return y; #endif } #endif @@ -1035,14 +1051,15 @@ int float128_is_signaling_nan(float128 a int float128_is_quiet_nan(float128 a STATUS_PARAM) { + int __attribute__ ((unused)) x, y; + x = ((((a.high >> 47) & 0xFFFF) == 0xFFFE) + && (a.low || (a.high & LIT64(0x00007FFFFFFFFFFF)))); + y = ((LIT64(0xFFFE000000000000) <= (uint64_t) (a.high << 1)) + && (a.low || (a.high & LIT64(0x0000FFFFFFFFFFFF)))); #if SNAN_BIT_IS_ONE - return - ( ( ( a.high>>47 ) & 0xFFFF ) == 0xFFFE ) - && ( a.low || ( a.high & LIT64( 0x00007FFFFFFFFFFF ) ) ); + return x; #else - return - ( LIT64( 0xFFFE000000000000 ) <= (uint64_t) ( a.high<<1 ) ) - && ( a.low || ( a.high & LIT64( 0x0000FFFFFFFFFFFF ) ) ); + return y; #endif } @@ -1053,14 +1070,15 @@ int float128_is_quiet_nan(float128 a STA int float128_is_signaling_nan(float128 a STATUS_PARAM) { + int __attribute__ ((unused)) x, y; + x = ((LIT64(0xFFFE000000000000) <= (uint64_t) (a.high << 1)) + && (a.low || (a.high & LIT64(0x0000FFFFFFFFFFFF)))); + y = ((((a.high >> 47) & 0xFFFF) == 0xFFFE) + && (a.low || (a.high & LIT64(0x00007FFFFFFFFFFF)))); #if SNAN_BIT_IS_ONE - return - ( LIT64( 0xFFFE000000000000 ) <= (uint64_t) ( a.high<<1 ) ) - && ( a.low || ( a.high & LIT64( 0x0000FFFFFFFFFFFF ) ) ); + return x; #else - return - ( ( ( a.high>>47 ) & 0xFFFF ) == 0xFFFE ) - && ( a.low || ( a.high & LIT64( 0x00007FFFFFFFFFFF ) ) ); + return y; #endif } #endif