cranelift: Implement float rounding operations (#4397)
Implements the following operations on the interpreter: * `ceil` * `floor` * `nearest` * `trunc`
This commit is contained in:
@@ -728,10 +728,10 @@ where
|
||||
(a, b) if a.is_zero()? && b.is_zero()? => a,
|
||||
(a, b) => a.max(b)?,
|
||||
}),
|
||||
Opcode::Ceil => unimplemented!("Ceil"),
|
||||
Opcode::Floor => unimplemented!("Floor"),
|
||||
Opcode::Trunc => unimplemented!("Trunc"),
|
||||
Opcode::Nearest => unimplemented!("Nearest"),
|
||||
Opcode::Ceil => assign(Value::ceil(arg(0)?)?),
|
||||
Opcode::Floor => assign(Value::floor(arg(0)?)?),
|
||||
Opcode::Trunc => assign(Value::trunc(arg(0)?)?),
|
||||
Opcode::Nearest => assign(Value::nearest(arg(0)?)?),
|
||||
Opcode::IsNull => unimplemented!("IsNull"),
|
||||
Opcode::IsInvalid => unimplemented!("IsInvalid"),
|
||||
Opcode::Trueif => choose(
|
||||
|
||||
@@ -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])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user