Skip to content

Commit

Permalink
Merge pull request #624 from tgross35/f128-int-to-float
Browse files Browse the repository at this point in the history
Add f128 int to float conversions
  • Loading branch information
tgross35 authored Oct 30, 2024
2 parents a81adbc + 02e939b commit 19b569d
Show file tree
Hide file tree
Showing 8 changed files with 563 additions and 169 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ of being added to Rust.
- [x] fixunstfdi.c
- [x] fixunstfsi.c
- [x] fixunstfti.c
- [ ] floatditf.c
- [ ] floatsitf.c
- [ ] floattitf.c
- [ ] floatunditf.c
- [ ] floatunsitf.c
- [ ] floatuntitf.c
- [x] floatditf.c
- [x] floatsitf.c
- [x] floattitf.c
- [x] floatunditf.c
- [x] floatunsitf.c
- [x] floatuntitf.c
- [x] multf3.c
- [x] powitf2.c
- [x] subtf3.c
Expand Down
18 changes: 2 additions & 16 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,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"),
("__fe_getround", "fp_mode.c"),
("__fe_raise_inexact", "fp_mode.c"),
]);
Expand All @@ -550,21 +546,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 @@ -264,14 +264,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 @@ -294,6 +298,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 @@ -314,6 +322,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 @@ -328,14 +348,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 @@ -358,6 +382,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 @@ -369,6 +397,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 @@ -466,6 +506,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

0 comments on commit 19b569d

Please sign in to comment.