linear_srgb/
targets.rs

1//! SIMD target definitions for multiversion dispatch.
2//!
3//! Provides macros for consistent SIMD target specification.
4
5// ============================================================================
6// x86/x86_64 macros
7// ============================================================================
8
9/// Primary SIMD targets for most functions (x86_64 version).
10#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
11#[macro_export]
12macro_rules! simd_multiversion {
13    ($($item:tt)*) => {
14        #[multiversion::multiversion(targets(
15            // x86-64-v3 (Haswell 2013+, Zen 2 2019+)
16            "x86_64+sse+sse2+sse3+ssse3+sse4.1+sse4.2+popcnt+cmpxchg16b+avx+avx2+bmi1+bmi2+f16c+fma+lzcnt+movbe+xsave+fxsr",
17        ))]
18        $($item)*
19    };
20}
21
22/// Extended SIMD targets (x86_64 version).
23#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
24#[macro_export]
25macro_rules! simd_multiversion_extended {
26    ($($item:tt)*) => {
27        #[multiversion::multiversion(targets(
28            // x86-64-v4 with AVX-512 (Skylake-X 2017+, Zen 4 2022+)
29            "x86_64+sse+sse2+sse3+ssse3+sse4.1+sse4.2+popcnt+cmpxchg16b+avx+avx2+bmi1+bmi2+f16c+fma+lzcnt+movbe+xsave+fxsr+avx512f+avx512bw+avx512dq+avx512vl+avx512cd+gfni+vaes+vpclmulqdq",
30            // x86-64-v3 (Haswell 2013+)
31            "x86_64+sse+sse2+sse3+ssse3+sse4.1+sse4.2+popcnt+cmpxchg16b+avx+avx2+bmi1+bmi2+f16c+fma+lzcnt+movbe+xsave+fxsr",
32        ))]
33        $($item)*
34    };
35}
36
37/// Full SIMD targets (x86_64 version).
38#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
39#[macro_export]
40macro_rules! simd_multiversion_full {
41    ($($item:tt)*) => {
42        #[multiversion::multiversion(targets(
43            // x86-64-v4 with AVX-512 (Skylake-X 2017+, Zen 4 2022+)
44            "x86_64+sse+sse2+sse3+ssse3+sse4.1+sse4.2+popcnt+cmpxchg16b+avx+avx2+bmi1+bmi2+f16c+fma+lzcnt+movbe+xsave+fxsr+avx512f+avx512bw+avx512dq+avx512vl+avx512cd+gfni+vaes+vpclmulqdq",
45            // x86-64-v3 (Haswell 2013+)
46            "x86_64+sse+sse2+sse3+ssse3+sse4.1+sse4.2+popcnt+cmpxchg16b+avx+avx2+bmi1+bmi2+f16c+fma+lzcnt+movbe+xsave+fxsr",
47        ))]
48        $($item)*
49    };
50}
51
52// ============================================================================
53// aarch64 macros
54// ============================================================================
55
56/// Primary SIMD targets for most functions (aarch64 version).
57#[cfg(target_arch = "aarch64")]
58#[macro_export]
59macro_rules! simd_multiversion {
60    ($($item:tt)*) => {
61        #[multiversion::multiversion(targets(
62            // aarch64 baseline (all ARM64)
63            "aarch64+neon+lse+aes+sha2+crc",
64        ))]
65        $($item)*
66    };
67}
68
69/// Extended SIMD targets (aarch64 version).
70#[cfg(target_arch = "aarch64")]
71#[macro_export]
72macro_rules! simd_multiversion_extended {
73    ($($item:tt)*) => {
74        #[multiversion::multiversion(targets(
75            // aarch64 with dotprod (A75 2017+, Apple A11+)
76            "aarch64+neon+lse+aes+sha2+crc+dotprod+rcpc+fp16+fhm",
77            // aarch64 baseline
78            "aarch64+neon+lse+aes+sha2+crc",
79        ))]
80        $($item)*
81    };
82}
83
84/// Full SIMD targets (aarch64 version).
85#[cfg(target_arch = "aarch64")]
86#[macro_export]
87macro_rules! simd_multiversion_full {
88    ($($item:tt)*) => {
89        #[multiversion::multiversion(targets(
90            // aarch64 with SVE2 (Neoverse V1 2020+, Apple M4 2024+)
91            "aarch64+neon+lse+aes+sha2+crc+dotprod+rcpc+fp16+fhm+sve2+sve2-bitperm+i8mm+bf16",
92            // aarch64 with sha3/fcma (A76 2018+, Apple M1+)
93            "aarch64+neon+lse+aes+sha2+sha3+crc+dotprod+rcpc+fp16+fhm+fcma",
94            // aarch64 with dotprod (A75 2017+, Apple A11+)
95            "aarch64+neon+lse+aes+sha2+crc+dotprod+rcpc+fp16+fhm",
96            // aarch64 baseline
97            "aarch64+neon+lse+aes+sha2+crc",
98        ))]
99        $($item)*
100    };
101}
102
103// ============================================================================
104// Fallback for other architectures (wasm32, etc.)
105// ============================================================================
106
107/// Primary SIMD targets (fallback - no multiversion).
108#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))]
109#[macro_export]
110macro_rules! simd_multiversion {
111    ($($item:tt)*) => {
112        $($item)*
113    };
114}
115
116/// Extended SIMD targets (fallback - no multiversion).
117#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))]
118#[macro_export]
119macro_rules! simd_multiversion_extended {
120    ($($item:tt)*) => {
121        $($item)*
122    };
123}
124
125/// Full SIMD targets (fallback - no multiversion).
126#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))]
127#[macro_export]
128macro_rules! simd_multiversion_full {
129    ($($item:tt)*) => {
130        $($item)*
131    };
132}
133
134// Macros are exported at crate root via #[macro_export]