f_trunc.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_TRUNC_H
  7. #define LIBSIMDPP_SIMDPP_CORE_F_TRUNC_H
  8. #ifndef LIBSIMDPP_SIMD_H
  9. #error "This file must be included through simd.h"
  10. #endif
  11. #include <cmath>
  12. #include <simdpp/detail/insn/f_trunc.h>
  13. namespace simdpp {
  14. namespace SIMDPP_ARCH_NAMESPACE {
  15. /** Rounds the values of a vector towards zero
  16. @code
  17. r0 = trunc(a0)
  18. ...
  19. rN = trunc(aN)
  20. @endcode
  21. @par 128-bit version:
  22. @icost{SSE2, SSE3, SSSE3, 7-9}
  23. @icost{NEON, 5-6}
  24. @par 256-bit version:
  25. @icost{SSE2, SSE3, SSSE3, 14-16}
  26. @icost{NEON, 10-11}
  27. @icost{SSE4.1, ALTIVEC, 2}
  28. */
  29. template<unsigned N, class E> SIMDPP_INL
  30. float32<N,expr_empty> trunc(const float32<N,E>& a)
  31. {
  32. return detail::insn::i_trunc(a.eval());
  33. }
  34. template<unsigned N, class E> SIMDPP_INL
  35. float64<N,expr_empty> trunc(const float64<N,E>& a)
  36. {
  37. return detail::insn::i_trunc(a.eval());
  38. }
  39. } // namespace SIMDPP_ARCH_NAMESPACE
  40. } // namespace simdpp
  41. #endif