1use crate::cpu::CPU_SIMD_64_SIZE;
22
23#[inline]
24pub fn copy_simd_slice<'a, const LANE_SIZE: usize>(src: &[u8], mut dst: &'a mut [u8]) -> &'a mut [u8] {
25 let (prefix, middle, postfix) = src.as_simd::<LANE_SIZE>();
26 let prefix_len = prefix.len();
27 let postfix_len = postfix.len();
28
29 dst[..prefix_len].copy_from_slice(prefix);
30 dst = &mut dst[prefix_len..];
31
32 for chunk in middle.into_iter() {
33 chunk.copy_to_slice(&mut dst[..LANE_SIZE]);
34 dst = &mut dst[LANE_SIZE..];
35 }
36
37 dst[..postfix_len].copy_from_slice(postfix);
38 dst
39}
40
41#[inline]
42pub fn copy_from_slice<'a>(src: &[u8], dst: &'a mut [u8]) -> &'a mut [u8] {
43 debug_assert!(src.len() <= dst.len(), "Destination memory slice is smaller than source! This is a bug near the call site of copy_from_slice!");
44 copy_simd_slice::<CPU_SIMD_64_SIZE>(
45 src,
46 dst,
47 )
48}
49
50#[macro_export]
51macro_rules! rumtk_mem_quick_array_init {
52 ( $typ:ty, $size:expr ) => {{
53 const DATA_SLICE_LEN: usize = $size * size_of::<$typ>();
54 let arr: [$typ; $size] = unsafe { mem::transmute([0u8; DATA_SLICE_LEN]) };
55 arr
56 }};
57 ( $typ:ty, $size:expr, $default:expr ) => {{
58 let arr: [$typ; $size] = [const {$default}; $size];
59 arr
60 }};
61}