Stream: cranelift

Topic: Floating point compare-and-branch?


view this post on Zulip osa1 (May 16 2020 at 15:40):

As far as I can see we don't have anything like br_icmp for floats, right? Do I have to use x = ffcmp(...); brff(cond, x, target) ?

view this post on Zulip osa1 (May 16 2020 at 15:42):

Currently I'm generating this:

block0(v0: i64, v1: f64, v2: f64, v3: f64):
    v4 = ffcmp v2, v1
    brff le v4, block1
    jump block2

view this post on Zulip osa1 (May 16 2020 at 15:42):

But it fails with Compilation(Verifier(VerifierErrors([VerifierError { location: inst1, context: Some("brff le v4, block1"), message: "Branch must have an encoding" }])))

view this post on Zulip bjorn3 (May 16 2020 at 16:31):

You should normally use icmp + brz/brnz instead of br_icmp. For floats that is fcmp + brz/brnz. The brz instruction jumps when the argument is false or zero. The brnz instruction jumps when the argument is true or non-zero.

view this post on Zulip osa1 (May 16 2020 at 16:35):

"You should" <-- why? It's easier with one instruction.

view this post on Zulip bjorn3 (May 16 2020 at 16:56):

There is an optimization pass that does this for you: https://github.com/bytecodealliance/wasmtime/blob/49622bde586deeb8400529fd61bf5bf1abab38e3/cranelift/codegen/src/postopt.rs#L134

Standalone JIT-style runtime for WebAssembly, using Cranelift - bytecodealliance/wasmtime

Last updated: Dec 23 2024 at 13:07 UTC