Stream: cranelift

Topic: Overflow detection


view this post on Zulip Yorick Peterse (Nov 14 2022 at 22:05):

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

view this post on Zulip Jamey Sharp (Nov 14 2022 at 23:07):

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.

👋 Hey, This PR adds lowerings for iadd_cout on the aarch64 backend. It's based on #5176 since it found an existing bug with the interpreter. But I've opened that as a separate PR so that its easier...

view this post on Zulip Afonso Bordado (Nov 15 2022 at 10:24):

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).

No description provided.

view this post on Zulip Yorick Peterse (Nov 15 2022 at 15:02):

Thanks, I'll take a look at the links :smile:


Last updated: Dec 23 2024 at 12:05 UTC