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 18, 2024
1 parent 449643f commit 65841d8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 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 @@ -544,7 +544,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)
}
}
26 changes: 23 additions & 3 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 @@ -96,7 +97,7 @@ fn leading_zeros() {
// 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);* ;) => {
$(
fuzz_float_2(N, |x: $f, y: $f| {
if !(Float::is_subnormal(x) || Float::is_subnormal(y) || x.is_nan()) {
Expand All @@ -118,12 +119,12 @@ macro_rules! pow {
b < $tolerance
} else {
let quo = b / a;
(quo < (1. + $tolerance)) && (quo > (1. - $tolerance))
(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 @@ -139,8 +140,27 @@ fn float_pow() {
use compiler_builtins::float::pow::{__powidf2, __powisf2};
use compiler_builtins::float::Float;

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

pow!(
f32, 1e-4, __powisf2;
f64, 1e-12, __powidf2;
);

// There is no apfloat fallback for `powi` so we just skip these tests on these platforms
#[cfg(not(any(feature = "no-f16-f128", feature = "no-sys-f128")))]
{
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
use compiler_builtins::float::pow::__powikf2;
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
use compiler_builtins::float::pow::__powitf2;

// FIXME(f16_f128): we do this to block const eval which currently ICEs. Change this
// once it works correctly.
use core::hint::black_box;

pow!(f128, 1e-24, __powitf2;);
}
}

0 comments on commit 65841d8

Please sign in to comment.