#[cfg(target_arch = "aarch64")] pub(crate) mod acle; mod braid; mod combine; #[cfg(target_arch = "x86_64")] mod pclmulqdq;
pubuse combine::crc32_combine;
pubfn crc32(start: u32, buf: &[u8]) -> u32 { /* For lens < 64, crc32_braid method is faster. The CRC32 instruction for
* these short lengths might also prove to be effective */ if buf.len() < 64 { return crc32_braid(start, buf);
}
#[allow(unused)] pubfn crc32_copy(dst: &mut ReadBuf, buf: &[u8]) -> u32 { /* For lens < 64, crc32_braid method is faster. The CRC32 instruction for
* these short lengths might also prove to be effective */ if buf.len() < 64 {
dst.extend(buf); return braid::crc32_braid::<5>(CRC32_INITIAL_VALUE, buf);
}
// when stable, use MaybeUninit::write_slice fn slice_to_uninit(slice: &[u8]) -> &[MaybeUninit<u8>] { // safety: &[T] and &[MaybeUninit<T>] have the same layout unsafe { &*(slice as *const [u8] as *const [MaybeUninit<u8>]) }
}
#[cfg(test)] mod test { use test::braid::crc32_braid;
usesuper::*;
const INPUT: [u8; 1024] = { letmut array = [0; 1024]; letmut i = 0; while i < array.len() {
array[i] = i as u8;
i += 1;
}
array
};
#[test] fn test_crc32_fold() { // input large enough to trigger the SIMD letmut h = crc32fast::Hasher::new_with_initial(CRC32_INITIAL_VALUE);
h.update(&INPUT);
assert_eq!(crc32(CRC32_INITIAL_VALUE, &INPUT), h.finalize());
}
#[test] fn test_crc32_fold_align() { // SIMD algorithm is sensitive to alignment; for i in0..16 { for start in [CRC32_INITIAL_VALUE, 42] { letmut h = crc32fast::Hasher::new_with_initial(start);
h.update(&INPUT[i..]);
assert_eq!(
crc32(start, &INPUT[i..]),
h.finalize(), "offset = {i}, start = {start}"
);
}
}
}
#[test] fn test_crc32_fold_copy() { // input large enough to trigger the SIMD letmut h = crc32fast::Hasher::new_with_initial(CRC32_INITIAL_VALUE);
h.update(&INPUT); letmut dst = [0; INPUT.len()]; letmut dst = ReadBuf::new(&mut dst);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.