Path: blob/main/contrib/llvm-project/libc/src/__support/FPUtil/FEnvImpl.h
213799 views
//===-- Floating point environment manipulation functions -------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H9#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H1011#include "hdr/fenv_macros.h"12#include "hdr/math_macros.h"13#include "hdr/types/fenv_t.h"14#include "src/__support/libc_errno.h"15#include "src/__support/macros/attributes.h" // LIBC_INLINE16#include "src/__support/macros/config.h"17#include "src/__support/macros/optimization.h"18#include "src/__support/macros/properties/architectures.h"1920#if defined(LIBC_TARGET_ARCH_IS_AARCH64) && defined(__ARM_FP)21#if defined(__APPLE__)22#include "aarch64/fenv_darwin_impl.h"23#else24#include "aarch64/FEnvImpl.h"25#endif2627// The extra !defined(APPLE) condition is to cause x86_64 MacOS builds to use28// 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#else3738namespace LIBC_NAMESPACE_DECL {39namespace fputil {4041// All dummy functions silently succeed.4243LIBC_INLINE int clear_except(int) { return 0; }4445LIBC_INLINE int test_except(int) { return 0; }4647LIBC_INLINE int get_except() { return 0; }4849LIBC_INLINE int set_except(int) { return 0; }5051LIBC_INLINE int raise_except(int) { return 0; }5253LIBC_INLINE int enable_except(int) { return 0; }5455LIBC_INLINE int disable_except(int) { return 0; }5657LIBC_INLINE int get_round() { return FE_TONEAREST; }5859LIBC_INLINE int set_round(int rounding_mode) {60return (rounding_mode == FE_TONEAREST) ? 0 : 1;61}6263LIBC_INLINE int get_env(fenv_t *) { return 0; }6465LIBC_INLINE int set_env(const fenv_t *) { return 0; }6667} // namespace fputil68} // namespace LIBC_NAMESPACE_DECL69#endif7071namespace LIBC_NAMESPACE_DECL {72namespace fputil {7374LIBC_INLINE static int clear_except_if_required([[maybe_unused]] int excepts) {75#ifndef LIBC_MATH_HAS_NO_EXCEPT76if (math_errhandling & MATH_ERREXCEPT)77return clear_except(excepts);78#endif // LIBC_MATH_HAS_NO_EXCEPT79return 0;80}8182LIBC_INLINE static int set_except_if_required([[maybe_unused]] int excepts) {83#ifndef LIBC_MATH_HAS_NO_EXCEPT84if (math_errhandling & MATH_ERREXCEPT)85return set_except(excepts);86#endif // LIBC_MATH_HAS_NO_EXCEPT87return 0;88}8990LIBC_INLINE static int raise_except_if_required([[maybe_unused]] int excepts) {91#ifndef LIBC_MATH_HAS_NO_EXCEPT92if (math_errhandling & MATH_ERREXCEPT)93#ifdef LIBC_TARGET_ARCH_IS_X86_6494return raise_except</*SKIP_X87_FPU*/ true>(excepts);95#else // !LIBC_TARGET_ARCH_IS_X8696return raise_except(excepts);97#endif // LIBC_TARGET_ARCH_IS_X869899#endif // LIBC_MATH_HAS_NO_EXCEPT100return 0;101}102103LIBC_INLINE static void set_errno_if_required([[maybe_unused]] int err) {104#ifndef LIBC_MATH_HAS_NO_ERRNO105if (math_errhandling & MATH_ERRNO)106libc_errno = err;107#endif // LIBC_MATH_HAS_NO_ERRNO108}109110} // namespace fputil111} // namespace LIBC_NAMESPACE_DECL112113#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H114115116