[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


  • To: Lin Liu <lin.liu@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Fri, 15 Oct 2021 10:22:53 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tcEEOLuogRK5uoZ3FacOBqBT2+NDkomXpHyEYUQstR4=; b=Svla099OAwZ15hV4mA6oSbMHn6s8/0IeOfQVkVvXByOZw4xEwyfZYFQ4XR+pDokRKNozszs64c/1dCn5pLaYNq+b/LK8doj3P9Y9vp04gt+tXYSLsSCyie06fAo9m3CrwMWPV+lOcfpu1ltprs143WEXPrXcaxwSeOZcYSgKef74NLldJfLyUKrv77YvipcQFBzwG1zlvBC7xp1SZvmHeCaf87n9fV1BOxK4ODMareldL+Bm+kCnjBWPJfE6VXxg1vxSsQxEg7y6/ZsUAwZ7TqDc1k2x5yyGXXo4rEq8L4AUIDAzpc4JfEsFy9zpt7PL7yAPNiOl3iSzMjbUYr2FNA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iYRyIQPbObyhdpT2DZ20kbjkxgX3UfV5sfVGhrU0omrFwhU7T8YY0sthG9BrhtQyQGYrIuOVg/Xmgwb8mQi5HpfPgvuEfdJGQtouFV/Pz8MZ7UxISHaSBY4uuoYX4BgC46z0KZzTRIFP9+ci0ktGfLoDw+pesYEBXHlZBFXX1+WH1HPzvNt/yglbfbMgM35wtayojkJ5JKh+BffauuUs7YP6pTeIwwaz5zvMIa18dmV0LGEFwuyM+BVCivCYZrxYxEmgKnefghPK9Qcx4HpCrtnEh6v7Wq3lFc3/fexj4d7ghnU35ZPlSbis8erAY8vcD/PKBqIx0xMlzs/7DYn66Q==
  • Authentication-results: lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=none action=none header.from=suse.com;
  • Cc: sstabellini@xxxxxxxxxx, julien@xxxxxxx, Volodymyr_Babchuk@xxxxxxxx, andrew.cooper3@xxxxxxxxxx, George.Dunlap@xxxxxxxxxxxxx, ian.jackson@xxxxxxxxxxxxx, konrad.wilk@xxxxxxxxxx, wl@xxxxxxx, roger.pau@xxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Fri, 15 Oct 2021 08:23:02 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.