Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
has_builtin_abs.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_PLATFORM_QUERIES_HAS_BUILTIN_ABS_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_PLATFORM_QUERIES_HAS_BUILTIN_ABS_HPP_
7
8// IWYU pragma: private, include "arene/base/compiler_support/platform_queries.hpp"
9// IWYU pragma: friend "arene/base/compiler_support/platform_queries/.*"
10
11// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
12#include "arene/base/compiler_support/platform_queries/compiler_info.hpp" // IWYU pragma: keep
13#include "arene/base/compiler_support/platform_queries/has_builtin.hpp"
14#include "arene/base/compiler_support/preprocessor.hpp"
15// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
16
17// NOLINTBEGIN(cppcoreguidelines-macro-usage)
18// parasoft-begin-suppress AUTOSAR-A16_0_1-d-2 "Conditional defines permitted by A16-0-1 Permit #2"
19// parasoft-begin-suppress AUTOSAR-A16_0_1-a-2 "Conditional defines permitted by A16-0-1 Permit #2"
20
21/// @def ARENE_HAS_BUILTIN_FABS
22/// @brief A platform support query for testing if @c __builtin_fabs is defined.
23///
24/// Usage:
25/// @code{c++}
26/// #if ARENE_IS_ON(ARENE_HAS_BUILTIN_FABS)
27/// @endcode
28///
29/// The value of this query is determined as follows, in order of precedence:
30/// 1. If @c __builtin_fabs is defined, it is @c ARENE_ON_BY_DEFAULT
31/// 1. Otherwise, it is @c ARENE_OFF_BY_DEFAULT
32
33// If the macro is defined earlier, do not redefine it.
34// This allows testing the difference implementation of the builtin abs.
35#ifndef ARENE_HAS_BUILTIN_FABS_I_
36// parasoft-begin-suppress AUTOSAR-M16_0_7-a-2 "False positive: not used as a macro"
37#if ARENE_HAS_BUILTIN(__builtin_fabs)
38// parasoft-end-suppress AUTOSAR-M16_0_7-a-2
39#define ARENE_HAS_BUILTIN_FABS_I_ ARENE_ON_BY_DEFAULT
40#elif !defined(__QNX__) && ARENE_IS_ON(ARENE_COMPILER_GCC) && __GNUC__ >= 8
41// The __builtin_fabs() exists in GCC (at least) 8 and later,
42// but the __has_builtin query was not added until GCC 10 and so we
43// may have returned a false negative when probing for the builtin above.
44#define ARENE_HAS_BUILTIN_FABS_I_ ARENE_ON_BY_DEFAULT
45#else
46#define ARENE_HAS_BUILTIN_FABS_I_ ARENE_OFF_BY_DEFAULT
47#endif
48#endif
49
50#ifdef ARENE_DOC_GENERATION_RUNNING // make this appear when running doxygen, as it won't otherwise.
51#ifndef ARENE_HAS_BUILTIN_FABS
52#define ARENE_HAS_BUILTIN_FABS
53#endif
54#endif
55
56/// @def ARENE_HAS_BUILTIN_FABSF
57/// @brief A platform support query for testing if @c __builtin_fabsf is defined.
58///
59/// Usage:
60/// @code{c++}
61/// #if ARENE_IS_ON(ARENE_HAS_BUILTIN_FABSF)
62/// @endcode
63///
64/// The value of this query is determined as follows, in order of precedence:
65/// 1. If @c __builtin_fabsf is defined, it is @c ARENE_ON_BY_DEFAULT
66/// 1. Otherwise, it is @c ARENE_OFF_BY_DEFAULT
67
68#ifndef ARENE_HAS_BUILTIN_FABSF_I_
69// parasoft-begin-suppress AUTOSAR-M16_0_7-a-2 "False positive: not used as a macro"
70#if ARENE_HAS_BUILTIN(__builtin_fabsf)
71// parasoft-end-suppress AUTOSAR-M16_0_7-a-2
72#define ARENE_HAS_BUILTIN_FABSF_I_ ARENE_ON_BY_DEFAULT
73#elif !defined(__QNX__) && ARENE_IS_ON(ARENE_COMPILER_GCC) && __GNUC__ >= 8
74// The __builtin_fabsf() exists in GCC (at least) 8 and later,
75// but the __builtin_fabsf query was not added until GCC 10 and so we
76// may have returned a false negative when probing for the builtin above.
77#define ARENE_HAS_BUILTIN_FABSF_I_ ARENE_ON_BY_DEFAULT
78#else
79#define ARENE_HAS_BUILTIN_FABSF_I_ ARENE_OFF_BY_DEFAULT
80#endif
81#endif
82
83#ifdef ARENE_DOC_GENERATION_RUNNING // make this appear when running doxygen, as it won't otherwise.
84#ifndef ARENE_HAS_BUILTIN_FABSF
85#define ARENE_HAS_BUILTIN_FABSF
86#endif
87#endif
88
89// NOLINTEND(cppcoreguidelines-macro-usage)
90// parasoft-end-suppress AUTOSAR-A16_0_1-d-2
91// parasoft-end-suppress AUTOSAR-A16_0_1-a-2
92
93#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_PLATFORM_QUERIES_HAS_BUILTIN_ABS_HPP_