make_int.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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_INT_H
  7. #define LIBSIMDPP_SIMDPP_CORE_MAKE_INT_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 signed 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. @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. // FIXME: return empty expr
  47. SIMDPP_INL expr_vec_make_const<int64_t,1> make_int(int64_t v0)
  48. {
  49. expr_vec_make_const<int64_t,1> a;
  50. a.a[0] = v0;
  51. return a;
  52. }
  53. static SIMDPP_INL
  54. expr_vec_make_const<int64_t,2> make_int(int64_t v0, int64_t v1)
  55. {
  56. expr_vec_make_const<int64_t,2> a;
  57. a.a[0] = v0; a.a[1] = v1;
  58. return a;
  59. }
  60. static SIMDPP_INL
  61. expr_vec_make_const<int64_t,4>
  62. make_int(int64_t v0, int64_t v1, int64_t v2, int64_t v3)
  63. {
  64. expr_vec_make_const<int64_t,4> a;
  65. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  66. return a;
  67. }
  68. static SIMDPP_INL
  69. expr_vec_make_const<int64_t,8>
  70. make_int(int64_t v0, int64_t v1, int64_t v2, int64_t v3,
  71. int64_t v4, int64_t v5, int64_t v6, int64_t v7)
  72. {
  73. expr_vec_make_const<int64_t,8> a;
  74. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  75. a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
  76. return a;
  77. }
  78. static SIMDPP_INL
  79. expr_vec_make_const<int64_t,16>
  80. make_int(int64_t v0, int64_t v1, int64_t v2, int64_t v3,
  81. int64_t v4, int64_t v5, int64_t v6, int64_t v7,
  82. int64_t v8, int64_t v9, int64_t v10, int64_t v11,
  83. int64_t v12, int64_t v13, int64_t v14, int64_t v15)
  84. {
  85. expr_vec_make_const<int64_t,16> a;
  86. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  87. a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
  88. a.a[8] = v8; a.a[9] = v9; a.a[10] = v10; a.a[11] = v11;
  89. a.a[12] = v12; a.a[13] = v13; a.a[14] = v14; a.a[15] = v15;
  90. return a;
  91. }
  92. template<class V> SIMDPP_INL
  93. V make_int(int64_t v0)
  94. {
  95. static_assert(is_vector<V>::value && !is_mask<V>::value,
  96. "V must be a non-mask vector");
  97. expr_vec_make_const<int64_t,1> a;
  98. a.a[0] = v0;
  99. return detail::insn::i_make_const_any<V>(a);
  100. }
  101. template<class V> SIMDPP_INL
  102. V make_int(int64_t v0, int64_t v1)
  103. {
  104. static_assert(is_vector<V>::value && !is_mask<V>::value,
  105. "V must be a non-mask vector");
  106. expr_vec_make_const<int64_t,2> a;
  107. a.a[0] = v0; a.a[1] = v1;
  108. return detail::insn::i_make_const_any<V>(a);
  109. }
  110. template<class V> SIMDPP_INL
  111. V make_int(int64_t v0, int64_t v1, int64_t v2, int64_t v3)
  112. {
  113. static_assert(is_vector<V>::value && !is_mask<V>::value,
  114. "V must be a non-mask vector");
  115. expr_vec_make_const<int64_t,4> a;
  116. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  117. return detail::insn::i_make_const_any<V>(a);
  118. }
  119. template<class V> SIMDPP_INL
  120. V make_int(int64_t v0, int64_t v1, int64_t v2, int64_t v3,
  121. int64_t v4, int64_t v5, int64_t v6, int64_t v7)
  122. {
  123. static_assert(is_vector<V>::value && !is_mask<V>::value,
  124. "V must be a non-mask vector");
  125. expr_vec_make_const<int64_t,8> a;
  126. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  127. a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
  128. return detail::insn::i_make_const_any<V>(a);
  129. }
  130. template<class V> SIMDPP_INL
  131. V make_int(int64_t v0, int64_t v1, int64_t v2, int64_t v3,
  132. int64_t v4, int64_t v5, int64_t v6, int64_t v7,
  133. int64_t v8, int64_t v9, int64_t v10, int64_t v11,
  134. int64_t v12, int64_t v13, int64_t v14, int64_t v15)
  135. {
  136. static_assert(is_vector<V>::value && !is_mask<V>::value,
  137. "V must be a non-mask vector");
  138. expr_vec_make_const<int64_t,16> a;
  139. a.a[0] = v0; a.a[1] = v1; a.a[2] = v2; a.a[3] = v3;
  140. a.a[4] = v4; a.a[5] = v5; a.a[6] = v6; a.a[7] = v7;
  141. a.a[8] = v8; a.a[9] = v9; a.a[10] = v10; a.a[11] = v11;
  142. a.a[12] = v12; a.a[13] = v13; a.a[14] = v14; a.a[15] = v15;
  143. return detail::insn::i_make_const_any<V>(a);
  144. }
  145. } // namespace SIMDPP_ARCH_NAMESPACE
  146. } // namespace simdpp
  147. #endif