171405d90SGuillaume Chatelet //===-- Floating point environment manipulation functions -------*- C++ -*-===// 271405d90SGuillaume Chatelet // 371405d90SGuillaume Chatelet // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 471405d90SGuillaume Chatelet // See https://llvm.org/LICENSE.txt for license information. 571405d90SGuillaume Chatelet // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 671405d90SGuillaume Chatelet // 771405d90SGuillaume Chatelet //===----------------------------------------------------------------------===// 871405d90SGuillaume Chatelet 9270547f3SGuillaume Chatelet #ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H 10270547f3SGuillaume Chatelet #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H 1171405d90SGuillaume Chatelet 1255d4a892SMichael Jones #include "hdr/fenv_macros.h" 135748ad84Slntue #include "hdr/math_macros.h" 1455d4a892SMichael Jones #include "hdr/types/fenv_t.h" 15e2f8c556SGuillaume Chatelet #include "src/__support/macros/attributes.h" // LIBC_INLINE 165ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 17f100ec25SGuillaume Chatelet #include "src/__support/macros/properties/architectures.h" 1831c39439STue Ly #include "src/errno/libc_errno.h" 190aa9593cSTue Ly 20a2569a76SGuillaume Chatelet #if defined(LIBC_TARGET_ARCH_IS_AARCH64) 210f031daeSTue Ly #if defined(__APPLE__) 220f031daeSTue Ly #include "aarch64/fenv_darwin_impl.h" 230f031daeSTue Ly #else 2471405d90SGuillaume Chatelet #include "aarch64/FEnvImpl.h" 250f031daeSTue Ly #endif 26effd56b0SMichael Jones 27effd56b0SMichael Jones // The extra !defined(APPLE) condition is to cause x86_64 MacOS builds to use 28effd56b0SMichael Jones // the dummy implementations below. Once a proper x86_64 darwin fenv is set up, 29effd56b0SMichael Jones // the apple condition here should be removed. 30effd56b0SMichael Jones #elif defined(LIBC_TARGET_ARCH_IS_X86) && !defined(__APPLE__) 3171405d90SGuillaume Chatelet #include "x86_64/FEnvImpl.h" 3286c57b97Slntue #elif defined(LIBC_TARGET_ARCH_IS_ARM) && defined(__ARM_FP) 33ae8e1b8fSSiva Chandra Reddy #include "arm/FEnvImpl.h" 34*157c3fb8SPetr Hosek #elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) && defined(__riscv_flen) 35e3087c4bSMikhail R. Gadelha #include "riscv/FEnvImpl.h" 3671405d90SGuillaume Chatelet #else 3771405d90SGuillaume Chatelet 385ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 395ff3ff33SPetr Hosek namespace fputil { 4071405d90SGuillaume Chatelet 4171405d90SGuillaume Chatelet // All dummy functions silently succeed. 4271405d90SGuillaume Chatelet 4359c809cdSSiva Chandra Reddy LIBC_INLINE int clear_except(int) { return 0; } 4471405d90SGuillaume Chatelet 4559c809cdSSiva Chandra Reddy LIBC_INLINE int test_except(int) { return 0; } 4671405d90SGuillaume Chatelet 47055be3c3STue Ly LIBC_INLINE int get_except() { return 0; } 48055be3c3STue Ly 4959c809cdSSiva Chandra Reddy LIBC_INLINE int set_except(int) { return 0; } 5071405d90SGuillaume Chatelet 5159c809cdSSiva Chandra Reddy LIBC_INLINE int raise_except(int) { return 0; } 5271405d90SGuillaume Chatelet 53e9be85daSMikhail R. Gadelha LIBC_INLINE int enable_except(int) { return 0; } 54e9be85daSMikhail R. Gadelha 55e9be85daSMikhail R. Gadelha LIBC_INLINE int disable_except(int) { return 0; } 56e9be85daSMikhail R. Gadelha 5759c809cdSSiva Chandra Reddy LIBC_INLINE int get_round() { return FE_TONEAREST; } 5871405d90SGuillaume Chatelet 59055be3c3STue Ly LIBC_INLINE int set_round(int rounding_mode) { 60055be3c3STue Ly return (rounding_mode == FE_TONEAREST) ? 0 : 1; 61055be3c3STue Ly } 6271405d90SGuillaume Chatelet 6359c809cdSSiva Chandra Reddy LIBC_INLINE int get_env(fenv_t *) { return 0; } 6471405d90SGuillaume Chatelet 6559c809cdSSiva Chandra Reddy LIBC_INLINE int set_env(const fenv_t *) { return 0; } 6671405d90SGuillaume Chatelet 675ff3ff33SPetr Hosek } // namespace fputil 685ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 6971405d90SGuillaume Chatelet #endif 7071405d90SGuillaume Chatelet 715ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 725ff3ff33SPetr Hosek namespace fputil { 730aa9593cSTue Ly 74c9ee6b19Slntue LIBC_INLINE int clear_except_if_required(int excepts) { 75c9ee6b19Slntue if (math_errhandling & MATH_ERREXCEPT) 76c9ee6b19Slntue return clear_except(excepts); 77c9ee6b19Slntue return 0; 78c9ee6b19Slntue } 79c9ee6b19Slntue 800aa9593cSTue Ly LIBC_INLINE int set_except_if_required(int excepts) { 810aa9593cSTue Ly if (math_errhandling & MATH_ERREXCEPT) 820aa9593cSTue Ly return set_except(excepts); 830aa9593cSTue Ly return 0; 840aa9593cSTue Ly } 850aa9593cSTue Ly 860aa9593cSTue Ly LIBC_INLINE int raise_except_if_required(int excepts) { 870aa9593cSTue Ly if (math_errhandling & MATH_ERREXCEPT) 880aa9593cSTue Ly return raise_except(excepts); 890aa9593cSTue Ly return 0; 900aa9593cSTue Ly } 910aa9593cSTue Ly 920aa9593cSTue Ly LIBC_INLINE void set_errno_if_required(int err) { 930aa9593cSTue Ly if (math_errhandling & MATH_ERRNO) 9431c39439STue Ly libc_errno = err; 950aa9593cSTue Ly } 960aa9593cSTue Ly 975ff3ff33SPetr Hosek } // namespace fputil 985ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 990aa9593cSTue Ly 100270547f3SGuillaume Chatelet #endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H 101