From c7bd2a565517664e1e7b67d2655e0381bc5d0f2b Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 21 May 2024 03:41:06 -0400 Subject: [PATCH] Add `ppc_alias` to the `intrinsics!` macro PowerPC platforms use `kf` rather than `tf` for `f128`. Add a way to alias this in the macro to make the code cleaner. This also fixes the names of `fixunstf*` and `fixtf*` on Power PC (`fixunskf*` and `fixkf*` are correct). --- library/compiler-builtins/src/float/add.rs | 8 +-- library/compiler-builtins/src/float/cmp.rs | 54 +++---------------- library/compiler-builtins/src/float/conv.rs | 6 +++ library/compiler-builtins/src/float/extend.rs | 21 ++------ library/compiler-builtins/src/float/mul.rs | 9 +--- library/compiler-builtins/src/float/sub.rs | 13 +++-- library/compiler-builtins/src/float/trunc.rs | 21 ++------ library/compiler-builtins/src/macros.rs | 33 ++++++++++++ .../compiler-builtins/testcrate/tests/conv.rs | 7 +++ 9 files changed, 70 insertions(+), 102 deletions(-) diff --git a/library/compiler-builtins/src/float/add.rs b/library/compiler-builtins/src/float/add.rs index fd151f77d8a0..7e8529f3e296 100644 --- a/library/compiler-builtins/src/float/add.rs +++ b/library/compiler-builtins/src/float/add.rs @@ -203,16 +203,12 @@ intrinsics! { add(a, b) } - #[cfg(not(any(feature = "no-f16-f128", target_arch = "powerpc", target_arch = "powerpc64")))] + #[ppc_alias = __addkf3] + #[cfg(not(feature = "no-f16-f128"))] pub extern "C" fn __addtf3(a: f128, b: f128) -> f128 { add(a, b) } - #[cfg(all(not(feature = "no-f16-f128"), any(target_arch = "powerpc", target_arch = "powerpc64")))] - pub extern "C" fn __addkf3(a: f128, b: f128) -> f128 { - add(a, b) - } - #[cfg(target_arch = "arm")] pub extern "C" fn __addsf3vfp(a: f32, b: f32) -> f32 { a + b diff --git a/library/compiler-builtins/src/float/cmp.rs b/library/compiler-builtins/src/float/cmp.rs index 44ebf6262ea4..5c431304c61e 100644 --- a/library/compiler-builtins/src/float/cmp.rs +++ b/library/compiler-builtins/src/float/cmp.rs @@ -172,89 +172,51 @@ intrinsics! { } } -#[cfg(not(any( - feature = "no-f16-f128", - target_arch = "powerpc", - target_arch = "powerpc64" -)))] +#[cfg(not(feature = "no-f16-f128",))] intrinsics! { #[avr_skip] + #[ppc_alias = __lekf2] pub extern "C" fn __letf2(a: f128, b: f128) -> i32 { cmp(a, b).to_le_abi() } #[avr_skip] + #[ppc_alias = __gekf2] pub extern "C" fn __getf2(a: f128, b: f128) -> i32 { cmp(a, b).to_ge_abi() } #[avr_skip] + #[ppc_alias = __unordkf2] pub extern "C" fn __unordtf2(a: f128, b: f128) -> i32 { unord(a, b) as i32 } #[avr_skip] + #[ppc_alias = __eqkf2] pub extern "C" fn __eqtf2(a: f128, b: f128) -> i32 { cmp(a, b).to_le_abi() } #[avr_skip] + #[ppc_alias = __ltkf2] pub extern "C" fn __lttf2(a: f128, b: f128) -> i32 { cmp(a, b).to_le_abi() } #[avr_skip] + #[ppc_alias = __nekf2] pub extern "C" fn __netf2(a: f128, b: f128) -> i32 { cmp(a, b).to_le_abi() } #[avr_skip] + #[ppc_alias = __gtkf2] pub extern "C" fn __gttf2(a: f128, b: f128) -> i32 { cmp(a, b).to_ge_abi() } } -#[cfg(all( - not(feature = "no-f16-f128"), - any(target_arch = "powerpc", target_arch = "powerpc64") -))] -intrinsics! { - #[avr_skip] - pub extern "C" fn __lekf2(a: f128, b: f128) -> i32 { - cmp(a, b).to_le_abi() - } - - #[avr_skip] - pub extern "C" fn __gekf2(a: f128, b: f128) -> i32 { - cmp(a, b).to_ge_abi() - } - - #[avr_skip] - pub extern "C" fn __unordkf2(a: f128, b: f128) -> i32 { - unord(a, b) as i32 - } - - #[avr_skip] - pub extern "C" fn __eqkf2(a: f128, b: f128) -> i32 { - cmp(a, b).to_le_abi() - } - - #[avr_skip] - pub extern "C" fn __ltkf2(a: f128, b: f128) -> i32 { - cmp(a, b).to_le_abi() - } - - #[avr_skip] - pub extern "C" fn __nekf2(a: f128, b: f128) -> i32 { - cmp(a, b).to_le_abi() - } - - #[avr_skip] - pub extern "C" fn __gtkf2(a: f128, b: f128) -> i32 { - cmp(a, b).to_ge_abi() - } -} - #[cfg(target_arch = "arm")] intrinsics! { pub extern "aapcs" fn __aeabi_fcmple(a: f32, b: f32) -> i32 { diff --git a/library/compiler-builtins/src/float/conv.rs b/library/compiler-builtins/src/float/conv.rs index a37206cdce60..52119f3e8006 100644 --- a/library/compiler-builtins/src/float/conv.rs +++ b/library/compiler-builtins/src/float/conv.rs @@ -262,16 +262,19 @@ intrinsics! { float_to_unsigned_int(f) } + #[ppc_alias = __fixunskfsi] #[cfg(not(feature = "no-f16-f128"))] pub extern "C" fn __fixunstfsi(f: f128) -> u32 { float_to_unsigned_int(f) } + #[ppc_alias = __fixunskfdi] #[cfg(not(feature = "no-f16-f128"))] pub extern "C" fn __fixunstfdi(f: f128) -> u64 { float_to_unsigned_int(f) } + #[ppc_alias = __fixunskfti] #[cfg(not(feature = "no-f16-f128"))] pub extern "C" fn __fixunstfti(f: f128) -> u128 { float_to_unsigned_int(f) @@ -310,16 +313,19 @@ intrinsics! { float_to_signed_int(f) } + #[ppc_alias = __fixkfsi] #[cfg(not(feature = "no-f16-f128"))] pub extern "C" fn __fixtfsi(f: f128) -> i32 { float_to_signed_int(f) } + #[ppc_alias = __fixkfdi] #[cfg(not(feature = "no-f16-f128"))] pub extern "C" fn __fixtfdi(f: f128) -> i64 { float_to_signed_int(f) } + #[ppc_alias = __fixkfti] #[cfg(not(feature = "no-f16-f128"))] pub extern "C" fn __fixtfti(f: f128) -> i128 { float_to_signed_int(f) diff --git a/library/compiler-builtins/src/float/extend.rs b/library/compiler-builtins/src/float/extend.rs index 12e5fc9e10f9..556048991334 100644 --- a/library/compiler-builtins/src/float/extend.rs +++ b/library/compiler-builtins/src/float/extend.rs @@ -100,37 +100,22 @@ intrinsics! { #[avr_skip] #[aapcs_on_arm] - #[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))] + #[ppc_alias = __extendhfkf2] pub extern "C" fn __extendhftf2(a: f16) -> f128 { extend(a) } - #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] - pub extern "C" fn __extendhfkf2(a: f16) -> f128 { - extend(a) - } - #[avr_skip] #[aapcs_on_arm] - #[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))] + #[ppc_alias = __extendsfkf2] pub extern "C" fn __extendsftf2(a: f32) -> f128 { extend(a) } - #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] - pub extern "C" fn __extendsfkf2(a: f32) -> f128 { - extend(a) - } - #[avr_skip] #[aapcs_on_arm] - #[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))] + #[ppc_alias = __extenddfkf2] pub extern "C" fn __extenddftf2(a: f64) -> f128 { extend(a) } - - #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] - pub extern "C" fn __extenddfkf2(a: f64) -> f128 { - extend(a) - } } diff --git a/library/compiler-builtins/src/float/mul.rs b/library/compiler-builtins/src/float/mul.rs index 9866b62804da..007cc09a498a 100644 --- a/library/compiler-builtins/src/float/mul.rs +++ b/library/compiler-builtins/src/float/mul.rs @@ -199,17 +199,12 @@ intrinsics! { mul(a, b) } - #[cfg(not(any(feature = "no-f16-f128", target_arch = "powerpc", target_arch = "powerpc64")))] + #[ppc_alias = __mulkf3] + #[cfg(not(feature = "no-f16-f128"))] pub extern "C" fn __multf3(a: f128, b: f128) -> f128 { mul(a, b) } - - #[cfg(all(not(feature = "no-f16-f128"), any(target_arch = "powerpc", target_arch = "powerpc64")))] - pub extern "C" fn __mulkf3(a: f128, b: f128) -> f128 { - mul(a, b) - } - #[cfg(target_arch = "arm")] pub extern "C" fn __mulsf3vfp(a: f32, b: f32) -> f32 { a * b diff --git a/library/compiler-builtins/src/float/sub.rs b/library/compiler-builtins/src/float/sub.rs index de33259d6406..1492679f6230 100644 --- a/library/compiler-builtins/src/float/sub.rs +++ b/library/compiler-builtins/src/float/sub.rs @@ -15,16 +15,15 @@ intrinsics! { __adddf3(a, f64::from_repr(b.repr() ^ f64::SIGN_MASK)) } - #[cfg(not(any(feature = "no-f16-f128", target_arch = "powerpc", target_arch = "powerpc64")))] + #[ppc_alias = __subkf3] + #[cfg(not(feature = "no-f16-f128"))] pub extern "C" fn __subtf3(a: f128, b: f128) -> f128 { + #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] + use crate::float::add::__addkf3 as __addtf3; + #[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))] use crate::float::add::__addtf3; - __addtf3(a, f128::from_repr(b.repr() ^ f128::SIGN_MASK)) - } - #[cfg(all(not(feature = "no-f16-f128"), any(target_arch = "powerpc", target_arch = "powerpc64")))] - pub extern "C" fn __subkf3(a: f128, b: f128) -> f128 { - use crate::float::add::__addkf3; - __addkf3(a, f128::from_repr(b.repr() ^ f128::SIGN_MASK)) + __addtf3(a, f128::from_repr(b.repr() ^ f128::SIGN_MASK)) } #[cfg(target_arch = "arm")] diff --git a/library/compiler-builtins/src/float/trunc.rs b/library/compiler-builtins/src/float/trunc.rs index 31351b5e9697..9aea6f91ebca 100644 --- a/library/compiler-builtins/src/float/trunc.rs +++ b/library/compiler-builtins/src/float/trunc.rs @@ -155,37 +155,22 @@ intrinsics! { #[avr_skip] #[aapcs_on_arm] - #[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))] + #[ppc_alias = __trunckfhf2] pub extern "C" fn __trunctfhf2(a: f128) -> f16 { trunc(a) } - #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] - pub extern "C" fn __trunckfhf2(a: f128) -> f16 { - trunc(a) - } - #[avr_skip] #[aapcs_on_arm] - #[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))] + #[ppc_alias = __trunckfsf2] pub extern "C" fn __trunctfsf2(a: f128) -> f32 { trunc(a) } - #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] - pub extern "C" fn __trunckfsf2(a: f128) -> f32 { - trunc(a) - } - #[avr_skip] #[aapcs_on_arm] - #[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))] + #[ppc_alias = __trunckfdf2] pub extern "C" fn __trunctfdf2(a: f128) -> f64 { trunc(a) } - - #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] - pub extern "C" fn __trunckfdf2(a: f128) -> f64 { - trunc(a) - } } diff --git a/library/compiler-builtins/src/macros.rs b/library/compiler-builtins/src/macros.rs index f762ef4da21d..f537c1a968f0 100644 --- a/library/compiler-builtins/src/macros.rs +++ b/library/compiler-builtins/src/macros.rs @@ -65,6 +65,9 @@ macro_rules! public_test_dep { /// it's a normal ABI elsewhere for returning a 128 bit integer. /// * `arm_aeabi_alias` - handles the "aliasing" of various intrinsics on ARM /// their otherwise typical names to other prefixed ones. +/// * `ppc_alias` - changes the name of the symbol on PowerPC platforms without +/// changing any other behavior. This is mostly for `f128`, which is `tf` on +/// most platforms but `kf` on PowerPC. macro_rules! intrinsics { () => (); @@ -320,6 +323,36 @@ macro_rules! intrinsics { intrinsics!($($rest)*); ); + // PowerPC usually uses `kf` rather than `tf` for `f128`. This is just an easy + // way to add an alias on those targets. + ( + #[ppc_alias = $alias:ident] + $(#[$($attr:tt)*])* + pub extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? { + $($body:tt)* + } + + $($rest:tt)* + ) => ( + #[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))] + intrinsics! { + $(#[$($attr)*])* + pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? { + $($body)* + } + } + + #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] + intrinsics! { + $(#[$($attr)*])* + pub extern $abi fn $alias( $($argname: $ty),* ) $(-> $ret)? { + $($body)* + } + } + + intrinsics!($($rest)*); + ); + // C mem* functions are only generated when the "mem" feature is enabled. ( #[mem_builtin] diff --git a/library/compiler-builtins/testcrate/tests/conv.rs b/library/compiler-builtins/testcrate/tests/conv.rs index f73b809d04fd..1425b49ce494 100644 --- a/library/compiler-builtins/testcrate/tests/conv.rs +++ b/library/compiler-builtins/testcrate/tests/conv.rs @@ -178,6 +178,13 @@ mod f_to_i { #[test] #[cfg(not(feature = "no-f16-f128"))] fn f128_to_int() { + #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] + use compiler_builtins::float::conv::{ + __fixkfdi as __fixtfdi, __fixkfsi as __fixtfsi, __fixkfti as __fixtfti, + __fixunskfdi as __fixunstfdi, __fixunskfsi as __fixunstfsi, + __fixunskfti as __fixunstfti, + }; + #[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))] use compiler_builtins::float::conv::{ __fixtfdi, __fixtfsi, __fixtfti, __fixunstfdi, __fixunstfsi, __fixunstfti, };