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