Skip to content

Commit d8643a5

Browse files
committed
Require target_has_atomic = "ptr" for runtime feature detection
The `feature_detect` module is currently being built on all targets, but the use of `AtomicU32` causes a problem if atomics are not available (such as with `bpfel-unknown-none`). Gate this module behind `target_has_atomic = "ptr"`. The below now completes successfully: cargo build -p compiler_builtins --target=bpfel-unknown-none -Z build-std=core Fixes: rust-lang#908
1 parent 1b1b2ed commit d8643a5

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

libm/src/math/arch/x86/detect.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
// Using runtime feature detection requires atomics. Currently there are no x86 targets
2+
// that support sse but not `AtomicPtr`.
3+
14
#[cfg(target_arch = "x86")]
25
use core::arch::x86::{__cpuid, __cpuid_count, _xgetbv, CpuidResult};
36
#[cfg(target_arch = "x86_64")]
47
use core::arch::x86_64::{__cpuid, __cpuid_count, _xgetbv, CpuidResult};
58

6-
use crate::support::{Flags, get_or_init_flags_cache};
9+
use crate::support::feature_detect::{Flags, get_or_init_flags_cache, unique_masks};
710

811
/// CPU features that get cached (doesn't correlate to anything on the CPU).
912
pub mod cpu_flags {
10-
use crate::support::unique_masks;
13+
use super::unique_masks;
1114

1215
unique_masks! {
1316
u32,

libm/src/math/arch/x86/fma.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use core::arch::asm;
44

55
use super::super::super::generic;
66
use super::detect::{cpu_flags, get_cpu_features};
7-
use crate::support::{Round, select_once};
7+
use crate::support::Round;
8+
use crate::support::feature_detect::select_once;
89

910
pub fn fma(x: f64, y: f64, z: f64) -> f64 {
1011
select_once! {

libm/src/math/support/feature_detect.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
//! Helpers for runtime target feature detection that are shared across architectures.
22
3+
// `AtomicU32` is preferred for a consistent size across targets.
4+
#[cfg(all(target_has_atomic = "ptr", not(target_has_atomic = "32")))]
5+
compile_error!("currently all targets that support `AtomicPtr` also support `AtomicU32`");
6+
37
use core::sync::atomic::{AtomicU32, Ordering};
48

59
/// Given a list of identifiers, assign each one a unique sequential single-bit mask.

libm/src/math/support/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
pub mod macros;
33
mod big;
44
mod env;
5-
mod feature_detect;
5+
// Runtime feature detection requires atomics.
6+
#[cfg(target_has_atomic = "ptr")]
7+
pub(crate) mod feature_detect;
68
mod float_traits;
79
pub mod hex_float;
810
mod int_traits;
@@ -11,8 +13,6 @@ mod int_traits;
1113
pub use big::{i256, u256};
1214
pub use env::{FpResult, Round, Status};
1315
#[allow(unused_imports)]
14-
pub(crate) use feature_detect::{Flags, get_or_init_flags_cache, select_once, unique_masks};
15-
#[allow(unused_imports)]
1616
pub use float_traits::{DFloat, Float, HFloat, IntTy};
1717
pub(crate) use float_traits::{f32_from_bits, f64_from_bits};
1818
#[cfg(f16_enabled)]

0 commit comments

Comments
 (0)