From 1fffefbe582f348864161b2b96b117ef62ce7b8d Mon Sep 17 00:00:00 2001 From: Olivier Giniaux Date: Sun, 17 Nov 2024 11:19:20 +0100 Subject: [PATCH] Inline 8x16 compression --- src/gxhash/mod.rs | 13 +++++++------ src/gxhash/platform/arm.rs | 2 +- src/gxhash/platform/x86.rs | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/gxhash/mod.rs b/src/gxhash/mod.rs index 3ef2604..984633e 100644 --- a/src/gxhash/mod.rs +++ b/src/gxhash/mod.rs @@ -65,11 +65,6 @@ macro_rules! load_unaligned { pub(crate) use load_unaligned; -#[cfg(target_arch = "arm")] -use core::arch::arm::*; -#[cfg(target_arch = "aarch64")] -use core::arch::aarch64::*; - #[inline(always)] pub(crate) unsafe fn gxhash(input: &[u8], seed: State) -> State { return finalize(gxhash_no_finish(input, seed)); @@ -94,7 +89,13 @@ pub(crate) unsafe fn gxhash_no_finish(input: &[u8], seed: State) -> State { if len < 16 { break 'p1; } else if len < 128 { - // Possibly we can have something here + // Turbo mode, but is it worth the extra code size? + // It's not even great quality-wise, and v0 mix v1 may be a source of DOS collision attack + // if len >= 32 { + // load_unaligned!(ptr, v0, v1); + // state = aes_encrypt(state, aes_encrypt(v0, v1)); + // whole_vector_count -= 2; + // } break 'p2; } diff --git a/src/gxhash/platform/arm.rs b/src/gxhash/platform/arm.rs index 1621983..309c800 100644 --- a/src/gxhash/platform/arm.rs +++ b/src/gxhash/platform/arm.rs @@ -77,7 +77,7 @@ pub unsafe fn ld(array: *const u32) -> State { vreinterpretq_s8_u32(vld1q_u32(array)) } -#[inline(never)] +#[inline(always)] pub unsafe fn compress_8(mut ptr: *const State, whole_vector_count: usize, hash_vector: State, len: usize) -> (State, *const State, usize) { let end_address = ptr.add((whole_vector_count / 8) * 8) as usize; diff --git a/src/gxhash/platform/x86.rs b/src/gxhash/platform/x86.rs index a4023bf..8c63e24 100644 --- a/src/gxhash/platform/x86.rs +++ b/src/gxhash/platform/x86.rs @@ -69,7 +69,7 @@ pub unsafe fn ld(array: *const u32) -> State { } #[cfg(not(feature = "hybrid"))] -#[inline(never)] +#[inline(always)] pub unsafe fn compress_8(mut ptr: *const State, whole_vector_count: usize, hash_vector: State, len: usize) -> State { let end_address = ptr.add((whole_vector_count / 8) * 8) as usize; @@ -113,7 +113,7 @@ pub unsafe fn compress_8(mut ptr: *const State, whole_vector_count: usize, hash_ } #[cfg(feature = "hybrid")] -#[inline(never)] +#[inline(always)] pub unsafe fn compress_8(ptr: *const State, end_address: usize, hash_vector: State, len: usize) -> State { macro_rules! load_unaligned_x2 { ($ptr:ident, $($var:ident),+) => {