Move likely/unlikely to compiler.h
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
b73dce1d6d
commit
68873efaa2
|
@ -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
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
// Copyright (c) 2018 Yuxuan Shui <yshuiv7@gmail.com>
|
||||
#pragma once
|
||||
#define auto __auto_type
|
||||
|
||||
#define auto __auto_type
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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";
|
||||
|
|
Loading…
Reference in New Issue