From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
James Clark <james.clark@linaro.org>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
Clark Williams <williams@redhat.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Vincent Mailhol <mailhol.vincent@wanadoo.fr>,
Yury Norov <yury.norov@gmail.com>
Subject: [PATCH 6/7] tools headers compiler: Pick the const_true() define from the kernel sources
Date: Mon, 19 May 2025 18:41:25 -0300 [thread overview]
Message-ID: <20250519214126.1652491-7-acme@kernel.org> (raw)
In-Reply-To: <20250519214126.1652491-1-acme@kernel.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
The sync of include/linux/bits.h with the kernel sources will make use
of this define, so add it to the tools/include/linux/compiler. variant
used to build tools/ living code.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Cc: Yury Norov <yury.norov@gmail.com>
Link: https://lore.kernel.org/r/
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/include/linux/compiler.h | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
index 9c05a59f01842c34..d627e66a04a6192e 100644
--- a/tools/include/linux/compiler.h
+++ b/tools/include/linux/compiler.h
@@ -81,6 +81,28 @@
#define __is_constexpr(x) \
(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
+/*
+ * Similar to statically_true() but produces a constant expression
+ *
+ * To be used in conjunction with macros, such as BUILD_BUG_ON_ZERO(),
+ * which require their input to be a constant expression and for which
+ * statically_true() would otherwise fail.
+ *
+ * This is a trade-off: const_true() requires all its operands to be
+ * compile time constants. Else, it would always returns false even on
+ * the most trivial cases like:
+ *
+ * true || non_const_var
+ *
+ * On the opposite, statically_true() is able to fold more complex
+ * tautologies and will return true on expressions such as:
+ *
+ * !(non_const_var * 8 % 4)
+ *
+ * For the general case, statically_true() is better.
+ */
+#define const_true(x) __builtin_choose_expr(__is_constexpr(x), x, false)
+
#ifdef __ANDROID__
/*
* FIXME: Big hammer to get rid of tons of:
--
2.49.0
next prev parent reply other threads:[~2025-05-19 21:42 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-19 21:41 [PATCH FYI 0/7] Updating some kernel headers with " Arnaldo Carvalho de Melo
2025-05-19 21:41 ` [PATCH 1/7] tools include UAPI: Sync linux/vhost.h " Arnaldo Carvalho de Melo
2025-05-20 7:20 ` Stefano Garzarella
2025-05-20 15:57 ` Arnaldo Carvalho de Melo
2025-05-24 10:58 ` Michael S. Tsirkin
2025-05-19 21:41 ` [PATCH 2/7] tools arch x86: Sync the msr-index.h copy " Arnaldo Carvalho de Melo
2025-05-19 21:41 ` [PATCH 3/7] tools headers x86 cpufeatures: Sync with the kernel sources to pick ZEN6 and Indirect Target Selection (ITS) bits Arnaldo Carvalho de Melo
2025-05-19 21:41 ` [PATCH 4/7] tools headers: Sync the linux/unaligned.h copy with the kernel sources Arnaldo Carvalho de Melo
2025-05-19 21:41 ` [PATCH 5/7] tools headers: Synchronize uapi/linux/bits.h " Arnaldo Carvalho de Melo
2025-05-19 21:41 ` Arnaldo Carvalho de Melo [this message]
2025-05-19 21:41 ` [PATCH 7/7] tools headers: Synchronize linux/bits.h " Arnaldo Carvalho de Melo
2025-05-19 23:41 ` [PATCH FYI 0/7] Updating some kernel headers " Namhyung Kim
2025-05-20 0:44 ` Vincent Mailhol
2025-05-20 15:52 ` Arnaldo Carvalho de Melo
2025-05-20 16:02 ` Vincent Mailhol
2025-05-20 19:38 ` Arnaldo Carvalho de Melo
2025-05-20 3:48 ` Yury Norov
2025-05-20 15:56 ` Arnaldo Carvalho de Melo
2025-05-20 16:09 ` Yury Norov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250519214126.1652491-7-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=tglx@linutronix.de \
--cc=williams@redhat.com \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®