blob: f9c434b4a3a4f67cfe7b6ce4f5555d952310192a [file] [log] [blame]
wdenkbf9e3b32004-02-12 00:47:09 +00001/*
2 * bitops.h: Bit string operations on the m68k
3 */
4
5#ifndef _M68K_BITOPS_H
6#define _M68K_BITOPS_H
7
wdenkbf9e3b32004-02-12 00:47:09 +00008#include <asm/byteorder.h>
9
10extern void set_bit(int nr, volatile void *addr);
11extern void clear_bit(int nr, volatile void *addr);
12extern void change_bit(int nr, volatile void *addr);
13extern int test_and_set_bit(int nr, volatile void *addr);
14extern int test_and_clear_bit(int nr, volatile void *addr);
15extern int test_and_change_bit(int nr, volatile void *addr);
16
TsiChungLiew1a33ce62007-08-05 04:31:18 -050017#ifdef __KERNEL__
18
TsiChungLiew1a33ce62007-08-05 04:31:18 -050019
Alison Wangf7799a12012-03-25 19:18:49 +000020extern 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;
TsiChungLiew1a33ce62007-08-05 04:31:18 -050025}
Alison Wangf7799a12012-03-25 19:18:49 +000026
27extern 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
TsiChungLiew1a33ce62007-08-05 04:31:18 -050039#define __ffs(x) (ffs(x) - 1)
Alison Wangf7799a12012-03-25 19:18:49 +000040
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)
TsiChungLiew1a33ce62007-08-05 04:31:18 -050049
50#endif /* __KERNEL__ */
51
wdenkbf9e3b32004-02-12 00:47:09 +000052#endif /* _M68K_BITOPS_H */