diff --git a/src/julia_atomics.h b/src/julia_atomics.h index e2121a9b4038a..4da2e4f7a9994 100644 --- a/src/julia_atomics.h +++ b/src/julia_atomics.h @@ -73,7 +73,14 @@ enum jl_memory_order { * are). We also need to access these atomic variables from the LLVM JIT code * which is very hard unless the layout of the object is fully specified. */ -#if defined(_CPU_X86_64_) + +/** + * On modern Intel and AMD platforms `lock orq` on the SP is faster than + * `mfence`. GCC 11 did switch to this representation. See #48123 + */ +#if defined(_CPU_X86_64_) && \ + ((defined(__GNUC__) && __GNUC__ < 11) || \ + (defined(__clang__))) #define jl_fence() __asm__ volatile("lock orq $0 , (%rsp)") #else #define jl_fence() atomic_thread_fence(memory_order_seq_cst)