Thread (18 messages) flat view 18 messages, 8 authors, 2026-04-09

RE: [Intel-wired-lan] [PATCH v2 1/4] bitmap: introduce bitmap_weighted_xor()

From: Loktionov, Aleksandr <hidden>
Date: 2026-03-02 07:13:01
Also in: dri-devel, intel-wired-lan, intel-xe, lkml

quoted hunk ↗ jump to hunk
-----Original Message-----
From: Intel-wired-lan <redacted> On Behalf
Of Yury Norov via Intel-wired-lan
Sent: Monday, March 2, 2026 2:12 AM
To: Nguyen, Anthony L <anthony.l.nguyen@intel.com>; David S. Miller
[off-list ref]; Thomas Hellström
[off-list ref]; Andrew Lunn
[off-list ref]; Andrew Morton [off-list ref];
David Airlie [off-list ref]; Eric Dumazet [off-list ref];
Jakub Kicinski [off-list ref]; Brost, Matthew
[off-list ref]; Paolo Abeni [off-list ref]; Kitszel,
Przemyslaw [off-list ref]; Vivi, Rodrigo
[off-list ref]; Simona Vetter [off-list ref]; Yury Norov
[off-list ref]; Rasmus Villemoes [off-list ref];
dri-devel@lists.freedesktop.org; intel-xe@lists.freedesktop.org;
linux-kernel@vger.kernel.org; netdev@vger.kernel.org; intel-wired-
lan@lists.osuosl.org
Cc: Yury Norov <redacted>; Simon Horman <horms@kernel.org>;
David Laight [off-list ref]
Subject: [Intel-wired-lan] [PATCH v2 1/4] bitmap: introduce
bitmap_weighted_xor()

The function helps to XOR bitmaps and calculate Hamming weight of the
result in one pass.

Signed-off-by: Yury Norov <redacted>
---
 include/linux/bitmap.h | 15 +++++++++++++++
 lib/bitmap.c           |  7 +++++++
 2 files changed, 22 insertions(+)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index
b0395e4ccf90..874f744870ef 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -46,6 +46,7 @@ struct device;
  *  bitmap_and(dst, src1, src2, nbits)          *dst = *src1 & *src2
  *  bitmap_or(dst, src1, src2, nbits)           *dst = *src1 | *src2
  *  bitmap_weighted_or(dst, src1, src2, nbits)	*dst = *src1 | *src2.
Returns Hamming Weight of dst
+ *  bitmap_weighted_xor(dst, src1, src2, nbits)	*dst = *src1 ^
*src2. Returns Hamming Weight of dst
  *  bitmap_xor(dst, src1, src2, nbits)          *dst = *src1 ^ *src2
  *  bitmap_andnot(dst, src1, src2, nbits)       *dst = *src1 &
~(*src2)
  *  bitmap_complement(dst, src, nbits)          *dst = ~(*src)
@@ -168,6 +169,8 @@ void __bitmap_or(unsigned long *dst, const
unsigned long *bitmap1,
 		 const unsigned long *bitmap2, unsigned int nbits);
unsigned int __bitmap_weighted_or(unsigned long *dst, const unsigned
long *bitmap1,
 				  const unsigned long *bitmap2, unsigned
int nbits);
+unsigned int __bitmap_weighted_xor(unsigned long *dst, const unsigned
long *bitmap1,
+				  const unsigned long *bitmap2, unsigned
int nbits);
 void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
 		  const unsigned long *bitmap2, unsigned int nbits);
bool __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
@@ -352,6 +355,18 @@ unsigned int bitmap_weighted_or(unsigned long
*dst, const unsigned long *src1,
 	}
 }

+static __always_inline
+unsigned int bitmap_weighted_xor(unsigned long *dst, const unsigned
long *src1,
+				const unsigned long *src2, unsigned int
nbits) {
+	if (small_const_nbits(nbits)) {
+		*dst = *src1 ^ *src2;
+		return hweight_long(*dst &
BITMAP_LAST_WORD_MASK(nbits));
+	} else {
+		return __bitmap_weighted_xor(dst, src1, src2, nbits);
+	}
+}
+
 static __always_inline
 void bitmap_xor(unsigned long *dst, const unsigned long *src1,
 		const unsigned long *src2, unsigned int nbits) diff --
git a/lib/bitmap.c b/lib/bitmap.c index 9dc526507875..a2bcb5b1fe99
100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -361,6 +361,13 @@ unsigned int __bitmap_weighted_or(unsigned long
*dst, const unsigned long *bitma
 	return BITMAP_WEIGHT(({dst[idx] = bitmap1[idx] | bitmap2[idx];
dst[idx]; }), bits);  }

+unsigned int __bitmap_weighted_xor(unsigned long *dst, const unsigned
long *bitmap1,
+				  const unsigned long *bitmap2, unsigned
int bits) {
+	return BITMAP_WEIGHT(({dst[idx] = bitmap1[idx] ^ bitmap2[idx];
+dst[idx]; }), bits); } EXPORT_SYMBOL(__bitmap_weighted_xor);
+
 void __bitmap_set(unsigned long *map, unsigned int start, int len)  {
 	unsigned long *p = map + BIT_WORD(start);
--
2.43.0
Reviewed-by: Aleksandr Loktionov <redacted>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help