Skip to content

Commit e96159e

Browse files
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.
1 parent cde7bdc commit e96159e

File tree

4 files changed

+57
-14
lines changed

4 files changed

+57
-14
lines changed

library/std/src/lib.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@
313313
#![feature(panic_internals)]
314314
#![feature(panic_unwind)]
315315
#![feature(pin_static_ref)]
316+
#![feature(platform_intrinsics)]
316317
#![feature(portable_simd)]
317318
#![feature(prelude_import)]
318319
#![feature(ptr_as_uninit)]
@@ -465,8 +466,6 @@ pub use core::pin;
465466
pub use core::ptr;
466467
#[stable(feature = "rust1", since = "1.0.0")]
467468
pub use core::result;
468-
#[unstable(feature = "portable_simd", issue = "86656")]
469-
pub use core::simd;
470469
#[unstable(feature = "async_stream", issue = "79024")]
471470
pub use core::stream;
472471
#[stable(feature = "i128", since = "1.26.0")]
@@ -513,6 +512,25 @@ pub mod time;
513512
#[unstable(feature = "once_cell", issue = "74465")]
514513
pub mod lazy;
515514

515+
// Pull in `std_float` crate into libstd. The contents of
516+
// `std_float` are in a different repository: rust-lang/portable-simd.
517+
#[path = "../../portable-simd/crates/std_float/src/lib.rs"]
518+
#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
519+
#[allow(rustdoc::bare_urls)]
520+
#[unstable(feature = "portable_simd", issue = "86656")]
521+
#[cfg(not(all(miri, doctest)))] // Miri does not support all SIMD intrinsics
522+
mod std_float;
523+
524+
#[cfg(not(all(miri, doctest)))] // Miri does not support all SIMD intrinsics
525+
#[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
526+
#[unstable(feature = "portable_simd", issue = "86656")]
527+
pub mod simd {
528+
#[doc(inline)]
529+
pub use crate::std_float::StdFloat;
530+
#[doc(inline)]
531+
pub use core::simd::*;
532+
}
533+
516534
#[stable(feature = "futures_api", since = "1.36.0")]
517535
pub mod task {
518536
//! Types and Traits for working with asynchronous tasks.
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// run-pass
2+
3+
// This is the converse of the other libm test.
4+
#![feature(portable_simd)]
5+
use std::simd::f32x4;
6+
use std::simd::StdFloat;
7+
8+
// For SIMD float ops, the LLIR version which is used to implement the portable
9+
// forms of them may become calls to math.h AKA libm. So, we can't guarantee
10+
// we can compile them for #![no_std] crates.
11+
//
12+
// However, we can expose some of these ops via an extension trait.
13+
fn main() {
14+
let x = f32x4::from_array([0.1, 0.5, 0.6, -1.5]);
15+
let x2 = x + x;
16+
let _xc = x.ceil();
17+
let _xf = x.floor();
18+
let _xr = x.round();
19+
let _xt = x.trunc();
20+
let _xfma = x.mul_add(x, x);
21+
let _xsqrt = x.sqrt();
22+
let _ = x2.abs() * x2;
23+
}

src/test/ui/simd/portable-intrinsics-arent-exposed.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// May not matter, since people can use them with a nightly feature.
22
// However this tests to guarantee they don't leak out via portable_simd,
33
// and thus don't accidentally get stabilized.
4-
use std::simd::intrinsics; //~ERROR E0603
4+
use core::simd::intrinsics; //~ERROR E0433
5+
use std::simd::intrinsics; //~ERROR E0432
56

67
fn main() {
78
()
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
error[E0603]: module `intrinsics` is private
2-
--> $DIR/portable-intrinsics-arent-exposed.rs:4:16
1+
error[E0433]: failed to resolve: maybe a missing crate `core`?
2+
--> $DIR/portable-intrinsics-arent-exposed.rs:4:5
33
|
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
4+
LL | use core::simd::intrinsics;
5+
| ^^^^ maybe a missing crate `core`?
6+
7+
error[E0432]: unresolved import `std::simd::intrinsics`
8+
--> $DIR/portable-intrinsics-arent-exposed.rs:5:5
99
|
10-
LL | pub use crate::core_simd::simd::*;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
10+
LL | use std::simd::intrinsics;
11+
| ^^^^^^^^^^^^^^^^^^^^^ no `intrinsics` in `simd`
1212

13-
error: aborting due to previous error
13+
error: aborting due to 2 previous errors
1414

15-
For more information about this error, try `rustc --explain E0603`.
15+
Some errors have detailed explanations: E0432, E0433.
16+
For more information about an error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)