From 838e0e34f69205c6414106455dc0dafe2abbacdf Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 23 Jun 2024 13:46:36 -0700 Subject: [PATCH] aes_gcm: Prefer integrated implementations, avoid inlining fallbacks. The `#[inline(always)]` on `open_strided` was just a mistake. But, even correcting that, the compiler won't structure `open()` and `seal()` in the expected way. With these changes, the integrated implementations will get inlined (as far as possible) and the compiler will be biased towards assuming they will be used. --- src/aead/aes_gcm.rs | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/aead/aes_gcm.rs b/src/aead/aes_gcm.rs index ca44ac3403..8472c93c37 100644 --- a/src/aead/aes_gcm.rs +++ b/src/aead/aes_gcm.rs @@ -218,6 +218,26 @@ pub(super) fn seal( } } +#[cfg_attr( + any( + all( + any(target_arch = "aarch64", target_arch = "arm"), + target_feature = "neon" + ), + all( + any(target_arch = "x86", target_arch = "x86_64"), + target_feature = "sse" + ) + ), + inline(never) +)] +#[cfg_attr( + any( + all(target_arch = "aarch64", target_feature = "neon"), + all(target_arch = "x86_64", target_feature = "sse") + ), + cold +)] fn seal_strided( Combo { aes_key, gcm_key }: &Combo, aad: Aad<&[u8]>, @@ -392,7 +412,26 @@ pub(super) fn open( } } -#[inline(always)] +#[cfg_attr( + any( + all( + any(target_arch = "aarch64", target_arch = "arm"), + target_feature = "neon" + ), + all( + any(target_arch = "x86", target_arch = "x86_64"), + target_feature = "sse" + ) + ), + inline(never) +)] +#[cfg_attr( + any( + all(target_arch = "aarch64", target_feature = "neon"), + all(target_arch = "x86_64", target_feature = "sse") + ), + cold +)] fn open_strided( Combo { aes_key, gcm_key }: &Combo, aad: Aad<&[u8]>,