blob: c5c84c61690c6550cc2b9f86651e88241d16e49b [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>
Fabio Estevamc38be382015-11-05 12:43:26 -02009#include <asm-generic/bitops/fls.h>
10#include <asm-generic/bitops/__fls.h>
11#include <asm-generic/bitops/fls64.h>
12#include <asm-generic/bitops/__ffs.h>
wdenke65527f2004-02-12 00:47:09 +000013
14extern void set_bit(int nr, volatile void *addr);
15extern void clear_bit(int nr, volatile void *addr);
16extern void change_bit(int nr, volatile void *addr);
wdenke65527f2004-02-12 00:47:09 +000017extern int test_and_clear_bit(int nr, volatile void *addr);
18extern int test_and_change_bit(int nr, volatile void *addr);
19
TsiChungLiewec8468f2007-08-05 04:31:18 -050020#ifdef __KERNEL__
21
Måns Rullgård4dc39702015-11-06 12:44:01 +000022static inline int test_bit(int nr, __const__ volatile void *addr)
TsiChungLiewec8468f2007-08-05 04:31:18 -050023{
Alison Wangfd54d532012-03-25 19:18:49 +000024 __const__ unsigned int *p = (__const__ unsigned int *) addr;
TsiChungLiewec8468f2007-08-05 04:31:18 -050025
Alison Wangfd54d532012-03-25 19:18:49 +000026 return (p[nr >> 5] & (1UL << (nr & 31))) != 0;
TsiChungLiewec8468f2007-08-05 04:31:18 -050027}
Alison Wangfd54d532012-03-25 19:18:49 +000028
Måns Rullgård4dc39702015-11-06 12:44:01 +000029static inline int test_and_set_bit(int nr, volatile void *vaddr)
Alison Wangfd54d532012-03-25 19:18:49 +000030{
31 char retval;
32
33 volatile char *p = &((volatile char *)vaddr)[(nr^31) >> 3];
34 __asm__ __volatile__ ("bset %2,(%4); sne %0"
35 : "=d" (retval), "=m" (*p)
36 : "di" (nr & 7), "m" (*p), "a" (p));
37
38 return retval;
39}
40
TsiChungLiewec8468f2007-08-05 04:31:18 -050041#define __ffs(x) (ffs(x) - 1)
Alison Wangfd54d532012-03-25 19:18:49 +000042
43/*
44 * * hweightN: returns the hamming weight (i.e. the number
45 * * of bits set) of a N-bit word
46 * */
47
48#define hweight32(x) generic_hweight32(x)
49#define hweight16(x) generic_hweight16(x)
50#define hweight8(x) generic_hweight8(x)
TsiChungLiewec8468f2007-08-05 04:31:18 -050051
52#endif /* __KERNEL__ */
53
wdenke65527f2004-02-12 00:47:09 +000054#endif /* _M68K_BITOPS_H */