cmp_eq.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* Copyright (C) 2013-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_CMP_EQ_H
  7. #define LIBSIMDPP_SIMDPP_CORE_CMP_EQ_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/cmp_eq.h>
  13. #include <simdpp/core/detail/scalar_arg_impl.h>
  14. namespace simdpp {
  15. namespace SIMDPP_ARCH_NAMESPACE {
  16. /** Compares 8-bit values for equality.
  17. @code
  18. r0 = (a0 == b0) ? 0xff : 0x0
  19. ...
  20. rN = (aN == bN) ? 0xff : 0x0
  21. @endcode
  22. @par 256-bit version:
  23. @icost{SSE2-AVX, NEON, ALTIVEC, 2}
  24. */
  25. template<unsigned N, class V1, class V2> SIMDPP_INL
  26. mask_int8<N,expr_empty> cmp_eq(const any_int8<N,V1>& a,
  27. const any_int8<N,V2>& b)
  28. {
  29. typename detail::get_expr2_nosign<V1, V2>::type ra, rb;
  30. ra = a.wrapped().eval();
  31. rb = b.wrapped().eval();
  32. return detail::insn::i_cmp_eq(ra, rb);
  33. }
  34. SIMDPP_SCALAR_ARG_IMPL_VEC_EXPR(cmp_eq, mask_int8, any_int8)
  35. /** Compares 16-bit values for equality.
  36. @code
  37. r0 = (a0 == b0) ? 0xffff : 0x0
  38. ...
  39. rN = (aN == bN) ? 0xffff : 0x0
  40. @endcode
  41. @par 256-bit version:
  42. @icost{SSE2-AVX, NEON, ALTIVEC, 2}
  43. */
  44. template<unsigned N, class V1, class V2> SIMDPP_INL
  45. mask_int16<N,expr_empty> cmp_eq(const any_int16<N,V1>& a,
  46. const any_int16<N,V2>& b)
  47. {
  48. typename detail::get_expr2_nosign<V1, V2>::type ra, rb;
  49. ra = a.wrapped().eval();
  50. rb = b.wrapped().eval();
  51. return detail::insn::i_cmp_eq(ra, rb);
  52. }
  53. SIMDPP_SCALAR_ARG_IMPL_VEC_EXPR(cmp_eq, mask_int16, any_int16)
  54. /** Compares the values of two int32x4 vectors for equality
  55. @code
  56. r0 = (a0 == b0) ? 0xffffffff : 0x0
  57. ...
  58. rN = (aN == bN) ? 0xffffffff : 0x0
  59. @endcode
  60. @par 256-bit version:
  61. @icost{SSE2-AVX, NEON, ALTIVEC, 2}
  62. */
  63. template<unsigned N, class V1, class V2> SIMDPP_INL
  64. mask_int32<N,expr_empty> cmp_eq(const any_int32<N,V1>& a,
  65. const any_int32<N,V2>& b)
  66. {
  67. typename detail::get_expr2_nosign<V1, V2>::type ra, rb;
  68. ra = a.wrapped().eval();
  69. rb = b.wrapped().eval();
  70. return detail::insn::i_cmp_eq(ra, rb);
  71. }
  72. SIMDPP_SCALAR_ARG_IMPL_VEC_EXPR(cmp_eq, mask_int32, any_int32)
  73. /** Compares the values of two int64x2 vectors for equality
  74. @code
  75. r0 = (a0 == b0) ? 0xffffffffffffffff : 0x0
  76. ...
  77. rN = (aN == bN) ? 0xffffffffffffffff : 0x0
  78. @endcode
  79. @par 128-bit version:
  80. @icost{SSE2-SSSE3, 5}
  81. @icost{XOP, 1}
  82. @icost{NEON, 3}
  83. @icost{ALTIVEC, 3-4}
  84. @par 256-bit version:
  85. @icost{SSE2-SSSE3, AVX, 10}
  86. @icost{XOP, SSE4.1, 2}
  87. @icost{NEON, 6}
  88. @icost{ALTIVEC, 6-7}
  89. */
  90. template<unsigned N, class V1, class V2> SIMDPP_INL
  91. mask_int64<N,expr_empty> cmp_eq(const any_int64<N,V1>& a,
  92. const any_int64<N,V2>& b)
  93. {
  94. typename detail::get_expr2_nosign<V1, V2>::type ra, rb;
  95. ra = a.wrapped().eval();
  96. rb = b.wrapped().eval();
  97. return detail::insn::i_cmp_eq(ra, rb);
  98. }
  99. SIMDPP_SCALAR_ARG_IMPL_VEC_EXPR(cmp_eq, mask_int64, any_int64)
  100. /** Compares the values of two float32x4 vectors for equality
  101. @code
  102. r0 = (a0 == b0) ? 0xffffffff : 0x0
  103. ...
  104. rN = (aN == bN) ? 0xffffffff : 0x0
  105. @endcode
  106. @par 256-bit version:
  107. @icost{SSE2-SSE4.1, NEON, ALTIVEC, 2}
  108. */
  109. template<unsigned N, class V1, class V2> SIMDPP_INL
  110. mask_float32<N,expr_empty> cmp_eq(const any_float32<N,V1>& a,
  111. const any_float32<N,V2>& b)
  112. {
  113. return detail::insn::i_cmp_eq(a.wrapped().eval(), b.wrapped().eval());
  114. }
  115. SIMDPP_SCALAR_ARG_IMPL_VEC_EXPR(cmp_eq, mask_float32, any_float32)
  116. /** Compares the values of two float64x2 vectors for equality
  117. @code
  118. r0 = (a0 == b0) ? 0xffffffffffffffff : 0x0
  119. ...
  120. rN = (aN == bN) ? 0xffffffffffffffff : 0x0
  121. @endcode
  122. @par 128-bit version:
  123. @novec{NEON, ALTIVEC}
  124. @par 256-bit version:
  125. @novec{NEON, ALTIVEC}
  126. @icost{SSE2-SSE4.1, 2}
  127. */
  128. template<unsigned N, class V1, class V2> SIMDPP_INL
  129. mask_float64<N,expr_empty> cmp_eq(const any_float64<N,V1>& a,
  130. const any_float64<N,V2>& b)
  131. {
  132. return detail::insn::i_cmp_eq(a.wrapped().eval(), b.wrapped().eval());
  133. }
  134. SIMDPP_SCALAR_ARG_IMPL_VEC_EXPR(cmp_eq, mask_float64, any_float64)
  135. } // namespace SIMDPP_ARCH_NAMESPACE
  136. } // namespace simdpp
  137. #endif