|
12 | 12 | #include "hdr/fenv_macros.h"
|
13 | 13 | #include "hdr/math_macros.h"
|
14 | 14 | #include "hdr/types/fenv_t.h"
|
| 15 | +#include "src/__support/CPP/type_traits.h" |
15 | 16 | #include "src/__support/libc_errno.h"
|
16 | 17 | #include "src/__support/macros/attributes.h" // LIBC_INLINE
|
17 | 18 | #include "src/__support/macros/config.h"
|
@@ -72,40 +73,58 @@ LIBC_INLINE int set_env(const fenv_t *) { return 0; }
|
72 | 73 | namespace LIBC_NAMESPACE_DECL {
|
73 | 74 | namespace fputil {
|
74 | 75 |
|
75 |
| -LIBC_INLINE static int clear_except_if_required([[maybe_unused]] int excepts) { |
| 76 | +LIBC_INLINE static constexpr int |
| 77 | +clear_except_if_required([[maybe_unused]] int excepts) { |
| 78 | + if (cpp::is_constant_evaluated()) { |
| 79 | + return 0; |
| 80 | + } else { |
76 | 81 | #ifndef LIBC_MATH_HAS_NO_EXCEPT
|
77 |
| - if (math_errhandling & MATH_ERREXCEPT) |
78 |
| - return clear_except(excepts); |
| 82 | + if (math_errhandling & MATH_ERREXCEPT) |
| 83 | + return clear_except(excepts); |
79 | 84 | #endif // LIBC_MATH_HAS_NO_EXCEPT
|
80 |
| - return 0; |
| 85 | + return 0; |
| 86 | + } |
81 | 87 | }
|
82 | 88 |
|
83 |
| -LIBC_INLINE static int set_except_if_required([[maybe_unused]] int excepts) { |
| 89 | +LIBC_INLINE static constexpr int |
| 90 | +set_except_if_required([[maybe_unused]] int excepts) { |
| 91 | + if (cpp::is_constant_evaluated()) { |
| 92 | + return 0; |
| 93 | + } else { |
84 | 94 | #ifndef LIBC_MATH_HAS_NO_EXCEPT
|
85 |
| - if (math_errhandling & MATH_ERREXCEPT) |
86 |
| - return set_except(excepts); |
| 95 | + if (math_errhandling & MATH_ERREXCEPT) |
| 96 | + return set_except(excepts); |
87 | 97 | #endif // LIBC_MATH_HAS_NO_EXCEPT
|
88 |
| - return 0; |
| 98 | + return 0; |
| 99 | + } |
89 | 100 | }
|
90 | 101 |
|
91 |
| -LIBC_INLINE static int raise_except_if_required([[maybe_unused]] int excepts) { |
| 102 | +LIBC_INLINE static constexpr int |
| 103 | +raise_except_if_required([[maybe_unused]] int excepts) { |
| 104 | + if (cpp::is_constant_evaluated()) { |
| 105 | + return 0; |
| 106 | + } else { |
92 | 107 | #ifndef LIBC_MATH_HAS_NO_EXCEPT
|
93 |
| - if (math_errhandling & MATH_ERREXCEPT) |
| 108 | + if (math_errhandling & MATH_ERREXCEPT) |
94 | 109 | #ifdef LIBC_TARGET_ARCH_IS_X86_64
|
95 |
| - return raise_except</*SKIP_X87_FPU*/ true>(excepts); |
| 110 | + return raise_except</*SKIP_X87_FPU*/ true>(excepts); |
96 | 111 | #else // !LIBC_TARGET_ARCH_IS_X86
|
97 |
| - return raise_except(excepts); |
| 112 | + return raise_except(excepts); |
98 | 113 | #endif // LIBC_TARGET_ARCH_IS_X86
|
99 | 114 |
|
100 | 115 | #endif // LIBC_MATH_HAS_NO_EXCEPT
|
101 |
| - return 0; |
| 116 | + return 0; |
| 117 | + } |
102 | 118 | }
|
103 | 119 |
|
104 |
| -LIBC_INLINE static void set_errno_if_required([[maybe_unused]] int err) { |
| 120 | +LIBC_INLINE static constexpr void |
| 121 | +set_errno_if_required([[maybe_unused]] int err) { |
| 122 | + if (!cpp::is_constant_evaluated()) { |
105 | 123 | #ifndef LIBC_MATH_HAS_NO_ERRNO
|
106 |
| - if (math_errhandling & MATH_ERRNO) |
107 |
| - libc_errno = err; |
| 124 | + if (math_errhandling & MATH_ERRNO) |
| 125 | + libc_errno = err; |
108 | 126 | #endif // LIBC_MATH_HAS_NO_ERRNO
|
| 127 | + } |
109 | 128 | }
|
110 | 129 |
|
111 | 130 | } // namespace fputil
|
|
0 commit comments