All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bitops: fix signedness of compile-time hweight implementations
@ 2013-12-18 13:02 ` Paul Walmsley
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Walmsley @ 2013-12-18 13:02 UTC (permalink / raw)
  To: H. Peter Anvin, Peter Zijlstra, Arnd Bergmann; +Cc: linux-arch, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2113 bytes --]


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: H. Peter Anvin <hpa@zytor.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnd Bergmann <arnd@arndb.de>
---
Intended for v3.14.

  include/asm-generic/bitops/const_hweight.h | 17 +++++++++--------
  1 file 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..40966203804d 100644
--- a/include/asm-generic/bitops/const_hweight.h
+++ b/include/asm-generic/bitops/const_hweight.h
@@ -5,14 +5,15 @@
   * Compile time versions of __arch_hweightN()
   */
  #define __const_hweight8(w)		\
-      (	(!!((w) & (1ULL << 0))) +	\
-	(!!((w) & (1ULL << 1))) +	\
-	(!!((w) & (1ULL << 2))) +	\
-	(!!((w) & (1ULL << 3))) +	\
-	(!!((w) & (1ULL << 4))) +	\
-	(!!((w) & (1ULL << 5))) +	\
-	(!!((w) & (1ULL << 6))) +	\
-	(!!((w) & (1ULL << 7)))	)
+	((unsigned int)		\
+	 ((!!((w) & (1ULL << 0))) +	\
+	  (!!((w) & (1ULL << 1))) +	\
+	  (!!((w) & (1ULL << 2))) +	\
+	  (!!((w) & (1ULL << 3))) +	\
+	  (!!((w) & (1ULL << 4))) +	\
+	  (!!((w) & (1ULL << 5))) +	\
+	  (!!((w) & (1ULL << 6))) +	\
+	  (!!((w) & (1ULL << 7)))))

  #define __const_hweight16(w) (__const_hweight8(w)  + __const_hweight8((w)  >> 8 ))
  #define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16))
-- 
1.8.5.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] bitops: fix signedness of compile-time hweight implementations
@ 2013-12-18 13:02 ` Paul Walmsley
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Walmsley @ 2013-12-18 13:02 UTC (permalink / raw)
  To: H. Peter Anvin, Peter Zijlstra, Arnd Bergmann; +Cc: linux-arch, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2113 bytes --]


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: H. Peter Anvin <hpa@zytor.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnd Bergmann <arnd@arndb.de>
---
Intended for v3.14.

  include/asm-generic/bitops/const_hweight.h | 17 +++++++++--------
  1 file 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..40966203804d 100644
--- a/include/asm-generic/bitops/const_hweight.h
+++ b/include/asm-generic/bitops/const_hweight.h
@@ -5,14 +5,15 @@
   * Compile time versions of __arch_hweightN()
   */
  #define __const_hweight8(w)		\
-      (	(!!((w) & (1ULL << 0))) +	\
-	(!!((w) & (1ULL << 1))) +	\
-	(!!((w) & (1ULL << 2))) +	\
-	(!!((w) & (1ULL << 3))) +	\
-	(!!((w) & (1ULL << 4))) +	\
-	(!!((w) & (1ULL << 5))) +	\
-	(!!((w) & (1ULL << 6))) +	\
-	(!!((w) & (1ULL << 7)))	)
+	((unsigned int)		\
+	 ((!!((w) & (1ULL << 0))) +	\
+	  (!!((w) & (1ULL << 1))) +	\
+	  (!!((w) & (1ULL << 2))) +	\
+	  (!!((w) & (1ULL << 3))) +	\
+	  (!!((w) & (1ULL << 4))) +	\
+	  (!!((w) & (1ULL << 5))) +	\
+	  (!!((w) & (1ULL << 6))) +	\
+	  (!!((w) & (1ULL << 7)))))

  #define __const_hweight16(w) (__const_hweight8(w)  + __const_hweight8((w)  >> 8 ))
  #define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16))
