From: Stanislav Fomichev <sdf@fomichev.me>
To: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
Eric Dumazet <edumazet@google.com>,
netdev <netdev@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] tcp: don't use __constant_cpu_to_be32
Date: Mon, 18 Mar 2019 09:28:22 -0700 [thread overview]
Message-ID: <20190318162822.GB7431@mini-arch.hsd1.ca.comcast.net> (raw)
In-Reply-To: <20190316051902.GA27630@tigerII.localdomain>
On 03/16, Sergey Senozhatsky wrote:
> On (03/15/19 10:24), Stanislav Fomichev wrote:
> > On 03/15, Sergey Senozhatsky wrote:
> > > On (03/14/19 05:42), Eric Dumazet wrote:
> > > > > cpu_to_be32() is capable enough to detect __builtin_constant_p()
> > > > > and to use an appropriate compile time ___constant_swahb32()
> > > > > function.
> > See my recent commit a0517a0f7ef23 ("selftests/bpf: use
> > __bpf_constant_htons in test_prog.c") where compiler was not smart
> > enough to figure it out (you can google similar issues for GCC < 4.8).
>
> Allow me to disagree.
>
> The error in a0517a0f7ef23 says
>
> error: implicit declaration of function '__builtin_bswap16'
>
> which doesn't sound like "the compiler was not smart".
>
> Let's look at __swab16
>
> 100 #ifdef __HAVE_BUILTIN_BSWAP16__
> 101 #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
> 102 #else
> 103 #define __swab16(x) \
> 104 (__builtin_constant_p((__u16)(x)) ? \
> 105 ___constant_swab16(x) : \
> 106 __fswab16(x))
> 107 #endif
>
> We can call __builtin_bswap16() only when the compiler has that builtin,
> which is what #ifdef __HAVE_BUILTIN_BSWAP16__ for.
>
> But this is not what tools/testing/selftests/bpf/bpf_endian.h does
>
> # define __bpf_ntohs(x) __builtin_bswap16(x)
> # define __bpf_htons(x) __builtin_bswap16(x)
>
> So I sort of suspect that what should have been done was that
> __HAVE_BUILTIN_BSWAP16__ ifdef, just like what include/uapi/linux/swab.h
> does.
That sounds convincing, especially since we have the following
in include/linux/compiler-gcc.h:
#if GCC_VERSION >= 40800
#define __HAVE_BUILTIN_BSWAP16__
#endif
So it does indeed look like it's not __builtin_constant_p, but rather
missing __builtin_bswap16 for gcc < 4.8.
>
> -ss
prev parent reply other threads:[~2019-03-18 16:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-14 6:15 [PATCH] tcp: don't use __constant_cpu_to_be32 Sergey Senozhatsky
2019-03-14 12:42 ` Eric Dumazet
2019-03-15 1:20 ` Sergey Senozhatsky
2019-03-15 17:24 ` Stanislav Fomichev
2019-03-16 5:19 ` Sergey Senozhatsky
2019-03-16 7:18 ` Sergey Senozhatsky
2019-03-16 14:26 ` Sergey Senozhatsky
2019-03-18 16:32 ` Stanislav Fomichev
2019-03-19 1:29 ` Sergey Senozhatsky
2019-03-18 16:28 ` Stanislav Fomichev [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190318162822.GB7431@mini-arch.hsd1.ca.comcast.net \
--to=sdf@fomichev.me \
--cc=edumazet@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=sergey.senozhatsky@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).