Warning: This file is not a C or C++ file. It does not have highlighting.

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/libc_errno.h"
16#include "src/__support/macros/attributes.h" // LIBC_INLINE
17#include "src/__support/macros/config.h"
18#include "src/__support/macros/properties/architectures.h"
19
20#if defined(LIBC_TARGET_ARCH_IS_AARCH64) && defined(__ARM_FP)
21#if defined(__APPLE__)
22#include "aarch64/fenv_darwin_impl.h"
23#else
24#include "aarch64/FEnvImpl.h"
25#endif
26
27// The extra !defined(APPLE) condition is to cause x86_64 MacOS builds to use
28// the dummy implementations below. Once a proper x86_64 darwin fenv is set up,
29// the apple condition here should be removed.
30#elif defined(LIBC_TARGET_ARCH_IS_X86) && !defined(__APPLE__)
31#include "x86_64/FEnvImpl.h"
32#elif defined(LIBC_TARGET_ARCH_IS_ARM) && defined(__ARM_FP)
33#include "arm/FEnvImpl.h"
34#elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) && defined(__riscv_flen)
35#include "riscv/FEnvImpl.h"
36#else
37
38namespace LIBC_NAMESPACE_DECL {
39namespace fputil {
40
41// All dummy functions silently succeed.
42
43LIBC_INLINE int clear_except(int) { return 0; }
44
45LIBC_INLINE int test_except(int) { return 0; }
46
47LIBC_INLINE int get_except() { return 0; }
48
49LIBC_INLINE int set_except(int) { return 0; }
50
51LIBC_INLINE int raise_except(int) { return 0; }
52
53LIBC_INLINE int enable_except(int) { return 0; }
54
55LIBC_INLINE int disable_except(int) { return 0; }
56
57LIBC_INLINE int get_round() { return FE_TONEAREST; }
58
59LIBC_INLINE int set_round(int rounding_mode) {
60 return (rounding_mode == FE_TONEAREST) ? 0 : 1;
61}
62
63LIBC_INLINE int get_env(fenv_t *) { return 0; }
64
65LIBC_INLINE int set_env(const fenv_t *) { return 0; }
66
67} // namespace fputil
68} // namespace LIBC_NAMESPACE_DECL
69#endif
70
71namespace LIBC_NAMESPACE_DECL {
72namespace fputil {
73
74LIBC_INLINE int clear_except_if_required(int excepts) {
75 if (math_errhandling & MATH_ERREXCEPT)
76 return clear_except(excepts);
77 return 0;
78}
79
80LIBC_INLINE int set_except_if_required(int excepts) {
81 if (math_errhandling & MATH_ERREXCEPT)
82 return set_except(excepts);
83 return 0;
84}
85
86LIBC_INLINE int raise_except_if_required(int excepts) {
87 if (math_errhandling & MATH_ERREXCEPT)
88 return raise_except(excepts);
89 return 0;
90}
91
92LIBC_INLINE void set_errno_if_required(int err) {
93 if (math_errhandling & MATH_ERRNO)
94 libc_errno = err;
95}
96
97} // namespace fputil
98} // namespace LIBC_NAMESPACE_DECL
99
100#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H
101

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of libc/src/__support/FPUtil/FEnvImpl.h