Fix interpreter semantics of 'irsub_imm'

Previously it used `arg - imm` but the functionality should be a wrapping `imm - arg` (see `cranelift/codegen/meta/src/shared/instructions.rs`).
This commit is contained in:
Andrew Brown
2020-05-27 20:23:56 -07:00
committed by Benjamin Bouvier
parent fbac2e53f9
commit b017844bef
2 changed files with 8 additions and 8 deletions

View File

@@ -163,7 +163,7 @@ impl Interpreter {
let arg = frame.get(&arg);
let result = match opcode {
IaddImm => binary_op!(Add::add[arg, imm]; [I8, I16, I32, I64, F32, F64]; inst),
IrsubImm => binary_op!(Sub::sub[arg, imm]; [I8, I16, I32, I64, F32, F64]; inst),
IrsubImm => binary_op!(Sub::sub[imm, arg]; [I8, I16, I32, I64, F32, F64]; inst),
_ => unimplemented!("interpreter does not support opcode yet: {}", opcode),
}?;
frame.set(first_result(frame.function, inst), result);
@@ -349,9 +349,9 @@ mod tests {
fn sanity() {
let code = "function %test() -> b1 {
block0:
v0 = iconst.i32 40
v1 = iadd_imm v0, 3
v2 = irsub_imm v1, 1
v0 = iconst.i32 1
v1 = iadd_imm v0, 1
v2 = irsub_imm v1, 44 ; 44 - 2 == 42 (see irsub_imm's semantics)
v3 = icmp_imm eq v2, 42
return v3
}";