cranelift: Fix iadd_carry/iadd_cout in the interpreter (#5176)

This commit is contained in:
Afonso Bordado
2022-11-14 18:18:28 +00:00
committed by GitHub
parent d3692c2f2b
commit ff46bbaebf
4 changed files with 23 additions and 4 deletions

View File

@@ -56,6 +56,7 @@ pub trait Value: Clone + From<DataValue> {
fn sqrt(self) -> ValueResult<Self>;
fn fma(self, a: Self, b: Self) -> ValueResult<Self>;
fn abs(self) -> ValueResult<Self>;
fn checked_add(self, other: Self) -> ValueResult<Option<Self>>;
// Float operations
fn neg(self) -> ValueResult<Self>;
@@ -187,6 +188,12 @@ macro_rules! binary_match {
_ => unimplemented!()
}
};
( option $op:ident($arg1:expr, $arg2:expr); [ $( $data_value_ty:ident ),* ] ) => {
match ($arg1, $arg2) {
$( (DataValue::$data_value_ty(a), DataValue::$data_value_ty(b)) => { Ok(a.$op(*b).map(DataValue::$data_value_ty)) } )*
_ => unimplemented!()
}
};
( $op:tt($arg1:expr, $arg2:expr); [ $( $data_value_ty:ident ),* ] ) => {
match ($arg1, $arg2) {
$( (DataValue::$data_value_ty(a), DataValue::$data_value_ty(b)) => { Ok(DataValue::$data_value_ty(a $op b)) } )*
@@ -615,6 +622,10 @@ impl Value for DataValue {
unary_match!(abs(&self); [F32, F64])
}
fn checked_add(self, other: Self) -> ValueResult<Option<Self>> {
binary_match!(option checked_add(&self, &other); [I8, I16, I32, I64, I128, U8, U16, U32, U64, U128])
}
fn neg(self) -> ValueResult<Self> {
unary_match!(neg(&self); [F32, F64])
}