From patchwork Tue Jul 18 20:20:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Anastasio X-Patchwork-Id: 13317672 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B8DCEB64DC for ; Tue, 18 Jul 2023 20:32:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.565460.883584 (Exim 4.92) (envelope-from ) id 1qLrMr-0007SM-Nb; Tue, 18 Jul 2023 20:32:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 565460.883584; Tue, 18 Jul 2023 20:32:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qLrMr-0007SF-Kv; Tue, 18 Jul 2023 20:32:21 +0000 Received: by outflank-mailman (input) for mailman id 565460; Tue, 18 Jul 2023 20:32:19 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qLrMp-0006yH-IK for xen-devel@lists.xenproject.org; Tue, 18 Jul 2023 20:32:19 +0000 Received: from raptorengineering.com (mail.raptorengineering.com [23.155.224.40]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2edc3385-25aa-11ee-8611-37d641c3527e; Tue, 18 Jul 2023 22:32:16 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id 635788285396; Tue, 18 Jul 2023 15:32:15 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id t0mjCamFhqmA; Tue, 18 Jul 2023 15:32:13 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id 938998285A3B; Tue, 18 Jul 2023 15:32:13 -0500 (CDT) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 7W-CI3l_eoV5; Tue, 18 Jul 2023 15:32:13 -0500 (CDT) Received: from raptor-ewks-026.lan (5.edge.rptsys.com [23.155.224.38]) by mail.rptsys.com (Postfix) with ESMTPSA id 2B2A5828589A; Tue, 18 Jul 2023 15:32:13 -0500 (CDT) 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: 2edc3385-25aa-11ee-8611-37d641c3527e DKIM-Filter: OpenDKIM Filter v2.10.3 mail.rptsys.com 938998285A3B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raptorengineering.com; s=B8E824E6-0BE2-11E6-931D-288C65937AAD; t=1689712333; bh=weycgpq7UdUBoobNsiQD+7ga0dfxfiI9umDJ8AHZ8kE=; h=From:To:Date:Message-Id:MIME-Version; b=HMKOJd1VlyEKyKu3om012mBPKf3gWCrvrkJWJqcqogxU1VkLhBZ2BAcYtZ0ebp/oZ L7ORdRGgrulIc+XEdSCrPuiEj8kdKk19AHGEdFvXuVHUv58F12I3+gfxG2V6NTxe4M nDlPrM6rlnmbJTNNptZJYlFbme2ek+rRyNIdFXm0= X-Virus-Scanned: amavisd-new at rptsys.com From: Shawn Anastasio To: xen-devel@lists.xenproject.org Cc: Timothy Pearson , Andrew Cooper , Jan Beulich , Shawn Anastasio Subject: [PATCH v4 1/4] common: Move a few more standalone macros from xen/lib.h to xen/macros.h Date: Tue, 18 Jul 2023 15:20:22 -0500 Message-Id: <10ce452be68b4f83213f5199a3b84459a479bcda.1689710519.git.sanastasio@raptorengineering.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Move a few more macros which have no dependencies on other headers from xen/lib.h to xen/macros.h. Notably, this includes BUILD_BUG_ON* and ARRAY_SIZE. Reviewed-by: Jan Beulich --- xen/include/xen/lib.h | 28 ---------------------------- xen/include/xen/macros.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h index dae2a1f085..359cfdc784 100644 --- a/xen/include/xen/lib.h +++ b/xen/include/xen/lib.h @@ -21,24 +21,6 @@ unlikely(ret_warn_on_); \ }) -/* All clang versions supported by Xen have _Static_assert. */ -#if defined(__clang__) || \ - (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) -/* Force a compilation error if condition is true */ -#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); }) - -/* Force a compilation error if condition is true, but also produce a - result (of value 0 and type size_t), so the expression can be used - e.g. in a structure initializer (or where-ever else comma expressions - aren't permitted). */ -#define BUILD_BUG_ON_ZERO(cond) \ - (sizeof(struct { char c; _Static_assert(!(cond), "!(" #cond ")"); }) & 0) -#else -#define BUILD_BUG_ON_ZERO(cond) \ - (sizeof(struct { unsigned u : !(cond); }) & 0) -#define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond)) -#endif - #ifndef NDEBUG #define ASSERT(p) \ do { if ( unlikely(!(p)) ) assert_failed(#p); } while (0) @@ -48,16 +30,6 @@ #define ASSERT_UNREACHABLE() do { } while (0) #endif -#define ABS(_x) ({ \ - typeof(_x) __x = (_x); \ - (__x < 0) ? -__x : __x; \ -}) - -#define SWAP(_a, _b) \ - do { typeof(_a) _t = (_a); (_a) = (_b); (_b) = _t; } while ( 0 ) - -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x)) - #define __ACCESS_ONCE(x) ({ \ (void)(typeof(x))0; /* Scalar typecheck. */ \ (volatile typeof(x) *)&(x); }) diff --git a/xen/include/xen/macros.h b/xen/include/xen/macros.h index 7b92d34504..e2832b0e8a 100644 --- a/xen/include/xen/macros.h +++ b/xen/include/xen/macros.h @@ -22,6 +22,38 @@ #define __STR(...) #__VA_ARGS__ #define STR(...) __STR(__VA_ARGS__) +#ifndef __ASSEMBLY__ + +/* All clang versions supported by Xen have _Static_assert. */ +#if defined(__clang__) || \ + (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +/* Force a compilation error if condition is true */ +#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); }) + +/* Force a compilation error if condition is true, but also produce a + result (of value 0 and type size_t), so the expression can be used + e.g. in a structure initializer (or where-ever else comma expressions + aren't permitted). */ +#define BUILD_BUG_ON_ZERO(cond) \ + (sizeof(struct { char c; _Static_assert(!(cond), "!(" #cond ")"); }) & 0) +#else +#define BUILD_BUG_ON_ZERO(cond) \ + (sizeof(struct { unsigned u : !(cond); }) & 0) +#define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond)) +#endif + +#define ABS(_x) ({ \ + typeof(_x) __x = (_x); \ + (__x < 0) ? -__x : __x; \ +}) + +#define SWAP(_a, _b) \ + do { typeof(_a) _t = (_a); (_a) = (_b); (_b) = _t; } while ( 0 ) + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x)) + +#endif /* __ASSEMBLY__ */ + #endif /* __MACROS_H__ */ /*