Does Cranelift have any instructions for performing checked integer operations (e.g. checked_add
, checked_div
, etc)? One can emulate it since Cranelift integers wrap around, but it would be nice to take advantage of whatever optimised routines there may be
Sort of: there are some variants of integer addition and subtraction instructions with carry/borrow outputs that you could use to implement an equivalent of Rust's checked_add
and checked_sub
. I don't know if they're implemented on any backends (see for example https://github.com/bytecodealliance/wasmtime/pull/5177), and I don't know if there are equivalents for any other arithmetic.
Right now we have iadd_cout and isub_bout and there is a open issue about adding more for multiplication and bit shifts
I've been (slowly) working on implementing at least iadd_* and isub_* on our backends since these are currently only working on the interpreter (and the one PR for AArch64).
Thanks, I'll take a look at the links :smile:
Last updated: Nov 22 2024 at 17:03 UTC