cranelift: Implement overflow flags for icmp in interpreter

This commit is contained in:
Afonso Bordado
2021-07-05 09:34:48 +01:00
committed by Andrew Brown
parent c42b725ce9
commit 04033fe645
3 changed files with 230 additions and 2 deletions

View File

@@ -720,8 +720,8 @@ where
&left.clone().convert(ValueConversionKind::ToUnsigned)?,
&right.clone().convert(ValueConversionKind::ToUnsigned)?,
)?,
IntCC::Overflow => unimplemented!("IntCC::Overflow"),
IntCC::NotOverflow => unimplemented!("IntCC::NotOverflow"),
IntCC::Overflow => Value::of(left, right)?,
IntCC::NotOverflow => !Value::of(left, right)?,
})
}

View File

@@ -37,6 +37,7 @@ pub trait Value: Clone + From<DataValue> {
Ok(other.eq(self)? || other.gt(self)?)
}
fn uno(&self, other: &Self) -> ValueResult<bool>;
fn of(&self, other: &Self) -> ValueResult<bool>;
// Arithmetic.
fn add(self, other: Self) -> ValueResult<Self>;
@@ -277,6 +278,16 @@ impl Value for DataValue {
Ok(self.is_nan()? || other.is_nan()?)
}
fn of(&self, other: &Self) -> ValueResult<bool> {
Ok(match (self, other) {
(DataValue::I8(a), DataValue::I8(b)) => a.checked_sub(*b).is_none(),
(DataValue::I16(a), DataValue::I16(b)) => a.checked_sub(*b).is_none(),
(DataValue::I32(a), DataValue::I32(b)) => a.checked_sub(*b).is_none(),
(DataValue::I64(a), DataValue::I64(b)) => a.checked_sub(*b).is_none(),
_ => unimplemented!(),
})
}
fn add(self, other: Self) -> ValueResult<Self> {
binary_match!(wrapping_add(&self, &other); [I8, I16, I32, I64]) // TODO: floats must handle NaNs, +/-0
}