blob: 525d90ccb02c2d47234cd92beb8a904be362d1ed [file] [log] [blame]
wdenke65527f2004-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
TsiChungLiewec8468f2007-08-05 04:31:18 -050018#ifdef __KERNEL__
19
Alison Wangfd54d532012-03-25 19:18:49 +000020
21extern inline int test_bit(int nr, __const__ volatile void *addr)
TsiChungLiewec8468f2007-08-05 04:31:18 -050022{
Alison Wangfd54d532012-03-25 19:18:49 +000023 __const__ unsigned int *p = (__const__ unsigned int *) addr;
TsiChungLiewec8468f2007-08-05 04:31:18 -050024
Alison Wangfd54d532012-03-25 19:18:49 +000025 return (p[nr >> 5] & (1UL << (nr & 31))) != 0;
TsiChungLiewec8468f2007-08-05 04:31:18 -050026}
Alison Wangfd54d532012-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
TsiChungLiewec8468f2007-08-05 04:31:18 -050040#define __ffs(x) (ffs(x) - 1)
Alison Wangfd54d532012-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)
TsiChungLiewec8468f2007-08-05 04:31:18 -050050
51#endif /* __KERNEL__ */
52
wdenke65527f2004-02-12 00:47:09 +000053#endif /* _M68K_BITOPS_H */