Ruby: include/ruby/internal/assume.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

assume.h
Go to the documentation of this file.
1#ifndef RBIMPL_ASSUME_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_ASSUME_H
28#include "ruby/internal/config.h"
29#include "ruby/internal/cast.h"
30#include "ruby/internal/compiler_since.h"
31#include "ruby/internal/has/builtin.h"
32#include "ruby/internal/warning_push.h"
33
35#if RBIMPL_COMPILER_SINCE(MSVC, 13, 10, 0)
36# define RBIMPL_HAVE___ASSUME
37
38#elif RBIMPL_COMPILER_SINCE(Intel, 13, 0, 0)
39# define RBIMPL_HAVE___ASSUME
40#endif
44#if RBIMPL_HAS_BUILTIN(__builtin_unreachable)
45# define RBIMPL_UNREACHABLE_RETURN(_) __builtin_unreachable()
46
47#elif defined(RBIMPL_HAVE___ASSUME)
48# define RBIMPL_UNREACHABLE_RETURN(_) return (__assume(0), (_))
49
50#else
51# define RBIMPL_UNREACHABLE_RETURN(_) return (_)
52#endif
53
55#if RBIMPL_HAS_BUILTIN(__builtin_unreachable)
56# define RBIMPL_UNREACHABLE __builtin_unreachable
57
58#elif defined(RBIMPL_HAVE___ASSUME)
59# define RBIMPL_UNREACHABLE() __assume(0)
60#endif
61
63#if RBIMPL_COMPILER_SINCE(Intel, 13, 0, 0)
64# /* icc warnings are false positives. Ignore them. */
65# /* "warning #2261: __assume expression with side effects discarded" */
66# define RBIMPL_ASSUME(expr) \
67 RBIMPL_WARNING_PUSH() \
68 RBIMPL_WARNING_IGNORED(2261) \
69 __assume(expr) \
70 RBIMPL_WARNING_POP()
71
72#elif defined(RBIMPL_HAVE___ASSUME)
73# define RBIMPL_ASSUME __assume
74
75#elif RBIMPL_HAS_BUILTIN(__builtin_assume)
76# define RBIMPL_ASSUME __builtin_assume
77
78#elif ! defined(RBIMPL_UNREACHABLE)
79# define RBIMPL_ASSUME(_) RBIMPL_CAST((void)(_))
80
81#else
82# define RBIMPL_ASSUME(_) \
83 (RB_LIKELY(!!(_)) ? RBIMPL_CAST((void)0) : RBIMPL_UNREACHABLE())
84#endif
85
86#if ! defined(RBIMPL_UNREACHABLE)
87# define RBIMPL_UNREACHABLE() RBIMPL_ASSUME(0)
88#endif
89
90#endif /* RBIMPL_ASSUME_H */
cast.h
Defines RBIMPL_CAST.
compiler_since.h
Defines RBIMPL_COMPILER_SINCE.
config.h
Thin wrapper to ruby/config.h.
builtin.h
Defines RBIMPL_HAS_BUILTIN.
warning_push.h
Defines RBIMPL_WARNING_PUSH.