Skip to content

Commit 80d022e

Browse files
tgross35Amanieu
authored andcommitted
Add f16 and f128 intrinsics to the example test
1 parent 39f45e9 commit 80d022e

File tree

1 file changed

+128
-6
lines changed

1 file changed

+128
-6
lines changed

examples/intrinsics.rs

Lines changed: 128 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,36 @@ extern "C" {}
2828
// have an additional comment: the function name is the ARM name for the intrinsic and the comment
2929
// in the non-ARM name for the intrinsic.
3030
mod intrinsics {
31+
/* f16 operations */
32+
33+
pub fn extendhfsf(x: f16) -> f32 {
34+
x as f32
35+
}
36+
37+
pub fn extendhfdf(x: f16) -> f64 {
38+
x as f64
39+
}
40+
41+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
42+
pub fn extendhftf(x: f16) -> f128 {
43+
x as f128
44+
}
45+
3146
/* f32 operations */
3247

48+
pub fn truncsfhf(x: f32) -> f16 {
49+
x as f16
50+
}
51+
3352
// extendsfdf2
3453
pub fn aeabi_f2d(x: f32) -> f64 {
3554
x as f64
3655
}
3756

57+
pub fn extendsftf(x: f32) -> f128 {
58+
x as f128
59+
}
60+
3861
// fixsfsi
3962
pub fn aeabi_f2iz(x: f32) -> i32 {
4063
x as i32
@@ -152,6 +175,75 @@ mod intrinsics {
152175
a - b
153176
}
154177

178+
/* f128 operations */
179+
180+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
181+
pub fn trunctfhf(x: f128) -> f16 {
182+
x as f16
183+
}
184+
185+
pub fn trunctfsf(x: f128) -> f32 {
186+
x as f32
187+
}
188+
189+
pub fn trunctfdf(x: f128) -> f64 {
190+
x as f64
191+
}
192+
193+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
194+
pub fn fixtfsi(x: f128) -> i32 {
195+
x as i32
196+
}
197+
198+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
199+
pub fn fixtfdi(x: f128) -> i64 {
200+
x as i64
201+
}
202+
203+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
204+
pub fn fixtfti(x: f128) -> i128 {
205+
x as i128
206+
}
207+
208+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
209+
pub fn fixunstfsi(x: f128) -> u32 {
210+
x as u32
211+
}
212+
213+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
214+
pub fn fixunstfdi(x: f128) -> u64 {
215+
x as u64
216+
}
217+
218+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
219+
pub fn fixunstfti(x: f128) -> u128 {
220+
x as u128
221+
}
222+
223+
pub fn addtf(a: f128, b: f128) -> f128 {
224+
a + b
225+
}
226+
227+
pub fn eqtf(a: f128, b: f128) -> bool {
228+
a == b
229+
}
230+
231+
pub fn gttf(a: f128, b: f128) -> bool {
232+
a > b
233+
}
234+
235+
pub fn lttf(a: f128, b: f128) -> bool {
236+
a < b
237+
}
238+
239+
pub fn multf(a: f128, b: f128) -> f128 {
240+
a * b
241+
}
242+
243+
pub fn subtf(a: f128, b: f128) -> f128 {
244+
a - b
245+
}
246+
155247
/* i32 operations */
156248

157249
// floatsidf
@@ -288,6 +380,9 @@ fn run() {
288380
use core::hint::black_box as bb;
289381
use intrinsics::*;
290382

383+
// FIXME(f16_f128): some PPC f128 <-> int conversion functions have the wrong names
384+
385+
bb(addtf(bb(2.), bb(2.)));
291386
bb(aeabi_d2f(bb(2.)));
292387
bb(aeabi_d2i(bb(2.)));
293388
bb(aeabi_d2l(bb(2.)));
@@ -327,18 +422,45 @@ fn run() {
327422
bb(aeabi_ul2d(bb(2)));
328423
bb(aeabi_ul2f(bb(2)));
329424
bb(aeabi_uldivmod(bb(2), bb(3)));
425+
bb(ashlti3(bb(2), bb(2)));
426+
bb(ashrti3(bb(2), bb(2)));
427+
bb(divti3(bb(2), bb(2)));
428+
bb(eqtf(bb(2.), bb(2.)));
429+
bb(extendhfdf(bb(2.)));
430+
bb(extendhfsf(bb(2.)));
431+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
432+
bb(extendhftf(bb(2.)));
433+
bb(extendsftf(bb(2.)));
434+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
435+
bb(fixtfdi(bb(2.)));
436+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
437+
bb(fixtfsi(bb(2.)));
438+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
439+
bb(fixtfti(bb(2.)));
440+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
441+
bb(fixunstfdi(bb(2.)));
442+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
443+
bb(fixunstfsi(bb(2.)));
444+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
445+
bb(fixunstfti(bb(2.)));
446+
bb(gttf(bb(2.), bb(2.)));
447+
bb(lshrti3(bb(2), bb(2)));
448+
bb(lttf(bb(2.), bb(2.)));
330449
bb(moddi3(bb(2), bb(3)));
450+
bb(modti3(bb(2), bb(2)));
331451
bb(mulodi4(bb(2), bb(3)));
332-
bb(umoddi3(bb(2), bb(3)));
333452
bb(muloti4(bb(2), bb(2)));
453+
bb(multf(bb(2.), bb(2.)));
334454
bb(multi3(bb(2), bb(2)));
335-
bb(ashlti3(bb(2), bb(2)));
336-
bb(ashrti3(bb(2), bb(2)));
337-
bb(lshrti3(bb(2), bb(2)));
455+
bb(subtf(bb(2.), bb(2.)));
456+
bb(truncsfhf(bb(2.)));
457+
bb(trunctfdf(bb(2.)));
458+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
459+
bb(trunctfhf(bb(2.)));
460+
bb(trunctfsf(bb(2.)));
338461
bb(udivti3(bb(2), bb(2)));
462+
bb(umoddi3(bb(2), bb(3)));
339463
bb(umodti3(bb(2), bb(2)));
340-
bb(divti3(bb(2), bb(2)));
341-
bb(modti3(bb(2), bb(2)));
342464

343465
something_with_a_dtor(&|| assert_eq!(bb(1), 1));
344466

0 commit comments

Comments
 (0)