From 3b494e84c403a513ee78cb322198dde4fa0c4cf6 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 20 Dec 2024 08:07:00 -0800 Subject: [PATCH] Remove float canonicalization from components This was removed from the spec quite awhile back so this catches up the runtime to the spec where this is no longer required. Closes #9826 --- .../src/runtime/component/func/typed.rs | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/crates/wasmtime/src/runtime/component/func/typed.rs b/crates/wasmtime/src/runtime/component/func/typed.rs index 4dd5050e000d..95fb52186c2a 100644 --- a/crates/wasmtime/src/runtime/component/func/typed.rs +++ b/crates/wasmtime/src/runtime/component/func/typed.rs @@ -875,19 +875,6 @@ integers! { macro_rules! floats { ($($float:ident/$get_float:ident = $ty:ident with abi:$abi:ident)*) => ($(const _: () = { - /// All floats in-and-out of the canonical abi always have their nan - /// payloads canonicalized. conveniently the `NAN` constant in rust has - /// the same representation as canonical nan, so we can use that for the - /// nan value. - #[inline] - fn canonicalize(float: $float) -> $float { - if float.is_nan() { - $float::NAN - } else { - float - } - } - unsafe impl ComponentType for $float { type Lower = ValRaw; @@ -910,7 +897,7 @@ macro_rules! floats { dst: &mut MaybeUninit, ) -> Result<()> { debug_assert!(matches!(ty, InterfaceType::$ty)); - dst.write(ValRaw::$float(canonicalize(*self).to_bits())); + dst.write(ValRaw::$float(self.to_bits())); Ok(()) } @@ -924,7 +911,7 @@ macro_rules! floats { debug_assert!(matches!(ty, InterfaceType::$ty)); debug_assert!(offset % Self::SIZE32 == 0); let ptr = cx.get(offset); - *ptr = canonicalize(*self).to_bits().to_le_bytes(); + *ptr = self.to_bits().to_le_bytes(); Ok(()) } } @@ -933,14 +920,14 @@ macro_rules! floats { #[inline] fn lift(_cx: &mut LiftContext<'_>, ty: InterfaceType, src: &Self::Lower) -> Result { debug_assert!(matches!(ty, InterfaceType::$ty)); - Ok(canonicalize($float::from_bits(src.$get_float()))) + Ok($float::from_bits(src.$get_float())) } #[inline] fn load(_cx: &mut LiftContext<'_>, ty: InterfaceType, bytes: &[u8]) -> Result { debug_assert!(matches!(ty, InterfaceType::$ty)); debug_assert!((bytes.as_ptr() as usize) % Self::SIZE32 == 0); - Ok(canonicalize($float::from_le_bytes(bytes.try_into().unwrap()))) + Ok($float::from_le_bytes(bytes.try_into().unwrap())) } } };)*)