[PATCH] cipher: prefer 128-bit blocksize in inline block helpers
Jussi Kivilinna <[email protected]> Thu, 23 Jul 2026 14:30:48 +0300
| Newsgroups | gmane.comp.encryption.gpg.libgcrypt.devel |
|---|---|
| Message-ID | <[email protected]> |
* cipher/cipher-internal.h (_gcry_blocksize_shift, cipher_block_add) (cipher_block_cpy, cipher_block_xor, cipher_block_xor_2dst) (cipher_block_xor_n_copy_2, cipher_block_bswap): Mark 8-byte blocksize branch with UNLIKELY. -- Inline block helpers branch on blocksize 8 versus 16. 128-bit ciphers dominate, so mark 8-byte branch unlikely and let compiler lay out 16-byte path as fall-through. Signed-off-by: Jussi Kivilinna <[email protected]> --- cipher/cipher-internal.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cipher/cipher-internal.h b/cipher/cipher-internal.h index 7a10de6e..8e6cbffc 100644 --- a/cipher/cipher-internal.h +++ b/cipher/cipher-internal.h @@ -804,7 +804,7 @@ static inline unsigned int _gcry_blocksize_shift(gcry_cipher_hd_t c) { /* Only blocksizes 8 and 16 are used. Return value in such way * that compiler can optimize calling functions based on this. */ - return c->spec->blocksize == 8 ? 3 : 4; + return UNLIKELY(c->spec->blocksize == 8) ? 3 : 4; } @@ -839,7 +839,7 @@ cipher_block_add(void *_dstsrc, unsigned int add, size_t blocksize) byte *dstsrc = _dstsrc; u64 s[2]; - if (blocksize == 8) + if (UNLIKELY(blocksize == 8)) { buf_put_be64(dstsrc + 0, buf_get_be64(dstsrc + 0) + add); } @@ -863,7 +863,7 @@ cipher_block_cpy(void *_dst, const void *_src, size_t blocksize) const byte *src = _src; u64 s[2]; - if (blocksize == 8) + if (UNLIKELY(blocksize == 8)) { buf_put_he64(dst + 0, buf_get_he64(src + 0)); } @@ -888,7 +888,7 @@ cipher_block_xor(void *_dst, const void *_src1, const void *_src2, u64 s1[2]; u64 s2[2]; - if (blocksize == 8) + if (UNLIKELY(blocksize == 8)) { buf_put_he64(dst + 0, buf_get_he64(src1 + 0) ^ buf_get_he64(src2 + 0)); } @@ -924,7 +924,7 @@ cipher_block_xor_2dst(void *_dst1, void *_dst2, const void *_src, u64 d2[2]; u64 s[2]; - if (blocksize == 8) + if (UNLIKELY(blocksize == 8)) { d2[0] = buf_get_he64(dst2 + 0) ^ buf_get_he64(src + 0); buf_put_he64(dst2 + 0, d2[0]); @@ -961,7 +961,7 @@ cipher_block_xor_n_copy_2(void *_dst_xor, const void *_src_xor, u64 sx[2]; u64 sdc[2]; - if (blocksize == 8) + if (UNLIKELY(blocksize == 8)) { sc[0] = buf_get_he64(src_cpy + 0); buf_put_he64(dst_xor + 0, @@ -995,7 +995,7 @@ cipher_block_bswap (void *_dst_bswap, const void *_src_bswap, const byte *src_bswap = _src_bswap; u64 t[2]; - if (blocksize == 8) + if (UNLIKELY(blocksize == 8)) { buf_put_le64(dst_bswap, buf_get_be64(src_bswap)); } -- 2.53.0