rill_core/math/vector/simd/
mod.rs1#![allow(unused_imports)]
19#![allow(dead_code)]
20
21#[cfg(feature = "simd")]
23pub mod wide;
24
25#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
26pub mod x86;
27
28#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
29pub mod arm;
30
31#[cfg(target_arch = "wasm32")]
32pub mod wasm;
33
34pub struct SimdDetector {
36 has_sse2: bool,
37 has_sse4_1: bool,
38 has_avx: bool,
39 has_avx2: bool,
40 has_avx512: bool,
41 has_neon: bool,
42 has_wasm_simd128: bool,
43}
44
45impl Default for SimdDetector {
46 fn default() -> Self {
47 Self::new()
48 }
49}
50
51impl SimdDetector {
52 pub fn new() -> Self {
58 Self {
59 #[cfg(target_arch = "x86_64")]
60 has_sse2: std::arch::is_x86_feature_detected!("sse2"),
61 #[cfg(target_arch = "x86")]
62 has_sse2: std::arch::is_x86_feature_detected!("sse2"),
63 #[cfg(target_arch = "x86_64")]
64 has_sse4_1: std::arch::is_x86_feature_detected!("sse4.1"),
65 #[cfg(target_arch = "x86")]
66 has_sse4_1: std::arch::is_x86_feature_detected!("sse4.1"),
67 #[cfg(target_arch = "x86_64")]
68 has_avx: std::arch::is_x86_feature_detected!("avx"),
69 #[cfg(target_arch = "x86")]
70 has_avx: std::arch::is_x86_feature_detected!("avx"),
71 #[cfg(target_arch = "x86_64")]
72 has_avx2: std::arch::is_x86_feature_detected!("avx2"),
73 #[cfg(target_arch = "x86")]
74 has_avx2: std::arch::is_x86_feature_detected!("avx2"),
75 #[cfg(target_arch = "x86_64")]
76 has_avx512: std::arch::is_x86_feature_detected!("avx512f"),
77 #[cfg(target_arch = "x86")]
78 has_avx512: std::arch::is_x86_feature_detected!("avx512f"),
79 #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
80 has_sse2: false,
81 #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
82 has_sse4_1: false,
83 #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
84 has_avx: false,
85 #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
86 has_avx2: false,
87 #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
88 has_avx512: false,
89 #[cfg(target_arch = "aarch64")]
90 has_neon: std::arch::is_aarch64_feature_detected!("neon"),
91 #[cfg(not(target_arch = "aarch64"))]
92 has_neon: false,
93 #[cfg(target_arch = "wasm32")]
94 has_wasm_simd128: true,
95 #[cfg(not(target_arch = "wasm32"))]
96 has_wasm_simd128: false,
97 }
98 }
99
100 pub fn recommended_simd_width<T: crate::Transcendental>() -> usize {
107 let det = Self::new();
108 if det.has_avx {
109 return 8;
110 }
111 if det.has_sse2 || det.has_neon || det.has_wasm_simd128 {
112 return 4;
113 }
114 1
115 }
116}
117
118#[cfg(feature = "simd")]
120pub use wide::*;
121
122