Ruby  3.4.0dev (2024-11-05 revision 348a53415339076afc4a02fcd09f3ae36e9c4c61)
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"
33 
35 #if defined(HAVE___ASSUME)
36 # define RBIMPL_HAVE___ASSUME
37 #endif
41 #if RBIMPL_HAS_BUILTIN(__builtin_unreachable)
42 # define RBIMPL_UNREACHABLE_RETURN(_) __builtin_unreachable()
43 
44 #elif defined(RBIMPL_HAVE___ASSUME)
45 # define RBIMPL_UNREACHABLE_RETURN(_) return (__assume(0), (_))
46 
47 #else
48 # define RBIMPL_UNREACHABLE_RETURN(_) return (_)
49 #endif
50 
52 #if RBIMPL_HAS_BUILTIN(__builtin_unreachable)
53 # define RBIMPL_UNREACHABLE __builtin_unreachable
54 
55 #elif defined(RBIMPL_HAVE___ASSUME)
56 # define RBIMPL_UNREACHABLE() __assume(0)
57 #endif
58 
60 #if RBIMPL_COMPILER_SINCE(Intel, 13, 0, 0)
61 # /* icc warnings are false positives. Ignore them. */
62 # /* "warning #2261: __assume expression with side effects discarded" */
63 # define RBIMPL_ASSUME(expr) \
64  RBIMPL_WARNING_PUSH() \
65  RBIMPL_WARNING_IGNORED(2261) \
66  __assume(expr) \
67  RBIMPL_WARNING_POP()
68 
69 #elif defined(RBIMPL_HAVE___ASSUME)
70 # define RBIMPL_ASSUME __assume
71 
72 #elif RBIMPL_HAS_BUILTIN(__builtin_assume)
73 # define RBIMPL_ASSUME __builtin_assume
74 
75 #elif ! defined(RBIMPL_UNREACHABLE)
76 # define RBIMPL_ASSUME(_) RBIMPL_CAST((void)(_))
77 
78 #else
79 # define RBIMPL_ASSUME(_) \
80  (RB_LIKELY(!!(_)) ? RBIMPL_CAST((void)0) : RBIMPL_UNREACHABLE())
81 #endif
82 
83 #if ! defined(RBIMPL_UNREACHABLE)
84 # define RBIMPL_UNREACHABLE() RBIMPL_ASSUME(0)
85 #endif
86 
87 #endif /* RBIMPL_ASSUME_H */
Defines RBIMPL_COMPILER_SINCE.
Defines RBIMPL_HAS_BUILTIN.
Defines RBIMPL_WARNING_PUSH.