Skip to content

Commit 4e961dc

Browse files
committed
make simd_insert and simd_extract const fns
1 parent a837e99 commit 4e961dc

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

library/core/src/intrinsics/simd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/// `idx` must be in-bounds of the vector.
1212
#[rustc_intrinsic]
1313
#[rustc_nounwind]
14-
pub unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T;
14+
pub const unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T;
1515

1616
/// Extracts an element from a vector.
1717
///
@@ -22,7 +22,7 @@ pub unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T;
2222
/// `idx` must be in-bounds of the vector.
2323
#[rustc_intrinsic]
2424
#[rustc_nounwind]
25-
pub unsafe fn simd_extract<T, U>(_x: T, _idx: u32) -> U;
25+
pub const unsafe fn simd_extract<T, U>(_x: T, _idx: u32) -> U;
2626

2727
/// Adds two simd vectors elementwise.
2828
///

tests/ui/consts/const-eval/simd/insert_extract.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,7 @@
55
#![stable(feature = "foo", since = "1.3.37")]
66
#![allow(non_camel_case_types)]
77

8-
// FIXME these intrinsics are not marked as const fn
9-
// use std::intrinsics::simd::{simd_extract, simd_insert};
10-
11-
#[stable(feature = "foo", since = "1.3.37")]
12-
#[rustc_const_stable(feature = "foo", since = "1.3.37")]
13-
#[rustc_intrinsic]
14-
const unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T {
15-
unimplemented!()
16-
}
17-
18-
#[stable(feature = "foo", since = "1.3.37")]
19-
#[rustc_const_stable(feature = "foo", since = "1.3.37")]
20-
#[rustc_intrinsic]
21-
const unsafe fn simd_extract<T, U>(_x: T, _idx: u32) -> U {
22-
unimplemented!()
23-
}
8+
use std::intrinsics::simd::{simd_extract, simd_insert};
249

2510
// repr(simd) now only supports array types
2611
#[repr(simd)]

tests/ui/simd/intrinsic/generic-reduction.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
error[E0511]: invalid monomorphization of `simd_reduce_add_ordered` intrinsic: expected return type `f32` (element of input `f32x4`), found `i32`
2-
--> $DIR/generic-reduction.rs:28:9
2+
--> $DIR/generic-reduction.rs:25:9
33
|
44
LL | simd_reduce_add_ordered(z, 0);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

77
error[E0511]: invalid monomorphization of `simd_reduce_mul_ordered` intrinsic: expected return type `f32` (element of input `f32x4`), found `i32`
8-
--> $DIR/generic-reduction.rs:30:9
8+
--> $DIR/generic-reduction.rs:27:9
99
|
1010
LL | simd_reduce_mul_ordered(z, 1);
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error[E0511]: invalid monomorphization of `simd_reduce_and` intrinsic: expected return type `u32` (element of input `u32x4`), found `f32`
14-
--> $DIR/generic-reduction.rs:33:22
14+
--> $DIR/generic-reduction.rs:30:22
1515
|
1616
LL | let _: f32 = simd_reduce_and(x);
1717
| ^^^^^^^^^^^^^^^^^^
1818

1919
error[E0511]: invalid monomorphization of `simd_reduce_or` intrinsic: expected return type `u32` (element of input `u32x4`), found `f32`
20-
--> $DIR/generic-reduction.rs:35:22
20+
--> $DIR/generic-reduction.rs:32:22
2121
|
2222
LL | let _: f32 = simd_reduce_or(x);
2323
| ^^^^^^^^^^^^^^^^^
2424

2525
error[E0511]: invalid monomorphization of `simd_reduce_xor` intrinsic: expected return type `u32` (element of input `u32x4`), found `f32`
26-
--> $DIR/generic-reduction.rs:37:22
26+
--> $DIR/generic-reduction.rs:34:22
2727
|
2828
LL | let _: f32 = simd_reduce_xor(x);
2929
| ^^^^^^^^^^^^^^^^^^
3030

3131
error[E0511]: invalid monomorphization of `simd_reduce_and` intrinsic: unsupported simd_reduce_and from `f32x4` with element `f32` to `f32`
32-
--> $DIR/generic-reduction.rs:40:22
32+
--> $DIR/generic-reduction.rs:37:22
3333
|
3434
LL | let _: f32 = simd_reduce_and(z);
3535
| ^^^^^^^^^^^^^^^^^^
3636

3737
error[E0511]: invalid monomorphization of `simd_reduce_or` intrinsic: unsupported simd_reduce_or from `f32x4` with element `f32` to `f32`
38-
--> $DIR/generic-reduction.rs:42:22
38+
--> $DIR/generic-reduction.rs:39:22
3939
|
4040
LL | let _: f32 = simd_reduce_or(z);
4141
| ^^^^^^^^^^^^^^^^^
4242

4343
error[E0511]: invalid monomorphization of `simd_reduce_xor` intrinsic: unsupported simd_reduce_xor from `f32x4` with element `f32` to `f32`
44-
--> $DIR/generic-reduction.rs:44:22
44+
--> $DIR/generic-reduction.rs:41:22
4545
|
4646
LL | let _: f32 = simd_reduce_xor(z);
4747
| ^^^^^^^^^^^^^^^^^^
4848

4949
error[E0511]: invalid monomorphization of `simd_reduce_all` intrinsic: unsupported simd_reduce_all from `f32x4` with element `f32` to `bool`
50-
--> $DIR/generic-reduction.rs:47:23
50+
--> $DIR/generic-reduction.rs:44:23
5151
|
5252
LL | let _: bool = simd_reduce_all(z);
5353
| ^^^^^^^^^^^^^^^^^^
5454

5555
error[E0511]: invalid monomorphization of `simd_reduce_any` intrinsic: unsupported simd_reduce_any from `f32x4` with element `f32` to `bool`
56-
--> $DIR/generic-reduction.rs:49:23
56+
--> $DIR/generic-reduction.rs:46:23
5757
|
5858
LL | let _: bool = simd_reduce_any(z);
5959
| ^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)