Skip to content

Commit

Permalink
x64: refactor EVEX encodings to use EvexInstruction
Browse files Browse the repository at this point in the history
This change replaces the `encode_evex` function with a builder-style struct, `EvexInstruction`. This approach clarifies the code, adds documentation, and results in slight speedups when benchmarked.
  • Loading branch information
abrown committed Apr 15, 2021
1 parent 2f73d66 commit edb142b
Show file tree
Hide file tree
Showing 4 changed files with 365 additions and 87 deletions.
30 changes: 15 additions & 15 deletions cranelift/codegen/src/isa/x64/inst/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use crate::isa::x64::inst::args::*;
use crate::isa::x64::inst::*;
use crate::machinst::{inst_common, MachBuffer, MachInstEmit, MachLabel};
use core::convert::TryInto;
use cranelift_codegen_shared::isa::x86::EncodingBits;
use encoding::evex::{encode_evex, EvexContext, EvexMasking};
use encoding::evex::{EvexInstruction, EvexVectorLength};
use encoding::rex::{
emit_simm, emit_std_enc_enc, emit_std_enc_mem, emit_std_reg_mem, emit_std_reg_reg, int_reg_enc,
low8_will_sign_extend_to_32, low8_will_sign_extend_to_64, reg_enc, LegacyPrefixes, RexFlags,
low8_will_sign_extend_to_32, low8_will_sign_extend_to_64, reg_enc, LegacyPrefixes, OpcodeMap,
RexFlags,
};
use log::debug;
use regalloc::{Reg, Writable};
Expand Down Expand Up @@ -1407,21 +1407,21 @@ pub(crate) fn emit(
}

Inst::XmmUnaryRmREvex { op, src, dst } => {
let bits = match op {
&Avx512Opcode::Vpabsq => EncodingBits::new(&[0x66, 0x0f, 0x38, 0x1f], 0, 1),
let opcode = match op {
Avx512Opcode::Vpabsq => 0x1f,
};
match src {
RegMem::Reg { reg: src } => encode_evex(
bits,
dst.to_reg().get_hw_encoding(),
0,
src.get_hw_encoding(),
EvexContext::v128(),
EvexMasking::default(),
sink,
),
RegMem::Reg { reg: src } => EvexInstruction::new()
.length(EvexVectorLength::V128)
.prefix(LegacyPrefixes::_66)
.map(OpcodeMap::_0F38)
.w(true)
.opcode(opcode)
.reg(dst.to_reg().get_hw_encoding())
.rm(src.get_hw_encoding())
.encode(sink),
_ => todo!(),
}
};
}

Inst::XmmRmR {
Expand Down
Loading

0 comments on commit edb142b

Please sign in to comment.