From: Gabe Black Date: Fri, 18 Sep 2020 03:44:47 +0000 (-0700) Subject: base: Add M5_LIKELY and M5_UNLIKELY macros to compiler.hh. X-Git-Tag: develop-gem5-snapshot~735 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2f6a770ccf1b1b477cfa45253eedf57a53d58685;p=gem5.git base: Add M5_LIKELY and M5_UNLIKELY macros to compiler.hh. The clang/gcc implementation uses the nonstandard __builtin_expect(). In C++20, new standard attributes can be used instead. We can't use those yet though. Change-Id: Idd2541a7eca0d97ac6c643abbf2910cbc343d7e5 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34816 Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- diff --git a/src/base/compiler.hh b/src/base/compiler.hh index 38736ca5b..1eaebc802 100644 --- a/src/base/compiler.hh +++ b/src/base/compiler.hh @@ -56,6 +56,8 @@ # define M5_UNREACHABLE __builtin_unreachable() # define M5_PUBLIC __attribute__ ((visibility ("default"))) # define M5_LOCAL __attribute__ ((visibility ("hidden"))) +# define M5_LIKELY(cond) __builtin_expect(!!(cond), 1) +# define M5_UNLIKELY(cond) __builtin_expect(!!(cond), 0) #endif #if defined(__clang__)