aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/lib/find_bit.c
diff options
context:
space:
mode:
authorYury Norov <yury.norov@gmail.com>2021-08-14 14:17:04 -0700
committerYury Norov <yury.norov@gmail.com>2022-01-15 08:47:31 -0800
commit4ade0818cf048bb166e875ed4f8b456e6c2c7b3c (patch)
tree710bfa076bf9dbed9349793aabc92e1c5055bbc1 /tools/lib/find_bit.c
parentall: replace find_next{,_zero}_bit with find_first{,_zero}_bit where appropriate (diff)
downloadwireguard-linux-4ade0818cf048bb166e875ed4f8b456e6c2c7b3c.tar.xz
wireguard-linux-4ade0818cf048bb166e875ed4f8b456e6c2c7b3c.zip
tools: sync tools/bitmap with mother linux
Remove tools/include/asm-generic/bitops/find.h and copy include/linux/bitmap.h to tools. find_*_le() functions are not copied because not needed in tools. Signed-off-by: Yury Norov <yury.norov@gmail.com> Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Diffstat (limited to 'tools/lib/find_bit.c')
-rw-r--r--tools/lib/find_bit.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/lib/find_bit.c b/tools/lib/find_bit.c
index 109aa7ffcf97..ba4b8d94e004 100644
--- a/tools/lib/find_bit.c
+++ b/tools/lib/find_bit.c
@@ -96,6 +96,26 @@ unsigned long _find_first_bit(const unsigned long *addr, unsigned long size)
}
#endif
+#ifndef find_first_and_bit
+/*
+ * Find the first set bit in two memory regions.
+ */
+unsigned long _find_first_and_bit(const unsigned long *addr1,
+ const unsigned long *addr2,
+ unsigned long size)
+{
+ unsigned long idx, val;
+
+ for (idx = 0; idx * BITS_PER_LONG < size; idx++) {
+ val = addr1[idx] & addr2[idx];
+ if (val)
+ return min(idx * BITS_PER_LONG + __ffs(val), size);
+ }
+
+ return size;
+}
+#endif
+
#ifndef find_first_zero_bit
/*
* Find the first cleared bit in a memory region.