base: Use M5_UNLIKELY for conditional panic, etc., macros.
authorGabe Black <gabeblack@google.com>
Fri, 18 Sep 2020 03:46:19 +0000 (20:46 -0700)
committerGabe Black <gabeblack@google.com>
Sun, 20 Sep 2020 01:03:31 +0000 (01:03 +0000)
panic_if and fail_if should happen at most once in any given simulation,
and warn_if, etc., should still not happen most of the time.

Change-Id: Iaa6cb03c11b86d84f51cc4738efb8f203de4201c
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34817
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/base/logging.hh

index 7113af8777a2c2856f1d9bec7194505f4f0342a7..f56420bfa6621f40848605e3a385c1889523e1c6 100644 (file)
@@ -196,7 +196,7 @@ class Logger
  */
 #define panic_if(cond, ...)                                  \
     do {                                                     \
-        if ((cond)) {                                        \
+        if (M5_UNLIKELY(cond)) {                             \
             panic("panic condition " # cond " occurred: %s", \
                   csprintf(__VA_ARGS__));                    \
         }                                                    \
@@ -218,7 +218,7 @@ class Logger
  */
 #define fatal_if(cond, ...)                                     \
     do {                                                        \
-        if ((cond)) {                                           \
+        if (M5_UNLIKELY(cond)) {                                \
             fatal("fatal condition " # cond " occurred: %s",    \
                   csprintf(__VA_ARGS__));                       \
         }                                                       \
@@ -262,13 +262,13 @@ class Logger
  */
 #define warn_if(cond, ...) \
     do { \
-        if ((cond)) \
+        if (M5_UNLIKELY(cond)) \
             warn(__VA_ARGS__); \
     } while (0)
 
 #define warn_if_once(cond, ...) \
     do { \
-        if ((cond)) \
+        if (M5_UNLIKELY(cond)) \
             warn_once(__VA_ARGS__); \
     } while (0)
 /** @} */ // end of api_logger
@@ -291,7 +291,7 @@ class Logger
 #else //!NDEBUG
 #define chatty_assert(cond, ...)                                        \
     do {                                                                \
-        if (!(cond))                                                    \
+        if (M5_UNLIKELY(!(cond)))                                       \
             panic("assert(" # cond ") failed: %s", csprintf(__VA_ARGS__)); \
     } while (0)
 #endif // NDEBUG