From: Dhruva G <goledhruva@gmail.com>
To: Usama Arif <usama.arif@linux.dev>,
dsterba@suse.com, linux-kernel@vger.kernel.org, terrelln@fb.com,
terrelln@meta.com, linux-crypto@vger.kernel.org,
yosry@kernel.org, ebiggers@kernel.org,
torvalds@linux-foundation.org
Cc: hannes@cmpxchg.org, nphamcs@gmail.com, chengming.zhou@linux.dev,
shakeel.butt@linux.dev, kernel-team@meta.com
Subject: Re: [PATCH v3 1/2] lib/zstd: add fallback aliases for disabled BMI2 variants
Date: Thu, 3 Sep 2026 18:05:17 +0530 [thread overview]
Message-ID: <fc9c4270-6ebf-4e6f-b0ff-5126f95ea006@gmail.com> (raw)
In-Reply-To: <20260901110850.1805747-2-usama.arif@linux.dev>
On 01-09-2026 16:37, Usama Arif wrote:
> When dynamic BMI2 dispatch is disabled, the BMI2-specific functions are
> not compiled and each selector is conditionally compiled to avoid naming
> them.
>
> The selector-level preprocessor guards will be replaced with a predicate
> that becomes constant false when dynamic BMI2 dispatch is disabled.
> Although the compiler eliminates an `if (0)` branch, it must still parse
> and resolve the BMI2 function referenced by it.
>
> Add aliases from the unavailable BMI2 function names to their default
> implementations. These aliases make the names valid without emitting
> BMI2-specific code. The selectors remain unchanged in this patch, so the
> aliases are not used yet and there is no code-generation change.
>
> Signed-off-by: Usama Arif <usama.arif@linux.dev>
> ---
Reviewed-by: Dhruva Gole <goledhruva@gmail.com>
> lib/zstd/common/entropy_common.c | 4 ++++
> lib/zstd/common/fse_decompress.c | 2 ++
> lib/zstd/compress/zstd_compress_sequences.c | 4 ++++
> lib/zstd/decompress/huf_decompress.c | 4 ++++
> lib/zstd/decompress/zstd_decompress_block.c | 12 ++++++++++++
> 5 files changed, 26 insertions(+)
>
> diff --git a/lib/zstd/common/entropy_common.c b/lib/zstd/common/entropy_common.c
> index 6cdd82233fb59..15a7c14ae8040 100644
> --- a/lib/zstd/common/entropy_common.c
> +++ b/lib/zstd/common/entropy_common.c
> @@ -202,6 +202,8 @@ BMI2_TARGET_ATTRIBUTE static size_t FSE_readNCount_body_bmi2(
> {
> return FSE_readNCount_body(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
> }
> +#else
> +#define FSE_readNCount_body_bmi2 FSE_readNCount_body_default
> #endif
>
> size_t FSE_readNCount_bmi2(
> @@ -323,6 +325,8 @@ static BMI2_TARGET_ATTRIBUTE size_t HUF_readStats_body_bmi2(BYTE* huffWeight, si
> {
> return HUF_readStats_body(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize, 1);
> }
> +#else
> +#define HUF_readStats_body_bmi2 HUF_readStats_body_default
> #endif
>
> size_t HUF_readStats_wksp(BYTE* huffWeight, size_t hwSize, U32* rankStats,
> diff --git a/lib/zstd/common/fse_decompress.c b/lib/zstd/common/fse_decompress.c
> index 15081d8dc607c..8d9c43b928833 100644
> --- a/lib/zstd/common/fse_decompress.c
> +++ b/lib/zstd/common/fse_decompress.c
> @@ -300,6 +300,8 @@ BMI2_TARGET_ATTRIBUTE static size_t FSE_decompress_wksp_body_bmi2(void* dst, siz
> {
> return FSE_decompress_wksp_body(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize, 1);
> }
> +#else
> +#define FSE_decompress_wksp_body_bmi2 FSE_decompress_wksp_body_default
> #endif
>
> size_t FSE_decompress_wksp_bmi2(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize, int bmi2)
> diff --git a/lib/zstd/compress/zstd_compress_sequences.c b/lib/zstd/compress/zstd_compress_sequences.c
> index 256980c9d85ad..64abcdf2c5714 100644
> --- a/lib/zstd/compress/zstd_compress_sequences.c
> +++ b/lib/zstd/compress/zstd_compress_sequences.c
> @@ -415,6 +415,10 @@ ZSTD_encodeSequences_bmi2(
> sequences, nbSeq, longOffsets);
> }
>
> +#else
> +
> +#define ZSTD_encodeSequences_bmi2 ZSTD_encodeSequences_default
> +
> #endif
>
> size_t ZSTD_encodeSequences(
> diff --git a/lib/zstd/decompress/huf_decompress.c b/lib/zstd/decompress/huf_decompress.c
> index ac8b87f48f847..5663ae524cd83 100644
> --- a/lib/zstd/decompress/huf_decompress.c
> +++ b/lib/zstd/decompress/huf_decompress.c
> @@ -700,6 +700,8 @@ size_t HUF_decompress4X1_usingDTable_internal_bmi2(void* dst, size_t dstSize, vo
> size_t cSrcSize, HUF_DTable const* DTable) {
> return HUF_decompress4X1_usingDTable_internal_body(dst, dstSize, cSrc, cSrcSize, DTable);
> }
> +#else
> +#define HUF_decompress4X1_usingDTable_internal_bmi2 HUF_decompress4X1_usingDTable_internal_default
> #endif
>
> static
> @@ -1503,6 +1505,8 @@ size_t HUF_decompress4X2_usingDTable_internal_bmi2(void* dst, size_t dstSize, vo
> size_t cSrcSize, HUF_DTable const* DTable) {
> return HUF_decompress4X2_usingDTable_internal_body(dst, dstSize, cSrc, cSrcSize, DTable);
> }
> +#else
> +#define HUF_decompress4X2_usingDTable_internal_bmi2 HUF_decompress4X2_usingDTable_internal_default
> #endif
>
> static
> diff --git a/lib/zstd/decompress/zstd_decompress_block.c b/lib/zstd/decompress/zstd_decompress_block.c
> index 710eb0ffd5a37..9c4215e435014 100644
> --- a/lib/zstd/decompress/zstd_decompress_block.c
> +++ b/lib/zstd/decompress/zstd_decompress_block.c
> @@ -622,6 +622,8 @@ BMI2_TARGET_ATTRIBUTE static void ZSTD_buildFSETable_body_bmi2(ZSTD_seqSymbol* d
> ZSTD_buildFSETable_body(dt, normalizedCounter, maxSymbolValue,
> baseValue, nbAdditionalBits, tableLog, wksp, wkspSize);
> }
> +#else
> +#define ZSTD_buildFSETable_body_bmi2 ZSTD_buildFSETable_body_default
> #endif
>
> void ZSTD_buildFSETable(ZSTD_seqSymbol* dt,
> @@ -1934,6 +1936,16 @@ ZSTD_decompressSequencesLong_bmi2(ZSTD_DCtx* dctx,
> }
> #endif /* ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT */
>
> +#else
> +
> +#ifndef ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG
> +#define ZSTD_decompressSequences_bmi2 ZSTD_decompressSequences_default
> +#define ZSTD_decompressSequencesSplitLitBuffer_bmi2 ZSTD_decompressSequencesSplitLitBuffer_default
> +#endif
> +#ifndef ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT
> +#define ZSTD_decompressSequencesLong_bmi2 ZSTD_decompressSequencesLong_default
> +#endif
> +
> #endif /* DYNAMIC_BMI2 */
>
> #ifndef ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG
next prev parent reply other threads:[~2026-09-03 12:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 11:07 [PATCH v3 0/2] zstd: use x86 feature infrastructure for BMI2 dispatch Usama Arif
2026-09-01 11:07 ` [PATCH v3 1/2] lib/zstd: add fallback aliases for disabled BMI2 variants Usama Arif
2026-09-03 12:35 ` Dhruva G [this message]
2026-09-01 11:07 ` [PATCH v3 2/2] zstd: use cpu_feature_enabled() for in-kernel BMI2 dispatch Usama Arif
2026-09-02 17:40 ` Dhruva G
2026-09-03 10:53 ` 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=fc9c4270-6ebf-4e6f-b0ff-5126f95ea006@gmail.com \
--to=goledhruva@gmail.com \
--cc=chengming.zhou@linux.dev \
--cc=dsterba@suse.com \
--cc=ebiggers@kernel.org \
--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=terrelln@meta.com \
--cc=torvalds@linux-foundation.org \
--cc=usama.arif@linux.dev \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox