Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1813442ybc; Wed, 20 Nov 2019 04:36:54 -0800 (PST) X-Google-Smtp-Source: APXvYqzFLA2XXHRMa7yvIyrPpWGc25je8gNiQUDzYT4O/ina91vEePQw+6z88OKusJf6xNcrh4DL X-Received: by 2002:adf:ab41:: with SMTP id r1mr3140409wrc.281.1574253414165; Wed, 20 Nov 2019 04:36:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574253414; cv=none; d=google.com; s=arc-20160816; b=ptfcv4OqICcmrlg3ago4QoAfwX3CCuCkXMjQbCdy98Oego3E4/okG/uGUOyF3NyzAA XQDOes1py7j2yHFJXwxabewLDhTFoZaRMdv2x3SEPJ92shVCO2Gx/3pBWzcyNZK1dVYw piM1cc3XYabBV7jPprIAPmcXGA7ZEBxst3h9oPLcBPVq0ArpRwr3Bw3DbOMFTlgKlO30 /0XA924xgFknRmChDyG7gNOU7NOaxAXa9r23wM3AXxqOOqpbzUY61PVSI9Zevoe1PViD JqemaghMCBR7eD12CJ/1BRDAPZsuFuZphDjXKKuakvhWvlnE1TxpmuG7peyNlA+koVW3 qrig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:references:cc:to:from:subject; bh=WySbrGwuVBlzPCNYWp+elJIIYKnzI6d190HH4SMkN3M=; b=PauPt8jmLm7Ow//sva5aXOy8C62mPZ/LCe7lxxz+k1sxLexfRIstpM9fxZrdBqkgIq RbKKzSZLcNa1trxK+WFIzAKlOtPvya32on+MnQ1/NuZvbARufRxs6i6HiCZojS9cC4Fe c4yZzLrnOK7u1KU9Y0+RkPIvHx7Mq8m6K8W92H4yQHAViChC8GANisiOSAL98BfpfkYQ XMloTKT/2bj+1UNw5kNTF2laDHT8uK973VwlLLtUJTymfHBc02wKdih1vg3oTZW58RAq 5X3y2xs2fcY+R6IEKA/VwjNP8uxXEAsfY2hujzYwQEC60FI8ggMVOI5jBoam5aysflYH XW3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q19si17546826eda.112.2019.11.20.04.36.30; Wed, 20 Nov 2019 04:36:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728325AbfKTJgf (ORCPT + 99 others); Wed, 20 Nov 2019 04:36:35 -0500 Received: from mga07.intel.com ([134.134.136.100]:29004 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727645AbfKTJgf (ORCPT ); Wed, 20 Nov 2019 04:36:35 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2019 01:36:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,221,1571727600"; d="scan'208";a="204679072" Received: from linux.intel.com ([10.54.29.200]) by fmsmga008.fm.intel.com with ESMTP; 20 Nov 2019 01:36:34 -0800 Received: from [10.249.33.94] (abudanko-mobl.ccr.corp.intel.com [10.249.33.94]) by linux.intel.com (Postfix) with ESMTP id 471EF5802E4; Wed, 20 Nov 2019 01:36:32 -0800 (PST) Subject: [PATCH v1 1/3] tools bitmap: implement bitmap_equal() operation at bitmap API From: Alexey Budankov To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel References: <26d1512a-9dea-bf7e-d18e-705846a870c4@linux.intel.com> Organization: Intel Corp. Message-ID: <9d1806f3-dc50-1392-31c2-eb399d7778ac@linux.intel.com> Date: Wed, 20 Nov 2019 12:36:31 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: <26d1512a-9dea-bf7e-d18e-705846a870c4@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Extend tools bitmap API with bitmap_equal() implementation. The implementation has been derived from the kernel. Signed-off-by: Alexey Budankov --- tools/include/linux/bitmap.h | 21 +++++++++++++++++++++ tools/lib/bitmap.c | 15 +++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index 05dca5c203f3..362f22fd3c00 100644 --- a/tools/include/linux/bitmap.h +++ b/tools/include/linux/bitmap.h @@ -15,6 +15,8 @@ void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, const unsigned long *bitmap2, int bits); int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int bits); +int __bitmap_equal(const unsigned long *bitmap1, + const unsigned long *bitmap2, unsigned int bits); void bitmap_clear(unsigned long *map, unsigned int start, int len); #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) @@ -148,4 +150,23 @@ static inline int bitmap_and(unsigned long *dst, const unsigned long *src1, return __bitmap_and(dst, src1, src2, nbits); } +#ifdef __LITTLE_ENDIAN +#define BITMAP_MEM_ALIGNMENT 8 +#else +#define BITMAP_MEM_ALIGNMENT (8 * sizeof(unsigned long)) +#endif +#define BITMAP_MEM_MASK (BITMAP_MEM_ALIGNMENT - 1) +#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) + +static inline int bitmap_equal(const unsigned long *src1, + const unsigned long *src2, unsigned int nbits) +{ + if (small_const_nbits(nbits)) + return !((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits)); + if (__builtin_constant_p(nbits & BITMAP_MEM_MASK) && + IS_ALIGNED(nbits, BITMAP_MEM_ALIGNMENT)) + return !memcmp(src1, src2, nbits / 8); + return __bitmap_equal(src1, src2, nbits); +} + #endif /* _PERF_BITOPS_H */ diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c index 38494782be06..5043747ef6c5 100644 --- a/tools/lib/bitmap.c +++ b/tools/lib/bitmap.c @@ -71,3 +71,18 @@ int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, BITMAP_LAST_WORD_MASK(bits)); return result != 0; } + +int __bitmap_equal(const unsigned long *bitmap1, + const unsigned long *bitmap2, unsigned int bits) +{ + unsigned int k, lim = bits/BITS_PER_LONG; + for (k = 0; k < lim; ++k) + if (bitmap1[k] != bitmap2[k]) + return 0; + + if (bits % BITS_PER_LONG) + if ((bitmap1[k] ^ bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits)) + return 0; + + return 1; +} -- 2.20.1