Date: Thu, 23 Feb 2017 09:53:54 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r314136 - head/sys/compat/linuxkpi/common/include/linux Message-ID: <201702230953.v1N9rsuR087346@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Thu Feb 23 09:53:54 2017 New Revision: 314136 URL: https://svnweb.freebsd.org/changeset/base/314136 Log: 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 Modified: head/sys/compat/linuxkpi/common/include/linux/bitops.h Modified: head/sys/compat/linuxkpi/common/include/linux/bitops.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/bitops.h Thu Feb 23 09:52:22 2017 (r314135) +++ head/sys/compat/linuxkpi/common/include/linux/bitops.h Thu Feb 23 09:53:54 2017 (r314136) @@ -338,6 +338,21 @@ test_and_clear_bit(long bit, volatile un } 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) { long val; @@ -352,6 +367,21 @@ test_and_set_bit(long bit, volatile unsi 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) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201702230953.v1N9rsuR087346>