annotate DEPENDENCIES/generic/include/boost/numeric/interval/detail/ppc_rounding_control.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /* Boost interval/detail/ppc_rounding_control.hpp file
Chris@16 2 *
Chris@16 3 * Copyright 2000 Jens Maurer
Chris@16 4 * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
Chris@16 5 * Copyright 2005 Guillaume Melquiond
Chris@16 6 *
Chris@16 7 * Distributed under the Boost Software License, Version 1.0.
Chris@16 8 * (See accompanying file LICENSE_1_0.txt or
Chris@16 9 * copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 10 */
Chris@16 11
Chris@16 12 #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_PPC_ROUNDING_CONTROL_HPP
Chris@16 13 #define BOOST_NUMERIC_INTERVAL_DETAIL_PPC_ROUNDING_CONTROL_HPP
Chris@16 14
Chris@16 15 #if !defined(powerpc) && !defined(__powerpc__) && !defined(__ppc__)
Chris@16 16 #error This header only works on PPC CPUs.
Chris@16 17 #endif
Chris@16 18
Chris@16 19 #if defined(__GNUC__ ) || (__IBMCPP__ >= 700)
Chris@16 20
Chris@16 21 namespace boost {
Chris@16 22 namespace numeric {
Chris@16 23 namespace interval_lib {
Chris@16 24 namespace detail {
Chris@16 25
Chris@16 26 typedef union {
Chris@16 27 ::boost::long_long_type imode;
Chris@16 28 double dmode;
Chris@16 29 } rounding_mode_struct;
Chris@16 30
Chris@16 31 static const rounding_mode_struct mode_upward = { 0xFFF8000000000002LL };
Chris@16 32 static const rounding_mode_struct mode_downward = { 0xFFF8000000000003LL };
Chris@16 33 static const rounding_mode_struct mode_to_nearest = { 0xFFF8000000000000LL };
Chris@16 34 static const rounding_mode_struct mode_toward_zero = { 0xFFF8000000000001LL };
Chris@16 35
Chris@16 36 struct ppc_rounding_control
Chris@16 37 {
Chris@16 38 typedef double rounding_mode;
Chris@16 39
Chris@16 40 static void set_rounding_mode(const rounding_mode mode)
Chris@16 41 { __asm__ __volatile__ ("mtfsf 255,%0" : : "f"(mode)); }
Chris@16 42
Chris@16 43 static void get_rounding_mode(rounding_mode& mode)
Chris@16 44 { __asm__ __volatile__ ("mffs %0" : "=f"(mode)); }
Chris@16 45
Chris@16 46 static void downward() { set_rounding_mode(mode_downward.dmode); }
Chris@16 47 static void upward() { set_rounding_mode(mode_upward.dmode); }
Chris@16 48 static void to_nearest() { set_rounding_mode(mode_to_nearest.dmode); }
Chris@16 49 static void toward_zero() { set_rounding_mode(mode_toward_zero.dmode); }
Chris@16 50 };
Chris@16 51
Chris@16 52 } // namespace detail
Chris@16 53
Chris@16 54 // Do not declare the following C99 symbols if <math.h> provides them.
Chris@16 55 // Otherwise, conflicts may occur, due to differences between prototypes.
Chris@16 56 #if !defined(_ISOC99_SOURCE) && !defined(__USE_ISOC99)
Chris@16 57 extern "C" {
Chris@16 58 float rintf(float);
Chris@16 59 double rint(double);
Chris@16 60 }
Chris@16 61 #endif
Chris@16 62
Chris@16 63 template<>
Chris@16 64 struct rounding_control<float>:
Chris@16 65 detail::ppc_rounding_control
Chris@16 66 {
Chris@16 67 static float force_rounding(const float r)
Chris@16 68 {
Chris@16 69 float tmp;
Chris@16 70 __asm__ __volatile__ ("frsp %0, %1" : "=f" (tmp) : "f" (r));
Chris@16 71 return tmp;
Chris@16 72 }
Chris@16 73 static float to_int(const float& x) { return rintf(x); }
Chris@16 74 };
Chris@16 75
Chris@16 76 template<>
Chris@16 77 struct rounding_control<double>:
Chris@16 78 detail::ppc_rounding_control
Chris@16 79 {
Chris@16 80 static const double & force_rounding(const double& r) { return r; }
Chris@16 81 static double to_int(const double& r) { return rint(r); }
Chris@16 82 };
Chris@16 83
Chris@16 84 template<>
Chris@16 85 struct rounding_control<long double>:
Chris@16 86 detail::ppc_rounding_control
Chris@16 87 {
Chris@16 88 static const long double & force_rounding(const long double& r) { return r; }
Chris@16 89 static long double to_int(const long double& r) { return rint(r); }
Chris@16 90 };
Chris@16 91
Chris@16 92 } // namespace interval_lib
Chris@16 93 } // namespace numeric
Chris@16 94 } // namespace boost
Chris@16 95
Chris@16 96 #undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE
Chris@16 97 #endif
Chris@16 98
Chris@16 99 #endif /* BOOST_NUMERIC_INTERVAL_DETAIL_PPC_ROUNDING_CONTROL_HPP */