Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+18 -18
+18 -18
tools/testing/selftests/kvm/x86/fastops_test.c
··· 8 8 * to set RFLAGS.CF based on whether or not the input is even or odd, so that 9 9 * instructions like ADC and SBB are deterministic. 10 10 */ 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 + 11 20 #define guest_execute_fastop_1(FEP, insn, __val, __flags) \ 12 21 ({ \ 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) \ 19 25 : "cc", "memory"); \ 20 26 }) 21 27 ··· 43 37 44 38 #define guest_execute_fastop_2(FEP, insn, __input, __output, __flags) \ 45 39 ({ \ 46 - __asm__ __volatile__("bt $0, %[ro_val]\n\t" \ 47 - FEP insn " %[input], %[output]\n\t" \ 48 - "pushfq\n\t" \ 49 - "pop %[flags]\n\t" \ 50 - : [output]"+r"(__output), [flags]"=r"(__flags) \ 51 - : [input]"r"(__input), [ro_val]"rm"((uint32_t)__output) \ 40 + __asm__ __volatile__(fastop(FEP insn " %[input], %[output]") \ 41 + : [output]"+r"(__output), flags_constraint(__flags) \ 42 + : [input]"r"(__input), bt_constraint(__output) \ 52 43 : "cc", "memory"); \ 53 44 }) 54 45 ··· 68 65 69 66 #define guest_execute_fastop_cl(FEP, insn, __shift, __output, __flags) \ 70 67 ({ \ 71 - __asm__ __volatile__("bt $0, %[ro_val]\n\t" \ 72 - FEP insn " %%cl, %[output]\n\t" \ 73 - "pushfq\n\t" \ 74 - "pop %[flags]\n\t" \ 75 - : [output]"+r"(__output), [flags]"=r"(__flags) \ 76 - : "c"(__shift), [ro_val]"rm"((uint32_t)__output) \ 68 + __asm__ __volatile__(fastop(FEP insn " %%cl, %[output]") \ 69 + : [output]"+r"(__output), flags_constraint(__flags) \ 70 + : "c"(__shift), bt_constraint(__output) \ 77 71 : "cc", "memory"); \ 78 72 }) 79 73