// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
#![allow(unsafe_code)]
usecrate::image::ImageDataType;
pubconst CACHE_LINE_BYTE_SIZE: usize = 64;
pubconstfn num_per_cache_line<T>() -> usize { // Post-mono check that T is smaller than a cache line and has size a power of 2. // This prevents some of the silliest mistakes. const {
assert!(std::mem::size_of::<T>() <= CACHE_LINE_BYTE_SIZE);
assert!(std::mem::size_of::<T>().is_power_of_two());
}
CACHE_LINE_BYTE_SIZE / std::mem::size_of::<T>()
}
pubfn round_up_size_to_cache_line<T>(size: usize) -> usize { let n = const { num_per_cache_line::<T>() };
size.div_ceil(n) * n
}
#[inline(always)] pubfn slice_from_cachelines<T: ImageDataType>(slice: &[CacheLine]) -> &[T] { const { assert!(64usize.is_multiple_of(std::mem::align_of::<T>())) }; const { assert!(CACHE_LINE_BYTE_SIZE.is_multiple_of(std::mem::size_of::<T>())) }; const { assert!(CACHE_LINE_BYTE_SIZE == 64) }; // SAFETY: CacheLine is 64 bytes with no padding, with higher alignment requirements than T. // T is guaranteed to be a bag-of-bits type by the safety requirements of ImageDataType. // The other safety requirements follow from the data pointer and length being obtained from a // slice. unsafe {
std::slice::from_raw_parts(
slice.as_ptr().cast::<T>(),
slice.len() * (CACHE_LINE_BYTE_SIZE / std::mem::size_of::<T>()),
)
}
}
#[inline(always)] pubfn slice_from_cachelines_mut<T: ImageDataType>(slice: &mut [CacheLine]) -> &mut [T] { const { assert!(64usize.is_multiple_of(std::mem::align_of::<T>())) }; const { assert!(CACHE_LINE_BYTE_SIZE.is_multiple_of(std::mem::size_of::<T>())) }; const { assert!(CACHE_LINE_BYTE_SIZE == 64) }; // SAFETY: CacheLine is 64 bytes with no padding, with higher alignment requirements than T. // T is guaranteed to be a bag-of-bits type by the safety requirements of ImageDataType. // The other safety requirements follow from the data pointer and length being obtained from a // slice. unsafe {
std::slice::from_raw_parts_mut(
slice.as_mut_ptr().cast::<T>(),
slice.len() * (CACHE_LINE_BYTE_SIZE / std::mem::size_of::<T>()),
)
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-08-25)
¤
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.