make_uint.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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_UINT_H
  7. #define LIBSIMDPP_SIMDPP_CORE_MAKE_UINT_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 unsigned integer 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. Note that per C++ rules negative values are sign-extended to fill entire
  26. element before being converted to unsigned type thus e.g. it's safe to use
  27. -1 to fill element with ones.
  28. @par 1 parameter version
  29. @code
  30. | 0 1 2 3 ... n |
  31. r = [ v0 v0 v0 v0 ... v0 ]
  32. @endcode
  33. @par 2 parameters version
  34. @code
  35. | 0 1 2 3 ... n |
  36. r = [ v0 v1 v0 v1 ... v1 ]
  37. @endcode
  38. @par 4 parameters version
  39. @code
  40. | 0 1 2 3 ... n |
  41. r = [ v0 v1 v2 v3 ... v3 ]
  42. @endcode
  43. @par 8 parameters version
  44. @code
  45. | 0 1 .. 7 8 ... n |
  46. r = [ v0 v1 .. v7 v0 ... v7 ]
  47. @endcode
  48. */
  49. // FIXME: return empty expr
  50. SIMDPP_INL expr_vec_make_const<uint64_t,1> make_uint(uint64_t v0)
  51. {
  52. expr_vec_make_const<uint64_t,1> a;
  53. a.a[0] = v0;
  54. return a;
  55. }
  56. static SIMDPP_INL
  57. expr_vec_make_const<uint64_t,2> make_uint(uint64_t v0, uint64_t v1)
  58. {
  59. expr_vec_make_const<uint64_t,2> a;
  60. a.a[0] = v0; a.a[1] = v1;
  61. return a;
  62. }
  63. static SIMDPP_INL
  64. expr_vec_make_const<uint64_t,4>
  65. make_uint(uint64_t v0, uint64_t v1, uint64_t v2, uint64_t v3)
  66. {
  67. expr_vec_make_const<uint64_t,4> a;
  68. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  69. return a;
  70. }
  71. static SIMDPP_INL
  72. expr_vec_make_const<uint64_t,8>
  73. make_uint(uint64_t v0, uint64_t v1, uint64_t v2, uint64_t v3,
  74. uint64_t v4, uint64_t v5, uint64_t v6, uint64_t v7)
  75. {
  76. expr_vec_make_const<uint64_t,8> a;
  77. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  78. a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
  79. return a;
  80. }
  81. static SIMDPP_INL
  82. expr_vec_make_const<uint64_t,16>
  83. make_uint(uint64_t v0, uint64_t v1, uint64_t v2, uint64_t v3,
  84. uint64_t v4, uint64_t v5, uint64_t v6, uint64_t v7,
  85. uint64_t v8, uint64_t v9, uint64_t v10, uint64_t v11,
  86. uint64_t v12, uint64_t v13, uint64_t v14, uint64_t v15)
  87. {
  88. expr_vec_make_const<uint64_t,16> a;
  89. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  90. a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
  91. a.a[8] = v8; a.a[9] = v9; a.a[10] = v10; a.a[11] = v11;
  92. a.a[12] = v12; a.a[13] = v13; a.a[14] = v14; a.a[15] = v15;
  93. return a;
  94. }
  95. template<class V> SIMDPP_INL
  96. V make_uint(uint64_t v0)
  97. {
  98. static_assert(is_vector<V>::value && !is_mask<V>::value,
  99. "V must be a non-mask vector");
  100. expr_vec_make_const<uint64_t,1> a;
  101. a.a[0] = v0;
  102. return detail::insn::i_make_const_any<V>(a);
  103. }
  104. template<class V> SIMDPP_INL
  105. V make_uint(uint64_t v0, uint64_t v1)
  106. {
  107. static_assert(is_vector<V>::value && !is_mask<V>::value,
  108. "V must be a non-mask vector");
  109. expr_vec_make_const<uint64_t,2> a;
  110. a.a[0] = v0; a.a[1] = v1;
  111. return detail::insn::i_make_const_any<V>(a);
  112. }
  113. template<class V> SIMDPP_INL
  114. V make_uint(uint64_t v0, uint64_t v1, uint64_t v2, uint64_t v3)
  115. {
  116. static_assert(is_vector<V>::value && !is_mask<V>::value,
  117. "V must be a non-mask vector");
  118. expr_vec_make_const<uint64_t,4> a;
  119. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  120. return detail::insn::i_make_const_any<V>(a);
  121. }
  122. template<class V> SIMDPP_INL
  123. V make_uint(uint64_t v0, uint64_t v1, uint64_t v2, uint64_t v3,
  124. uint64_t v4, uint64_t v5, uint64_t v6, uint64_t v7)
  125. {
  126. static_assert(is_vector<V>::value && !is_mask<V>::value,
  127. "V must be a non-mask vector");
  128. expr_vec_make_const<uint64_t,8> a;
  129. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  130. a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
  131. return detail::insn::i_make_const_any<V>(a);
  132. }
  133. template<class V> SIMDPP_INL
  134. V make_uint(uint64_t v0, uint64_t v1, uint64_t v2, uint64_t v3,
  135. uint64_t v4, uint64_t v5, uint64_t v6, uint64_t v7,
  136. uint64_t v8, uint64_t v9, uint64_t v10, uint64_t v11,
  137. uint64_t v12, uint64_t v13, uint64_t v14, uint64_t v15)
  138. {
  139. static_assert(is_vector<V>::value && !is_mask<V>::value,
  140. "V must be a non-mask vector");
  141. expr_vec_make_const<uint64_t,16> a;
  142. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  143. a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
  144. a.a[8] = v8; a.a[9] = v9; a.a[10] = v10; a.a[11] = v11;
  145. a.a[12] = v12; a.a[13] = v13; a.a[14] = v14; a.a[15] = v15;
  146. return detail::insn::i_make_const_any<V>(a);
  147. }
  148. /// Creates a vector initialized to zero
  149. SIMDPP_INL expr_vec_make_const<uint64_t,1> make_zero()
  150. {
  151. return make_uint(0);
  152. }
  153. template<class V> SIMDPP_INL
  154. V make_zero()
  155. {
  156. return make_uint<V>(0);
  157. }
  158. /// Creates a vector initialized to ones
  159. SIMDPP_INL expr_vec_make_ones make_ones()
  160. {
  161. return expr_vec_make_ones();
  162. }
  163. template<class V> SIMDPP_INL
  164. V make_ones()
  165. {
  166. return (V) make_ones();
  167. }
  168. } // namespace SIMDPP_ARCH_NAMESPACE
  169. } // namespace simdpp
  170. #endif