Skip to content

Commit

Permalink
fix alignment issue
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Feb 16, 2024
1 parent 98994f3 commit 6adb8a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions zlib-rs/src/crc32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,23 @@ mod test {
assert_eq!(crc32(&INPUT, CRC32_INITIAL_VALUE), h.finalize());
}

#[test]
fn test_crc32_fold_align() {
// SIMD algorithm is sensitive to alignment;
for i in 0..16 {
let mut h = crc32fast::Hasher::new_with_initial(CRC32_INITIAL_VALUE);
h.update(&INPUT[i..]);
assert_eq!(crc32(&INPUT[i..], CRC32_INITIAL_VALUE), h.finalize());
}
}

#[test]
fn test_crc32_fold_copy() {
// input large enought to trigger the SIMD
let mut h = crc32fast::Hasher::new_with_initial(CRC32_INITIAL_VALUE);
h.update(&INPUT);
let mut dst = [0; INPUT.len()];

assert_eq!(crc32_copy(&mut dst, &INPUT), h.finalize());

assert_eq!(INPUT, dst);
Expand Down
2 changes: 1 addition & 1 deletion zlib-rs/src/crc32/pclmulqdq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl Accumulator {
init_crc: &mut u32,
) -> usize {
let mut it = src.chunks_exact(16);
let mut input: [_; 4] = std::array::from_fn(|_| unsafe {
let mut input: [_; N] = std::array::from_fn(|_| unsafe {
_mm_load_si128(it.next().unwrap().as_ptr() as *const __m128i)
});

Expand Down

0 comments on commit 6adb8a4

Please sign in to comment.