Skip to main content

arrow_buffer/alloc/
alignment.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5// NOTE: Below code is written for spatial/temporal prefetcher optimizations. Memory allocation
6// should align well with usage pattern of cache access and block sizes on layers of storage levels from
7// registers to non-volatile memory. These alignments are all cache aware alignments incorporated
8// from [cuneiform](https://crates.io/crates/cuneiform) crate. This approach mimics Intel TBB's
9// cache_aligned_allocator which exploits cache locality and minimizes prefetch signals
10// resulting in less round trip time between the layers of storage.
11// For further info: https://software.intel.com/en-us/node/506094
12
13// 32-bit architecture and things other than netburst microarchitecture are using 64 bytes.
14/// Cache and allocation multiple alignment size
15#[cfg(target_arch = "x86")]
16pub const ALIGNMENT: usize = 1 << 6;
17
18// Intel x86_64:
19// L2D streamer from L1:
20// Loads data or instructions from memory to the second-level cache. To use the streamer,
21// organize the data or instructions in blocks of 128 bytes, aligned on 128 bytes.
22// - https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-optimization-manual.pdf
23/// Cache and allocation multiple alignment size
24#[cfg(target_arch = "x86_64")]
25pub const ALIGNMENT: usize = 1 << 7;
26
27// 24Kc:
28// Data Line Size
29// - https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MD00346-2B-24K-DTS-04.00.pdf
30// - https://gitlab.e.foundation/e/devices/samsung/n7100/stable_android_kernel_samsung_smdk4412/commit/2dbac10263b2f3c561de68b4c369bc679352ccee
31/// Cache and allocation multiple alignment size
32#[cfg(target_arch = "mips")]
33pub const ALIGNMENT: usize = 1 << 5;
34/// Cache and allocation multiple alignment size
35#[cfg(target_arch = "mips64")]
36pub const ALIGNMENT: usize = 1 << 5;
37
38// Defaults for powerpc
39/// Cache and allocation multiple alignment size
40#[cfg(target_arch = "powerpc")]
41pub const ALIGNMENT: usize = 1 << 5;
42
43// Defaults for the ppc 64
44/// Cache and allocation multiple alignment size
45#[cfg(target_arch = "powerpc64")]
46pub const ALIGNMENT: usize = 1 << 6;
47
48// e.g.: sifive
49// - https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/riscv/sifive-l2-cache.txt#L41
50// in general all of them are the same.
51/// Cache and allocation multiple alignment size
52#[cfg(target_arch = "riscv64")]
53pub const ALIGNMENT: usize = 1 << 6;
54
55// This size is same across all hardware for this architecture.
56// - https://docs.huihoo.com/doxygen/linux/kernel/3.7/arch_2s390_2include_2asm_2cache_8h.html
57/// Cache and allocation multiple alignment size
58#[cfg(target_arch = "s390x")]
59pub const ALIGNMENT: usize = 1 << 8;
60
61// This size is same across all hardware for this architecture.
62// - https://docs.huihoo.com/doxygen/linux/kernel/3.7/arch_2sparc_2include_2asm_2cache_8h.html#a9400cc2ba37e33279bdbc510a6311fb4
63/// Cache and allocation multiple alignment size
64#[cfg(target_arch = "sparc")]
65pub const ALIGNMENT: usize = 1 << 5;
66/// Cache and allocation multiple alignment size
67#[cfg(target_arch = "sparc64")]
68pub const ALIGNMENT: usize = 1 << 6;
69
70// Operating Systems cache size determines this.
71// Currently no way to determine this without runtime inference.
72/// Cache and allocation multiple alignment size
73#[cfg(target_arch = "wasm32")]
74pub const ALIGNMENT: usize = 1 << 6;
75
76// Same as v6 and v7.
77// List goes like that:
78// Cortex A, M, R, ARM v7, v7-M, Krait and NeoverseN uses this size.
79/// Cache and allocation multiple alignment size
80#[cfg(target_arch = "arm")]
81pub const ALIGNMENT: usize = 1 << 5;
82
83// Combined from 4 sectors. Volta says 128.
84// Prevent chunk optimizations better to go to the default size.
85// If you have smaller data with less padded functionality then use 32 with force option.
86// - https://devtalk.nvidia.com/default/topic/803600/variable-cache-line-width-/
87/// Cache and allocation multiple alignment size
88#[cfg(target_arch = "nvptx64")]
89pub const ALIGNMENT: usize = 1 << 7;
90
91// This size is same across all hardware for this architecture.
92/// Cache and allocation multiple alignment size
93#[cfg(target_arch = "aarch64")]
94pub const ALIGNMENT: usize = 1 << 6;
95
96/// Cache and allocation multiple alignment size
97#[cfg(target_arch = "loongarch64")]
98pub const ALIGNMENT: usize = 1 << 6;