mirror of https://github.com/torvalds/linux.git
find: Add find_first_andnot_bit()
The function helps to implement cpumask_andnot() APIs. Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com> Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: James Morse <james.morse@arm.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Reviewed-by: Fenghua Yu <fenghuay@nvidia.com> Tested-by: James Morse <james.morse@arm.com> Tested-by: Tony Luck <tony.luck@intel.com> Tested-by: Fenghua Yu <fenghuay@nvidia.com> Link: https://lore.kernel.org/20250515165855.31452-3-james.morse@arm.com
This commit is contained in:
parent
189572bf4e
commit
13f0a02bf4
|
|
@ -29,6 +29,8 @@ unsigned long __find_nth_and_andnot_bit(const unsigned long *addr1, const unsign
|
||||||
unsigned long n);
|
unsigned long n);
|
||||||
extern unsigned long _find_first_and_bit(const unsigned long *addr1,
|
extern unsigned long _find_first_and_bit(const unsigned long *addr1,
|
||||||
const unsigned long *addr2, unsigned long size);
|
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,
|
unsigned long _find_first_and_and_bit(const unsigned long *addr1, const unsigned long *addr2,
|
||||||
const unsigned long *addr3, unsigned long size);
|
const unsigned long *addr3, unsigned long size);
|
||||||
extern unsigned long _find_first_zero_bit(const unsigned long *addr, 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
|
#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
|
* find_first_and_and_bit - find the first set bit in 3 memory regions
|
||||||
* @addr1: The first address to base the search on
|
* @addr1: The first address to base the search on
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,17 @@ unsigned long _find_first_and_bit(const unsigned long *addr1,
|
||||||
EXPORT_SYMBOL(_find_first_and_bit);
|
EXPORT_SYMBOL(_find_first_and_bit);
|
||||||
#endif
|
#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.
|
* Find the first set bit in three memory regions.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue