Skip to content

Commit 19b569d

Browse files
authored
Merge pull request #624 from tgross35/f128-int-to-float
Add f128 int to float conversions
2 parents a81adbc + 02e939b commit 19b569d

File tree

8 files changed

+563
-169
lines changed

8 files changed

+563
-169
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ of being added to Rust.
233233
- [x] fixunstfdi.c
234234
- [x] fixunstfsi.c
235235
- [x] fixunstfti.c
236-
- [ ] floatditf.c
237-
- [ ] floatsitf.c
238-
- [ ] floattitf.c
239-
- [ ] floatunditf.c
240-
- [ ] floatunsitf.c
241-
- [ ] floatuntitf.c
236+
- [x] floatditf.c
237+
- [x] floatsitf.c
238+
- [x] floattitf.c
239+
- [x] floatunditf.c
240+
- [x] floatunsitf.c
241+
- [x] floatuntitf.c
242242
- [x] multf3.c
243243
- [x] powitf2.c
244244
- [x] subtf3.c

build.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,6 @@ mod c {
532532
if (target.arch == "aarch64" || target.arch == "arm64ec") && consider_float_intrinsics {
533533
sources.extend(&[
534534
("__comparetf2", "comparetf2.c"),
535-
("__floatditf", "floatditf.c"),
536-
("__floatsitf", "floatsitf.c"),
537-
("__floatunditf", "floatunditf.c"),
538-
("__floatunsitf", "floatunsitf.c"),
539535
("__fe_getround", "fp_mode.c"),
540536
("__fe_raise_inexact", "fp_mode.c"),
541537
]);
@@ -550,21 +546,11 @@ mod c {
550546
}
551547

552548
if target.arch == "mips64" {
553-
sources.extend(&[
554-
("__netf2", "comparetf2.c"),
555-
("__floatsitf", "floatsitf.c"),
556-
("__floatunsitf", "floatunsitf.c"),
557-
("__fe_getround", "fp_mode.c"),
558-
]);
549+
sources.extend(&[("__netf2", "comparetf2.c"), ("__fe_getround", "fp_mode.c")]);
559550
}
560551

561552
if target.arch == "loongarch64" {
562-
sources.extend(&[
563-
("__netf2", "comparetf2.c"),
564-
("__floatsitf", "floatsitf.c"),
565-
("__floatunsitf", "floatunsitf.c"),
566-
("__fe_getround", "fp_mode.c"),
567-
]);
553+
sources.extend(&[("__netf2", "comparetf2.c"), ("__fe_getround", "fp_mode.c")]);
568554
}
569555

570556
// Remove the assembly implementations that won't compile for the target

examples/intrinsics.rs

+56-6
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,18 @@ mod intrinsics {
264264

265265
/* i32 operations */
266266

267+
// floatsisf
268+
pub fn aeabi_i2f(x: i32) -> f32 {
269+
x as f32
270+
}
271+
267272
// floatsidf
268273
pub fn aeabi_i2d(x: i32) -> f64 {
269274
x as f64
270275
}
271276

272-
// floatsisf
273-
pub fn aeabi_i2f(x: i32) -> f32 {
274-
x as f32
277+
pub fn floatsitf(x: i32) -> f128 {
278+
x as f128
275279
}
276280

277281
pub fn aeabi_idiv(a: i32, b: i32) -> i32 {
@@ -294,6 +298,10 @@ mod intrinsics {
294298
x as f64
295299
}
296300

301+
pub fn floatditf(x: i64) -> f128 {
302+
x as f128
303+
}
304+
297305
pub fn mulodi4(a: i64, b: i64) -> i64 {
298306
a * b
299307
}
@@ -314,6 +322,18 @@ mod intrinsics {
314322

315323
/* i128 operations */
316324

325+
pub fn floattisf(x: i128) -> f32 {
326+
x as f32
327+
}
328+
329+
pub fn floattidf(x: i128) -> f64 {
330+
x as f64
331+
}
332+
333+
pub fn floattitf(x: i128) -> f128 {
334+
x as f128
335+
}
336+
317337
pub fn lshrti3(a: i128, b: usize) -> i128 {
318338
a >> b
319339
}
@@ -328,14 +348,18 @@ mod intrinsics {
328348

329349
/* u32 operations */
330350

351+
// floatunsisf
352+
pub fn aeabi_ui2f(x: u32) -> f32 {
353+
x as f32
354+
}
355+
331356
// floatunsidf
332357
pub fn aeabi_ui2d(x: u32) -> f64 {
333358
x as f64
334359
}
335360

336-
// floatunsisf
337-
pub fn aeabi_ui2f(x: u32) -> f32 {
338-
x as f32
361+
pub fn floatunsitf(x: u32) -> f128 {
362+
x as f128
339363
}
340364

341365
pub fn aeabi_uidiv(a: u32, b: u32) -> u32 {
@@ -358,6 +382,10 @@ mod intrinsics {
358382
x as f64
359383
}
360384

385+
pub fn floatunditf(x: u64) -> f128 {
386+
x as f128
387+
}
388+
361389
// udivdi3
362390
pub fn aeabi_uldivmod(a: u64, b: u64) -> u64 {
363391
a * b
@@ -369,6 +397,18 @@ mod intrinsics {
369397

370398
/* u128 operations */
371399

400+
pub fn floatuntisf(x: u128) -> f32 {
401+
x as f32
402+
}
403+
404+
pub fn floatuntidf(x: u128) -> f64 {
405+
x as f64
406+
}
407+
408+
pub fn floatuntitf(x: u128) -> f128 {
409+
x as f128
410+
}
411+
372412
pub fn muloti4(a: u128, b: u128) -> Option<u128> {
373413
a.checked_mul(b)
374414
}
@@ -466,6 +506,16 @@ fn run() {
466506
bb(fixunstfsi(bb(2.)));
467507
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
468508
bb(fixunstfti(bb(2.)));
509+
bb(floatditf(bb(2)));
510+
bb(floatsitf(bb(2)));
511+
bb(floattidf(bb(2)));
512+
bb(floattisf(bb(2)));
513+
bb(floattitf(bb(2)));
514+
bb(floatunditf(bb(2)));
515+
bb(floatunsitf(bb(2)));
516+
bb(floatuntidf(bb(2)));
517+
bb(floatuntisf(bb(2)));
518+
bb(floatuntitf(bb(2)));
469519
bb(gttf(bb(2.), bb(2.)));
470520
bb(lshrti3(bb(2), bb(2)));
471521
bb(lttf(bb(2.), bb(2.)));

0 commit comments

Comments
 (0)