Skip to content

Commit 642d082

Browse files
committed
Add float to integer conversion functions for f128
1 parent db5f678 commit 642d082

File tree

6 files changed

+88
-20
lines changed

6 files changed

+88
-20
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,12 @@ These builtins are needed to support `f16` and `f128`, which are in the process
239239
- [x] extendhfsf2.c
240240
- [x] extendhftf2.c
241241
- [x] extendsftf2.c
242-
- [ ] fixtfdi.c
243-
- [ ] fixtfsi.c
244-
- [ ] fixtfti.c
245-
- [ ] fixunstfdi.c
246-
- [ ] fixunstfsi.c
247-
- [ ] fixunstfti.c
242+
- [x] fixtfdi.c
243+
- [x] fixtfsi.c
244+
- [x] fixtfti.c
245+
- [x] fixunstfdi.c
246+
- [x] fixunstfsi.c
247+
- [x] fixunstfti.c
248248
- [ ] floatditf.c
249249
- [ ] floatsitf.c
250250
- [ ] floatunditf.c

build.rs

-10
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,6 @@ mod c {
533533
if (target_arch == "aarch64" || target_arch == "arm64ec") && consider_float_intrinsics {
534534
sources.extend(&[
535535
("__comparetf2", "comparetf2.c"),
536-
("__fixtfdi", "fixtfdi.c"),
537-
("__fixtfsi", "fixtfsi.c"),
538-
("__fixtfti", "fixtfti.c"),
539-
("__fixunstfdi", "fixunstfdi.c"),
540-
("__fixunstfsi", "fixunstfsi.c"),
541-
("__fixunstfti", "fixunstfti.c"),
542536
("__floatditf", "floatditf.c"),
543537
("__floatsitf", "floatsitf.c"),
544538
("__floatunditf", "floatunditf.c"),
@@ -561,9 +555,7 @@ mod c {
561555
if target_arch == "mips64" {
562556
sources.extend(&[
563557
("__netf2", "comparetf2.c"),
564-
("__fixtfsi", "fixtfsi.c"),
565558
("__floatsitf", "floatsitf.c"),
566-
("__fixunstfsi", "fixunstfsi.c"),
567559
("__floatunsitf", "floatunsitf.c"),
568560
("__fe_getround", "fp_mode.c"),
569561
]);
@@ -572,9 +564,7 @@ mod c {
572564
if target_arch == "loongarch64" {
573565
sources.extend(&[
574566
("__netf2", "comparetf2.c"),
575-
("__fixtfsi", "fixtfsi.c"),
576567
("__floatsitf", "floatsitf.c"),
577-
("__fixunstfsi", "fixunstfsi.c"),
578568
("__floatunsitf", "floatunsitf.c"),
579569
("__fe_getround", "fp_mode.c"),
580570
]);

src/float/conv.rs

+30
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,21 @@ intrinsics! {
261261
pub extern "C" fn __fixunsdfti(f: f64) -> u128 {
262262
float_to_unsigned_int(f)
263263
}
264+
265+
#[cfg(not(feature = "no-f16-f128"))]
266+
pub extern "C" fn __fixunstfsi(f: f128) -> u32 {
267+
float_to_unsigned_int(f)
268+
}
269+
270+
#[cfg(not(feature = "no-f16-f128"))]
271+
pub extern "C" fn __fixunstfdi(f: f128) -> u64 {
272+
float_to_unsigned_int(f)
273+
}
274+
275+
#[cfg(not(feature = "no-f16-f128"))]
276+
pub extern "C" fn __fixunstfti(f: f128) -> u128 {
277+
float_to_unsigned_int(f)
278+
}
264279
}
265280

266281
// Conversions from floats to signed integers.
@@ -294,4 +309,19 @@ intrinsics! {
294309
pub extern "C" fn __fixdfti(f: f64) -> i128 {
295310
float_to_signed_int(f)
296311
}
312+
313+
#[cfg(not(feature = "no-f16-f128"))]
314+
pub extern "C" fn __fixtfsi(f: f128) -> i32 {
315+
float_to_signed_int(f)
316+
}
317+
318+
#[cfg(not(feature = "no-f16-f128"))]
319+
pub extern "C" fn __fixtfdi(f: f128) -> i64 {
320+
float_to_signed_int(f)
321+
}
322+
323+
#[cfg(not(feature = "no-f16-f128"))]
324+
pub extern "C" fn __fixtfti(f: f128) -> i128 {
325+
float_to_signed_int(f)
326+
}
297327
}

testcrate/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ no-f16-f128 = ["compiler_builtins/no-f16-f128"]
3434
mem = ["compiler_builtins/mem"]
3535
mangled-names = ["compiler_builtins/mangled-names"]
3636
# Skip tests that rely on f128 symbols being available on the system
37-
no-sys-f128 = []
37+
no-sys-f128 = ["no-sys-f128-int-convert"]
38+
# Some platforms have some f128 functions but everything except integer conversions
39+
no-sys-f128-int-convert = []

testcrate/build.rs

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
use std::env;
1+
use std::{collections::HashSet, env};
2+
3+
/// Features to enable
4+
#[derive(Debug, PartialEq, Eq, Hash)]
5+
enum Feature {
6+
NoSysF128,
7+
NoSysF128IntConvert,
8+
}
29

310
fn main() {
411
let target = env::var("TARGET").unwrap();
12+
let mut features = HashSet::new();
513

614
// These platforms do not have f128 symbols available in their system libraries, so
715
// skip related tests.
@@ -21,7 +29,23 @@ fn main() {
2129
// <https://github.com/rust-lang/compiler-builtins/pull/606#issuecomment-2105657287>.
2230
|| target.starts_with("powerpc64-")
2331
{
24-
println!("cargo:warning=using apfloat fallback for f128");
25-
println!("cargo:rustc-cfg=feature=\"no-sys-f128\"");
32+
features.insert(Feature::NoSysF128);
33+
features.insert(Feature::NoSysF128IntConvert);
34+
}
35+
36+
if target.starts_with("i586") {
37+
features.insert(Feature::NoSysF128IntConvert);
38+
}
39+
40+
for feature in features {
41+
let (name, warning) = match feature {
42+
Feature::NoSysF128 => ("no-sys-f128", "using apfloat fallback for f128"),
43+
Feature::NoSysF128IntConvert => (
44+
"no-sys-f128-int-convert",
45+
"using apfloat fallback for f128 to int conversions",
46+
),
47+
};
48+
println!("cargo:warning={warning}");
49+
println!("cargo:rustc-cfg=feature=\"{name}\"");
2650
}
2751
}

testcrate/tests/conv.rs

+22
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,28 @@ fn float_to_int() {
166166
i128, __fixdfti;
167167
);
168168
});
169+
170+
#[cfg(not(feature = "no-f16-f128"))]
171+
{
172+
use compiler_builtins::float::conv::{
173+
__fixtfdi, __fixtfsi, __fixtfti, __fixunstfdi, __fixunstfsi, __fixunstfti,
174+
};
175+
176+
fuzz_float(N, |x: f128| {
177+
f_to_i!(
178+
x,
179+
f128,
180+
Quad,
181+
not(feature = "no-sys-f128-int-convert"),
182+
u32, __fixunstfsi;
183+
u64, __fixunstfdi;
184+
u128, __fixunstfti;
185+
i32, __fixtfsi;
186+
i64, __fixtfdi;
187+
i128, __fixtfti;
188+
);
189+
});
190+
}
169191
}
170192

171193
macro_rules! conv {

0 commit comments

Comments
 (0)