Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bitmap: introduce bitmap_weighted_xor()

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

Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Yury Norov <ynorov@nvidia.com>

+22
+15
include/linux/bitmap.h
··· 46 46 * bitmap_and(dst, src1, src2, nbits) *dst = *src1 & *src2 47 47 * bitmap_or(dst, src1, src2, nbits) *dst = *src1 | *src2 48 48 * bitmap_weighted_or(dst, src1, src2, nbits) *dst = *src1 | *src2. Returns Hamming Weight of dst 49 + * bitmap_weighted_xor(dst, src1, src2, nbits) *dst = *src1 ^ *src2. Returns Hamming Weight of dst 49 50 * bitmap_xor(dst, src1, src2, nbits) *dst = *src1 ^ *src2 50 51 * bitmap_andnot(dst, src1, src2, nbits) *dst = *src1 & ~(*src2) 51 52 * bitmap_complement(dst, src, nbits) *dst = ~(*src) ··· 169 168 void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, 170 169 const unsigned long *bitmap2, unsigned int nbits); 171 170 unsigned int __bitmap_weighted_or(unsigned long *dst, const unsigned long *bitmap1, 171 + const unsigned long *bitmap2, unsigned int nbits); 172 + unsigned int __bitmap_weighted_xor(unsigned long *dst, const unsigned long *bitmap1, 172 173 const unsigned long *bitmap2, unsigned int nbits); 173 174 void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1, 174 175 const unsigned long *bitmap2, unsigned int nbits); ··· 353 350 return hweight_long(*dst & BITMAP_LAST_WORD_MASK(nbits)); 354 351 } else { 355 352 return __bitmap_weighted_or(dst, src1, src2, nbits); 353 + } 354 + } 355 + 356 + static __always_inline 357 + unsigned int bitmap_weighted_xor(unsigned long *dst, const unsigned long *src1, 358 + const unsigned long *src2, unsigned int nbits) 359 + { 360 + if (small_const_nbits(nbits)) { 361 + *dst = *src1 ^ *src2; 362 + return hweight_long(*dst & BITMAP_LAST_WORD_MASK(nbits)); 363 + } else { 364 + return __bitmap_weighted_xor(dst, src1, src2, nbits); 356 365 } 357 366 } 358 367
+7
lib/bitmap.c
··· 363 363 } 364 364 EXPORT_SYMBOL(__bitmap_weighted_or); 365 365 366 + unsigned int __bitmap_weighted_xor(unsigned long *dst, const unsigned long *bitmap1, 367 + const unsigned long *bitmap2, unsigned int bits) 368 + { 369 + return BITMAP_WEIGHT(({dst[idx] = bitmap1[idx] ^ bitmap2[idx]; dst[idx]; }), bits); 370 + } 371 + EXPORT_SYMBOL(__bitmap_weighted_xor); 372 + 366 373 void __bitmap_set(unsigned long *map, unsigned int start, int len) 367 374 { 368 375 unsigned long *p = map + BIT_WORD(start);