|
1 | 1 | macro_rules! exec_op { |
| 2 | + ($executor:ident; unary_fallible $from:ty => $to:ty, |$v:ident| $expr:expr) => {{ |
| 3 | + #[inline(always)] |
| 4 | + fn exec_unary_fallible(value_stack: &mut ValueStack) -> Result<(), Trap> { |
| 5 | + let $v = <$from>::stack_pop(value_stack); |
| 6 | + <$to>::stack_push(value_stack, $expr?); |
| 7 | + Ok(()) |
| 8 | + } |
| 9 | + exec_unary_fallible(&mut $executor.value_stack)?; |
| 10 | + }}; |
2 | 11 | ($executor:ident; binary_fallible $ty:ty, |$lhs:ident, $rhs:ident| $expr:expr) => {{ |
3 | 12 | fn exec_binary_fallible(value_stack: &mut ValueStack) -> Result<(), Trap> { |
4 | 13 | let $rhs = <$ty>::stack_pop(value_stack); |
@@ -280,14 +289,14 @@ macro_rules! instruction_handlers { |
280 | 289 | I64Mul => exec_op!(executor; binary i64 => i64, |a, b| a.wrapping_mul(b)), |
281 | 290 | F32Mul => exec_op!(executor; binary f32 => f32, |a, b| a * b), |
282 | 291 | F64Mul => exec_op!(executor; binary f64 => f64, |a, b| a * b), |
283 | | - I32DivS => exec_op!(executor; binary_fallible i32, |a, b| a.tw_checked_div(b)), |
284 | | - I64DivS => exec_op!(executor; binary_fallible i64, |a, b| a.tw_checked_div(b)), |
285 | | - I32DivU => exec_op!(executor; binary_fallible u32, |a, b| a.checked_div(b).ok_or(Trap::DivisionByZero)), |
286 | | - I64DivU => exec_op!(executor; binary_fallible u64, |a, b| a.checked_div(b).ok_or(Trap::DivisionByZero)), |
287 | | - I32RemS => exec_op!(executor; binary_fallible i32, |a, b| a.tw_checked_wrapping_rem(b)), |
288 | | - I64RemS => exec_op!(executor; binary_fallible i64, |a, b| a.tw_checked_wrapping_rem(b)), |
289 | | - I32RemU => exec_op!(executor; binary_fallible u32, |a, b| a.tw_checked_wrapping_rem(b)), |
290 | | - I64RemU => exec_op!(executor; binary_fallible u64, |a, b| a.tw_checked_wrapping_rem(b)), |
| 292 | + I32DivS => exec_op!(executor; binary_fallible i32, |a, b| num::i32::div(a, b)), |
| 293 | + I64DivS => exec_op!(executor; binary_fallible i64, |a, b| num::i64::div(a, b)), |
| 294 | + I32DivU => exec_op!(executor; binary_fallible u32, |a, b| num::u32::div(a, b)), |
| 295 | + I64DivU => exec_op!(executor; binary_fallible u64, |a, b| num::u64::div(a, b)), |
| 296 | + I32RemS => exec_op!(executor; binary_fallible i32, |a, b| num::i32::rem(a, b)), |
| 297 | + I64RemS => exec_op!(executor; binary_fallible i64, |a, b| num::i64::rem(a, b)), |
| 298 | + I32RemU => exec_op!(executor; binary_fallible u32, |a, b| num::u32::rem(a, b)), |
| 299 | + I64RemU => exec_op!(executor; binary_fallible u64, |a, b| num::u64::rem(a, b)), |
291 | 300 | I32And => exec_op!(executor; binary i32 => i32, |a, b| a & b), |
292 | 301 | I64And => exec_op!(executor; binary i64 => i64, |a, b| a & b), |
293 | 302 | I32Or => exec_op!(executor; binary i32 => i32, |a, b| a | b), |
@@ -423,40 +432,40 @@ macro_rules! instruction_handlers { |
423 | 432 | F64Abs => exec_op!(executor; unary f64 => f64, |v| v.abs()), |
424 | 433 | F32Neg => exec_op!(executor; unary f32 => f32, |v| -v), |
425 | 434 | F64Neg => exec_op!(executor; unary f64 => f64, |v| -v), |
426 | | - F32Ceil => exec_op!(executor; unary f32 => f32, |v| v.ceil()), |
427 | | - F64Ceil => exec_op!(executor; unary f64 => f64, |v| v.ceil()), |
428 | | - F32Floor => exec_op!(executor; unary f32 => f32, |v| v.floor()), |
429 | | - F64Floor => exec_op!(executor; unary f64 => f64, |v| v.floor()), |
430 | | - F32Trunc => exec_op!(executor; unary f32 => f32, |v| v.trunc()), |
431 | | - F64Trunc => exec_op!(executor; unary f64 => f64, |v| v.trunc()), |
432 | | - F32Nearest => exec_op!(executor; unary f32 => f32, |v| v.tw_nearest()), |
433 | | - F64Nearest => exec_op!(executor; unary f64 => f64, |v| v.tw_nearest()), |
434 | | - F32Sqrt => exec_op!(executor; unary f32 => f32, |v| v.sqrt()), |
435 | | - F64Sqrt => exec_op!(executor; unary f64 => f64, |v| v.sqrt()), |
436 | | - F32Min => exec_op!(executor; binary f32 => f32, |a, b| a.tw_minimum(b)), |
437 | | - F64Min => exec_op!(executor; binary f64 => f64, |a, b| a.tw_minimum(b)), |
438 | | - F32Max => exec_op!(executor; binary f32 => f32, |a, b| a.tw_maximum(b)), |
439 | | - F64Max => exec_op!(executor; binary f64 => f64, |a, b| a.tw_maximum(b)), |
| 435 | + F32Ceil => exec_op!(executor; unary f32 => f32, |v| num::f32::ceil(v)), |
| 436 | + F64Ceil => exec_op!(executor; unary f64 => f64, |v| num::f64::ceil(v)), |
| 437 | + F32Floor => exec_op!(executor; unary f32 => f32, |v| num::f32::floor(v)), |
| 438 | + F64Floor => exec_op!(executor; unary f64 => f64, |v| num::f64::floor(v)), |
| 439 | + F32Trunc => exec_op!(executor; unary f32 => f32, |v| num::f32::trunc(v)), |
| 440 | + F64Trunc => exec_op!(executor; unary f64 => f64, |v| num::f64::trunc(v)), |
| 441 | + F32Nearest => exec_op!(executor; unary f32 => f32, |v| num::f32::nearest(v)), |
| 442 | + F64Nearest => exec_op!(executor; unary f64 => f64, |v| num::f64::nearest(v)), |
| 443 | + F32Sqrt => exec_op!(executor; unary f32 => f32, |v| num::f32::sqrt(v)), |
| 444 | + F64Sqrt => exec_op!(executor; unary f64 => f64, |v| num::f64::sqrt(v)), |
| 445 | + F32Min => exec_op!(executor; binary f32 => f32, |a, b| num::f32::minimum(a, b)), |
| 446 | + F64Min => exec_op!(executor; binary f64 => f64, |a, b| num::f64::minimum(a, b)), |
| 447 | + F32Max => exec_op!(executor; binary f32 => f32, |a, b| num::f32::maximum(a, b)), |
| 448 | + F64Max => exec_op!(executor; binary f64 => f64, |a, b| num::f64::maximum(a, b)), |
440 | 449 | F32Copysign => exec_op!(executor; binary f32 => f32, |a, b| a.copysign(b)), |
441 | 450 | F64Copysign => exec_op!(executor; binary f64 => f64, |a, b| a.copysign(b)), |
442 | | - I32TruncF32S => checked_conv_float!(f32, i32, executor), |
443 | | - I32TruncF64S => checked_conv_float!(f64, i32, executor), |
444 | | - I32TruncF32U => checked_conv_float!(f32, u32, i32, executor), |
445 | | - I32TruncF64U => checked_conv_float!(f64, u32, i32, executor), |
446 | | - I64TruncF32S => checked_conv_float!(f32, i64, executor), |
447 | | - I64TruncF64S => checked_conv_float!(f64, i64, executor), |
448 | | - I64TruncF32U => checked_conv_float!(f32, u64, i64, executor), |
449 | | - I64TruncF64U => checked_conv_float!(f64, u64, i64, executor), |
| 451 | + I32TruncF32S => exec_op!(executor; unary_fallible f32 => i32, |v| num::f32::trunc_to_i32(v)), |
| 452 | + I32TruncF64S => exec_op!(executor; unary_fallible f64 => i32, |v| num::f64::trunc_to_i32(v)), |
| 453 | + I32TruncF32U => exec_op!(executor; unary_fallible f32 => u32, |v| num::f32::trunc_to_u32(v)), |
| 454 | + I32TruncF64U => exec_op!(executor; unary_fallible f64 => u32, |v| num::f64::trunc_to_u32(v)), |
| 455 | + I64TruncF32S => exec_op!(executor; unary_fallible f32 => i64, |v| num::f32::trunc_to_i64(v)), |
| 456 | + I64TruncF64S => exec_op!(executor; unary_fallible f64 => i64, |v| num::f64::trunc_to_i64(v)), |
| 457 | + I64TruncF32U => exec_op!(executor; unary_fallible f32 => u64, |v| num::f32::trunc_to_u64(v)), |
| 458 | + I64TruncF64U => exec_op!(executor; unary_fallible f64 => u64, |v| num::f64::trunc_to_u64(v)), |
450 | 459 |
|
451 | 460 | // Non-trapping float-to-int conversions |
452 | | - I32TruncSatF32S => exec_op!(executor; unary f32 => i32, |v| v.trunc() as i32), |
453 | | - I32TruncSatF32U => exec_op!(executor; unary f32 => u32, |v| v.trunc() as u32), |
454 | | - I32TruncSatF64S => exec_op!(executor; unary f64 => i32, |v| v.trunc() as i32), |
455 | | - I32TruncSatF64U => exec_op!(executor; unary f64 => u32, |v| v.trunc() as u32), |
456 | | - I64TruncSatF32S => exec_op!(executor; unary f32 => i64, |v| v.trunc() as i64), |
457 | | - I64TruncSatF32U => exec_op!(executor; unary f32 => u64, |v| v.trunc() as u64), |
458 | | - I64TruncSatF64S => exec_op!(executor; unary f64 => i64, |v| v.trunc() as i64), |
459 | | - I64TruncSatF64U => exec_op!(executor; unary f64 => u64, |v| v.trunc() as u64), |
| 461 | + I32TruncSatF32S => exec_op!(executor; unary f32 => i32, |v| v as i32), |
| 462 | + I32TruncSatF32U => exec_op!(executor; unary f32 => u32, |v| v as u32), |
| 463 | + I32TruncSatF64S => exec_op!(executor; unary f64 => i32, |v| v as i32), |
| 464 | + I32TruncSatF64U => exec_op!(executor; unary f64 => u32, |v| v as u32), |
| 465 | + I64TruncSatF32S => exec_op!(executor; unary f32 => i64, |v| v as i64), |
| 466 | + I64TruncSatF32U => exec_op!(executor; unary f32 => u64, |v| v as u64), |
| 467 | + I64TruncSatF64S => exec_op!(executor; unary f64 => i64, |v| v as i64), |
| 468 | + I64TruncSatF64U => exec_op!(executor; unary f64 => u64, |v| v as u64), |
460 | 469 |
|
461 | 470 | // SIMD extension |
462 | 471 | V128Not => exec_op!(executor; unary Value128 => Value128, |v| v.v128_not()), |
|
0 commit comments