4
4
5
5
/// Inserts an element into a vector, returning the updated vector.
6
6
///
7
- /// `T` must be a vector with element type `U`.
7
+ /// `T` must be a vector with element type `U`, and `idx` must be `const` .
8
8
///
9
9
/// # Safety
10
10
///
@@ -15,15 +15,48 @@ pub const unsafe fn simd_insert<T, U>(x: T, idx: u32, val: U) -> T;
15
15
16
16
/// Extracts an element from a vector.
17
17
///
18
- /// `T` must be a vector with element type `U`.
18
+ /// `T` must be a vector with element type `U`, and `idx` must be `const` .
19
19
///
20
20
/// # Safety
21
21
///
22
- /// `idx` must be in-bounds of the vector.
22
+ /// `idx` must be const and in-bounds of the vector.
23
23
#[ rustc_intrinsic]
24
24
#[ rustc_nounwind]
25
25
pub const unsafe fn simd_extract < T , U > ( x : T , idx : u32 ) -> U ;
26
26
27
+ /// Inserts an element into a vector, returning the updated vector.
28
+ ///
29
+ /// `T` must be a vector with element type `U`.
30
+ ///
31
+ /// If the index is `const`, [`simd_insert`] may emit better assembly.
32
+ ///
33
+ /// # Safety
34
+ ///
35
+ /// `idx` must be in-bounds of the vector.
36
+ #[ rustc_nounwind]
37
+ #[ cfg_attr( not( bootstrap) , rustc_intrinsic) ]
38
+ pub unsafe fn simd_insert_dyn < T , U > ( mut x : T , idx : u32 , val : U ) -> T {
39
+ // SAFETY: `idx` must be in-bounds
40
+ unsafe { ( & raw mut x) . cast :: < U > ( ) . add ( idx as usize ) . write ( val) }
41
+ x
42
+ }
43
+
44
+ /// Extracts an element from a vector.
45
+ ///
46
+ /// `T` must be a vector with element type `U`.
47
+ ///
48
+ /// If the index is `const`, [`simd_extract`] may emit better assembly.
49
+ ///
50
+ /// # Safety
51
+ ///
52
+ /// `idx` must be in-bounds of the vector.
53
+ #[ rustc_nounwind]
54
+ #[ cfg_attr( not( bootstrap) , rustc_intrinsic) ]
55
+ pub unsafe fn simd_extract_dyn < T , U > ( x : T , idx : u32 ) -> U {
56
+ // SAFETY: `idx` must be in-bounds
57
+ unsafe { ( & raw const x) . cast :: < U > ( ) . add ( idx as usize ) . read ( ) }
58
+ }
59
+
27
60
/// Adds two simd vectors elementwise.
28
61
///
29
62
/// `T` must be a vector of integers or floats.
0 commit comments