aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2006-03-25 06:08:01 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-03-25 11:22:58 -0500
commit962749af67b145c57917bfbff3c303ebd7d5988c (patch)
treece454f8a1cb0beb89c875a11d31426a4b44ca0ba
parent231bed205879236357171e50bd8965e70797ecdc (diff)
[PATCH] roundup_pow_of_two() 64-bit fix
fls() takes an integer, so roundup_pow_of_two() is busted for ulongs larger than 2^32-1. Fix this by implementing and using fls_long(). (Why does roundup_pow_of_two() return a long?) (Why is roundup_pow_of_two() __attribute_const__ whereas long_log2() is __attribute_pure__?) (Why does long_log2() suck so much? Because we were missing fls_long()?) Cc: Roland Dreier <rdreier@cisco.com> Cc: "Chen, Kenneth W" <kenneth.w.chen@intel.com> Cc: John Hawkes <hawkes@sgi.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--include/linux/bitops.h7
-rw-r--r--include/linux/kernel.h5
2 files changed, 10 insertions, 2 deletions
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 208650b1ad3a..f17525a963d1 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -175,4 +175,11 @@ static inline __u32 ror32(__u32 word, unsigned int shift)
175 return (word >> shift) | (word << (32 - shift)); 175 return (word >> shift) | (word << (32 - shift));
176} 176}
177 177
178static inline unsigned fls_long(unsigned long l)
179{
180 if (sizeof(l) == 4)
181 return fls(l);
182 return fls64(l);
183}
184
178#endif 185#endif
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index bb6e7ddee2fd..03d6cfaa5b8a 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -154,9 +154,10 @@ static inline int __attribute_pure__ long_log2(unsigned long x)
154 return r; 154 return r;
155} 155}
156 156
157static inline unsigned long __attribute_const__ roundup_pow_of_two(unsigned long x) 157static inline unsigned long
158__attribute_const__ roundup_pow_of_two(unsigned long x)
158{ 159{
159 return (1UL << fls(x - 1)); 160 return 1UL << fls_long(x - 1);
160} 161}
161 162
162extern int printk_ratelimit(void); 163extern int printk_ratelimit(void);