Commit a13265af99c8c10c61b7713d62d8d163fbf30a94
1 parent
1ae9ab17e7
Exists in
master
and in
4 other branches
Blackfin: fix typo in hweight asm
Run ONES on the incoming value rather than random garbage. This fixes random crashes with some networking code. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Showing 1 changed file with 1 additions and 1 deletions Inline Diff
arch/blackfin/include/asm/bitops.h
1 | /* | 1 | /* |
2 | * Copyright 2004-2009 Analog Devices Inc. | 2 | * Copyright 2004-2009 Analog Devices Inc. |
3 | * | 3 | * |
4 | * Licensed under the GPL-2 or later. | 4 | * Licensed under the GPL-2 or later. |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef _BLACKFIN_BITOPS_H | 7 | #ifndef _BLACKFIN_BITOPS_H |
8 | #define _BLACKFIN_BITOPS_H | 8 | #define _BLACKFIN_BITOPS_H |
9 | 9 | ||
10 | #include <linux/compiler.h> | 10 | #include <linux/compiler.h> |
11 | 11 | ||
12 | #include <asm-generic/bitops/__ffs.h> | 12 | #include <asm-generic/bitops/__ffs.h> |
13 | #include <asm-generic/bitops/ffz.h> | 13 | #include <asm-generic/bitops/ffz.h> |
14 | #include <asm-generic/bitops/fls.h> | 14 | #include <asm-generic/bitops/fls.h> |
15 | #include <asm-generic/bitops/__fls.h> | 15 | #include <asm-generic/bitops/__fls.h> |
16 | #include <asm-generic/bitops/fls64.h> | 16 | #include <asm-generic/bitops/fls64.h> |
17 | #include <asm-generic/bitops/find.h> | 17 | #include <asm-generic/bitops/find.h> |
18 | 18 | ||
19 | #ifndef _LINUX_BITOPS_H | 19 | #ifndef _LINUX_BITOPS_H |
20 | #error only <linux/bitops.h> can be included directly | 20 | #error only <linux/bitops.h> can be included directly |
21 | #endif | 21 | #endif |
22 | 22 | ||
23 | #include <asm-generic/bitops/sched.h> | 23 | #include <asm-generic/bitops/sched.h> |
24 | #include <asm-generic/bitops/ffs.h> | 24 | #include <asm-generic/bitops/ffs.h> |
25 | #include <asm-generic/bitops/lock.h> | 25 | #include <asm-generic/bitops/lock.h> |
26 | #include <asm-generic/bitops/ext2-non-atomic.h> | 26 | #include <asm-generic/bitops/ext2-non-atomic.h> |
27 | #include <asm-generic/bitops/ext2-atomic.h> | 27 | #include <asm-generic/bitops/ext2-atomic.h> |
28 | #include <asm-generic/bitops/minix.h> | 28 | #include <asm-generic/bitops/minix.h> |
29 | 29 | ||
30 | #ifndef CONFIG_SMP | 30 | #ifndef CONFIG_SMP |
31 | #include <linux/irqflags.h> | 31 | #include <linux/irqflags.h> |
32 | 32 | ||
33 | /* | 33 | /* |
34 | * clear_bit may not imply a memory barrier | 34 | * clear_bit may not imply a memory barrier |
35 | */ | 35 | */ |
36 | #ifndef smp_mb__before_clear_bit | 36 | #ifndef smp_mb__before_clear_bit |
37 | #define smp_mb__before_clear_bit() smp_mb() | 37 | #define smp_mb__before_clear_bit() smp_mb() |
38 | #define smp_mb__after_clear_bit() smp_mb() | 38 | #define smp_mb__after_clear_bit() smp_mb() |
39 | #endif | 39 | #endif |
40 | #include <asm-generic/bitops/atomic.h> | 40 | #include <asm-generic/bitops/atomic.h> |
41 | #include <asm-generic/bitops/non-atomic.h> | 41 | #include <asm-generic/bitops/non-atomic.h> |
42 | #else | 42 | #else |
43 | 43 | ||
44 | #include <asm/byteorder.h> /* swab32 */ | 44 | #include <asm/byteorder.h> /* swab32 */ |
45 | #include <linux/linkage.h> | 45 | #include <linux/linkage.h> |
46 | 46 | ||
47 | asmlinkage int __raw_bit_set_asm(volatile unsigned long *addr, int nr); | 47 | asmlinkage int __raw_bit_set_asm(volatile unsigned long *addr, int nr); |
48 | 48 | ||
49 | asmlinkage int __raw_bit_clear_asm(volatile unsigned long *addr, int nr); | 49 | asmlinkage int __raw_bit_clear_asm(volatile unsigned long *addr, int nr); |
50 | 50 | ||
51 | asmlinkage int __raw_bit_toggle_asm(volatile unsigned long *addr, int nr); | 51 | asmlinkage int __raw_bit_toggle_asm(volatile unsigned long *addr, int nr); |
52 | 52 | ||
53 | asmlinkage int __raw_bit_test_set_asm(volatile unsigned long *addr, int nr); | 53 | asmlinkage int __raw_bit_test_set_asm(volatile unsigned long *addr, int nr); |
54 | 54 | ||
55 | asmlinkage int __raw_bit_test_clear_asm(volatile unsigned long *addr, int nr); | 55 | asmlinkage int __raw_bit_test_clear_asm(volatile unsigned long *addr, int nr); |
56 | 56 | ||
57 | asmlinkage int __raw_bit_test_toggle_asm(volatile unsigned long *addr, int nr); | 57 | asmlinkage int __raw_bit_test_toggle_asm(volatile unsigned long *addr, int nr); |
58 | 58 | ||
59 | asmlinkage int __raw_bit_test_asm(const volatile unsigned long *addr, int nr); | 59 | asmlinkage int __raw_bit_test_asm(const volatile unsigned long *addr, int nr); |
60 | 60 | ||
61 | static inline void set_bit(int nr, volatile unsigned long *addr) | 61 | static inline void set_bit(int nr, volatile unsigned long *addr) |
62 | { | 62 | { |
63 | volatile unsigned long *a = addr + (nr >> 5); | 63 | volatile unsigned long *a = addr + (nr >> 5); |
64 | __raw_bit_set_asm(a, nr & 0x1f); | 64 | __raw_bit_set_asm(a, nr & 0x1f); |
65 | } | 65 | } |
66 | 66 | ||
67 | static inline void clear_bit(int nr, volatile unsigned long *addr) | 67 | static inline void clear_bit(int nr, volatile unsigned long *addr) |
68 | { | 68 | { |
69 | volatile unsigned long *a = addr + (nr >> 5); | 69 | volatile unsigned long *a = addr + (nr >> 5); |
70 | __raw_bit_clear_asm(a, nr & 0x1f); | 70 | __raw_bit_clear_asm(a, nr & 0x1f); |
71 | } | 71 | } |
72 | 72 | ||
73 | static inline void change_bit(int nr, volatile unsigned long *addr) | 73 | static inline void change_bit(int nr, volatile unsigned long *addr) |
74 | { | 74 | { |
75 | volatile unsigned long *a = addr + (nr >> 5); | 75 | volatile unsigned long *a = addr + (nr >> 5); |
76 | __raw_bit_toggle_asm(a, nr & 0x1f); | 76 | __raw_bit_toggle_asm(a, nr & 0x1f); |
77 | } | 77 | } |
78 | 78 | ||
79 | static inline int test_bit(int nr, const volatile unsigned long *addr) | 79 | static inline int test_bit(int nr, const volatile unsigned long *addr) |
80 | { | 80 | { |
81 | volatile const unsigned long *a = addr + (nr >> 5); | 81 | volatile const unsigned long *a = addr + (nr >> 5); |
82 | return __raw_bit_test_asm(a, nr & 0x1f) != 0; | 82 | return __raw_bit_test_asm(a, nr & 0x1f) != 0; |
83 | } | 83 | } |
84 | 84 | ||
85 | static inline int test_and_set_bit(int nr, volatile unsigned long *addr) | 85 | static inline int test_and_set_bit(int nr, volatile unsigned long *addr) |
86 | { | 86 | { |
87 | volatile unsigned long *a = addr + (nr >> 5); | 87 | volatile unsigned long *a = addr + (nr >> 5); |
88 | return __raw_bit_test_set_asm(a, nr & 0x1f); | 88 | return __raw_bit_test_set_asm(a, nr & 0x1f); |
89 | } | 89 | } |
90 | 90 | ||
91 | static inline int test_and_clear_bit(int nr, volatile unsigned long *addr) | 91 | static inline int test_and_clear_bit(int nr, volatile unsigned long *addr) |
92 | { | 92 | { |
93 | volatile unsigned long *a = addr + (nr >> 5); | 93 | volatile unsigned long *a = addr + (nr >> 5); |
94 | return __raw_bit_test_clear_asm(a, nr & 0x1f); | 94 | return __raw_bit_test_clear_asm(a, nr & 0x1f); |
95 | } | 95 | } |
96 | 96 | ||
97 | static inline int test_and_change_bit(int nr, volatile unsigned long *addr) | 97 | static inline int test_and_change_bit(int nr, volatile unsigned long *addr) |
98 | { | 98 | { |
99 | volatile unsigned long *a = addr + (nr >> 5); | 99 | volatile unsigned long *a = addr + (nr >> 5); |
100 | return __raw_bit_test_toggle_asm(a, nr & 0x1f); | 100 | return __raw_bit_test_toggle_asm(a, nr & 0x1f); |
101 | } | 101 | } |
102 | 102 | ||
103 | /* | 103 | /* |
104 | * clear_bit() doesn't provide any barrier for the compiler. | 104 | * clear_bit() doesn't provide any barrier for the compiler. |
105 | */ | 105 | */ |
106 | #define smp_mb__before_clear_bit() barrier() | 106 | #define smp_mb__before_clear_bit() barrier() |
107 | #define smp_mb__after_clear_bit() barrier() | 107 | #define smp_mb__after_clear_bit() barrier() |
108 | 108 | ||
109 | #include <asm-generic/bitops/non-atomic.h> | 109 | #include <asm-generic/bitops/non-atomic.h> |
110 | 110 | ||
111 | #endif /* CONFIG_SMP */ | 111 | #endif /* CONFIG_SMP */ |
112 | 112 | ||
113 | /* | 113 | /* |
114 | * hweightN: returns the hamming weight (i.e. the number | 114 | * hweightN: returns the hamming weight (i.e. the number |
115 | * of bits set) of a N-bit word | 115 | * of bits set) of a N-bit word |
116 | */ | 116 | */ |
117 | 117 | ||
118 | static inline unsigned int hweight32(unsigned int w) | 118 | static inline unsigned int hweight32(unsigned int w) |
119 | { | 119 | { |
120 | unsigned int res; | 120 | unsigned int res; |
121 | 121 | ||
122 | __asm__ ("%0.l = ONES %0;" | 122 | __asm__ ("%0.l = ONES %1;" |
123 | "%0 = %0.l (Z);" | 123 | "%0 = %0.l (Z);" |
124 | : "=d" (res) : "d" (w)); | 124 | : "=d" (res) : "d" (w)); |
125 | return res; | 125 | return res; |
126 | } | 126 | } |
127 | 127 | ||
128 | static inline unsigned int hweight64(__u64 w) | 128 | static inline unsigned int hweight64(__u64 w) |
129 | { | 129 | { |
130 | return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w); | 130 | return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w); |
131 | } | 131 | } |
132 | 132 | ||
133 | static inline unsigned int hweight16(unsigned int w) | 133 | static inline unsigned int hweight16(unsigned int w) |
134 | { | 134 | { |
135 | return hweight32(w & 0xffff); | 135 | return hweight32(w & 0xffff); |
136 | } | 136 | } |
137 | 137 | ||
138 | static inline unsigned int hweight8(unsigned int w) | 138 | static inline unsigned int hweight8(unsigned int w) |
139 | { | 139 | { |
140 | return hweight32(w & 0xff); | 140 | return hweight32(w & 0xff); |
141 | } | 141 | } |
142 | 142 | ||
143 | #endif /* _BLACKFIN_BITOPS_H */ | 143 | #endif /* _BLACKFIN_BITOPS_H */ |
144 | 144 |