about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJubilee Young <workingjubilee@gmail.com>2022-01-27 11:50:58 -0800
committerJubilee Young <workingjubilee@gmail.com>2022-01-27 11:50:58 -0800
commite96159e9af4e55070481a7c071e61e0adf337807 (patch)
treefbfbc641183d7daacc3e8164d731b7c1c7eb26da
parentcde7bdc678c52efd16baead2c9cb8eb3bf8be854 (diff)
pub use std::simd::StdFloat;
Make available the remaining float intrinsics that require runtime support
from a platform's libm, and thus cannot be included in a no-deps libcore,
by exposing them through a sealed trait, `std::simd::StdFloat`.

We might use the trait approach a bit more in the future, or maybe not.
Ideally, this trait doesn't stick around, even if so.
If we don't need to intermesh it with std, it can be used as a crate,
but currently that is somewhat uncertain.
-rw-r--r--library/std/src/lib.rs22
-rw-r--r--src/test/ui/simd/libm_std_can_float.rs23
-rw-r--r--src/test/ui/simd/portable-intrinsics-arent-exposed.rs3
-rw-r--r--src/test/ui/simd/portable-intrinsics-arent-exposed.stderr23
4 files changed, 57 insertions, 14 deletions
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index 17fe0011569..159b5027455 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -313,6 +313,7 @@
 #![feature(panic_internals)]
 #![feature(panic_unwind)]
 #![feature(pin_static_ref)]
+#![feature(platform_intrinsics)]
 #![feature(portable_simd)]
 #![feature(prelude_import)]
 #![feature(ptr_as_uninit)]
@@ -465,8 +466,6 @@ pub use core::pin;
 pub use core::ptr;
 #[stable(feature = "rust1", since = "1.0.0")]
 pub use core::result;
-#[unstable(feature = "portable_simd", issue = "86656")]
-pub use core::simd;
 #[unstable(feature = "async_stream", issue = "79024")]
 pub use core::stream;
 #[stable(feature = "i128", since = "1.26.0")]
@@ -513,6 +512,25 @@ pub mod time;
 #[unstable(feature = "once_cell", issue = "74465")]
 pub mod lazy;
 
+// Pull in `std_float` crate  into libstd. The contents of
+// `std_float` are in a different repository: rust-lang/portable-simd.
+#[path = "../../portable-simd/crates/std_float/src/lib.rs"]
+#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
+#[allow(rustdoc::bare_urls)]
+#[unstable(feature = "portable_simd", issue = "86656")]
+#[cfg(not(all(miri, doctest)))] // Miri does not support all SIMD intrinsics
+mod std_float;
+
+#[cfg(not(all(miri, doctest)))] // Miri does not support all SIMD intrinsics
+#[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
+#[unstable(feature = "portable_simd", issue = "86656")]
+pub mod simd {
+    #[doc(inline)]
+    pub use crate::std_float::StdFloat;
+    #[doc(inline)]
+    pub use core::simd::*;
+}
+
 #[stable(feature = "futures_api", since = "1.36.0")]
 pub mod task {
     //! Types and Traits for working with asynchronous tasks.
diff --git a/src/test/ui/simd/libm_std_can_float.rs b/src/test/ui/simd/libm_std_can_float.rs
new file mode 100644
index 00000000000..6a844e7120e
--- /dev/null
+++ b/src/test/ui/simd/libm_std_can_float.rs
@@ -0,0 +1,23 @@
+// run-pass
+
+// This is the converse of the other libm test.
+#![feature(portable_simd)]
+use std::simd::f32x4;
+use std::simd::StdFloat;
+
+// 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.
+//
+// However, we can expose some of these ops via an extension trait.
+fn main() {
+    let x = f32x4::from_array([0.1, 0.5, 0.6, -1.5]);
+    let x2 = x + x;
+    let _xc = x.ceil();
+    let _xf = x.floor();
+    let _xr = x.round();
+    let _xt = x.trunc();
+    let _xfma = x.mul_add(x, x);
+    let _xsqrt = x.sqrt();
+    let _ = x2.abs() * x2;
+}
diff --git a/src/test/ui/simd/portable-intrinsics-arent-exposed.rs b/src/test/ui/simd/portable-intrinsics-arent-exposed.rs
index 4d759032355..667c8b67b1d 100644
--- a/src/test/ui/simd/portable-intrinsics-arent-exposed.rs
+++ b/src/test/ui/simd/portable-intrinsics-arent-exposed.rs
@@ -1,7 +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
+use core::simd::intrinsics; //~ERROR E0433
+use std::simd::intrinsics; //~ERROR E0432
 
 fn main() {
     ()
diff --git a/src/test/ui/simd/portable-intrinsics-arent-exposed.stderr b/src/test/ui/simd/portable-intrinsics-arent-exposed.stderr
index 9ac73eca193..f568aa04295 100644
--- a/src/test/ui/simd/portable-intrinsics-arent-exposed.stderr
+++ b/src/test/ui/simd/portable-intrinsics-arent-exposed.stderr
@@ -1,15 +1,16 @@
-error[E0603]: module `intrinsics` is private
-  --> $DIR/portable-intrinsics-arent-exposed.rs:4:16
+error[E0433]: failed to resolve: maybe a missing crate `core`?
+  --> $DIR/portable-intrinsics-arent-exposed.rs:4:5
    |
-LL | use std::simd::intrinsics;
-   |                ^^^^^^^^^^ private module
-   |
-note: the module `intrinsics` is defined here
-  --> $SRC_DIR/core/src/lib.rs:LL:COL
+LL | use core::simd::intrinsics;
+   |     ^^^^ maybe a missing crate `core`?
+
+error[E0432]: unresolved import `std::simd::intrinsics`
+  --> $DIR/portable-intrinsics-arent-exposed.rs:5:5
    |
-LL |     pub use crate::core_simd::simd::*;
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | use std::simd::intrinsics;
+   |     ^^^^^^^^^^^^^^^^^^^^^ no `intrinsics` in `simd`
 
-error: aborting due to previous error
+error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0603`.
+Some errors have detailed explanations: E0432, E0433.
+For more information about an error, try `rustc --explain E0432`.