URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [include/] [asm-or32/] [bitops.h] - Rev 1774
Go to most recent revision | Compare with Previous | Blame | View Log
#ifdef __KERNEL__ #ifndef _OR32_BITOPS_H #define _OR32_BITOPS_H #include <linux/config.h> #include <asm/byteorder.h> #include <asm/system.h> extern __inline__ int set_bit(int nr, void * a) { int * addr = a; int mask, retval; unsigned long flags; addr += nr >> 5; mask = 1 << (nr & 0x1f); save_and_cli(flags); retval = (mask & *addr) != 0; *addr |= mask; restore_flags(flags); return retval; } extern __inline__ int clear_bit(int nr, void * a) { int * addr = a; int mask, retval; unsigned long flags; addr += nr >> 5; mask = 1 << (nr & 0x1f); save_and_cli(flags); retval = (mask & *addr) != 0; *addr &= ~mask; restore_flags(flags); return retval; } extern __inline__ unsigned long change_bit(unsigned long nr, void *addr) { int mask; unsigned long flags; unsigned long *ADDR = (unsigned long *) addr; unsigned long oldbit; ADDR += nr >> 5; mask = 1 << (nr & 31); save_and_cli(flags); oldbit = (mask & *ADDR); *ADDR ^= mask; restore_flags(flags); return oldbit != 0; } extern __inline__ int test_bit(int nr, void * a) { int * addr = a; int mask; addr += nr >> 5; mask = 1 << (nr & 0x1f); return ((mask & *addr) != 0); } static __inline__ int test_and_set_bit(int nr, void *addr) { unsigned int mask, retval; unsigned long flags; unsigned int *adr = (unsigned int *)addr; adr += nr >> 5; mask = 1 << (nr & 0x1f); save_and_cli(flags); retval = (mask & *adr) != 0; *adr |= mask; restore_flags(flags); return retval; } static __inline__ int test_and_clear_bit(int nr, void *addr) { unsigned int mask, retval; unsigned long flags; unsigned int *adr = (unsigned int *)addr; adr += nr >> 5; mask = 1 << (nr & 0x1f); save_and_cli(flags); retval = (mask & *adr) != 0; *adr &= ~mask; restore_flags(flags); return retval; } static __inline__ int test_and_change_bit(int nr, void *addr) { unsigned int mask, retval; unsigned long flags; unsigned int *adr = (unsigned int *)addr; adr += nr >> 5; mask = 1 << (nr & 0x1f); save_and_cli(flags); retval = (mask & *adr) != 0; *adr ^= mask; restore_flags(flags); return retval; } #define __change_bit(nr, addr) (void)__test_and_change_bit(nr, addr) static __inline__ int __test_and_change_bit(int nr, void *addr) { unsigned int mask, retval; unsigned int *adr = (unsigned int *)addr; adr += nr >> 5; mask = 1 << (nr & 0x1f); retval = (mask & *adr) != 0; *adr ^= mask; return retval; } /* The easy/cheese version for now. */ extern __inline__ unsigned long ffz(unsigned long word) { unsigned long result = 0; while(word & 1) { result++; word >>= 1; } return result; } /* find_next_zero_bit() finds the first zero bit in a bit string of length * 'size' bits, starting the search at bit 'offset'. This is largely based * on Linus's ALPHA routines, which are pretty portable BTW. */ extern __inline__ unsigned long find_next_zero_bit(void *addr, unsigned long size, unsigned long 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); } /* Linus sez that gcc can optimize the following correctly, we'll see if this * holds on the Sparc as it does for the ALPHA. */ #define find_first_zero_bit(addr, size) \ find_next_zero_bit((addr), (size), 0) /* Now for the ext2 filesystem bit operations and helper routines. */ extern __inline__ int ext2_set_bit(int nr,void * addr) { int mask, retval; unsigned long flags; unsigned char *ADDR = (unsigned char *) addr; ADDR += nr >> 3; mask = 1 << (nr & 0x07); save_and_cli(flags); retval = (mask & *ADDR) != 0; *ADDR |= mask; restore_flags(flags); return retval; } extern __inline__ int ext2_clear_bit(int nr, void * addr) { int mask, retval; unsigned long flags; unsigned char *ADDR = (unsigned char *) addr; ADDR += nr >> 3; mask = 1 << (nr & 0x07); save_and_cli(flags); retval = (mask & *ADDR) != 0; *ADDR &= ~mask; restore_flags(flags); return retval; } extern __inline__ int ext2_test_bit(int nr, const void * addr) { int mask; const unsigned char *ADDR = (const unsigned char *) addr; ADDR += nr >> 3; mask = 1 << (nr & 0x07); return ((mask & *ADDR) != 0); } #define ext2_find_first_zero_bit(addr, size) \ ext2_find_next_zero_bit((addr), (size), 0) extern __inline__ unsigned long ext2_find_next_zero_bit(void *addr, unsigned long size, unsigned long 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: tmp = ((tmp>>24) | ((tmp>>8)&0xff00) | ((tmp<<8)&0xff0000) | (tmp<<24)); return result + ffz(tmp); } #define __ext2_set_bit ext2_set_bit #define __ext2_clear_bit ext2_clear_bit extern __inline__ int __ext2_test_bit(int nr, __const__ void * addr) { int mask; __const__ unsigned char *ADDR = (__const__ unsigned char *) addr; ADDR += nr >> 3; mask = 1 << (nr & 0x07); return ((mask & *ADDR) != 0); } #define __ext2_find_first_zero_bit(addr, size) \ __ext2_find_next_zero_bit((addr), (size), 0) extern __inline__ unsigned long __ext2_find_next_zero_bit(void *addr, unsigned long size, unsigned long 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 |= __swab32(~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: return result + ffz(__swab32(tmp) | (~0UL << size)); found_middle: return result + ffz(__swab32(tmp)); } /* * clear_bit() doesn't provide any barrier for the compiler. */ /* __PHX__ :: enable for SMP */ //#define smp_mb__before_clear_bit() barrier() //#define smp_mb__after_clear_bit() barrier() #define smp_mb__before_clear_bit() #define smp_mb__after_clear_bit() #endif /* _OR32_BITOPS_H */ #endif /* __KERNEL__ */
Go to most recent revision | Compare with Previous | Blame | View Log