blob: 0f9e8abe9c12e43e23865686e1a8edea3ae29203 [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
20/*
21 * ffs: find first bit set. This is defined the same way as
22 * the libc and compiler builtin ffs routines, therefore
23 * differs in spirit from the above ffz (man ffs).
24 */
25extern __inline__ int ffs(int x)
26{
27 int r = 1;
28
29 if (!x)
30 return 0;
31 if (!(x & 0xffff)) {
32 x >>= 16;
33 r += 16;
34 }
35 if (!(x & 0xff)) {
36 x >>= 8;
37 r += 8;
38 }
39 if (!(x & 0xf)) {
40 x >>= 4;
41 r += 4;
42 }
43 if (!(x & 3)) {
44 x >>= 2;
45 r += 2;
46 }
47 if (!(x & 1)) {
48 x >>= 1;
49 r += 1;
50 }
51 return r;
52}
53#define __ffs(x) (ffs(x) - 1)
54
55#endif /* __KERNEL__ */
56
wdenkbf9e3b32004-02-12 00:47:09 +000057#endif /* _M68K_BITOPS_H */