wasm_interp: even more copy-and-pasting

This commit is contained in:
Brian Carroll 2022-11-28 17:35:51 +00:00
parent ea9b53aff3
commit 0dc3441301
No known key found for this signature in database
GPG Key ID: 5C7B2EC4101703C0
2 changed files with 154 additions and 132 deletions

View File

@ -889,15 +889,17 @@ impl<'a> ExecutionState<'a> {
I64CLZ => {
let arg = self.value_stack.pop_u64();
self.value_stack.push(Value::from(arg.leading_zeros()));
self.value_stack
.push(Value::from(arg.leading_zeros() as u64));
}
I64CTZ => {
let arg = self.value_stack.pop_u64();
self.value_stack.push(Value::from(arg.trailing_zeros()));
self.value_stack
.push(Value::from(arg.trailing_zeros() as u64));
}
I64POPCNT => {
let arg = self.value_stack.pop_u64();
self.value_stack.push(Value::from(arg.count_ones()));
self.value_stack.push(Value::from(arg.count_ones() as u64));
}
I64ADD => {
let arg2 = self.value_stack.pop_i64();

View File

@ -131,153 +131,173 @@ fn test_i64geu() {
test_u64_binop(op, u64::MAX, u64::MIN, 1);
}
// #[test]
// fn test_i64clz() {
// let op = I64CLZ;
// test_i64_unop(op, 0, 64);
// test_i64_unop(op, -1, 0);
// test_i64_unop(op, 1, 31);
// test_i64_unop(op, 1024, 21);
// }
#[test]
fn test_i64clz() {
let op = I64CLZ;
test_i64_unop(op, 0, 64);
test_i64_unop(op, -1, 0);
test_i64_unop(op, 1, 63);
test_i64_unop(op, 1024, 53);
}
// #[test]
// fn test_i64ctz() {
// let op = I64CTZ;
// test_i64_unop(op, 0, 64);
// test_i64_unop(op, -1, 0);
// test_i64_unop(op, 2, 1);
// test_i64_unop(op, 1024, 10);
// }
#[test]
fn test_i64ctz() {
let op = I64CTZ;
test_i64_unop(op, 0, 64);
test_i64_unop(op, -1, 0);
test_i64_unop(op, 2, 1);
test_i64_unop(op, 1024, 10);
}
// #[test]
// fn test_i64popcnt() {
// let op = I64POPCNT;
// test_i64_unop(op, 0, 0);
// test_i64_unop(op, -1, 64);
// test_i64_unop(op, 2, 1);
// test_i64_unop(op, 96, 2);
// }
#[test]
fn test_i64popcnt() {
let op = I64POPCNT;
test_i64_unop(op, 0, 0);
test_i64_unop(op, -1, 64);
test_i64_unop(op, 2, 1);
test_i64_unop(op, 96, 2);
}
// #[test]
// fn test_i64add() {
// let op = I64ADD;
// test_i64_binop(op, 0, 0, 0);
// test_i64_binop(op, -1, -1, -2);
// test_i64_binop(op, 1, 1, 2);
// test_i64_binop(op, i64::MAX, 1, i64::MIN);
// }
#[test]
fn test_i64add() {
let op = I64ADD;
test_i64_binop(op, 0, 0, 0);
test_i64_binop(op, -1, -1, -2);
test_i64_binop(op, 1, 1, 2);
test_i64_binop(op, i64::MAX, 1, i64::MIN);
}
// #[test]
// fn test_i64sub() {
// let op = I64SUB;
// test_i64_binop(op, 0, 0, 0);
// test_i64_binop(op, -1, 1, -2);
// test_i64_binop(op, 1, 1, 0);
// test_i64_binop(op, i64::MIN, 1, i64::MAX);
// }
#[test]
fn test_i64sub() {
let op = I64SUB;
test_i64_binop(op, 0, 0, 0);
test_i64_binop(op, -1, 1, -2);
test_i64_binop(op, 1, 1, 0);
test_i64_binop(op, i64::MIN, 1, i64::MAX);
}
// #[test]
// fn test_i64mul() {
// let op = I64MUL;
// test_i64_binop(op, 0, 0, 0);
// test_i64_binop(op, -1, -1, 1);
// test_i64_binop(op, 2, 3, 6);
// test_i64_binop(op, i64::MAX, 2, -2);
// }
#[test]
fn test_i64mul() {
let op = I64MUL;
test_i64_binop(op, 0, 0, 0);
test_i64_binop(op, -1, -1, 1);
test_i64_binop(op, 2, 3, 6);
test_i64_binop(op, i64::MAX, 2, -2);
}
// #[test]
// fn test_i64divs() {
// let op = I64DIVS;
// test_i64_binop(op, -1, -1, 1);
// test_i64_binop(op, 6, 3, 2);
// test_i64_binop(op, i64::MIN, -1, i64::MIN);
// }
#[test]
fn test_i64divs() {
let op = I64DIVS;
test_i64_binop(op, -1, -1, 1);
test_i64_binop(op, 6, 3, 2);
test_i64_binop(op, i64::MIN, -1, i64::MIN);
}
// #[test]
// #[should_panic(expected = "divide by zero")]
// fn test_i64divs_zero() {
// test_i64_binop(I64DIVS, 1, 0, -1);
// }
#[test]
#[should_panic(expected = "divide by zero")]
fn test_i64divs_zero() {
test_i64_binop(I64DIVS, 1, 0, -1);
}
// #[test]
// fn test_i64divu() {
// let op = I64DIVU;
// test_u64_binop(op, 1, 1, 1);
// test_u64_binop(op, 6, 3, 2);
// }
#[test]
fn test_i64divu() {
let op = I64DIVU;
test_u64_binop(op, 1, 1, 1);
test_u64_binop(op, 6, 3, 2);
}
// #[test]
// #[should_panic(expected = "divide by zero")]
// fn test_i64divu_zero() {
// test_i64_binop(I64DIVU, 1, 0, -1);
// }
#[test]
#[should_panic(expected = "divide by zero")]
fn test_i64divu_zero() {
test_i64_binop(I64DIVU, 1, 0, -1);
}
// #[test]
// fn test_i64rems() {
// let op = I64REMS;
// test_i64_binop(op, 5, 2, 1);
// // test_i64_binop(op, 5, -2, 1); // TODO: we don't match Wasmer, we get 0
// test_i64_binop(op, -5, 2, -1);
// // test_i64_binop(op, -5, -2, -1); // TODO: we don't match Wasmer, we get 0
// }
#[test]
fn test_i64rems() {
let op = I64REMS;
test_i64_binop(op, 5, 2, 1);
// test_i64_binop(op, 5, -2, 1); // TODO: we don't match Wasmer, we get 0
test_i64_binop(op, -5, 2, -1);
// test_i64_binop(op, -5, -2, -1); // TODO: we don't match Wasmer, we get 0
}
// #[test]
// #[should_panic(expected = "divisor of zero")]
// fn test_i64rems_zero() {
// test_i64_binop(I64REMS, 1, 0, -1);
// }
#[test]
#[should_panic(expected = "divisor of zero")]
fn test_i64rems_zero() {
test_i64_binop(I64REMS, 1, 0, -1);
}
// #[test]
// fn test_i64remu() {
// let op = I64REMU;
// test_i64_binop(op, 5, 2, 1);
// }
#[test]
fn test_i64remu() {
let op = I64REMU;
test_i64_binop(op, 5, 2, 1);
}
// #[test]
// #[should_panic(expected = "divisor of zero")]
// fn test_i64remu_zero() {
// test_i64_binop(I64REMU, 1, 0, -1);
// }
#[test]
#[should_panic(expected = "divisor of zero")]
fn test_i64remu_zero() {
test_i64_binop(I64REMU, 1, 0, -1);
}
// #[test]
// fn test_i64and() {
// test_u64_binop(I64AND, 0x0000_ffff, 0x00ff_00ff, 0x0000_00ff);
// }
#[test]
fn test_i64and() {
test_u64_binop(
I64AND,
0x0000_0000_ffff_ffff,
0x0000_ffff_0000_ffff,
0x0000_0000_0000_ffff,
);
}
// #[test]
// fn test_i64or() {
// test_u64_binop(I64OR, 0x0000_ffff, 0x00ff_00ff, 0x00ff_ffff);
// }
#[test]
fn test_i64or() {
test_u64_binop(
I64OR,
0x0000_0000_ffff_ffff,
0x0000_ffff_0000_ffff,
0x0000_ffff_ffff_ffff,
);
}
// #[test]
// fn test_i64xor() {
// test_u64_binop(I64XOR, 0x0000_ffff, 0x00ff_00ff, 0x00ff_ff00);
// }
#[test]
fn test_i64xor() {
test_u64_binop(
I64XOR,
0x0000_0000_ffff_ffff,
0x0000_ffff_0000_ffff,
0x0000_ffff_ffff_0000,
);
}
// #[test]
// fn test_i64shl() {
// test_u64_binop(I64SHL, 0xffff_ffff, 8, 0xffff_ff00);
// test_u64_binop(I64SHL, 0xffff_ffff, 40, 0xffff_ff00);
// }
#[test]
fn test_i64shl() {
test_u64_binop(I64SHL, 0xffff_ffff_ffff_ffff, 8, 0xffff_ffff_ffff_ff00);
test_u64_binop(I64SHL, 0xffff_ffff_ffff_ffff, 72, 0xffff_ffff_ffff_ff00);
}
// #[test]
// fn test_i64shrs() {
// test_u64_binop(I64SHRS, 0xffff_0000, 8, 0xffff_ff00);
// test_u64_binop(I64SHRS, 0xffff_0000, 40, 0xffff_ff00);
// }
#[test]
#[ignore] // TODO: i64.const is encoding the wrong LEB bytes
fn test_i64shrs() {
test_u64_binop(I64SHRS, 0xffff_ffff_0000_0000, 8, 0xffff_ffff_ff00_0000);
test_u64_binop(I64SHRS, 0xffff_ffff_0000_0000, 72, 0xffff_ffff_ff00_0000);
}
// #[test]
// fn test_i64shru() {
// test_u64_binop(I64SHRU, 0xffff_0000, 8, 0x00ff_ff00);
// test_u64_binop(I64SHRU, 0xffff_0000, 40, 0x00ff_ff00);
// }
#[test]
#[ignore] // TODO: i64.const is encoding the wrong LEB bytes
fn test_i64shru() {
test_u64_binop(I64SHRU, 0xffff_ffff_0000_0000, 8, 0x00ff_ffff_ff00_0000);
test_u64_binop(I64SHRU, 0xffff_ffff_0000_0000, 72, 0x00ff_ffff_ff00_0000);
}
// #[test]
// fn test_i64rotl() {
// test_u64_binop(I64ROTL, 0xff00_0000, 4, 0xf000_000f);
// }
#[test]
#[ignore] // TODO: i64.const is encoding the wrong LEB bytes
fn test_i64rotl() {
test_u64_binop(I64ROTL, 0xff00_0000_0000_0000, 4, 0xf000_0000_0000_000f);
test_u64_binop(I64ROTL, 0xff00_0000_0000_0000, 68, 0xf000_0000_0000_000f);
}
// #[test]
// fn test_i64rotr() {
// test_u64_binop(I64ROTR, 0x0000_00ff, 4, 0xf000_000f);
// }
#[test]
fn test_i64rotr() {
test_u64_binop(I64ROTR, 0x0000_0000_0000_00ff, 4, 0xf000_0000_0000_000f);
test_u64_binop(I64ROTR, 0x0000_0000_0000_00ff, 68, 0xf000_0000_0000_000f);
}