| 1 | use craterust-analyzer cargo target-features 0.1.6 crate/::Architecturerust-analyzer cargo target-features 0.1.6 Architecture#; |
| 2 | |
| 3 | #[doc(hidden)] |
| 4 | pub enum SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# { |
| 5 | Float32rust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Float32#, |
| 6 | Float64rust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Float64#, |
| 7 | Otherrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Other#, |
| 8 | } |
| 9 | |
| 10 | /// Types which can be SIMD vector elements. |
| 11 | pub trait SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# { |
| 12 | #[doc(hidden)] |
| 13 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/SimdType#IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#; |
| 14 | } |
| 15 | |
| 16 | impl SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# for u8 { |
| 17 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/impl#[u8][SimdType]IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# = SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Otherrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Other#; |
| 18 | } |
| 19 | |
| 20 | impl SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# for u16 { |
| 21 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/impl#[u16][SimdType]IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# = SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Otherrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Other#; |
| 22 | } |
| 23 | |
| 24 | impl SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# for u32 { |
| 25 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/impl#[u32][SimdType]IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# = SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Otherrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Other#; |
| 26 | } |
| 27 | |
| 28 | impl SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# for u64 { |
| 29 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/impl#[u64][SimdType]IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# = SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Otherrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Other#; |
| 30 | } |
| 31 | |
| 32 | impl SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# for usize { |
| 33 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/impl#[usize][SimdType]IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# = SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Otherrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Other#; |
| 34 | } |
| 35 | |
| 36 | impl SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# for i8 { |
| 37 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/impl#[i8][SimdType]IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# = SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Otherrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Other#; |
| 38 | } |
| 39 | |
| 40 | impl SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# for i16 { |
| 41 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/impl#[i16][SimdType]IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# = SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Otherrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Other#; |
| 42 | } |
| 43 | |
| 44 | impl SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# for i32 { |
| 45 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/impl#[i32][SimdType]IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# = SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Otherrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Other#; |
| 46 | } |
| 47 | |
| 48 | impl SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# for i64 { |
| 49 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/impl#[i64][SimdType]IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# = SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Otherrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Other#; |
| 50 | } |
| 51 | |
| 52 | impl SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# for isize { |
| 53 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/impl#[isize][SimdType]IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# = SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Otherrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Other#; |
| 54 | } |
| 55 | |
| 56 | impl SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# for f32 { |
| 57 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/impl#[f32][SimdType]IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# = SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Float32rust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Float32#; |
| 58 | } |
| 59 | |
| 60 | impl SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# for f64 { |
| 61 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/impl#[f64][SimdType]IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# = SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Float64rust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Float64#; |
| 62 | } |
| 63 | |
| 64 | impl<T> SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# for *const T { |
| 65 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/impl#[`*const T`][SimdType]IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# = SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Otherrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Other#; |
| 66 | } |
| 67 | |
| 68 | impl<T> SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType# for *mut T { |
| 69 | const IMPLrust-analyzer cargo target-features 0.1.6 simd/impl#[`*mut T`][SimdType]IMPL.: SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl# = SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Otherrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Other#; |
| 70 | } |
| 71 | |
| 72 | impl craterust-analyzer cargo target-features 0.1.6 crate/::Targetrust-analyzer cargo target-features 0.1.6 Target# { |
| 73 | /// Returns a suggested number of elements for a SIMD vector of the provided type. |
| 74 | /// |
| 75 | /// The returned value is an approximation and not necessarily indicative of the |
| 76 | /// optimal vector width. A few caveats: |
| 77 | /// * Every instruction set is different, and this function doesn't take into account any |
| 78 | /// particular operations--it's just a guess, and should be accurate at least for basic arithmetic. |
| 79 | /// * Variable length vector instruction sets (ARM SVE and RISC-V V) only return the minimum |
| 80 | /// vector length. |
| 81 | pub const fn suggested_simd_widthrust-analyzer cargo target-features 0.1.6 simd/impl#[`crate::Target`]suggested_simd_width().<T: SimdTyperust-analyzer cargo target-features 0.1.6 simd/SimdType#>(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> { |
| 82 | let is_f32 = T::IMPLrust-analyzer cargo target-features 0.1.6 simd/SimdType#IMPL. as u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Float32rust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Float32# as u8; |
| 83 | let is_f64 = T::IMPLrust-analyzer cargo target-features 0.1.6 simd/SimdType#IMPL. as u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().SimdTypeImplrust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#::Float64rust-analyzer cargo target-features 0.1.6 simd/SimdTypeImpl#Float64# as u8; |
| 84 | |
| 85 | let v128 = 16 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>(); |
| 86 | let v256 = 32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>(); |
| 87 | let v512 = 64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>(); |
| 88 | let v1024 = 128 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<T>(); |
| 89 | |
| 90 | if let Architecturerust-analyzer cargo target-features 0.1.6 Architecture#::Armrust-analyzer cargo target-features 0.1.6 Architecture#Arm# = self.architecturerust-analyzer cargo target-features 0.1.6 impl#[Target]architecture().() { |
| 91 | // Neon on arm doesn't support f64 |
| 92 | if self.supports_feature_strrust-analyzer cargo target-features 0.1.6 impl#[Target]supports_feature_str().("neon") && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_f64 { |
| 93 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v128) |
| 94 | } else { |
| 95 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 96 | } |
| 97 | } else if let Architecturerust-analyzer cargo target-features 0.1.6 Architecture#::AArch64rust-analyzer cargo target-features 0.1.6 Architecture#AArch64# = self.architecturerust-analyzer cargo target-features 0.1.6 impl#[Target]architecture().() { |
| 98 | if self.supports_feature_strrust-analyzer cargo target-features 0.1.6 impl#[Target]supports_feature_str().("neon") { |
| 99 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v128) |
| 100 | } else { |
| 101 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 102 | } |
| 103 | } else if let Architecturerust-analyzer cargo target-features 0.1.6 Architecture#::Hexagonrust-analyzer cargo target-features 0.1.6 Architecture#Hexagon# = self.architecturerust-analyzer cargo target-features 0.1.6 impl#[Target]architecture().() { |
| 104 | // HVX doesn't support floats |
| 105 | if is_f32 || is_f64 { |
| 106 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 107 | } else if self.supports_feature_strrust-analyzer cargo target-features 0.1.6 impl#[Target]supports_feature_str().("hvx-length128b") { |
| 108 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v1024) |
| 109 | } else if self.supports_feature_strrust-analyzer cargo target-features 0.1.6 impl#[Target]supports_feature_str().("hvx") { |
| 110 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v512) |
| 111 | } else { |
| 112 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 113 | } |
| 114 | } else if let Architecturerust-analyzer cargo target-features 0.1.6 Architecture#::Mipsrust-analyzer cargo target-features 0.1.6 Architecture#Mips# = self.architecturerust-analyzer cargo target-features 0.1.6 impl#[Target]architecture().() { |
| 115 | if self.supports_feature_strrust-analyzer cargo target-features 0.1.6 impl#[Target]supports_feature_str().("msa") { |
| 116 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v128) |
| 117 | } else { |
| 118 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 119 | } |
| 120 | } else if let Architecturerust-analyzer cargo target-features 0.1.6 Architecture#::PowerPCrust-analyzer cargo target-features 0.1.6 Architecture#PowerPC# = self.architecturerust-analyzer cargo target-features 0.1.6 impl#[Target]architecture().() { |
| 121 | // Altivec without VSX doesn't support f64 |
| 122 | if self.supports_feature_strrust-analyzer cargo target-features 0.1.6 impl#[Target]supports_feature_str().("vsx") || (self.supports_feature_strrust-analyzer cargo target-features 0.1.6 impl#[Target]supports_feature_str().("altivec") && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_f64) |
| 123 | { |
| 124 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v128) |
| 125 | } else { |
| 126 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 127 | } |
| 128 | } else if let Architecturerust-analyzer cargo target-features 0.1.6 Architecture#::RiscVrust-analyzer cargo target-features 0.1.6 Architecture#RiscV# = self.architecturerust-analyzer cargo target-features 0.1.6 impl#[Target]architecture().() { |
| 129 | // V provides at least 128-bit vectors |
| 130 | if self.supports_feature_strrust-analyzer cargo target-features 0.1.6 impl#[Target]supports_feature_str().("v") { |
| 131 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v128) |
| 132 | } else { |
| 133 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 134 | } |
| 135 | } else if let Architecturerust-analyzer cargo target-features 0.1.6 Architecture#::Wasmrust-analyzer cargo target-features 0.1.6 Architecture#Wasm# = self.architecturerust-analyzer cargo target-features 0.1.6 impl#[Target]architecture().() { |
| 136 | if self.supports_feature_strrust-analyzer cargo target-features 0.1.6 impl#[Target]supports_feature_str().("simd128") { |
| 137 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v128) |
| 138 | } else { |
| 139 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 140 | } |
| 141 | } else if let Architecturerust-analyzer cargo target-features 0.1.6 Architecture#::X86rust-analyzer cargo target-features 0.1.6 Architecture#X86# = self.architecturerust-analyzer cargo target-features 0.1.6 impl#[Target]architecture().() { |
| 142 | if self.supports_feature_strrust-analyzer cargo target-features 0.1.6 impl#[Target]supports_feature_str().("avx512f") { |
| 143 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v512) |
| 144 | } else if self.supports_feature_strrust-analyzer cargo target-features 0.1.6 impl#[Target]supports_feature_str().("avx2") |
| 145 | || (is_f32 || is_f64) && self.supports_feature_strrust-analyzer cargo target-features 0.1.6 impl#[Target]supports_feature_str().("avx") |
| 146 | { |
| 147 | // AVX supports f32 and f64 |
| 148 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v256) |
| 149 | } else if self.supports_feature_strrust-analyzer cargo target-features 0.1.6 impl#[Target]supports_feature_str().("sse2") |
| 150 | || is_f32 && self.supports_feature_strrust-analyzer cargo target-features 0.1.6 impl#[Target]supports_feature_str().("sse") |
| 151 | { |
| 152 | // SSE supports f32 |
| 153 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v128) |
| 154 | } else { |
| 155 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 156 | } |
| 157 | } else { |
| 158 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 159 | } |
| 160 | } |
| 161 | } |