Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -488,11 +488,11 @@ { #if defined(OF_HAVE_BUILTIN_BSWAP16) return __builtin_bswap16(i); #elif (defined(OF_AMD64) || defined(OF_X86)) && defined(__GNUC__) __asm__ ( - "xchgb %h0, %b0" + "xchg{b} { %h0, %b0 | %b0, %h0 }" : "=Q"(i) : "0"(i) ); #elif defined(OF_POWERPC) && defined(__GNUC__) __asm__ ( @@ -556,13 +556,13 @@ : "=r"(i) : "0"(i) ); #elif defined(OF_X86) && defined(__GNUC__) __asm__ ( - "bswap %%eax\n\t" - "bswap %%edx\n\t" - "xchgl %%eax, %%edx" + "bswap {%%}eax\n\t" + "bswap {%%}edx\n\t" + "xchg{l} { %%eax, %%edx | edx, eax }" : "=A"(i) : "0"(i) ); #else i = (uint64_t)OFByteSwap32NonConst( Index: src/platform/x86/OFAtomic.h ================================================================== --- src/platform/x86/OFAtomic.h +++ src/platform/x86/OFAtomic.h @@ -18,12 +18,12 @@ static OF_INLINE int32_t OFAtomicInt32Add(volatile int32_t *_Nonnull p, int32_t i) { __asm__ __volatile__ ( "lock\n\t" - "xaddl %0, %2\n\t" - "addl %1, %0" + "xadd{l} { %0, %2 | %2, %0 }\n\t" + "add{l} { %1, %0 | %0, %1 }" : "+&r"(i) : "r"(i), "m"(*p) ); return i; @@ -36,12 +36,12 @@ return OFAtomicInt32Add(p, i); #ifdef OF_AMD64 else if (sizeof(int) == 8) __asm__ __volatile__ ( "lock\n\t" - "xaddq %0, %2\n\t" - "addq %1, %0" + "xadd{q} { %0, %2 | %2, %0 }\n\t" + "add{q} { %1, %0 | %0, %1 }" : "+&r"(i) : "r"(i), "m"(*p) ); #endif else @@ -54,22 +54,22 @@ OFAtomicPointerAdd(void *volatile _Nullable *_Nonnull p, intptr_t i) { #if defined(OF_AMD64) __asm__ __volatile__ ( "lock\n\t" - "xaddq %0, %2\n\t" - "addq %1, %0" + "xadd{q} { %0, %2 | %2, %0 }\n\t" + "add{q} { %1, %0 | %0, %1 }" : "+&r"(i) : "r"(i), "m"(*p) ); return (void *)i; #elif defined(OF_X86) __asm__ __volatile__ ( "lock\n\t" - "xaddl %0, %2\n\t" - "addl %1, %0" + "xadd{l} { %0, %2 | %2, %0 }\n\t" + "add{l} { %1, %0 | %0, %1 }" : "+&r"(i) : "r"(i), "m"(*p) ); return (void *)i; @@ -78,14 +78,14 @@ static OF_INLINE int32_t OFAtomicInt32Subtract(volatile int32_t *_Nonnull p, int32_t i) { __asm__ __volatile__ ( - "negl %0\n\t" + "neg{l} %0\n\t" "lock\n\t" - "xaddl %0, %2\n\t" - "subl %1, %0" + "xadd{l} { %0, %2 | %2, %0 }\n\t" + "sub{l} { %1, %0 | %0, %1 }" : "+&r"(i) : "r"(i), "m"(*p) ); return i; @@ -97,14 +97,14 @@ if (sizeof(int) == 4) return OFAtomicInt32Subtract(p, i); #ifdef OF_AMD64 else if (sizeof(int) == 8) __asm__ __volatile__ ( - "negq %0\n\t" + "neg{q} %0\n\t" "lock\n\t" - "xaddq %0, %2\n\t" - "subq %1, %0" + "xadd{q} { %0, %2 | %2, %0 }\n\t" + "sub{q} { %1, %0 | %0, %1 }" : "+&r"(i) : "r"(i), "m"(*p) ); #endif else @@ -116,25 +116,25 @@ static OF_INLINE void *_Nullable OFAtomicPointerSubtract(void *volatile _Nullable *_Nonnull p, intptr_t i) { #if defined(OF_AMD64) __asm__ __volatile__ ( - "negq %0\n\t" + "neg{q} %0\n\t" "lock\n\t" - "xaddq %0, %2\n\t" - "subq %1, %0" + "xadd{q} { %0, %2 | %2, %0 }\n\t" + "sub{q} { %1, %0 | %0, %1 }" : "+&r"(i) : "r"(i), "m"(*p) ); return (void *)i; #elif defined(OF_X86) __asm__ __volatile__ ( - "negl %0\n\t" + "neg{l} %0\n\t" "lock\n\t" - "xaddl %0, %2\n\t" - "subl %1, %0" + "xadd{l} { %0, %2 | %2, %0 }\n\t" + "sub{l} { %1, %0 | %0, %1 }" : "+&r"(i) : "r"(i), "m"(*p) ); return (void *)i; @@ -145,15 +145,15 @@ OFAtomicInt32Increase(volatile int32_t *_Nonnull p) { int32_t i; __asm__ __volatile__ ( - "xorl %0, %0\n\t" - "incl %0\n\t" + "xor{l} %0, %0\n\t" + "inc{l} %0\n\t" "lock\n\t" - "xaddl %0, %1\n\t" - "incl %0" + "xadd{l} { %0, %1 | %1, %0 }\n\t" + "inc{l} %0" : "=&r"(i) : "m"(*p) ); return i; @@ -167,15 +167,15 @@ if (sizeof(int) == 4) return OFAtomicInt32Increase(p); #ifdef OF_AMD64 else if (sizeof(int) == 8) __asm__ __volatile__ ( - "xorq %0, %0\n\t" - "incq %0\n\t" + "xor{q} %0, %0\n\t" + "inc{q} %0\n\t" "lock\n\t" - "xaddq %0, %1\n\t" - "incq %0" + "xadd{q} { %0, %1 | %1, %0 }\n\t" + "inc{q} %0" : "=&r"(i) : "m"(*p) ); #endif else @@ -188,15 +188,15 @@ OFAtomicInt32Decrease(volatile int32_t *_Nonnull p) { int32_t i; __asm__ __volatile__ ( - "xorl %0, %0\n\t" - "decl %0\n\t" + "xor{l} %0, %0\n\t" + "dec{l} %0\n\t" "lock\n\t" - "xaddl %0, %1\n\t" - "decl %0" + "xadd{l} { %0, %1 | %1, %0 }\n\t" + "dec{l} %0" : "=&r"(i) : "m"(*p) ); return i; @@ -210,15 +210,15 @@ if (sizeof(int) == 4) return OFAtomicInt32Decrease(p); #ifdef OF_AMD64 else if (sizeof(int) == 8) __asm__ __volatile__ ( - "xorq %0, %0\n\t" - "decq %0\n\t" + "xor{q} %0, %0\n\t" + "dec{q} %0\n\t" "lock\n\t" - "xaddq %0, %1\n\t" - "decq %0" + "xadd{q} { %0, %1 | %1, %0 }\n\t" + "dec{q} %0" : "=&r"(i) : "m"(*p) ); #endif else @@ -230,16 +230,16 @@ static OF_INLINE uint32_t OFAtomicInt32Or(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" - "movl %2, %0\n\t" - "movl %0, %%eax\n\t" - "orl %1, %0\n\t" + "mov{l} { %2, %0 | %0, %2 }\n\t" + "mov{l} { %0, %%eax | eax, %0 }\n\t" + "or{l} { %1, %0 | %0, %1 }\n\t" "lock\n\t" - "cmpxchg %0, %2\n\t" - "jne 0b" + "cmpxchg{l} { %0, %2 | %2, %0 }\n\t" + "jne { | short } 0b" : "=&r"(i) : "r"(i), "m"(*p) : "eax", "cc" ); @@ -253,16 +253,16 @@ return OFAtomicInt32Or(p, i); #ifdef OF_AMD64 else if (sizeof(int) == 8) __asm__ __volatile__ ( "0:\n\t" - "movq %2, %0\n\t" - "movq %0, %%rax\n\t" - "orq %1, %0\n\t" + "mov{q} { %2, %0 | %0, %2 }\n\t" + "mov{q} { %0, %%rax | rax, %0 }\n\t" + "or{q} { %1, %0 | %0, %1 }\n\t" "lock\n\t" - "cmpxchg %0, %2\n\t" - "jne 0b" + "cmpxchg{q} { %0, %2 | %2, %0 }\n\t" + "jne { | short } 0b" : "=&r"(i) : "r"(i), "m"(*p) : "rax", "cc" ); #endif @@ -275,16 +275,16 @@ static OF_INLINE uint32_t OFAtomicInt32And(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" - "movl %2, %0\n\t" - "movl %0, %%eax\n\t" - "andl %1, %0\n\t" + "mov{l} { %2, %0 | %0, %2 }\n\t" + "mov{l} { %0, %%eax | eax, %0 }\n\t" + "and{l} { %1, %0 | %0, %1 }\n\t" "lock\n\t" - "cmpxchg %0, %2\n\t" - "jne 0b" + "cmpxchg{l} { %0, %2 | %2, %0 }\n\t" + "jne { | short } 0b" : "=&r"(i) : "r"(i), "m"(*p) : "eax", "cc" ); @@ -298,16 +298,16 @@ return OFAtomicInt32And(p, i); #ifdef OF_AMD64 else if (sizeof(int) == 8) __asm__ __volatile__ ( "0:\n\t" - "movq %2, %0\n\t" - "movq %0, %%rax\n\t" - "andq %1, %0\n\t" + "mov{q} { %2, %0 | %0, %2 }\n\t" + "mov{q} { %0, %%rax | rax, %0 }\n\t" + "and{q} { %1, %0 | %0, %1 }\n\t" "lock\n\t" - "cmpxchg %0, %2\n\t" - "jne 0b" + "cmpxchg{q} { %0, %2 | %2, %0 }\n\t" + "jne { | short } 0b" : "=&r"(i) : "r"(i), "m"(*p) : "rax", "cc" ); #endif @@ -320,16 +320,16 @@ static OF_INLINE uint32_t OFAtomicInt32Xor(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" - "movl %2, %0\n\t" - "movl %0, %%eax\n\t" - "xorl %1, %0\n\t" + "mov{l} { %2, %0 | %0, %2 }\n\t" + "mov{l} { %0, %%eax | eax, %0 }\n\t" + "xor{l} { %1, %0 | %0, %1 }\n\t" "lock\n\t" - "cmpxchgl %0, %2\n\t" - "jne 0b" + "cmpxchg{l} { %0, %2 | %2, %0 }\n\t" + "jne { | short } 0b" : "=&r"(i) : "r"(i), "m"(*p) : "eax", "cc" ); @@ -343,16 +343,16 @@ return OFAtomicInt32Xor(p, i); #ifdef OF_AMD64 else if (sizeof(int) == 8) __asm__ __volatile__ ( "0:\n\t" - "movq %2, %0\n\t" - "movq %0, %%rax\n\t" - "xorq %1, %0\n\t" + "mov{q} { %2, %0 | %0, %2 }\n\t" + "mov{q} { %0, %%rax | rax, %0 }\n\t" + "xor{q} { %1, %0 | %0, %1 }\n\t" "lock\n\t" - "cmpxchg %0, %2\n\t" - "jne 0b" + "cmpxchg{q} { %0, %2 | %2, %0 }\n\t" + "jne { | short } 0b" : "=&r"(i) : "r"(i), "m"(*p) : "rax", "cc" ); #endif @@ -367,13 +367,13 @@ { int r; __asm__ __volatile__ ( "lock\n\t" - "cmpxchg %2, %3\n\t" + "cmpxchg{l} { %2, %3 | %3, %2 }\n\t" "sete %b0\n\t" - "movzbl %b0, %0" + "movz{bl|x} { %b0, %0 | %0, %b0 }" : "=&d"(r), "+a"(o) /* use d instead of r to avoid a gcc bug */ : "r"(n), "m"(*p) : "cc" ); @@ -385,13 +385,13 @@ { int r; __asm__ __volatile__ ( "lock\n\t" - "cmpxchg %2, %3\n\t" + "cmpxchg { %2, %3 | %3, %2 }\n\t" "sete %b0\n\t" - "movzbl %b0, %0" + "movz{bl|x} { %b0, %0 | %0, %b0 }" : "=&d"(r), "+a"(o) /* use d instead of r to avoid a gcc bug */ : "r"(n), "m"(*p) : "cc" ); @@ -404,13 +404,13 @@ { int r; __asm__ __volatile__ ( "lock\n\t" - "cmpxchg %2, %3\n\t" + "cmpxchg { %2, %3 | %3, %2 }\n\t" "sete %b0\n\t" - "movzbl %b0, %0" + "movz{bl|x} { %b0, %0 | %0, %b0 }" : "=&d"(r), "+a"(o) /* use d instead of r to avoid a gcc bug */ : "r"(n), "m"(*p) : "cc" ); @@ -420,15 +420,15 @@ static OF_INLINE void OFMemoryBarrier(void) { #ifdef OF_AMD64 __asm__ __volatile__ ( - "lock orq $0, (%%rsp)" ::: "memory", "cc" + "lock or{q} { $0, (%%rsp) | [rsp], 0 }" ::: "memory", "cc" ); #else __asm__ __volatile__ ( - "lock orl $0, (%%esp)" ::: "memory", "cc" + "lock or{l} { $0, (%%esp) | [esp], 0 }" ::: "memory", "cc" ); #endif } static OF_INLINE void