Commit | Line | Data |
---|---|---|
96f1050d RG |
1 | /* |
2 | * Copyright 2004-2009 Analog Devices Inc. | |
3 | * | |
4 | * Licensed under the GPL-2 or later. | |
5 | */ | |
6 | ||
1394f032 BW |
7 | #ifndef _BLACKFIN_BITOPS_H |
8 | #define _BLACKFIN_BITOPS_H | |
9 | ||
0f7b468b MH |
10 | #include <linux/compiler.h> |
11 | ||
12 | #include <asm-generic/bitops/__ffs.h> | |
13 | #include <asm-generic/bitops/ffz.h> | |
14 | #include <asm-generic/bitops/fls.h> | |
15 | #include <asm-generic/bitops/__fls.h> | |
16 | #include <asm-generic/bitops/fls64.h> | |
17 | #include <asm-generic/bitops/find.h> | |
1394f032 | 18 | |
0624517d JS |
19 | #ifndef _LINUX_BITOPS_H |
20 | #error only <linux/bitops.h> can be included directly | |
21 | #endif | |
22 | ||
1394f032 | 23 | #include <asm-generic/bitops/sched.h> |
0f7b468b | 24 | #include <asm-generic/bitops/ffs.h> |
97e94c3a | 25 | #include <asm-generic/bitops/const_hweight.h> |
0f7b468b | 26 | #include <asm-generic/bitops/lock.h> |
97e94c3a | 27 | |
0f7b468b | 28 | #include <asm-generic/bitops/ext2-atomic.h> |
0f7b468b | 29 | |
b7bb7d9b PZ |
30 | #include <asm/barrier.h> |
31 | ||
0f7b468b MH |
32 | #ifndef CONFIG_SMP |
33 | #include <linux/irqflags.h> | |
0f7b468b MH |
34 | /* |
35 | * clear_bit may not imply a memory barrier | |
36 | */ | |
0f7b468b MH |
37 | #include <asm-generic/bitops/atomic.h> |
38 | #include <asm-generic/bitops/non-atomic.h> | |
39 | #else | |
1394f032 | 40 | |
0f7b468b | 41 | #include <asm/byteorder.h> /* swab32 */ |
6b3087c6 GY |
42 | #include <linux/linkage.h> |
43 | ||
44 | asmlinkage int __raw_bit_set_asm(volatile unsigned long *addr, int nr); | |
45 | ||
46 | asmlinkage int __raw_bit_clear_asm(volatile unsigned long *addr, int nr); | |
47 | ||
48 | asmlinkage int __raw_bit_toggle_asm(volatile unsigned long *addr, int nr); | |
49 | ||
50 | asmlinkage int __raw_bit_test_set_asm(volatile unsigned long *addr, int nr); | |
51 | ||
52 | asmlinkage int __raw_bit_test_clear_asm(volatile unsigned long *addr, int nr); | |
53 | ||
54 | asmlinkage int __raw_bit_test_toggle_asm(volatile unsigned long *addr, int nr); | |
55 | ||
56 | asmlinkage int __raw_bit_test_asm(const volatile unsigned long *addr, int nr); | |
57 | ||
58 | static inline void set_bit(int nr, volatile unsigned long *addr) | |
1394f032 | 59 | { |
6b3087c6 GY |
60 | volatile unsigned long *a = addr + (nr >> 5); |
61 | __raw_bit_set_asm(a, nr & 0x1f); | |
62 | } | |
1394f032 | 63 | |
6b3087c6 GY |
64 | static inline void clear_bit(int nr, volatile unsigned long *addr) |
65 | { | |
66 | volatile unsigned long *a = addr + (nr >> 5); | |
67 | __raw_bit_clear_asm(a, nr & 0x1f); | |
1394f032 BW |
68 | } |
69 | ||
6b3087c6 | 70 | static inline void change_bit(int nr, volatile unsigned long *addr) |
1394f032 | 71 | { |
6b3087c6 GY |
72 | volatile unsigned long *a = addr + (nr >> 5); |
73 | __raw_bit_toggle_asm(a, nr & 0x1f); | |
74 | } | |
1394f032 | 75 | |
6b3087c6 GY |
76 | static inline int test_bit(int nr, const volatile unsigned long *addr) |
77 | { | |
78 | volatile const unsigned long *a = addr + (nr >> 5); | |
79 | return __raw_bit_test_asm(a, nr & 0x1f) != 0; | |
1394f032 BW |
80 | } |
81 | ||
6b3087c6 GY |
82 | static inline int test_and_set_bit(int nr, volatile unsigned long *addr) |
83 | { | |
84 | volatile unsigned long *a = addr + (nr >> 5); | |
85 | return __raw_bit_test_set_asm(a, nr & 0x1f); | |
86 | } | |
1394f032 | 87 | |
6b3087c6 GY |
88 | static inline int test_and_clear_bit(int nr, volatile unsigned long *addr) |
89 | { | |
90 | volatile unsigned long *a = addr + (nr >> 5); | |
91 | return __raw_bit_test_clear_asm(a, nr & 0x1f); | |
92 | } | |
93 | ||
94 | static inline int test_and_change_bit(int nr, volatile unsigned long *addr) | |
95 | { | |
96 | volatile unsigned long *a = addr + (nr >> 5); | |
97 | return __raw_bit_test_toggle_asm(a, nr & 0x1f); | |
98 | } | |
99 | ||
71a516ad | 100 | #define test_bit __skip_test_bit |
3d150630 | 101 | #include <asm-generic/bitops/non-atomic.h> |
71a516ad | 102 | #undef test_bit |
1394f032 | 103 | |
0f7b468b | 104 | #endif /* CONFIG_SMP */ |
1394f032 | 105 | |
92a19d66 MF |
106 | /* Needs to be after test_bit and friends */ |
107 | #include <asm-generic/bitops/le.h> | |
108 | ||
0f7b468b MH |
109 | /* |
110 | * hweightN: returns the hamming weight (i.e. the number | |
111 | * of bits set) of a N-bit word | |
112 | */ | |
1394f032 | 113 | |
97e94c3a | 114 | static inline unsigned int __arch_hweight32(unsigned int w) |
0f7b468b MH |
115 | { |
116 | unsigned int res; | |
1394f032 | 117 | |
a13265af | 118 | __asm__ ("%0.l = ONES %1;" |
0f7b468b MH |
119 | "%0 = %0.l (Z);" |
120 | : "=d" (res) : "d" (w)); | |
121 | return res; | |
122 | } | |
1394f032 | 123 | |
97e94c3a | 124 | static inline unsigned int __arch_hweight64(__u64 w) |
0f7b468b | 125 | { |
97e94c3a MF |
126 | return __arch_hweight32((unsigned int)(w >> 32)) + |
127 | __arch_hweight32((unsigned int)w); | |
0f7b468b MH |
128 | } |
129 | ||
97e94c3a | 130 | static inline unsigned int __arch_hweight16(unsigned int w) |
0f7b468b | 131 | { |
97e94c3a | 132 | return __arch_hweight32(w & 0xffff); |
0f7b468b MH |
133 | } |
134 | ||
97e94c3a | 135 | static inline unsigned int __arch_hweight8(unsigned int w) |
0f7b468b | 136 | { |
97e94c3a | 137 | return __arch_hweight32(w & 0xff); |
0f7b468b | 138 | } |
3d150630 | 139 | |
1394f032 | 140 | #endif /* _BLACKFIN_BITOPS_H */ |