From b484619f203403fb410d74f165d9a62aa828b1b4 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Mon, 13 May 2019 14:29:02 +0100 Subject: [PATCH] Added branch predictor hint. --- src/ds/bits.h | 4 ++++ src/mem/alloc.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ds/bits.h b/src/ds/bits.h index 52b5b18..c07ad92 100644 --- a/src/ds/bits.h +++ b/src/ds/bits.h @@ -9,7 +9,11 @@ # define ALWAYSINLINE __forceinline # define NOINLINE __declspec(noinline) # define HEADER_GLOBAL __declspec(selectany) +# define likely(x) !!(x) +# define unlikely(x) !!(x) #else +# define likely(x) __builtin_expect(!!(x), 1) +# define unlikely(x) __builtin_expect(!!(x), 0) # include # include # define ALWAYSINLINE __attribute__((always_inline)) diff --git a/src/mem/alloc.h b/src/mem/alloc.h index c00fb5e..e16c2bd 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -872,7 +872,7 @@ namespace snmalloc inline void handle_message_queue() { // Inline the empty check, but not necessarily the full queue handling. - if (message_queue().is_empty()) + if (likely(message_queue().is_empty())) return; handle_message_queue_inner();