llvm.org GIT mirror llvm / 3f2f21e
Attempt to support platforms which don't have fenv.h. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114196 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 8 years ago
5 changed file(s) with 64 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
12611261 AC_CHECK_HEADERS([sys/mman.h sys/param.h sys/resource.h sys/time.h])
12621262 AC_CHECK_HEADERS([sys/types.h sys/ioctl.h malloc/malloc.h mach/mach.h])
12631263 AC_CHECK_HEADERS([valgrind/valgrind.h])
1264 AC_CHECK_HEADERS([fenv.h])
12641265 if test "$ENABLE_THREADS" -eq 1 ; then
12651266 AC_CHECK_HEADERS(pthread.h,
12661267 AC_SUBST(HAVE_PTHREAD, 1),
459459
460460 /* Define to 1 if you have the header file. */
461461 #cmakedefine HAVE_VALGRIND_VALGRIND_H ${HAVE_VALGRIND_VALGRIND_H}
462
463 /* Define to 1 if you have the header file. */
464 #cmakedefine HAVE_FENV_H ${HAVE_FENV_H}
462465
463466 /* Define to 1 if you have the header file. */
464467 #cmakedefine HAVE_WINDOWS_H ${HAVE_WINDOWS_H}
454454 /* Define to 1 if you have the header file. */
455455 #undef HAVE_VALGRIND_VALGRIND_H
456456
457 /* Define to 1 if you have the header file. */
458 #undef HAVE_FENV_H
459
457460 /* Define to 1 if you have the header file. */
458461 #undef HAVE_WINDOWS_H
459462
0 //===- llvm/System/FEnv.h - Host floating-point exceptions ------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides an operating system independent interface to
10 // floating-point exception interfaces.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SYSTEM_FENV_H
15 #define LLVM_SYSTEM_FENV_H
16
17 #include "llvm/Config/config.h"
18 #include
19 #ifdef HAVE_FENV_H
20 #include
21 #endif
22
23 namespace llvm {
24 namespace sys {
25
26 /// llvm_fenv_clearexcept - Clear the floating-point exception state.
27 static inline void llvm_fenv_clearexcept() {
28 #ifdef HAVE_FENV_H
29 feclearexcept(FE_ALL_EXCEPT);
30 #endif
31 errno = 0;
32 }
33
34 /// llvm_fenv_testexcept - Test if a floating-point exception was raised.
35 static inline bool llvm_fenv_testexcept() {
36 int errno_val = errno;
37 if (errno_val == ERANGE || errno_val == EDOM)
38 return true;
39 #ifdef HAVE_FENV_H
40 if (fetestexcept(FE_ALL_EXCEPT))
41 return true;
42 #endif
43 return false;
44 }
45
46 } // End sys namespace
47 } // End llvm namespace
48
49 #endif
2929 #include "llvm/Support/ErrorHandling.h"
3030 #include "llvm/Support/GetElementPtrTypeIterator.h"
3131 #include "llvm/Support/MathExtras.h"
32 #include "llvm/System/FEnv.h"
3233 #include
3334 #include
3435 #include
10391040
10401041 static Constant *ConstantFoldFP(double (*NativeFP)(double), double V,
10411042 const Type *Ty) {
1042 feclearexcept(FE_ALL_EXCEPT);
1043 errno = 0;
1043 sys::llvm_fenv_clearexcept();
10441044 V = NativeFP(V);
1045 if (errno != 0 ||
1046 fetestexcept(FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)) {
1047 feclearexcept(FE_ALL_EXCEPT);
1048 errno = 0;
1045 if (sys::llvm_fenv_testexcept()) {
1046 sys::llvm_fenv_clearexcept();
10491047 return 0;
10501048 }
10511049
10591057
10601058 static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double),
10611059 double V, double W, const Type *Ty) {
1062 feclearexcept(FE_ALL_EXCEPT);
1063 errno = 0;
1060 sys::llvm_fenv_clearexcept();
10641061 V = NativeFP(V, W);
1065 if (errno != 0 ||
1066 fetestexcept(FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)) {
1067 feclearexcept(FE_ALL_EXCEPT);
1068 errno = 0;
1062 if (sys::llvm_fenv_testexcept()) {
1063 sys::llvm_fenv_clearexcept();
10691064 return 0;
10701065 }
10711066