wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * bitops.h: Bit string operations on the m68k |
| 3 | */ |
| 4 | |
| 5 | #ifndef _M68K_BITOPS_H |
| 6 | #define _M68K_BITOPS_H |
| 7 | |
| 8 | #include <linux/config.h> |
| 9 | #include <asm/byteorder.h> |
| 10 | |
| 11 | extern void set_bit(int nr, volatile void *addr); |
| 12 | extern void clear_bit(int nr, volatile void *addr); |
| 13 | extern void change_bit(int nr, volatile void *addr); |
| 14 | extern int test_and_set_bit(int nr, volatile void *addr); |
| 15 | extern int test_and_clear_bit(int nr, volatile void *addr); |
| 16 | extern int test_and_change_bit(int nr, volatile void *addr); |
| 17 | |
TsiChungLiew | 1a33ce6 | 2007-08-05 04:31:18 -0500 | [diff] [blame] | 18 | #ifdef __KERNEL__ |
| 19 | |
| 20 | /* |
| 21 | * ffs: find first bit set. This is defined the same way as |
| 22 | * the libc and compiler builtin ffs routines, therefore |
| 23 | * differs in spirit from the above ffz (man ffs). |
| 24 | */ |
| 25 | extern __inline__ int ffs(int x) |
| 26 | { |
| 27 | int r = 1; |
| 28 | |
| 29 | if (!x) |
| 30 | return 0; |
| 31 | if (!(x & 0xffff)) { |
| 32 | x >>= 16; |
| 33 | r += 16; |
| 34 | } |
| 35 | if (!(x & 0xff)) { |
| 36 | x >>= 8; |
| 37 | r += 8; |
| 38 | } |
| 39 | if (!(x & 0xf)) { |
| 40 | x >>= 4; |
| 41 | r += 4; |
| 42 | } |
| 43 | if (!(x & 3)) { |
| 44 | x >>= 2; |
| 45 | r += 2; |
| 46 | } |
| 47 | if (!(x & 1)) { |
| 48 | x >>= 1; |
| 49 | r += 1; |
| 50 | } |
| 51 | return r; |
| 52 | } |
| 53 | #define __ffs(x) (ffs(x) - 1) |
Simon Kagstrom | 0413cfe | 2009-09-17 15:15:52 +0200 | [diff] [blame] | 54 | #define PLATFORM_FFS |
TsiChungLiew | 1a33ce6 | 2007-08-05 04:31:18 -0500 | [diff] [blame] | 55 | |
| 56 | #endif /* __KERNEL__ */ |
| 57 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 58 | #endif /* _M68K_BITOPS_H */ |