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)
 {
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to