Skip to contentSkip to conversation

x86/bitops: Force __scanbit() to be always inline

PATCH In review Andrew Cooper 2 participants 2 messages Feb 10, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/bitops: Force __scanbit() to be always inline

It turns out that GCCs 4.9.2 and 6.3.0 instantiate __scanbit() in three translation units, but never references the result. All real uses of __scanbit() are already suitably inline.

---
CC: Jan Beulich <[email protected]>

Forcing __scanbit() to be always_inline appears to cause GCC to reorder some of its basic blocks, so there is a moderately large perturbance to functions. As far as I can see, even the register scheduling is the same, and the delta is just changes in the nops used to align the basic blocks.

---
 xen/include/asm-x86/bitops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/asm-x86/bitops.h +1 -1
index fd494e8..0f18645 100644
@@ -334,7 +334,7 @@ extern unsigned int __find_first_zero_bit(
 extern unsigned int __find_next_zero_bit(
     const unsigned long *addr, unsigned int size, unsigned int offset);
 
-static inline unsigned int __scanbit(unsigned long val, unsigned int max)
+static always_inline unsigned int __scanbit(unsigned long val, unsigned int max)
 {
     if ( __builtin_constant_p(max) && max == BITS_PER_LONG )
         alternative_io("bsf %[in],%[out]; cmovz %[max],%k[out]",
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 10.02.17 at 12:44, <[email protected]> wrote:

It turns out that GCCs 4.9.2 and 6.3.0 instantiate __scanbit() in three translation units, but never references the result. All real uses of __scanbit() are already suitably inline.

While I'm not opposed to this at all, we should set ourselves a reasonably clear rule of thumb of when to use always_inline. As was noted the other day, mixing (apparently arbitrarily) with normal inline functions is at least confusing to the reader. For that it may be necessary to understand what exactly it is that makes gcc create (even unreferenced) static function instances.

Jan

Quoted 1 line

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel