Implement IsubBin, IsubBout, and IsubBorrow

Implemented the following Opcodes for the Cranelift interpreter:
- `IsubBin` to subtract two scalar integers with an input borrow flag.
- `IsubBout` to subtract two scalar integers with an output borrow flag.
- `IsubBorrow` to subtract two scalar integers with an input and output borrow flag.

Copyright (c) 2021, Arm Limited
This commit is contained in:
dheaton-arm
2021-08-16 11:43:16 +01:00
parent 7b8ab065c6
commit 721cfc16b3
4 changed files with 229 additions and 3 deletions

View File

@@ -460,11 +460,28 @@ where
Opcode::IaddIfcout => unimplemented!("IaddIfcout"),
Opcode::IaddCarry => unimplemented!("IaddCarry"),
Opcode::IaddIfcarry => unimplemented!("IaddIfcarry"),
Opcode::IsubBin => unimplemented!("IsubBin"),
Opcode::IsubBin => choose(
Value::into_bool(arg(2)?)?,
Value::sub(arg(0)?, Value::add(arg(1)?, Value::int(1, ctrl_ty)?)?)?,
Value::sub(arg(0)?, arg(1)?)?,
),
Opcode::IsubIfbin => unimplemented!("IsubIfbin"),
Opcode::IsubBout => unimplemented!("IsubBout"),
Opcode::IsubBout => {
let sum = Value::sub(arg(0)?, arg(1)?)?;
let borrow = Value::lt(&arg(0)?, &arg(1)?)?;
assign_multiple(&[sum, Value::bool(borrow, types::B1)?])
}
Opcode::IsubIfbout => unimplemented!("IsubIfbout"),
Opcode::IsubBorrow => unimplemented!("IsubBorrow"),
Opcode::IsubBorrow => {
let rhs = if Value::into_bool(arg(2)?)? {
Value::add(arg(1)?, Value::int(1, ctrl_ty)?)?
} else {
arg(1)?
};
let borrow = Value::lt(&arg(0)?, &rhs)?;
let sum = Value::sub(arg(0)?, rhs)?;
assign_multiple(&[sum, Value::bool(borrow, types::B1)?])
}
Opcode::IsubIfborrow => unimplemented!("IsubIfborrow"),
Opcode::Band => binary(Value::and, arg(0)?, arg(1)?)?,
Opcode::Bor => binary(Value::or, arg(0)?, arg(1)?)?,