From 3e268dc5bbc52bf71c64678edbfc9c174989e88f Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Mon, 14 Oct 2024 11:50:32 +0200 Subject: [PATCH 1/5] move f{32,64}.{min,max} down in file --- crates/core/src/untyped.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/core/src/untyped.rs b/crates/core/src/untyped.rs index 1baf7f5219..4cafbb6642 100644 --- a/crates/core/src/untyped.rs +++ b/crates/core/src/untyped.rs @@ -956,16 +956,6 @@ impl UntypedVal { self.execute_unary(>::sqrt) } - /// Execute `f32.min` Wasm operation. - pub fn f32_min(self, other: Self) -> Self { - self.execute_binary(other, >::min) - } - - /// Execute `f32.max` Wasm operation. - pub fn f32_max(self, other: Self) -> Self { - self.execute_binary(other, >::max) - } - /// Execute `f32.copysign` Wasm operation. pub fn f32_copysign(self, other: Self) -> Self { self.execute_binary(other, >::copysign) @@ -1046,11 +1036,21 @@ impl UntypedVal { self.execute_binary(rhs, >::div) } + /// Execute `f32.min` Wasm operation. + pub fn f32_min(self, other: Self) -> Self { + self.execute_binary(other, >::min) + } + /// Execute `f64.min` Wasm operation. pub fn f64_min(self, other: Self) -> Self { self.execute_binary(other, >::min) } + /// Execute `f32.max` Wasm operation. + pub fn f32_max(self, other: Self) -> Self { + self.execute_binary(other, >::max) + } + /// Execute `f64.max` Wasm operation. pub fn f64_max(self, other: Self) -> Self { self.execute_binary(other, >::max) From 6a40fe807e8e9c814dee8b95936b3bda28ecc26d Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Mon, 14 Oct 2024 12:00:21 +0200 Subject: [PATCH 2/5] add default T=Self to ArithmeticOps and Float traits --- crates/core/src/value.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/core/src/value.rs b/crates/core/src/value.rs index da233825c9..63c1246d65 100644 --- a/crates/core/src/value.rs +++ b/crates/core/src/value.rs @@ -197,7 +197,7 @@ impl_little_endian_convert_float!( ); /// Arithmetic operations. -pub trait ArithmeticOps: Copy { +pub trait ArithmeticOps: Copy { /// Add two values. fn add(self, other: T) -> T; /// Subtract two values. @@ -233,7 +233,7 @@ pub trait Integer: ArithmeticOps { } /// Float-point value. -pub trait Float: ArithmeticOps { +pub trait Float: ArithmeticOps { /// Get absolute value. fn abs(self) -> T; /// Returns the largest integer less than or equal to a number. @@ -624,6 +624,8 @@ macro_rules! impl_float { } impl_float!( type F32 as f32 ); impl_float!( type F64 as f64 ); +impl_float!( type f32 as f32 ); +impl_float!( type f64 as f64 ); /// Low-level Wasm float interface to support `no_std` environments. /// From 1f99e80fe292ca13b2825a6fcfc2709810c765ee Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Mon, 14 Oct 2024 11:52:41 +0200 Subject: [PATCH 3/5] move f32_copysign down in file --- crates/core/src/untyped.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/core/src/untyped.rs b/crates/core/src/untyped.rs index 4cafbb6642..f9ea4ab24f 100644 --- a/crates/core/src/untyped.rs +++ b/crates/core/src/untyped.rs @@ -956,11 +956,6 @@ impl UntypedVal { self.execute_unary(>::sqrt) } - /// Execute `f32.copysign` Wasm operation. - pub fn f32_copysign(self, other: Self) -> Self { - self.execute_binary(other, >::copysign) - } - /// Execute `f64.abs` Wasm operation. pub fn f64_abs(self) -> Self { self.execute_unary(>::abs) @@ -1056,6 +1051,11 @@ impl UntypedVal { self.execute_binary(other, >::max) } + /// Execute `f32.copysign` Wasm operation. + pub fn f32_copysign(self, other: Self) -> Self { + self.execute_binary(other, >::copysign) + } + /// Execute `f64.copysign` Wasm operation. pub fn f64_copysign(self, other: Self) -> Self { self.execute_binary(other, >::copysign) From d0778ad359c09db42abacce6d0b63be2b4beaa78 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Mon, 14 Oct 2024 17:47:30 +0200 Subject: [PATCH 4/5] use new default T=Self in UntypedVal impls --- crates/core/src/untyped.rs | 52 +++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/crates/core/src/untyped.rs b/crates/core/src/untyped.rs index f9ea4ab24f..0d25fdf98f 100644 --- a/crates/core/src/untyped.rs +++ b/crates/core/src/untyped.rs @@ -923,7 +923,7 @@ impl UntypedVal { /// Execute `f32.abs` Wasm operation. pub fn f32_abs(self) -> Self { - self.execute_unary(>::abs) + self.execute_unary(::abs) } /// Execute `f32.neg` Wasm operation. @@ -933,32 +933,32 @@ impl UntypedVal { /// Execute `f32.ceil` Wasm operation. pub fn f32_ceil(self) -> Self { - self.execute_unary(>::ceil) + self.execute_unary(::ceil) } /// Execute `f32.floor` Wasm operation. pub fn f32_floor(self) -> Self { - self.execute_unary(>::floor) + self.execute_unary(::floor) } /// Execute `f32.trunc` Wasm operation. pub fn f32_trunc(self) -> Self { - self.execute_unary(>::trunc) + self.execute_unary(::trunc) } /// Execute `f32.nearest` Wasm operation. pub fn f32_nearest(self) -> Self { - self.execute_unary(>::nearest) + self.execute_unary(::nearest) } /// Execute `f32.sqrt` Wasm operation. pub fn f32_sqrt(self) -> Self { - self.execute_unary(>::sqrt) + self.execute_unary(::sqrt) } /// Execute `f64.abs` Wasm operation. pub fn f64_abs(self) -> Self { - self.execute_unary(>::abs) + self.execute_unary(::abs) } /// Execute `f64.neg` Wasm operation. @@ -968,97 +968,97 @@ impl UntypedVal { /// Execute `f64.ceil` Wasm operation. pub fn f64_ceil(self) -> Self { - self.execute_unary(>::ceil) + self.execute_unary(::ceil) } /// Execute `f64.floor` Wasm operation. pub fn f64_floor(self) -> Self { - self.execute_unary(>::floor) + self.execute_unary(::floor) } /// Execute `f64.trunc` Wasm operation. pub fn f64_trunc(self) -> Self { - self.execute_unary(>::trunc) + self.execute_unary(::trunc) } /// Execute `f64.nearest` Wasm operation. pub fn f64_nearest(self) -> Self { - self.execute_unary(>::nearest) + self.execute_unary(::nearest) } /// Execute `f64.sqrt` Wasm operation. pub fn f64_sqrt(self) -> Self { - self.execute_unary(>::sqrt) + self.execute_unary(::sqrt) } /// Execute `f32.add` Wasm operation. pub fn f32_add(self, rhs: Self) -> Self { - self.execute_binary(rhs, >::add) + self.execute_binary(rhs, ::add) } /// Execute `f64.add` Wasm operation. pub fn f64_add(self, rhs: Self) -> Self { - self.execute_binary(rhs, >::add) + self.execute_binary(rhs, ::add) } /// Execute `f32.sub` Wasm operation. pub fn f32_sub(self, rhs: Self) -> Self { - self.execute_binary(rhs, >::sub) + self.execute_binary(rhs, ::sub) } /// Execute `f64.sub` Wasm operation. pub fn f64_sub(self, rhs: Self) -> Self { - self.execute_binary(rhs, >::sub) + self.execute_binary(rhs, ::sub) } /// Execute `f32.mul` Wasm operation. pub fn f32_mul(self, rhs: Self) -> Self { - self.execute_binary(rhs, >::mul) + self.execute_binary(rhs, ::mul) } /// Execute `f64.mul` Wasm operation. pub fn f64_mul(self, rhs: Self) -> Self { - self.execute_binary(rhs, >::mul) + self.execute_binary(rhs, ::mul) } /// Execute `f32.div` Wasm operation. pub fn f32_div(self, rhs: Self) -> Self { - self.execute_binary(rhs, >::div) + self.execute_binary(rhs, ::div) } /// Execute `f64.div` Wasm operation. pub fn f64_div(self, rhs: Self) -> Self { - self.execute_binary(rhs, >::div) + self.execute_binary(rhs, ::div) } /// Execute `f32.min` Wasm operation. pub fn f32_min(self, other: Self) -> Self { - self.execute_binary(other, >::min) + self.execute_binary(other, ::min) } /// Execute `f64.min` Wasm operation. pub fn f64_min(self, other: Self) -> Self { - self.execute_binary(other, >::min) + self.execute_binary(other, ::min) } /// Execute `f32.max` Wasm operation. pub fn f32_max(self, other: Self) -> Self { - self.execute_binary(other, >::max) + self.execute_binary(other, ::max) } /// Execute `f64.max` Wasm operation. pub fn f64_max(self, other: Self) -> Self { - self.execute_binary(other, >::max) + self.execute_binary(other, ::max) } /// Execute `f32.copysign` Wasm operation. pub fn f32_copysign(self, other: Self) -> Self { - self.execute_binary(other, >::copysign) + self.execute_binary(other, ::copysign) } /// Execute `f64.copysign` Wasm operation. pub fn f64_copysign(self, other: Self) -> Self { - self.execute_binary(other, >::copysign) + self.execute_binary(other, ::copysign) } /// Execute `i32.wrap_i64` Wasm operation. From 925ae9b8457b78f872a3daa3c6b2b822c6053371 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Mon, 14 Oct 2024 17:50:23 +0200 Subject: [PATCH 5/5] use f{32,64} where possible instead of F{32,64} --- crates/core/src/untyped.rs | 90 +++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/crates/core/src/untyped.rs b/crates/core/src/untyped.rs index 0d25fdf98f..b8a8a4eaa1 100644 --- a/crates/core/src/untyped.rs +++ b/crates/core/src/untyped.rs @@ -923,142 +923,142 @@ impl UntypedVal { /// Execute `f32.abs` Wasm operation. pub fn f32_abs(self) -> Self { - self.execute_unary(::abs) + self.execute_unary(::abs) } /// Execute `f32.neg` Wasm operation. pub fn f32_neg(self) -> Self { - self.execute_unary(::neg) + self.execute_unary(::neg) } /// Execute `f32.ceil` Wasm operation. pub fn f32_ceil(self) -> Self { - self.execute_unary(::ceil) + self.execute_unary(::ceil) } /// Execute `f32.floor` Wasm operation. pub fn f32_floor(self) -> Self { - self.execute_unary(::floor) + self.execute_unary(::floor) } /// Execute `f32.trunc` Wasm operation. pub fn f32_trunc(self) -> Self { - self.execute_unary(::trunc) + self.execute_unary(::trunc) } /// Execute `f32.nearest` Wasm operation. pub fn f32_nearest(self) -> Self { - self.execute_unary(::nearest) + self.execute_unary(::nearest) } /// Execute `f32.sqrt` Wasm operation. pub fn f32_sqrt(self) -> Self { - self.execute_unary(::sqrt) + self.execute_unary(::sqrt) } /// Execute `f64.abs` Wasm operation. pub fn f64_abs(self) -> Self { - self.execute_unary(::abs) + self.execute_unary(::abs) } /// Execute `f64.neg` Wasm operation. pub fn f64_neg(self) -> Self { - self.execute_unary(::neg) + self.execute_unary(::neg) } /// Execute `f64.ceil` Wasm operation. pub fn f64_ceil(self) -> Self { - self.execute_unary(::ceil) + self.execute_unary(::ceil) } /// Execute `f64.floor` Wasm operation. pub fn f64_floor(self) -> Self { - self.execute_unary(::floor) + self.execute_unary(::floor) } /// Execute `f64.trunc` Wasm operation. pub fn f64_trunc(self) -> Self { - self.execute_unary(::trunc) + self.execute_unary(::trunc) } /// Execute `f64.nearest` Wasm operation. pub fn f64_nearest(self) -> Self { - self.execute_unary(::nearest) + self.execute_unary(::nearest) } /// Execute `f64.sqrt` Wasm operation. pub fn f64_sqrt(self) -> Self { - self.execute_unary(::sqrt) + self.execute_unary(::sqrt) } /// Execute `f32.add` Wasm operation. pub fn f32_add(self, rhs: Self) -> Self { - self.execute_binary(rhs, ::add) + self.execute_binary(rhs, ::add) } /// Execute `f64.add` Wasm operation. pub fn f64_add(self, rhs: Self) -> Self { - self.execute_binary(rhs, ::add) + self.execute_binary(rhs, ::add) } /// Execute `f32.sub` Wasm operation. pub fn f32_sub(self, rhs: Self) -> Self { - self.execute_binary(rhs, ::sub) + self.execute_binary(rhs, ::sub) } /// Execute `f64.sub` Wasm operation. pub fn f64_sub(self, rhs: Self) -> Self { - self.execute_binary(rhs, ::sub) + self.execute_binary(rhs, ::sub) } /// Execute `f32.mul` Wasm operation. pub fn f32_mul(self, rhs: Self) -> Self { - self.execute_binary(rhs, ::mul) + self.execute_binary(rhs, ::mul) } /// Execute `f64.mul` Wasm operation. pub fn f64_mul(self, rhs: Self) -> Self { - self.execute_binary(rhs, ::mul) + self.execute_binary(rhs, ::mul) } /// Execute `f32.div` Wasm operation. pub fn f32_div(self, rhs: Self) -> Self { - self.execute_binary(rhs, ::div) + self.execute_binary(rhs, ::div) } /// Execute `f64.div` Wasm operation. pub fn f64_div(self, rhs: Self) -> Self { - self.execute_binary(rhs, ::div) + self.execute_binary(rhs, ::div) } /// Execute `f32.min` Wasm operation. pub fn f32_min(self, other: Self) -> Self { - self.execute_binary(other, ::min) + self.execute_binary(other, ::min) } /// Execute `f64.min` Wasm operation. pub fn f64_min(self, other: Self) -> Self { - self.execute_binary(other, ::min) + self.execute_binary(other, ::min) } /// Execute `f32.max` Wasm operation. pub fn f32_max(self, other: Self) -> Self { - self.execute_binary(other, ::max) + self.execute_binary(other, ::max) } /// Execute `f64.max` Wasm operation. pub fn f64_max(self, other: Self) -> Self { - self.execute_binary(other, ::max) + self.execute_binary(other, ::max) } /// Execute `f32.copysign` Wasm operation. pub fn f32_copysign(self, other: Self) -> Self { - self.execute_binary(other, ::copysign) + self.execute_binary(other, ::copysign) } /// Execute `f64.copysign` Wasm operation. pub fn f64_copysign(self, other: Self) -> Self { - self.execute_binary(other, ::copysign) + self.execute_binary(other, ::copysign) } /// Execute `i32.wrap_i64` Wasm operation. @@ -1079,7 +1079,7 @@ impl UntypedVal { /// [WebAssembly specification]: /// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s pub fn i32_trunc_f32_s(self) -> Result { - self.try_execute_unary(>::try_truncate_into) + self.try_execute_unary(>::try_truncate_into) } /// Execute `i32.trunc_f32_u` Wasm operation. @@ -1095,7 +1095,7 @@ impl UntypedVal { /// [WebAssembly specification]: /// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s pub fn i32_trunc_f32_u(self) -> Result { - self.try_execute_unary(>::try_truncate_into) + self.try_execute_unary(>::try_truncate_into) } /// Execute `i32.trunc_f64_s` Wasm operation. @@ -1111,7 +1111,7 @@ impl UntypedVal { /// [WebAssembly specification]: /// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s pub fn i32_trunc_f64_s(self) -> Result { - self.try_execute_unary(>::try_truncate_into) + self.try_execute_unary(>::try_truncate_into) } /// Execute `i32.trunc_f64_u` Wasm operation. @@ -1127,7 +1127,7 @@ impl UntypedVal { /// [WebAssembly specification]: /// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s pub fn i32_trunc_f64_u(self) -> Result { - self.try_execute_unary(>::try_truncate_into) + self.try_execute_unary(>::try_truncate_into) } /// Execute `i64.extend_i32_s` Wasm operation. @@ -1148,7 +1148,7 @@ impl UntypedVal { /// [WebAssembly specification]: /// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s pub fn i64_trunc_f32_s(self) -> Result { - self.try_execute_unary(>::try_truncate_into) + self.try_execute_unary(>::try_truncate_into) } /// Execute `i64.trunc_f32_u` Wasm operation. @@ -1164,7 +1164,7 @@ impl UntypedVal { /// [WebAssembly specification]: /// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s pub fn i64_trunc_f32_u(self) -> Result { - self.try_execute_unary(>::try_truncate_into) + self.try_execute_unary(>::try_truncate_into) } /// Execute `i64.trunc_f64_s` Wasm operation. @@ -1180,7 +1180,7 @@ impl UntypedVal { /// [WebAssembly specification]: /// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s pub fn i64_trunc_f64_s(self) -> Result { - self.try_execute_unary(>::try_truncate_into) + self.try_execute_unary(>::try_truncate_into) } /// Execute `i64.trunc_f64_u` Wasm operation. @@ -1196,7 +1196,7 @@ impl UntypedVal { /// [WebAssembly specification]: /// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s pub fn i64_trunc_f64_u(self) -> Result { - self.try_execute_unary(>::try_truncate_into) + self.try_execute_unary(>::try_truncate_into) } /// Execute `f32.convert_i32_s` Wasm operation. @@ -1246,7 +1246,7 @@ impl UntypedVal { /// Execute `f64.promote_f32` Wasm operation. pub fn f64_promote_f32(self) -> Self { - self.execute_unary(>::extend_into) + self.execute_unary(>::extend_into) } /// Execute `i32.extend8_s` Wasm operation. @@ -1276,42 +1276,42 @@ impl UntypedVal { /// Execute `i32.trunc_sat_f32_s` Wasm operation. pub fn i32_trunc_sat_f32_s(self) -> Self { - self.execute_unary(>::truncate_saturate_into) + self.execute_unary(>::truncate_saturate_into) } /// Execute `i32.trunc_sat_f32_u` Wasm operation. pub fn i32_trunc_sat_f32_u(self) -> Self { - self.execute_unary(>::truncate_saturate_into) + self.execute_unary(>::truncate_saturate_into) } /// Execute `i32.trunc_sat_f64_s` Wasm operation. pub fn i32_trunc_sat_f64_s(self) -> Self { - self.execute_unary(>::truncate_saturate_into) + self.execute_unary(>::truncate_saturate_into) } /// Execute `i32.trunc_sat_f64_u` Wasm operation. pub fn i32_trunc_sat_f64_u(self) -> Self { - self.execute_unary(>::truncate_saturate_into) + self.execute_unary(>::truncate_saturate_into) } /// Execute `i64.trunc_sat_f32_s` Wasm operation. pub fn i64_trunc_sat_f32_s(self) -> Self { - self.execute_unary(>::truncate_saturate_into) + self.execute_unary(>::truncate_saturate_into) } /// Execute `i64.trunc_sat_f32_u` Wasm operation. pub fn i64_trunc_sat_f32_u(self) -> Self { - self.execute_unary(>::truncate_saturate_into) + self.execute_unary(>::truncate_saturate_into) } /// Execute `i64.trunc_sat_f64_s` Wasm operation. pub fn i64_trunc_sat_f64_s(self) -> Self { - self.execute_unary(>::truncate_saturate_into) + self.execute_unary(>::truncate_saturate_into) } /// Execute `i64.trunc_sat_f64_u` Wasm operation. pub fn i64_trunc_sat_f64_u(self) -> Self { - self.execute_unary(>::truncate_saturate_into) + self.execute_unary(>::truncate_saturate_into) } }