Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_UnitTestMainUtils.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ****************************************************************************
3 // Tempus: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef TEMPUS_UNIT_TEST_MAIN_UTILS_HPP
10 #define TEMPUS_UNIT_TEST_MAIN_UTILS_HPP
11 
12 #if defined(__linux__) && defined(__GNUC__) && !defined(__INTEL_COMPILER)
13 #include <fenv.h>
14 #elif defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__)
15 #include <xmmintrin.h>
16 #endif
17 
18 namespace Tempus_Test {
19 
27 void enableFPE(bool enableFPE)
28 {
29 #if defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__)
30  static int eMask = _MM_GET_EXCEPTION_MASK();
31 #endif
32 
33  if (enableFPE) {
34 #if defined(__linux__) && defined(__GNUC__) && !defined(__INTEL_COMPILER)
35  feenableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID);
36 #elif defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__)
37  eMask = _MM_GET_EXCEPTION_MASK(); // Save current eMask so we can disable.
38  _MM_SET_EXCEPTION_MASK(eMask & ~_MM_MASK_DIV_ZERO & ~_MM_MASK_OVERFLOW &
39  ~_MM_MASK_INVALID);
40 #endif
41  }
42  else {
43 #if defined(__linux__) && defined(__GNUC__) && !defined(__INTEL_COMPILER)
44  fedisableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID);
45 #elif defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__)
46  _MM_SET_EXCEPTION_MASK(eMask);
47 #endif
48  }
49 }
50 
51 } // namespace Tempus_Test
52 
53 #endif // TEMPUS_UNIT_TEST_MAIN_UTILS_HPP
void enableFPE(bool enableFPE)
Enable Floating Point Exceptions.