File: portable_pause

package info (click to toggle)
rapmap 0.15.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,352 kB
  • sloc: cpp: 48,826; ansic: 4,471; sh: 215; python: 82; makefile: 17
file content (40 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
From: Michael R. Crusoe <crusoe@debian.org>
Subject: Add portable pauses
Forwarded: https://github.com/COMBINE-lab/RapMap/pull/49
--- a/include/FastxParserThreadUtils.hpp
+++ b/include/FastxParserThreadUtils.hpp
@@ -6,6 +6,9 @@
 #include <chrono>
 #include <random>
 #include <pthread.h>
+#if defined(__SSE2__)
+#include <xmmintrin.h> // _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() {