Skip to content

Commit 7c3d72d

Browse files
Test core::simd works
These tests just verify some basic APIs of core::simd function, and guarantees that attempting to access the wrong things doesn't work. The majority of tests are stochastic, and so remain upstream, but a few deterministic tests arrive in the subtree as doc tests.
1 parent 39cb863 commit 7c3d72d

6 files changed

+99
-0
lines changed

library/core/tests/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#![feature(unwrap_infallible)]
6363
#![feature(option_result_unwrap_unchecked)]
6464
#![feature(result_into_ok_or_err)]
65+
#![cfg_attr(not(bootstrap), feature(portable_simd))]
6566
#![feature(ptr_metadata)]
6667
#![feature(once_cell)]
6768
#![feature(unsized_tuple_coercion)]
@@ -104,6 +105,8 @@ mod pattern;
104105
mod pin;
105106
mod ptr;
106107
mod result;
108+
#[cfg(not(bootstrap))]
109+
mod simd;
107110
mod slice;
108111
mod str;
109112
mod str_lossy;

library/core/tests/simd.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use core::simd::f32x4;
2+
3+
#[test]
4+
fn testing() {
5+
let x = f32x4::from_array([1.0, 1.0, 1.0, 1.0]);
6+
let y = -x;
7+
8+
let h = x * 0.5;
9+
10+
let r = y.abs();
11+
assert_eq!(x, r);
12+
assert_eq!(h, f32x4::splat(0.5));
13+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![crate_type = "rlib"]
2+
#![no_std]
3+
#![feature(portable_simd)]
4+
use core::simd::f32x4;
5+
6+
// For SIMD float ops, the LLIR version which is used to implement the portable
7+
// forms of them may become calls to math.h AKA libm. So, we can't guarantee
8+
// we can compile them for #![no_std] crates.
9+
// Someday we may solve this.
10+
// Until then, this test at least guarantees these functions require std.
11+
fn guarantee_no_std_nolibm_calls() -> f32x4 {
12+
let x = f32x4::from_array([0.1, 0.5, 0.6, -1.5]);
13+
let x2 = x + x;
14+
let _xc = x.ceil(); //~ ERROR E0599
15+
let _xf = x.floor(); //~ ERROR E0599
16+
let _xr = x.round(); //~ ERROR E0599
17+
let _xt = x.trunc(); //~ ERROR E0599
18+
let _xfma = x.mul_add(x, x); //~ ERROR E0599
19+
let _xsqrt = x.sqrt(); //~ ERROR E0599
20+
x2.abs() * x2
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0599]: no method named `ceil` found for struct `Simd` in the current scope
2+
--> $DIR/libm_no_std_cant_float.rs:14:17
3+
|
4+
LL | let _xc = x.ceil();
5+
| ^^^^ method not found in `Simd<f32, 4_usize>`
6+
7+
error[E0599]: no method named `floor` found for struct `Simd` in the current scope
8+
--> $DIR/libm_no_std_cant_float.rs:15:17
9+
|
10+
LL | let _xf = x.floor();
11+
| ^^^^^ method not found in `Simd<f32, 4_usize>`
12+
13+
error[E0599]: no method named `round` found for struct `Simd` in the current scope
14+
--> $DIR/libm_no_std_cant_float.rs:16:17
15+
|
16+
LL | let _xr = x.round();
17+
| ^^^^^ method not found in `Simd<f32, 4_usize>`
18+
19+
error[E0599]: no method named `trunc` found for struct `Simd` in the current scope
20+
--> $DIR/libm_no_std_cant_float.rs:17:17
21+
|
22+
LL | let _xt = x.trunc();
23+
| ^^^^^ method not found in `Simd<f32, 4_usize>`
24+
25+
error[E0599]: no method named `mul_add` found for struct `Simd` in the current scope
26+
--> $DIR/libm_no_std_cant_float.rs:18:19
27+
|
28+
LL | let _xfma = x.mul_add(x, x);
29+
| ^^^^^^^ method not found in `Simd<f32, 4_usize>`
30+
31+
error[E0599]: no method named `sqrt` found for struct `Simd` in the current scope
32+
--> $DIR/libm_no_std_cant_float.rs:19:20
33+
|
34+
LL | let _xsqrt = x.sqrt();
35+
| ^^^^ method not found in `Simd<f32, 4_usize>`
36+
37+
error: aborting due to 6 previous errors
38+
39+
For more information about this error, try `rustc --explain E0599`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// May not matter, since people can use them with a nightly feature.
2+
// However this tests to guarantee they don't leak out via portable_simd,
3+
// and thus don't accidentally get stabilized.
4+
use std::simd::intrinsics; //~ERROR E0603
5+
6+
fn main() {
7+
()
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0603]: module `intrinsics` is private
2+
--> $DIR/portable-intrinsics-arent-exposed.rs:4:16
3+
|
4+
LL | use std::simd::intrinsics;
5+
| ^^^^^^^^^^ private module
6+
|
7+
note: the module `intrinsics` is defined here
8+
--> $SRC_DIR/core/src/lib.rs:LL:COL
9+
|
10+
LL | pub use crate::core_simd::simd::*;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0603`.

0 commit comments

Comments
 (0)