-- 
1.8.5.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] bitops: fix signedness of compile-time hweight implementations
  2013-12-18 13:02 ` Paul Walmsley
  (?)
@ 2014-01-22 17:19 ` Paul Walmsley
  2014-01-22 17:47   ` Peter Zijlstra
  -1 siblings, 1 reply; 5+ messages in thread
From: Paul Walmsley @ 2014-01-22 17:19 UTC (permalink / raw)
  To: H. Peter Anvin, Peter Zijlstra, Arnd Bergmann; +Cc: linux-arch, linux-kernel

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2512 bytes --]

Hi Peter, hpa, Arnd,

On Wed, 18 Dec 2013, Paul Walmsley wrote:

> 
> 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: H. Peter Anvin <hpa@zytor.com>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Cc: Arnd Bergmann <arnd@arndb.de>
> ---
> Intended for v3.14.

Ping.  Just checking to see if you have any comments on this one, or if 
you're planning to send it upstream for v3.14.


- Paul

> 
>  include/asm-generic/bitops/const_hweight.h | 17 +++++++++--------
>  1 file 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..40966203804d 100644
> --- a/include/asm-generic/bitops/const_hweight.h
> +++ b/include/asm-generic/bitops/const_hweight.h
> @@ -5,14 +5,15 @@
>   * Compile time versions of __arch_hweightN()
>   */
>  #define __const_hweight8(w)		\
> -      (	(!!((w) & (1ULL << 0))) +	\
> -	(!!((w) & (1ULL << 1))) +	\
> -	(!!((w) & (1ULL << 2))) +	\
> -	(!!((w) & (1ULL << 3))) +	\
> -	(!!((w) & (1ULL << 4))) +	\
> -	(!!((w) & (1ULL << 5))) +	\
> -	(!!((w) & (1ULL << 6))) +	\
> -	(!!((w) & (1ULL << 7)))	)
> +	((unsigned int)		\
> +	 ((!!((w) & (1ULL << 0))) +	\
> +	  (!!((w) & (1ULL << 1))) +	\
> +	  (!!((w) & (1ULL << 2))) +	\
> +	  (!!((w) & (1ULL << 3))) +	\
> +	  (!!((w) & (1ULL << 4))) +	\
> +	  (!!((w) & (1ULL << 5))) +	\
> +	  (!!((w) & (1ULL << 6))) +	\
> +	  (!!((w) & (1ULL << 7)))))
> 
>  #define __const_hweight16(w) (__const_hweight8(w)  + __const_hweight8((w)  >>
> 8 ))
>  #define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >>
> 16))
> -- 
> 1.8.5.1
> 


- Paul

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] bitops: fix signedness of compile-time hweight implementations
  2014-01-22 17:19 ` Paul Walmsley
@ 2014-01-22 17:47   ` Peter Zijlstra
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Zijlstra @ 2014-01-22 17:47 UTC (permalink / raw)
  To: Paul Walmsley; +Cc: H. Peter Anvin, Arnd Bergmann, linux-arch, linux-kernel

On Wed, Jan 22, 2014 at 05:19:58PM +0000, Paul Walmsley wrote:
> Hi Peter, hpa, Arnd,
> 
> On Wed, 18 Dec 2013, Paul Walmsley wrote:
> 
> > 
> > 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: H. Peter Anvin <hpa@zytor.com>
> > Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> > Cc: Arnd Bergmann <arnd@arndb.de>
> > ---
> > Intended for v3.14.
> 
> Ping.  Just checking to see if you have any comments on this one, or if 
> you're planning to send it upstream for v3.14.

I'm not sure through which tree to send it, but just I've queued it so
it doesn't get lost again.

Also, it didn't apply as is for some reason, hit it on the head with a
hammer though.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tip:core/types] bitops: Fix signedness of compile-time hweight implementations
  2013-12-18 13:02 ` Paul Walmsley
  (?)
  (?)
@ 2014-02-10 13:30 ` tip-bot for Paul Walmsley
  -1 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Paul Walmsley @ 2014-02-10 13:30 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, torvalds, peterz, arnd, akpm, tglx, pwalmsley

Commit-ID:  c32fa99f0b4252633aa464e28d1cb925bd2a79df
Gitweb:     http://git.kernel.org/tip/c32fa99f0b4252633aa464e28d1cb925bd2a79df
Author:     Paul Walmsley <pwalmsley@nvidia.com>
AuthorDate: Wed, 18 Dec 2013 05:02:14 -0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sun, 9 Feb 2014 13:39:26 +0100

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>
---
 include/asm-generic/bitops/const_hweight.h | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/include/asm-generic/bitops/const_hweight.h b/include/asm-generic/bitops/const_hweight.h
index fa2a50b..0a7e066 100644
--- a/include/asm-generic/bitops/const_hweight.h
+++ b/include/asm-generic/bitops/const_hweight.h
@@ -5,14 +5,15 @@
  * Compile time versions of __arch_hweightN()
  */
 #define __const_hweight8(w)		\
-      (	(!!((w) & (1ULL << 0))) +	\
-	(!!((w) & (1ULL << 1))) +	\
-	(!!((w) & (1ULL << 2))) +	\
-	(!!((w) & (1ULL << 3))) +	\
-	(!!((w) & (1ULL << 4))) +	\
-	(!!((w) & (1ULL << 5))) +	\
-	(!!((w) & (1ULL << 6))) +	\
-	(!!((w) & (1ULL << 7)))	)
+	((unsigned int)			\
+	 ((!!((w) & (1ULL << 0))) +	\
+	  (!!((w) & (1ULL << 1))) +	\
+	  (!!((w) & (1ULL << 2))) +	\
+	  (!!((w) & (1ULL << 3))) +	\
+	  (!!((w) & (1ULL << 4))) +	\
+	  (!!((w) & (1ULL << 5))) +	\
+	  (!!((w) & (1ULL << 6))) +	\
+	  (!!((w) & (1ULL << 7)))))
 
 #define __const_hweight16(w) (__const_hweight8(w)  + __const_hweight8((w)  >> 8 ))
 #define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16))

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-02-10 13:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-18 13:02 [PATCH] bitops: fix signedness of compile-time hweight implementations Paul Walmsley
2013-12-18 13:02 ` Paul Walmsley
2014-01-22 17:19 ` Paul Walmsley
2014-01-22 17:47   ` Peter Zijlstra
2014-02-10 13:30 ` [tip:core/types] bitops: Fix " tip-bot for Paul Walmsley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.