Skip to content

Commit 279a016

Browse files
hcahcaVasily Gorbik
authored andcommitted
s390/atomic_ops: Make use of flag output constraint
With gcc 14.1.0 support for flag output constraint was added for s390. Use this for __atomic_cmpxchg_bool(). This allows for slightly better code, since the compiler can generate code depending on the condition code which is the result of an inline assembly. The size of the kernel image is reduced by ~12kb. Reviewed-by: Juergen Christ <[email protected]> Signed-off-by: Heiko Carstens <[email protected]> Signed-off-by: Vasily Gorbik <[email protected]>
1 parent ee19370 commit 279a016

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

arch/s390/include/asm/atomic_ops.h

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,26 +178,54 @@ static __always_inline int __atomic_cmpxchg(int *ptr, int old, int new)
178178
return old;
179179
}
180180

181+
static __always_inline long __atomic64_cmpxchg(long *ptr, long old, long new)
182+
{
183+
asm volatile(
184+
" csg %[old],%[new],%[ptr]"
185+
: [old] "+d" (old), [ptr] "+QS" (*ptr)
186+
: [new] "d" (new)
187+
: "cc", "memory");
188+
return old;
189+
}
190+
191+
#ifdef __GCC_ASM_FLAG_OUTPUTS__
192+
181193
static __always_inline bool __atomic_cmpxchg_bool(int *ptr, int old, int new)
182194
{
183-
int old_expected = old;
195+
int cc;
184196

185197
asm volatile(
186198
" cs %[old],%[new],%[ptr]"
187-
: [old] "+d" (old), [ptr] "+Q" (*ptr)
199+
: [old] "+d" (old), [ptr] "+Q" (*ptr), "=@cc" (cc)
188200
: [new] "d" (new)
189-
: "cc", "memory");
190-
return old == old_expected;
201+
: "memory");
202+
return cc == 0;
191203
}
192204

193-
static __always_inline long __atomic64_cmpxchg(long *ptr, long old, long new)
205+
static __always_inline bool __atomic64_cmpxchg_bool(long *ptr, long old, long new)
194206
{
207+
int cc;
208+
195209
asm volatile(
196210
" csg %[old],%[new],%[ptr]"
197-
: [old] "+d" (old), [ptr] "+QS" (*ptr)
211+
: [old] "+d" (old), [ptr] "+QS" (*ptr), "=@cc" (cc)
212+
: [new] "d" (new)
213+
: "memory");
214+
return cc == 0;
215+
}
216+
217+
#else /* __GCC_ASM_FLAG_OUTPUTS__ */
218+
219+
static __always_inline bool __atomic_cmpxchg_bool(int *ptr, int old, int new)
220+
{
221+
int old_expected = old;
222+
223+
asm volatile(
224+
" cs %[old],%[new],%[ptr]"
225+
: [old] "+d" (old), [ptr] "+Q" (*ptr)
198226
: [new] "d" (new)
199227
: "cc", "memory");
200-
return old;
228+
return old == old_expected;
201229
}
202230

203231
static __always_inline bool __atomic64_cmpxchg_bool(long *ptr, long old, long new)
@@ -212,4 +240,6 @@ static __always_inline bool __atomic64_cmpxchg_bool(long *ptr, long old, long ne
212240
return old == old_expected;
213241
}
214242

243+
#endif /* __GCC_ASM_FLAG_OUTPUTS__ */
244+
215245
#endif /* __ARCH_S390_ATOMIC_OPS__ */

0 commit comments

Comments
 (0)