diff --git a/src/common.h b/src/common.h index 26d0e87..2577e06 100644 --- a/src/common.h +++ b/src/common.h @@ -121,12 +121,6 @@ #define MSTR_(s) #s #define MSTR(s) MSTR_(s) -/// @brief Wrapper for gcc branch prediction builtin, for likely branch. -#define likely(x) __builtin_expect(!!(x), 1) - -/// @brief Wrapper for gcc branch prediction builtin, for unlikely branch. -#define unlikely(x) __builtin_expect(!!(x), 0) - // Use #s here to prevent macro expansion /// Macro used for shortening some debugging code. #define CASESTRRET(s) case s: return #s diff --git a/src/compiler.h b/src/compiler.h index 2a2060d..75d3fcb 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -1,4 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright (c) 2018 Yuxuan Shui #pragma once -#define auto __auto_type + +#define auto __auto_type +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) diff --git a/src/utils.h b/src/utils.h index db48502..5aadda9 100644 --- a/src/utils.h +++ b/src/utils.h @@ -10,6 +10,8 @@ #include #include +#include "compiler.h" + #define ARR_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) #ifdef __FAST_MATH__ @@ -104,7 +106,7 @@ normalize_d(double d) { */ static inline void * allocchk_(const char *func_name, void *ptr) { - if (!ptr) { + if (unlikely(!ptr)) { // Since memory allocation failed, we try to print // this error message without any memory allocation. const char msg[] = "(): Failed to allocate memory\n";