Skip to content

Commit

Permalink
Bench urbd asm
Browse files Browse the repository at this point in the history
  • Loading branch information
ogxd committed Nov 9, 2024
1 parent 9ac65ce commit 27eeaae
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/gxhash/platform/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ pub unsafe fn get_partial_safe(data: *const State, len: usize) -> State {
#[inline(always)]
pub unsafe fn get_partial_unsafe_no_ub(data: *const State, len: usize) -> State {
// Using inline assembly to load out-of-bounds
// use std::arch::asm;
// 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);
// let mut result: State;
// asm!("movdqu [{}], {}", in(reg) data, out(xmm_reg) result, options(pure, nomem, nostack));
// let partial_vector = _mm_and_si128(result, mask);
// _mm_add_epi8(partial_vector, _mm_set1_epi8(len as i8))
use std::arch::asm;
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);
let mut result: State;
asm!("movdqu [{}], {}", in(reg) data, out(xmm_reg) result, options(pure, nomem, nostack));
let partial_vector = _mm_and_si128(result, mask);
_mm_add_epi8(partial_vector, _mm_set1_epi8(len as i8))

// Using std::simd
use std::simd::*;
use std::mem::transmute;
let slice = std::slice::from_raw_parts(data as *const i8, len);
let data: Simd<i8, 16> = Simd::<i8, 16>::load_or_default(&slice);
let vector: State = transmute(data);
return vector;
// use std::simd::*;
// use std::mem::transmute;
// let slice = std::slice::from_raw_parts(data as *const i8, len);
// let data: Simd<i8, 16> = Simd::<i8, 16>::load_or_default(&slice);
// let vector: State = transmute(data);
// return vector;
}

#[inline(always)]
Expand Down

0 comments on commit 27eeaae

Please sign in to comment.