]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
s390/atomic_ops: Improve __atomic_set() for small values
authorHeiko Carstens <hca@linux.ibm.com>
Mon, 1 Jul 2024 15:04:57 +0000 (17:04 +0200)
committerVasily Gorbik <gor@linux.ibm.com>
Wed, 10 Jul 2024 17:50:44 +0000 (19:50 +0200)
Use mvhi/mvghi for small constant values within the __atomic_set()
inline assemblies. This avoids loading the specified value into a
register.

The size of the kernel image is reduced by ~1.2kb.

Reviewed-by: Juergen Christ <jchrist@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/include/asm/atomic_ops.h

index 7f47e29278041fe871bb0fc9adc48c07a420726b..b028c5309befb8a96fe5c192d1caa78449817bae 100644 (file)
@@ -8,6 +8,8 @@
 #ifndef __ARCH_S390_ATOMIC_OPS__
 #define __ARCH_S390_ATOMIC_OPS__
 
+#include <linux/limits.h>
+
 static __always_inline int __atomic_read(const atomic_t *v)
 {
        int c;
@@ -20,9 +22,15 @@ static __always_inline int __atomic_read(const atomic_t *v)
 
 static __always_inline void __atomic_set(atomic_t *v, int i)
 {
-       asm volatile(
-               "       st      %[i],%[counter]\n"
-               : [counter] "=R" (v->counter) : [i] "d" (i));
+       if (__builtin_constant_p(i) && i >= S16_MIN && i <= S16_MAX) {
+               asm volatile(
+                       "       mvhi    %[counter], %[i]\n"
+                       : [counter] "=Q" (v->counter) : [i] "K" (i));
+       } else {
+               asm volatile(
+                       "       st      %[i],%[counter]\n"
+                       : [counter] "=R" (v->counter) : [i] "d" (i));
+       }
 }
 
 static __always_inline s64 __atomic64_read(const atomic64_t *v)
@@ -37,9 +45,15 @@ static __always_inline s64 __atomic64_read(const atomic64_t *v)
 
 static __always_inline void __atomic64_set(atomic64_t *v, s64 i)
 {
-       asm volatile(
-               "       stg     %[i],%[counter]\n"
-               : [counter] "=RT" (v->counter) : [i] "d" (i));
+       if (__builtin_constant_p(i) && i >= S16_MIN && i <= S16_MAX) {
+               asm volatile(
+                       "       mvghi   %[counter], %[i]\n"
+                       : [counter] "=Q" (v->counter) : [i] "K" (i));
+       } else {
+               asm volatile(
+                       "       stg     %[i],%[counter]\n"
+                       : [counter] "=RT" (v->counter) : [i] "d" (i));
+       }
 }
 
 #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES