Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1428712

Re: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug

From Tomas Winkler <tomasw@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug
Date 2016-06-22 13:50 +0200
Message-ID <rMOPn-2Q3-9@gated-at.bofh.it> (permalink)
References <rutT5-3cr-19@gated-at.bofh.it> <rMq0F-3PM-9@gated-at.bofh.it> <rMLRw-137-13@gated-at.bofh.it> <rMNqi-25n-11@gated-at.bofh.it> <rMNJD-2bS-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, Jun 22, 2016 at 1:25 PM, Levy, Amir (Jer)
<amir.jer.levy@intel.com> wrote:
> On 2016-06-22 Arnd Bergmann wrote:
>> On Wednesday, June 22, 2016 11:24:50 AM CEST Tomas Winkler wrote:
>> > On Tue, Jun 21, 2016 at 12:02 PM, Tomas Winkler <tomasw@gmail.com>
>> wrote:
>> > > On Tue, May 3, 2016 at 9:36 AM, Arnd Bergmann <arnd@arndb.de>
>> wrote:
>> > >> On Monday 02 May 2016 16:32:25 Andrew Morton wrote:
>>
>> > >>  #ifdef __HAVE_BUILTIN_BSWAP32__
>> > >> -#define __swab32(x) __builtin_bswap32((__u32)(x))
>> > >> +#define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
>> > >>  #else
>> > >>  #define __swab32(x)                            \
>> > >>         (__builtin_constant_p((__u32)(x)) ?     \
>> > >
>> > >>
>> > >
>> > > I wonder if this doesn't break switch statement that requires a
>> > > constant expression, there few cases like this over the kernel.
>> > >
>> > > switch(val) {
>> > > case cpu_to_le32(IXGBE_RXDADV_STAT_FCSTAT_FCPRSP):
>> > >
>> > > http://lxr.free-electrons.com/source/drivers/net/ethernet/intel/ixgb
>> > > e/ixgbe_fcoe.c#L458
>> > >
>> >
>> > I'm asking because sparse and checkpatch doesn't agree on that ping
>> > sparse issues
>> > 'error: bad constant expression'
>> > When changing to __constant_cpu_to_le32 sparse is happy but
>> > checkpatch.ps is complaining
>> > __constant_cpu_to_le32 should be cpu_to_le32
>> >
>>
>> That is an interesting problem, as both seem to be reasonable:
>> sparse probably doesn't understand __builtin_constant_p() enough, while
>> avoiding __constant_cpu_to_le32() is a good recommendation in general.
>>
>> How many instances of this do you see in the kernel? If ixgbe is the only one,
>> I'd just move the byteswap up into the switch statement:
>>
>>       switch (le32_to_cpu(val)) {
>>       case IXGBE_RXDADV_STAT_FCSTAT_FCPRSP:
>>
>> which may cost one or two cycles for the non-constant byteswap, but is also
>> easier to read than the current code.
>>
>>       Arnd
>
> There are more than 20 files that have the statement: case cpu_to_...
> Sparse complains about: case __builtin_bswap, not about __builtin_constant_p.

There is even much more in the header files used in  initializers,
which also require constants.  I wonder if __builtin_bswap produces
constant expression correctly under gcc?

Thanks
Tomas

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug Tomas Winkler <tomasw@gmail.com> - 2016-06-21 11:20 +0200
  Re: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug Tomas Winkler <tomasw@gmail.com> - 2016-06-22 10:40 +0200
    Re: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug Arnd Bergmann <arnd@arndb.de> - 2016-06-22 12:20 +0200
      RE: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug "Levy, Amir (Jer)" <amir.jer.levy@intel.com> - 2016-06-22 12:40 +0200
        Re: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug Tomas Winkler <tomasw@gmail.com> - 2016-06-22 13:50 +0200
          Re: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug Arnd Bergmann <arnd@arndb.de> - 2016-06-22 14:40 +0200
            Re: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug Tomas Winkler <tomasw@gmail.com> - 2016-06-23 08:30 +0200
              Re: [PATCH v2] byteswap: try to avoid __builtin_constant_p gcc bug Arnd Bergmann <arnd@arndb.de> - 2016-06-23 11:30 +0200

csiph-web