Skip to content

Commit fc0051a

Browse files
committed
Add missing functions for f16 and f128
1 parent d8ab794 commit fc0051a

File tree

8 files changed

+74
-8
lines changed

8 files changed

+74
-8
lines changed

README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,22 @@ These builtins are needed to support 128-bit integers, which are in the process
213213
- [x] udivti3.c
214214
- [x] umodti3.c
215215

216+
These builtins are needed to support 16-bit floating point numbers, which are
217+
in the process of being added to Rust.
218+
219+
- [x] addtf3.c
220+
- [x] comparetf2.c
221+
- [x] divtf3.c
222+
- [x] multf3.c
223+
- [x] subtf3.c
224+
216225
## Unimplemented functions
217226

218-
These builtins involve floating-point types ("`f128`", "`f80`" and complex numbers) that are not supported by Rust.
227+
These builtins involve floating-point types ("`f80`" and complex numbers) that are not supported by Rust.
219228

220-
- ~~addtf3.c~~
221-
- ~~comparetf2.c~~
222229
- ~~divdc3.c~~
223230
- ~~divsc3.c~~
224231
- ~~divtc3.c~~
225-
- ~~divtf3.c~~
226232
- ~~divxc3.c~~
227233
- ~~extenddftf2.c~~
228234
- ~~extendsftf2.c~~
@@ -250,7 +256,6 @@ These builtins involve floating-point types ("`f128`", "`f80`" and complex numbe
250256
- ~~muldc3.c~~
251257
- ~~mulsc3.c~~
252258
- ~~multc3.c~~
253-
- ~~multf3.c~~
254259
- ~~mulxc3.c~~
255260
- ~~powitf2.c~~
256261
- ~~powixf2.c~~
@@ -264,7 +269,6 @@ These builtins involve floating-point types ("`f128`", "`f80`" and complex numbe
264269
- ~~ppc/gcc_qmul.c~~
265270
- ~~ppc/gcc_qsub.c~~
266271
- ~~ppc/multc3.c~~
267-
- ~~subtf3.c~~
268272
- ~~trunctfdf2.c~~
269273
- ~~trunctfsf2.c~~
270274
- ~~x86_64/floatdixf.c~~

src/float/add.rs

+4
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ intrinsics! {
201201
add(a, b)
202202
}
203203

204+
pub extern "C" fn __addtf3(a: f128, b: f128) -> f128 {
205+
add(a, b)
206+
}
207+
204208
#[cfg(target_arch = "arm")]
205209
pub extern "C" fn __addsf3vfp(a: f32, b: f32) -> f32 {
206210
a + b

src/float/cmp.rs

+35
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,41 @@ intrinsics! {
170170
pub extern "C" fn __gtdf2(a: f64, b: f64) -> i32 {
171171
cmp(a, b).to_ge_abi()
172172
}
173+
174+
#[avr_skip]
175+
pub extern "C" fn __letf2(a: f128, b: f128) -> i32 {
176+
cmp(a, b).to_le_abi()
177+
}
178+
179+
#[avr_skip]
180+
pub extern "C" fn __getf2(a: f128, b: f128) -> i32 {
181+
cmp(a, b).to_ge_abi()
182+
}
183+
184+
#[avr_skip]
185+
pub extern "C" fn __unordtf2(a: f128, b: f128) -> i32 {
186+
unord(a, b) as i32
187+
}
188+
189+
#[avr_skip]
190+
pub extern "C" fn __eqtf2(a: f128, b: f128) -> i32 {
191+
cmp(a, b).to_le_abi()
192+
}
193+
194+
#[avr_skip]
195+
pub extern "C" fn __lttf2(a: f128, b: f128) -> i32 {
196+
cmp(a, b).to_le_abi()
197+
}
198+
199+
#[avr_skip]
200+
pub extern "C" fn __netf2(a: f128, b: f128) -> i32 {
201+
cmp(a, b).to_le_abi()
202+
}
203+
204+
#[avr_skip]
205+
pub extern "C" fn __gttf2(a: f128, b: f128) -> i32 {
206+
cmp(a, b).to_ge_abi()
207+
}
173208
}
174209

175210
#[cfg(target_arch = "arm")]

src/float/div.rs

+9
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,15 @@ intrinsics! {
914914
div64(a, b)
915915
}
916916

917+
// TODO: how should `HInt` be handled?
918+
pub extern "C" fn __divtf3(a: f128, b: f128) -> f128 {
919+
if cfg!(target_pointer_width = "64") {
920+
div32(a, b)
921+
} else {
922+
div64(a, b)
923+
}
924+
}
925+
917926
#[cfg(target_arch = "arm")]
918927
pub extern "C" fn __divsf3vfp(a: f32, b: f32) -> f32 {
919928
a / b

src/float/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub(crate) trait Float:
5959
/// A mask for the significand
6060
const SIGNIFICAND_MASK: Self::Int;
6161

62-
// The implicit bit of the float format
62+
/// The implicit bit of the float format
6363
const IMPLICIT_BIT: Self::Int;
6464

6565
/// A mask for the exponent
@@ -171,5 +171,8 @@ macro_rules! float_impl {
171171
};
172172
}
173173

174+
// FIXME: there aren't any intrinsics for f16 that I know of, do we need this?
175+
float_impl!(f16, u16, i16, i16, 16, 10);
174176
float_impl!(f32, u32, i32, i16, 32, 23);
175177
float_impl!(f64, u64, i64, i16, 64, 52);
178+
float_impl!(f128, u128, i128, i16, 128, 112);

src/float/mul.rs

+4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ intrinsics! {
199199
mul(a, b)
200200
}
201201

202+
pub extern "C" fn __multf3(a: f128, b: f128) -> f128 {
203+
mul(a, b)
204+
}
205+
202206
#[cfg(target_arch = "arm")]
203207
pub extern "C" fn __mulsf3vfp(a: f32, b: f32) -> f32 {
204208
a * b

src/float/sub.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::float::add::__adddf3;
22
use crate::float::add::__addsf3;
3+
use crate::float::add::__addtf3;
34
use crate::float::Float;
45

56
intrinsics! {
@@ -15,6 +16,10 @@ intrinsics! {
1516
__adddf3(a, f64::from_repr(b.repr() ^ f64::SIGN_MASK))
1617
}
1718

19+
pub extern "C" fn __subtf3(a: f128, b: f128) -> f128 {
20+
__addtf3(a, f128::from_repr(b.repr() ^ f128::SIGN_MASK))
21+
}
22+
1823
#[cfg(target_arch = "arm")]
1924
pub extern "C" fn __subsf3vfp(a: f32, b: f32) -> f32 {
2025
a - b

src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
#![cfg_attr(not(feature = "no-asm"), feature(asm))]
33
#![feature(abi_unadjusted)]
44
#![feature(asm_experimental_arch)]
5+
#![feature(c_unwind)]
56
#![cfg_attr(not(feature = "no-asm"), feature(global_asm))]
67
#![feature(cfg_target_has_atomic)]
78
#![feature(compiler_builtins)]
89
#![feature(core_ffi_c)]
910
#![feature(core_intrinsics)]
11+
#![feature(f128)]
12+
#![feature(f16)]
1013
#![feature(inline_const)]
1114
#![feature(lang_items)]
1215
#![feature(linkage)]
1316
#![feature(naked_functions)]
1417
#![feature(repr_simd)]
15-
#![feature(c_unwind)]
1618
#![no_builtins]
1719
#![no_std]
1820
#![allow(unused_features)]

0 commit comments

Comments
 (0)