From c964524f18fc5c3b7baf5a3d0eac0980f17d3cf0 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 15 May 2024 11:08:00 -0400 Subject: atomic: Add a spin_loop() hint --- src/atomic.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/atomic.h b/src/atomic.h index 7d32e73..360de20 100644 --- a/src/atomic.h +++ b/src/atomic.h @@ -8,6 +8,7 @@ #ifndef BFS_ATOMIC_H #define BFS_ATOMIC_H +#include "prelude.h" #include "sanity.h" #include @@ -101,4 +102,17 @@ #define signal_fence(order) \ atomic_signal_fence(memory_order_##order) +/** + * A hint to the CPU to relax while it spins. + */ +#if __has_builtin(__builtin_ia32_pause) +# define spin_loop() __builtin_ia32_pause() +#elif __has_builtin(__builtin_arm_yield) +# define spin_loop() __builtin_arm_yield() +#elif __has_builtin(__builtin_riscv_pause) +# define spin_loop() __builtin_riscv_pause() +#else +# define spin_loop() ((void)0) +#endif + #endif // BFS_ATOMIC_H -- cgit v1.2.3