[PATCH v2 08/13] x86/kvm/emulate: Introduce COP3WCL

Peter Zijlstra
2025-04-30T11:26:47Z

Replace the FASTOP3WCL instructions.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
arch/x86/kvm/emulate.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)

--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -302,6 +302,9 @@ static int em_##op(struct x86_emulate_ct
#define COP_ASM2(op, dst, src) \
COP_ASM(#op " %%" #src ", %%" #dst " \n\t")

+#define COP_ASM3(op, dst, src, src2) \
+ COP_ASM(#op " %%" #src2 ", %%" #src ", %%" #dst " \n\t")
+
#define COP_END \
} \
ctxt->eflags = (ctxt->eflags & ~EFLAGS_MASK) | (flags & EFLAGS_MASK); \
@@ -371,6 +374,16 @@ static int em_##op(struct x86_emulate_ct
ON64(case 8: COP_ASM2(op##q, rax, cl); break;) \
COP_END

+/* 3-operand, using "a" (dst), "d" (src) and CL (src2) */
+#define COP3WCL(op) \
+ COP_START(op) \
+ case 1: break; \
+ case 2: COP_ASM3(op##w, ax, dx, cl); break; \
+ case 4: COP_ASM3(op##l, eax, edx, cl); break; \
+ ON64(case 8: COP_ASM3(op##q, rax, rdx, cl); break;) \
+ COP_END
+
+
/*
* fastop functions have a special calling convention:
*
@@ -1097,8 +1110,8 @@ COP1SRC2(imul, imul_ex);
COP1SRC2EX(div, div_ex);
COP1SRC2EX(idiv, idiv_ex);

-FASTOP3WCL(shld);
-FASTOP3WCL(shrd);
+COP3WCL(shld);
+COP3WCL(shrd);

COP2W(imul);

@@ -4496,14 +4509,14 @@ static const struct opcode twobyte_table
I(Stack | Src2FS, em_push_sreg), I(Stack | Src2FS, em_pop_sreg),
II(ImplicitOps, em_cpuid, cpuid),
I(DstMem | SrcReg | ModRM | BitOp | NoWrite, em_bt),
- F(DstMem | SrcReg | Src2ImmByte | ModRM, em_shld),
- F(DstMem | SrcReg | Src2CL | ModRM, em_shld), N, N,
+ I(DstMem | SrcReg | Src2ImmByte | ModRM, em_shld),
+ I(DstMem | SrcReg | Src2CL | ModRM, em_shld), N, N,
/* 0xA8 - 0xAF */
I(Stack | Src2GS, em_push_sreg), I(Stack | Src2GS, em_pop_sreg),
II(EmulateOnUD | ImplicitOps, em_rsm, rsm),
I(DstMem | SrcReg | ModRM | BitOp | Lock | PageTable, em_bts),
- F(DstMem | SrcReg | Src2ImmByte | ModRM, em_shrd),
- F(DstMem | SrcReg | Src2CL | ModRM, em_shrd),
+ I(DstMem | SrcReg | Src2ImmByte | ModRM, em_shrd),
+ I(DstMem | SrcReg | Src2CL | ModRM, em_shrd),
GD(0, &group15), I(DstReg | SrcMem | ModRM, em_imul),
/* 0xB0 - 0xB7 */
I2bv(DstMem | SrcReg | ModRM | Lock | PageTable | SrcWrite, em_cmpxchg),