Ruby: include/ruby/internal/has/builtin.h Source File

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

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"
24#include "ruby/internal/compiler_since.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_alloca RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0)
52# define RBIMPL_HAS_BUILTIN___builtin_alloca_with_align RBIMPL_COMPILER_SINCE(GCC, 6, 1, 0)
53# define RBIMPL_HAS_BUILTIN___builtin_assume 0
54# /* See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624 for bswap16. */
55# define RBIMPL_HAS_BUILTIN___builtin_bswap16 RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0)
56#ifndef __OpenBSD__
57# define RBIMPL_HAS_BUILTIN___builtin_bswap32 RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
58# define RBIMPL_HAS_BUILTIN___builtin_bswap64 RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
59#endif
60# define RBIMPL_HAS_BUILTIN___builtin_clz RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
61# define RBIMPL_HAS_BUILTIN___builtin_clzl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
62# define RBIMPL_HAS_BUILTIN___builtin_clzll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
63# define RBIMPL_HAS_BUILTIN___builtin_constant_p RBIMPL_COMPILER_SINCE(GCC, 2,95, 3)
64# define RBIMPL_HAS_BUILTIN___builtin_ctz RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
65# define RBIMPL_HAS_BUILTIN___builtin_ctzl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
66# define RBIMPL_HAS_BUILTIN___builtin_ctzll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
67# define RBIMPL_HAS_BUILTIN___builtin_expect RBIMPL_COMPILER_SINCE(GCC, 3, 0, 0)
68# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0)
69# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow_p RBIMPL_COMPILER_SINCE(GCC, 7, 0, 0)
70# define RBIMPL_HAS_BUILTIN___builtin_popcount RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
71# define RBIMPL_HAS_BUILTIN___builtin_popcountl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
72# define RBIMPL_HAS_BUILTIN___builtin_popcountll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0)
73# define RBIMPL_HAS_BUILTIN___builtin_rotateleft32 0
74# define RBIMPL_HAS_BUILTIN___builtin_rotateleft64 0
75# define RBIMPL_HAS_BUILTIN___builtin_rotateright32 0
76# define RBIMPL_HAS_BUILTIN___builtin_rotateright64 0
77# define RBIMPL_HAS_BUILTIN___builtin_sub_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0)
78# define RBIMPL_HAS_BUILTIN___builtin_unreachable RBIMPL_COMPILER_SINCE(GCC, 4, 5, 0)
79# /* Note that "0, 0, 0" might be inaccurate. */
80
81#else
82# /* Take config.h definition when available */
83# define RBIMPL_HAS_BUILTIN(_) ((RBIMPL_HAS_BUILTIN_ ## _)+0)
84# define RBIMPL_HAS_BUILTIN___builtin_add_overflow HAVE_BUILTIN___BUILTIN_ADD_OVERFLOW
85# define RBIMPL_HAS_BUILTIN___builtin_alloca 0
86# define RBIMPL_HAS_BUILTIN___builtin_alloca_with_align HAVE_BUILTIN___BUILTIN_ALLOCA_WITH_ALIGN
87# define RBIMPL_HAS_BUILTIN___builtin_assume 0
88# define RBIMPL_HAS_BUILTIN___builtin_assume_aligned HAVE_BUILTIN___BUILTIN_ASSUME_ALIGNED
89# define RBIMPL_HAS_BUILTIN___builtin_bswap16 HAVE_BUILTIN___BUILTIN_BSWAP16
90# define RBIMPL_HAS_BUILTIN___builtin_bswap32 HAVE_BUILTIN___BUILTIN_BSWAP32
91# define RBIMPL_HAS_BUILTIN___builtin_bswap64 HAVE_BUILTIN___BUILTIN_BSWAP64
92# define RBIMPL_HAS_BUILTIN___builtin_clz HAVE_BUILTIN___BUILTIN_CLZ
93# define RBIMPL_HAS_BUILTIN___builtin_clzl HAVE_BUILTIN___BUILTIN_CLZL
94# define RBIMPL_HAS_BUILTIN___builtin_clzll HAVE_BUILTIN___BUILTIN_CLZLL
95# define RBIMPL_HAS_BUILTIN___builtin_constant_p HAVE_BUILTIN___BUILTIN_CONSTANT_P
96# define RBIMPL_HAS_BUILTIN___builtin_ctz HAVE_BUILTIN___BUILTIN_CTZ
97# define RBIMPL_HAS_BUILTIN___builtin_ctzl 0
98# define RBIMPL_HAS_BUILTIN___builtin_ctzll HAVE_BUILTIN___BUILTIN_CTZLL
99# define RBIMPL_HAS_BUILTIN___builtin_expect HAVE_BUILTIN___BUILTIN_EXPECT
100# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW
101# define RBIMPL_HAS_BUILTIN___builtin_mul_overflow_p HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW_P
102# define RBIMPL_HAS_BUILTIN___builtin_popcount HAVE_BUILTIN___BUILTIN_POPCOUNT
103# define RBIMPL_HAS_BUILTIN___builtin_popcountl 0
104# define RBIMPL_HAS_BUILTIN___builtin_rotateleft32 0
105# define RBIMPL_HAS_BUILTIN___builtin_rotateleft64 0
106# define RBIMPL_HAS_BUILTIN___builtin_rotateright32 0
107# define RBIMPL_HAS_BUILTIN___builtin_rotateright64 0
108# define RBIMPL_HAS_BUILTIN___builtin_popcountll HAVE_BUILTIN___BUILTIN_POPCOUNTLL
109# define RBIMPL_HAS_BUILTIN___builtin_sub_overflow HAVE_BUILTIN___BUILTIN_SUB_OVERFLOW
110# if defined(HAVE___BUILTIN_UNREACHABLE)
111# define RBIMPL_HAS_BUILTIN___builtin_unreachable 1
112# else
113# define RBIMPL_HAS_BUILTIN___builtin_unreachable 0
114# endif
115#endif
116
117#endif /* RBIMPL_HAS_BUILTIN_H */
compiler_since.h
Defines RBIMPL_COMPILER_SINCE.