From patchwork Fri Oct 5 18:01:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 148295 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp771059lji; Fri, 5 Oct 2018 11:20:22 -0700 (PDT) X-Google-Smtp-Source: ACcGV611/N6mC2RfHxpl8f/kjSBJJ2ri3ExUiYQYHNIw3vQLrDYcFdm1HMX5FiDEkom8FHgf+CBh X-Received: by 2002:a37:a512:: with SMTP id o18-v6mr9695908qke.232.1538763622170; Fri, 05 Oct 2018 11:20:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538763622; cv=none; d=google.com; s=arc-20160816; b=q+NTayhHseNXc3lxPNARtPa75KSh57xnNrnt4OoUxxjIGkqA0UD/dna9opLE0E4b3d iN31Tm2mT6Ro9+8WHTRfmel0eFfywdwI1hnjGY0zlmeFmodqayM83JXcYusNYnAYE2nV GFC5RgTZulkXhqzcTEI5+0ywGgHa+0Q5A0CWyocMVgL6D97jzy+KkRGPFNxt2NKVWrpw ItvtzfMwWAYBoPQfBOfULhKITlAhceiomSLjGb4xin+CMcikzU9Ym+CyI7QD/+FKp6lk r2MiD5v71kpA9RE9chrw+6253TThvX34sNozyPCm4O0g5fZ1ZztIGD2S//gwgl/6u8cf 9wDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=DwGVwZ74JFosJt80rbYq2MM2myPeHP9EtmhcPJDQx9A=; b=zhMjoWevZ+CmooKk39YB0Op1mbUwokPEDo//xSixGoOv5e3u7JvsH/KrzT6xgC+7+s KEwAZF/gp8aYPfsDe3v+5BiMjCtcb4EOr9it8N2Bv232AOKcgs7qGpkuNy9yxo6/21n6 zZZsRtbbtWY0bsuY+RFC75hf5zxF48iDxlGfZfVB299bXuUy8p9dAnPnCRiL/qSORI0q PlSSALf2R77AZF09Ro6u66ps90owLJfvMMntCa4WzLbUrFSL93CIkwSKXK3h867GxRUX 6NO1k8WQfQoDyAG2/nLNwMZO6bkKn/4CFhExrZpXnHE5BCAUXJEJKgZq0LbKryd5nGll kknQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SMVivl8n; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d188-v6si363063qkc.57.2018.10.05.11.20.21 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 05 Oct 2018 11:20:22 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SMVivl8n; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36489 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g8Ui5-0002Y3-Jh for patch@linaro.org; Fri, 05 Oct 2018 14:20:21 -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) 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-Received: by 2002:aca:50c1:: with SMTP id e184-v6mr35039oib.264.1538762533644; Fri, 05 Oct 2018 11:02:13 -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) 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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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ée Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé 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(-) -- 2.17.1 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. */ -/*---------------------------------------------------------------------------- -| 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__ >= ((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) } -/*---------------------------------------------------------------------------- -| 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[] = { - 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 = 0; - if ( a < 0x10000 ) { - shiftCount += 16; - a <<= 16; - } - if ( a < 0x1000000 ) { - shiftCount += 8; - a <<= 8; - } - shiftCount += 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 = 0; - if ( a < ( (uint64_t) 1 )<<32 ) { - shiftCount += 32; - } - else { - a >>= 32; - } - shiftCount += 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; - shiftCount = countLeadingZeros32( aSig ) - 8; + shiftCount = clz32(aSig) - 8; *zSigPtr = aSig<>( - shiftCount ); *zSig1Ptr = aSig1<<( shiftCount & 63 ); @@ -3308,7 +3308,7 @@ static void *zExpPtr = - shiftCount - 63; } else { - shiftCount = countLeadingZeros64( aSig0 ) - 15; + shiftCount = clz64(aSig0) - 15; shortShift128Left( aSig0, aSig1, shiftCount, zSig0Ptr, zSig1Ptr ); *zExpPtr = 1 - shiftCount; } @@ -3497,7 +3497,7 @@ static float128 normalizeRoundAndPackFloat128(flag zSign, int32_t zExp, zSig1 = 0; zExp -= 64; } - shiftCount = countLeadingZeros64( zSig0 ) - 15; + shiftCount = clz64(zSig0) - 15; if ( 0 <= shiftCount ) { zSig2 = 0; shortShift128Left( zSig0, zSig1, shiftCount, &zSig0, &zSig1 ); @@ -3529,7 +3529,7 @@ floatx80 int32_to_floatx80(int32_t a, float_status *status) if ( a == 0 ) return packFloatx80( 0, 0, 0 ); zSign = ( a < 0 ); absA = zSign ? - a : a; - shiftCount = countLeadingZeros32( absA ) + 32; + shiftCount = clz32(absA) + 32; zSig = absA; return packFloatx80( zSign, 0x403E - shiftCount, zSig<