Skip to content
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
8 changes: 8 additions & 0 deletions crates/dialect-mir/src/rust_intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ pub const CALLEE_MINNUM_NSZ_F32: &str = placeholder!("minimum_number_nsz_f32");
/// Placeholder call used for `core::intrinsics::minimum_number_nsz_f64`
/// (the intrinsic backing `f64::min`).
pub const CALLEE_MINNUM_NSZ_F64: &str = placeholder!("minimum_number_nsz_f64");
/// Placeholder call used for `f32::asin` / `std::sys::cmath::asinf`.
pub const CALLEE_ASIN_F32: &str = placeholder!("asinf32");
/// Placeholder call used for `f64::asin` / `std::sys::cmath::asin`.
pub const CALLEE_ASIN_F64: &str = placeholder!("asinf64");
/// Placeholder call used for `f32::acos` / `std::sys::cmath::acosf`.
pub const CALLEE_ACOS_F32: &str = placeholder!("acosf32");
/// Placeholder call used for `f64::acos` / `std::sys::cmath::acos`.
pub const CALLEE_ACOS_F64: &str = placeholder!("acosf64");
/// Placeholder call used for `f32::atan2` / `std::sys::cmath::atan2f`.
pub const CALLEE_ATAN2_F32: &str = placeholder!("atan2f32");
/// Placeholder call used for `f64::atan2` / `std::sys::cmath::atan2`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ pub enum RustFloatMathIntrinsic {
MinNumNszF32,
/// `core::intrinsics::minimum_number_nsz_f64` (backs `f64::min`).
MinNumNszF64,
/// `f32::asin` / `std::sys::cmath::asinf`.
AsinF32,
/// `f64::asin` / `std::sys::cmath::asin`.
AsinF64,
/// `f32::acos` / `std::sys::cmath::acosf`.
AcosF32,
/// `f64::acos` / `std::sys::cmath::acos`.
AcosF64,
/// `f32::atan2` / `std::sys::cmath::atan2f`.
Atan2F32,
/// `f64::atan2` / `std::sys::cmath::atan2`.
Expand Down Expand Up @@ -182,6 +190,10 @@ impl RustFloatMathIntrinsic {
| "std::intrinsics::minimum_number_nsz_f32" => Some(Self::MinNumNszF32),
"core::intrinsics::minimum_number_nsz_f64"
| "std::intrinsics::minimum_number_nsz_f64" => Some(Self::MinNumNszF64),
"std::sys::cmath::asinf" => Some(Self::AsinF32),
"std::sys::cmath::asin" => Some(Self::AsinF64),
"std::sys::cmath::acosf" => Some(Self::AcosF32),
"std::sys::cmath::acos" => Some(Self::AcosF64),
"std::sys::cmath::atan2f" => Some(Self::Atan2F32),
"std::sys::cmath::atan2" => Some(Self::Atan2F64),
"std::sys::cmath::atanf" => Some(Self::AtanF32),
Expand Down Expand Up @@ -249,6 +261,10 @@ impl RustFloatMathIntrinsic {
"fmax" => Some(Self::MaxNumNszF64),
"fminf" => Some(Self::MinNumNszF32),
"fmin" => Some(Self::MinNumNszF64),
"asinf" => Some(Self::AsinF32),
"asin" => Some(Self::AsinF64),
"acosf" => Some(Self::AcosF32),
"acos" => Some(Self::AcosF64),
"atan2f" => Some(Self::Atan2F32),
"atan2" => Some(Self::Atan2F64),
"atanf" => Some(Self::AtanF32),
Expand Down Expand Up @@ -305,6 +321,10 @@ impl RustFloatMathIntrinsic {
Self::MaxNumNszF64 => rust_intrinsics::CALLEE_MAXNUM_NSZ_F64,
Self::MinNumNszF32 => rust_intrinsics::CALLEE_MINNUM_NSZ_F32,
Self::MinNumNszF64 => rust_intrinsics::CALLEE_MINNUM_NSZ_F64,
Self::AsinF32 => rust_intrinsics::CALLEE_ASIN_F32,
Self::AsinF64 => rust_intrinsics::CALLEE_ASIN_F64,
Self::AcosF32 => rust_intrinsics::CALLEE_ACOS_F32,
Self::AcosF64 => rust_intrinsics::CALLEE_ACOS_F64,
Self::Atan2F32 => rust_intrinsics::CALLEE_ATAN2_F32,
Self::Atan2F64 => rust_intrinsics::CALLEE_ATAN2_F64,
Self::AtanF32 => rust_intrinsics::CALLEE_ATAN_F32,
Expand Down Expand Up @@ -595,6 +615,31 @@ mod tests {
}
}

/// `asin`/`acos` reach libdevice from both the std `f{32,64}` inherent
/// methods (`std::sys::cmath::*`) and the `libm` crate spellings glam's
/// `nostd-libm` lowering emits on nvptx. Unlike `cbrt` these are std-only
/// (no `core::num::imp::libm` form), so only the cmath and libm-crate
/// spellings exist; both must map to the same `__nv_a{sin,cos}{,f}` path.
#[test]
fn from_core_path_recognizes_asin_acos_via_cmath_and_libm() {
for (path, expected) in [
("std::sys::cmath::asinf", RustFloatMathIntrinsic::AsinF32),
("std::sys::cmath::asin", RustFloatMathIntrinsic::AsinF64),
("std::sys::cmath::acosf", RustFloatMathIntrinsic::AcosF32),
("std::sys::cmath::acos", RustFloatMathIntrinsic::AcosF64),
("libm::asinf", RustFloatMathIntrinsic::AsinF32),
("libm::math::asin::asin", RustFloatMathIntrinsic::AsinF64),
("libm::acosf", RustFloatMathIntrinsic::AcosF32),
("libm::math::acos::acos", RustFloatMathIntrinsic::AcosF64),
] {
assert_eq!(
RustFloatMathIntrinsic::from_core_path(path),
Some(expected),
"`{path}` did not map to the expected asin/acos intrinsic"
);
}
}

/// Libm interception must be anchored to the `libm` crate root. A user
/// function that shares a libm function name, inside a path that merely
/// mentions "libm", must stay a regular call: a bare `contains("libm")`
Expand Down
32 changes: 32 additions & 0 deletions crates/mir-lower/src/convert/ops/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ enum RustFloatMathIntrinsic {
MaxNumNszF64,
MinNumNszF32,
MinNumNszF64,
AsinF32,
AsinF64,
AcosF32,
AcosF64,
Atan2F32,
Atan2F64,
AtanF32,
Expand Down Expand Up @@ -270,6 +274,10 @@ impl RustFloatMathIntrinsic {
rust_intrinsics::CALLEE_MAXNUM_NSZ_F64 => Some(Self::MaxNumNszF64),
rust_intrinsics::CALLEE_MINNUM_NSZ_F32 => Some(Self::MinNumNszF32),
rust_intrinsics::CALLEE_MINNUM_NSZ_F64 => Some(Self::MinNumNszF64),
rust_intrinsics::CALLEE_ASIN_F32 => Some(Self::AsinF32),
rust_intrinsics::CALLEE_ASIN_F64 => Some(Self::AsinF64),
rust_intrinsics::CALLEE_ACOS_F32 => Some(Self::AcosF32),
rust_intrinsics::CALLEE_ACOS_F64 => Some(Self::AcosF64),
rust_intrinsics::CALLEE_ATAN2_F32 => Some(Self::Atan2F32),
rust_intrinsics::CALLEE_ATAN2_F64 => Some(Self::Atan2F64),
rust_intrinsics::CALLEE_ATAN_F32 => Some(Self::AtanF32),
Expand Down Expand Up @@ -336,6 +344,10 @@ impl RustFloatMathIntrinsic {
Self::MaxNumNszF64 => Ok("__nv_fmax"),
Self::MinNumNszF32 => Ok("__nv_fminf"),
Self::MinNumNszF64 => Ok("__nv_fmin"),
Self::AsinF32 => Ok("__nv_asinf"),
Self::AsinF64 => Ok("__nv_asin"),
Self::AcosF32 => Ok("__nv_acosf"),
Self::AcosF64 => Ok("__nv_acos"),
Self::Atan2F32 => Ok("__nv_atan2f"),
Self::Atan2F64 => Ok("__nv_atan2"),
Self::AtanF32 => Ok("__nv_atanf"),
Expand Down Expand Up @@ -1378,6 +1390,22 @@ mod tests {
rust_intrinsics::CALLEE_MINNUM_NSZ_F64,
RustFloatMathIntrinsic::MinNumNszF64,
),
(
rust_intrinsics::CALLEE_ASIN_F32,
RustFloatMathIntrinsic::AsinF32,
),
(
rust_intrinsics::CALLEE_ASIN_F64,
RustFloatMathIntrinsic::AsinF64,
),
(
rust_intrinsics::CALLEE_ACOS_F32,
RustFloatMathIntrinsic::AcosF32,
),
(
rust_intrinsics::CALLEE_ACOS_F64,
RustFloatMathIntrinsic::AcosF64,
),
(
rust_intrinsics::CALLEE_ATAN2_F32,
RustFloatMathIntrinsic::Atan2F32,
Expand Down Expand Up @@ -1426,6 +1454,10 @@ mod tests {
assert_eq!(RustFloatMathIntrinsic::PowiF32.arg_count(), 2);
assert_eq!(RustFloatMathIntrinsic::PowfF64.arg_count(), 2);
assert_eq!(RustFloatMathIntrinsic::CopysignF32.arg_count(), 2);
assert_eq!(RustFloatMathIntrinsic::AsinF32.arg_count(), 1);
assert_eq!(RustFloatMathIntrinsic::AsinF64.arg_count(), 1);
assert_eq!(RustFloatMathIntrinsic::AcosF32.arg_count(), 1);
assert_eq!(RustFloatMathIntrinsic::AcosF64.arg_count(), 1);
assert_eq!(RustFloatMathIntrinsic::Atan2F32.arg_count(), 2);
assert_eq!(RustFloatMathIntrinsic::Atan2F64.arg_count(), 2);
assert_eq!(RustFloatMathIntrinsic::AtanF32.arg_count(), 1);
Expand Down
Loading
Loading