]> git.buserror.net Git - polintos/scott/priv.git/blobdiff - include/c/lowlevel/arch-x86-common/bitops.h
Use GCC builtins for bit scanning. The minor benefit is that it is
[polintos/scott/priv.git] / include / c / lowlevel / arch-x86-common / bitops.h
diff --git a/include/c/lowlevel/arch-x86-common/bitops.h b/include/c/lowlevel/arch-x86-common/bitops.h
new file mode 100644 (file)
index 0000000..beca262
--- /dev/null
@@ -0,0 +1,19 @@
+// Bit manipulation functions.  These functions are not privileged.
+
+#ifndef _LL_ARCH_X86C_BITOPS_H
+#define _LL_ARCH_X86C_BITOPS_H
+
+// Set/Clear the nth bit in a multiword bitmap.  These functions
+// are endian and word-size dependent.
+
+static inline void ll_multiword_set_bit(unsigned long *bitmap, int bit)
+{
+       asm("bts %1, %0" : "=m" (bitmap[0]) : "r" (bit) : "memory");
+}
+
+static inline void ll_multiword_clear_bit(unsigned long *bitmap, int bit)
+{
+       asm("btr %1, %0" : "=m" (bitmap[0]) : "r" (bit) : "memory");
+}
+
+#endif