Stream: git-wasmtime

Topic: wasmtime / PR #6026 x64: Take SIGFPE signals for divide t...


view this post on Zulip Wasmtime GitHub notifications bot (Mar 15 2023 at 17:44):

alexcrichton opened PR #6026 from x64-sigfpe to main:

Prior to this commit Wasmtime would configure avoid_div_traps=true unconditionally for Cranelift. This, for the division-based instructions, would change emitted code to explicitly trap on trap conditions instead of letting the div x86 instruction trap.

There's no specific reason for Wasmtime, however, to specifically avoid traps in the div instruction. This means that the extra generated branches on x86 aren't necessary since the div and idiv instructions already trap for similar conditions as wasm requires.

This commit instead disables the avoid_div_traps setting for Wasmtime's usage of Cranelift. Subsequently the codegen rules were updated slightly:

This means that the codegen for udiv and urem no longer have any branches. The codegen for sdiv removes one branch but keeps the zero-check to differentiate the two kinds of traps. The codegen for srem removes one branch but keeps the -1 check since the semantics of srem mismatch with the semantics of idiv with a -1 divisor (specifically for INT_MIN).

This is unlikely to have really all that much of a speedup but was something I noticed during #6008 which seemed like it'd be good to clean up. Plus Wasmtime's signal handling was already set up to catch SIGFPE, it was just never firing.

<!--

Please ensure that the following steps are all taken care of before submitting
the PR.

Please ensure all communication adheres to the code of conduct.
-->

view this post on Zulip Wasmtime GitHub notifications bot (Mar 15 2023 at 18:52):

cfallin submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 15 2023 at 18:52):

cfallin submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 15 2023 at 18:52):

cfallin created PR review comment:

I wonder if it would be simpler to include a trap_code field in the instruction, and set this when creating it in the lowering? That would avoid the implicit state flow via the flag on the EmitState and would also place this conditional logic closer to where the rest of the instruction sequence is specified.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 15 2023 at 22:16):

alexcrichton updated PR #6026 from x64-sigfpe to main.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 15 2023 at 22:18):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 15 2023 at 22:18):

alexcrichton created PR review comment:

Ah good suggestion!

view this post on Zulip Wasmtime GitHub notifications bot (Mar 15 2023 at 22:44):

alexcrichton updated PR #6026 from x64-sigfpe to main.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 15 2023 at 22:50):

alexcrichton updated PR #6026 from x64-sigfpe to main.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 15 2023 at 23:40):

cfallin submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 15 2023 at 23:45):

alexcrichton updated PR #6026 from x64-sigfpe to main.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 15 2023 at 23:59):

alexcrichton has enabled auto merge for PR #6026.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 16 2023 at 00:59):

alexcrichton merged PR #6026.


Last updated: Oct 23 2024 at 20:03 UTC