Skip to content

Commit fbf79c0

Browse files
committed
Add support for f128 integer exponentiation
Adds `__powitf2`
1 parent d96d3a7 commit fbf79c0

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
@@ -274,7 +274,7 @@ of being added to Rust.
274274
- [ ] floatunsitf.c
275275
- [ ] floatuntitf.c
276276
- [x] multf3.c
277-
- [ ] powitf2.c
277+
- [x] powitf2.c
278278
- [x] subtf3.c
279279
- [x] truncdfhf2.c
280280
- [x] truncsfhf2.c

build.rs

-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,6 @@ mod c {
527527
("__floatunditf", "floatunditf.c"),
528528
("__floatunsitf", "floatunsitf.c"),
529529
("__divtf3", "divtf3.c"),
530-
("__powitf2", "powitf2.c"),
531530
("__fe_getround", "fp_mode.c"),
532531
("__fe_raise_inexact", "fp_mode.c"),
533532
]);

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

@@ -238,12 +239,15 @@ macro_rules! pow {
238239
b < $tolerance
239240
} else {
240241
let quo = b / a;
241-
(quo < (1. + $tolerance)) && (quo > (1. - $tolerance))
242+
// FIXME(f16_f128): we do this to block const eval which currently
243+
// ICEs on f128. Change this once it works correctly.
244+
(quo < (1. + black_box($tolerance)))
245+
&& (quo > (1. - black_box($tolerance)))
242246
}
243247
};
244248
if !good {
245249
panic!(
246-
"{}({}, {}): std: {}, builtins: {}",
250+
"{}({:?}, {:?}): std: {:?}, builtins: {:?}",
247251
stringify!($fn), x, n, tmp0, tmp1
248252
);
249253
}
@@ -258,8 +262,32 @@ macro_rules! pow {
258262
mod float_pow {
259263
use super::*;
260264

265+
fn black_box<T>(val: T) -> T {
266+
val
267+
}
268+
261269
pow! {
262270
f32, 1e-4, __powisf2;
263271
f64, 1e-12, __powidf2;
264272
}
265273
}
274+
275+
#[cfg(not(all(target_arch = "x86", not(target_feature = "sse"))))]
276+
#[cfg(not(any(feature = "no-f16-f128", feature = "no-sys-f128")))]
277+
mod float_pow_f128 {
278+
use super::*;
279+
use core::hint::black_box;
280+
281+
// Windows can't link the required arithmetic functions. See
282+
// <https://github.com/rust-lang/compiler-builtins/pull/614#issuecomment-2118636613>
283+
#[cfg(not(target_family = "windows"))]
284+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
285+
pow! {
286+
f128, 1e-36, __powitf2;
287+
}
288+
289+
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
290+
pow! {
291+
f128, 1e-36, __powikf2;
292+
}
293+
}

0 commit comments

Comments
 (0)