]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
__arch_xprod64(): make __always_inline when optimizing for performance
authorNicolas Pitre <npitre@baylibre.com>
Thu, 3 Oct 2024 21:16:16 +0000 (17:16 -0400)
committerArnd Bergmann <arnd@arndb.de>
Mon, 28 Oct 2024 21:44:28 +0000 (21:44 +0000)
Recent gcc versions started not systematically inline __arch_xprod64()
and that has performance implications. Give the compiler the freedom to
decide only when optimizing for size.

Here's some timing numbers from lib/math/test_div64.c

Using __always_inline:

```
test_div64: Starting 64bit/32bit division and modulo test
test_div64: Completed 64bit/32bit division and modulo test, 0.048285584s elapsed
```

Without __always_inline:

```
test_div64: Starting 64bit/32bit division and modulo test
test_div64: Completed 64bit/32bit division and modulo test, 0.053023584s elapsed
```

Forcing constant base through the non-constant base code path:

```
test_div64: Starting 64bit/32bit division and modulo test
test_div64: Completed 64bit/32bit division and modulo test, 0.103263776s elapsed
```

It is worth noting that test_div64 does half the test with non constant
divisors already so the impact is greater than what those numbers show.
And for what it is worth, those numbers were obtained using QEMU. The
gcc version is 14.1.0.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
arch/arm/include/asm/div64.h
include/asm-generic/div64.h

index 562d5376ae7a581915ee92daa10fd4168443832f..d3ef8e416b27d22d38bf084e091b0e4795f74bd4 100644 (file)
@@ -52,7 +52,12 @@ static inline uint32_t __div64_32(uint64_t *n, uint32_t base)
 
 #else
 
-static inline uint64_t __arch_xprod_64(uint64_t m, uint64_t n, bool bias)
+#ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
+static __always_inline
+#else
+static inline
+#endif
+uint64_t __arch_xprod_64(uint64_t m, uint64_t n, bool bias)
 {
        unsigned long long res;
        register unsigned int tmp asm("ip") = 0;
index 5d59cf7e73d90885d0bb20b9c1795af624bfd6c3..25e7b4b58dcf55a395b9db72e01f2cd220da58a0 100644 (file)
  * Hoping for compile-time optimization of  conditional code.
  * Architectures may provide their own optimized assembly implementation.
  */
-static inline uint64_t __arch_xprod_64(const uint64_t m, uint64_t n, bool bias)
+#ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
+static __always_inline
+#else
+static inline
+#endif
+uint64_t __arch_xprod_64(const uint64_t m, uint64_t n, bool bias)
 {
        uint32_t m_lo = m;
        uint32_t m_hi = m >> 32;