From patchwork Fri Dec 6 13:19:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 22126 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f72.google.com (mail-pb0-f72.google.com [209.85.160.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2A09B23A4E for ; Fri, 6 Dec 2013 13:19:34 +0000 (UTC) Received: by mail-pb0-f72.google.com with SMTP id jt11sf2904587pbb.3 for ; Fri, 06 Dec 2013 05:19:33 -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=fj5pho051XLRoncDLtkrLbca8XXTAYUbPEWjW4I+1X8=; b=QRPx4QXBAboPeBoWSj0sYDMvBw47qR4ZRxlCuTe8hbdq4Ax+5RPE1M2//bIMnNtL/s +qVD4UWl908/8vMY1Ft9F3JQj0FbzoMbYlZMRu9tca6Ciee9zVjP6Pm1+qv3/wNgBgBG hM4fKBNomjFA/R0gg3byLmIMXCfmYFNvbs9A/xSm+wW/Ru2IN+++fH/MFMoLc02w4apc ctGNJqJVvTFlL1J6BdZCssT1QSaFJ2S3+3A+41a3xBdRtOqAMScK4DVWZDwgsZTB2W1W X5+b2VPohvlJfMB5RgEZUMmxxo/vFTTlXnbJ1zHz0PowleSPbjtg28leIYuznkgVb7hE xlJg== X-Gm-Message-State: ALoCoQkBEvLthZz+dK6XApA7yMrW2GOyK36LR74aUdM+7itdTC1q5YZZutpUHHi9p90EeRqOEqAn X-Received: by 10.66.227.193 with SMTP id sc1mr1800980pac.25.1386335973437; Fri, 06 Dec 2013 05:19:33 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.127.99 with SMTP id nf3ls1339843qeb.30.gmail; Fri, 06 Dec 2013 05:19:33 -0800 (PST) X-Received: by 10.58.252.167 with SMTP id zt7mr984027vec.60.1386335973321; Fri, 06 Dec 2013 05:19:33 -0800 (PST) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id sf4si18461431vcb.122.2013.12.06.05.19.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 06 Dec 2013 05:19:33 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id ks9so674147vcb.40 for ; Fri, 06 Dec 2013 05:19:33 -0800 (PST) X-Received: by 10.220.97.69 with SMTP id k5mr1216062vcn.45.1386335973182; Fri, 06 Dec 2013 05:19:33 -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.220.174.196 with SMTP id u4csp99126vcz; Fri, 6 Dec 2013 05:19:32 -0800 (PST) X-Received: by 10.180.13.242 with SMTP id k18mr2477117wic.44.1386335972416; Fri, 06 Dec 2013 05:19:32 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id gm6si1245616wib.47.2013.12.06.05.19.31 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 06 Dec 2013 05:19:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1VovJJ-0007Wv-Rr; Fri, 06 Dec 2013 13:19:13 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Michael Matz , Claudio Fontana , Dirk Mueller , Laurent Desnogues , kvmarm@lists.cs.columbia.edu, Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Christoffer Dall , Will Newton Subject: [PATCH v2 11/13] host-utils: add clrsb32/64 - count leading redundant sign bits Date: Fri, 6 Dec 2013 13:19:11 +0000 Message-Id: <1386335953-28876-12-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1386335953-28876-1-git-send-email-peter.maydell@linaro.org> References: <1386335953-28876-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=neutral (google.com: 209.85.220.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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: , From: Claudio Fontana this patch introduces wrappers for the clrsb builtins, which count the leading redundant sign bits. Signed-off-by: Claudio Fontana Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- include/qemu/host-utils.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h index 0f688c1..de85d28 100644 --- a/include/qemu/host-utils.h +++ b/include/qemu/host-utils.h @@ -228,6 +228,38 @@ static inline int cto64(uint64_t val) } /** + * clrsb32 - count leading redundant sign bits in a 32-bit value. + * @val: The value to search + * + * Returns the number of bits following the sign bit that are equal to it. + * No special cases; output range is [0-31]. + */ +static inline int clrsb32(uint32_t val) +{ +#if QEMU_GNUC_PREREQ(4, 7) + return __builtin_clrsb(val); +#else + return clz32(val ^ ((int32_t)val >> 1)) - 1; +#endif +} + +/** + * clrsb64 - count leading redundant sign bits in a 64-bit value. + * @val: The value to search + * + * Returns the number of bits following the sign bit that are equal to it. + * No special cases; output range is [0-63]. + */ +static inline int clrsb64(uint64_t val) +{ +#if QEMU_GNUC_PREREQ(4, 7) + return __builtin_clrsbll(val); +#else + return clz64(val ^ ((int64_t)val >> 1)) - 1; +#endif +} + +/** * ctpop8 - count the population of one bits in an 8-bit value. * @val: The value to search */