Commit 58168a8c3c70527c9ed12e4e861a634fac05d55d

Ryan C. Gordon 2018-06-25T16:34:16

atomic: Fight with all the assemblers that don't like REP NOP. :/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c
index f5e17d0..8630e66 100644
--- a/src/atomic/SDL_spinlock.c
+++ b/src/atomic/SDL_spinlock.c
@@ -122,12 +122,13 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
 
 /* "REP NOP" is PAUSE, coded for tools that don't know it by that name. */
 #if (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))
-    #define PAUSE_INSTRUCTION() __asm__ __volatile__("rep nop\n")
+    #define PAUSE_INSTRUCTION() __asm__ __volatile__("pause\n")  /* Clang lets you do REP NOP, GCC wants PAUSE. */
 #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
-    #define PAUSE_INSRUCTION() _mm_pause()  /* this is actually "rep nop" and not a SIMD instruction. */
+    #define PAUSE_INSRUCTION() _mm_pause()  /* this is actually "rep nop" and not a SIMD instruction. No inline asm in MSVC x86-64! */
 #elif defined(__WATCOMC__) && defined(__386__)
+    /* watcom assembler won't let you do PAUSE, but refuses REP NOP as an invalid combination. Hardcode the bytes. */
     extern _inline void PAUSE_INSTRUCTION(void);
-    #pragma aux PAUSE_INSTRUCTION = "rep nop"
+    #pragma aux PAUSE_INSTRUCTION = "db 0f3h,90h"
 #else
     #define PAUSE_INSTRUCTION()
 #endif