bit_and.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_BIT_AND_H
  7. #define LIBSIMDPP_SIMDPP_CORE_BIT_AND_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/bit_and.h>
  13. #include <simdpp/detail/expr/bit_and.h>
  14. #include <simdpp/detail/get_expr.h>
  15. #include <simdpp/core/detail/get_expr_bitwise.h>
  16. #include <simdpp/core/detail/scalar_arg_impl.h>
  17. namespace simdpp {
  18. namespace SIMDPP_ARCH_NAMESPACE {
  19. /** Computes bitwise AND of integer or floating-point vectors.
  20. @code
  21. r0 = a0 & b0
  22. ...
  23. rN = aN & bN
  24. @endcode
  25. @todo: icost
  26. */
  27. template<unsigned N, class V1, class V2> SIMDPP_INL
  28. typename detail::get_expr_bitwise2_and<expr_bit_and, V1, V2>::type
  29. bit_and(const any_vec<N,V1>& a,
  30. const any_vec<N,V2>& b)
  31. {
  32. return { { a.wrapped(), b.wrapped() } };
  33. }
  34. // support scalar arguments
  35. template<unsigned N, class V> SIMDPP_INL
  36. typename detail::get_expr_bitwise2_and<expr_bit_and, unsigned, V>::type
  37. bit_and(const unsigned& a, const any_vec<N,V>& b)
  38. {
  39. return { { a, b.wrapped() } };
  40. }
  41. template<unsigned N, class V> SIMDPP_INL
  42. typename detail::get_expr_bitwise2_and<expr_bit_and, unsigned long, V>::type
  43. bit_and(const unsigned long& a, const any_vec<N,V>& b)
  44. {
  45. return { { a, b.wrapped() } };
  46. }
  47. template<unsigned N, class V> SIMDPP_INL
  48. typename detail::get_expr_bitwise2_and<expr_bit_and, unsigned long long, V>::type
  49. bit_and(const unsigned long long& a, const any_vec<N,V>& b)
  50. {
  51. return { { a, b.wrapped() } };
  52. }
  53. template<unsigned N, class V> SIMDPP_INL
  54. typename detail::get_expr_bitwise2_and<expr_bit_and, int, V>::type
  55. bit_and(const int& a, const any_vec<N,V>& b)
  56. {
  57. return { { a, b.wrapped() } };
  58. }
  59. template<unsigned N, class V> SIMDPP_INL
  60. typename detail::get_expr_bitwise2_and<expr_bit_and, long, V>::type
  61. bit_and(const long& a, const any_vec<N,V>& b)
  62. {
  63. return { { a, b.wrapped() } };
  64. }
  65. template<unsigned N, class V> SIMDPP_INL
  66. typename detail::get_expr_bitwise2_and<expr_bit_and, long long, V>::type
  67. bit_and(const long long& a, const any_vec<N,V>& b)
  68. {
  69. return { { a, b.wrapped() } };
  70. }
  71. template<unsigned N, class V> SIMDPP_INL
  72. typename detail::get_expr_bitwise2_and<expr_bit_and, V, unsigned>::type
  73. bit_and(const any_vec<N,V>& a, const unsigned& b)
  74. {
  75. return { { a.wrapped(), b } };
  76. }
  77. template<unsigned N, class V> SIMDPP_INL
  78. typename detail::get_expr_bitwise2_and<expr_bit_and, V, unsigned long>::type
  79. bit_and(const any_vec<N,V>& a, const unsigned long& b)
  80. {
  81. return { { a.wrapped(), b } };
  82. }
  83. template<unsigned N, class V> SIMDPP_INL
  84. typename detail::get_expr_bitwise2_and<expr_bit_and, V, unsigned long long>::type
  85. bit_and(const any_vec<N,V>& a, const unsigned long long& b)
  86. {
  87. return { { a.wrapped(), b } };
  88. }
  89. template<unsigned N, class V> SIMDPP_INL
  90. typename detail::get_expr_bitwise2_and<expr_bit_and, V, int>::type
  91. bit_and(const any_vec<N,V>& a, const int& b)
  92. {
  93. return { { a.wrapped(), b } };
  94. }
  95. template<unsigned N, class V> SIMDPP_INL
  96. typename detail::get_expr_bitwise2_and<expr_bit_and, V, long>::type
  97. bit_and(const any_vec<N,V>& a, const long& b)
  98. {
  99. return { { a.wrapped(), b } };
  100. }
  101. template<unsigned N, class V> SIMDPP_INL
  102. typename detail::get_expr_bitwise2_and<expr_bit_and, V, long long>::type
  103. bit_and(const any_vec<N,V>& a, const long long& b)
  104. {
  105. return { { a.wrapped(), b } };
  106. }
  107. } // namespace SIMDPP_ARCH_NAMESPACE
  108. } // namespace simdpp
  109. #endif