Skip to content

Commit 34db533

Browse files
committed
Add implementations for f128 addition and subtraction
1 parent 798d46f commit 34db533

File tree

7 files changed

+44
-8
lines changed

7 files changed

+44
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ These builtins are needed to support 128-bit integers.
232232

233233
These builtins are needed to support `f16` and `f128`, which are in the process of being added to Rust.
234234

235-
- [ ] addtf3.c
235+
- [x] addtf3.c
236236
- [ ] comparetf2.c
237237
- [ ] divtf3.c
238238
- [x] extenddftf2.c
@@ -255,7 +255,7 @@ These builtins are needed to support `f16` and `f128`, which are in the process
255255
- [ ] ppc/fixunstfdi.c
256256
- [ ] ppc/floatditf.c
257257
- [ ] ppc/floatunditf.c
258-
- [ ] subtf3.c
258+
- [x] subtf3.c
259259
- [x] truncdfhf2.c
260260
- [x] truncsfhf2.c
261261
- [x] trunctfdf2.c

build.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,7 @@ mod c {
479479
("__floatsitf", "floatsitf.c"),
480480
("__floatunditf", "floatunditf.c"),
481481
("__floatunsitf", "floatunsitf.c"),
482-
("__addtf3", "addtf3.c"),
483482
("__multf3", "multf3.c"),
484-
("__subtf3", "subtf3.c"),
485483
("__divtf3", "divtf3.c"),
486484
("__powitf2", "powitf2.c"),
487485
("__fe_getround", "fp_mode.c"),
@@ -500,9 +498,7 @@ mod c {
500498
if target_arch == "mips64" {
501499
sources.extend(&[
502500
("__netf2", "comparetf2.c"),
503-
("__addtf3", "addtf3.c"),
504501
("__multf3", "multf3.c"),
505-
("__subtf3", "subtf3.c"),
506502
("__fixtfsi", "fixtfsi.c"),
507503
("__floatsitf", "floatsitf.c"),
508504
("__fixunstfsi", "fixunstfsi.c"),
@@ -515,9 +511,7 @@ mod c {
515511
if target_arch == "loongarch64" {
516512
sources.extend(&[
517513
("__netf2", "comparetf2.c"),
518-
("__addtf3", "addtf3.c"),
519514
("__multf3", "multf3.c"),
520-
("__subtf3", "subtf3.c"),
521515
("__fixtfsi", "fixtfsi.c"),
522516
("__floatsitf", "floatsitf.c"),
523517
("__fixunstfsi", "fixunstfsi.c"),

src/float/add.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ intrinsics! {
203203
add(a, b)
204204
}
205205

206+
#[cfg(not(feature = "no-f16-f128"))]
207+
pub extern "C" fn __addtf3(a: f128, b: f128) -> f128 {
208+
add(a, b)
209+
}
210+
206211
#[cfg(target_arch = "arm")]
207212
pub extern "C" fn __addsf3vfp(a: f32, b: f32) -> f32 {
208213
a + b

src/float/sub.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ intrinsics! {
1515
__adddf3(a, f64::from_repr(b.repr() ^ f64::SIGN_MASK))
1616
}
1717

18+
#[cfg(not(feature = "no-f16-f128"))]
19+
pub extern "C" fn __subtf3(a: f128, b: f128) -> f128 {
20+
use crate::float::add::__addtf3;
21+
__addtf3(a, f128::from_repr(b.repr() ^ f128::SIGN_MASK))
22+
}
23+
1824
#[cfg(target_arch = "arm")]
1925
pub extern "C" fn __subsf3vfp(a: f32, b: f32) -> f32 {
2026
a - b

testcrate/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ no-asm = ["compiler_builtins/no-asm"]
3333
no-f16-f128 = ["compiler_builtins/no-f16-f128"]
3434
mem = ["compiler_builtins/mem"]
3535
mangled-names = ["compiler_builtins/mangled-names"]
36+
# Skip tests that rely on f128 symbols being available on the system
37+
no-sys-f128 = []

testcrate/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use std::env;
2+
3+
fn main() {
4+
let target = env::var("TARGET").unwrap();
5+
6+
// These platforms do not have f128 symbols available in their system libraries, so
7+
// skip related tests.
8+
if target.starts_with("arm-")
9+
|| target.contains("apple-darwin")
10+
|| target.contains("windows-msvc")
11+
// FIXME(llvm): There is an ABI incompatibility between GCC and Clang on 32-bit x86.
12+
// See <https://github.com/llvm/llvm-project/issues/77401>.
13+
|| target.starts_with("i686")
14+
{
15+
println!("cargo:warning=using apfloat fallback for f128");
16+
println!("cargo:rustc-cfg=feature=\"no-sys-f128\"");
17+
}
18+
}

testcrate/tests/addsub.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![allow(unused_macros)]
2+
#![feature(f128)]
3+
#![feature(f16)]
24

35
use core::ops::{Add, Sub};
46
use testcrate::*;
@@ -109,6 +111,15 @@ fn float_addsub() {
109111
f32, __addsf3, __subsf3, Single, all();
110112
f64, __adddf3, __subdf3, Double, all();
111113
);
114+
115+
#[cfg(not(feature = "no-f16-f128"))]
116+
{
117+
use compiler_builtins::float::{add::__addtf3, sub::__subtf3, Float};
118+
119+
float_sum!(
120+
f128, __addtf3, __subtf3, Quad, not(feature = "no-sys-f128");
121+
);
122+
}
112123
}
113124

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

0 commit comments

Comments
 (0)