1 | //===-- Floating point environment manipulation functions -------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H |
10 | #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H |
11 | |
12 | #include "hdr/fenv_macros.h" |
13 | #include "hdr/math_macros.h" |
14 | #include "hdr/types/fenv_t.h" |
15 | #include "src/__support/macros/attributes.h" // LIBC_INLINE |
16 | #include "src/__support/macros/properties/architectures.h" |
17 | #include "src/errno/libc_errno.h" |
18 | |
19 | #if defined(LIBC_TARGET_ARCH_IS_AARCH64) |
20 | #if defined(__APPLE__) |
21 | #include "aarch64/fenv_darwin_impl.h" |
22 | #else |
23 | #include "aarch64/FEnvImpl.h" |
24 | #endif |
25 | |
26 | // The extra !defined(APPLE) condition is to cause x86_64 MacOS builds to use |
27 | // the dummy implementations below. Once a proper x86_64 darwin fenv is set up, |
28 | // the apple condition here should be removed. |
29 | #elif defined(LIBC_TARGET_ARCH_IS_X86) && !defined(__APPLE__) |
30 | #include "x86_64/FEnvImpl.h" |
31 | #elif defined(LIBC_TARGET_ARCH_IS_ARM) && defined(__ARM_FP) |
32 | #include "arm/FEnvImpl.h" |
33 | #elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) |
34 | #include "riscv/FEnvImpl.h" |
35 | #else |
36 | |
37 | namespace LIBC_NAMESPACE::fputil { |
38 | |
39 | // All dummy functions silently succeed. |
40 | |
41 | LIBC_INLINE int clear_except(int) { return 0; } |
42 | |
43 | LIBC_INLINE int test_except(int) { return 0; } |
44 | |
45 | LIBC_INLINE int get_except() { return 0; } |
46 | |
47 | LIBC_INLINE int set_except(int) { return 0; } |
48 | |
49 | LIBC_INLINE int raise_except(int) { return 0; } |
50 | |
51 | LIBC_INLINE int enable_except(int) { return 0; } |
52 | |
53 | LIBC_INLINE int disable_except(int) { return 0; } |
54 | |
55 | LIBC_INLINE int get_round() { return FE_TONEAREST; } |
56 | |
57 | LIBC_INLINE int set_round(int rounding_mode) { |
58 | return (rounding_mode == FE_TONEAREST) ? 0 : 1; |
59 | } |
60 | |
61 | LIBC_INLINE int get_env(fenv_t *) { return 0; } |
62 | |
63 | LIBC_INLINE int set_env(const fenv_t *) { return 0; } |
64 | |
65 | } // namespace LIBC_NAMESPACE::fputil |
66 | #endif |
67 | |
68 | namespace LIBC_NAMESPACE::fputil { |
69 | |
70 | LIBC_INLINE int set_except_if_required(int excepts) { |
71 | if (math_errhandling & MATH_ERREXCEPT) |
72 | return set_except(excepts); |
73 | return 0; |
74 | } |
75 | |
76 | LIBC_INLINE int raise_except_if_required(int excepts) { |
77 | if (math_errhandling & MATH_ERREXCEPT) |
78 | return raise_except(excepts); |
79 | return 0; |
80 | } |
81 | |
82 | LIBC_INLINE void set_errno_if_required(int err) { |
83 | if (math_errhandling & MATH_ERRNO) |
84 | libc_errno = err; |
85 | } |
86 | |
87 | } // namespace LIBC_NAMESPACE::fputil |
88 | |
89 | #endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H |
90 | |