make_float.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* Copyright (C) 2014 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_MAKE_FLOAT_H
  7. #define LIBSIMDPP_SIMDPP_CORE_MAKE_FLOAT_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/detail/insn/make_const.h>
  13. namespace simdpp {
  14. namespace SIMDPP_ARCH_NAMESPACE {
  15. /** Creates a vector from floating-point values known at compile-time.
  16. The result of this function may be assigned or converted to a vector of any
  17. type: standard conversions are used to convert the arguments. All
  18. conversions and other overhead is performed at compile-time thus even if the
  19. minimal optimization level is selected, the function results in a simple
  20. load from memory.
  21. The function is not guaranteed to have adequate performance if the
  22. arguments are not known at compile-time.
  23. If the vector has fewer elements than the number of the parameters this
  24. function accepts then the extra values are discarded.
  25. @par 1 parameter version
  26. @code
  27. | 0 1 2 3 ... n |
  28. r = [ v0 v0 v0 v0 ... v0 ]
  29. @endcode
  30. @par 2 parameters version
  31. @code
  32. | 0 1 2 3 ... n |
  33. r = [ v0 v1 v0 v1 ... v1 ]
  34. @endcode
  35. @par 4 parameters version
  36. @code
  37. | 0 1 2 3 ... n |
  38. r = [ v0 v1 v2 v3 ... v3 ]
  39. @endcode
  40. @par 8 parameters version
  41. @code
  42. | 0 1 .. 7 8 ... n |
  43. r = [ v0 v1 .. v7 v0 ... v7 ]
  44. @endcode
  45. */
  46. SIMDPP_INL expr_vec_make_const<double,1> make_float(double v0)
  47. {
  48. expr_vec_make_const<double,1> a;
  49. a.a[0] = v0;
  50. return a;
  51. }
  52. SIMDPP_INL expr_vec_make_const<double,2> make_float(double v0, double v1)
  53. {
  54. expr_vec_make_const<double,2> a;
  55. a.a[0] = v0; a.a[1] = v1;
  56. return a;
  57. }
  58. SIMDPP_INL expr_vec_make_const<double,4>
  59. make_float(double v0, double v1, double v2, double v3)
  60. {
  61. expr_vec_make_const<double,4> a;
  62. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  63. return a;
  64. }
  65. SIMDPP_INL expr_vec_make_const<double,8>
  66. make_float(double v0, double v1, double v2, double v3,
  67. double v4, double v5, double v6, double v7)
  68. {
  69. expr_vec_make_const<double,8> a;
  70. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  71. a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
  72. return a;
  73. }
  74. SIMDPP_INL expr_vec_make_const<double,16>
  75. make_float(double v0, double v1, double v2, double v3,
  76. double v4, double v5, double v6, double v7,
  77. double v8, double v9, double v10, double v11,
  78. double v12, double v13, double v14, double v15)
  79. {
  80. expr_vec_make_const<double,16> a;
  81. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  82. a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
  83. a.a[8] = v8; a.a[9] = v9; a.a[10] = v10; a.a[11] = v11;
  84. a.a[12] = v12; a.a[13] = v13; a.a[14] = v14; a.a[15] = v15;
  85. return a;
  86. }
  87. template<class V> SIMDPP_INL
  88. V make_float(double v0)
  89. {
  90. static_assert(is_vector<V>::value && !is_mask<V>::value,
  91. "V must be a non-mask vector");
  92. expr_vec_make_const<double,1> a;
  93. a.a[0] = v0;
  94. return detail::insn::i_make_const_any<V>(a);
  95. }
  96. template<class V> SIMDPP_INL
  97. V make_float(double v0, double v1)
  98. {
  99. static_assert(is_vector<V>::value && !is_mask<V>::value,
  100. "V must be a non-mask vector");
  101. expr_vec_make_const<double,2> a;
  102. a.a[0] = v0; a.a[1] = v1;
  103. return detail::insn::i_make_const_any<V>(a);
  104. }
  105. template<class V> SIMDPP_INL
  106. V make_float(double v0, double v1, double v2, double v3)
  107. {
  108. static_assert(is_vector<V>::value && !is_mask<V>::value,
  109. "V must be a non-mask vector");
  110. expr_vec_make_const<double,4> a;
  111. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  112. return detail::insn::i_make_const_any<V>(a);
  113. }
  114. template<class V> SIMDPP_INL
  115. V make_float(double v0, double v1, double v2, double v3,
  116. double v4, double v5, double v6, double v7)
  117. {
  118. static_assert(is_vector<V>::value && !is_mask<V>::value,
  119. "V must be a non-mask vector");
  120. expr_vec_make_const<double,8> a;
  121. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  122. a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
  123. return detail::insn::i_make_const_any<V>(a);
  124. }
  125. template<class V> SIMDPP_INL
  126. V make_float(double v0, double v1, double v2, double v3,
  127. double v4, double v5, double v6, double v7,
  128. double v8, double v9, double v10, double v11,
  129. double v12, double v13, double v14, double v15)
  130. {
  131. static_assert(is_vector<V>::value && !is_mask<V>::value,
  132. "V must be a non-mask vector");
  133. expr_vec_make_const<double,16> a;
  134. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  135. a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
  136. a.a[8] = v8; a.a[9] = v9; a.a[10] = v10; a.a[11] = v11;
  137. a.a[12] = v12; a.a[13] = v13; a.a[14] = v14; a.a[15] = v15;
  138. return detail::insn::i_make_const_any<V>(a);
  139. }
  140. } // namespace SIMDPP_ARCH_NAMESPACE
  141. } // namespace simdpp
  142. #endif