From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
"Jason A . Donenfeld" <Jason@zx2c4.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
x86@kernel.org
Subject: Re: [PATCH v2] lib/crypto: x86/sm3: De-bloat sm3-avx-asm_64.S
Date: Tue, 24 Nov 2026 15:31:59 -0800 [thread overview]
Message-ID: <20261124233159.GE2001@quark> (raw)
In-Reply-To: <20261124083736.247567-1-ebiggers@kernel.org>
On Tue, Nov 24, 2026 at 12:37:36AM -0800, Eric Biggers wrote:
> sm3_transform_avx() previously unrolled all 64 rounds, resulting in 9567
> bytes of .text and making it currently the second largest object file in
> lib/crypto/x86/. Additionally, all 64 round constants were inlined as
> immediates, despite the fact that all round 0-15 constants are rotations
> of one value, and all round 16-63 constants are rotations of one value.
>
> Therefore:
>
> - Roll up rounds 16-63 into 4 iterations, each doing 12 rounds.
>
> 12 is chosen because it's the least common multiple of the 4-round
> rotation period of the scalar state registers and the 6-round
> alternation period of the two XW stack slots.
>
> - Generate the round constant for each of rounds 1-15 and 17-63 by
> just rotating the previous round constant.
>
> This requires one extra GPR (KREG) for the round constant, which also
> serves to terminate the rounds 16-63 loop when it reaches the "round 64"
> value. Free up %rdx for KREG by replacing RNBLKS with an end-of-data
> pointer stored on the stack, terminating the block loop when RDATA
> reaches it.
>
> The .text of sm3-avx-asm_64.o shrinks from 9567 bytes to 4257 bytes, a
> 56% reduction. Performance is unchanged to within 0.2% on AMD Ryzen 9
> 9950X (Zen 5), measured using the benchmark in sm3_kunit.
>
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> ---
>
> v2: Avoided spilling RDATA and RNBLKS to the stack by using different
> methods to terminate the loops.
>
> lib/crypto/x86/sm3-avx-asm_64.S | 236 +++++++++-----------------------
> 1 file changed, 68 insertions(+), 168 deletions(-)
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next
- Eric
prev parent reply other threads:[~2026-11-24 23:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 8:37 [PATCH v2] lib/crypto: x86/sm3: De-bloat sm3-avx-asm_64.S Eric Biggers
2026-11-24 10:58 ` Ard Biesheuvel
2026-11-24 23:31 ` Eric Biggers [this message]
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=20261124233159.GE2001@quark \
--to=ebiggers@kernel.org \
--cc=Jason@zx2c4.com \
--cc=ardb@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=x86@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