[PATCH v2 06/13] x86/kvm/emulate: Introduce COP2CL

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

Replace the FASTOP2CL instructions.

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

--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -344,6 +344,15 @@ static int em_##op(struct x86_emulate_ct
ON64(case 8: COP_ASM2(op##q, rax, rdx); break;) \
COP_END

+/* 2-operand, using "a" (dst) and CL (src2) */
+#define COP2CL(op) \
+ COP_START(op) \
+ case 1: COP_ASM2(op##b, al, cl); break; \
+ case 2: COP_ASM2(op##w, ax, cl); break; \
+ case 4: COP_ASM2(op##l, eax, cl); break; \
+ ON64(case 8: COP_ASM2(op##q, rax, cl); break;) \
+ COP_END
+
/*
* fastop functions have a special calling convention:
*
@@ -1080,13 +1089,13 @@ COP1(neg);
COP1(inc);
COP1(dec);

-FASTOP2CL(rol);
-FASTOP2CL(ror);
-FASTOP2CL(rcl);
-FASTOP2CL(rcr);
-FASTOP2CL(shl);
-FASTOP2CL(shr);
-FASTOP2CL(sar);
+COP2CL(rol);
+COP2CL(ror);
+COP2CL(rcl);
+COP2CL(rcr);
+COP2CL(shl);
+COP2CL(shr);
+COP2CL(sar);

COP2W(bsf);
COP2W(bsr);
@@ -4079,14 +4088,14 @@ static const struct opcode group1A[] = {
};

static const struct opcode group2[] = {
- F(DstMem | ModRM, em_rol),
- F(DstMem | ModRM, em_ror),
- F(DstMem | ModRM, em_rcl),
- F(DstMem | ModRM, em_rcr),
- F(DstMem | ModRM, em_shl),
- F(DstMem | ModRM, em_shr),
- F(DstMem | ModRM, em_shl),
- F(DstMem | ModRM, em_sar),
+ I(DstMem | ModRM, em_rol),
+ I(DstMem | ModRM, em_ror),
+ I(DstMem | ModRM, em_rcl),
+ I(DstMem | ModRM, em_rcr),
+ I(DstMem | ModRM, em_shl),
+ I(DstMem | ModRM, em_shr),
+ I(DstMem | ModRM, em_shl),
+ I(DstMem | ModRM, em_sar),
};

static const struct opcode group3[] = {