Debian Codegraph @

include/ruby/backward/2/assume.h

raw
1 #ifndef RUBY_BACKWARD2_ASSUME_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RUBY_BACKWARD2_ASSUME_H
3 /**
4 * @file
5 * @author Ruby developers <[email protected]>
6 * @copyright This file is a part of the programming language Ruby.
7 * Permission is hereby granted, to either redistribute and/or
8 * modify this file, provided that the conditions mentioned in the
9 * file COPYING are met. Consult the file for details.
10 * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11 * implementation details. Don't take them as canon. They could
12 * rapidly appear then vanish. The name (path) of this header file
13 * is also an implementation detail. Do not expect it to persist
14 * at the place it is now. Developers are free to move it anywhere
15 * anytime at will.
16 * @note To ruby-core: remember that this header can be possibly
17 * recursively included from extension libraries written in C++.
18 * Do not expect for instance `__VA_ARGS__` is always available.
19 * We assume C99 for ruby itself but we don't assume languages of
20 * extension libraries. They could be written in C++98.
21 * @brief Defines #ASSUME / #RB_LIKELY / #UNREACHABLE
22 */
23 #include "ruby/internal/config.h"
24 #include "ruby/internal/assume.h"
25 #include "ruby/internal/has/builtin.h"
26
27 #define ASSUME RBIMPL_ASSUME /**< @old{RBIMPL_ASSUME} */
28 #define UNREACHABLE RBIMPL_UNREACHABLE() /**< @old{RBIMPL_UNREACHABLE} */
29 #define UNREACHABLE_RETURN RBIMPL_UNREACHABLE_RETURN /**< @old{RBIMPL_UNREACHABLE_RETURN} */
30
31 /* likely */
32 #if RBIMPL_HAS_BUILTIN(__builtin_expect)
33 /**
34 * Asserts that the given Boolean expression likely holds.
35 *
36 * @param x An expression that likely holds.
37 *
38 * @note Consider this macro carefully. It has been here since when CPUs were
39 * like babies, but contemporary processors are beasts. They are
40 * smarter than mare mortals like us today. Their branch predictions
41 * highly expectedly outperform your use of this macro.
42 */
43 # define RB_LIKELY(x) (__builtin_expect(!!(x), 1))
44
45 /**
46 * Asserts that the given Boolean expression likely doesn't hold.
47 *
48 * @param x An expression that likely doesn't hold.
49 */
50 # define RB_UNLIKELY(x) (__builtin_expect(!!(x), 0))
51 #else
52 # define RB_LIKELY(x) (x)
53 # define RB_UNLIKELY(x) (x)
54 #endif
55
56 #endif /* RUBY_BACKWARD2_ASSUME_H */