Skip to content

Commit

Permalink
Use f16_enabled/f128_enabled in examples/intrinsics.rs (#724)
Browse files Browse the repository at this point in the history
Enable conditional compilation for intrinsics with `f16_enabled` and `f128_enabled`
  • Loading branch information
heiher authored Nov 1, 2024
1 parent b1459f3 commit 9ddeafc
Showing 1 changed file with 106 additions and 16 deletions.
122 changes: 106 additions & 16 deletions examples/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,28 @@ extern "C" {}
mod intrinsics {
/* f16 operations */

#[cfg(f16_enabled)]
pub fn extendhfsf(x: f16) -> f32 {
x as f32
}

#[cfg(f16_enabled)]
pub fn extendhfdf(x: f16) -> f64 {
x as f64
}

#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f16_enabled,
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
pub fn extendhftf(x: f16) -> f128 {
x as f128
}

/* f32 operations */

#[cfg(f16_enabled)]
pub fn truncsfhf(x: f32) -> f16 {
x as f16
}
Expand All @@ -52,6 +59,7 @@ mod intrinsics {
x as f64
}

#[cfg(f128_enabled)]
pub fn extendsftf(x: f32) -> f128 {
x as f128
}
Expand Down Expand Up @@ -191,73 +199,104 @@ mod intrinsics {

/* f128 operations */

#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f16_enabled,
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
pub fn trunctfhf(x: f128) -> f16 {
x as f16
}

#[cfg(f128_enabled)]
pub fn trunctfsf(x: f128) -> f32 {
x as f32
}

#[cfg(f128_enabled)]
pub fn trunctfdf(x: f128) -> f64 {
x as f64
}

#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
pub fn fixtfsi(x: f128) -> i32 {
x as i32
}

#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
pub fn fixtfdi(x: f128) -> i64 {
x as i64
}

#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
pub fn fixtfti(x: f128) -> i128 {
x as i128
}

#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
pub fn fixunstfsi(x: f128) -> u32 {
x as u32
}

#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
pub fn fixunstfdi(x: f128) -> u64 {
x as u64
}

#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
pub fn fixunstfti(x: f128) -> u128 {
x as u128
}

#[cfg(f128_enabled)]
pub fn addtf(a: f128, b: f128) -> f128 {
a + b
}

#[cfg(f128_enabled)]
pub fn eqtf(a: f128, b: f128) -> bool {
a == b
}

#[cfg(f128_enabled)]
pub fn gttf(a: f128, b: f128) -> bool {
a > b
}

#[cfg(f128_enabled)]
pub fn lttf(a: f128, b: f128) -> bool {
a < b
}

#[cfg(f128_enabled)]
pub fn multf(a: f128, b: f128) -> f128 {
a * b
}

#[cfg(f128_enabled)]
pub fn divtf(a: f128, b: f128) -> f128 {
a / b
}

#[cfg(f128_enabled)]
pub fn subtf(a: f128, b: f128) -> f128 {
a - b
}
Expand All @@ -274,6 +313,7 @@ mod intrinsics {
x as f64
}

#[cfg(f128_enabled)]
pub fn floatsitf(x: i32) -> f128 {
x as f128
}
Expand All @@ -298,6 +338,7 @@ mod intrinsics {
x as f64
}

#[cfg(f128_enabled)]
pub fn floatditf(x: i64) -> f128 {
x as f128
}
Expand Down Expand Up @@ -330,6 +371,7 @@ mod intrinsics {
x as f64
}

#[cfg(f128_enabled)]
pub fn floattitf(x: i128) -> f128 {
x as f128
}
Expand Down Expand Up @@ -358,6 +400,7 @@ mod intrinsics {
x as f64
}

#[cfg(f128_enabled)]
pub fn floatunsitf(x: u32) -> f128 {
x as f128
}
Expand All @@ -382,6 +425,7 @@ mod intrinsics {
x as f64
}

#[cfg(f128_enabled)]
pub fn floatunditf(x: u64) -> f128 {
x as f128
}
Expand All @@ -405,6 +449,7 @@ mod intrinsics {
x as f64
}

#[cfg(f128_enabled)]
pub fn floatuntitf(x: u128) -> f128 {
x as f128
}
Expand Down Expand Up @@ -440,6 +485,7 @@ fn run() {

// FIXME(f16_f128): some PPC f128 <-> int conversion functions have the wrong names

#[cfg(f128_enabled)]
bb(addtf(bb(2.), bb(2.)));
bb(aeabi_d2f(bb(2.)));
bb(aeabi_d2i(bb(2.)));
Expand Down Expand Up @@ -482,54 +528,98 @@ fn run() {
bb(aeabi_uldivmod(bb(2), bb(3)));
bb(ashlti3(bb(2), bb(2)));
bb(ashrti3(bb(2), bb(2)));
#[cfg(f128_enabled)]
bb(divtf(bb(2.), bb(2.)));
bb(divti3(bb(2), bb(2)));
#[cfg(f128_enabled)]
bb(eqtf(bb(2.), bb(2.)));
#[cfg(f16_enabled)]
bb(extendhfdf(bb(2.)));
#[cfg(f16_enabled)]
bb(extendhfsf(bb(2.)));
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f16_enabled,
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
bb(extendhftf(bb(2.)));
#[cfg(f128_enabled)]
bb(extendsftf(bb(2.)));
bb(fixdfti(bb(2.)));
bb(fixsfti(bb(2.)));
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
bb(fixtfdi(bb(2.)));
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
bb(fixtfsi(bb(2.)));
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
bb(fixtfti(bb(2.)));
bb(fixunsdfti(bb(2.)));
bb(fixunssfti(bb(2.)));
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
bb(fixunstfdi(bb(2.)));
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
bb(fixunstfsi(bb(2.)));
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
bb(fixunstfti(bb(2.)));
#[cfg(f128_enabled)]
bb(floatditf(bb(2)));
#[cfg(f128_enabled)]
bb(floatsitf(bb(2)));
bb(floattidf(bb(2)));
bb(floattisf(bb(2)));
#[cfg(f128_enabled)]
bb(floattitf(bb(2)));
#[cfg(f128_enabled)]
bb(floatunditf(bb(2)));
#[cfg(f128_enabled)]
bb(floatunsitf(bb(2)));
bb(floatuntidf(bb(2)));
bb(floatuntisf(bb(2)));
#[cfg(f128_enabled)]
bb(floatuntitf(bb(2)));
#[cfg(f128_enabled)]
bb(gttf(bb(2.), bb(2.)));
bb(lshrti3(bb(2), bb(2)));
#[cfg(f128_enabled)]
bb(lttf(bb(2.), bb(2.)));
bb(moddi3(bb(2), bb(3)));
bb(modti3(bb(2), bb(2)));
bb(mulodi4(bb(2), bb(3)));
bb(muloti4(bb(2), bb(2)));
#[cfg(f128_enabled)]
bb(multf(bb(2.), bb(2.)));
bb(multi3(bb(2), bb(2)));
#[cfg(f128_enabled)]
bb(subtf(bb(2.), bb(2.)));
#[cfg(f16_enabled)]
bb(truncsfhf(bb(2.)));
#[cfg(f128_enabled)]
bb(trunctfdf(bb(2.)));
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(
f16_enabled,
f128_enabled,
not(any(target_arch = "powerpc", target_arch = "powerpc64"))
))]
bb(trunctfhf(bb(2.)));
#[cfg(f128_enabled)]
bb(trunctfsf(bb(2.)));
bb(udivti3(bb(2), bb(2)));
bb(umoddi3(bb(2), bb(3)));
Expand Down

0 comments on commit 9ddeafc

Please sign in to comment.