blob: ae813bb2faae5fc0bb75235873cd0b1cbc7efce8 [file] [log] [blame]
Michalis Spyroubcf8a962018-10-12 10:51:31 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Michalis Spyroubcf8a962018-10-12 10:51:31 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_WRAPPER_GET_LANE_H
25#define ARM_COMPUTE_WRAPPER_GET_LANE_H
Michalis Spyroubcf8a962018-10-12 10:51:31 +010026
27#include <arm_neon.h>
28
29namespace arm_compute
30{
31namespace wrapper
32{
Manuel Bottini053e7512018-12-28 15:05:20 +000033#define VGETLANE_IMPL_8(stype, vtype, postfix) \
34 inline stype vgetlane(const vtype vector, const unsigned int lane) \
35 { \
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010036 switch (lane) \
Manuel Bottini053e7512018-12-28 15:05:20 +000037 { \
38 case 0: \
39 return vget_lane_##postfix(vector, 0); \
40 case 1: \
41 return vget_lane_##postfix(vector, 1); \
42 case 2: \
43 return vget_lane_##postfix(vector, 2); \
44 case 3: \
45 return vget_lane_##postfix(vector, 3); \
46 case 4: \
47 return vget_lane_##postfix(vector, 4); \
48 case 5: \
49 return vget_lane_##postfix(vector, 5); \
50 case 6: \
51 return vget_lane_##postfix(vector, 6); \
52 case 7: \
53 return vget_lane_##postfix(vector, 7); \
54 default: \
55 ARM_COMPUTE_ERROR("Invalid lane"); \
56 } \
Michalis Spyroubcf8a962018-10-12 10:51:31 +010057 }
58
Manuel Bottini053e7512018-12-28 15:05:20 +000059#define VGETLANE_IMPL_4(stype, vtype, postfix) \
60 inline stype vgetlane(const vtype vector, const unsigned int lane) \
61 { \
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010062 switch (lane) \
Manuel Bottini053e7512018-12-28 15:05:20 +000063 { \
64 case 0: \
65 return vget_lane_##postfix(vector, 0); \
66 case 1: \
67 return vget_lane_##postfix(vector, 1); \
68 case 2: \
69 return vget_lane_##postfix(vector, 2); \
70 case 3: \
71 return vget_lane_##postfix(vector, 3); \
72 default: \
73 ARM_COMPUTE_ERROR("Invalid lane"); \
74 } \
Michalis Spyroubcf8a962018-10-12 10:51:31 +010075 }
76
Manuel Bottini053e7512018-12-28 15:05:20 +000077#define VGETLANE_IMPL_2(stype, vtype, postfix) \
78 inline stype vgetlane(const vtype vector, const unsigned int lane) \
79 { \
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010080 switch (lane) \
Manuel Bottini053e7512018-12-28 15:05:20 +000081 { \
82 case 0: \
83 return vget_lane_##postfix(vector, 0); \
84 case 1: \
85 return vget_lane_##postfix(vector, 1); \
86 default: \
87 ARM_COMPUTE_ERROR("Invalid lane"); \
88 } \
Michalis Spyroubcf8a962018-10-12 10:51:31 +010089 }
90
91VGETLANE_IMPL_8(uint8_t, uint8x8_t, u8)
92VGETLANE_IMPL_8(int8_t, int8x8_t, s8)
93VGETLANE_IMPL_4(uint16_t, uint16x4_t, u16)
94VGETLANE_IMPL_4(int16_t, int16x4_t, s16)
95VGETLANE_IMPL_2(uint32_t, uint32x2_t, u32)
96VGETLANE_IMPL_2(int32_t, int32x2_t, s32)
97VGETLANE_IMPL_2(float, float32x2_t, f32)
98#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
99VGETLANE_IMPL_4(float16_t, float16x4_t, f16)
100#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
101
Manuel Bottini053e7512018-12-28 15:05:20 +0000102#define VGETQLANE_IMPL_16(stype, vtype, postfix) \
103 inline stype vgetlane(const vtype vector, const unsigned int lane) \
104 { \
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100105 switch (lane) \
Manuel Bottini053e7512018-12-28 15:05:20 +0000106 { \
107 case 0: \
108 return vgetq_lane_##postfix(vector, 0); \
109 case 1: \
110 return vgetq_lane_##postfix(vector, 1); \
111 case 2: \
112 return vgetq_lane_##postfix(vector, 2); \
113 case 3: \
114 return vgetq_lane_##postfix(vector, 3); \
115 case 4: \
116 return vgetq_lane_##postfix(vector, 4); \
117 case 5: \
118 return vgetq_lane_##postfix(vector, 5); \
119 case 6: \
120 return vgetq_lane_##postfix(vector, 6); \
121 case 7: \
122 return vgetq_lane_##postfix(vector, 7); \
123 case 8: \
124 return vgetq_lane_##postfix(vector, 8); \
125 case 9: \
126 return vgetq_lane_##postfix(vector, 9); \
127 case 10: \
128 return vgetq_lane_##postfix(vector, 10); \
129 case 11: \
130 return vgetq_lane_##postfix(vector, 11); \
131 case 12: \
132 return vgetq_lane_##postfix(vector, 12); \
133 case 13: \
134 return vgetq_lane_##postfix(vector, 13); \
135 case 14: \
136 return vgetq_lane_##postfix(vector, 14); \
137 case 15: \
138 return vgetq_lane_##postfix(vector, 15); \
139 default: \
140 ARM_COMPUTE_ERROR("Invalid lane"); \
141 } \
Michalis Spyroubcf8a962018-10-12 10:51:31 +0100142 }
143
Manuel Bottini053e7512018-12-28 15:05:20 +0000144#define VGETQLANE_IMPL_8(stype, vtype, postfix) \
145 inline stype vgetlane(const vtype vector, const unsigned int lane) \
146 { \
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100147 switch (lane) \
Manuel Bottini053e7512018-12-28 15:05:20 +0000148 { \
149 case 0: \
150 return vgetq_lane_##postfix(vector, 0); \
151 case 1: \
152 return vgetq_lane_##postfix(vector, 1); \
153 case 2: \
154 return vgetq_lane_##postfix(vector, 2); \
155 case 3: \
156 return vgetq_lane_##postfix(vector, 3); \
157 case 4: \
158 return vgetq_lane_##postfix(vector, 4); \
159 case 5: \
160 return vgetq_lane_##postfix(vector, 5); \
161 case 6: \
162 return vgetq_lane_##postfix(vector, 6); \
163 case 7: \
164 return vgetq_lane_##postfix(vector, 7); \
165 default: \
166 ARM_COMPUTE_ERROR("Invalid lane"); \
167 } \
Michalis Spyroubcf8a962018-10-12 10:51:31 +0100168 }
169
Manuel Bottini053e7512018-12-28 15:05:20 +0000170#define VGETQLANE_IMPL_4(stype, vtype, postfix) \
171 inline stype vgetlane(const vtype vector, const unsigned int lane) \
172 { \
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100173 switch (lane) \
Manuel Bottini053e7512018-12-28 15:05:20 +0000174 { \
175 case 0: \
176 return vgetq_lane_##postfix(vector, 0); \
177 case 1: \
178 return vgetq_lane_##postfix(vector, 1); \
179 case 2: \
180 return vgetq_lane_##postfix(vector, 2); \
181 case 3: \
182 return vgetq_lane_##postfix(vector, 3); \
183 default: \
184 ARM_COMPUTE_ERROR("Invalid lane"); \
185 } \
Michalis Spyroubcf8a962018-10-12 10:51:31 +0100186 }
187
Sang-Hoon Park0d008f72020-03-13 14:56:05 +0000188#define VGETQLANE_IMPL_2(stype, vtype, postfix) \
189 inline stype vgetlane(const vtype vector, const unsigned int lane) \
190 { \
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100191 switch (lane) \
Sang-Hoon Park0d008f72020-03-13 14:56:05 +0000192 { \
193 case 0: \
194 return vgetq_lane_##postfix(vector, 0); \
195 case 1: \
196 return vgetq_lane_##postfix(vector, 1); \
197 default: \
198 ARM_COMPUTE_ERROR("Invalid lane"); \
199 } \
200 }
201
Michalis Spyroubcf8a962018-10-12 10:51:31 +0100202VGETQLANE_IMPL_16(uint8_t, uint8x16_t, u8)
203VGETQLANE_IMPL_16(int8_t, int8x16_t, s8)
204VGETQLANE_IMPL_8(uint16_t, uint16x8_t, u16)
205VGETQLANE_IMPL_8(int16_t, int16x8_t, s16)
206VGETQLANE_IMPL_4(uint32_t, uint32x4_t, u32)
207VGETQLANE_IMPL_4(int32_t, int32x4_t, s32)
208VGETQLANE_IMPL_4(float, float32x4_t, f32)
Sang-Hoon Park0d008f72020-03-13 14:56:05 +0000209VGETQLANE_IMPL_2(int64_t, int64x2_t, s64)
Michalis Spyroubcf8a962018-10-12 10:51:31 +0100210#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
211VGETQLANE_IMPL_8(float16_t, float16x8_t, f16)
212#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
213
214#undef VGETLANE_IMPL_8
215#undef VGETLANE_IMPL_4
216#undef VGETLANE_IMPL_2
Manuel Bottini053e7512018-12-28 15:05:20 +0000217
218#undef VGETQLANE_IMPL_16
219#undef VGETQLANE_IMPL_8
220#undef VGETQLANE_IMPL_4
Michalis Spyroubcf8a962018-10-12 10:51:31 +0100221} // namespace wrapper
222} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000223#endif /* ARM_COMPUTE_WRAPPER_GET_LANE_H */