forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x64: Add support for some BMI2 instructions (bytecodealliance#6976)
* x64: Add support for sarx, shlx, and shrx These instructions are in the BMI2 instruction set and unconditionally used by LLVM for shifts which don't have an immediate. They're equivalent to the sar, shl, and shr instructions except they use 3-operand form to lessen register allocation pressure. Currently the integration here doesn't add new lowering but instead takes an AVX-like approach by updating the `x64_sar` and related helpers to use `sarx` instead if it fits. This means that the shift-a-value-stored-in-memory functionality of `sarx` and friends isn't exposed, so that's left for a future PR. * x64: Add support for BMI2 `rorx` instruction This is similar to `rol` and `ror` but requires an immediate argument and additionally has no constraints on registers. * x64: Add support for BMI2 `bzhi` instruction This commit adds support for the `bzhi` instruction which is part of BMI2. This instruction is used to zero out the upper bits of a register indexed by a register operand. Emission of this instruction is pattern-matched on CLIF which looks like this pattern. Equivalent code fed to LLVM will additionally generate the `bzhi` instruction. Relative to the alternative lowerings x64 provides this gives a little bit more register freedom and additionally cuts down on a few instructions. Note that the raw functionality of `bzhi` can't be exposed though because the semantics of when the index is out-of-bounds doesn't match easily to a CLIF instruction, so usage of `bzhi` is always preceded by an `and` instruction. This matches LLVM as well, but LLVM probably has fancy logic where if it can prove the range of values of the index it probably elides the `and`. * Pattern match more `x - 1` patterns Looks like LLVM generates this as `x + (-1)` which is equivalent to `x - 1` so create a custom partial constructor to pattern match the possibilities of a decremented value. * Add tests for BMI{1,2} coming from wasm These are intended to serve as integration tests to ensure that even coming from wasm these instructions are all emitted.
- Loading branch information
1 parent
f751a89
commit 2794dd3
Showing
18 changed files
with
1,113 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.