From: Yury Norov <yury.norov@gmail.com>
To: Tony Luck <tony.luck@intel.com>,
Reinette Chatre <reinette.chatre@intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>,
"Yury Norov [NVIDIA]" <yury.norov@gmail.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/4] find: add find_first_andnot_bit()
Date: Mon, 7 Apr 2025 11:38:53 -0400 [thread overview]
Message-ID: <20250407153856.133093-3-yury.norov@gmail.com> (raw)
In-Reply-To: <20250407153856.133093-1-yury.norov@gmail.com>
From: Yury Norov [NVIDIA] <yury.norov@gmail.com>
The function helps to implement cpumask_andnot() APIs.
Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
---
include/linux/find.h | 25 +++++++++++++++++++++++++
lib/find_bit.c | 11 +++++++++++
2 files changed, 36 insertions(+)
diff --git a/include/linux/find.h b/include/linux/find.h
index 68685714bc18..d1578cfb667c 100644
--- a/include/linux/find.h
+++ b/include/linux/find.h
@@ -29,6 +29,8 @@ unsigned long __find_nth_and_andnot_bit(const unsigned long *addr1, const unsign
unsigned long n);
extern unsigned long _find_first_and_bit(const unsigned long *addr1,
const unsigned long *addr2, unsigned long size);
+unsigned long _find_first_andnot_bit(const unsigned long *addr1, const unsigned long *addr2,
+ unsigned long size);
unsigned long _find_first_and_and_bit(const unsigned long *addr1, const unsigned long *addr2,
const unsigned long *addr3, unsigned long size);
extern unsigned long _find_first_zero_bit(const unsigned long *addr, unsigned long size);
@@ -347,6 +349,29 @@ unsigned long find_first_and_bit(const unsigned long *addr1,
}
#endif
+/**
+ * find_first_andnot_bit - find the first bit set in 1st memory region and unset in 2nd
+ * @addr1: The first address to base the search on
+ * @addr2: The second address to base the search on
+ * @size: The bitmap size in bits
+ *
+ * Returns the bit number for the matched bit
+ * If no bits are set, returns >= @size.
+ */
+static __always_inline
+unsigned long find_first_andnot_bit(const unsigned long *addr1,
+ const unsigned long *addr2,
+ unsigned long size)
+{
+ if (small_const_nbits(size)) {
+ unsigned long val = *addr1 & (~*addr2) & GENMASK(size - 1, 0);
+
+ return val ? __ffs(val) : size;
+ }
+
+ return _find_first_andnot_bit(addr1, addr2, size);
+}
+
/**
* find_first_and_and_bit - find the first set bit in 3 memory regions
* @addr1: The first address to base the search on
diff --git a/lib/find_bit.c b/lib/find_bit.c
index 0836bb3d76c5..06b6342aa3ae 100644
--- a/lib/find_bit.c
+++ b/lib/find_bit.c
@@ -116,6 +116,17 @@ unsigned long _find_first_and_bit(const unsigned long *addr1,
EXPORT_SYMBOL(_find_first_and_bit);
#endif
+/*
+ * Find the first bit set in 1st memory region and unset in 2nd.
+ */
+unsigned long _find_first_andnot_bit(const unsigned long *addr1,
+ const unsigned long *addr2,
+ unsigned long size)
+{
+ return FIND_FIRST_BIT(addr1[idx] & ~addr2[idx], /* nop */, size);
+}
+EXPORT_SYMBOL(_find_first_andnot_bit);
+
/*
* Find the first set bit in three memory regions.
*/
--
2.43.0
next prev parent reply other threads:[~2025-04-07 15:39 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-07 15:38 [PATCH 0/4] cpumask: add missing API and simplify cpumask_any_housekeeping() Yury Norov
2025-04-07 15:38 ` [PATCH 1/4] cpumask: relax cpumask_any_but() Yury Norov
2025-04-23 21:28 ` Reinette Chatre
2025-04-24 2:46 ` Yury Norov
2025-04-07 15:38 ` Yury Norov [this message]
2025-04-23 21:28 ` [PATCH 2/4] find: add find_first_andnot_bit() Reinette Chatre
2025-04-24 2:57 ` Yury Norov
2025-04-07 15:38 ` [PATCH 3/4] cpumask: add cpumask_{first,next}_andnot() API Yury Norov
2025-04-23 21:28 ` Reinette Chatre
2025-04-24 2:58 ` Yury Norov
2025-04-24 17:07 ` James Morse
2025-04-07 15:38 ` [PATCH 4/4] x86/resctrl: optimize cpumask_any_housekeeping() Yury Norov
2025-04-23 21:29 ` Reinette Chatre
2025-04-24 3:01 ` Yury Norov
2025-04-22 13:50 ` [PATCH 0/4] cpumask: add missing API and simplify cpumask_any_housekeeping() Yury Norov
2025-04-22 15:13 ` Reinette Chatre
2025-04-23 21:27 ` Reinette Chatre
2025-04-24 3:11 ` Yury Norov
2025-04-24 17:22 ` James Morse
2025-04-24 17:12 ` James Morse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250407153856.133093-3-yury.norov@gmail.com \
--to=yury.norov@gmail.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mingo@redhat.com \
--cc=reinette.chatre@intel.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®