1 /* Boost interval/detail/sparc_rounding_control.hpp file
3 * Copyright 2000 Jens Maurer
4 * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
6 * Distributed under the Boost Software License, Version 1.0.
7 * (See accompanying file LICENSE_1_0.txt or
8 * copy at http://www.boost.org/LICENSE_1_0.txt)
10 * The basic code in this file was kindly provided by Jeremy Siek.
13 #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP
14 #define BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP
16 #if !defined(sparc) && !defined(__sparc__)
17 # error This header is only intended for SPARC CPUs.
27 namespace interval_lib {
30 struct sparc_rounding_control
32 typedef unsigned int rounding_mode;
34 static void set_rounding_mode(const rounding_mode& mode)
36 # if defined(__GNUC__)
37 __asm__ __volatile__("ld %0, %%fsr" : : "m"(mode));
38 # elif defined (__SUNPRO_CC)
39 fpsetround(fp_rnd(mode));
41 asm("sethi %hi(mode), %o1");
42 asm("ld [%o1+%lo(mode)], %fsr");
44 # error Unsupported compiler for Sparc rounding control.
48 static void get_rounding_mode(rounding_mode& mode)
50 # if defined(__GNUC__)
51 __asm__ __volatile__("st %%fsr, %0" : "=m"(mode));
52 # elif defined (__SUNPRO_CC)
55 # error KCC on Sun SPARC get_round_mode: please fix me
56 asm("st %fsr, [mode]");
58 # error Unsupported compiler for Sparc rounding control.
62 #if defined(__SUNPRO_CC)
63 static void downward() { set_rounding_mode(FP_RM); }
64 static void upward() { set_rounding_mode(FP_RP); }
65 static void to_nearest() { set_rounding_mode(FP_RN); }
66 static void toward_zero() { set_rounding_mode(FP_RZ); }
68 static void downward() { set_rounding_mode(0xc0000000); }
69 static void upward() { set_rounding_mode(0x80000000); }
70 static void to_nearest() { set_rounding_mode(0x00000000); }
71 static void toward_zero() { set_rounding_mode(0x40000000); }
83 struct rounding_control<float>:
84 detail::sparc_rounding_control
86 static const float& force_rounding(const float& x) { return x; }
87 static float to_int(const float& x) { return rintf(x); }
91 struct rounding_control<double>:
92 detail::sparc_rounding_control
94 static const double& force_rounding(const double& x) { return x; }
95 static double to_int(const double& x) { return rint(x); }
99 struct rounding_control<long double>:
100 detail::sparc_rounding_control
102 static const long double& force_rounding(const long double& x) { return x; }
103 static long double to_int(const long double& x) { return rint(x); }
106 } // namespace interval_lib
107 } // namespace numeric
110 #undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
112 #endif /* BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP */