Skip to content

Commit

Permalink
test: try to improve throughput
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Dec 29, 2024
1 parent dc9f444 commit d837288
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions fuel-vm/src/interpreter/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,17 +1040,37 @@ fn slice_eq(a: &[u8], b: &[u8]) -> bool {
return false;
}

let chunks = a.chunks_exact(16);
let remainder = chunks.remainder();
for (chunk_a, chunk_b) in chunks.zip(b.chunks_exact(16)) {
let simd_a = u8x16::from_slice(chunk_a);
let simd_b = u8x16::from_slice(chunk_b);
if simd_a != simd_b {
return false;
}
// because we're using simd, we can parallelize by a factor of 4
let mut res_a = false;
let mut res_b = false;
let mut res_c = false;
let mut res_d = false;

let chunks_a = a.chunks_exact(16);
let chunks_b = b.chunks_exact(16);
let remainder_a = chunks_a.remainder();
let remainder_b = chunks_b.remainder();

for i in (0..chunks_a.len()).step_by(4) {
let simd_a = u8x16::from_slice(&a[i..i + 16]);
let simd_b = u8x16::from_slice(&b[i..i + 16]);
res_a |= simd_a != simd_b;

let simd_a = u8x16::from_slice(&a[i + 16..i + 32]);
let simd_b = u8x16::from_slice(&b[i + 16..i + 32]);
res_b |= simd_a != simd_b;

let simd_a = u8x16::from_slice(&a[i + 32..i + 48]);
let simd_b = u8x16::from_slice(&b[i + 32..i + 48]);
res_c |= simd_a != simd_b;

let simd_a = u8x16::from_slice(&a[i + 48..i + 64]);
let simd_b = u8x16::from_slice(&b[i + 48..i + 64]);
res_d |= simd_a != simd_b;
}

remainder == &b[a.len() - remainder.len()..]
// check the remainder
remainder_a == remainder_b && res_a && res_b && res_c && res_d
}
#[cfg(not(feature = "experimental"))]
{
Expand Down

0 comments on commit d837288

Please sign in to comment.