From patchwork Thu Dec 5 21:51:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 22104 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f199.google.com (mail-ie0-f199.google.com [209.85.223.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2E12923FD0 for ; Thu, 5 Dec 2013 21:51:40 +0000 (UTC) Received: by mail-ie0-f199.google.com with SMTP id lx4sf57846090iec.6 for ; Thu, 05 Dec 2013 13:51:39 -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=4bSjdfCaik9f+wmJDRc6CwtahazZuA98gy+yap54Gk4=; b=RCgpv3c7u3xO8bxgL7AGZanTThgC/WnWj9wexPiEezOgc+rViVD/quLtRufYhFxPwS wxZ+vlb9YCMgl776Fq2IaTdTIsS3+ytlBCE29FLoTSBXgB1SHiS/v7RkE/Z/6fobSiJ4 SqpyMZDB2IHhPpofIeydyPtI9GfoxXCi508rqINEKU5QTHc9NLqyHB0BaERhK5PdFhit /pK8tTlRinXEGpxHc+VGZJeNFSV6VZ++65vEl1VzDzhKOp4fYEIXaIp9ibS3bgLNAn4s oPSEa34FKpoBujLfTsNwQBYR1H2AVrBS91mKyNJM2C/C7VArdjaJuM32y4anjn8VMmvX F7Fg== X-Gm-Message-State: ALoCoQkyrNQM99RffHeg5wzzgSQq8+w0r9L2LrsDYmafRHmsbevi0mdDpWWN8wRxI4RUWuuSgT2P X-Received: by 10.42.29.5 with SMTP id p5mr25981988icc.19.1386280299883; Thu, 05 Dec 2013 13:51:39 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.94.41 with SMTP id cz9ls1102505qeb.57.gmail; Thu, 05 Dec 2013 13:51:39 -0800 (PST) X-Received: by 10.58.246.136 with SMTP id xw8mr3103440vec.41.1386280299677; Thu, 05 Dec 2013 13:51:39 -0800 (PST) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id q19si22172856vea.139.2013.12.05.13.51.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 05 Dec 2013 13:51:39 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.179 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.179; Received: by mail-vc0-f179.google.com with SMTP id ie18so13896004vcb.10 for ; Thu, 05 Dec 2013 13:51:39 -0800 (PST) X-Received: by 10.52.165.131 with SMTP id yy3mr11508vdb.25.1386280299491; Thu, 05 Dec 2013 13:51:39 -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 u4csp50144vcz; Thu, 5 Dec 2013 13:51:39 -0800 (PST) X-Received: by 10.194.237.99 with SMTP id vb3mr11490wjc.28.1386280297302; Thu, 05 Dec 2013 13:51:37 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id r4si35308376wjr.86.2013.12.05.13.51.35 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 05 Dec 2013 13:51:37 -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 1VogpV-0007Cv-Pq; Thu, 05 Dec 2013 21:51:29 +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 11/13] host-utils: add clrsb32/64 - count leading redundant sign bits Date: Thu, 5 Dec 2013 21:51:27 +0000 Message-Id: <1386280289-27636-12-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1386280289-27636-1-git-send-email-peter.maydell@linaro.org> References: <1386280289-27636-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.179 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 */