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 clear_except(int)41LIBC_INLINE int clear_except(int) { return 0; } 42 test_except(int)43LIBC_INLINE int test_except(int) { return 0; } 44 get_except()45LIBC_INLINE int get_except() { return 0; } 46 set_except(int)47LIBC_INLINE int set_except(int) { return 0; } 48 raise_except(int)49LIBC_INLINE int raise_except(int) { return 0; } 50 enable_except(int)51LIBC_INLINE int enable_except(int) { return 0; } 52 disable_except(int)53LIBC_INLINE int disable_except(int) { return 0; } 54 get_round()55LIBC_INLINE int get_round() { return FE_TONEAREST; } 56 set_round(int rounding_mode)57LIBC_INLINE int set_round(int rounding_mode) { 58 return (rounding_mode == FE_TONEAREST) ? 0 : 1; 59 } 60 get_env(fenv_t *)61LIBC_INLINE int get_env(fenv_t *) { return 0; } 62 set_env(const fenv_t *)63LIBC_INLINE int set_env(const fenv_t *) { return 0; } 64 65 } // namespace LIBC_NAMESPACE::fputil 66 #endif 67 68 namespace LIBC_NAMESPACE::fputil { 69 set_except_if_required(int excepts)70LIBC_INLINE int set_except_if_required(int excepts) { 71 if (math_errhandling & MATH_ERREXCEPT) 72 return set_except(excepts); 73 return 0; 74 } 75 raise_except_if_required(int excepts)76LIBC_INLINE int raise_except_if_required(int excepts) { 77 if (math_errhandling & MATH_ERREXCEPT) 78 return raise_except(excepts); 79 return 0; 80 } 81 set_errno_if_required(int err)82LIBC_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