public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* better asm-generic/bitops.h
@ 2000-11-10 22:21 Pavel Machek
  0 siblings, 0 replies; only message in thread
From: Pavel Machek @ 2000-11-10 22:21 UTC (permalink / raw)
  To: kernel list

Hi!

It might be usefull to someone..
							Pavel

Index: bitops.h
===================================================================
RCS file: /home/cvs/Repository/linux/include/asm-generic/bitops.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 bitops.h
--- bitops.h	2000/09/04 16:50:34	1.1.1.1
+++ bitops.h	2000/11/09 13:23:02
@@ -1,5 +1,6 @@
 #ifndef _ASM_GENERIC_BITOPS_H_
 #define _ASM_GENERIC_BITOPS_H_
+#include <asm/system.h>
 
 /*
  * For the benefit of those who are trying to port Linux to another
@@ -13,43 +14,120 @@
  * You will have to change this if you are trying to port Linux to the
  * Alpha architecture or to a Cray.  :-)
  * 
- * C language equivalents written by Theodore Ts'o, 9/26/92
+ * C language equivalents written by Theodore Ts'o, 9/26/92 
  */
 
-extern __inline__ int set_bit(int nr,int * addr)
+extern __inline__ int set_bit(int nr, void * a)
 {
 	int	mask, retval;
+	int	*addr = a;
+	unsigned long flags;
 
 	addr += nr >> 5;
 	mask = 1 << (nr & 0x1f);
-	cli();
+	save_flags(flags); cli();
 	retval = (mask & *addr) != 0;
 	*addr |= mask;
-	sti();
+	restore_flags(flags);
 	return retval;
 }
 
-extern __inline__ int clear_bit(int nr, int * addr)
+extern __inline__ int clear_bit(int nr, void * a)
 {
 	int	mask, retval;
+	int	*addr = a;
+	unsigned long flags;
 
 	addr += nr >> 5;
 	mask = 1 << (nr & 0x1f);
-	cli();
+	save_flags(flags); cli();
 	retval = (mask & *addr) != 0;
 	*addr &= ~mask;
-	sti();
+	restore_flags(flags);
 	return retval;
 }
 
-extern __inline__ int test_bit(int nr, int * addr)
+extern __inline__ int change_bit(int nr, void * a)
 {
+	int	mask, retval;
+	int	*addr = a;
+	unsigned long flags;
+
+	addr += nr >> 5;
+	mask = 1 << (nr & 0x1f);
+	save_flags(flags); cli();
+	retval = (mask & *addr) != 0;
+	*addr ^= mask;
+	restore_flags(flags);
+	return retval;
+}
+
+#define test_and_set_bit set_bit
+#define test_and_clear_bit clear_bit
+#define test_and_change_bit change_bit
+
+extern __inline__ int test_bit(int nr, void * a)
+{
 	int	mask;
+	int	*addr = a;
 
 	addr += nr >> 5;
 	mask = 1 << (nr & 0x1f);
 	return ((mask & *addr) != 0);
 }
+
+
+/*
+ * ffz = Find First Zero in word. Undefined if no zero exists,
+ * so code should check against ~0UL first..
+ */
+extern __inline__ unsigned long ffz(unsigned long word)
+{
+	int i;
+	for (i=0; i<64; i++)
+		if (!(word & (1<<i)))
+			return i;
+	return -1;
+}
+
+extern __inline__ int find_next_zero_bit(void *addr, int size, int offset)
+{
+	unsigned long *p = ((unsigned long *) addr) + (offset >> 5);
+	unsigned long result = offset & ~31UL;
+	unsigned long tmp;
+
+	if (offset >= size)
+		return size;
+	size -= result;
+	offset &= 31UL;
+	if (offset) {
+		tmp = *(p++);
+		tmp |= ~0UL >> (32-offset);
+		if (size < 32)
+			goto found_first;
+		if (~tmp)
+			goto found_middle;
+		size -= 32;
+		result += 32;
+	}
+	while (size & ~31UL) {
+		if (~(tmp = *(p++)))
+			goto found_middle;
+		result += 32;
+		size -= 32;
+	}
+	if (!size)
+		return result;
+	tmp = *p;
+
+found_first:
+	tmp |= ~0UL << size;
+found_middle:
+	return result + ffz(tmp);
+}
+
+#define find_first_zero_bit(addr, size) \
+        find_next_zero_bit((addr), (size), 0)
 
 #ifdef __KERNEL__
 


----- End forwarded message -----

-- 
I'm pavel@ucw.cz. "In my country we have almost anarchy and I don't care."
Panos Katsaloulis describing me w.r.t. patents at discuss@linmodems.org
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-11-10 21:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-11-10 22:21 better asm-generic/bitops.h Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox