| 1 |
#ifndef RBIMPL_HAS_BUILTIN_H /*-*-C++-*-vi:se ft=cpp:*/ |
| 2 |
#define RBIMPL_HAS_BUILTIN_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 #RBIMPL_HAS_BUILTIN. |
| 22 |
*/ |
| 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 |
|
| 40 |
/** Wraps (or simulates) `__has_builtin`. */ |
| 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 */ |