Skip to content

Commit b833734

Browse files
authored
[libc][math] Skip setting errno and floating point exception for math functions when LIBC_MATH flag has LIBC_MATH_NO_ERRNO and LIBC_MATH_NO_EXCEPT. (#144920)
1 parent c1ac87b commit b833734

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

libc/src/__support/FPUtil/FEnvImpl.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "src/__support/libc_errno.h"
1616
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1717
#include "src/__support/macros/config.h"
18+
#include "src/__support/macros/optimization.h"
1819
#include "src/__support/macros/properties/architectures.h"
1920

2021
#if defined(LIBC_TARGET_ARCH_IS_AARCH64) && defined(__ARM_FP)
@@ -71,27 +72,35 @@ LIBC_INLINE int set_env(const fenv_t *) { return 0; }
7172
namespace LIBC_NAMESPACE_DECL {
7273
namespace fputil {
7374

74-
LIBC_INLINE int clear_except_if_required(int excepts) {
75+
LIBC_INLINE static int clear_except_if_required([[maybe_unused]] int excepts) {
76+
#ifndef LIBC_MATH_HAS_NO_EXCEPT
7577
if (math_errhandling & MATH_ERREXCEPT)
7678
return clear_except(excepts);
79+
#endif // LIBC_MATH_HAS_NO_EXCEPT
7780
return 0;
7881
}
7982

80-
LIBC_INLINE int set_except_if_required(int excepts) {
83+
LIBC_INLINE static int set_except_if_required([[maybe_unused]] int excepts) {
84+
#ifndef LIBC_MATH_HAS_NO_EXCEPT
8185
if (math_errhandling & MATH_ERREXCEPT)
8286
return set_except(excepts);
87+
#endif // LIBC_MATH_HAS_NO_EXCEPT
8388
return 0;
8489
}
8590

86-
LIBC_INLINE int raise_except_if_required(int excepts) {
91+
LIBC_INLINE static int raise_except_if_required([[maybe_unused]] int excepts) {
92+
#ifndef LIBC_MATH_HAS_NO_EXCEPT
8793
if (math_errhandling & MATH_ERREXCEPT)
8894
return raise_except(excepts);
95+
#endif // LIBC_MATH_HAS_NO_EXCEPT
8996
return 0;
9097
}
9198

92-
LIBC_INLINE void set_errno_if_required(int err) {
99+
LIBC_INLINE static void set_errno_if_required([[maybe_unused]] int err) {
100+
#ifndef LIBC_MATH_HAS_NO_ERRNO
93101
if (math_errhandling & MATH_ERRNO)
94102
libc_errno = err;
103+
#endif // LIBC_MATH_HAS_NO_ERRNO
95104
}
96105

97106
} // namespace fputil

libc/src/__support/macros/optimization.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,12 @@ LIBC_INLINE constexpr bool expects_bool_condition(T value, T expected) {
6363
#define LIBC_MATH_HAS_INTERMEDIATE_COMP_IN_FLOAT
6464
#endif
6565

66+
#if (LIBC_MATH & LIBC_MATH_NO_ERRNO)
67+
#define LIBC_MATH_HAS_NO_ERRNO
68+
#endif
69+
70+
#if (LIBC_MATH & LIBC_MATH_NO_EXCEPT)
71+
#define LIBC_MATH_HAS_NO_EXCEPT
72+
#endif
73+
6674
#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_OPTIMIZATION_H

0 commit comments

Comments
 (0)