aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-generic/bitops.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-generic/bitops.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/asm-generic/bitops.h')
-rw-r--r--include/asm-generic/bitops.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/include/asm-generic/bitops.h b/include/asm-generic/bitops.h
new file mode 100644
index 000000000000..ce31b739fd80
--- /dev/null
+++ b/include/asm-generic/bitops.h
@@ -0,0 +1,81 @@
1#ifndef _ASM_GENERIC_BITOPS_H_
2#define _ASM_GENERIC_BITOPS_H_
3
4/*
5 * For the benefit of those who are trying to port Linux to another
6 * architecture, here are some C-language equivalents. You should
7 * recode these in the native assembly language, if at all possible.
8 * To guarantee atomicity, these routines call cli() and sti() to
9 * disable interrupts while they operate. (You have to provide inline
10 * routines to cli() and sti().)
11 *
12 * Also note, these routines assume that you have 32 bit longs.
13 * You will have to change this if you are trying to port Linux to the
14 * Alpha architecture or to a Cray. :-)
15 *
16 * C language equivalents written by Theodore Ts'o, 9/26/92
17 */
18
19extern __inline__ int set_bit(int nr,long * addr)
20{
21 int mask, retval;
22
23 addr += nr >> 5;
24 mask = 1 << (nr & 0x1f);
25 cli();
26 retval = (mask & *addr) != 0;
27 *addr |= mask;
28 sti();
29 return retval;
30}
31
32extern __inline__ int clear_bit(int nr, long * addr)
33{
34 int mask, retval;
35
36 addr += nr >> 5;
37 mask = 1 << (nr & 0x1f);
38 cli();
39 retval = (mask & *addr) != 0;
40 *addr &= ~mask;
41 sti();
42 return retval;
43}
44
45extern __inline__ int test_bit(int nr, const unsigned long * addr)
46{
47 int mask;
48
49 addr += nr >> 5;
50 mask = 1 << (nr & 0x1f);
51 return ((mask & *addr) != 0);
52}
53
54/*
55 * fls: find last bit set.
56 */
57
58#define fls(x) generic_fls(x)
59
60#ifdef __KERNEL__
61
62/*
63 * ffs: find first bit set. This is defined the same way as
64 * the libc and compiler builtin ffs routines, therefore
65 * differs in spirit from the above ffz (man ffs).
66 */
67
68#define ffs(x) generic_ffs(x)
69
70/*
71 * hweightN: returns the hamming weight (i.e. the number
72 * of bits set) of a N-bit word
73 */
74
75#define hweight32(x) generic_hweight32(x)
76#define hweight16(x) generic_hweight16(x)
77#define hweight8(x) generic_hweight8(x)
78
79#endif /* __KERNEL__ */
80
81#endif /* _ASM_GENERIC_BITOPS_H */