Skip to content

Commit 575b608

Browse files
authored
Minor code move & clean-up (#1238)
* move f{32,64}.{min,max} down in file * add default T=Self to ArithmeticOps and Float traits * move f32_copysign down in file * use new default T=Self in UntypedVal impls * use f{32,64} where possible instead of F{32,64}
1 parent a322012 commit 575b608

File tree

2 files changed

+61
-59
lines changed

2 files changed

+61
-59
lines changed

crates/core/src/untyped.rs

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -923,142 +923,142 @@ impl UntypedVal {
923923

924924
/// Execute `f32.abs` Wasm operation.
925925
pub fn f32_abs(self) -> Self {
926-
self.execute_unary(<F32 as Float<F32>>::abs)
926+
self.execute_unary(<f32 as Float>::abs)
927927
}
928928

929929
/// Execute `f32.neg` Wasm operation.
930930
pub fn f32_neg(self) -> Self {
931-
self.execute_unary(<F32 as Neg>::neg)
931+
self.execute_unary(<f32 as Neg>::neg)
932932
}
933933

934934
/// Execute `f32.ceil` Wasm operation.
935935
pub fn f32_ceil(self) -> Self {
936-
self.execute_unary(<F32 as Float<F32>>::ceil)
936+
self.execute_unary(<f32 as Float>::ceil)
937937
}
938938

939939
/// Execute `f32.floor` Wasm operation.
940940
pub fn f32_floor(self) -> Self {
941-
self.execute_unary(<F32 as Float<F32>>::floor)
941+
self.execute_unary(<f32 as Float>::floor)
942942
}
943943

944944
/// Execute `f32.trunc` Wasm operation.
945945
pub fn f32_trunc(self) -> Self {
946-
self.execute_unary(<F32 as Float<F32>>::trunc)
946+
self.execute_unary(<f32 as Float>::trunc)
947947
}
948948

949949
/// Execute `f32.nearest` Wasm operation.
950950
pub fn f32_nearest(self) -> Self {
951-
self.execute_unary(<F32 as Float<F32>>::nearest)
951+
self.execute_unary(<f32 as Float>::nearest)
952952
}
953953

954954
/// Execute `f32.sqrt` Wasm operation.
955955
pub fn f32_sqrt(self) -> Self {
956-
self.execute_unary(<F32 as Float<F32>>::sqrt)
957-
}
958-
959-
/// Execute `f32.min` Wasm operation.
960-
pub fn f32_min(self, other: Self) -> Self {
961-
self.execute_binary(other, <F32 as Float<F32>>::min)
962-
}
963-
964-
/// Execute `f32.max` Wasm operation.
965-
pub fn f32_max(self, other: Self) -> Self {
966-
self.execute_binary(other, <F32 as Float<F32>>::max)
967-
}
968-
969-
/// Execute `f32.copysign` Wasm operation.
970-
pub fn f32_copysign(self, other: Self) -> Self {
971-
self.execute_binary(other, <F32 as Float<F32>>::copysign)
956+
self.execute_unary(<f32 as Float>::sqrt)
972957
}
973958

974959
/// Execute `f64.abs` Wasm operation.
975960
pub fn f64_abs(self) -> Self {
976-
self.execute_unary(<F64 as Float<F64>>::abs)
961+
self.execute_unary(<f64 as Float>::abs)
977962
}
978963

979964
/// Execute `f64.neg` Wasm operation.
980965
pub fn f64_neg(self) -> Self {
981-
self.execute_unary(<F64 as Neg>::neg)
966+
self.execute_unary(<f64 as Neg>::neg)
982967
}
983968

984969
/// Execute `f64.ceil` Wasm operation.
985970
pub fn f64_ceil(self) -> Self {
986-
self.execute_unary(<F64 as Float<F64>>::ceil)
971+
self.execute_unary(<f64 as Float>::ceil)
987972
}
988973

989974
/// Execute `f64.floor` Wasm operation.
990975
pub fn f64_floor(self) -> Self {
991-
self.execute_unary(<F64 as Float<F64>>::floor)
976+
self.execute_unary(<f64 as Float>::floor)
992977
}
993978

994979
/// Execute `f64.trunc` Wasm operation.
995980
pub fn f64_trunc(self) -> Self {
996-
self.execute_unary(<F64 as Float<F64>>::trunc)
981+
self.execute_unary(<f64 as Float>::trunc)
997982
}
998983

999984
/// Execute `f64.nearest` Wasm operation.
1000985
pub fn f64_nearest(self) -> Self {
1001-
self.execute_unary(<F64 as Float<F64>>::nearest)
986+
self.execute_unary(<f64 as Float>::nearest)
1002987
}
1003988

1004989
/// Execute `f64.sqrt` Wasm operation.
1005990
pub fn f64_sqrt(self) -> Self {
1006-
self.execute_unary(<F64 as Float<F64>>::sqrt)
991+
self.execute_unary(<f64 as Float>::sqrt)
1007992
}
1008993

1009994
/// Execute `f32.add` Wasm operation.
1010995
pub fn f32_add(self, rhs: Self) -> Self {
1011-
self.execute_binary(rhs, <F32 as ArithmeticOps<F32>>::add)
996+
self.execute_binary(rhs, <f32 as ArithmeticOps>::add)
1012997
}
1013998

1014999
/// Execute `f64.add` Wasm operation.
10151000
pub fn f64_add(self, rhs: Self) -> Self {
1016-
self.execute_binary(rhs, <F64 as ArithmeticOps<F64>>::add)
1001+
self.execute_binary(rhs, <f64 as ArithmeticOps>::add)
10171002
}
10181003

10191004
/// Execute `f32.sub` Wasm operation.
10201005
pub fn f32_sub(self, rhs: Self) -> Self {
1021-
self.execute_binary(rhs, <F32 as ArithmeticOps<F32>>::sub)
1006+
self.execute_binary(rhs, <f32 as ArithmeticOps>::sub)
10221007
}
10231008

10241009
/// Execute `f64.sub` Wasm operation.
10251010
pub fn f64_sub(self, rhs: Self) -> Self {
1026-
self.execute_binary(rhs, <F64 as ArithmeticOps<F64>>::sub)
1011+
self.execute_binary(rhs, <f64 as ArithmeticOps>::sub)
10271012
}
10281013

10291014
/// Execute `f32.mul` Wasm operation.
10301015
pub fn f32_mul(self, rhs: Self) -> Self {
1031-
self.execute_binary(rhs, <F32 as ArithmeticOps<F32>>::mul)
1016+
self.execute_binary(rhs, <f32 as ArithmeticOps>::mul)
10321017
}
10331018

10341019
/// Execute `f64.mul` Wasm operation.
10351020
pub fn f64_mul(self, rhs: Self) -> Self {
1036-
self.execute_binary(rhs, <F64 as ArithmeticOps<F64>>::mul)
1021+
self.execute_binary(rhs, <f64 as ArithmeticOps>::mul)
10371022
}
10381023

10391024
/// Execute `f32.div` Wasm operation.
10401025
pub fn f32_div(self, rhs: Self) -> Self {
1041-
self.execute_binary(rhs, <F32 as Float<F32>>::div)
1026+
self.execute_binary(rhs, <f32 as Float>::div)
10421027
}
10431028

10441029
/// Execute `f64.div` Wasm operation.
10451030
pub fn f64_div(self, rhs: Self) -> Self {
1046-
self.execute_binary(rhs, <F64 as Float<F64>>::div)
1031+
self.execute_binary(rhs, <f64 as Float>::div)
1032+
}
1033+
1034+
/// Execute `f32.min` Wasm operation.
1035+
pub fn f32_min(self, other: Self) -> Self {
1036+
self.execute_binary(other, <f32 as Float>::min)
10471037
}
10481038

10491039
/// Execute `f64.min` Wasm operation.
10501040
pub fn f64_min(self, other: Self) -> Self {
1051-
self.execute_binary(other, <F64 as Float<F64>>::min)
1041+
self.execute_binary(other, <f64 as Float>::min)
1042+
}
1043+
1044+
/// Execute `f32.max` Wasm operation.
1045+
pub fn f32_max(self, other: Self) -> Self {
1046+
self.execute_binary(other, <f32 as Float>::max)
10521047
}
10531048

10541049
/// Execute `f64.max` Wasm operation.
10551050
pub fn f64_max(self, other: Self) -> Self {
1056-
self.execute_binary(other, <F64 as Float<F64>>::max)
1051+
self.execute_binary(other, <f64 as Float>::max)
1052+
}
1053+
1054+
/// Execute `f32.copysign` Wasm operation.
1055+
pub fn f32_copysign(self, other: Self) -> Self {
1056+
self.execute_binary(other, <f32 as Float>::copysign)
10571057
}
10581058

10591059
/// Execute `f64.copysign` Wasm operation.
10601060
pub fn f64_copysign(self, other: Self) -> Self {
1061-
self.execute_binary(other, <F64 as Float<F64>>::copysign)
1061+
self.execute_binary(other, <f64 as Float>::copysign)
10621062
}
10631063

10641064
/// Execute `i32.wrap_i64` Wasm operation.
@@ -1079,7 +1079,7 @@ impl UntypedVal {
10791079
/// [WebAssembly specification]:
10801080
/// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s
10811081
pub fn i32_trunc_f32_s(self) -> Result<Self, TrapCode> {
1082-
self.try_execute_unary(<F32 as TryTruncateInto<i32, TrapCode>>::try_truncate_into)
1082+
self.try_execute_unary(<f32 as TryTruncateInto<i32, TrapCode>>::try_truncate_into)
10831083
}
10841084

10851085
/// Execute `i32.trunc_f32_u` Wasm operation.
@@ -1095,7 +1095,7 @@ impl UntypedVal {
10951095
/// [WebAssembly specification]:
10961096
/// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s
10971097
pub fn i32_trunc_f32_u(self) -> Result<Self, TrapCode> {
1098-
self.try_execute_unary(<F32 as TryTruncateInto<u32, TrapCode>>::try_truncate_into)
1098+
self.try_execute_unary(<f32 as TryTruncateInto<u32, TrapCode>>::try_truncate_into)
10991099
}
11001100

11011101
/// Execute `i32.trunc_f64_s` Wasm operation.
@@ -1111,7 +1111,7 @@ impl UntypedVal {
11111111
/// [WebAssembly specification]:
11121112
/// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s
11131113
pub fn i32_trunc_f64_s(self) -> Result<Self, TrapCode> {
1114-
self.try_execute_unary(<F64 as TryTruncateInto<i32, TrapCode>>::try_truncate_into)
1114+
self.try_execute_unary(<f64 as TryTruncateInto<i32, TrapCode>>::try_truncate_into)
11151115
}
11161116

11171117
/// Execute `i32.trunc_f64_u` Wasm operation.
@@ -1127,7 +1127,7 @@ impl UntypedVal {
11271127
/// [WebAssembly specification]:
11281128
/// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s
11291129
pub fn i32_trunc_f64_u(self) -> Result<Self, TrapCode> {
1130-
self.try_execute_unary(<F64 as TryTruncateInto<u32, TrapCode>>::try_truncate_into)
1130+
self.try_execute_unary(<f64 as TryTruncateInto<u32, TrapCode>>::try_truncate_into)
11311131
}
11321132

11331133
/// Execute `i64.extend_i32_s` Wasm operation.
@@ -1148,7 +1148,7 @@ impl UntypedVal {
11481148
/// [WebAssembly specification]:
11491149
/// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s
11501150
pub fn i64_trunc_f32_s(self) -> Result<Self, TrapCode> {
1151-
self.try_execute_unary(<F32 as TryTruncateInto<i64, TrapCode>>::try_truncate_into)
1151+
self.try_execute_unary(<f32 as TryTruncateInto<i64, TrapCode>>::try_truncate_into)
11521152
}
11531153

11541154
/// Execute `i64.trunc_f32_u` Wasm operation.
@@ -1164,7 +1164,7 @@ impl UntypedVal {
11641164
/// [WebAssembly specification]:
11651165
/// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s
11661166
pub fn i64_trunc_f32_u(self) -> Result<Self, TrapCode> {
1167-
self.try_execute_unary(<F32 as TryTruncateInto<u64, TrapCode>>::try_truncate_into)
1167+
self.try_execute_unary(<f32 as TryTruncateInto<u64, TrapCode>>::try_truncate_into)
11681168
}
11691169

11701170
/// Execute `i64.trunc_f64_s` Wasm operation.
@@ -1180,7 +1180,7 @@ impl UntypedVal {
11801180
/// [WebAssembly specification]:
11811181
/// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s
11821182
pub fn i64_trunc_f64_s(self) -> Result<Self, TrapCode> {
1183-
self.try_execute_unary(<F64 as TryTruncateInto<i64, TrapCode>>::try_truncate_into)
1183+
self.try_execute_unary(<f64 as TryTruncateInto<i64, TrapCode>>::try_truncate_into)
11841184
}
11851185

11861186
/// Execute `i64.trunc_f64_u` Wasm operation.
@@ -1196,7 +1196,7 @@ impl UntypedVal {
11961196
/// [WebAssembly specification]:
11971197
/// https://webassembly.github.io/spec/core/exec/numerics.html#op-trunc-s
11981198
pub fn i64_trunc_f64_u(self) -> Result<Self, TrapCode> {
1199-
self.try_execute_unary(<F64 as TryTruncateInto<u64, TrapCode>>::try_truncate_into)
1199+
self.try_execute_unary(<f64 as TryTruncateInto<u64, TrapCode>>::try_truncate_into)
12001200
}
12011201

12021202
/// Execute `f32.convert_i32_s` Wasm operation.
@@ -1246,7 +1246,7 @@ impl UntypedVal {
12461246

12471247
/// Execute `f64.promote_f32` Wasm operation.
12481248
pub fn f64_promote_f32(self) -> Self {
1249-
self.execute_unary(<F32 as ExtendInto<F64>>::extend_into)
1249+
self.execute_unary(<f32 as ExtendInto<F64>>::extend_into)
12501250
}
12511251

12521252
/// Execute `i32.extend8_s` Wasm operation.
@@ -1276,42 +1276,42 @@ impl UntypedVal {
12761276

12771277
/// Execute `i32.trunc_sat_f32_s` Wasm operation.
12781278
pub fn i32_trunc_sat_f32_s(self) -> Self {
1279-
self.execute_unary(<F32 as TruncateSaturateInto<i32>>::truncate_saturate_into)
1279+
self.execute_unary(<f32 as TruncateSaturateInto<i32>>::truncate_saturate_into)
12801280
}
12811281

12821282
/// Execute `i32.trunc_sat_f32_u` Wasm operation.
12831283
pub fn i32_trunc_sat_f32_u(self) -> Self {
1284-
self.execute_unary(<F32 as TruncateSaturateInto<u32>>::truncate_saturate_into)
1284+
self.execute_unary(<f32 as TruncateSaturateInto<u32>>::truncate_saturate_into)
12851285
}
12861286

12871287
/// Execute `i32.trunc_sat_f64_s` Wasm operation.
12881288
pub fn i32_trunc_sat_f64_s(self) -> Self {
1289-
self.execute_unary(<F64 as TruncateSaturateInto<i32>>::truncate_saturate_into)
1289+
self.execute_unary(<f64 as TruncateSaturateInto<i32>>::truncate_saturate_into)
12901290
}
12911291

12921292
/// Execute `i32.trunc_sat_f64_u` Wasm operation.
12931293
pub fn i32_trunc_sat_f64_u(self) -> Self {
1294-
self.execute_unary(<F64 as TruncateSaturateInto<u32>>::truncate_saturate_into)
1294+
self.execute_unary(<f64 as TruncateSaturateInto<u32>>::truncate_saturate_into)
12951295
}
12961296

12971297
/// Execute `i64.trunc_sat_f32_s` Wasm operation.
12981298
pub fn i64_trunc_sat_f32_s(self) -> Self {
1299-
self.execute_unary(<F32 as TruncateSaturateInto<i64>>::truncate_saturate_into)
1299+
self.execute_unary(<f32 as TruncateSaturateInto<i64>>::truncate_saturate_into)
13001300
}
13011301

13021302
/// Execute `i64.trunc_sat_f32_u` Wasm operation.
13031303
pub fn i64_trunc_sat_f32_u(self) -> Self {
1304-
self.execute_unary(<F32 as TruncateSaturateInto<u64>>::truncate_saturate_into)
1304+
self.execute_unary(<f32 as TruncateSaturateInto<u64>>::truncate_saturate_into)
13051305
}
13061306

13071307
/// Execute `i64.trunc_sat_f64_s` Wasm operation.
13081308
pub fn i64_trunc_sat_f64_s(self) -> Self {
1309-
self.execute_unary(<F64 as TruncateSaturateInto<i64>>::truncate_saturate_into)
1309+
self.execute_unary(<f64 as TruncateSaturateInto<i64>>::truncate_saturate_into)
13101310
}
13111311

13121312
/// Execute `i64.trunc_sat_f64_u` Wasm operation.
13131313
pub fn i64_trunc_sat_f64_u(self) -> Self {
1314-
self.execute_unary(<F64 as TruncateSaturateInto<u64>>::truncate_saturate_into)
1314+
self.execute_unary(<f64 as TruncateSaturateInto<u64>>::truncate_saturate_into)
13151315
}
13161316
}
13171317

crates/core/src/value.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl_little_endian_convert_float!(
197197
);
198198

199199
/// Arithmetic operations.
200-
pub trait ArithmeticOps<T>: Copy {
200+
pub trait ArithmeticOps<T = Self>: Copy {
201201
/// Add two values.
202202
fn add(self, other: T) -> T;
203203
/// Subtract two values.
@@ -233,7 +233,7 @@ pub trait Integer<T>: ArithmeticOps<T> {
233233
}
234234

235235
/// Float-point value.
236-
pub trait Float<T>: ArithmeticOps<T> {
236+
pub trait Float<T = Self>: ArithmeticOps<T> {
237237
/// Get absolute value.
238238
fn abs(self) -> T;
239239
/// Returns the largest integer less than or equal to a number.
@@ -624,6 +624,8 @@ macro_rules! impl_float {
624624
}
625625
impl_float!( type F32 as f32 );
626626
impl_float!( type F64 as f64 );
627+
impl_float!( type f32 as f32 );
628+
impl_float!( type f64 as f64 );
627629

628630
/// Low-level Wasm float interface to support `no_std` environments.
629631
///

0 commit comments

Comments
 (0)