blob: 525d90ccb02c2d47234cd92beb8a904be362d1ed [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
8#include <linux/config.h>
9#include <asm/byteorder.h>
10
11extern void set_bit(int nr, volatile void *addr);
12extern void clear_bit(int nr, volatile void *addr);
13extern void change_bit(int nr, volatile void *addr);
14extern int test_and_set_bit(int nr, volatile void *addr);
15extern int test_and_clear_bit(int nr, volatile void *addr);
16extern int test_and_change_bit(int nr, volatile void *addr);
17
TsiChungLiew1a33ce62007-08-05 04:31:18 -050018#ifdef __KERNEL__
19
TsiChungLiew1a33ce62007-08-05 04:31:18 -050020
Alison Wangf7799a12012-03-25 19:18:49 +000021extern 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;
TsiChungLiew1a33ce62007-08-05 04:31:18 -050026}
Alison Wangf7799a12012-03-25 19:18:49 +000027
28extern 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
TsiChungLiew1a33ce62007-08-05 04:31:18 -050040#define __ffs(x) (ffs(x) - 1)
Alison Wangf7799a12012-03-25 19:18:49 +000041
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)
TsiChungLiew1a33ce62007-08-05 04:31:18 -050050
51#endif /* __KERNEL__ */
52
wdenkbf9e3b32004-02-12 00:47:09 +000053#endif /* _M68K_BITOPS_H */