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 thediv
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 thediv
andidiv
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:
- When
avoid_div_traps=true
, traps are no longer emitted fordiv
instructions.- The
udiv
/urem
instructions now list their trap as divide-by-zero instead of integer overflow.- The lowering for
sdiv
was updated to still explicitly check for zero but the integer overflow case is deferred to the instruction itself.- The lowering of
srem
no longer checks for zero and the listed trap for thediv
instruction is a divide-by-zero.This means that the codegen for
udiv
andurem
no longer have any branches. The codegen forsdiv
removes one branch but keeps the zero-check to differentiate the two kinds of traps. The codegen forsrem
removes one branch but keeps the -1 check since the semantics ofsrem
mismatch with the semantics ofidiv
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.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
cfallin submitted PR review.
cfallin submitted PR review.
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 theEmitState
and would also place this conditional logic closer to where the rest of the instruction sequence is specified.
alexcrichton updated PR #6026 from x64-sigfpe
to main
.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Ah good suggestion!
alexcrichton updated PR #6026 from x64-sigfpe
to main
.
alexcrichton updated PR #6026 from x64-sigfpe
to main
.
cfallin submitted PR review.
alexcrichton updated PR #6026 from x64-sigfpe
to main
.
alexcrichton has enabled auto merge for PR #6026.
alexcrichton merged PR #6026.
Last updated: Dec 23 2024 at 12:05 UTC