[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 1/7] xen: implement byteswap.h


  • To: Lin Liu <lin.liu@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 2 Nov 2021 15:23:28 +0100
  • 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=OJng58TG3BKvwIEUR8OViWD7UL6AEv0nwt8jLHHik0E=; b=IlZqjRotabS7ilyzqv3WWfh+kh8gqLRxOjxgNlxPJ9r9643V7kyKXeVo3CTuqTw8D4Q/4ccA8jzPMB69YF4iw38WvU/InX/7V72pQmnXp/ts/MED9sPaBKAmC0GhtNeKqX2utw9SOZsQVE1fpX9Xbi9NAU96r2ebom5+0s7Lvspw8O3CHYXOcZq22gIJwsoTiejSAP/Z3TaGVoBExG+E55pI1lQ77CXxLilV1N/7Ov3c4Rnwc4Rb04IsdwRpxQFbcD68CTE9AYTitFKoxnJ8wdEioV1/E8U2sWdKoZC7y2bZcRsKCcw5Dczw/c1kBq91ce5bx9pDJraDvYMoFy5ruw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ASgwDXxWSohfZRoscCcnY9AMrTuhVQex0FkTOckNao8J2ztDu12l1Dso1IA2D2kQtyU9d14mirDMQEuA0nnu0RIJiimlD+SAn0XaouvOH0re/XQU/u4/EAxNbkcYihbhA196jdU1dImo2E9sldwBnn410cR2BahVqR26pjzji9VmX0D2jV0r1347/RNSL6wmwcZ5qZZMibxOzbGDDuntybJSb8HezQy13kLyJ9L3l6BcFi/I2RCj+bNTiXEN3NgE122n2vkltG+FAnBOpDGsa3Mo97wEo08pqKJfscK1SqZEVcom2/MF0I9UdEzwkTCcOkI9qf2yMTL8Luxcduu+Eg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 02 Nov 2021 14:23:44 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 22.10.2021 12:47, Lin Liu wrote:
> --- /dev/null
> +++ b/xen/include/xen/byteswap.h
> @@ -0,0 +1,93 @@
> +#ifndef _BYTESWAP_H
> +#define _BYTESWAP_H
> +
> +#include <xen/types.h>
> +
> +#if !__has_builtin(__builtin_bswap16)
> +static always_inline uint16_t __builtin_bswap16(uint16_t val)
> +{
> +    return ((val & 0x00FF) << 8) | ((val & 0xFF00) >> 8);
> +}
> +#endif
> +
> +#if !__has_builtin(__builtin_bswap32)
> +static always_inline uint32_t __builtin_bswap32(uint32_t val)
> +{
> +    return ((val & 0x000000FF) << 24) |
> +           ((val & 0x0000FF00) <<  8) |
> +           ((val & 0x00FF0000) >>  8) |
> +           ((val & 0xFF000000) >> 24);
> +}
> +#endif
> +
> +#if !__has_builtin(__builtin_bswap64)
> +static always_inline uint64_t __builtin_bswap64(uint64_t val)
> +{
> +    return ((val & 0x00000000000000FF) << 56) |
> +           ((val & 0x000000000000FF00) << 40) |
> +           ((val & 0x0000000000FF0000) << 24) |
> +           ((val & 0x00000000FF000000) <<  8) |
> +           ((val & 0x000000FF00000000) >>  8) |
> +           ((val & 0x0000FF0000000000) >> 24) |
> +           ((val & 0x00FF000000000000) >> 40) |
> +           ((val & 0xFF00000000000000) >> 56);
> +}
> +#endif
> +
> +#define bswap16(x) __builtin_bswap16(x)
> +#define bswap32(x) __builtin_bswap32(x)
> +#define bswap64(x) __builtin_bswap64(x)
> +
> +#define bswap_ul(x) bswap##BITS_PER_LONG(x)

I don't see how this is supposed to work - the compiler isn't going to
expand BITS_PER_LONG before the token concatenation. You'll need helper
macros to achieve that. Linux has __PASTE(); we may want to "steal" that
(albeit preferably without any leading underscores).

> +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__

While you've worked towards abstracting older vs newer compiler
versions, I'm afraid these constants aren't available in gcc 4.1 yet.
They look to have appeared in 4.6.

> +#  ifndef __LITTLE_ENDIAN
> +#    define __LITTLE_ENDIAN 1234
> +#  endif
> +
> +#  ifndef __LITTLE_ENDIAN_BITFIELD
> +#    define __LITTLE_ENDIAN_BITFIELD
> +#  endif

These are definitions which I don't think belong into a header of this
name. They're imo well placed in byteorder/*.h.

Jan




 


Rackspace

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