cranelift: Implement float rounding operations in interpreter#4397
cranelift: Implement float rounding operations in interpreter#4397cfallin merged 1 commit intobytecodealliance:mainfrom
Conversation
|
Merge conflict, happy to merge once resolved! |
Implements the following operations on the interpreter: * `ceil` * `floor` * `nearest` * `trunc`
d86b5a6 to
d8e181b
Compare
|
|
||
| /// Returns the nearest integer to `self`. Round half-way cases away from `0.0`. | ||
| pub fn nearest(self) -> Self { | ||
| Self::with_float(self.as_f32().round()) |
There was a problem hiding this comment.
round is not the same as nearest. I think I once implemented the correct & efficient "nearest" in the past: #2171
There was a problem hiding this comment.
Ah, sorry I missed this... @afonso360 could you look into this further?
There was a problem hiding this comment.
Rust has not had this operation for very many years. Here it seems someone finally want to add it:
rust-lang/rust#95317
There was a problem hiding this comment.
Oh wow! Great catch!
Is there a simple way to organize the code so that we can reuse that implementation?
I'm not sure we can use nightly features in wasmtime/cranelift.
Otherwise we can probably duplicate the function pending stabilization of the rust implementation.
As @MaxGraey pointed out (thanks!) in bytecodealliance#4397, `round` has different behavior from `nearest`. And it looks like the native rust implementation is still pending stabilization. Right now we duplicate the wasmtime implementation, merged in bytecodealliance#2171. However, we definitely should switch to the rust native version when it is available.
As @MaxGraey pointed out (thanks!) in #4397, `round` has different behavior from `nearest`. And it looks like the native rust implementation is still pending stabilization. Right now we duplicate the wasmtime implementation, merged in #2171. However, we definitely should switch to the rust native version when it is available.
👋 Hey,
This PR implements the following operations on the interpreter:
ceilfloornearesttrunc