Skip to content

Commit

Permalink
x64: Use 4 register Vex Inst
Browse files Browse the repository at this point in the history
  • Loading branch information
afonso360 committed Jul 25, 2022
1 parent 10d2da2 commit a61b6b0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
25 changes: 16 additions & 9 deletions cranelift/codegen/src/isa/x64/inst.isle
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@

;; XMM (scalar or vector) binary op that relies on the VEX prefix.
(XmmRmRVex (op AvxOpcode)
(src1 XmmMem)
(src1 Xmm)
(src2 Xmm)
(src3 XmmMem)
(dst WritableXmm))

;; XMM (scalar or vector) binary op that relies on the EVEX prefix.
Expand Down Expand Up @@ -2815,21 +2816,27 @@
(_ Unit (emit (MInst.XmmRmR (SseOpcode.Maxpd) x y dst))))
dst))


;; Helper for creating `MInst.XmmRmRVex` instructions.
(decl xmm_rmr_vex (AvxOpcode Xmm Xmm XmmMem) Xmm)
(rule (xmm_rmr_vex op src1 src2 src3)
(let ((dst WritableXmm (temp_writable_xmm))
(_ Unit (emit (MInst.XmmRmRVex op
src1
src2
src3
dst))))
dst))

;; Helper for creating `vfmadd213ps` instructions.
(decl x64_vfmadd213ps (Xmm Xmm XmmMem) Xmm)
(rule (x64_vfmadd213ps x y z)
(let ((dst WritableXmm (temp_writable_xmm))
(_1 Unit (emit (MInst.XmmUnaryRmR (SseOpcode.Movups) x dst)))
(_2 Unit (emit (MInst.XmmRmRVex (AvxOpcode.Vfmadd213ps) z y dst))))
dst))
(xmm_rmr_vex (AvxOpcode.Vfmadd213ps) x y z))

;; Helper for creating `vfmadd213pd` instructions.
(decl x64_vfmadd213pd (Xmm Xmm XmmMem) Xmm)
(rule (x64_vfmadd213pd x y z)
(let ((dst WritableXmm (temp_writable_xmm))
(_1 Unit (emit (MInst.XmmUnaryRmR (SseOpcode.Movups) x dst)))
(_2 Unit (emit (MInst.XmmRmRVex (AvxOpcode.Vfmadd213pd) z y dst))))
dst))
(xmm_rmr_vex (AvxOpcode.Vfmadd213pd) x y z))


;; Helper for creating `sqrtss` instructions.
Expand Down
7 changes: 5 additions & 2 deletions cranelift/codegen/src/isa/x64/inst/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1695,18 +1695,21 @@ pub(crate) fn emit(
op,
src1,
src2,
src3,
dst,
} => {
let src1 = allocs.next(src1.to_reg());
let dst = allocs.next(dst.to_reg().to_reg());
debug_assert_eq!(src1, dst);
let src2 = allocs.next(src2.to_reg());
let src1 = src1.clone().to_reg_mem().with_allocs(allocs);
let src3 = src3.clone().to_reg_mem().with_allocs(allocs);

let (w, opcode) = match op {
AvxOpcode::Vfmadd213ps => (false, 0xA8),
AvxOpcode::Vfmadd213pd => (true, 0xA8),
};

match src1 {
match src3 {
RegMem::Reg { reg: src } => VexInstruction::new()
.length(VexVectorLength::V128)
.prefix(LegacyPrefixes::_66)
Expand Down
21 changes: 16 additions & 5 deletions cranelift/codegen/src/isa/x64/inst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,13 +1147,23 @@ impl PrettyPrint for Inst {
op,
src1,
src2,
src3,
dst,
..
} => {
let src3 = src3.pretty_print(8, allocs);
let src2 = pretty_print_reg(src2.to_reg(), 8, allocs);
let src1 = pretty_print_reg(src1.to_reg(), 8, allocs);
let dst = pretty_print_reg(dst.to_reg().to_reg(), 8, allocs);
let src1 = src1.pretty_print(8, allocs);
format!("{} {}, {}, {}", ljustify(op.to_string()), src1, src2, dst)

format!(
"{} {}, {}, {}, {}",
ljustify(op.to_string()),
src1,
src2,
src3,
dst
)
}

Inst::XmmRmREvex {
Expand Down Expand Up @@ -1864,6 +1874,7 @@ fn x64_get_operands<F: Fn(VReg) -> VReg>(inst: &Inst, collector: &mut OperandCol
op,
src1,
src2,
src3,
dst,
..
} => {
Expand All @@ -1872,10 +1883,10 @@ fn x64_get_operands<F: Fn(VReg) -> VReg>(inst: &Inst, collector: &mut OperandCol
// register uses.
assert!(*op == AvxOpcode::Vfmadd213ps || *op == AvxOpcode::Vfmadd213pd);

// We both use and def dst
collector.reg_mod(dst.to_writable_reg());
collector.reg_use(src1.to_reg());
collector.reg_reuse_def(dst.to_writable_reg(), 0);
collector.reg_use(src2.to_reg());
src1.get_operands(collector);
src3.get_operands(collector);
}
Inst::XmmRmREvex {
op,
Expand Down

0 comments on commit a61b6b0

Please sign in to comment.