Skip to content

Commit c26a65a

Browse files
authored
x64: Add most remaining AVX lowerings (bytecodealliance#5819)
* x64: Add most remaining AVX lowerings This commit goes through `inst.isle` and adds a corresponding AVX lowering for most SSE lowerings. I opted to skip instructions where the SSE lowering didn't read/modify a register, such as `roundps`. I think that AVX will benefit these instructions when there's load-merging since AVX doesn't require alignment, but I've deferred that work to a future PR. Otherwise though in this PR I think all (or almost all) of the 3-operand forms of AVX instructions are supported with their SSE counterparts. This should ideally improve codegen slightly by removing register pressure and the need for `movdqa` between registers. I've attempted to ensure that there's at least one codegen test for all the new instructions. As a side note, the recent capstone integration into `precise-output` tests helped me catch a number of encoding bugs much earlier than otherwise, so I've found that incredibly useful in tests! * Move `vpinsr*` instructions to their own variant Use true `XmmMem` and `GprMem` types in the instruction as well to get more type-level safety for what goes where. * Remove `Inst::produces_const` accessor Instead of conditionally defining regalloc and various other operations instead add dedicated `MInst` variants for operations which are intended to produce a constant to have more clear interactions with regalloc and printing and such. * Fix tests * Register traps in `MachBuffer` for load-folding ops This adds a missing `add_trap` to encoding of VEX instructions with memory operands to ensure that if they cause a segfault that there's appropriate metadata for Wasmtime to understand that the instruction could in fact trap. This fixes a fuzz test case found locally where v8 trapped and Wasmtime didn't catch the signal and crashed the fuzzer.
1 parent ad128b6 commit c26a65a

File tree

16 files changed

+4144
-465
lines changed

16 files changed

+4144
-465
lines changed

cranelift/codegen/src/isa/x64/encoding/vex.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use super::evex::Register;
55
use super::rex::{LegacyPrefixes, OpcodeMap};
66
use super::ByteSink;
7+
use crate::ir::TrapCode;
78
use crate::isa::x64::args::Amode;
89
use crate::isa::x64::encoding::rex;
910
use crate::isa::x64::inst::Inst;
@@ -267,6 +268,12 @@ impl VexInstruction {
267268

268269
/// Emit the VEX-encoded instruction to the provided buffer.
269270
pub fn encode(&self, sink: &mut MachBuffer<Inst>) {
271+
if let RegisterOrAmode::Amode(amode) = &self.rm {
272+
if amode.can_trap() {
273+
sink.add_trap(TrapCode::HeapOutOfBounds);
274+
}
275+
}
276+
270277
// 2/3 byte prefix
271278
if self.use_2byte_prefix() {
272279
self.encode_2byte_prefix(sink);

0 commit comments

Comments
 (0)