i_sub.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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_I_SUB_H
  7. #define LIBSIMDPP_SIMDPP_CORE_I_SUB_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/expr/i_sub.h>
  13. #include <simdpp/core/detail/get_expr_uint.h>
  14. #include <simdpp/core/detail/scalar_arg_impl.h>
  15. #include <simdpp/core/detail/get_expr_uint.h>
  16. namespace simdpp {
  17. namespace SIMDPP_ARCH_NAMESPACE {
  18. /** Subtracts 8-bit integer values.
  19. @code
  20. r0 = a0 - b0
  21. ...
  22. rN = aN - bN
  23. @endcode
  24. @par 256-bit version:
  25. @icost{SSE2-AVX, NEON, ALTIVEC, 2}
  26. */
  27. template<unsigned N, class V1, class V2> SIMDPP_INL
  28. typename detail::get_expr_uint<expr_isub, V1, V2>::type
  29. sub(const any_int8<N,V1>& a,
  30. const any_int8<N,V2>& b)
  31. {
  32. return { { a.wrapped(), b.wrapped() } };
  33. }
  34. SIMDPP_SCALAR_ARG_IMPL_INT_UNSIGNED(sub, expr_isub, any_int8, int8)
  35. /** Subtracts 16-bit integer values.
  36. @code
  37. r0 = a0 - b0
  38. ...
  39. rN = aN - bN
  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. typename detail::get_expr_uint<expr_isub, V1, V2>::type
  46. sub(const any_int16<N,V1>& a,
  47. const any_int16<N,V2>& b)
  48. {
  49. return { { a.wrapped(), b.wrapped() } };
  50. }
  51. SIMDPP_SCALAR_ARG_IMPL_INT_UNSIGNED(sub, expr_isub, any_int16, int16)
  52. /** Subtracts 32-bit integer values.
  53. @code
  54. r0 = a0 - b0
  55. ...
  56. rN = aN - bN
  57. @endcode
  58. @par 256-bit version:
  59. @icost{SSE2-AVX, NEON, ALTIVEC, 2}
  60. */
  61. template<unsigned N, class V1, class V2> SIMDPP_INL
  62. typename detail::get_expr_uint<expr_isub, V1, V2>::type
  63. sub(const any_int32<N,V1>& a,
  64. const any_int32<N,V2>& b)
  65. {
  66. return { { a.wrapped(), b.wrapped() } };
  67. }
  68. SIMDPP_SCALAR_ARG_IMPL_INT_UNSIGNED(sub, expr_isub, any_int32, int32)
  69. /** Subtracts 64-bit integer values.
  70. @code
  71. r0 = a0 - b0
  72. ...
  73. rN = aN - bN
  74. @endcode
  75. @par 128-bit version:
  76. @icost{ALTIVEC, 5-6}
  77. @par 256-bit version:
  78. @icost{SSE2-AVX, NEON, 2}
  79. @icost{ALTIVEC, 10-11}
  80. */
  81. template<unsigned N, class V1, class V2> SIMDPP_INL
  82. typename detail::get_expr_uint<expr_isub, V1, V2>::type
  83. sub(const any_int64<N,V1>& a,
  84. const any_int64<N,V2>& b)
  85. {
  86. return { { a.wrapped(), b.wrapped() } };
  87. }
  88. SIMDPP_SCALAR_ARG_IMPL_INT_UNSIGNED(sub, expr_isub, any_int64, int64)
  89. } // namespace SIMDPP_ARCH_NAMESPACE
  90. } // namespace simdpp
  91. #endif