cranelift: Implement float rounding operations (#4397)

Implements the following operations on the interpreter:
* `ceil`
* `floor`
* `nearest`
* `trunc`
This commit is contained in:
Afonso Bordado
2022-07-07 00:43:54 +01:00
committed by GitHub
parent 9575ed4eb7
commit f98076ae88
7 changed files with 540 additions and 4 deletions

View File

@@ -60,6 +60,10 @@ pub trait Value: Clone + From<DataValue> {
// Float operations
fn neg(self) -> ValueResult<Self>;
fn copysign(self, sign: Self) -> ValueResult<Self>;
fn ceil(self) -> ValueResult<Self>;
fn floor(self) -> ValueResult<Self>;
fn trunc(self) -> ValueResult<Self>;
fn nearest(self) -> ValueResult<Self>;
// Saturating arithmetic.
fn add_sat(self, other: Self) -> ValueResult<Self>;
@@ -517,6 +521,22 @@ impl Value for DataValue {
binary_match!(copysign(&self, &sign); [F32, F64])
}
fn ceil(self) -> ValueResult<Self> {
unary_match!(ceil(&self); [F32, F64])
}
fn floor(self) -> ValueResult<Self> {
unary_match!(floor(&self); [F32, F64])
}
fn trunc(self) -> ValueResult<Self> {
unary_match!(trunc(&self); [F32, F64])
}
fn nearest(self) -> ValueResult<Self> {
unary_match!(nearest(&self); [F32, F64])
}
fn add_sat(self, other: Self) -> ValueResult<Self> {
binary_match!(saturating_add(self, &other); [I8, I16, I32, I64, I128, U8, U16, U32, U64, U128])
}