Skip to content

Commit 5bd703d

Browse files
committed
Implement f128 comparison
1 parent c99f5b6 commit 5bd703d

File tree

3 files changed

+124
-1
lines changed

3 files changed

+124
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ These builtins are needed to support 128-bit integers.
233233
These builtins are needed to support `f16` and `f128`, which are in the process of being added to Rust.
234234

235235
- [x] addtf3.c
236-
- [ ] comparetf2.c
236+
- [x] comparetf2.c
237237
- [ ] divtf3.c
238238
- [x] extenddftf2.c
239239
- [x] extendhfsf2.c

src/float/cmp.rs

+83
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,89 @@ intrinsics! {
172172
}
173173
}
174174

175+
#[cfg(not(any(
176+
feature = "no-f16-f128",
177+
target_arch = "powerpc",
178+
target_arch = "powerpc64"
179+
)))]
180+
intrinsics! {
181+
#[avr_skip]
182+
pub extern "C" fn __letf2(a: f128, b: f128) -> i32 {
183+
cmp(a, b).to_le_abi()
184+
}
185+
186+
#[avr_skip]
187+
pub extern "C" fn __getf2(a: f128, b: f128) -> i32 {
188+
cmp(a, b).to_ge_abi()
189+
}
190+
191+
#[avr_skip]
192+
pub extern "C" fn __unordtf2(a: f128, b: f128) -> i32 {
193+
unord(a, b) as i32
194+
}
195+
196+
#[avr_skip]
197+
pub extern "C" fn __eqtf2(a: f128, b: f128) -> i32 {
198+
cmp(a, b).to_le_abi()
199+
}
200+
201+
#[avr_skip]
202+
pub extern "C" fn __lttf2(a: f128, b: f128) -> i32 {
203+
cmp(a, b).to_le_abi()
204+
}
205+
206+
#[avr_skip]
207+
pub extern "C" fn __netf2(a: f128, b: f128) -> i32 {
208+
cmp(a, b).to_le_abi()
209+
}
210+
211+
#[avr_skip]
212+
pub extern "C" fn __gttf2(a: f128, b: f128) -> i32 {
213+
cmp(a, b).to_ge_abi()
214+
}
215+
}
216+
217+
#[cfg(all(
218+
not(feature = "no-f16-f128"),
219+
any(target_arch = "powerpc", target_arch = "powerpc64")
220+
))]
221+
intrinsics! {
222+
#[avr_skip]
223+
pub extern "C" fn __lekf2(a: f128, b: f128) -> i32 {
224+
cmp(a, b).to_le_abi()
225+
}
226+
227+
#[avr_skip]
228+
pub extern "C" fn __gekf2(a: f128, b: f128) -> i32 {
229+
cmp(a, b).to_ge_abi()
230+
}
231+
232+
#[avr_skip]
233+
pub extern "C" fn __unordkf2(a: f128, b: f128) -> i32 {
234+
unord(a, b) as i32
235+
}
236+
237+
#[avr_skip]
238+
pub extern "C" fn __eqkf2(a: f128, b: f128) -> i32 {
239+
cmp(a, b).to_le_abi()
240+
}
241+
242+
#[avr_skip]
243+
pub extern "C" fn __ltkf2(a: f128, b: f128) -> i32 {
244+
cmp(a, b).to_le_abi()
245+
}
246+
247+
#[avr_skip]
248+
pub extern "C" fn __nekf2(a: f128, b: f128) -> i32 {
249+
cmp(a, b).to_le_abi()
250+
}
251+
252+
#[avr_skip]
253+
pub extern "C" fn __gtkf2(a: f128, b: f128) -> i32 {
254+
cmp(a, b).to_ge_abi()
255+
}
256+
}
257+
175258
#[cfg(target_arch = "arm")]
176259
intrinsics! {
177260
pub extern "aapcs" fn __aeabi_fcmple(a: f32, b: f32) -> i32 {

testcrate/tests/cmp.rs

+40
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![allow(unused_macros)]
22
#![allow(unreachable_code)]
3+
#![feature(f128)]
4+
#![feature(f16)]
35

46
#[cfg(not(target_arch = "powerpc64"))]
57
use testcrate::*;
@@ -79,6 +81,44 @@ fn float_comparisons() {
7981
1, __nedf2;
8082
);
8183
});
84+
85+
#[cfg(not(feature = "no-f16-f128"))]
86+
{
87+
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
88+
use compiler_builtins::float::cmp::{
89+
__eqkf2 as __eqtf2, __gekf2 as __getf2, __gtkf2 as __gttf2, __lekf2 as __letf2,
90+
__ltkf2 as __lttf2, __nekf2 as __netf2, __unordkf2 as __unordtf2,
91+
};
92+
93+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
94+
use compiler_builtins::float::cmp::{
95+
__eqtf2, __getf2, __gttf2, __letf2, __lttf2, __netf2, __unordtf2,
96+
};
97+
98+
fuzz_float_2(N, |x: f128, y: f128| {
99+
let x_is_nan = apfloat_fallback!(
100+
f128, Quad, not(feature = "no-sys-f128"),
101+
|x: FloatTy| x.is_nan() => no_convert,
102+
x
103+
);
104+
let y_is_nan = apfloat_fallback!(
105+
f128, Quad, not(feature = "no-sys-f128"),
106+
|x: FloatTy| x.is_nan() => no_convert,
107+
y
108+
);
109+
110+
assert_eq!(__unordtf2(x, y) != 0, x_is_nan || y_is_nan);
111+
112+
cmp!(f128, x, y, Quad, not(feature = "no-sys-f128"),
113+
1, __lttf2;
114+
1, __letf2;
115+
1, __eqtf2;
116+
-1, __getf2;
117+
-1, __gttf2;
118+
1, __netf2;
119+
);
120+
});
121+
}
82122
}
83123

84124
macro_rules! cmp2 {

0 commit comments

Comments
 (0)