blob: d740091464a18bd7b1d37c6da16d69881af7f152 [file] [log] [blame]
Viet-Hoa Do40b44192022-09-22 10:24:23 +01001/*
2 * Copyright (c) 2022 Arm Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#ifndef ARM_COMPUTE_WRAPPER_SHR_H
26#define ARM_COMPUTE_WRAPPER_SHR_H
27
28#include <type_traits>
29#include <arm_neon.h>
30
31namespace arm_compute
32{
33namespace wrapper
34{
35
36#define VQRSHRN_IMPL(half_vtype, vtype, prefix, postfix) \
37 template <int b> \
38 inline half_vtype vqrshrn(const vtype &a) \
39 { \
40 return prefix##_##postfix(a, b); \
41 }
42
43VQRSHRN_IMPL(int8x8_t, int16x8_t, vqrshrn_n, s16)
44VQRSHRN_IMPL(uint8x8_t, uint16x8_t, vqrshrn_n, u16)
45VQRSHRN_IMPL(int16x4_t, int32x4_t, vqrshrn_n, s32)
46VQRSHRN_IMPL(uint16x4_t, uint32x4_t, vqrshrn_n, u32)
47VQRSHRN_IMPL(int32x2_t, int64x2_t, vqrshrn_n, s64)
48VQRSHRN_IMPL(uint32x2_t, uint64x2_t, vqrshrn_n, u64)
49
50#undef VQRSHRN_IMPL
51
Viet-Hoa Do910e3f92022-10-11 13:21:35 +010052#ifdef __aarch64__
53#define VQRSHRN_SCALAR_IMPL(half_vtype, vtype, prefix, postfix) \
54 template <int b> \
55 inline half_vtype vqrshrn(const vtype &a) \
56 { \
57 return prefix##_##postfix(a, b); \
58 }
59
60VQRSHRN_SCALAR_IMPL(int8_t, int16_t, vqrshrnh_n, s16)
61VQRSHRN_SCALAR_IMPL(uint8_t, uint16_t, vqrshrnh_n, u16)
62VQRSHRN_SCALAR_IMPL(int16_t, int32_t, vqrshrns_n, s32)
63VQRSHRN_SCALAR_IMPL(uint16_t, uint32_t, vqrshrns_n, u32)
64VQRSHRN_SCALAR_IMPL(int32_t, int64_t, vqrshrnd_n, s64)
65VQRSHRN_SCALAR_IMPL(uint32_t, uint64_t, vqrshrnd_n, u64)
66
67#undef VQRSHRN_SCALAR_IMPL
68#endif // __aarch64__
69
Viet-Hoa Do40b44192022-09-22 10:24:23 +010070// This function is the mixed version of VQRSHRN and VQRSHRUN.
71// The input vector is always signed integer, while the returned vector
72// can be either signed or unsigned depending on the signedness of scalar type T.
73#define VQRSHRN_EX_IMPL(half_vtype, vtype, prefix_signed, prefix_unsigned, postfix) \
74 template <int b, typename T> \
75 inline typename std::enable_if<std::is_integral<T>::value && std::is_signed<T>::value, half_vtype>::type \
76 vqrshrn_ex(const vtype &a) \
77 { \
78 return prefix_signed##_##postfix(a, b); \
79 } \
80 \
81 template <int b, typename T> \
82 inline typename std::enable_if<std::is_integral<T>::value && !std::is_signed<T>::value, u##half_vtype>::type \
83 vqrshrn_ex(const vtype &a) \
84 { \
85 return prefix_unsigned##_##postfix(a, b); \
86 }
87
88VQRSHRN_EX_IMPL(int8x8_t, int16x8_t, vqrshrn_n, vqrshrun_n, s16)
89VQRSHRN_EX_IMPL(int16x4_t, int32x4_t, vqrshrn_n, vqrshrun_n, s32)
90VQRSHRN_EX_IMPL(int32x2_t, int64x2_t, vqrshrn_n, vqrshrun_n, s64)
91
92#undef VQRSHRN_EX_IMPL
93
Viet-Hoa Do910e3f92022-10-11 13:21:35 +010094#ifdef __aarch64__
95#define VQRSHRN_EX_SCALAR_IMPL(half_vtype, vtype, prefix_signed, prefix_unsigned, postfix) \
96 template <int b, typename T> \
97 inline typename std::enable_if<std::is_integral<T>::value && std::is_signed<T>::value, half_vtype>::type \
98 vqrshrn_ex(const vtype &a) \
99 { \
100 return prefix_signed##_##postfix(a, b); \
101 } \
102 \
103 template <int b, typename T> \
104 inline typename std::enable_if<std::is_integral<T>::value && !std::is_signed<T>::value, u##half_vtype>::type \
105 vqrshrn_ex(const vtype &a) \
106 { \
107 return prefix_unsigned##_##postfix(a, b); \
108 }
109
110VQRSHRN_EX_SCALAR_IMPL(int8_t, int16_t, vqrshrnh_n, vqrshrunh_n, s16)
111VQRSHRN_EX_SCALAR_IMPL(int16_t, int32_t, vqrshrns_n, vqrshruns_n, s32)
112VQRSHRN_EX_SCALAR_IMPL(int32_t, int64_t, vqrshrnd_n, vqrshrund_n, s64)
113
114#undef VQRSHRN_EX_IMPL
115#endif // __aarch64__
116
Viet-Hoa Do40b44192022-09-22 10:24:23 +0100117} // namespace wrapper
118} // namespace arm_compute
119#endif /* ARM_COMPUTE_WRAPPER_SHR_H */