Chris@16: /* Boost interval/detail/sparc_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: * The basic code in this file was kindly provided by Jeremy Siek. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP Chris@16: #define BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP Chris@16: Chris@16: #if !defined(sparc) && !defined(__sparc__) Chris@16: # error This header is only intended for SPARC CPUs. Chris@16: #endif Chris@16: Chris@16: #ifdef __SUNPRO_CC Chris@16: # include Chris@16: #endif Chris@16: Chris@16: Chris@16: namespace boost { Chris@16: namespace numeric { Chris@16: namespace interval_lib { Chris@16: namespace detail { Chris@16: Chris@16: struct sparc_rounding_control Chris@16: { Chris@16: typedef unsigned int rounding_mode; Chris@16: Chris@16: static void set_rounding_mode(const rounding_mode& mode) Chris@16: { Chris@16: # if defined(__GNUC__) Chris@16: __asm__ __volatile__("ld %0, %%fsr" : : "m"(mode)); Chris@16: # elif defined (__SUNPRO_CC) Chris@16: fpsetround(fp_rnd(mode)); Chris@16: # elif defined(__KCC) Chris@16: asm("sethi %hi(mode), %o1"); Chris@16: asm("ld [%o1+%lo(mode)], %fsr"); Chris@16: # else Chris@16: # error Unsupported compiler for Sparc rounding control. Chris@16: # endif Chris@16: } Chris@16: Chris@16: static void get_rounding_mode(rounding_mode& mode) Chris@16: { Chris@16: # if defined(__GNUC__) Chris@16: __asm__ __volatile__("st %%fsr, %0" : "=m"(mode)); Chris@16: # elif defined (__SUNPRO_CC) Chris@16: mode = fpgetround(); Chris@16: # elif defined(__KCC) Chris@16: # error KCC on Sun SPARC get_round_mode: please fix me Chris@16: asm("st %fsr, [mode]"); Chris@16: # else Chris@16: # error Unsupported compiler for Sparc rounding control. Chris@16: # endif Chris@16: } Chris@16: Chris@16: #if defined(__SUNPRO_CC) Chris@16: static void downward() { set_rounding_mode(FP_RM); } Chris@16: static void upward() { set_rounding_mode(FP_RP); } Chris@16: static void to_nearest() { set_rounding_mode(FP_RN); } Chris@16: static void toward_zero() { set_rounding_mode(FP_RZ); } Chris@16: #else Chris@16: static void downward() { set_rounding_mode(0xc0000000); } Chris@16: static void upward() { set_rounding_mode(0x80000000); } Chris@16: static void to_nearest() { set_rounding_mode(0x00000000); } Chris@16: static void toward_zero() { set_rounding_mode(0x40000000); } Chris@16: #endif Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: Chris@16: extern "C" { Chris@16: float rintf(float); Chris@16: double rint(double); Chris@16: } Chris@16: Chris@16: template<> Chris@16: struct rounding_control: Chris@16: detail::sparc_rounding_control Chris@16: { Chris@16: static const float& force_rounding(const float& x) { return x; } Chris@16: static float to_int(const float& x) { return rintf(x); } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct rounding_control: Chris@16: detail::sparc_rounding_control Chris@16: { Chris@16: static const double& force_rounding(const double& x) { return x; } Chris@16: static double to_int(const double& x) { return rint(x); } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct rounding_control: Chris@16: detail::sparc_rounding_control Chris@16: { Chris@16: static const long double& force_rounding(const long double& x) { return x; } Chris@16: static long double to_int(const long double& x) { return rint(x); } 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_SPARC_ROUNDING_CONTROL_HPP */