mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 19:43:32 +00:00
24 lines
1.3 KiB
C
24 lines
1.3 KiB
C
#ifndef COSMOPOLITAN_LIBC_INTRIN_CMPXCHG_H_
|
|
#define COSMOPOLITAN_LIBC_INTRIN_CMPXCHG_H_
|
|
#include "libc/intrin/asmflag.h"
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
COSMOPOLITAN_C_START_
|
|
|
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86__)
|
|
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
|
|
({ \
|
|
bool DidIt; \
|
|
autotype(IFTHING) IfThing = (IFTHING); \
|
|
typeof(*IfThing) IsEqualToMe = (ISEQUALTOME); \
|
|
typeof(*IfThing) ReplaceItWithMe = (REPLACEITWITHME); \
|
|
asm volatile(ZFLAG_ASM("cmpxchg\t%3,%1") \
|
|
: ZFLAG_CONSTRAINT(DidIt), "+m"(*IfThing), "+a"(IsEqualToMe) \
|
|
: "r"(ReplaceItWithMe) \
|
|
: "cc"); \
|
|
DidIt; \
|
|
})
|
|
#endif /* GNUC && !ANSI && x86 */
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
#endif /* COSMOPOLITAN_LIBC_INTRIN_CMPXCHG_H_ */
|