-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96851fd
commit 854585f
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// FIXME: This module existing reflects a failure of the codegen backend to always legalize bitops. | ||
// LLVM should be taught how to always emit llvm.fcopysign for f{16,32,64,128} without needing this! | ||
|
||
// FIXME: delete when we move fabs to core and it reaches stable | ||
fn fabs_f32(f: f32) -> f32 { | ||
f32::from_bits(f.to_bits() & const { !(i32::MIN as u32) }) | ||
} | ||
|
||
// FIXME: delete when we move fabs to core and it reaches stable | ||
fn fabs_f64(f: f64) -> f64 { | ||
f64::from_bits(f.to_bits() & const { !(i64::MIN as u64) }) | ||
} | ||
|
||
// FIXME: delete when we move fabs to core and it reaches stable | ||
fn fabs_128(f: f128) -> f128 { | ||
f128::from_bits(f.to_bits() & const { !(i128::MIN as u128) }) | ||
} | ||
|
||
fn copysign_f32(magnitude: f32, sign: f32) -> f32 { | ||
let sign = fabs_f32(sign).to_bits() ^ sign.to_bits(); | ||
f32::from_bits(fabs_f32(magnitude).to_bits() | sign) | ||
} | ||
|
||
fn copysign_f64(magnitude: f64, sign: f64) -> f64 { | ||
let sign = fabs_f64(sign).to_bits() ^ sign.to_bits(); | ||
f64::from_bits(fabs_f64(magnitude).to_bits() | sign) | ||
} | ||
|
||
fn copysign_f128(magnitude: f128, sign: f128) -> f128 { | ||
let sign = fabs_128(sign).to_bits() ^ sign.to_bits(); | ||
f128::from_bits(fabs_128(magnitude).to_bits() | sign) | ||
} | ||
|
||
intrinsics! { | ||
#[cfg_attr(target_env = "msvc", link_name = "_fcopysign")] | ||
pub extern "C" fn fcopysign(magnitude: f32, sign: f32) -> f32 { | ||
copysign_f32(magnitude, sign) | ||
} | ||
|
||
#[cfg_attr(target_env = "msvc", link_name = "_copysign")] | ||
pub extern "C" fn copysign(magnitude: f64, sign: f64) -> f64 { | ||
copysign_f64(magnitude, sign) | ||
} | ||
|
||
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "powerpc", target_arch = "powerpc64")))] | ||
pub extern "C" fn copysignl(magnitude: f128, sign: f128) -> f128 { | ||
copysign_f128(magnitude, sign) | ||
} | ||
|
||
#[cfg(any(target_arch = "x86_64", target_arch = "x86_64", target_arch = "powerpc", target_arch = "powerpc64"))] | ||
pub extern "C" fn copysignf128(magnitude: f128, sign: f128) -> f128 { | ||
copysign_f128(magnitude, sign) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters