1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_CMPXCHG_64_H
3 #define _ASM_X86_CMPXCHG_64_H
5 #define arch_cmpxchg64(ptr, o, n) \
7 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
8 arch_cmpxchg((ptr), (o), (n)); \
11 #define arch_cmpxchg64_local(ptr, o, n) \
13 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
14 arch_cmpxchg_local((ptr), (o), (n)); \
17 #define arch_try_cmpxchg64(ptr, po, n) \
19 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
20 arch_try_cmpxchg((ptr), (po), (n)); \
23 #define arch_try_cmpxchg64_local(ptr, po, n) \
25 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
26 arch_try_cmpxchg_local((ptr), (po), (n)); \
36 #define __arch_cmpxchg128(_ptr, _old, _new, _lock) \
38 union __u128_halves o = { .full = (_old), }, \
39 n = { .full = (_new), }; \
41 asm volatile(_lock "cmpxchg16b %[ptr]" \
42 : [ptr] "+m" (*(_ptr)), \
43 "+a" (o.low), "+d" (o.high) \
44 : "b" (n.low), "c" (n.high) \
50 static __always_inline u128 arch_cmpxchg128(volatile u128 *ptr, u128 old, u128 new)
52 return __arch_cmpxchg128(ptr, old, new, LOCK_PREFIX);
54 #define arch_cmpxchg128 arch_cmpxchg128
56 static __always_inline u128 arch_cmpxchg128_local(volatile u128 *ptr, u128 old, u128 new)
58 return __arch_cmpxchg128(ptr, old, new,);
60 #define arch_cmpxchg128_local arch_cmpxchg128_local
62 #define __arch_try_cmpxchg128(_ptr, _oldp, _new, _lock) \
64 union __u128_halves o = { .full = *(_oldp), }, \
65 n = { .full = (_new), }; \
68 asm volatile(_lock "cmpxchg16b %[ptr]" \
71 [ptr] "+m" (*(_ptr)), \
72 "+a" (o.low), "+d" (o.high) \
73 : "b" (n.low), "c" (n.high) \
82 static __always_inline bool arch_try_cmpxchg128(volatile u128 *ptr, u128 *oldp, u128 new)
84 return __arch_try_cmpxchg128(ptr, oldp, new, LOCK_PREFIX);
86 #define arch_try_cmpxchg128 arch_try_cmpxchg128
88 static __always_inline bool arch_try_cmpxchg128_local(volatile u128 *ptr, u128 *oldp, u128 new)
90 return __arch_try_cmpxchg128(ptr, oldp, new,);
92 #define arch_try_cmpxchg128_local arch_try_cmpxchg128_local
94 #define system_has_cmpxchg128() boot_cpu_has(X86_FEATURE_CX16)
96 #endif /* _ASM_X86_CMPXCHG_64_H */