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/config.h" 17 #include "src/__support/macros/properties/architectures.h" 18 #include "src/errno/libc_errno.h" 19 20 #if defined(LIBC_TARGET_ARCH_IS_AARCH64) 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 38 namespace LIBC_NAMESPACE_DECL { 39 namespace fputil { 40 41 // All dummy functions silently succeed. 42 clear_except(int)43LIBC_INLINE int clear_except(int) { return 0; } 44 test_except(int)45LIBC_INLINE int test_except(int) { return 0; } 46 get_except()47LIBC_INLINE int get_except() { return 0; } 48 set_except(int)49LIBC_INLINE int set_except(int) { return 0; } 50 raise_except(int)51LIBC_INLINE int raise_except(int) { return 0; } 52 enable_except(int)53LIBC_INLINE int enable_except(int) { return 0; } 54 disable_except(int)55LIBC_INLINE int disable_except(int) { return 0; } 56 get_round()57LIBC_INLINE int get_round() { return FE_TONEAREST; } 58 set_round(int rounding_mode)59LIBC_INLINE int set_round(int rounding_mode) { 60 return (rounding_mode == FE_TONEAREST) ? 0 : 1; 61 } 62 get_env(fenv_t *)63LIBC_INLINE int get_env(fenv_t *) { return 0; } 64 set_env(const fenv_t *)65LIBC_INLINE int set_env(const fenv_t *) { return 0; } 66 67 } // namespace fputil 68 } // namespace LIBC_NAMESPACE_DECL 69 #endif 70 71 namespace LIBC_NAMESPACE_DECL { 72 namespace fputil { 73 clear_except_if_required(int excepts)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 set_except_if_required(int excepts)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 raise_except_if_required(int excepts)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 set_errno_if_required(int err)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