Re: [PATCH] bitops.h: Widen BIT macro to support 64-bit types

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linus Torvalds
Date: Thursday, October 14, 2010 - 8:03 am

On Thu, Oct 14, 2010 at 3:58 AM, Borislav Petkov <bp@amd64.org> wrote:

Yeah. I object. I have no idea what this will change for everything
else that expects bitops to work on unsigned long values.

I really think that the bug is not in the BIT() definition, but in the
use. If somebody wants a non-unsigned-long bit field, they had better
not use bitops.h.

And no, just changing the BIT() macro to return a 64-bit value is
_not_ trivially safe. Due to C type rules, now all arithmetic using
BIT() will suddenly be 64-bit, which is often *much* slower, and can
introduce real bugs.

On many architectures, a 64-bit non-constant shift will even end up
being a function call. And if the thing is used in a varargs function,
the argument layout will be totally different. We've also had several
issues with 64-bit types and switch() statements, for example. And a
quick grep for '\<BIT(' shows that non-constant cases are not unheard
of, and there's a lot of random use where it is not at all obvious
that it's safe (because it's used for defining other defines).

So no. I do not think BIT() should be 64-bit. It's "unsigned long".
Look at all the other things around it, and look at all the historical
uses.

                                    Linus
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH -next] edac/mce_amd: fix shift warning, Randy Dunlap, (Wed Oct 13, 1:10 pm)
Re: [PATCH -next] edac/mce_amd: fix shift warning, Borislav Petkov, (Wed Oct 13, 9:24 pm)
[PATCH] bitops.h: Widen BIT macro to support 64-bit types, Borislav Petkov, (Thu Oct 14, 3:58 am)
Re: [PATCH] bitops.h: Widen BIT macro to support 64-bit types, Linus Torvalds, (Thu Oct 14, 8:03 am)