Skip to content

Commit 241b9a8

Browse files
committed
Add support for f128 integer exponentiation
Adds `__powitf2`
1 parent 1f701b0 commit 241b9a8

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ These builtins are needed to support `f16` and `f128`, which are in the process
250250
- [ ] floatunditf.c
251251
- [ ] floatunsitf.c
252252
- [x] multf3.c
253-
- [ ] powitf2.c
253+
- [x] powitf2.c
254254
- [ ] ppc/fixtfdi.c
255255
- [ ] ppc/fixunstfdi.c
256256
- [ ] ppc/floatditf.c

build.rs

-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ mod c {
538538
("__floatunditf", "floatunditf.c"),
539539
("__floatunsitf", "floatunsitf.c"),
540540
("__divtf3", "divtf3.c"),
541-
("__powitf2", "powitf2.c"),
542541
("__fe_getround", "fp_mode.c"),
543542
("__fe_raise_inexact", "fp_mode.c"),
544543
]);

src/float/pow.rs

+12
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,16 @@ intrinsics! {
3535
pub extern "C" fn __powidf2(a: f64, b: i32) -> f64 {
3636
pow(a, b)
3737
}
38+
39+
#[avr_skip]
40+
#[cfg(not(any(feature = "no-f16-f128", target_arch = "powerpc", target_arch = "powerpc64")))]
41+
pub extern "C" fn __powitf2(a: f128, b: i32) -> f128 {
42+
pow(a, b)
43+
}
44+
45+
#[avr_skip]
46+
#[cfg(all(not(feature = "no-f16-f128"), any(target_arch = "powerpc", target_arch = "powerpc64")))]
47+
pub extern "C" fn __powikf2(a: f128, b: i32) -> f128 {
48+
pow(a, b)
49+
}
3850
}

testcrate/tests/misc.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// makes configuration easier
22
#![allow(unused_macros)]
3+
#![feature(f128)]
34

45
use testcrate::*;
56

@@ -122,12 +123,15 @@ macro_rules! pow {
122123
b < $tolerance
123124
} else {
124125
let quo = b / a;
125-
(quo < (1. + $tolerance)) && (quo > (1. - $tolerance))
126+
// FIXME(f16_f128): we do this to block const eval which currently
127+
// ICEs on f128. Change this once it works correctly.
128+
(quo < (1. + black_box($tolerance)))
129+
&& (quo > (1. - black_box($tolerance)))
126130
}
127131
};
128132
if !good {
129133
panic!(
130-
"{}({}, {}): std: {}, builtins: {}",
134+
"{}({:?}, {:?}): std: {:?}, builtins: {:?}",
131135
stringify!($fn), x, n, tmp0, tmp1
132136
);
133137
}
@@ -142,8 +146,32 @@ macro_rules! pow {
142146
mod float_pow {
143147
use super::*;
144148

149+
fn black_box<T>(val: T) -> T {
150+
val
151+
}
152+
145153
pow! {
146154
f32, 1e-4, __powisf2;
147155
f64, 1e-12, __powidf2;
148156
}
149157
}
158+
159+
#[cfg(not(all(target_arch = "x86", not(target_feature = "sse"))))]
160+
#[cfg(not(any(feature = "no-f16-f128", feature = "no-sys-f128")))]
161+
mod float_pow_f128 {
162+
use super::*;
163+
use core::hint::black_box;
164+
165+
// Windows can't link the required arithmetic functions. See
166+
// <https://github.com/rust-lang/compiler-builtins/pull/614#issuecomment-2118636613>
167+
#[cfg(not(target_family = "windows"))]
168+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
169+
pow! {
170+
f128, 1e-36, __powitf2;
171+
}
172+
173+
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
174+
pow! {
175+
f128, 1e-36, __powikf2;
176+
}
177+
}

0 commit comments

Comments
 (0)