Ruby  3.4.0dev (2024-11-22 revision 0989400a925cd201defdca9eb28eb87200b30785)
builtin.h
Go to the documentation of this file.
1 #ifndef RBIMPL_HAS_BUILTIN_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_HAS_BUILTIN_H
23 #include "ruby/internal/config.h"
25 
26 #if defined(__has_builtin)
27 # if RBIMPL_COMPILER_IS(Intel)
28 # /* :TODO: Intel C Compiler has __has_builtin (since 19.1 maybe?), and is
29 # * reportedly broken. We have to skip them. However the situation can
30 # * change. They might improve someday. We need to revisit here later. */
31 # elif RBIMPL_COMPILER_IS(GCC) && ! __has_builtin(__builtin_alloca)
32 # /* FreeBSD's <sys/cdefs.h> defines its own *broken* version of
33 # * __has_builtin. Cygwin copied that content to be a victim of the
34 # * broken-ness. We don't take them into account. */
35 # else
36 # define RBIMPL_HAVE___HAS_BUILTIN 1
37 # endif
38 #endif
39 
41 #if defined(RBIMPL_HAVE___HAS_BUILTIN)
42 # define RBIMPL_HAS_BUILTIN(_) __has_builtin(_)
43 
44 #elif RBIMPL_COMPILER_IS(GCC)
45 # /* :FIXME: Historically GCC has had tons of builtins, but it implemented
46 # * __has_builtin only since GCC 10. This section can be made more
47 # * granular. */
48 # /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66970 */
49 # define RBIMPL_HAS_BUILTIN(_) (RBIMPL_HAS_BUILTIN_ ## _)
50 # define RBIMPL_HAS_BUILTIN___builtin_add_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0)
51 # define RBIMPL_HAS_BUILTIN___builtin_add_overflow_p RBIMPL_COMPILER_SINCE(GCC, 7, 0, 0)
52 # define RBIMPL_HAS_BUILTIN___builtin_alloca RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
53 # define RBIMPL_HAS_BUILTIN___builtin_alloca_with_align RBIMPL_COMPILER_SINCE(GCC, 6, 1, 0)
54 # define RBIMPL_HAS_BUILTIN___builtin_assume 0
55 # /* See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624 for bswap16. */
56 # define RBIMPL_HAS_BUILTIN___builtin_bswap16 RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0)
57 #ifndef __OpenBSD__
58 # define RBIMPL_HAS_BUILTIN___builtin_bswap32 RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
59 # define RBIMPL_HAS_BUILTIN___builtin_bswap64 RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
60 #endif
61 # define RBIMPL_HAS_BUILTIN___builtin_clz RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
62 # define RBIMPL_HAS_BUILTIN___builtin_clzl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
63 # define RBIMPL_HAS_BUILTIN___builtin_clzll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
64 # define RBIMPL_HAS_BUILTIN___builtin_constant_p RBIMPL_COMPILER_SINCE(GCC, 2,95, 3)
65 # define RBIMPL_HAS_BUILTIN___builtin_ctz RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
66 # define RBIMPL_HAS_BUILTIN___builtin_ctzl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
67 # define RBIMPL_HAS_BUILTIN___builtin_ctzll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
68 # define RBIMPL_HAS_BUILTIN___builtin_expect RBIMPL_COMPILER_SINCE(GCC, 3, 0, 0)
69 # define RBIMPL_HAS_BUILTIN___builtin_mul_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0)
70 # define RBIMPL_HAS_BUILTIN___builtin_mul_overflow_p RBIMPL_COMPILER_SINCE(GCC, 7, 0, 0)
71 # define RBIMPL_HAS_BUILTIN___builtin_popcount RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
72 # define RBIMPL_HAS_BUILTIN___builtin_popcountl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
73 # define RBIMPL_HAS_BUILTIN___builtin_popcountll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
74 # define RBIMPL_HAS_BUILTIN___builtin_rotateleft32 0
75 # define RBIMPL_HAS_BUILTIN___builtin_rotateleft64 0
76 # define RBIMPL_HAS_BUILTIN___builtin_rotateright32 0
77 # define RBIMPL_HAS_BUILTIN___builtin_rotateright64 0
78 # define RBIMPL_HAS_BUILTIN___builtin_sub_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0)
79 # define RBIMPL_HAS_BUILTIN___builtin_sub_overflow_p RBIMPL_COMPILER_SINCE(GCC, 7, 0, 0)
80 # define RBIMPL_HAS_BUILTIN___builtin_unreachable RBIMPL_COMPILER_SINCE(GCC, 4, 5, 0)
81 # /* Note that "0, 0, 0" might be inaccurate. */
82 
83 #else
84 # /* Take config.h definition when available */
85 # define RBIMPL_HAS_BUILTIN(_) ((RBIMPL_HAS_BUILTIN_ ## _)+0)
86 # define RBIMPL_HAS_BUILTIN___builtin_add_overflow HAVE_BUILTIN___BUILTIN_ADD_OVERFLOW
87 # define RBIMPL_HAS_BUILTIN___builtin_add_overflow_p HAVE_BUILTIN___BUILTIN_ADD_OVERFLOW_P
88 # define RBIMPL_HAS_BUILTIN___builtin_alloca 0
89 # define RBIMPL_HAS_BUILTIN___builtin_alloca_with_align HAVE_BUILTIN___BUILTIN_ALLOCA_WITH_ALIGN
90 # define RBIMPL_HAS_BUILTIN___builtin_assume 0
91 # define RBIMPL_HAS_BUILTIN___builtin_assume_aligned HAVE_BUILTIN___BUILTIN_ASSUME_ALIGNED
92 # define RBIMPL_HAS_BUILTIN___builtin_bswap16 HAVE_BUILTIN___BUILTIN_BSWAP16
93 # define RBIMPL_HAS_BUILTIN___builtin_bswap32 HAVE_BUILTIN___BUILTIN_BSWAP32
94 # define RBIMPL_HAS_BUILTIN___builtin_bswap64 HAVE_BUILTIN___BUILTIN_BSWAP64
95 # define RBIMPL_HAS_BUILTIN___builtin_clz HAVE_BUILTIN___BUILTIN_CLZ
96 # define RBIMPL_HAS_BUILTIN___builtin_clzl HAVE_BUILTIN___BUILTIN_CLZL
97 # define RBIMPL_HAS_BUILTIN___builtin_clzll HAVE_BUILTIN___BUILTIN_CLZLL
98 # define RBIMPL_HAS_BUILTIN___builtin_constant_p HAVE_BUILTIN___BUILTIN_CONSTANT_P
99 # define RBIMPL_HAS_BUILTIN___builtin_ctz HAVE_BUILTIN___BUILTIN_CTZ
100 # define RBIMPL_HAS_BUILTIN___builtin_ctzl 0
101 # define RBIMPL_HAS_BUILTIN___builtin_ctzll HAVE_BUILTIN___BUILTIN_CTZLL
102 # define RBIMPL_HAS_BUILTIN___builtin_expect HAVE_BUILTIN___BUILTIN_EXPECT
103 # define RBIMPL_HAS_BUILTIN___builtin_mul_overflow HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW
104 # define RBIMPL_HAS_BUILTIN___builtin_mul_overflow_p HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW_P
105 # define RBIMPL_HAS_BUILTIN___builtin_popcount HAVE_BUILTIN___BUILTIN_POPCOUNT
106 # define RBIMPL_HAS_BUILTIN___builtin_popcountl 0
107 # define RBIMPL_HAS_BUILTIN___builtin_rotateleft32 0
108 # define RBIMPL_HAS_BUILTIN___builtin_rotateleft64 0
109 # define RBIMPL_HAS_BUILTIN___builtin_rotateright32 0
110 # define RBIMPL_HAS_BUILTIN___builtin_rotateright64 0
111 # define RBIMPL_HAS_BUILTIN___builtin_popcountll HAVE_BUILTIN___BUILTIN_POPCOUNTLL
112 # define RBIMPL_HAS_BUILTIN___builtin_sub_overflow HAVE_BUILTIN___BUILTIN_SUB_OVERFLOW
113 # define RBIMPL_HAS_BUILTIN___builtin_sub_overflow_p HAVE_BUILTIN___BUILTIN_SUB_OVERFLOW_P
114 # if defined(HAVE___BUILTIN_UNREACHABLE)
115 # define RBIMPL_HAS_BUILTIN___builtin_unreachable 1
116 # else
117 # define RBIMPL_HAS_BUILTIN___builtin_unreachable 0
118 # endif
119 #endif
120 
121 #endif /* RBIMPL_HAS_BUILTIN_H */
Defines RBIMPL_COMPILER_SINCE.