From nobody Sat Nov 1 07:50:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1743169516; cv=none; d=zohomail.com; s=zohoarc; b=Pah5Lv2caHpCx7jj82HJLo5QXH9mrX5bjvxNFmCC/OxaZhhPnZ7ONtMhAVpz3lZWWl21oYLGYtWQqfh1b9Mq5GsL+oO+A4OaTFzhxKdUo/PjdiGUWPMWChTmlkv2HLDKg7r/BFPKKHpZEvckQymCJOQaCF3jlEI6OQlGqyWGEHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1743169516; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SnmFGZh2rWbEy7OVP//9VnfXl8YcAR4cPveLI05OgG8=; b=Ygs5osZCKNSTPDxx1cd3savuI94jyTZ7D3nyOUKPJG3+7Xg4GVszgTKV2TBE2FMSRv9u0RtkR3yAgA/nLXyZIeQ/VSdQn8TuudtbewnuPjytx6TzXE+3jT+LdV6vYdWkbWrvU0LVi3ounYHbTyb2FviDvZPhsSJzzyD7afQgSrI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1743169516797643.6576682210859; Fri, 28 Mar 2025 06:45:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.930660.1333243 (Exim 4.92) (envelope-from ) id 1tyA0l-0005N7-Qc; Fri, 28 Mar 2025 13:44:39 +0000 Received: by outflank-mailman (output) from mailman id 930660.1333243; Fri, 28 Mar 2025 13:44:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tyA0l-0005Lk-MU; Fri, 28 Mar 2025 13:44:39 +0000 Received: by outflank-mailman (input) for mailman id 930660; Fri, 28 Mar 2025 13:44:38 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tyA0k-0005Dp-5i for xen-devel@lists.xenproject.org; Fri, 28 Mar 2025 13:44:38 +0000 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [2a00:1450:4864:20::331]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ca3bd7d6-0bda-11f0-9ea3-5ba50f476ded; Fri, 28 Mar 2025 14:44:37 +0100 (CET) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-43d04ea9d9aso9910575e9.3 for ; Fri, 28 Mar 2025 06:44:37 -0700 (PDT) Received: from localhost.localdomain (host-92-26-98-202.as13285.net. [92.26.98.202]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d8314f5c6sm73339085e9.40.2025.03.28.06.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Mar 2025 06:44:35 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ca3bd7d6-0bda-11f0-9ea3-5ba50f476ded DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1743169476; x=1743774276; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SnmFGZh2rWbEy7OVP//9VnfXl8YcAR4cPveLI05OgG8=; b=oukTryhz2N+E26GnKvoZohLGKQk4H74xRzqqk6pQpGilyQNFAOC5X9hw1+0sQWwXrI FILXX1zcpnXtDy1uOBBXnFI3XqfkfNNIL+xReQ/FeaJkv6Iq02Oj7RdYVDtXWlChiIJH GReTGxJ/+FPXC8b7s1TLRL7Ys+sJkfdn51KQY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743169476; x=1743774276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SnmFGZh2rWbEy7OVP//9VnfXl8YcAR4cPveLI05OgG8=; b=LOr5Pjn8h/ZqCAGP/yOMlmsnrA9Cm+uIzuaCAXUPXeyTzmPmciwI85U3KXNR77WGb0 wDJ2/ZtZ6NKv1CkUB9SoXLJDBOYOESiPf7zpQ8jxIE9IOCnEutuFB64NLHaCAXoXANd1 T5zsszfr4k6n124xMlNQrq7D7rgSP/Nba7QlkjnjRNq9go8u+2PfhKPw6jQi/TBJPq58 vYxagrs6Lh1vOz31xfByORBf7uOfGOQHipUCnd0UtDSvqlpoDyE2W7UH/QcbqUZ1I/vt nkU/8OuxJUeG6IvTx3XC2s/7V6qGVWC6TkltA63/fnGxw6LMGCHjp95pX6S+UkfRQsS7 PtdA== X-Gm-Message-State: AOJu0YxsxDNXDkxEsd/SGJXxyMF9pScpWG4AlPH3HcQOmr2U4BLT0b5d dmJbJOxbefjlguaUN4wrVNL3GwXXzDOnCqb91wtjJL56YfdEGXjKzdQ7TjJveLU3ojspeB8bNCN qJN8= X-Gm-Gg: ASbGncuE5M4+HR3WusOlM2qNE4Dpm7+P5q2WmiiFdTFr47DeT5ii9gxKCEuQUrylD+/ VNH9no4Rph1kb7Ha00unjmxD2FT+cnCjYAMXy0/oQmj9m7bI6R0b5mZM2AuBlxw9sa7WgR7E2LW 3zrz2o7dRT+zlyllkmMlnxiBMW5TSpYA9DdYx/sp2z6L+ngbedp/yWyjMZYLfq1pHx7yQIww8jZ L46ewDKrU53rpVsVCab/SAbqTWolWQ8bsNMXdOGjU+geDJEv0ZhTfuoML3hvmnRRVh36dTJ10+9 8Xejk2oZb8YOTeumv1x+CnuRyRJ2OIgXbgh5waFKKXect9qoeoZtOy6W4+A2Syd2MPXtgEbtJhv CB9j3K2CfBHRd3GFWng== X-Google-Smtp-Source: AGHT+IG0L24lXhaREFMHxWE7TkKiPdJJLa25T1zFmm+87C1wfPYQvQrBSAHNDtw8hOILYL/dRPC8wg== X-Received: by 2002:a05:600c:1388:b0:43d:b3:fb1 with SMTP id 5b1f17b1804b1-43d8528c38cmr53745725e9.27.1743169476335; Fri, 28 Mar 2025 06:44:36 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Lin Liu , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Volodymyr Babchuk , Bertrand Marquis , Shawn Anastasio , Oleksii Kurochko , "Daniel P . Smith" Subject: [PATCH v5 03/16] xen: Implement common byte{order,swap}.h Date: Fri, 28 Mar 2025 13:44:14 +0000 Message-Id: <20250328134427.874848-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250328134427.874848-1-andrew.cooper3@citrix.com> References: <20250328134427.874848-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1743169525374019100 From: Lin Liu The current swab??() infrastructure is unecesserily complicated, and can be repated entirely with compiler builtins. All supported compilers provide __BYTE_ORDER__ and __builtin_bswap??(). Nothing in Xen cares about the values of __{BIG,LITTLE}_ENDIAN; just that o= ne of them is defined. Therefore, centralise their definitions in xen/config.h Signed-off-by: Lin Liu Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Anthony PERARD CC: Michal Orzel CC: Jan Beulich CC: Julien Grall CC: Roger Pau Monn=C3=A9 CC: Stefano Stabellini CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Shawn Anastasio CC: Oleksii Kurochko CC: Daniel P. Smith CC: Lin Liu v5: * Rebase substantially * Drop PASTE(). It doesn't work when BITS_PER_LONG isn't a plain integer * Simplify in light of new toolchain baseline --- xen/include/xen/byteorder.h | 44 +++++++++++++++++++++++ xen/include/xen/byteorder/big_endian.h | 4 --- xen/include/xen/byteorder/little_endian.h | 4 --- xen/include/xen/byteswap.h | 15 ++++++++ xen/include/xen/config.h | 6 ++++ 5 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 xen/include/xen/byteorder.h create mode 100644 xen/include/xen/byteswap.h diff --git a/xen/include/xen/byteorder.h b/xen/include/xen/byteorder.h new file mode 100644 index 000000000000..570a7fe027e5 --- /dev/null +++ b/xen/include/xen/byteorder.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef XEN_BYTEORDER_H +#define XEN_BYTEORDER_H + +#include +#include + +#if defined(__LITTLE_ENDIAN) + +# define cpu_to_le64(x) (uint64_t)(x) +# define le64_to_cpu(x) (uint64_t)(x) +# define cpu_to_le32(x) (uint32_t)(x) +# define le32_to_cpu(x) (uint32_t)(x) +# define cpu_to_le16(x) (uint16_t)(x) +# define le16_to_cpu(x) (uint16_t)(x) + +# define cpu_to_be64(x) bswap64(x) +# define be64_to_cpu(x) bswap64(x) +# define cpu_to_be32(x) bswap32(x) +# define be32_to_cpu(x) bswap32(x) +# define cpu_to_be16(x) bswap16(x) +# define be16_to_cpu(x) bswap16(x) + +#elif defined(__BIG_ENDIAN) + +# define cpu_to_le64(x) bswap64(x) +# define le64_to_cpu(x) bswap64(x) +# define cpu_to_le32(x) bswap32(x) +# define le32_to_cpu(x) bswap32(x) +# define cpu_to_le16(x) bswap16(x) +# define le16_to_cpu(x) bswap16(x) + +# define cpu_to_be64(x) (uint64_t)(x) +# define be64_to_cpu(x) (uint64_t)(x) +# define cpu_to_be32(x) (uint32_t)(x) +# define be32_to_cpu(x) (uint32_t)(x) +# define cpu_to_be16(x) (uint16_t)(x) +# define be16_to_cpu(x) (uint16_t)(x) + +#else +# error Unknown Endianness +#endif /* __*_ENDIAN */ + +#endif /* XEN_BYTEORDER_H */ diff --git a/xen/include/xen/byteorder/big_endian.h b/xen/include/xen/byteo= rder/big_endian.h index 9cfb567d51d5..512291c76f1b 100644 --- a/xen/include/xen/byteorder/big_endian.h +++ b/xen/include/xen/byteorder/big_endian.h @@ -1,10 +1,6 @@ #ifndef __XEN_BYTEORDER_BIG_ENDIAN_H__ #define __XEN_BYTEORDER_BIG_ENDIAN_H__ =20 -#ifndef __BIG_ENDIAN -#define __BIG_ENDIAN 4321 -#endif - #include #include =20 diff --git a/xen/include/xen/byteorder/little_endian.h b/xen/include/xen/by= teorder/little_endian.h index 96c80eab2b12..bd1afc6a67c3 100644 --- a/xen/include/xen/byteorder/little_endian.h +++ b/xen/include/xen/byteorder/little_endian.h @@ -1,10 +1,6 @@ #ifndef __XEN_BYTEORDER_LITTLE_ENDIAN_H__ #define __XEN_BYTEORDER_LITTLE_ENDIAN_H__ =20 -#ifndef __LITTLE_ENDIAN -#define __LITTLE_ENDIAN 1234 -#endif - #include #include =20 diff --git a/xen/include/xen/byteswap.h b/xen/include/xen/byteswap.h new file mode 100644 index 000000000000..46d93f88eac9 --- /dev/null +++ b/xen/include/xen/byteswap.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef XEN_BYTESWAP_H +#define XEN_BYTESWAP_H + +#define bswap16(x) __builtin_bswap16(x) +#define bswap32(x) __builtin_bswap32(x) +#define bswap64(x) __builtin_bswap64(x) + +#if BITS_PER_LONG =3D=3D 64 +# define bswapl(x) bswap64(x) +#elif BITS_PER_LONG =3D=3D 32 +# define bswapl(x) bswap32(x) +#endif + +#endif /* XEN_BYTESWAP_H */ diff --git a/xen/include/xen/config.h b/xen/include/xen/config.h index d888b2314daf..6815a0ef0c1a 100644 --- a/xen/include/xen/config.h +++ b/xen/include/xen/config.h @@ -98,4 +98,10 @@ #define ZERO_BLOCK_PTR ((void *)-1L) #endif =20 +#if __BYTE_ORDER__ =3D=3D __ORDER_LITTLE_ENDIAN__ +# define __LITTLE_ENDIAN +#elif __BYTE_ORDER__ =3D=3D __ORDER_BIG_ENDIAN__ +# define __BIG_ENDIAN +#endif + #endif /* __XEN_CONFIG_H__ */ --=20 2.39.5