source: vendor/nemo/current/NEMOGCM/EXTERNAL/XIOS/extern/boost/include/boost/numeric/interval/detail/sparc_rounding_control.hpp @ 44

Last change on this file since 44 was 44, checked in by cholod, 12 years ago

Load NEMO_TMP into vendor/nemo/current.

File size: 3.0 KB
Line 
1/* Boost interval/detail/sparc_rounding_control.hpp file
2 *
3 * Copyright 2000 Jens Maurer
4 * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
5 *
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)
9 *
10 * The basic code in this file was kindly provided by Jeremy Siek.
11 */
12
13#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP
14#define BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP
15
16#if !defined(sparc) && !defined(__sparc__)
17#  error This header is only intended for SPARC CPUs.
18#endif
19
20#ifdef __SUNPRO_CC
21#  include <ieeefp.h>
22#endif
23
24
25namespace boost {
26namespace numeric {
27namespace interval_lib {
28namespace detail {
29
30struct sparc_rounding_control
31{
32  typedef unsigned int rounding_mode;
33
34  static void set_rounding_mode(const rounding_mode& mode)
35  {
36#   if defined(__GNUC__)
37    __asm__ __volatile__("ld %0, %%fsr" : : "m"(mode));
38#   elif defined (__SUNPRO_CC)
39    fpsetround(fp_rnd(mode));
40#   elif defined(__KCC)
41    asm("sethi %hi(mode), %o1");
42    asm("ld [%o1+%lo(mode)], %fsr");
43#   else
44#     error Unsupported compiler for Sparc rounding control.
45#   endif
46  }
47
48  static void get_rounding_mode(rounding_mode& mode)
49  {
50#   if defined(__GNUC__)
51    __asm__ __volatile__("st %%fsr, %0" : "=m"(mode));
52#   elif defined (__SUNPRO_CC)
53    mode = fpgetround();
54#   elif defined(__KCC)
55#     error KCC on Sun SPARC get_round_mode: please fix me
56    asm("st %fsr, [mode]");
57#   else
58#     error Unsupported compiler for Sparc rounding control.
59#   endif
60  }
61
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); }
67#else
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); }
72#endif
73};
74
75} // namespace detail
76
77extern "C" {
78  float rintf(float);
79  double rint(double);
80}
81
82template<>
83struct rounding_control<float>:
84  detail::sparc_rounding_control
85{
86  static const float& force_rounding(const float& x) { return x; }
87  static float to_int(const float& x) { return rintf(x); }
88};
89
90template<>
91struct rounding_control<double>:
92  detail::sparc_rounding_control
93{
94  static const double& force_rounding(const double& x) { return x; }
95  static double to_int(const double& x) { return rint(x); }
96};
97
98template<>
99struct rounding_control<long double>:
100  detail::sparc_rounding_control
101{
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); }
104};
105
106} // namespace interval_lib
107} // namespace numeric
108} // namespace boost
109
110#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
111
112#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP */
Note: See TracBrowser for help on using the repository browser.