Changeset View
Changeset View
Standalone View
Standalone View
flang/unittests/Evaluate/fp-testing.cpp
#include "fp-testing.h" | #include "fp-testing.h" | ||||
Lint: Lint: clang-format not found in user's PATH; not linting file. | |||||
#include "llvm/Support/Errno.h" | #include "llvm/Support/Errno.h" | ||||
#include <cstdio> | #include <cstdio> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <cstring> | #include <cstring> | ||||
#if __x86_64__ && defined(_MSC_VER) | |||||
#include <xmmintrin.h> | |||||
#endif | |||||
using Fortran::common::RoundingMode; | using Fortran::common::RoundingMode; | ||||
using Fortran::evaluate::RealFlag; | using Fortran::evaluate::RealFlag; | ||||
ScopedHostFloatingPointEnvironment::ScopedHostFloatingPointEnvironment( | ScopedHostFloatingPointEnvironment::ScopedHostFloatingPointEnvironment( | ||||
#if __x86_64__ | #if __x86_64__ | ||||
bool treatSubnormalOperandsAsZero, bool flushSubnormalResultsToZero | bool treatSubnormalOperandsAsZero, bool flushSubnormalResultsToZero | ||||
#else | #else | ||||
bool, bool | bool, bool | ||||
#endif | #endif | ||||
) { | ) { | ||||
errno = 0; | errno = 0; | ||||
if (feholdexcept(&originalFenv_) != 0) { | if (feholdexcept(&originalFenv_) != 0) { | ||||
std::fprintf(stderr, "feholdexcept() failed: %s\n", | std::fprintf(stderr, "feholdexcept() failed: %s\n", | ||||
llvm::sys::StrError(errno).c_str()); | llvm::sys::StrError(errno).c_str()); | ||||
std::abort(); | std::abort(); | ||||
} | } | ||||
if (fegetenv(¤tFenv_) != 0) { | if (fegetenv(¤tFenv_) != 0) { | ||||
std::fprintf( | std::fprintf( | ||||
stderr, "fegetenv() failed: %s\n", llvm::sys::StrError(errno).c_str()); | stderr, "fegetenv() failed: %s\n", llvm::sys::StrError(errno).c_str()); | ||||
std::abort(); | std::abort(); | ||||
} | } | ||||
#if __x86_64__ | #if __x86_64__ | ||||
#ifdef _MSC_VER | |||||
unsigned int new_mxcsr{_mm_getcsr()}; | |||||
if (treatSubnormalOperandsAsZero) { | |||||
new_mxcsr |= 0x0040; | |||||
} else { | |||||
new_mxcsr &= ~0x0040; | |||||
} | |||||
if (flushSubnormalResultsToZero) { | |||||
new_mxcsr |= 0x8000; | |||||
} else { | |||||
new_mxcsr &= ~0x8000; | |||||
} | |||||
#else | |||||
if (treatSubnormalOperandsAsZero) { | if (treatSubnormalOperandsAsZero) { | ||||
currentFenv_.__mxcsr |= 0x0040; | currentFenv_.__mxcsr |= 0x0040; | ||||
} else { | } else { | ||||
currentFenv_.__mxcsr &= ~0x0040; | currentFenv_.__mxcsr &= ~0x0040; | ||||
} | } | ||||
if (flushSubnormalResultsToZero) { | if (flushSubnormalResultsToZero) { | ||||
currentFenv_.__mxcsr |= 0x8000; | currentFenv_.__mxcsr |= 0x8000; | ||||
} else { | } else { | ||||
currentFenv_.__mxcsr &= ~0x8000; | currentFenv_.__mxcsr &= ~0x8000; | ||||
} | } | ||||
#endif | |||||
#else | #else | ||||
// TODO others | // TODO others | ||||
#endif | #endif | ||||
errno = 0; | errno = 0; | ||||
if (fesetenv(¤tFenv_) != 0) { | if (fesetenv(¤tFenv_) != 0) { | ||||
std::fprintf( | std::fprintf( | ||||
stderr, "fesetenv() failed: %s\n", llvm::sys::StrError(errno).c_str()); | stderr, "fesetenv() failed: %s\n", llvm::sys::StrError(errno).c_str()); | ||||
std::abort(); | std::abort(); | ||||
} | } | ||||
#if __x86_64__ && defined(_MSC_VER) | |||||
_mm_setcsr(new_mxcsr); | |||||
#endif | |||||
} | } | ||||
ScopedHostFloatingPointEnvironment::~ScopedHostFloatingPointEnvironment() { | ScopedHostFloatingPointEnvironment::~ScopedHostFloatingPointEnvironment() { | ||||
errno = 0; | errno = 0; | ||||
if (fesetenv(&originalFenv_) != 0) { | if (fesetenv(&originalFenv_) != 0) { | ||||
std::fprintf( | std::fprintf( | ||||
stderr, "fesetenv() failed: %s\n", llvm::sys::StrError(errno).c_str()); | stderr, "fesetenv() failed: %s\n", llvm::sys::StrError(errno).c_str()); | ||||
std::abort(); | std::abort(); | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |
clang-format not found in user's PATH; not linting file.