Skip to content

Commit a062626

Browse files
committed
Add integer to f128 conversions
1 parent 7211bba commit a062626

File tree

6 files changed

+260
-26
lines changed

6 files changed

+260
-26
lines changed

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,12 @@ These builtins are needed to support `f16` and `f128`, which are in the process
245245
- [x] fixunstfdi.c
246246
- [x] fixunstfsi.c
247247
- [x] fixunstfti.c
248-
- [ ] floatditf.c
249-
- [ ] floatsitf.c
250-
- [ ] floatunditf.c
251-
- [ ] floatunsitf.c
248+
- [x] floatditf.c
249+
- [x] floatsitf.c
250+
- [x] floattitf.c
251+
- [x] floatunditf.c
252+
- [x] floatunsitf.c
253+
- [x] floatuntitf.c
252254
- [x] multf3.c
253255
- [ ] powitf2.c
254256
- [ ] ppc/fixtfdi.c

build.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,6 @@ mod c {
524524
if (target_arch == "aarch64" || target_arch == "arm64ec") && consider_float_intrinsics {
525525
sources.extend(&[
526526
("__comparetf2", "comparetf2.c"),
527-
("__floatditf", "floatditf.c"),
528-
("__floatsitf", "floatsitf.c"),
529-
("__floatunditf", "floatunditf.c"),
530-
("__floatunsitf", "floatunsitf.c"),
531527
("__divtf3", "divtf3.c"),
532528
("__powitf2", "powitf2.c"),
533529
("__fe_getround", "fp_mode.c"),
@@ -544,21 +540,11 @@ mod c {
544540
}
545541

546542
if target_arch == "mips64" {
547-
sources.extend(&[
548-
("__netf2", "comparetf2.c"),
549-
("__floatsitf", "floatsitf.c"),
550-
("__floatunsitf", "floatunsitf.c"),
551-
("__fe_getround", "fp_mode.c"),
552-
]);
543+
sources.extend(&[("__netf2", "comparetf2.c"), ("__fe_getround", "fp_mode.c")]);
553544
}
554545

555546
if target_arch == "loongarch64" {
556-
sources.extend(&[
557-
("__netf2", "comparetf2.c"),
558-
("__floatsitf", "floatsitf.c"),
559-
("__floatunsitf", "floatunsitf.c"),
560-
("__fe_getround", "fp_mode.c"),
561-
]);
547+
sources.extend(&[("__netf2", "comparetf2.c"), ("__fe_getround", "fp_mode.c")]);
562548
}
563549

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

examples/intrinsics.rs

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

263263
/* i32 operations */
264264

265+
// floatsisf
266+
pub fn aeabi_i2f(x: i32) -> f32 {
267+
x as f32
268+
}
269+
265270
// floatsidf
266271
pub fn aeabi_i2d(x: i32) -> f64 {
267272
x as f64
268273
}
269274

270-
// floatsisf
271-
pub fn aeabi_i2f(x: i32) -> f32 {
272-
x as f32
275+
pub fn floatsitf(x: i32) -> f128 {
276+
x as f128
273277
}
274278

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

299+
pub fn floatditf(x: i64) -> f128 {
300+
x as f128
301+
}
302+
295303
pub fn mulodi4(a: i64, b: i64) -> i64 {
296304
a * b
297305
}
@@ -312,6 +320,18 @@ mod intrinsics {
312320

313321
/* i128 operations */
314322

323+
pub fn floattisf(x: i128) -> f32 {
324+
x as f32
325+
}
326+
327+
pub fn floattidf(x: i128) -> f64 {
328+
x as f64
329+
}
330+
331+
pub fn floattitf(x: i128) -> f128 {
332+
x as f128
333+
}
334+
315335
pub fn lshrti3(a: i128, b: usize) -> i128 {
316336
a >> b
317337
}
@@ -326,14 +346,18 @@ mod intrinsics {
326346

327347
/* u32 operations */
328348

349+
// floatunsisf
350+
pub fn aeabi_ui2f(x: u32) -> f32 {
351+
x as f32
352+
}
353+
329354
// floatunsidf
330355
pub fn aeabi_ui2d(x: u32) -> f64 {
331356
x as f64
332357
}
333358

334-
// floatunsisf
335-
pub fn aeabi_ui2f(x: u32) -> f32 {
336-
x as f32
359+
pub fn floatunsitf(x: u32) -> f128 {
360+
x as f128
337361
}
338362

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

383+
pub fn floatunditf(x: u64) -> f128 {
384+
x as f128
385+
}
386+
359387
// udivdi3
360388
pub fn aeabi_uldivmod(a: u64, b: u64) -> u64 {
361389
a * b
@@ -367,6 +395,18 @@ mod intrinsics {
367395

368396
/* u128 operations */
369397

398+
pub fn floatuntisf(x: u128) -> f32 {
399+
x as f32
400+
}
401+
402+
pub fn floatuntidf(x: u128) -> f64 {
403+
x as f64
404+
}
405+
406+
pub fn floatuntitf(x: u128) -> f128 {
407+
x as f128
408+
}
409+
370410
pub fn muloti4(a: u128, b: u128) -> Option<u128> {
371411
a.checked_mul(b)
372412
}
@@ -463,6 +503,16 @@ fn run() {
463503
bb(fixunstfsi(bb(2.)));
464504
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
465505
bb(fixunstfti(bb(2.)));
506+
bb(floatditf(bb(2)));
507+
bb(floatsitf(bb(2)));
508+
bb(floattidf(bb(2)));
509+
bb(floattisf(bb(2)));
510+
bb(floattitf(bb(2)));
511+
bb(floatunditf(bb(2)));
512+
bb(floatunsitf(bb(2)));
513+
bb(floatuntidf(bb(2)));
514+
bb(floatuntisf(bb(2)));
515+
bb(floatuntitf(bb(2)));
466516
bb(gttf(bb(2.), bb(2.)));
467517
bb(lshrti3(bb(2), bb(2)));
468518
bb(lttf(bb(2.), bb(2.)));

src/float/conv.rs

+36
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,24 @@ intrinsics! {
120120
pub extern "C" fn __floatuntidf(i: u128) -> f64 {
121121
int_to_float(i)
122122
}
123+
124+
#[ppc_alias = __floatunsikf]
125+
#[cfg(not(feature = "no-f16-f128"))]
126+
pub extern "C" fn __floatunsitf(i: u32) -> f128 {
127+
int_to_float(i)
128+
}
129+
130+
#[ppc_alias = __floatundikf]
131+
#[cfg(not(feature = "no-f16-f128"))]
132+
pub extern "C" fn __floatunditf(i: u64) -> f128 {
133+
int_to_float(i)
134+
}
135+
136+
#[ppc_alias = __floatuntikf]
137+
#[cfg(not(feature = "no-f16-f128"))]
138+
pub extern "C" fn __floatuntitf(i: u128) -> f128 {
139+
int_to_float(i)
140+
}
123141
}
124142

125143
// Conversions from signed integers to floats.
@@ -153,6 +171,24 @@ intrinsics! {
153171
pub extern "C" fn __floattidf(i: i128) -> f64 {
154172
int_to_float(i)
155173
}
174+
175+
#[ppc_alias = __floatsikf]
176+
#[cfg(not(feature = "no-f16-f128"))]
177+
pub extern "C" fn __floatsitf(i: i32) -> f128 {
178+
int_to_float(i)
179+
}
180+
181+
#[ppc_alias = __floatdikf]
182+
#[cfg(not(feature = "no-f16-f128"))]
183+
pub extern "C" fn __floatditf(i: i64) -> f128 {
184+
int_to_float(i)
185+
}
186+
187+
#[ppc_alias = __floattikf]
188+
#[cfg(not(feature = "no-f16-f128"))]
189+
pub extern "C" fn __floattitf(i: i128) -> f128 {
190+
int_to_float(i)
191+
}
156192
}
157193

158194
/// Generic float to unsigned int conversions.

0 commit comments

Comments
 (0)