[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH 1/1] xen/include/xen/byteorder: Re-implement bswap/swab with compiler builtin functions
On 15.10.2021 09:26, Lin Liu wrote: > Current implementation of bswap/swab is overhaul which involves > byte operations, compilers has builtin functions can help to > simply the implementation > * GCC: https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html > * Clang: https://clang.llvm.org/docs/LanguageExtensions.html > > This commit replace the implementation with compiler builtins __builtin_bswap{32,64}() appeared in gcc 4.3, __builtin_bswap16() in gcc 4.8. I don't think we can use these just yet without having any fallback. Apart from this aspect the change looks okay to me, with just one nit: > --- a/xen/include/xen/byteorder/swab.h > +++ b/xen/include/xen/byteorder/swab.h > @@ -10,166 +10,32 @@ > * to clean up support for bizarre-endian architectures. > */ > > -/* casts are necessary for constants, because we never know how for sure > - * how U/UL/ULL map to __u16, __u32, __u64. At least not in a portable way. > - */ > -#define ___swab16(x) \ > -({ \ > - __u16 __x = (x); \ > - ((__u16)( \ > - (((__u16)(__x) & (__u16)0x00ffU) << 8) | \ > - (((__u16)(__x) & (__u16)0xff00U) >> 8) )); \ > -}) > - > -#define ___swab32(x) \ > -({ \ > - __u32 __x = (x); \ > - ((__u32)( \ > - (((__u32)(__x) & (__u32)0x000000ffUL) << 24) | \ > - (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | \ > - (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | \ > - (((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); \ > -}) > +#define __swab16(x) (__builtin_bswap16(x)) In cases like this one there's no need for the outer pair of parentheses. Jan
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |