From: Usama Arif <usama.arif@linux.dev>
To: dsterba@suse.com, linux-kernel@vger.kernel.org, terrelln@fb.com,
linux-crypto@vger.kernel.org, yosry@kernel.org
Cc: hannes@cmpxchg.org, nphamcs@gmail.com, chengming.zhou@linux.dev,
shakeel.butt@linux.dev, kernel-team@meta.com,
Usama Arif <usama.arif@linux.dev>
Subject: [PATCH 2/3] zstd: skip the BMI2 probe when dynamic BMI2 dispatch is disabled
Date: Wed, 26 Aug 2026 05:25:37 -0700 [thread overview]
Message-ID: <20260826122558.2662013-3-usama.arif@linux.dev> (raw)
In-Reply-To: <20260826122558.2662013-1-usama.arif@linux.dev>
When DYNAMIC_BMI2 is 0 - GCC older than 11, a non-x86 target, or a build
that already has BMI2 on globally - nothing reads the flag.
HUF_compress1X_usingCTable_internal(), FSE_decompress_wksp_bmi2(),
HUF_readStats_body() and the rest all resolve to the default body
without consulting it. ZSTD_cpuSupportsBmi2() nevertheless issues
CPUID, which on x86 is two serializing instructions, and throws the
answer away.
ZSTD_initDCtx_internal() already wraps its assignment in
#if DYNAMIC_BMI2 - it has to, because the dctx->bmi2 field is itself
declared under that #if. The two compress-side callers have no such
guard, and ZSTD_CCtx_s::bmi2 is unconditional, so they probe
unconditionally.
Put the test inside ZSTD_cpuSupportsBmi2() so every caller gets it
without having to remember.
Signed-off-by: Usama Arif <usama.arif@linux.dev>
---
lib/zstd/common/zstd_internal.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lib/zstd/common/zstd_internal.h b/lib/zstd/common/zstd_internal.h
index 52a79435caf66..41f190b533209 100644
--- a/lib/zstd/common/zstd_internal.h
+++ b/lib/zstd/common/zstd_internal.h
@@ -311,8 +311,13 @@ size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
*/
MEM_STATIC int ZSTD_cpuSupportsBmi2(void)
{
+#if DYNAMIC_BMI2
ZSTD_cpuid_t cpuid = ZSTD_cpuid();
return ZSTD_cpuid_bmi1(cpuid) && ZSTD_cpuid_bmi2(cpuid);
+#else
+ /* Nothing looks at the flag in this configuration. */
+ return 0;
+#endif
}
#endif /* ZSTD_CCOMMON_H_MODULE */
--
2.53.0-Meta
next prev parent reply other threads:[~2026-08-26 12:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 12:25 [PATCH 0/3] zstd: probe the CPU for BMI2 support once, not per context Usama Arif
2026-08-26 12:25 ` [PATCH 1/3] zstd: use ZSTD_cpuSupportsBmi2() in ZSTD_initStaticCCtx() Usama Arif
2026-08-26 12:25 ` Usama Arif [this message]
2026-08-26 12:25 ` [PATCH 3/3] zstd: probe the CPU for BMI2 support only once Usama Arif
2026-08-26 17:10 ` [PATCH 0/3] zstd: probe the CPU for BMI2 support once, not per context Nhat Pham
2026-08-27 2:39 ` Eric Biggers
2026-08-27 14:21 ` Usama Arif
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=20260826122558.2662013-3-usama.arif@linux.dev \
--to=usama.arif@linux.dev \
--cc=chengming.zhou@linux.dev \
--cc=dsterba@suse.com \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@meta.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nphamcs@gmail.com \
--cc=shakeel.butt@linux.dev \
--cc=terrelln@fb.com \
--cc=yosry@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.