blob: f9c434b4a3a4f67cfe7b6ce4f5555d952310192a [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
wdenke65527f2004-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
TsiChungLiewec8468f2007-08-05 04:31:18 -050017#ifdef __KERNEL__
18
Alison Wangfd54d532012-03-25 19:18:49 +000019
20extern inline int test_bit(int nr, __const__ volatile void *addr)
TsiChungLiewec8468f2007-08-05 04:31:18 -050021{
Alison Wangfd54d532012-03-25 19:18:49 +000022 __const__ unsigned int *p = (__const__ unsigned int *) addr;
TsiChungLiewec8468f2007-08-05 04:31:18 -050023
Alison Wangfd54d532012-03-25 19:18:49 +000024 return (p[nr >> 5] & (1UL << (nr & 31))) != 0;
TsiChungLiewec8468f2007-08-05 04:31:18 -050025}
Alison Wangfd54d532012-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
TsiChungLiewec8468f2007-08-05 04:31:18 -050039#define __ffs(x) (ffs(x) - 1)
Alison Wangfd54d532012-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)
TsiChungLiewec8468f2007-08-05 04:31:18 -050049
50#endif /* __KERNEL__ */
51
wdenke65527f2004-02-12 00:47:09 +000052#endif /* _M68K_BITOPS_H */