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 |
|
---|
20 | namespace boost {
|
---|
21 | namespace numeric {
|
---|
22 | namespace interval_lib {
|
---|
23 |
|
---|
24 | namespace detail {
|
---|
25 |
|
---|
26 | // exceptions masked, expected precision (the mask is 0x0300)
|
---|
27 | static const fpu_rounding_modes rnd_mode_f = { 0x107f, 0x147f, 0x187f, 0x1c7f };
|
---|
28 | static const fpu_rounding_modes rnd_mode_d = { 0x127f, 0x167f, 0x1a7f, 0x1e7f };
|
---|
29 | static const fpu_rounding_modes rnd_mode_l = { 0x137f, 0x177f, 0x1b7f, 0x1f7f };
|
---|
30 |
|
---|
31 | } // namespace detail
|
---|
32 |
|
---|
33 | template<class T>
|
---|
34 | struct x86_fast_rounding_control;
|
---|
35 |
|
---|
36 | template<>
|
---|
37 | struct 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 |
|
---|
46 | template<>
|
---|
47 | struct 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 |
|
---|
56 | template<>
|
---|
57 | struct 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
|
---|