Skip to content

Commit ee19370

Browse files
hcahcaVasily Gorbik
authored andcommitted
s390/atomic_ops: Improve __atomic_set() for small values
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 <[email protected]> Signed-off-by: Heiko Carstens <[email protected]> Signed-off-by: Vasily Gorbik <[email protected]>
1 parent f2ed836 commit ee19370

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

arch/s390/include/asm/atomic_ops.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#ifndef __ARCH_S390_ATOMIC_OPS__
99
#define __ARCH_S390_ATOMIC_OPS__
1010

11+
#include <linux/limits.h>
12+
1113
static __always_inline int __atomic_read(const atomic_t *v)
1214
{
1315
int c;
@@ -20,9 +22,15 @@ static __always_inline int __atomic_read(const atomic_t *v)
2022

2123
static __always_inline void __atomic_set(atomic_t *v, int i)
2224
{
23-
asm volatile(
24-
" st %[i],%[counter]\n"
25-
: [counter] "=R" (v->counter) : [i] "d" (i));
25+
if (__builtin_constant_p(i) && i >= S16_MIN && i <= S16_MAX) {
26+
asm volatile(
27+
" mvhi %[counter], %[i]\n"
28+
: [counter] "=Q" (v->counter) : [i] "K" (i));
29+
} else {
30+
asm volatile(
31+
" st %[i],%[counter]\n"
32+
: [counter] "=R" (v->counter) : [i] "d" (i));
33+
}
2634
}
2735

2836
static __always_inline s64 __atomic64_read(const atomic64_t *v)
@@ -37,9 +45,15 @@ static __always_inline s64 __atomic64_read(const atomic64_t *v)
3745

3846
static __always_inline void __atomic64_set(atomic64_t *v, s64 i)
3947
{
40-
asm volatile(
41-
" stg %[i],%[counter]\n"
42-
: [counter] "=RT" (v->counter) : [i] "d" (i));
48+
if (__builtin_constant_p(i) && i >= S16_MIN && i <= S16_MAX) {
49+
asm volatile(
50+
" mvghi %[counter], %[i]\n"
51+
: [counter] "=Q" (v->counter) : [i] "K" (i));
52+
} else {
53+
asm volatile(
54+
" stg %[i],%[counter]\n"
55+
: [counter] "=RT" (v->counter) : [i] "d" (i));
56+
}
4357
}
4458

4559
#ifdef CONFIG_HAVE_MARCH_Z196_FEATURES

0 commit comments

Comments
 (0)