Skip to content

Commit 5309135

Browse files
committed
move pal cfgs in f32 and f64 to sys
1 parent 70fd012 commit 5309135

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

library/std/src/f32.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,7 @@ impl f32 {
470470
#[stable(feature = "rust1", since = "1.0.0")]
471471
#[inline]
472472
pub fn log2(self) -> f32 {
473-
#[cfg(target_os = "android")]
474-
return crate::sys::android::log2f32(self);
475-
#[cfg(not(target_os = "android"))]
476-
return unsafe { intrinsics::log2f32(self) };
473+
return crate::sys::log2f32(self);
477474
}
478475

479476
/// Returns the base 10 logarithm of the number.

library/std/src/f64.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,7 @@ impl f64 {
470470
#[stable(feature = "rust1", since = "1.0.0")]
471471
#[inline]
472472
pub fn log2(self) -> f64 {
473-
self.log_wrapper(|n| {
474-
#[cfg(target_os = "android")]
475-
return crate::sys::android::log2f64(n);
476-
#[cfg(not(target_os = "android"))]
477-
return unsafe { intrinsics::log2f64(n) };
478-
})
473+
self.log_wrapper(crate::sys::log2f64)
479474
}
480475

481476
/// Returns the base 10 logarithm of the number.
@@ -936,8 +931,8 @@ impl f64 {
936931
// of expected NaN).
937932
#[rustc_allow_incoherent_impl]
938933
fn log_wrapper<F: Fn(f64) -> f64>(self, log_fn: F) -> f64 {
939-
if !cfg!(any(target_os = "solaris", target_os = "illumos")) {
940-
log_fn(self)
934+
if let Some(result) = crate::sys::log_wrapper(self) {
935+
log_fn(result)
941936
} else if self.is_finite() {
942937
if self > 0.0 {
943938
log_fn(self)

library/std/src/sys/mod.rs

+29
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,32 @@ cfg_if::cfg_if! {
7676
pub mod c;
7777
}
7878
}
79+
80+
#[cfg(not(test))]
81+
cfg_if::cfg_if! {
82+
if #[cfg(target_os = "android")] {
83+
pub use crate::android::log2f32;
84+
pub use crate::android::log2f64;
85+
} else {
86+
pub fn log2f32(n: f32) -> f32 {
87+
unsafe { crate::intrinsics::log2f32(n) }
88+
}
89+
90+
pub fn log2f64(n: f64) -> f64 {
91+
unsafe { crate::intrinsics::log2f64(n) }
92+
}
93+
}
94+
}
95+
96+
#[cfg(not(test))]
97+
cfg_if::cfg_if! {
98+
if #[cfg(any(target_os = "solaris", target_os = "illumos"))] {
99+
pub fn log_wrapper(n: f64) -> Option<f64> {
100+
Some(n)
101+
}
102+
} else {
103+
pub fn log_wrapper(_n: f64) -> Option<f64> {
104+
None
105+
}
106+
}
107+
}

src/tools/tidy/src/pal.rs

-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ const EXCEPTION_PATHS: &[&str] = &[
5454
// FIXME: platform-specific code should be moved to `sys`
5555
"library/std/src/io/copy.rs",
5656
"library/std/src/io/stdio.rs",
57-
"library/std/src/f32.rs",
58-
"library/std/src/f64.rs",
5957
"library/std/src/path.rs",
6058
"library/std/src/sys_common", // Should only contain abstractions over platforms
6159
"library/std/src/net/test.rs", // Utility helpers for tests

0 commit comments

Comments
 (0)