xref: /openbmc/u-boot/arch/m68k/include/asm/bitops.h (revision ee52b188)
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 
18 #ifdef __KERNEL__
19 
20 
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;
26 }
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 
40 #define __ffs(x) (ffs(x) - 1)
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)
50 
51 #endif /* __KERNEL__ */
52 
53 #endif /* _M68K_BITOPS_H */
54