Skip to content

Commit 343146c

Browse files
committed
perf(cache): add architecture-specific L1 cache size detection
1 parent 3f2e751 commit 343146c

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/ntt/utils.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
/// Target single-thread workload size for `T`.
22
/// Should ideally be a multiple of a cache line (64 bytes)
3-
/// and close to the L1 cache size (32 KB).
3+
/// and close to the L1 cache size.
44
pub const fn workload_size<T: Sized>() -> usize {
5-
const CACHE_SIZE: usize = 1 << 15;
5+
#[cfg(all(target_arch = "aarch64", target_os = "macos"))]
6+
const CACHE_SIZE: usize = 1 << 17; // 128KB for Apple Silicon
7+
8+
#[cfg(all(target_arch = "aarch64", any(target_os = "ios", target_os = "android")))]
9+
const CACHE_SIZE: usize = 1 << 16; // 64KB for mobile ARM
10+
11+
#[cfg(target_arch = "x86_64")]
12+
const CACHE_SIZE: usize = 1 << 15; // 32KB for x86-64
13+
14+
#[cfg(not(any(
15+
all(target_arch = "aarch64", target_os = "macos"),
16+
all(target_arch = "aarch64", any(target_os = "ios", target_os = "android")),
17+
target_arch = "x86_64"
18+
)))]
19+
const CACHE_SIZE: usize = 1 << 15; // 32KB default
20+
621
CACHE_SIZE / size_of::<T>()
722
}
823

0 commit comments

Comments
 (0)