wasm_interp: fix return type for i64 comparison ops

This commit is contained in:
Brian Carroll 2022-11-28 20:41:14 +00:00
parent c2bf7d68fc
commit fc10c520b1
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
2 changed files with 80 additions and 64 deletions

View file

@ -716,67 +716,67 @@ impl<'a> Instance<'a> {
I64EQZ => {
let arg = self.value_stack.pop_i64();
let result: bool = arg == 0;
self.value_stack.push(Value::I64(result as i64));
self.value_stack.push(Value::I32(result as i32));
}
I64EQ => {
let arg2 = self.value_stack.pop_i64();
let arg1 = self.value_stack.pop_i64();
let result: bool = arg1 == arg2;
self.value_stack.push(Value::I64(result as i64));
self.value_stack.push(Value::I32(result as i32));
}
I64NE => {
let arg2 = self.value_stack.pop_i64();
let arg1 = self.value_stack.pop_i64();
let result: bool = arg1 != arg2;
self.value_stack.push(Value::I64(result as i64));
self.value_stack.push(Value::I32(result as i32));
}
I64LTS => {
let arg2 = self.value_stack.pop_i64();
let arg1 = self.value_stack.pop_i64();
let result: bool = arg1 < arg2;
self.value_stack.push(Value::I64(result as i64));
self.value_stack.push(Value::I32(result as i32));
}
I64LTU => {
let arg2 = self.value_stack.pop_u64();
let arg1 = self.value_stack.pop_u64();
let result: bool = arg1 < arg2;
self.value_stack.push(Value::I64(result as i64));
self.value_stack.push(Value::I32(result as i32));
}
I64GTS => {
let arg2 = self.value_stack.pop_i64();
let arg1 = self.value_stack.pop_i64();
let result: bool = arg1 > arg2;
self.value_stack.push(Value::I64(result as i64));
self.value_stack.push(Value::I32(result as i32));
}
I64GTU => {
let arg2 = self.value_stack.pop_u64();
let arg1 = self.value_stack.pop_u64();
let result: bool = arg1 > arg2;
self.value_stack.push(Value::I64(result as i64));
self.value_stack.push(Value::I32(result as i32));
}
I64LES => {
let arg2 = self.value_stack.pop_i64();
let arg1 = self.value_stack.pop_i64();
let result: bool = arg1 <= arg2;
self.value_stack.push(Value::I64(result as i64));
self.value_stack.push(Value::I32(result as i32));
}
I64LEU => {
let arg2 = self.value_stack.pop_u64();
let arg1 = self.value_stack.pop_u64();
let result: bool = arg1 <= arg2;
self.value_stack.push(Value::I64(result as i64));
self.value_stack.push(Value::I32(result as i32));
}
I64GES => {
let arg2 = self.value_stack.pop_i64();
let arg1 = self.value_stack.pop_i64();
let result: bool = arg1 >= arg2;
self.value_stack.push(Value::I64(result as i64));
self.value_stack.push(Value::I32(result as i32));
}
I64GEU => {
let arg2 = self.value_stack.pop_u64();
let arg1 = self.value_stack.pop_u64();
let result: bool = arg1 >= arg2;
self.value_stack.push(Value::I64(result as i64));
self.value_stack.push(Value::I32(result as i32));
}
F32EQ => todo!("{:?} @ {:#x}", op_code, file_offset),

View file

@ -3,6 +3,22 @@
use roc_wasm_interp::test_utils::test_op_example;
use roc_wasm_module::{opcodes::OpCode, opcodes::OpCode::*, Value};
fn test_i64_comparison(op: OpCode, arg1: i64, arg2: i64, expected: bool) {
test_op_example(
op,
[Value::from(arg1), Value::from(arg2)],
Value::I32(expected as i32),
)
}
fn test_u64_comparison(op: OpCode, arg1: u64, arg2: u64, expected: bool) {
test_op_example(
op,
[Value::from(arg1), Value::from(arg2)],
Value::I32(expected as i32),
)
}
fn test_i64_binop(op: OpCode, arg1: i64, arg2: i64, expected: i64) {
test_op_example(
op,
@ -26,109 +42,109 @@ fn test_i64_unop(op: OpCode, arg: i64, expected: i64) {
#[test]
fn test_i64eqz() {
let op = I64EQZ;
test_i64_unop(op, 0, 1);
test_i64_unop(op, i64::MIN, 0);
test_i64_unop(op, i64::MAX, 0);
test_op_example(op, [Value::I64(0)], Value::I32(true as i32));
test_op_example(op, [Value::I64(i64::MIN)], Value::I32(false as i32));
test_op_example(op, [Value::I64(i64::MAX)], Value::I32(false as i32));
}
#[test]
fn test_i64eq() {
let op = I64EQ;
test_i64_binop(op, 0, 0, 1);
test_i64_binop(op, i64::MIN, i64::MIN, 1);
test_i64_binop(op, i64::MAX, i64::MAX, 1);
test_i64_binop(op, i64::MIN, i64::MAX, 0);
test_i64_binop(op, i64::MAX, i64::MIN, 0);
test_i64_comparison(op, 0, 0, true);
test_i64_comparison(op, i64::MIN, i64::MIN, true);
test_i64_comparison(op, i64::MAX, i64::MAX, true);
test_i64_comparison(op, i64::MIN, i64::MAX, false);
test_i64_comparison(op, i64::MAX, i64::MIN, false);
}
#[test]
fn test_i64ne() {
let op = I64NE;
test_i64_binop(op, 0, 0, 0);
test_i64_binop(op, i64::MIN, i64::MIN, 0);
test_i64_binop(op, i64::MAX, i64::MAX, 0);
test_i64_binop(op, i64::MIN, i64::MAX, 1);
test_i64_binop(op, i64::MAX, i64::MIN, 1);
test_i64_comparison(op, 0, 0, false);
test_i64_comparison(op, i64::MIN, i64::MIN, false);
test_i64_comparison(op, i64::MAX, i64::MAX, false);
test_i64_comparison(op, i64::MIN, i64::MAX, true);
test_i64_comparison(op, i64::MAX, i64::MIN, true);
}
#[test]
fn test_i64lts() {
let op = I64LTS;
test_i64_binop(op, 0, 0, 0);
test_i64_binop(op, i64::MIN, i64::MIN, 0);
test_i64_binop(op, i64::MAX, i64::MAX, 0);
test_i64_binop(op, i64::MIN, i64::MAX, 1);
test_i64_binop(op, i64::MAX, i64::MIN, 0);
test_i64_comparison(op, 0, 0, false);
test_i64_comparison(op, i64::MIN, i64::MIN, false);
test_i64_comparison(op, i64::MAX, i64::MAX, false);
test_i64_comparison(op, i64::MIN, i64::MAX, true);
test_i64_comparison(op, i64::MAX, i64::MIN, false);
}
#[test]
fn test_i64ltu() {
let op = I64LTU;
test_u64_binop(op, 0, 0, 0);
test_u64_binop(op, u64::MIN, u64::MIN, 0);
test_u64_binop(op, u64::MAX, u64::MAX, 0);
test_u64_binop(op, u64::MIN, u64::MAX, 1);
test_u64_binop(op, u64::MAX, u64::MIN, 0);
test_u64_comparison(op, 0, 0, false);
test_u64_comparison(op, u64::MIN, u64::MIN, false);
test_u64_comparison(op, u64::MAX, u64::MAX, false);
test_u64_comparison(op, u64::MIN, u64::MAX, true);
test_u64_comparison(op, u64::MAX, u64::MIN, false);
}
#[test]
fn test_i64gts() {
let op = I64GTS;
test_i64_binop(op, 0, 0, 0);
test_i64_binop(op, i64::MIN, i64::MIN, 0);
test_i64_binop(op, i64::MAX, i64::MAX, 0);
test_i64_binop(op, i64::MIN, i64::MAX, 0);
test_i64_binop(op, i64::MAX, i64::MIN, 1);
test_i64_comparison(op, 0, 0, false);
test_i64_comparison(op, i64::MIN, i64::MIN, false);
test_i64_comparison(op, i64::MAX, i64::MAX, false);
test_i64_comparison(op, i64::MIN, i64::MAX, false);
test_i64_comparison(op, i64::MAX, i64::MIN, true);
}
#[test]
fn test_i64gtu() {
let op = I64GTU;
test_u64_binop(op, 0, 0, 0);
test_u64_binop(op, u64::MIN, u64::MIN, 0);
test_u64_binop(op, u64::MAX, u64::MAX, 0);
test_u64_binop(op, u64::MIN, u64::MAX, 0);
test_u64_binop(op, u64::MAX, u64::MIN, 1);
test_u64_comparison(op, 0, 0, false);
test_u64_comparison(op, u64::MIN, u64::MIN, false);
test_u64_comparison(op, u64::MAX, u64::MAX, false);
test_u64_comparison(op, u64::MIN, u64::MAX, false);
test_u64_comparison(op, u64::MAX, u64::MIN, true);
}
#[test]
fn test_i64les() {
let op = I64LES;
test_i64_binop(op, 0, 0, 1);
test_i64_binop(op, i64::MIN, i64::MIN, 1);
test_i64_binop(op, i64::MAX, i64::MAX, 1);
test_i64_binop(op, i64::MIN, i64::MAX, 1);
test_i64_binop(op, i64::MAX, i64::MIN, 0);
test_i64_comparison(op, 0, 0, true);
test_i64_comparison(op, i64::MIN, i64::MIN, true);
test_i64_comparison(op, i64::MAX, i64::MAX, true);
test_i64_comparison(op, i64::MIN, i64::MAX, true);
test_i64_comparison(op, i64::MAX, i64::MIN, false);
}
#[test]
fn test_i64leu() {
let op = I64LEU;
test_u64_binop(op, 0, 0, 1);
test_u64_binop(op, u64::MIN, u64::MIN, 1);
test_u64_binop(op, u64::MAX, u64::MAX, 1);
test_u64_binop(op, u64::MIN, u64::MAX, 1);
test_u64_binop(op, u64::MAX, u64::MIN, 0);
test_u64_comparison(op, 0, 0, true);
test_u64_comparison(op, u64::MIN, u64::MIN, true);
test_u64_comparison(op, u64::MAX, u64::MAX, true);
test_u64_comparison(op, u64::MIN, u64::MAX, true);
test_u64_comparison(op, u64::MAX, u64::MIN, false);
}
#[test]
fn test_i64ges() {
let op = I64GES;
test_i64_binop(op, 0, 0, 1);
test_i64_binop(op, i64::MIN, i64::MIN, 1);
test_i64_binop(op, i64::MAX, i64::MAX, 1);
test_i64_binop(op, i64::MIN, i64::MAX, 0);
test_i64_binop(op, i64::MAX, i64::MIN, 1);
test_i64_comparison(op, 0, 0, true);
test_i64_comparison(op, i64::MIN, i64::MIN, true);
test_i64_comparison(op, i64::MAX, i64::MAX, true);
test_i64_comparison(op, i64::MIN, i64::MAX, false);
test_i64_comparison(op, i64::MAX, i64::MIN, true);
}
#[test]
fn test_i64geu() {
let op = I64GEU;
test_u64_binop(op, 0, 0, 1);
test_u64_binop(op, u64::MIN, u64::MIN, 1);
test_u64_binop(op, u64::MAX, u64::MAX, 1);
test_u64_binop(op, u64::MIN, u64::MAX, 0);
test_u64_binop(op, u64::MAX, u64::MIN, 1);
test_u64_comparison(op, 0, 0, true);
test_u64_comparison(op, u64::MIN, u64::MIN, true);
test_u64_comparison(op, u64::MAX, u64::MAX, true);
test_u64_comparison(op, u64::MIN, u64::MAX, false);
test_u64_comparison(op, u64::MAX, u64::MIN, true);
}
#[test]