Skip to content

Commit 276b893

Browse files
ubizjakIngo Molnar
authored andcommitted
locking/atomic/x86: Introduce arch_atomic64_try_cmpxchg() to x86_32
Introduce arch_atomic64_try_cmpxchg() for 32-bit targets to use optimized target specific implementation instead of a generic one. This implementation eliminates dual-word compare after cmpxchg8b instruction and improves generated asm code from: 2273: f0 0f c7 0f lock cmpxchg8b (%edi) 2277: 8b 74 24 2c mov 0x2c(%esp),%esi 227b: 89 d3 mov %edx,%ebx 227d: 89 c2 mov %eax,%edx 227f: 89 5c 24 10 mov %ebx,0x10(%esp) 2283: 8b 7c 24 30 mov 0x30(%esp),%edi 2287: 89 44 24 1c mov %eax,0x1c(%esp) 228b: 31 f2 xor %esi,%edx 228d: 89 d0 mov %edx,%eax 228f: 89 da mov %ebx,%edx 2291: 31 fa xor %edi,%edx 2293: 09 d0 or %edx,%eax 2295: 0f 85 a5 00 00 00 jne 2340 <...> to: 2270: f0 0f c7 0f lock cmpxchg8b (%edi) 2274: 0f 85 a6 00 00 00 jne 2320 <...> Signed-off-by: Uros Bizjak <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Linus Torvalds <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent aef95da commit 276b893

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arch/x86/include/asm/atomic64_32.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,18 @@ ATOMIC64_DECL(add_unless);
6161
#undef __ATOMIC64_DECL
6262
#undef ATOMIC64_EXPORT
6363

64-
static __always_inline s64 arch_atomic64_cmpxchg(atomic64_t *v, s64 o, s64 n)
64+
static __always_inline s64 arch_atomic64_cmpxchg(atomic64_t *v, s64 old, s64 new)
6565
{
66-
return arch_cmpxchg64(&v->counter, o, n);
66+
return arch_cmpxchg64(&v->counter, old, new);
6767
}
6868
#define arch_atomic64_cmpxchg arch_atomic64_cmpxchg
6969

70+
static __always_inline bool arch_atomic64_try_cmpxchg(atomic64_t *v, s64 *old, s64 new)
71+
{
72+
return arch_try_cmpxchg64(&v->counter, old, new);
73+
}
74+
#define arch_atomic64_try_cmpxchg arch_atomic64_try_cmpxchg
75+
7076
static __always_inline s64 arch_atomic64_xchg(atomic64_t *v, s64 n)
7177
{
7278
s64 o;

0 commit comments

Comments
 (0)