Chris@16: /* Boost interval/detail/x86_rounding_control.hpp file Chris@16: * Chris@16: * Copyright 2000 Jens Maurer Chris@16: * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion Chris@16: * Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or Chris@16: * copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_X86_ROUNDING_CONTROL_HPP Chris@16: #define BOOST_NUMERIC_INTERVAL_DETAIL_X86_ROUNDING_CONTROL_HPP Chris@16: Chris@16: #ifdef __GNUC__ Chris@16: # include Chris@16: #elif defined(__BORLANDC__) Chris@16: # include Chris@16: #elif defined(_MSC_VER) Chris@16: # include Chris@16: #elif defined(__MWERKS__) || defined(__ICC) || defined (__SUNPRO_CC) Chris@16: # define BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM Chris@16: # include Chris@16: #else Chris@16: # error Unsupported C++ compiler. Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: namespace numeric { Chris@16: namespace interval_lib { Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: #ifdef BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM Chris@16: typedef c99_rounding_control x86_rounding_control; Chris@16: #undef BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM Chris@16: #else Chris@16: struct fpu_rounding_modes Chris@16: { Chris@16: unsigned short to_nearest; Chris@16: unsigned short downward; Chris@16: unsigned short upward; Chris@16: unsigned short toward_zero; Chris@16: }; Chris@16: Chris@16: // exceptions masked, extended precision Chris@16: // hardware default is 0x037f (0x1000 only has a meaning on 287) Chris@16: static const fpu_rounding_modes rnd_mode = { 0x137f, 0x177f, 0x1b7f, 0x1f7f }; Chris@16: Chris@16: struct x86_rounding_control: x86_rounding Chris@16: { Chris@16: static void to_nearest() { set_rounding_mode(rnd_mode.to_nearest); } Chris@16: static void downward() { set_rounding_mode(rnd_mode.downward); } Chris@16: static void upward() { set_rounding_mode(rnd_mode.upward); } Chris@16: static void toward_zero() { set_rounding_mode(rnd_mode.toward_zero); } Chris@16: }; Chris@16: #endif // BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM Chris@16: Chris@16: } // namespace detail Chris@16: Chris@16: template<> Chris@16: struct rounding_control: detail::x86_rounding_control Chris@16: { Chris@16: static float force_rounding(const float& r) Chris@16: { volatile float r_ = r; return r_; } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct rounding_control: detail::x86_rounding_control Chris@16: { Chris@16: /*static double force_rounding(double r) Chris@16: { asm volatile ("" : "+m"(r) : ); return r; }*/ Chris@16: static double force_rounding(const double& r) Chris@16: { volatile double r_ = r; return r_; } Chris@16: }; Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: struct x86_rounding_control_long_double; Chris@16: Chris@16: template<> Chris@16: struct x86_rounding_control_long_double: x86_rounding_control Chris@16: { Chris@16: static long double force_rounding(long double const &r) Chris@16: { volatile long double r_ = r; return r_; } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct x86_rounding_control_long_double: x86_rounding_control Chris@16: { Chris@16: static long double const &force_rounding(long double const &r) Chris@16: { return r; } Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: Chris@16: template<> Chris@16: struct rounding_control: Chris@16: detail::x86_rounding_control_long_double< (sizeof(long double) >= 10) > Chris@16: {}; Chris@16: Chris@16: } // namespace interval_lib Chris@16: } // namespace numeric Chris@16: } // namespace boost Chris@16: Chris@16: #undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE Chris@16: Chris@16: #endif /* BOOST_NUMERIC_INTERVAL_DETAIL_X86_ROUNDING_CONTROL_HPP */