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

Re: [PATCH v4 1/4] common: Move a few more standalone macros from xen/lib.h to xen/macros.h


  • To: Shawn Anastasio <sanastasio@xxxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 19 Jul 2023 10:08:36 +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=aTLgFJWNstHopnT5HXG6kEe/abyzGC77JFD7tO9ND/c=; b=HgKccJ/Gx31tq9vnqbFhGTryTPJR86NSXDaYWzJWVwF4m70a5xbOMG7USCT156nS9YmMJfsUcKy9gb867fcmgHUbU7Awt36dHirhUnVK102Vtn74Xo1s6vrUZFSiLXeox3ulEen1mLxgbFVkAZDjpwnYyRIdx4pntAEyEeGD/TnHkuhBPCpl3xEg1rDDZRBh0ltdPx8V5TX+w71EfKNlV5ZfcvFJ3Ril005S6YkgM5EwrklEpg69Lcu0TigYmpCa0xb3yHHj9LrsqfZvWRj0XoMf/OLB5jjKPFOrz3RbvUq7K/6Epa6f5iO/LWSauyXV4eEq/MP8iS3VCG0Kgww9PQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K409wA3uhtHazrQ46rFhYeoLsk9gICXD9+0T4UYKMR5cmeNosqTXmRRCsuELqGRlj4Romu5/qaYZGFV3DrrZgcxyNFfG64t0dkaH4WjRL3VmLSC06eVTjL762acJgqcPCDio6gnXVeU2xYtBxOG/wJ7TQZBkEKQ3eks4utuNoXlmnNzuNthMmDU67EsrFo410eWQCleaVZgmen4B6vGO16h5z8y7S2CYT+VtXmLydk0DiA88H4dwUd8YbWuJnnwfWldhZ++67f9z2IDGeMD3HzEf9voIBaT2reFrvnJtixfBxpQeN4pHLHuRBf5m5Cau9reEklKduNbWUJ4XMCb9YQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Timothy Pearson <tpearson@xxxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 19 Jul 2023 08:08:47 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 18.07.2023 22:20, Shawn Anastasio wrote:
> 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.
> ---

I would have wanted to put this directly on top of my patch, but
the submission lack S-o-b.

> --- 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). */

While moving this, please correct comment style.

> +#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 )

While I won't insist here, it would be nice if we could also get rid of
the bogus leading underscores as these are moved. Arguments here don't
need any, while the local variables want to use trailing underscores,
like we do elsewhere.

With at least the earlier two items taken care of, feel free to also add
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>

Jan



 


Rackspace

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