@@ -76,6 +76,10 @@ use crate::simd::{
76
76
/// [`read`]: pointer::read
77
77
/// [`write`]: pointer::write
78
78
/// [as_simd]: slice::as_simd
79
+ //
80
+ // NOTE: Accessing the inner array directly in any way (e.g. by using the `.0` field syntax) should
81
+ // be avoided, as it will likely become illegal on `#[repr(simd)]` structs in the future. It also
82
+ // causes rustc to emit illegal LLVM IR in some cases.
79
83
#[ repr( simd) ]
80
84
pub struct Simd < T , const LANES : usize > ( [ T ; LANES ] )
81
85
where
@@ -138,6 +142,9 @@ where
138
142
// SAFETY: Transmuting between `Simd<T, LANES>` and `[T; LANES]`
139
143
// is always valid and `Simd<T, LANES>` never has a lower alignment
140
144
// than `[T; LANES]`.
145
+ //
146
+ // NOTE: This deliberately doesn't just use `&self.0`, see the comment
147
+ // on the struct definition for details.
141
148
unsafe { & * ( self as * const Self as * const [ T ; LANES ] ) }
142
149
}
143
150
@@ -146,20 +153,29 @@ where
146
153
// SAFETY: Transmuting between `Simd<T, LANES>` and `[T; LANES]`
147
154
// is always valid and `Simd<T, LANES>` never has a lower alignment
148
155
// than `[T; LANES]`.
156
+ //
157
+ // NOTE: This deliberately doesn't just use `&mut self.0`, see the comment
158
+ // on the struct definition for details.
149
159
unsafe { & mut * ( self as * mut Self as * mut [ T ; LANES ] ) }
150
160
}
151
161
152
162
/// Converts an array to a SIMD vector.
153
163
pub const fn from_array ( array : [ T ; LANES ] ) -> Self {
154
164
// SAFETY: Transmuting between `Simd<T, LANES>` and `[T; LANES]`
155
165
// is always valid.
166
+ //
167
+ // NOTE: This deliberately doesn't just use `Self(array)`, see the comment
168
+ // on the struct definition for details.
156
169
unsafe { core:: mem:: transmute_copy ( & array) }
157
170
}
158
171
159
172
/// Converts a SIMD vector to an array.
160
173
pub const fn to_array ( self ) -> [ T ; LANES ] {
161
174
// SAFETY: Transmuting between `Simd<T, LANES>` and `[T; LANES]`
162
175
// is always valid.
176
+ //
177
+ // NOTE: This deliberately doesn't just use `self.0`, see the comment
178
+ // on the struct definition for details.
163
179
unsafe { core:: mem:: transmute_copy ( & self ) }
164
180
}
165
181
0 commit comments