Skip to content

Commit fe08478

Browse files
committed
KVM: selftests: Dedup the gnarly constraints of the fastops tests (more macros!)
Add a fastop() macro along with macros to define its required constraints, and use the macros to dedup the innermost guts of the fastop testcases. No functional change intended. Link: https://lore.kernel.org/r/20250909202835.333554-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 9bf5da1 commit fe08478

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

tools/testing/selftests/kvm/x86/fastops_test.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@
88
* to set RFLAGS.CF based on whether or not the input is even or odd, so that
99
* instructions like ADC and SBB are deterministic.
1010
*/
11+
#define fastop(__insn) \
12+
"bt $0, %[bt_val]\n\t" \
13+
__insn "\n\t" \
14+
"pushfq\n\t" \
15+
"pop %[flags]\n\t"
16+
17+
#define flags_constraint(flags_val) [flags]"=r"(flags_val)
18+
#define bt_constraint(__bt_val) [bt_val]"rm"((uint32_t)__bt_val)
19+
1120
#define guest_execute_fastop_1(FEP, insn, __val, __flags) \
1221
({ \
13-
__asm__ __volatile__("bt $0, %[ro_val]\n\t" \
14-
FEP insn " %[val]\n\t" \
15-
"pushfq\n\t" \
16-
"pop %[flags]\n\t" \
17-
: [val]"+r"(__val), [flags]"=r"(__flags) \
18-
: [ro_val]"rm"((uint32_t)__val) \
22+
__asm__ __volatile__(fastop(FEP insn " %[val]") \
23+
: [val]"+r"(__val), flags_constraint(__flags) \
24+
: bt_constraint(__val) \
1925
: "cc", "memory"); \
2026
})
2127

@@ -37,12 +43,9 @@
3743

3844
#define guest_execute_fastop_2(FEP, insn, __input, __output, __flags) \
3945
({ \
40-
__asm__ __volatile__("bt $0, %[ro_val]\n\t" \
41-
FEP insn " %[input], %[output]\n\t" \
42-
"pushfq\n\t" \
43-
"pop %[flags]\n\t" \
44-
: [output]"+r"(__output), [flags]"=r"(__flags) \
45-
: [input]"r"(__input), [ro_val]"rm"((uint32_t)__output) \
46+
__asm__ __volatile__(fastop(FEP insn " %[input], %[output]") \
47+
: [output]"+r"(__output), flags_constraint(__flags) \
48+
: [input]"r"(__input), bt_constraint(__output) \
4649
: "cc", "memory"); \
4750
})
4851

@@ -65,12 +68,9 @@
6568

6669
#define guest_execute_fastop_cl(FEP, insn, __shift, __output, __flags) \
6770
({ \
68-
__asm__ __volatile__("bt $0, %[ro_val]\n\t" \
69-
FEP insn " %%cl, %[output]\n\t" \
70-
"pushfq\n\t" \
71-
"pop %[flags]\n\t" \
72-
: [output]"+r"(__output), [flags]"=r"(__flags) \
73-
: "c"(__shift), [ro_val]"rm"((uint32_t)__output) \
71+
__asm__ __volatile__(fastop(FEP insn " %%cl, %[output]") \
72+
: [output]"+r"(__output), flags_constraint(__flags) \
73+
: "c"(__shift), bt_constraint(__output) \
7474
: "cc", "memory"); \
7575
})
7676

0 commit comments

Comments
 (0)