1 /* Boost interval/detail/x86gcc_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 11 #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP 12 #define BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP 13 14 #if !defined(__GNUC__) && !(defined(__BORLANDC__) && defined(__clang__)) 15 # error This header only works with GNU CC. 16 #endif 17 18 #if !defined(__i386__) && !defined(__x86_64__) 19 # error This header only works on x86 CPUs. 20 #endif 21 22 namespace boost { 23 namespace numeric { 24 namespace interval_lib { 25 namespace detail { 26 27 struct x86_rounding 28 { 29 typedef unsigned short rounding_mode; 30 set_rounding_modeboost::numeric::interval_lib::detail::x86_rounding31 static void set_rounding_mode(const rounding_mode& mode) 32 { __asm__ __volatile__ ("fldcw %0" : : "m"(mode)); } 33 get_rounding_modeboost::numeric::interval_lib::detail::x86_rounding34 static void get_rounding_mode(rounding_mode& mode) 35 { __asm__ __volatile__ ("fnstcw %0" : "=m"(mode)); } 36 37 template<class T> to_intboost::numeric::interval_lib::detail::x86_rounding38 static T to_int(T r) 39 { 40 T r_; 41 __asm__ ("frndint" : "=&t"(r_) : "0"(r)); 42 return r_; 43 } 44 }; 45 46 } // namespace detail 47 } // namespace interval_lib 48 } // namespace numeric 49 } // namespace boost 50 51 #endif /* BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP */ 52