better asm-generic/bitops.h
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
bitops.h +86 -8
@@ -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 -----
Signature · 6 lines
I'm [email protected]. "In my country we have almost anarchy and I don't care." Panos Katsaloulis describing me w.r.t. patents at [email protected] - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] Please read the FAQ at http://www.tux.org/lkml/