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