Skip to content

Commit

Permalink
Add support for f128 integer exponentiation
Browse files Browse the repository at this point in the history
Adds `__powitf2`
  • Loading branch information
tgross35 committed May 21, 2024
1 parent 1f701b0 commit 241b9a8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ These builtins are needed to support `f16` and `f128`, which are in the process
- [ ] floatunditf.c
- [ ] floatunsitf.c
- [x] multf3.c
- [ ] powitf2.c
- [x] powitf2.c
- [ ] ppc/fixtfdi.c
- [ ] ppc/fixunstfdi.c
- [ ] ppc/floatditf.c
Expand Down
1 change: 0 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ mod c {
("__floatunditf", "floatunditf.c"),
("__floatunsitf", "floatunsitf.c"),
("__divtf3", "divtf3.c"),
("__powitf2", "powitf2.c"),
("__fe_getround", "fp_mode.c"),
("__fe_raise_inexact", "fp_mode.c"),
]);
Expand Down
12 changes: 12 additions & 0 deletions src/float/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,16 @@ intrinsics! {
pub extern "C" fn __powidf2(a: f64, b: i32) -> f64 {
pow(a, b)
}

#[avr_skip]
#[cfg(not(any(feature = "no-f16-f128", target_arch = "powerpc", target_arch = "powerpc64")))]
pub extern "C" fn __powitf2(a: f128, b: i32) -> f128 {
pow(a, b)
}

#[avr_skip]
#[cfg(all(not(feature = "no-f16-f128"), any(target_arch = "powerpc", target_arch = "powerpc64")))]
pub extern "C" fn __powikf2(a: f128, b: i32) -> f128 {
pow(a, b)
}
}
32 changes: 30 additions & 2 deletions testcrate/tests/misc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// makes configuration easier
#![allow(unused_macros)]
#![feature(f128)]

use testcrate::*;

Expand Down Expand Up @@ -122,12 +123,15 @@ macro_rules! pow {
b < $tolerance
} else {
let quo = b / a;
(quo < (1. + $tolerance)) && (quo > (1. - $tolerance))
// FIXME(f16_f128): we do this to block const eval which currently
// ICEs on f128. Change this once it works correctly.
(quo < (1. + black_box($tolerance)))
&& (quo > (1. - black_box($tolerance)))
}
};
if !good {
panic!(
"{}({}, {}): std: {}, builtins: {}",
"{}({:?}, {:?}): std: {:?}, builtins: {:?}",
stringify!($fn), x, n, tmp0, tmp1
);
}
Expand All @@ -142,8 +146,32 @@ macro_rules! pow {
mod float_pow {
use super::*;

fn black_box<T>(val: T) -> T {
val
}

pow! {
f32, 1e-4, __powisf2;
f64, 1e-12, __powidf2;
}
}

#[cfg(not(all(target_arch = "x86", not(target_feature = "sse"))))]
#[cfg(not(any(feature = "no-f16-f128", feature = "no-sys-f128")))]
mod float_pow_f128 {
use super::*;
use core::hint::black_box;

// Windows can't link the required arithmetic functions. See
// <https://github.com/rust-lang/compiler-builtins/pull/614#issuecomment-2118636613>
#[cfg(not(target_family = "windows"))]
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
pow! {
f128, 1e-36, __powitf2;
}

#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
pow! {
f128, 1e-36, __powikf2;
}
}

0 comments on commit 241b9a8

Please sign in to comment.