lkml.org 
[lkml]   [2019]   [Mar]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] tcp: don't use __constant_cpu_to_be32
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.

-ss

\
 
 \ /
  Last update: 2019-03-16 06:20    [W:0.265 / U:0.208 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site