Add a simple i32.eq operator.
This commit is contained in:
committed by
Dan Gohman
parent
b42696f207
commit
ba216b2e8a
@@ -243,6 +243,20 @@ pub fn store_i32(ctx: &mut Context, local_idx: u32) {
|
|||||||
ctx.regs.release_scratch_gpr(gpr);
|
ctx.regs.release_scratch_gpr(gpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn relop_eq_i32(ctx: &mut Context) {
|
||||||
|
let right = pop_i32(ctx);
|
||||||
|
let left = pop_i32(ctx);
|
||||||
|
let result = ctx.regs.take_scratch_gpr();
|
||||||
|
dynasm!(ctx.asm
|
||||||
|
; xor Rq(result), Rq(result)
|
||||||
|
; cmp Rd(left), Rd(right)
|
||||||
|
; sete Rb(result)
|
||||||
|
);
|
||||||
|
push_i32(ctx, result);
|
||||||
|
ctx.regs.release_scratch_gpr(left);
|
||||||
|
ctx.regs.release_scratch_gpr(right);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn prepare_return_value(ctx: &mut Context) {
|
pub fn prepare_return_value(ctx: &mut Context) {
|
||||||
let ret_gpr = pop_i32(ctx);
|
let ret_gpr = pop_i32(ctx);
|
||||||
if ret_gpr != RAX {
|
if ret_gpr != RAX {
|
||||||
|
|||||||
@@ -133,6 +133,9 @@ pub fn translate(session: &mut CodeGenSession, body: &FunctionBody) -> Result<()
|
|||||||
define_label(&mut ctx, control_frame.kind.br_destination());
|
define_label(&mut ctx, control_frame.kind.br_destination());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Operator::I32Eq => {
|
||||||
|
relop_eq_i32(&mut ctx);
|
||||||
|
}
|
||||||
Operator::I32Add => {
|
Operator::I32Add => {
|
||||||
add_i32(&mut ctx);
|
add_i32(&mut ctx);
|
||||||
}
|
}
|
||||||
|
|||||||
22
src/tests.rs
22
src/tests.rs
@@ -31,4 +31,26 @@ fn adds() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn relop_eq() {
|
||||||
|
const CASES: &[(usize, usize, usize)] = &[
|
||||||
|
(0, 0, 1),
|
||||||
|
(0, 1, 0),
|
||||||
|
(1, 0, 0),
|
||||||
|
(1, 1, 1),
|
||||||
|
(1312, 1, 0),
|
||||||
|
(1312, 1312, 1),
|
||||||
|
];
|
||||||
|
|
||||||
|
let code = r#"
|
||||||
|
(module
|
||||||
|
(func (param i32) (param i32) (result i32) (i32.eq (get_local 0) (get_local 1)))
|
||||||
|
)
|
||||||
|
"#;
|
||||||
|
|
||||||
|
for (a, b, expected) in CASES {
|
||||||
|
assert_eq!(execute_wat(code, *a, *b), *expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Add a test that checks argument passing via the stack.
|
// TODO: Add a test that checks argument passing via the stack.
|
||||||
|
|||||||
Reference in New Issue
Block a user