f_abs.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_F_ABS_H
  7. #define LIBSIMDPP_SIMDPP_CORE_F_ABS_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/f_abs.h>
  13. namespace simdpp {
  14. namespace SIMDPP_ARCH_NAMESPACE {
  15. /** Computes absolute value of floating point values.
  16. @code
  17. r0 = abs(a0)
  18. ...
  19. rN = abs(aN)
  20. @endcode
  21. @par 128-bit version:
  22. @icost{SSE2-AVX2, 1-2}
  23. @icost{ALTIVEC, 1-2}
  24. @par 256-bit version:
  25. @icost{SSE2-SSE4.1, 2-3}
  26. @icost{NEON, 2}
  27. @icost{AVX-AVX2, 1-2}
  28. @icost{ALTIVEC, 2-3}
  29. */
  30. template<unsigned N, class E> SIMDPP_INL
  31. float32<N, expr_fabs<float32<N,E>>> abs(const float32<N,E>& a)
  32. {
  33. return { { a } };
  34. }
  35. /** Computes absolute value of floating point values.
  36. @code
  37. r0 = abs(a0)
  38. ...
  39. rN = abs(aN)
  40. @endcode
  41. @par 128-bit version:
  42. @novec{NEON, ALTIVEC}
  43. @icost{SSE2-AVX2, 1-2}
  44. @par 256-bit version:
  45. @novec{NEON, ALTIVEC}
  46. @icost{SSE2-SSE4.1, 2-3}
  47. @icost{AVX-AVX2, 1-2}
  48. */
  49. template<unsigned N, class E> SIMDPP_INL
  50. float64<N, expr_fabs<float64<N,E>>> abs(const float64<N,E>& a)
  51. {
  52. return { { a } };
  53. }
  54. } // namespace SIMDPP_ARCH_NAMESPACE
  55. } // namespace simdpp
  56. #endif