diff --git a/include/FastxParserThreadUtils.hpp b/include/FastxParserThreadUtils.hpp index b813907..4172cfc 100644 --- a/include/FastxParserThreadUtils.hpp +++ b/include/FastxParserThreadUtils.hpp @@ -6,6 +6,9 @@ #include #include #include +#if defined(__SSE2__) +#include // _mm_pause +#endif // Most of this code is taken directly from https://github.com/geidav/spinlocks-bench/blob/master/os.hpp. // However, things may be renamed, modified, or randomly mangled over time. @@ -18,7 +21,23 @@ namespace fastx_parser { static const size_t MAX_BACKOFF_ITERS = 1024; ALWAYS_INLINE static void cpuRelax() { - asm("pause"); + #if defined(__SSE2__) // AMD and Intel + _mm_pause(); + #elif defined(__i386__) || defined(__x86_64__) + asm volatile("pause"); + #elif defined(__aarch64__) + asm volatile("wfe"); + #elif defined(__armel__) || defined(__ARMEL__) + asm volatile ("nop" ::: "memory"); + #elif defined(__arm__) || defined(__aarch64__) + __asm__ __volatile__ ("yield" ::: "memory"); + #elif defined(__ia64__) // IA64 + __asm__ __volatile__ ("hint @pause"); + #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) + __asm__ __volatile__ ("or 27,27,27" ::: "memory"); + #else // everything else. + asm volatile ("nop" ::: "memory"); + #endif } ALWAYS_INLINE void yieldSleep() {