From nobody Fri Nov 7 13:01:38 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; dkim=fail; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538763673035771.1309644480203; Fri, 5 Oct 2018 11:21:13 -0700 (PDT) Received: from localhost ([::1]:36493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g8Uio-00036w-Q8 for importer@patchew.org; Fri, 05 Oct 2018 14:21:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g8UQd-0000U1-4E for qemu-devel@nongnu.org; Fri, 05 Oct 2018 14:02:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g8UQZ-0004Cq-As for qemu-devel@nongnu.org; Fri, 05 Oct 2018 14:02:17 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]:41009) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g8UQY-00046m-SC for qemu-devel@nongnu.org; Fri, 05 Oct 2018 14:02:15 -0400 Received: by mail-oi1-x234.google.com with SMTP id l197-v6so11096620oib.8 for ; Fri, 05 Oct 2018 11:02:14 -0700 (PDT) Received: from cloudburst.twiddle.net ([187.217.230.84]) by smtp.gmail.com with ESMTPSA id d37-v6sm2601302otb.0.2018.10.05.11.02.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 05 Oct 2018 11:02:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DwGVwZ74JFosJt80rbYq2MM2myPeHP9EtmhcPJDQx9A=; b=SMVivl8nZuNqVBj7CV4cAnTSWn0BIsrv3tSDsvJtJ3WlZFngNPlYjW59XGE/ZqRyOa P9eBiO4mBP887C88xbZ5JL4T0LXc9Hp/HY7y2m80WyTU4aQfD2Uaac1fUWGEYDH3rg5V +M2Ewkc7V9Qd6aebLxhGn8WkZfAjBqoEiH/vY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DwGVwZ74JFosJt80rbYq2MM2myPeHP9EtmhcPJDQx9A=; b=j80dF51NGOKn2fA8K20dzZepaewZtrUQhB+uDr8tjVzkbYjMQ8yMdfPzJHs9E4Tf6y j58b/wJexrGsUDgbTIwPUPZKiFiieHC9AZabiCw5ukATajbkuUo3s92+hIHryCLzJGsU EaBjFzJFBzomMmvGkg3gQZ4Oa7o4JqpjU6eaz759KVuVT2zBVWD3tSrJfhBqaIGz+Fuu F/ObRJbVccbeAFXcz48uxU2kXJ63VVDeeCAZLgy1K77KAoXLIIeUmS6RuwS3Auqbm5ih O+D1Zn0hyezu9RjuglhF2ivRNhYX8wKnQLnbnRcimbpqVTinioo/QwPU221uVi6puTJD Omuw== X-Gm-Message-State: ABuFfoib/u6Ehl8NslSqY2vNbA5CMjbv/tqi2a5KWOMJaNscV1t1vU1f gJhnqIWwVfvyNVF3lEXGOB6MR0Et3wUMm7fujyk= X-Google-Smtp-Source: ACcGV62b2kPKutMUAxFkvbJzxBFkD6Cpr7l4NPDXrZzlGJf8bIYCsBzm4wUL3Ol9riaN4uXM9VOuFQ== X-Received: by 2002:aca:50c1:: with SMTP id e184-v6mr35039oib.264.1538762533644; Fri, 05 Oct 2018 11:02:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 5 Oct 2018 13:01:57 -0500 Message-Id: <20181005180201.11387-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181005180201.11387-1-richard.henderson@linaro.org> References: <20181005180201.11387-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::234 Subject: [Qemu-devel] [PULL 4/8] 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: peter.maydell@linaro.org, Thomas Huth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 From: Thomas Huth 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 Acked-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Thomas Huth Message-Id: <1538118095-7003-1-git-send-email-thuth@redhat.com> Signed-off-by: Richard Henderson --- include/fpu/softfloat-macros.h | 87 ---------------------------------- fpu/softfloat.c | 26 +++++----- 2 files changed, 13 insertions(+), 100 deletions(-) diff --git a/include/fpu/softfloat-macros.h b/include/fpu/softfloat-macros.h index 35e1603a5e..edc682139e 100644 --- a/include/fpu/softfloat-macros.h +++ b/include/fpu/softfloat-macros.h @@ -79,17 +79,6 @@ this code that are retained. * version 2 or later. See the COPYING file in the top-level directory. */ =20 -/*------------------------------------------------------------------------= ---- -| This macro tests for minimum version of the GNU C compiler. -*-------------------------------------------------------------------------= ---*/ -#if defined(__GNUC__) && defined(__GNUC_MINOR__) -# define SOFTFLOAT_GNUC_PREREQ(maj, min) \ - ((__GNUC__ << 16) + __GNUC_MINOR__ >=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 @@ -712,82 +701,6 @@ static inline uint32_t estimateSqrt32(int aExp, uint32= _t a) =20 } =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'. diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 9405f12a03..71da0f68bb 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -2683,7 +2683,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 ); @@ -3308,7 +3308,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; } @@ -3497,7 +3497,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 ); @@ -3529,7 +3529,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<