diff --git a/src/collision.h b/src/collision.h index afd5999a..5caba2c4 100644 --- a/src/collision.h +++ b/src/collision.h @@ -430,4 +430,4 @@ static inline bool Collision_instancesOverlapPrecise(Runner* runner, Instance* a } return false; -} +} \ No newline at end of file diff --git a/src/common.h b/src/common.h index 53f82562..130aa77d 100644 --- a/src/common.h +++ b/src/common.h @@ -35,3 +35,24 @@ #define MAYBE_UNUSED #endif #endif + +#if defined(__GNUC__) || defined(__clang__) + #if defined(__x86_64__) || defined(__i386__) || defined(__riscv) + #define YIELD() __asm__ volatile("rep; nop" : : : "memory") + #elif defined(__aarch64__) || (defined(__arm__) && defined(__ARM_ARCH) && (__ARM_ARCH >= 7)) + #define YIELD() __asm__ volatile("yield" : : : "memory") + #else + #define YIELD() ((void)0) + #endif +#elif defined(_MSC_VER) + #include + #if defined(_M_X64) || defined(_M_IX86) + #define YIELD() _mm_pause() + #elif defined(_M_ARM64) || defined(_M_ARM) + #define YIELD() __yield() + #else + #define YIELD() ((void)0) + #endif +#else + #define YIELD() ((void)0) +#endif diff --git a/src/desktop/backends/glfw2.c b/src/desktop/backends/glfw2.c index 26c706ec..79976c9a 100644 --- a/src/desktop/backends/glfw2.c +++ b/src/desktop/backends/glfw2.c @@ -267,5 +267,6 @@ void platformSleepUntil(double time) { while (platformGetTime() < time) { // Spin-wait for the remaining sub-millisecond + YIELD(); } } diff --git a/src/desktop/backends/glfw3.c b/src/desktop/backends/glfw3.c index 5f978f72..d4c2cdc1 100644 --- a/src/desktop/backends/glfw3.c +++ b/src/desktop/backends/glfw3.c @@ -428,5 +428,6 @@ void platformSleepUntil(double time) { } while (platformGetTime() < time) { // Spin-wait for the remaining sub-millisecond + YIELD(); } } diff --git a/src/desktop/backends/sdl1.c b/src/desktop/backends/sdl1.c index c5785707..f46755b6 100644 --- a/src/desktop/backends/sdl1.c +++ b/src/desktop/backends/sdl1.c @@ -258,5 +258,6 @@ void platformSleepUntil(double time) { while (platformGetTime() < time) { // Spin-wait for the remaining sub-millisecond + YIELD(); } } diff --git a/src/desktop/backends/sdl2.c b/src/desktop/backends/sdl2.c index c8f48fc5..590375db 100644 --- a/src/desktop/backends/sdl2.c +++ b/src/desktop/backends/sdl2.c @@ -321,6 +321,7 @@ void platformSleepUntil(double time) { while (platformGetTime() < time) { // Spin-wait for the remaining sub-millisecond + YIELD(); } }