]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: selftests: Dedup the gnarly constraints of the fastops tests (more macros!)
authorSean Christopherson <seanjc@google.com>
Tue, 9 Sep 2025 20:28:34 +0000 (13:28 -0700)
committerSean Christopherson <seanjc@google.com>
Thu, 11 Sep 2025 15:55:44 +0000 (08:55 -0700)
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>
tools/testing/selftests/kvm/x86/fastops_test.c

index 6c9a2dbf63657ed7e74b41dce1d3a3609c90be1c..26a381c8303ac2ff4c438ac793fd697418c4aa6d 100644 (file)
@@ -8,14 +8,20 @@
  * to set RFLAGS.CF based on whether or not the input is even or odd, so that
  * instructions like ADC and SBB are deterministic.
  */
+#define fastop(__insn)                                                                 \
+       "bt $0, %[bt_val]\n\t"                                                          \
+       __insn "\n\t"                                                                   \
+       "pushfq\n\t"                                                                    \
+       "pop %[flags]\n\t"
+
+#define flags_constraint(flags_val) [flags]"=r"(flags_val)
+#define bt_constraint(__bt_val) [bt_val]"rm"((uint32_t)__bt_val)
+
 #define guest_execute_fastop_1(FEP, insn, __val, __flags)                              \
 ({                                                                                     \
-       __asm__ __volatile__("bt $0, %[ro_val]\n\t"                                     \
-                            FEP insn " %[val]\n\t"                                     \
-                            "pushfq\n\t"                                               \
-                            "pop %[flags]\n\t"                                         \
-                            : [val]"+r"(__val), [flags]"=r"(__flags)                   \
-                            : [ro_val]"rm"((uint32_t)__val)                            \
+       __asm__ __volatile__(fastop(FEP insn " %[val]")                                 \
+                            : [val]"+r"(__val), flags_constraint(__flags)              \
+                            : bt_constraint(__val)                                     \
                             : "cc", "memory");                                         \
 })
 
 
 #define guest_execute_fastop_2(FEP, insn, __input, __output, __flags)                  \
 ({                                                                                     \
-       __asm__ __volatile__("bt $0, %[ro_val]\n\t"                                     \
-                            FEP insn " %[input], %[output]\n\t"                        \
-                            "pushfq\n\t"                                               \
-                            "pop %[flags]\n\t"                                         \
-                            : [output]"+r"(__output), [flags]"=r"(__flags)             \
-                            : [input]"r"(__input), [ro_val]"rm"((uint32_t)__output)    \
+       __asm__ __volatile__(fastop(FEP insn " %[input], %[output]")                    \
+                            : [output]"+r"(__output), flags_constraint(__flags)        \
+                            : [input]"r"(__input), bt_constraint(__output)             \
                             : "cc", "memory");                                         \
 })
 
 
 #define guest_execute_fastop_cl(FEP, insn, __shift, __output, __flags)                 \
 ({                                                                                     \
-       __asm__ __volatile__("bt $0, %[ro_val]\n\t"                                     \
-                            FEP insn " %%cl, %[output]\n\t"                            \
-                            "pushfq\n\t"                                               \
-                            "pop %[flags]\n\t"                                         \
-                            : [output]"+r"(__output), [flags]"=r"(__flags)             \
-                            : "c"(__shift), [ro_val]"rm"((uint32_t)__output)           \
+       __asm__ __volatile__(fastop(FEP insn " %%cl, %[output]")                        \
+                            : [output]"+r"(__output), flags_constraint(__flags)        \
+                            : "c"(__shift), bt_constraint(__output)                    \
                             : "cc", "memory");                                         \
 })