Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add f128 int to float conversions #624

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,12 @@ These builtins are needed to support `f16` and `f128`, which are in the process
- [x] fixunstfdi.c
- [x] fixunstfsi.c
- [x] fixunstfti.c
- [ ] floatditf.c
- [ ] floatsitf.c
- [ ] floatunditf.c
- [ ] floatunsitf.c
- [x] floatditf.c
- [x] floatsitf.c
- [x] floattitf.c
- [x] floatunditf.c
- [x] floatunsitf.c
- [x] floatuntitf.c
- [x] multf3.c
- [ ] powitf2.c
- [ ] ppc/fixtfdi.c
Expand Down
18 changes: 2 additions & 16 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,6 @@ mod c {
if (target_arch == "aarch64" || target_arch == "arm64ec") && consider_float_intrinsics {
sources.extend(&[
("__comparetf2", "comparetf2.c"),
("__floatditf", "floatditf.c"),
("__floatsitf", "floatsitf.c"),
("__floatunditf", "floatunditf.c"),
("__floatunsitf", "floatunsitf.c"),
("__divtf3", "divtf3.c"),
("__powitf2", "powitf2.c"),
("__fe_getround", "fp_mode.c"),
Expand All @@ -545,21 +541,11 @@ mod c {
}

if target_arch == "mips64" {
sources.extend(&[
("__netf2", "comparetf2.c"),
("__floatsitf", "floatsitf.c"),
("__floatunsitf", "floatunsitf.c"),
("__fe_getround", "fp_mode.c"),
]);
sources.extend(&[("__netf2", "comparetf2.c"), ("__fe_getround", "fp_mode.c")]);
}

if target_arch == "loongarch64" {
sources.extend(&[
("__netf2", "comparetf2.c"),
("__floatsitf", "floatsitf.c"),
("__floatunsitf", "floatunsitf.c"),
("__fe_getround", "fp_mode.c"),
]);
sources.extend(&[("__netf2", "comparetf2.c"), ("__fe_getround", "fp_mode.c")]);
}

// Remove the assembly implementations that won't compile for the target
Expand Down
62 changes: 56 additions & 6 deletions examples/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,18 @@ mod intrinsics {

/* i32 operations */

// floatsisf
pub fn aeabi_i2f(x: i32) -> f32 {
x as f32
}

// floatsidf
pub fn aeabi_i2d(x: i32) -> f64 {
x as f64
}

// floatsisf
pub fn aeabi_i2f(x: i32) -> f32 {
x as f32
pub fn floatsitf(x: i32) -> f128 {
x as f128
}

pub fn aeabi_idiv(a: i32, b: i32) -> i32 {
Expand All @@ -292,6 +296,10 @@ mod intrinsics {
x as f64
}

pub fn floatditf(x: i64) -> f128 {
x as f128
}

pub fn mulodi4(a: i64, b: i64) -> i64 {
a * b
}
Expand All @@ -312,6 +320,18 @@ mod intrinsics {

/* i128 operations */

pub fn floattisf(x: i128) -> f32 {
x as f32
}

pub fn floattidf(x: i128) -> f64 {
x as f64
}

pub fn floattitf(x: i128) -> f128 {
x as f128
}

pub fn lshrti3(a: i128, b: usize) -> i128 {
a >> b
}
Expand All @@ -326,14 +346,18 @@ mod intrinsics {

/* u32 operations */

// floatunsisf
pub fn aeabi_ui2f(x: u32) -> f32 {
x as f32
}

// floatunsidf
pub fn aeabi_ui2d(x: u32) -> f64 {
x as f64
}

// floatunsisf
pub fn aeabi_ui2f(x: u32) -> f32 {
x as f32
pub fn floatunsitf(x: u32) -> f128 {
x as f128
}

pub fn aeabi_uidiv(a: u32, b: u32) -> u32 {
Expand All @@ -356,6 +380,10 @@ mod intrinsics {
x as f64
}

pub fn floatunditf(x: u64) -> f128 {
x as f128
}

// udivdi3
pub fn aeabi_uldivmod(a: u64, b: u64) -> u64 {
a * b
Expand All @@ -367,6 +395,18 @@ mod intrinsics {

/* u128 operations */

pub fn floatuntisf(x: u128) -> f32 {
x as f32
}

pub fn floatuntidf(x: u128) -> f64 {
x as f64
}

pub fn floatuntitf(x: u128) -> f128 {
x as f128
}

pub fn muloti4(a: u128, b: u128) -> Option<u128> {
a.checked_mul(b)
}
Expand Down Expand Up @@ -463,6 +503,16 @@ fn run() {
bb(fixunstfsi(bb(2.)));
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
bb(fixunstfti(bb(2.)));
bb(floatditf(bb(2)));
bb(floatsitf(bb(2)));
bb(floattidf(bb(2)));
bb(floattisf(bb(2)));
bb(floattitf(bb(2)));
bb(floatunditf(bb(2)));
bb(floatunsitf(bb(2)));
bb(floatuntidf(bb(2)));
bb(floatuntisf(bb(2)));
bb(floatuntitf(bb(2)));
bb(gttf(bb(2.), bb(2.)));
bb(lshrti3(bb(2), bb(2)));
bb(lttf(bb(2.), bb(2.)));
Expand Down
Loading
Loading