Skip to content

Commit

Permalink
Also enable sse2
Browse files Browse the repository at this point in the history
  • Loading branch information
ogxd committed Jan 6, 2024
1 parent 138db01 commit 14b2caa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ fn main() {
&& cfg!(target_arch = "x86_64")
&& cfg!(target_feature = "avx2")
&& cfg!(target_feature = "vaes") {
println!("cargo:rustc-cfg=hybrid");
//println!("cargo:rustc-cfg=hybrid");
}
}
6 changes: 3 additions & 3 deletions src/gxhash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ pub(crate) unsafe fn gxhash(input: &[u8], seed: State) -> State {
#[inline(always)]
pub(crate) unsafe fn compress_all(input: &[u8]) -> State {

if !check_support() {
panic!("No supported");
}
// if !check_support() {
// panic!("Not supported");
// }

let len = input.len();
let mut ptr = input.as_ptr() as *const State;
Expand Down
55 changes: 36 additions & 19 deletions src/gxhash/platform/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,26 @@ pub unsafe fn check_support() -> bool {
std::arch::is_x86_feature_detected!("aes") && std::arch::is_x86_feature_detected!("sse2")
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn create_empty() -> State {
_mm_setzero_si128()
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn create_seed(seed: i64) -> State {
_mm_set1_epi64x(seed)
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn load_unaligned(p: *const State) -> State {
_mm_loadu_si128(p)
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn get_partial_safe(data: *const State, len: usize) -> State {
// Temporary buffer filled with zeros
let mut buffer = [0i8; VECTOR_SIZE];
Expand All @@ -38,7 +42,8 @@ pub unsafe fn get_partial_safe(data: *const State, len: usize) -> State {
_mm_add_epi8(partial_vector, _mm_set1_epi8(len as i8))
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn get_partial_unsafe(data: *const State, len: usize) -> State {
let indices = _mm_set_epi8(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
let mask = _mm_cmpgt_epi8(_mm_set1_epi8(len as i8), indices);
Expand All @@ -58,14 +63,15 @@ pub unsafe fn aes_encrypt_last(data: State, keys: State) -> State {
_mm_aesenclast_si128(data, keys)
}

#[inline(always)]
#[allow(dead_code)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn ld(array: *const u32) -> State {
_mm_loadu_si128(array as *const State)
}

#[cfg(not(hybrid))]
#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn compress_8(mut ptr: *const State, end_address: usize, hash_vector: State, len: usize) -> State {

// Disambiguation vectors
Expand Down Expand Up @@ -106,7 +112,8 @@ pub unsafe fn compress_8(mut ptr: *const State, end_address: usize, hash_vector:
}

#[cfg(hybrid)]
#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
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),+) => {
Expand Down Expand Up @@ -144,53 +151,63 @@ pub unsafe fn compress_8(ptr: *const State, end_address: usize, hash_vector: Sta
aes_encrypt(lane1, lane2)
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn load_u8(x: u8) -> State {
_mm_set1_epi8(x as i8)
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn load_u16(x: u16) -> State {
_mm_set1_epi16(x as i16)
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn load_u32(x: u32) -> State {
_mm_set1_epi32(x as i32)
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn load_u64(x: u64) -> State {
_mm_set1_epi64x(x as i64)
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn load_u128(x: u128) -> State {
let ptr = &x as *const u128 as *const State;
_mm_loadu_si128(ptr)
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn load_i8(x: i8) -> State {
_mm_set1_epi8(x)
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn load_i16(x: i16) -> State {
_mm_set1_epi16(x)
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn load_i32(x: i32) -> State {
_mm_set1_epi32(x)
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn load_i64(x: i64) -> State {
_mm_set1_epi64x(x)
}

#[inline(always)]
#[inline]
#[target_feature(enable = "sse2")]
pub unsafe fn load_i128(x: i128) -> State {
let ptr = &x as *const i128 as *const State;
_mm_loadu_si128(ptr)
Expand Down

0 comments on commit 14b2caa

Please sign in to comment.