[PATCH kvm-unit-tests 1/2] access: optimize check for multiple reserved bits

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Instead of using multiple ANDs statements, build a mask and check
it for more than one set bit.

Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
---
 x86/access.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/x86/access.c b/x86/access.c
index c71f39d..6285c8c 100644
--- a/x86/access.c
+++ b/x86/access.c
@@ -288,6 +288,7 @@ static int ac_test_bump_one(ac_test_t *at)
 static _Bool ac_test_legal(ac_test_t *at)
 {
     int flags = at->flags;
+    unsigned reserved;
 
     if (F(AC_ACCESS_FETCH) && F(AC_ACCESS_WRITE))
 	return false;
@@ -321,8 +322,12 @@ static _Bool ac_test_legal(ac_test_t *at)
      * error code; the odds of a KVM bug are super low, and the odds of actually
      * being able to detect a bug are even lower.
      */
-    if ((F(AC_PDE_BIT51) + F(AC_PDE_BIT36) + F(AC_PDE_BIT13) +
-        F(AC_PTE_BIT51) + F(AC_PTE_BIT36)) > 1)
+    reserved = (AC_PDE_BIT51_MASK | AC_PDE_BIT36_MASK | AC_PDE_BIT13_MASK |
+	        AC_PTE_BIT51_MASK | AC_PTE_BIT36_MASK);
+
+    /* Only test one reserved bit at a time.  */
+    reserved &= flags;
+    if (reserved & (reserved - 1))
         return false;
 
     return true;
-- 
2.27.0





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux