]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
xen/vpci: Improve code generation in mask_write()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 15 Mar 2024 11:31:33 +0000 (11:31 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 19 Mar 2024 18:29:37 +0000 (18:29 +0000)
The use of __clear_bit() forces dmask to be spilled to the stack, and
interferes with the compiler heuristcs for some upcoming improvements to the
ffs() code generation.

First, shrink dmask to just the active vectors by making out the upper bits.
This replaces the "i < msi->vectors" part of the loop condition.

Next, use a simple while() loop with "clear bottom bit" expressed in plane C,
which affords the optimiser a far better understanding of what the loop is
doing.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
xen/drivers/vpci/msi.c

index d3aa5df089417e4f8931fdc29c2e7c5ff3e20569..30adcf7df05d5540cb3a28a6fc5f596875c2bc98 100644 (file)
@@ -169,13 +169,15 @@ static void cf_check mask_write(
 
     if ( msi->enabled )
     {
-        unsigned int i;
+        /* Skip changes to vectors which aren't enabled. */
+        dmask &= (~0U >> (32 - msi->vectors));
 
-        for ( i = ffs(dmask) - 1; dmask && i < msi->vectors;
-              i = ffs(dmask) - 1 )
+        while ( dmask )
         {
+            unsigned int i = ffs(dmask) - 1;
+
             vpci_msi_arch_mask(msi, pdev, i, (val >> i) & 1);
-            __clear_bit(i, &dmask);
+            dmask &= (dmask - 1);
         }
     }