1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! Non-temporal (streaming) store utilities for large arrays
//!
//! Non-temporal stores bypass the CPU cache and write directly to RAM.
//! This is beneficial for large arrays (> L3 cache) where the output
//! won't be read immediately, avoiding cache pollution.
//!
//! # When to Use
//!
//! - Arrays larger than ~1MB (larger than typical L3 cache)
//! - Write-only operations (output not read immediately after)
//! - Element-wise ops that don't reuse output data
//!
//! # Requirements
//!
//! - **Alignment**: Streaming stores require aligned memory
//! - AVX2: 32-byte alignment for `_mm256_stream_ps`
//! - AVX-512: 64-byte alignment for `_mm512_stream_ps`
//! - **Memory fence**: `_mm_sfence()` must be called after streaming stores
//! to ensure writes are visible to other threads/devices
//!
//! # Performance
//!
//! Streaming stores help only on arrays that exceed L3 cache, because they
//! skip the read-for-ownership of lines that are never read back. Small
//! arrays gain nothing and can lose a little.
/// Threshold in bytes above which streaming stores are beneficial.
/// Set to 1MB - arrays larger than this will use non-temporal stores.
pub const STREAMING_THRESHOLD_BYTES: usize = 1024 * 1024;
/// Threshold in f32 elements (1MB / 4 bytes = 262144)
pub const STREAMING_THRESHOLD_F32: usize = STREAMING_THRESHOLD_BYTES / 4;
/// Threshold in f64 elements (1MB / 8 bytes = 131072)
pub const STREAMING_THRESHOLD_F64: usize = STREAMING_THRESHOLD_BYTES / 8;
/// Check if streaming stores should be used based on array length
pub const
/// Check if streaming stores should be used based on array length
pub const
/// AVX2 alignment requirement (32 bytes)
pub const AVX2_ALIGN: usize = 32;
/// AVX-512 alignment requirement (64 bytes)
pub const AVX512_ALIGN: usize = 64;
/// Check if pointer is aligned for AVX2 streaming stores (32-byte)
/// Check if pointer is aligned for AVX-512 streaming stores (64-byte)