Implement __test_and_clear_bit() and __test_and_set_bit() in the LinuxKPI.

The clang compiler will optimise these functions down to three AMD64
instructions if the bit argument is a constant during compilation.

MFC after:		1 week
Sponsored by:		Mellanox Technologies
This commit is contained in:
Hans Petter Selasky 2017-02-23 09:53:54 +00:00
parent c1f156d447
commit cffaf933d7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=314136

View File

@ -337,6 +337,21 @@ test_and_clear_bit(long bit, volatile unsigned long *var)
return !!(val & bit);
}
static inline int
__test_and_clear_bit(long bit, volatile unsigned long *var)
{
long val;
var += BIT_WORD(bit);
bit %= BITS_PER_LONG;
bit = (1UL << bit);
val = *var;
*var &= ~bit;
return !!(val & bit);
}
static inline int
test_and_set_bit(long bit, volatile unsigned long *var)
{
@ -352,6 +367,21 @@ test_and_set_bit(long bit, volatile unsigned long *var)
return !!(val & bit);
}
static inline int
__test_and_set_bit(long bit, volatile unsigned long *var)
{
long val;
var += BIT_WORD(bit);
bit %= BITS_PER_LONG;
bit = (1UL << bit);
val = *var;
*var |= bit;
return !!(val & bit);
}
static inline void
bitmap_set(unsigned long *map, int start, int nr)
{