[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <174747618641.406.4541810444223655669.tip-bot2@tip-bot2>
Date: Sat, 17 May 2025 10:03:06 -0000
From: "tip-bot2 for Yury Norov [NVIDIA]" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: "Yury Norov [NVIDIA]" <yury.norov@...il.com>,
James Morse <james.morse@....com>, "Borislav Petkov (AMD)" <bp@...en8.de>,
Reinette Chatre <reinette.chatre@...el.com>, Fenghua Yu <fenghuay@...dia.com>,
Tony Luck <tony.luck@...el.com>, x86@...nel.org, linux-kernel@...r.kernel.org
Subject: [tip: x86/cache] find: Add find_first_andnot_bit()
The following commit has been merged into the x86/cache branch of tip:
Commit-ID: 13f0a02bf4c1c5888c736cedef9ca50de666adb3
Gitweb: https://git.kernel.org/tip/13f0a02bf4c1c5888c736cedef9ca50de666adb3
Author: Yury Norov [NVIDIA] <yury.norov@...il.com>
AuthorDate: Thu, 15 May 2025 16:58:32
Committer: Borislav Petkov (AMD) <bp@...en8.de>
CommitterDate: Thu, 15 May 2025 20:24:40 +02:00
find: Add find_first_andnot_bit()
The function helps to implement cpumask_andnot() APIs.
Signed-off-by: Yury Norov [NVIDIA] <yury.norov@...il.com>
Signed-off-by: James Morse <james.morse@....com>
Signed-off-by: Borislav Petkov (AMD) <bp@...en8.de>
Reviewed-by: James Morse <james.morse@....com>
Reviewed-by: Reinette Chatre <reinette.chatre@...el.com>
Reviewed-by: Fenghua Yu <fenghuay@...dia.com>
Tested-by: James Morse <james.morse@....com>
Tested-by: Tony Luck <tony.luck@...el.com>
Tested-by: Fenghua Yu <fenghuay@...dia.com>
Link: https://lore.kernel.org/20250515165855.31452-3-james.morse@arm.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 6868571..5a2c267 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);
@@ -348,6 +350,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 first set 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
* @addr2: The second address to base the search on
diff --git a/lib/find_bit.c b/lib/find_bit.c
index 0836bb3..06b6342 100644
--- a/lib/find_bit.c
+++ b/lib/find_bit.c
@@ -117,6 +117,17 @@ 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.
*/
unsigned long _find_first_and_and_bit(const unsigned long *addr1,
Powered by blists - more mailing lists