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 
19 namespace Tempus_Test {
20 
21 
29 void enableFPE(bool enableFPE)
30 {
31 #if defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__)
32  static int eMask = _MM_GET_EXCEPTION_MASK();
33 #endif
34 
35  if (enableFPE) {
36 #if defined(__linux__) && defined(__GNUC__) && !defined(__INTEL_COMPILER)
37  feenableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID);
38 #elif defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__)
39  eMask = _MM_GET_EXCEPTION_MASK(); // Save current eMask so we can disable.
40  _MM_SET_EXCEPTION_MASK(eMask & ~_MM_MASK_DIV_ZERO
41  & ~_MM_MASK_OVERFLOW
42  & ~_MM_MASK_INVALID);
43 #endif
44  } else {
45 #if defined(__linux__) && defined(__GNUC__) && !defined(__INTEL_COMPILER)
46  fedisableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID);
47 #elif defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__)
48  _MM_SET_EXCEPTION_MASK(eMask);
49 #endif
50  }
51 }
52 
53 } // namespace Tempus_Test
54 
55 #endif // TEMPUS_UNIT_TEST_MAIN_UTILS_HPP
56 
void enableFPE(bool enableFPE)
Enable Floating Point Exceptions.