From nobody Wed Nov 5 22:16:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538118673756230.59798647519153; Fri, 28 Sep 2018 00:11:13 -0700 (PDT) Received: from localhost ([::1]:41724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5mvg-0000fN-Ei for importer@patchew.org; Fri, 28 Sep 2018 03:11:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41803) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5mu0-0006qe-Nd for qemu-devel@nongnu.org; Fri, 28 Sep 2018 03:09:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5mmT-0006Js-Lg for qemu-devel@nongnu.org; Fri, 28 Sep 2018 03:01:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42948) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5mmT-0006JN-E6 for qemu-devel@nongnu.org; Fri, 28 Sep 2018 03:01:41 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2CA72308212A; Fri, 28 Sep 2018 07:01:40 +0000 (UTC) Received: from thuth.com (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id E70F22010D62; Fri, 28 Sep 2018 07:01:38 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org, Peter Maydell Date: Fri, 28 Sep 2018 09:01:35 +0200 Message-Id: <1538118095-7003-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 28 Sep 2018 07:01:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] fpu/softfloat: Replace countLeadingZeros32/64 with clz32/64 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Our minimum required compiler for compiling QEMU is GCC 4.1 these days, so we can drop the support for compilers which do not provide the __builtin_clz*() functions yet. Since the countLeadingZeros32/64 are then identical to the clz32/64 functions, and we do not have to sync the softloat 2 codebase with upstream anymore (softloat 3 is a complete rewrite) we can simply replace the functions with our QEMU versions. Suggested-by: Peter Maydell Signed-off-by: Thomas Huth Acked-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- fpu/softfloat.c | 26 ++++++------- include/fpu/softfloat-macros.h | 87 --------------------------------------= ---- 2 files changed, 13 insertions(+), 100 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 8b91cd6..25a8dd9 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -2681,7 +2681,7 @@ static void { int8_t shiftCount; =20 - shiftCount =3D countLeadingZeros32( aSig ) - 8; + shiftCount =3D clz32(aSig) - 8; *zSigPtr =3D aSig<>( - shiftCount ); *zSig1Ptr =3D aSig1<<( shiftCount & 63 ); @@ -3306,7 +3306,7 @@ static void *zExpPtr =3D - shiftCount - 63; } else { - shiftCount =3D countLeadingZeros64( aSig0 ) - 15; + shiftCount =3D clz64(aSig0) - 15; shortShift128Left( aSig0, aSig1, shiftCount, zSig0Ptr, zSig1Ptr ); *zExpPtr =3D 1 - shiftCount; } @@ -3495,7 +3495,7 @@ static float128 normalizeRoundAndPackFloat128(flag zS= ign, int32_t zExp, zSig1 =3D 0; zExp -=3D 64; } - shiftCount =3D countLeadingZeros64( zSig0 ) - 15; + shiftCount =3D clz64(zSig0) - 15; if ( 0 <=3D shiftCount ) { zSig2 =3D 0; shortShift128Left( zSig0, zSig1, shiftCount, &zSig0, &zSig1 ); @@ -3527,7 +3527,7 @@ floatx80 int32_to_floatx80(int32_t a, float_status *s= tatus) if ( a =3D=3D 0 ) return packFloatx80( 0, 0, 0 ); zSign =3D ( a < 0 ); absA =3D zSign ? - a : a; - shiftCount =3D countLeadingZeros32( absA ) + 32; + shiftCount =3D clz32(absA) + 32; zSig =3D absA; return packFloatx80( zSign, 0x403E - shiftCount, zSig<=3D ((maj) << 16) + (min)) -#else -# define SOFTFLOAT_GNUC_PREREQ(maj, min) 0 -#endif - - -/*------------------------------------------------------------------------= ---- | Shifts `a' right by the number of bits given in `count'. If any nonzero | bits are shifted off, they are ``jammed'' into the least significant bit= of | the result by setting the least significant bit to 1. The value of `cou= nt' @@ -713,82 +702,6 @@ static inline uint32_t estimateSqrt32(int aExp, uint32= _t a) } =20 /*------------------------------------------------------------------------= ---- -| Returns the number of leading 0 bits before the most-significant 1 bit of -| `a'. If `a' is zero, 32 is returned. -*-------------------------------------------------------------------------= ---*/ - -static inline int8_t countLeadingZeros32(uint32_t a) -{ -#if SOFTFLOAT_GNUC_PREREQ(3, 4) - if (a) { - return __builtin_clz(a); - } else { - return 32; - } -#else - static const int8_t countLeadingZerosHigh[] =3D { - 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - int8_t shiftCount; - - shiftCount =3D 0; - if ( a < 0x10000 ) { - shiftCount +=3D 16; - a <<=3D 16; - } - if ( a < 0x1000000 ) { - shiftCount +=3D 8; - a <<=3D 8; - } - shiftCount +=3D countLeadingZerosHigh[ a>>24 ]; - return shiftCount; -#endif -} - -/*------------------------------------------------------------------------= ---- -| Returns the number of leading 0 bits before the most-significant 1 bit of -| `a'. If `a' is zero, 64 is returned. -*-------------------------------------------------------------------------= ---*/ - -static inline int8_t countLeadingZeros64(uint64_t a) -{ -#if SOFTFLOAT_GNUC_PREREQ(3, 4) - if (a) { - return __builtin_clzll(a); - } else { - return 64; - } -#else - int8_t shiftCount; - - shiftCount =3D 0; - if ( a < ( (uint64_t) 1 )<<32 ) { - shiftCount +=3D 32; - } - else { - a >>=3D 32; - } - shiftCount +=3D countLeadingZeros32( a ); - return shiftCount; -#endif -} - -/*------------------------------------------------------------------------= ---- | Returns 1 if the 128-bit value formed by concatenating `a0' and `a1' | is equal to the 128-bit value formed by concatenating `b0' and `b1'. | Otherwise, returns 0. --=20 1.8.3.1