about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTrevor Gross <tmgross@umich.edu>2024-08-19 17:32:42 -0400
committerTrevor Gross <tmgross@umich.edu>2024-09-28 11:06:33 -0400
commit606d971958936c77245d77b0ebd0cf09a2d461c2 (patch)
treed201632170691cadeff9c110fc0bcfd5615ee885
parent2a32f80cdc060eb55eb2abd5a9dccc297fb31b9a (diff)
downloadrust-606d971958936c77245d77b0ebd0cf09a2d461c2.tar.gz
rust-606d971958936c77245d77b0ebd0cf09a2d461c2.zip
Add support for `f128` integer exponentiation
Create the symbol `__powitf2`.
-rw-r--r--library/compiler-builtins/README.md2
-rw-r--r--library/compiler-builtins/build.rs1
-rw-r--r--library/compiler-builtins/src/float/pow.rs9
-rw-r--r--library/compiler-builtins/testcrate/tests/float_pow.rs24
4 files changed, 31 insertions, 5 deletions
diff --git a/library/compiler-builtins/README.md b/library/compiler-builtins/README.md
index 06137f3c754..985020f5a8f 100644
--- a/library/compiler-builtins/README.md
+++ b/library/compiler-builtins/README.md
@@ -240,7 +240,7 @@ of being added to Rust.
 - [ ] floatunsitf.c
 - [ ] floatuntitf.c
 - [x] multf3.c
-- [ ] powitf2.c
+- [x] powitf2.c
 - [x] subtf3.c
 - [x] truncdfhf2.c
 - [x] truncsfhf2.c
diff --git a/library/compiler-builtins/build.rs b/library/compiler-builtins/build.rs
index 3b2805f8328..df98688d16a 100644
--- a/library/compiler-builtins/build.rs
+++ b/library/compiler-builtins/build.rs
@@ -526,7 +526,6 @@ mod c {
                 ("__floatsitf", "floatsitf.c"),
                 ("__floatunditf", "floatunditf.c"),
                 ("__floatunsitf", "floatunsitf.c"),
-                ("__powitf2", "powitf2.c"),
                 ("__fe_getround", "fp_mode.c"),
                 ("__fe_raise_inexact", "fp_mode.c"),
             ]);
diff --git a/library/compiler-builtins/src/float/pow.rs b/library/compiler-builtins/src/float/pow.rs
index 3103fe6f697..dac768f7be3 100644
--- a/library/compiler-builtins/src/float/pow.rs
+++ b/library/compiler-builtins/src/float/pow.rs
@@ -35,4 +35,13 @@ intrinsics! {
     pub extern "C" fn __powidf2(a: f64, b: i32) -> f64 {
         pow(a, b)
     }
+
+    #[avr_skip]
+    #[ppc_alias = __powikf2]
+    #[cfg(f128_enabled)]
+    // FIXME(f16_f128): MSVC cannot build these until `__divtf3` is available in nightly.
+    #[cfg(not(target_env = "msvc"))]
+    pub extern "C" fn __powitf2(a: f128, b: i32) -> f128 {
+        pow(a, b)
+    }
 }
diff --git a/library/compiler-builtins/testcrate/tests/float_pow.rs b/library/compiler-builtins/testcrate/tests/float_pow.rs
index 761a6611dda..d85ee99dfd3 100644
--- a/library/compiler-builtins/testcrate/tests/float_pow.rs
+++ b/library/compiler-builtins/testcrate/tests/float_pow.rs
@@ -1,4 +1,5 @@
 #![allow(unused_macros)]
+#![cfg_attr(f128_enabled, feature(f128))]
 #![cfg(not(all(target_arch = "x86", not(target_feature = "sse"))))]
 
 use testcrate::*;
@@ -7,9 +8,12 @@ use testcrate::*;
 // https://github.com/rust-lang/rust/issues/73920.
 // TODO how do we resolve this indeterminacy?
 macro_rules! pow {
-    ($($f:ty, $tolerance:expr, $fn:ident);*;) => {
+    ($($f:ty, $tolerance:expr, $fn:ident, $sys_available:meta);*;) => {
         $(
             #[test]
+            // FIXME(apfloat): We skip tests if system symbols aren't available rather
+            // than providing a fallback, since `rustc_apfloat` does not provide `pow`.
+            #[cfg($sys_available)]
             fn $fn() {
                 use compiler_builtins::float::pow::$fn;
                 use compiler_builtins::float::Float;
@@ -49,6 +53,20 @@ macro_rules! pow {
 }
 
 pow! {
-    f32, 1e-4, __powisf2;
-    f64, 1e-12, __powidf2;
+    f32, 1e-4, __powisf2, all();
+    f64, 1e-12, __powidf2, all();
+}
+
+#[cfg(f128_enabled)]
+// FIXME(f16_f128): MSVC cannot build these until `__divtf3` is available in nightly.
+#[cfg(not(target_env = "msvc"))]
+#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
+pow! {
+    f128, 1e-36, __powitf2, not(feature = "no-sys-f128");
+}
+
+#[cfg(f128_enabled)]
+#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
+pow! {
+    f128, 1e-36, __powikf2, not(feature = "no-sys-f128");
 }