Skip to content

Commit

Permalink
extend block_forward test
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbepop committed Nov 20, 2023
1 parent 4830169 commit df92d3e
Showing 1 changed file with 65 additions and 22 deletions.
87 changes: 65 additions & 22 deletions crates/wasmi/src/engine/regmach/tests/op/cmp_br.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,29 +171,72 @@ fn loop_backward_imm_eqz() {
#[test]
#[cfg_attr(miri, ignore)]
fn block_forward() {
let wasm = wat2wasm(
r"
(module
(func (param i32 i32)
(block
(local.get 0)
(local.get 1)
(i32.eq)
(br_if 0)
fn test_for(
ty: ValueType,
op: &str,
expect_instr: fn(Register, Register, BranchOffset16) -> Instruction,
) {
let ty = DisplayValueType::from(ty);
let wasm = wat2wasm(&format!(
r"
(module
(func (param {ty} {ty})
(block
(local.get 0)
(local.get 1)
({ty}.{op})
(br_if 0)
)
)
)
)",
);
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::branch_i32_eq(
Register::from_i16(0),
Register::from_i16(1),
BranchOffset16::from(1),
),
Instruction::Return,
])
.run()
)",
));
TranslationTest::new(wasm)
.expect_func_instrs([
expect_instr(
Register::from_i16(0),
Register::from_i16(1),
BranchOffset16::from(1),
),
Instruction::Return,
])
.run()
}

test_for(ValueType::I32, "eq", Instruction::branch_i32_eq);
test_for(ValueType::I32, "ne", Instruction::branch_i32_ne);
test_for(ValueType::I32, "lt_s", Instruction::branch_i32_lt_s);
test_for(ValueType::I32, "lt_u", Instruction::branch_i32_lt_u);
test_for(ValueType::I32, "le_s", Instruction::branch_i32_le_s);
test_for(ValueType::I32, "le_u", Instruction::branch_i32_le_u);
test_for(ValueType::I32, "gt_s", Instruction::branch_i32_gt_s);
test_for(ValueType::I32, "gt_u", Instruction::branch_i32_gt_u);
test_for(ValueType::I32, "ge_s", Instruction::branch_i32_ge_s);
test_for(ValueType::I32, "ge_u", Instruction::branch_i32_ge_u);

test_for(ValueType::I64, "eq", Instruction::branch_i64_eq);
test_for(ValueType::I64, "ne", Instruction::branch_i64_ne);
test_for(ValueType::I64, "lt_s", Instruction::branch_i64_lt_s);
test_for(ValueType::I64, "lt_u", Instruction::branch_i64_lt_u);
test_for(ValueType::I64, "le_s", Instruction::branch_i64_le_s);
test_for(ValueType::I64, "le_u", Instruction::branch_i64_le_u);
test_for(ValueType::I64, "gt_s", Instruction::branch_i64_gt_s);
test_for(ValueType::I64, "gt_u", Instruction::branch_i64_gt_u);
test_for(ValueType::I64, "ge_s", Instruction::branch_i64_ge_s);
test_for(ValueType::I64, "ge_u", Instruction::branch_i64_ge_u);

test_for(ValueType::F32, "eq", Instruction::branch_f32_eq);
test_for(ValueType::F32, "ne", Instruction::branch_f32_ne);
test_for(ValueType::F32, "lt", Instruction::branch_f32_lt);
test_for(ValueType::F32, "le", Instruction::branch_f32_le);
test_for(ValueType::F32, "gt", Instruction::branch_f32_gt);
test_for(ValueType::F32, "ge", Instruction::branch_f32_ge);

test_for(ValueType::F64, "eq", Instruction::branch_f64_eq);
test_for(ValueType::F64, "ne", Instruction::branch_f64_ne);
test_for(ValueType::F64, "lt", Instruction::branch_f64_lt);
test_for(ValueType::F64, "le", Instruction::branch_f64_le);
test_for(ValueType::F64, "gt", Instruction::branch_f64_gt);
test_for(ValueType::F64, "ge", Instruction::branch_f64_ge);
}

#[test]
Expand Down

0 comments on commit df92d3e

Please sign in to comment.