x86gcc_rounding_control.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP
  11. #define BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP
  12. #ifndef __GNUC__
  13. # error This header only works with GNU CC.
  14. #endif
  15. #if !defined(__i386__) && !defined(__x86_64__)
  16. # error This header only works on x86 CPUs.
  17. #endif
  18. namespace boost {
  19. namespace numeric {
  20. namespace interval_lib {
  21. namespace detail {
  22. struct x86_rounding
  23. {
  24. typedef unsigned short rounding_mode;
  25. static void set_rounding_mode(const rounding_mode& mode)
  26. { __asm__ __volatile__ ("fldcw %0" : : "m"(mode)); }
  27. static void get_rounding_mode(rounding_mode& mode)
  28. { __asm__ __volatile__ ("fnstcw %0" : "=m"(mode)); }
  29. template<class T>
  30. static T to_int(T r)
  31. {
  32. T r_;
  33. __asm__ ("frndint" : "=&t"(r_) : "0"(r));
  34. return r_;
  35. }
  36. };
  37. } // namespace detail
  38. } // namespace interval_lib
  39. } // namespace numeric
  40. } // namespace boost
  41. #endif /* BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP */