Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Use core::arch::wasm functions rather than intrinsics #418

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![no_std]
#![cfg_attr(intrinsics_enabled, allow(internal_features))]
#![cfg_attr(intrinsics_enabled, feature(core_intrinsics))]
#![cfg_attr(all(intrinsics_enabled, target_family = "wasm"), feature(wasm_numeric_instr))]
#![cfg_attr(f128_enabled, feature(f128))]
#![cfg_attr(f16_enabled, feature(f16))]
#![allow(clippy::assign_op_pattern)]
Expand Down
30 changes: 10 additions & 20 deletions src/math/arch/wasm32.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
//! Wasm asm is not stable; just use intrinsics for operations that have asm routine equivalents.
//!
//! Note that we need to be absolutely certain that everything here lowers to assembly operations,
//! otherwise libcalls will be recursive.
//! Wasm has builtins for simple float operations. Use the unstable `core::arch` intrinsics which
//! are significantly faster than soft float operations.

pub fn ceil(x: f64) -> f64 {
// SAFETY: safe intrinsic with no preconditions
unsafe { core::intrinsics::ceilf64(x) }
core::arch::wasm32::f64_ceil(x)
}

pub fn ceilf(x: f32) -> f32 {
// SAFETY: safe intrinsic with no preconditions
unsafe { core::intrinsics::ceilf32(x) }
core::arch::wasm32::f32_ceil(x)
}

pub fn fabs(x: f64) -> f64 {
Expand All @@ -22,31 +18,25 @@ pub fn fabsf(x: f32) -> f32 {
}

pub fn floor(x: f64) -> f64 {
// SAFETY: safe intrinsic with no preconditions
unsafe { core::intrinsics::floorf64(x) }
core::arch::wasm32::f64_floor(x)
}

pub fn floorf(x: f32) -> f32 {
// SAFETY: safe intrinsic with no preconditions
unsafe { core::intrinsics::floorf32(x) }
core::arch::wasm32::f32_floor(x)
}

pub fn sqrt(x: f64) -> f64 {
// SAFETY: safe intrinsic with no preconditions
unsafe { core::intrinsics::sqrtf64(x) }
core::arch::wasm32::f64_sqrt(x)
}

pub fn sqrtf(x: f32) -> f32 {
// SAFETY: safe intrinsic with no preconditions
unsafe { core::intrinsics::sqrtf32(x) }
core::arch::wasm32::f32_sqrt(x)
}

pub fn trunc(x: f64) -> f64 {
// SAFETY: safe intrinsic with no preconditions
unsafe { core::intrinsics::truncf64(x) }
core::arch::wasm32::f64_trunc(x)
}

pub fn truncf(x: f32) -> f32 {
// SAFETY: safe intrinsic with no preconditions
unsafe { core::intrinsics::truncf32(x) }
core::arch::wasm32::f32_trunc(x)
}