Implement f128 comparison

This commit is contained in:
Trevor Gross 2024-05-11 01:18:38 -05:00
parent 191c1b88cd
commit aaa5260748
3 changed files with 124 additions and 1 deletions

View file

@ -233,7 +233,7 @@ These builtins are needed to support 128-bit integers.
These builtins are needed to support `f16` and `f128`, which are in the process of being added to Rust.
- [x] addtf3.c
- [ ] comparetf2.c
- [x] comparetf2.c
- [ ] divtf3.c
- [x] extenddftf2.c
- [x] extendhfsf2.c

View file

@ -172,6 +172,89 @@ intrinsics! {
}
}
#[cfg(not(any(
feature = "no-f16-f128",
target_arch = "powerpc",
target_arch = "powerpc64"
)))]
intrinsics! {
#[avr_skip]
pub extern "C" fn __letf2(a: f128, b: f128) -> i32 {
cmp(a, b).to_le_abi()
}
#[avr_skip]
pub extern "C" fn __getf2(a: f128, b: f128) -> i32 {
cmp(a, b).to_ge_abi()
}
#[avr_skip]
pub extern "C" fn __unordtf2(a: f128, b: f128) -> i32 {
unord(a, b) as i32
}
#[avr_skip]
pub extern "C" fn __eqtf2(a: f128, b: f128) -> i32 {
cmp(a, b).to_le_abi()
}
#[avr_skip]
pub extern "C" fn __lttf2(a: f128, b: f128) -> i32 {
cmp(a, b).to_le_abi()
}
#[avr_skip]
pub extern "C" fn __netf2(a: f128, b: f128) -> i32 {
cmp(a, b).to_le_abi()
}
#[avr_skip]
pub extern "C" fn __gttf2(a: f128, b: f128) -> i32 {
cmp(a, b).to_ge_abi()
}
}
#[cfg(all(
not(feature = "no-f16-f128"),
any(target_arch = "powerpc", target_arch = "powerpc64")
))]
intrinsics! {
#[avr_skip]
pub extern "C" fn __lekf2(a: f128, b: f128) -> i32 {
cmp(a, b).to_le_abi()
}
#[avr_skip]
pub extern "C" fn __gekf2(a: f128, b: f128) -> i32 {
cmp(a, b).to_ge_abi()
}
#[avr_skip]
pub extern "C" fn __unordkf2(a: f128, b: f128) -> i32 {
unord(a, b) as i32
}
#[avr_skip]
pub extern "C" fn __eqkf2(a: f128, b: f128) -> i32 {
cmp(a, b).to_le_abi()
}
#[avr_skip]
pub extern "C" fn __ltkf2(a: f128, b: f128) -> i32 {
cmp(a, b).to_le_abi()
}
#[avr_skip]
pub extern "C" fn __nekf2(a: f128, b: f128) -> i32 {
cmp(a, b).to_le_abi()
}
#[avr_skip]
pub extern "C" fn __gtkf2(a: f128, b: f128) -> i32 {
cmp(a, b).to_ge_abi()
}
}
#[cfg(target_arch = "arm")]
intrinsics! {
pub extern "aapcs" fn __aeabi_fcmple(a: f32, b: f32) -> i32 {

View file

@ -1,5 +1,7 @@
#![allow(unused_macros)]
#![allow(unreachable_code)]
#![feature(f128)]
#![feature(f16)]
#[cfg(not(target_arch = "powerpc64"))]
use testcrate::*;
@ -79,6 +81,44 @@ fn float_comparisons() {
1, __nedf2;
);
});
#[cfg(not(feature = "no-f16-f128"))]
{
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
use compiler_builtins::float::cmp::{
__eqkf2 as __eqtf2, __gekf2 as __getf2, __gtkf2 as __gttf2, __lekf2 as __letf2,
__ltkf2 as __lttf2, __nekf2 as __netf2, __unordkf2 as __unordtf2,
};
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
use compiler_builtins::float::cmp::{
__eqtf2, __getf2, __gttf2, __letf2, __lttf2, __netf2, __unordtf2,
};
fuzz_float_2(N, |x: f128, y: f128| {
let x_is_nan = apfloat_fallback!(
f128, Quad, not(feature = "no-sys-f128"),
|x: FloatTy| x.is_nan() => no_convert,
x
);
let y_is_nan = apfloat_fallback!(
f128, Quad, not(feature = "no-sys-f128"),
|x: FloatTy| x.is_nan() => no_convert,
y
);
assert_eq!(__unordtf2(x, y) != 0, x_is_nan || y_is_nan);
cmp!(f128, x, y, Quad, not(feature = "no-sys-f128"),
1, __lttf2;
1, __letf2;
1, __eqtf2;
-1, __getf2;
-1, __gttf2;
1, __netf2;
);
});
}
}
macro_rules! cmp2 {