toolchain: Define a HAS_BUILTIN(x) macro in toolchain.h.
Compilers based on Clang provide a __has_builtin(x) macro which can be used to detect in the preprocessor if a given builtin function is supported by the compiler. For other compilers (notably GCC), we provide an alternative definition of HAS_BUILTIN(x) that depends on the toolchain-specific header file to declare which builtin functions are supported based on the current compiler version. Signed-off-by: Jakob Olesen <jolesen@fb.com>
This commit is contained in:
parent
e66c0da0c1
commit
f4f09dd7cd
2 changed files with 34 additions and 0 deletions
|
@ -15,6 +15,24 @@
|
||||||
#ifndef ZEPHYR_INCLUDE_TOOLCHAIN_H_
|
#ifndef ZEPHYR_INCLUDE_TOOLCHAIN_H_
|
||||||
#define ZEPHYR_INCLUDE_TOOLCHAIN_H_
|
#define ZEPHYR_INCLUDE_TOOLCHAIN_H_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def HAS_BUILTIN(x)
|
||||||
|
* @brief Check if the compiler supports the built-in function \a x.
|
||||||
|
*
|
||||||
|
* This macro is for use with conditional compilation to enable code using a
|
||||||
|
* builtin function that may not be available in every compiler.
|
||||||
|
*/
|
||||||
|
#ifdef __has_builtin
|
||||||
|
#define HAS_BUILTIN(x) __has_builtin(x)
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
* The compiler doesn't provide the __has_builtin() macro, so instead we depend
|
||||||
|
* on the toolchain-specific headers to define HAS_BUILTIN_x for the builtins
|
||||||
|
* supported.
|
||||||
|
*/
|
||||||
|
#define HAS_BUILTIN(x) HAS_BUILTIN_##x
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__XCC__)
|
#if defined(__XCC__)
|
||||||
#include <toolchain/xcc.h>
|
#include <toolchain/xcc.h>
|
||||||
#elif defined(__GNUC__) || (defined(_LINKER) && defined(__GCC_LINKER_CMD__))
|
#elif defined(__GNUC__) || (defined(_LINKER) && defined(__GCC_LINKER_CMD__))
|
||||||
|
|
|
@ -152,6 +152,22 @@ do { \
|
||||||
#endif
|
#endif
|
||||||
#define __unused __attribute__((__unused__))
|
#define __unused __attribute__((__unused__))
|
||||||
|
|
||||||
|
/* Builtins with availability that depend on the compiler version. */
|
||||||
|
#if __GNUC__ >= 5
|
||||||
|
#define HAS_BUILTIN___builtin_add_overflow 1
|
||||||
|
#define HAS_BUILTIN___builtin_sub_overflow 1
|
||||||
|
#define HAS_BUILTIN___builtin_mul_overflow 1
|
||||||
|
#define HAS_BUILTIN___builtin_div_overflow 1
|
||||||
|
#endif
|
||||||
|
#if __GNUC__ >= 4
|
||||||
|
#define HAS_BUILTIN___builtin_clz 1
|
||||||
|
#define HAS_BUILTIN___builtin_clzl 1
|
||||||
|
#define HAS_BUILTIN___builtin_clzll 1
|
||||||
|
#define HAS_BUILTIN___builtin_ctz 1
|
||||||
|
#define HAS_BUILTIN___builtin_ctzl 1
|
||||||
|
#define HAS_BUILTIN___builtin_ctzll 1
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Be *very* careful with this, you cannot filter out with -wno-deprecated,
|
/* Be *very* careful with this, you cannot filter out with -wno-deprecated,
|
||||||
* which has implications for -Werror
|
* which has implications for -Werror
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue