aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-generic/bitops/const_hweight.h
diff options
context:
space:
mode:
authorPaul Walmsley <pwalmsley@nvidia.com>2013-12-18 08:02:14 -0500
committerIngo Molnar <mingo@kernel.org>2014-02-09 07:39:26 -0500
commitc32fa99f0b4252633aa464e28d1cb925bd2a79df (patch)
tree3f857effbb10d28785fa4d4cc8d0f2fbe1c1e7ba /include/asm-generic/bitops/const_hweight.h
parent494479038d97f1b9f76fc633a360a681acdf035c (diff)
bitops: Fix signedness of compile-time hweight implementations
Enabling '-Wsign-compare' compiler warnings on code that includes include/linux/bitops.h can generate the following warning: In file included from include/linux/kernel.h:10:0, from <random filename>:48: include/linux/bitops.h: In function 'hweight_long': include/linux/bitops.h:77:26: error: signed and unsigned type in conditional expression [-Werror=sign-compare] (converted to an error with -Werror) This is due to the use of the logical negation operator '!' in the __const_hweight8 macro in include/asm-generic/bitops/const_hweight.h. The use of that operator here results in a signed value. Fix by explicitly casting the __const_hweight8 macro expansion to 'unsigned int'. While here, clean up several checkpatch.pl warnings. Signed-off-by: Paul Walmsley <pwalmsley@nvidia.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/alpine.DEB.2.02.1312180459580.30198@tamien Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'include/asm-generic/bitops/const_hweight.h')
-rw-r--r--include/asm-generic/bitops/const_hweight.h17
1 files changed, 9 insertions, 8 deletions
diff --git a/include/asm-generic/bitops/const_hweight.h b/include/asm-generic/bitops/const_hweight.h
index fa2a50b7ee66..0a7e06623470 100644
--- a/include/asm-generic/bitops/const_hweight.h
+++ b/include/asm-generic/bitops/const_hweight.h
@@ -5,14 +5,15 @@
5 * Compile time versions of __arch_hweightN() 5 * Compile time versions of __arch_hweightN()
6 */ 6 */
7#define __const_hweight8(w) \ 7#define __const_hweight8(w) \
8 ( (!!((w) & (1ULL << 0))) + \ 8 ((unsigned int) \
9 (!!((w) & (1ULL << 1))) + \ 9 ((!!((w) & (1ULL << 0))) + \
10 (!!((w) & (1ULL << 2))) + \ 10 (!!((w) & (1ULL << 1))) + \
11 (!!((w) & (1ULL << 3))) + \ 11 (!!((w) & (1ULL << 2))) + \
12 (!!((w) & (1ULL << 4))) + \ 12 (!!((w) & (1ULL << 3))) + \
13 (!!((w) & (1ULL << 5))) + \ 13 (!!((w) & (1ULL << 4))) + \
14 (!!((w) & (1ULL << 6))) + \ 14 (!!((w) & (1ULL << 5))) + \
15 (!!((w) & (1ULL << 7))) ) 15 (!!((w) & (1ULL << 6))) + \
16 (!!((w) & (1ULL << 7)))))
16 17
17#define __const_hweight16(w) (__const_hweight8(w) + __const_hweight8((w) >> 8 )) 18#define __const_hweight16(w) (__const_hweight8(w) + __const_hweight8((w) >> 8 ))
18#define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16)) 19#define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16))