to_float64.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Copyright (C) 2013-2017 Povilas Kanapickas <[email protected]>
  2. Distributed under the Boost Software License, Version 1.0.
  3. (See accompanying file LICENSE_1_0.txt or copy at
  4. http://www.boost.org/LICENSE_1_0.txt)
  5. */
  6. #ifndef LIBSIMDPP_SIMDPP_CORE_TO_FLOAT64_H
  7. #define LIBSIMDPP_SIMDPP_CORE_TO_FLOAT64_H
  8. #ifndef LIBSIMDPP_SIMD_H
  9. #error "This file must be included through simd.h"
  10. #endif
  11. #include <simdpp/types.h>
  12. #include <simdpp/capabilities.h>
  13. #include <simdpp/detail/insn/conv_any_to_float64.h>
  14. #include <simdpp/detail/not_implemented.h>
  15. namespace simdpp {
  16. namespace SIMDPP_ARCH_NAMESPACE {
  17. /** Converts elements within a vector to 64-bit floating-point values.
  18. SSE specific:
  19. If only inexact conversion can be performed, the current rounding mode is
  20. used.
  21. NEON specific:
  22. If only inexact conversion can be performed, round to nearest mode is used.
  23. @code
  24. r0 = (double) a0
  25. ...
  26. rN = (double) aN
  27. @endcode
  28. */
  29. template<unsigned N, class E> SIMDPP_INL
  30. float64<N,expr_empty> to_float64(const int8<N,E>& a)
  31. {
  32. return detail::insn::i_to_float64(a.eval());
  33. }
  34. template<unsigned N, class E> SIMDPP_INL
  35. float64<N,expr_empty> to_float64(const uint8<N,E>& a)
  36. {
  37. return detail::insn::i_to_float64(a.eval());
  38. }
  39. template<unsigned N, class E> SIMDPP_INL
  40. float64<N,expr_empty> to_float64(const int16<N,E>& a)
  41. {
  42. return detail::insn::i_to_float64(a.eval());
  43. }
  44. template<unsigned N, class E> SIMDPP_INL
  45. float64<N,expr_empty> to_float64(const uint16<N,E>& a)
  46. {
  47. return detail::insn::i_to_float64(a.eval());
  48. }
  49. template<unsigned N, class E> SIMDPP_INL
  50. float64<N,expr_empty> to_float64(const int32<N,E>& a)
  51. {
  52. return detail::insn::i_to_float64(a.eval());
  53. }
  54. template<unsigned N, class E> SIMDPP_INL
  55. float64<N,expr_empty> to_float64(const uint32<N,E>& a)
  56. {
  57. return detail::insn::i_to_float64(a.eval());
  58. }
  59. template<unsigned N, class E> SIMDPP_INL
  60. float64<N,expr_empty> to_float64(const int64<N,E>& a)
  61. {
  62. #if SIMDPP_HAS_INT64_TO_FLOAT64_CONVERSION
  63. return detail::insn::i_to_float64(a.eval());
  64. #else
  65. return SIMDPP_NOT_IMPLEMENTED_TEMPLATE1(E, a);
  66. #endif
  67. }
  68. template<unsigned N, class E> SIMDPP_INL
  69. float64<N,expr_empty> to_float64(const uint64<N,E>& a)
  70. {
  71. #if SIMDPP_HAS_UINT64_TO_FLOAT64_CONVERSION
  72. return detail::insn::i_to_float64(a.eval());
  73. #else
  74. return SIMDPP_NOT_IMPLEMENTED_TEMPLATE1(E, a);
  75. #endif
  76. }
  77. template<unsigned N, class E> SIMDPP_INL
  78. float64<N,expr_empty> to_float64(const float32<N,E>& a)
  79. {
  80. return detail::insn::i_to_float64(a.eval());
  81. }
  82. template<unsigned N, class E> SIMDPP_INL
  83. float64<N,expr_empty> to_float64(const float64<N,E>& a)
  84. {
  85. return a;
  86. }
  87. } // namespace SIMDPP_ARCH_NAMESPACE
  88. } // namespace simdpp
  89. #endif