1/* Copyright (C) 2013-2014 Povilas Kanapickas <povilas@radix.lt>
2
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt)
6*/
7
8#ifndef LIBSIMDPP_SIMDPP_CORE_I_ABS_H
9#define LIBSIMDPP_SIMDPP_CORE_I_ABS_H
10
11#ifndef LIBSIMDPP_SIMD_H
12 #error "This file must be included through simd.h"
13#endif
14
15#include <simdpp/types.h>
16#include <simdpp/detail/expr/i_abs.h>
17
18namespace simdpp {
19namespace SIMDPP_ARCH_NAMESPACE {
20
21/** Computes absolute value of 8-bit integer values.
22
23 @code
24 r0 = abs(a0)
25 ...
26 rN = abs(aN)
27 @endcode
28
29 @par 128-bit version:
30 @icost{SSE2-SSE3, 3}
31 @icost{ALTIVEC, 1-3}
32
33 @par 256-bit version:
34 @icost{SSE2-SSE3, 6}
35 @icost{SSSE3-AVX, NEON, 2}
36 @icost{ALTIVEC, 2-4}
37*/
38template<unsigned N, class E> SIMDPP_INL
39uint8<N, expr_iabs<int8<N,E>>> abs(const int8<N,E>& a)
40{
41 return { { a } };
42}
43
44
45/** Computes absolute value of 16-bit integer values.
46
47 @code
48 r0 = abs(a0)
49 ...
50 rN = abs(aN)
51 @endcode
52 @par 128-bit version:
53 @icost{SSE2-SSE3, 3}
54 @icost{ALTIVEC, 1-3}
55
56 @par 256-bit version:
57 @icost{SSE2-SSE3, 6}
58 @icost{SSSE3-AVX, NEON, 2}
59 @icost{ALTIVEC, 2-5}
60*/
61template<unsigned N, class E> SIMDPP_INL
62uint16<N, expr_iabs<int16<N,E>>> abs(const int16<N,E>& a)
63{
64 return { { a } };
65}
66
67/** Computes absolute value of 32-bit integer values.
68
69 @code
70 r0 = abs(a0)
71 ...
72 rN = abs(aN)
73 @endcode
74 @par 128-bit version:
75 @icost{SSE2-SSE3, 3}
76 @icost{ALTIVEC, 1-3}
77
78 @par 256-bit version:
79 @icost{SSE2-SSE3, 6}
80 @icost{SSSE3-AVX, NEON, 2}
81 @icost{ALTIVEC, 2-4}
82*/
83template<unsigned N, class E> SIMDPP_INL
84uint32<N, expr_iabs<int32<N,E>>> abs(const int32<N,E>& a)
85{
86 return { { a } };
87}
88
89/** Computes absolute value of 64-bit integer values.
90
91 @code
92 r0 = abs(a0)
93 ...
94 rN = abs(aN)
95 @endcode
96 @par 128-bit version:
97 @icost{SSE2-AVX, 5}
98 @icost{NEON, 6}
99 @novec{ALTIVEC}
100
101 @par 256-bit version:
102 @icost{SSE2-AVX, 10}
103 @icost{NEON, 12}
104 @icost{AVX2, 4}
105 @novec{ALTIVEC}
106*/
107template<unsigned N, class E> SIMDPP_INL
108uint64<N, expr_iabs<int64<N,E>>> abs(const int64<N,E>& a)
109{
110 return { { a } };
111}
112
113} // namespace SIMDPP_ARCH_NAMESPACE
114} // namespace simdpp
115
116#endif
117
118