Linux cryptographic layer development
 help / color / mirror / Atom feed
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>,
	Martin Willi <martin@strongswan.org>,
	Antonio Quartulli <antonio@mandelbit.com>
Subject: Re: [PATCH] lib/crypto: x86/chacha: Eliminate more never-taken branches
Date: Sat, 7 Nov 2026 13:52:09 -0800	[thread overview]
Message-ID: <20261107215209.GI137269@quark> (raw)
In-Reply-To: <20261104225526.68557-1-ebiggers@kernel.org>

On Wed, Nov 04, 2026 at 02:55:26PM -0800, Eric Biggers wrote:
> The x86_64 optimized ChaCha code has assembly functions that generate 1,
> 2, 4, 8, or 16 keystream blocks and XOR them with up to that number of
> data blocks.
> 
> However, to avoid unnecessary overhead, the 4, 8, and 16-block
> functions, and the AVX2 2-block function, are never called with a length
> that is supported by the next-smaller function (that is, <= N/2 blocks,
> or <= 1 block for the SSSE3 4-block function), since a smaller function
> is called to handle such cases instead.
> 
> As a result, all the branches in those assembly functions that handle
> XOR'ing fewer than that minimum number of data blocks are dead code.
> 
> Remove these branches to eliminate dead code and overhead.  Also rename
> the assembly functions to make it clear which cases they handle.
> 
> Some register moves in chacha_1to4blocks_ssse3() are also eliminated, as
> they were needed only because of the support for less than 1 block.
> 
> Note: many of the functions could use exclusive rather than inclusive
> lower bounds.  Inclusive is used for simplicity.
> 
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> ---
>  lib/crypto/x86/chacha-avx2-x86_64.S   | 73 +++++++--------------
>  lib/crypto/x86/chacha-avx512-x86_64.S | 94 +++++++++------------------
>  lib/crypto/x86/chacha-ssse3-x86_64.S  | 51 ++++++---------
>  lib/crypto/x86/chacha.h               | 72 +++++++++++++-------
>  4 files changed, 119 insertions(+), 171 deletions(-)

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next

- Eric

      parent reply	other threads:[~2026-11-07 21:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 22:55 [PATCH] lib/crypto: x86/chacha: Eliminate more never-taken branches Eric Biggers
2026-11-05 15:31 ` Antonio Quartulli
2026-11-05 19:08   ` Eric Biggers
2026-11-05 20:06     ` Antonio Quartulli
2026-11-07 21:52 ` 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=20261107215209.GI137269@quark \
    --to=ebiggers@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=antonio@mandelbit.com \
    --cc=ardb@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=martin@strongswan.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