mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-27 14:24:08 +00:00
Rollup merge of #68033 - ollie27:win_f32, r=dtolnay
Don't use f64 shims for f32 cmath functions on non 32-bit x86 MSVC These shims are only needed on 32-bit x86. Additionally since https://reviews.llvm.org/rL268875 LLVM handles adding the shims itself for the intrinsics.
This commit is contained in:
commit
c8125fb36a
@ -44,23 +44,7 @@ impl f32 {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn floor(self) -> f32 {
|
pub fn floor(self) -> f32 {
|
||||||
// On MSVC LLVM will lower many math intrinsics to a call to the
|
unsafe { intrinsics::floorf32(self) }
|
||||||
// corresponding function. On MSVC, however, many of these functions
|
|
||||||
// aren't actually available as symbols to call, but rather they are all
|
|
||||||
// `static inline` functions in header files. This means that from a C
|
|
||||||
// perspective it's "compatible", but not so much from an ABI
|
|
||||||
// perspective (which we're worried about).
|
|
||||||
//
|
|
||||||
// The inline header functions always just cast to a f64 and do their
|
|
||||||
// operation, so we do that here as well, but only for MSVC targets.
|
|
||||||
//
|
|
||||||
// Note that there are many MSVC-specific float operations which
|
|
||||||
// redirect to this comment, so `floorf` is just one case of a missing
|
|
||||||
// function on MSVC, but there are many others elsewhere.
|
|
||||||
#[cfg(target_env = "msvc")]
|
|
||||||
return (self as f64).floor() as f32;
|
|
||||||
#[cfg(not(target_env = "msvc"))]
|
|
||||||
return unsafe { intrinsics::floorf32(self) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the smallest integer greater than or equal to a number.
|
/// Returns the smallest integer greater than or equal to a number.
|
||||||
@ -78,11 +62,7 @@ impl f32 {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ceil(self) -> f32 {
|
pub fn ceil(self) -> f32 {
|
||||||
// see notes above in `floor`
|
unsafe { intrinsics::ceilf32(self) }
|
||||||
#[cfg(target_env = "msvc")]
|
|
||||||
return (self as f64).ceil() as f32;
|
|
||||||
#[cfg(not(target_env = "msvc"))]
|
|
||||||
return unsafe { intrinsics::ceilf32(self) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the nearest integer to a number. Round half-way cases away from
|
/// Returns the nearest integer to a number. Round half-way cases away from
|
||||||
@ -348,11 +328,7 @@ impl f32 {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn powf(self, n: f32) -> f32 {
|
pub fn powf(self, n: f32) -> f32 {
|
||||||
// see notes above in `floor`
|
unsafe { intrinsics::powf32(self, n) }
|
||||||
#[cfg(target_env = "msvc")]
|
|
||||||
return (self as f64).powf(n as f64) as f32;
|
|
||||||
#[cfg(not(target_env = "msvc"))]
|
|
||||||
return unsafe { intrinsics::powf32(self, n) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the square root of a number.
|
/// Returns the square root of a number.
|
||||||
@ -399,11 +375,7 @@ impl f32 {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn exp(self) -> f32 {
|
pub fn exp(self) -> f32 {
|
||||||
// see notes above in `floor`
|
unsafe { intrinsics::expf32(self) }
|
||||||
#[cfg(target_env = "msvc")]
|
|
||||||
return (self as f64).exp() as f32;
|
|
||||||
#[cfg(not(target_env = "msvc"))]
|
|
||||||
return unsafe { intrinsics::expf32(self) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `2^(self)`.
|
/// Returns `2^(self)`.
|
||||||
@ -447,11 +419,7 @@ impl f32 {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ln(self) -> f32 {
|
pub fn ln(self) -> f32 {
|
||||||
// see notes above in `floor`
|
unsafe { intrinsics::logf32(self) }
|
||||||
#[cfg(target_env = "msvc")]
|
|
||||||
return (self as f64).ln() as f32;
|
|
||||||
#[cfg(not(target_env = "msvc"))]
|
|
||||||
return unsafe { intrinsics::logf32(self) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the logarithm of the number with respect to an arbitrary base.
|
/// Returns the logarithm of the number with respect to an arbitrary base.
|
||||||
@ -521,11 +489,7 @@ impl f32 {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn log10(self) -> f32 {
|
pub fn log10(self) -> f32 {
|
||||||
// see notes above in `floor`
|
unsafe { intrinsics::log10f32(self) }
|
||||||
#[cfg(target_env = "msvc")]
|
|
||||||
return (self as f64).log10() as f32;
|
|
||||||
#[cfg(not(target_env = "msvc"))]
|
|
||||||
return unsafe { intrinsics::log10f32(self) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The positive difference of two numbers.
|
/// The positive difference of two numbers.
|
||||||
@ -625,11 +589,7 @@ impl f32 {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn sin(self) -> f32 {
|
pub fn sin(self) -> f32 {
|
||||||
// see notes in `core::f32::Float::floor`
|
unsafe { intrinsics::sinf32(self) }
|
||||||
#[cfg(target_env = "msvc")]
|
|
||||||
return (self as f64).sin() as f32;
|
|
||||||
#[cfg(not(target_env = "msvc"))]
|
|
||||||
return unsafe { intrinsics::sinf32(self) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the cosine of a number (in radians).
|
/// Computes the cosine of a number (in radians).
|
||||||
@ -649,11 +609,7 @@ impl f32 {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cos(self) -> f32 {
|
pub fn cos(self) -> f32 {
|
||||||
// see notes in `core::f32::Float::floor`
|
unsafe { intrinsics::cosf32(self) }
|
||||||
#[cfg(target_env = "msvc")]
|
|
||||||
return (self as f64).cos() as f32;
|
|
||||||
#[cfg(not(target_env = "msvc"))]
|
|
||||||
return unsafe { intrinsics::cosf32(self) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the tangent of a number (in radians).
|
/// Computes the tangent of a number (in radians).
|
||||||
|
@ -27,7 +27,7 @@ extern "C" {
|
|||||||
|
|
||||||
pub use self::shims::*;
|
pub use self::shims::*;
|
||||||
|
|
||||||
#[cfg(not(target_env = "msvc"))]
|
#[cfg(not(all(target_env = "msvc", target_arch = "x86")))]
|
||||||
mod shims {
|
mod shims {
|
||||||
use libc::c_float;
|
use libc::c_float;
|
||||||
|
|
||||||
@ -43,10 +43,10 @@ mod shims {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// On MSVC these functions aren't defined, so we just define shims which promote
|
// On 32-bit x86 MSVC these functions aren't defined, so we just define shims
|
||||||
// everything fo f64, perform the calculation, and then demote back to f32.
|
// which promote everything fo f64, perform the calculation, and then demote
|
||||||
// While not precisely correct should be "correct enough" for now.
|
// back to f32. While not precisely correct should be "correct enough" for now.
|
||||||
#[cfg(target_env = "msvc")]
|
#[cfg(all(target_env = "msvc", target_arch = "x86"))]
|
||||||
mod shims {
|
mod shims {
|
||||||
use libc::c_float;
|
use libc::c_float;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user