New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
x86_fast_rounding_control.hpp in vendors/XIOS/current/extern/boost/include/boost/numeric/interval/ext – NEMO

source: vendors/XIOS/current/extern/boost/include/boost/numeric/interval/ext/x86_fast_rounding_control.hpp @ 3408

Last change on this file since 3408 was 3408, checked in by rblod, 12 years ago

importing initial XIOS vendor drop

  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1/* Boost interval/detail/x86gcc_rounding_control.hpp file
2 *
3 * This header provides a rounding control policy
4 * that avoids flushing results to memory. In
5 * order for this optimization to be reliable, it
6 * should be used only when no underflow or
7 * overflow would happen without it. Indeed, only
8 * values in range are correctly rounded.
9 *
10 * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
11 *
12 * Distributed under the Boost Software License, Version 1.0.
13 * (See accompanying file LICENSE_1_0.txt or
14 * copy at http://www.boost.org/LICENSE_1_0.txt)
15 */
16
17#ifndef BOOST_NUMERIC_INTERVAL_EXT_X86_FAST_ROUNDING_CONTROL_HPP
18#define BOOST_NUMERIC_INTERVAL_EXT_X86_FAST_ROUNDING_CONTROL_HPP
19
20namespace boost {
21namespace numeric {
22namespace interval_lib {
23
24namespace detail {
25
26// exceptions masked, expected precision (the mask is 0x0300)
27static const fpu_rounding_modes rnd_mode_f = { 0x107f, 0x147f, 0x187f, 0x1c7f };
28static const fpu_rounding_modes rnd_mode_d = { 0x127f, 0x167f, 0x1a7f, 0x1e7f };
29static const fpu_rounding_modes rnd_mode_l = { 0x137f, 0x177f, 0x1b7f, 0x1f7f };
30
31} // namespace detail
32
33template<class T>
34struct x86_fast_rounding_control;
35
36template<>
37struct x86_fast_rounding_control<float>: detail::x86_rounding
38{
39  static void to_nearest()  { set_rounding_mode(detail::rnd_mode_f.to_nearest);  }
40  static void downward()    { set_rounding_mode(detail::rnd_mode_f.downward);    }
41  static void upward()      { set_rounding_mode(detail::rnd_mode_f.upward);      }
42  static void toward_zero() { set_rounding_mode(detail::rnd_mode_f.toward_zero); }
43  static const float& force_rounding(const float& r) { return r; }
44};
45
46template<>
47struct x86_fast_rounding_control<double>: detail::x86_rounding
48{
49  static void to_nearest()  { set_rounding_mode(detail::rnd_mode_d.to_nearest);  }
50  static void downward()    { set_rounding_mode(detail::rnd_mode_d.downward);    }
51  static void upward()      { set_rounding_mode(detail::rnd_mode_d.upward);      }
52  static void toward_zero() { set_rounding_mode(detail::rnd_mode_d.toward_zero); }
53  static const double& force_rounding(const double& r) { return r; }
54};
55
56template<>
57struct x86_fast_rounding_control<long double>: detail::x86_rounding
58{
59  static void to_nearest()  { set_rounding_mode(detail::rnd_mode_l.to_nearest);  }
60  static void downward()    { set_rounding_mode(detail::rnd_mode_l.downward);    }
61  static void upward()      { set_rounding_mode(detail::rnd_mode_l.upward);      }
62  static void toward_zero() { set_rounding_mode(detail::rnd_mode_l.toward_zero); }
63  static const long double& force_rounding(const long double& r) { return r; }
64};
65
66} // namespace interval_lib
67} // namespace numeric
68} // namespace boost
69
70#endif // BOOST_NUMERIC_INTERVAL_EXT_X86_FAST_ROUNDING_CONTROL_HPP
Note: See TracBrowser for help on using the repository browser.