Files
externals/linux/include/ActivMiddleware/Config/Compilers/GCC.h
T
2023-12-15 13:15:08 -05:00

162 lines
4.9 KiB
C++

/**
* @file include/ActivMiddleware/Config/Compilers/GCC.h
*
* @brief GNU C++ configuration file.
*/
#if (!defined ACTIV_CONFIG_COMPILERS_GCC_H)
#define ACTIV_CONFIG_COMPILERS_GCC_H
#if (!defined ACTIV_COMPILER_CLANG && !defined ACTIV_COMPILER_EMCC && (ACTIV_GCC_COMPILER_VERSION < ACTIV_MAKE_GCC_COMPILER_VERSION(4, 3)))
#error GCC version not supported
#endif
#if (!defined ACTIV_COMPILER_NAME)
#define ACTIV_COMPILER_NAME "GNU C++ " __VERSION__
#endif
#if (!defined ACTIV_PLATFORM_WINDOWS)
#define ACTIV_BUILDING_DLL_EXPORTED_API __attribute__ ((visibility("default")))
#define ACTIV_BUILDING_DLL_INLINE_API __attribute__ ((visibility("hidden")))
#define ACTIV_BUILDING_DLL_LOCAL_API __attribute__ ((visibility("hidden")))
#define ACTIV_USING_DLL_EXPORTED_API
#define ACTIV_USING_DLL_INLINE_API
#define ACTIV_USING_DLL_LOCAL_API
#else
#define ACTIV_BUILDING_DLL_EXPORTED_API
#define ACTIV_BUILDING_DLL_INLINE_API
#define ACTIV_BUILDING_DLL_LOCAL_API
#define ACTIV_USING_DLL_EXPORTED_API
#define ACTIV_USING_DLL_INLINE_API
#define ACTIV_USING_DLL_LOCAL_API
#endif
#define ACTIV_BUILDING_LIB_EXPORTED_API
#define ACTIV_BUILDING_LIB_INLINE_API
#define ACTIV_BUILDING_LIB_LOCAL_API
#define ACTIV_USING_LIB_EXPORTED_API
#define ACTIV_USING_LIB_INLINE_API
#define ACTIV_USING_LIB_LOCAL_API
/**
* @brief Define rules for exporting template member functions.
*
* The Intel & Visual C++ compilers have different rules for __declspec exporting template
* instantiations from dlls. Use ACTIV_TEMPLATE_API as a workaround, e.g.
*
* class Example
* {
* template \<typename T\>
* ACTIV_TEMPLATE_API(MY_LIB_API) void Fn(T &);
* };
*
* @param a __declspec macro, e.g. ACTIV_BASE_API.
*/
#define ACTIV_TEMPLATE_API(a) a
#if (!defined ACTIV_DECLARE_TEMPLATE_PARAMETER_FRIEND)
#if (ACTIV_GCC_COMPILER_VERSION >= ACTIV_MAKE_GCC_COMPILER_VERSION(4, 7))
#define ACTIV_DECLARE_TEMPLATE_PARAMETER_FRIEND(T) friend T
#else
namespace Activ
{
template<typename T>
class GccFriendWorkaround
{
public:
typedef T type;
};
} // namespace Activ
#define ACTIV_DECLARE_TEMPLATE_PARAMETER_FRIEND(T) friend class ::Activ::GccFriendWorkaround<T>::type
#endif
#endif
//! Ensure a function is always inlined.
#if (defined _DEBUG)
#define ACTIV_FORCE_INLINE inline
#else
#define ACTIV_FORCE_INLINE inline __attribute__((__always_inline__))
#endif
//! Ensure a function is never inlined.
#define ACTIV_NEVER_INLINE __attribute__((__noinline__))
/**
* @brief Specify that a function is a printf style function.
*
* @param type printf, scanf, strftime.
* @param formatIndex for static or global functions, the 1-based index of the parameter containing the format specifier string.
* For member functions, the 2-based index.
* @param firstParameterIndex for static or global functions, the 1-based index of the parameter containing the first value to be
* used by the format string. For member functions, the 2-based index.
* Use 0 if the function takes a va_list of parameters.
*/
#define ACTIV_PRINTF_FUNCTION(type, formatIndex, firstParameterIndex) \
__attribute__ ((format (type, formatIndex, firstParameterIndex)))
#define stricmp strcasecmp
#define strnicmp strncasecmp
/**
* @brief Give a hint that a switch case statement is likely.
*
* Usage:
* switch (ACTIV_LIKELY_SWITCH_CASE(variable, 0))
* {
* case 0: <-- the expected case.
* case 1:
* ...
* default:
* }
*
* If the expected case statement is not present then default is the likely case.
*
* @param expr the expression under test.
* @param expected the expected value of expr.
*
* @return expr
*/
#define ACTIV_LIKELY_SWITCH_CASE(expr, expected) __builtin_expect(expr, expected)
/**
* @brief Give a hint that an expression is @a likely to be true.
*
* @param expr
*/
#define ACTIV_LIKELY(expr) __builtin_expect(!!(expr), 1)
/**
* @brief Give a hint that an expression is @a unlikely to be true.
*
* @param expr
*/
#define ACTIV_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
// TODO: add _DEBUG case counting mispredicted cases.
//! Mark a function with the hot attribute.
#define ACTIV_HOT __attribute__ ((hot))
//! Mark a function with the cold attribute.
#define ACTIV_COLD __attribute__ ((cold))
// Pragma push/pop were added in gcc 4.6 but gcc < 5.0 has a bug where the "padded" warning is left enabled after the pop, see
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59304.
// Only apply padding warnings on 64 bit.
#if (ACTIV_GCC_COMPILER_VERSION >= ACTIV_MAKE_GCC_COMPILER_VERSION(5, 0)) && (ACTIV_PROCESSOR_WORD_SIZE == 64)
//! Start enablement of compiler error on struct padding.
#define ACTIV_ENABLE_ERROR_ON_PADDING_START \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic error \"-Wpadded\"")
//! End enablement of compiler error on struct padding.
#define ACTIV_ENABLE_ERROR_ON_PADDING_END \
_Pragma("GCC diagnostic pop")
#endif // (ACTIV_GCC_COMPILER_VERSION >= ACTIV_MAKE_GCC_COMPILER_VERSION(5, 0))
#endif // (!defined ACTIV_CONFIG_COMPILERS_GCC_H)