about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJubilee Young <workingjubilee@gmail.com>2021-10-22 00:47:12 -0700
committerJubilee Young <workingjubilee@gmail.com>2021-11-12 16:58:47 -0800
commit7c3d72d069600c7826e44d26bf005eb28e91b169 (patch)
tree52110b39f2cdc7da94db6500aa8302924a107f9a
parent39cb863253a1d7cd8371d49871a20a3244ba6211 (diff)
downloadrust-7c3d72d069600c7826e44d26bf005eb28e91b169.tar.gz
rust-7c3d72d069600c7826e44d26bf005eb28e91b169.zip
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.
-rw-r--r--library/core/tests/lib.rs3
-rw-r--r--library/core/tests/simd.rs13
-rw-r--r--src/test/ui/simd/libm_no_std_cant_float.rs21
-rw-r--r--src/test/ui/simd/libm_no_std_cant_float.stderr39
-rw-r--r--src/test/ui/simd/portable-intrinsics-arent-exposed.rs8
-rw-r--r--src/test/ui/simd/portable-intrinsics-arent-exposed.stderr15
6 files changed, 99 insertions, 0 deletions
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
index ab0295c6314..c68766cb9e9 100644
--- a/library/core/tests/lib.rs
+++ b/library/core/tests/lib.rs
@@ -62,6 +62,7 @@
 #![feature(unwrap_infallible)]
 #![feature(option_result_unwrap_unchecked)]
 #![feature(result_into_ok_or_err)]
+#![cfg_attr(not(bootstrap), feature(portable_simd))]
 #![feature(ptr_metadata)]
 #![feature(once_cell)]
 #![feature(unsized_tuple_coercion)]
@@ -104,6 +105,8 @@ mod pattern;
 mod pin;
 mod ptr;
 mod result;
+#[cfg(not(bootstrap))]
+mod simd;
 mod slice;
 mod str;
 mod str_lossy;
diff --git a/library/core/tests/simd.rs b/library/core/tests/simd.rs
new file mode 100644
index 00000000000..8c11d788c67
--- /dev/null
+++ b/library/core/tests/simd.rs
@@ -0,0 +1,13 @@
+use core::simd::f32x4;
+
+#[test]
+fn testing() {
+    let x = f32x4::from_array([1.0, 1.0, 1.0, 1.0]);
+    let y = -x;
+
+    let h = x * 0.5;
+
+    let r = y.abs();
+    assert_eq!(x, r);
+    assert_eq!(h, f32x4::splat(0.5));
+}
diff --git a/src/test/ui/simd/libm_no_std_cant_float.rs b/src/test/ui/simd/libm_no_std_cant_float.rs
new file mode 100644
index 00000000000..abe460a326b
--- /dev/null
+++ b/src/test/ui/simd/libm_no_std_cant_float.rs
@@ -0,0 +1,21 @@
+#![crate_type = "rlib"]
+#![no_std]
+#![feature(portable_simd)]
+use core::simd::f32x4;
+
+// For SIMD float ops, the LLIR version which is used to implement the portable
+// forms of them may become calls to math.h AKA libm. So, we can't guarantee
+// we can compile them for #![no_std] crates.
+// Someday we may solve this.
+// Until then, this test at least guarantees these functions require std.
+fn guarantee_no_std_nolibm_calls() -> f32x4 {
+    let x = f32x4::from_array([0.1, 0.5, 0.6, -1.5]);
+    let x2 = x + x;
+    let _xc = x.ceil(); //~ ERROR E0599
+    let _xf = x.floor(); //~ ERROR E0599
+    let _xr = x.round(); //~ ERROR E0599
+    let _xt = x.trunc(); //~ ERROR E0599
+    let _xfma = x.mul_add(x, x); //~ ERROR E0599
+    let _xsqrt = x.sqrt(); //~ ERROR E0599
+    x2.abs() * x2
+}
diff --git a/src/test/ui/simd/libm_no_std_cant_float.stderr b/src/test/ui/simd/libm_no_std_cant_float.stderr
new file mode 100644
index 00000000000..dc8638f6ab7
--- /dev/null
+++ b/src/test/ui/simd/libm_no_std_cant_float.stderr
@@ -0,0 +1,39 @@
+error[E0599]: no method named `ceil` found for struct `Simd` in the current scope
+  --> $DIR/libm_no_std_cant_float.rs:14:17
+   |
+LL |     let _xc = x.ceil();
+   |                 ^^^^ method not found in `Simd<f32, 4_usize>`
+
+error[E0599]: no method named `floor` found for struct `Simd` in the current scope
+  --> $DIR/libm_no_std_cant_float.rs:15:17
+   |
+LL |     let _xf = x.floor();
+   |                 ^^^^^ method not found in `Simd<f32, 4_usize>`
+
+error[E0599]: no method named `round` found for struct `Simd` in the current scope
+  --> $DIR/libm_no_std_cant_float.rs:16:17
+   |
+LL |     let _xr = x.round();
+   |                 ^^^^^ method not found in `Simd<f32, 4_usize>`
+
+error[E0599]: no method named `trunc` found for struct `Simd` in the current scope
+  --> $DIR/libm_no_std_cant_float.rs:17:17
+   |
+LL |     let _xt = x.trunc();
+   |                 ^^^^^ method not found in `Simd<f32, 4_usize>`
+
+error[E0599]: no method named `mul_add` found for struct `Simd` in the current scope
+  --> $DIR/libm_no_std_cant_float.rs:18:19
+   |
+LL |     let _xfma = x.mul_add(x, x);
+   |                   ^^^^^^^ method not found in `Simd<f32, 4_usize>`
+
+error[E0599]: no method named `sqrt` found for struct `Simd` in the current scope
+  --> $DIR/libm_no_std_cant_float.rs:19:20
+   |
+LL |     let _xsqrt = x.sqrt();
+   |                    ^^^^ method not found in `Simd<f32, 4_usize>`
+
+error: aborting due to 6 previous errors
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/simd/portable-intrinsics-arent-exposed.rs b/src/test/ui/simd/portable-intrinsics-arent-exposed.rs
new file mode 100644
index 00000000000..4d759032355
--- /dev/null
+++ b/src/test/ui/simd/portable-intrinsics-arent-exposed.rs
@@ -0,0 +1,8 @@
+// May not matter, since people can use them with a nightly feature.
+// However this tests to guarantee they don't leak out via portable_simd,
+// and thus don't accidentally get stabilized.
+use std::simd::intrinsics; //~ERROR E0603
+
+fn main() {
+    ()
+}
diff --git a/src/test/ui/simd/portable-intrinsics-arent-exposed.stderr b/src/test/ui/simd/portable-intrinsics-arent-exposed.stderr
new file mode 100644
index 00000000000..9ac73eca193
--- /dev/null
+++ b/src/test/ui/simd/portable-intrinsics-arent-exposed.stderr
@@ -0,0 +1,15 @@
+error[E0603]: module `intrinsics` is private
+  --> $DIR/portable-intrinsics-arent-exposed.rs:4:16
+   |
+LL | use std::simd::intrinsics;
+   |                ^^^^^^^^^^ private module
+   |
+note: the module `intrinsics` is defined here
+  --> $SRC_DIR/core/src/lib.rs:LL:COL
+   |
+LL |     pub use crate::core_simd::simd::*;
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0603`.