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 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 8 | #include <asm/byteorder.h> |
| 9 | |
| 10 | extern void set_bit(int nr, volatile void *addr); |
| 11 | extern void clear_bit(int nr, volatile void *addr); |
| 12 | extern void change_bit(int nr, volatile void *addr); |
| 13 | extern int test_and_set_bit(int nr, volatile void *addr); |
| 14 | extern int test_and_clear_bit(int nr, volatile void *addr); |
| 15 | extern int test_and_change_bit(int nr, volatile void *addr); |
| 16 | |
TsiChungLiew | 1a33ce6 | 2007-08-05 04:31:18 -0500 | [diff] [blame] | 17 | #ifdef __KERNEL__ |
| 18 | |
TsiChungLiew | 1a33ce6 | 2007-08-05 04:31:18 -0500 | [diff] [blame] | 19 | |
Alison Wang | f7799a1 | 2012-03-25 19:18:49 +0000 | [diff] [blame] | 20 | extern inline int test_bit(int nr, __const__ volatile void *addr) |
| 21 | { |
| 22 | __const__ unsigned int *p = (__const__ unsigned int *) addr; |
| 23 | |
| 24 | return (p[nr >> 5] & (1UL << (nr & 31))) != 0; |
TsiChungLiew | 1a33ce6 | 2007-08-05 04:31:18 -0500 | [diff] [blame] | 25 | } |
Alison Wang | f7799a1 | 2012-03-25 19:18:49 +0000 | [diff] [blame] | 26 | |
| 27 | extern inline int test_and_set_bit(int nr, volatile void *vaddr) |
| 28 | { |
| 29 | char retval; |
| 30 | |
| 31 | volatile char *p = &((volatile char *)vaddr)[(nr^31) >> 3]; |
| 32 | __asm__ __volatile__ ("bset %2,(%4); sne %0" |
| 33 | : "=d" (retval), "=m" (*p) |
| 34 | : "di" (nr & 7), "m" (*p), "a" (p)); |
| 35 | |
| 36 | return retval; |
| 37 | } |
| 38 | |
TsiChungLiew | 1a33ce6 | 2007-08-05 04:31:18 -0500 | [diff] [blame] | 39 | #define __ffs(x) (ffs(x) - 1) |
Alison Wang | f7799a1 | 2012-03-25 19:18:49 +0000 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * * hweightN: returns the hamming weight (i.e. the number |
| 43 | * * of bits set) of a N-bit word |
| 44 | * */ |
| 45 | |
| 46 | #define hweight32(x) generic_hweight32(x) |
| 47 | #define hweight16(x) generic_hweight16(x) |
| 48 | #define hweight8(x) generic_hweight8(x) |
TsiChungLiew | 1a33ce6 | 2007-08-05 04:31:18 -0500 | [diff] [blame] | 49 | |
| 50 | #endif /* __KERNEL__ */ |
| 51 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 52 | #endif /* _M68K_BITOPS_H */ |