blob: f5fb9c09aa570a094a2907219e10f3613db6fd89 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Luca Foschianidaa3aba2020-01-08 15:55:08 +00002 * Copyright (c) 2016-2020 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +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 */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000024#include "arm_compute/core/NEON/kernels/NEDepthConvertLayerKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010025
Michele Di Giorgio3e570db2018-08-24 18:28:48 +010026#include "arm_compute/core/CPP/Validate.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/Error.h"
28#include "arm_compute/core/Helpers.h"
29#include "arm_compute/core/ITensor.h"
30#include "arm_compute/core/NEON/NEFixedPoint.h"
Michalis Spyroue2588182018-12-13 18:31:18 +000031#include "arm_compute/core/NEON/NEMath.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032#include "arm_compute/core/TensorInfo.h"
33#include "arm_compute/core/Validate.h"
34
35#include <arm_neon.h>
36
37using namespace arm_compute;
38
Michele Di Giorgio3e570db2018-08-24 18:28:48 +010039namespace
Anthony Barbier6ff3b192017-09-04 18:44:23 +010040{
Michele Di Giorgio3e570db2018-08-24 18:28:48 +010041Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, ConvertPolicy policy, uint32_t shift)
42{
43 ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input);
44 ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(output);
45 ARM_COMPUTE_UNUSED(policy);
46 ARM_COMPUTE_RETURN_ERROR_ON(input == output);
Luca Foschianidaa3aba2020-01-08 15:55:08 +000047 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8_SIGNED, DataType::QASYMM8, DataType::U8, DataType::S16, DataType::U16, DataType::F16, DataType::F32, DataType::S32);
48 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::QASYMM8_SIGNED, DataType::QASYMM8, DataType::U8, DataType::S16, DataType::U16, DataType::U32, DataType::S32, DataType::F16,
49 DataType::F32);
Michele Di Giorgio3e570db2018-08-24 18:28:48 +010050 ARM_COMPUTE_RETURN_ERROR_ON(shift >= 8);
51
Luca Foschianidaa3aba2020-01-08 15:55:08 +000052 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::QASYMM8_SIGNED && (output->data_type() != DataType::S16 && output->data_type() != DataType::S32
53 && output->data_type() != DataType::F16 && output->data_type() != DataType::F32),
54 "Only data_types supported [in] QASYMM8 -> [out] U16, S16, S32, F16, F32");
55
Usama Arif9e631c22019-05-14 17:10:40 +010056 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::QASYMM8 && (output->data_type() != DataType::S16 && output->data_type() != DataType::U16
Michalis Spyrou6bff1952019-10-02 17:22:11 +010057 && output->data_type() != DataType::S32 && output->data_type() != DataType::F16 && output->data_type() != DataType::F32),
Usama Arif9e631c22019-05-14 17:10:40 +010058 "Only data_types supported [in] QASYMM8 -> [out] U16, S16, S32, F16, F32");
Michalis Spyroue2588182018-12-13 18:31:18 +000059
Michele Di Giorgio3e570db2018-08-24 18:28:48 +010060 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::U8 && (output->data_type() != DataType::S16 && output->data_type() != DataType::U16
Usama Arif9e631c22019-05-14 17:10:40 +010061 && output->data_type() != DataType::S32 && output->data_type() != DataType::F16 && output->data_type() != DataType::F32),
62 "Only data_types supported [in] U8 -> [out] U16, S16, S32, F16, F32");
Michele Di Giorgio3e570db2018-08-24 18:28:48 +010063
64 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::U16 && (output->data_type() != DataType::U8 && output->data_type() != DataType::U32),
65 "Only data_types supported [in] U16 -> [out] U8, U32");
66
Luca Foschianidaa3aba2020-01-08 15:55:08 +000067 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::S16 && (output->data_type() != DataType::QASYMM8_SIGNED && output->data_type() != DataType::U8 && output->data_type() != DataType::S32),
Michele Di Giorgio3e570db2018-08-24 18:28:48 +010068 "Only data_types supported [in] S16 -> [out] U8, S32");
69
Luca Foschianidaa3aba2020-01-08 15:55:08 +000070 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::F16 && (output->data_type() != DataType::QASYMM8_SIGNED && output->data_type() != DataType::QASYMM8
71 && output->data_type() != DataType::U8
72 && output->data_type() != DataType::F32 && output->data_type() != DataType::S32),
Usama Arif9e631c22019-05-14 17:10:40 +010073 "Only data_types supported [in] F16 -> [out] QASYMM8, F32, S32, U8");
Michele Di Giorgio3e570db2018-08-24 18:28:48 +010074
Luca Foschianidaa3aba2020-01-08 15:55:08 +000075 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::F32 && (output->data_type() != DataType::QASYMM8_SIGNED && output->data_type() != DataType::QASYMM8
76 && output->data_type() != DataType::F16
77 && output->data_type() != DataType::S32 && output->data_type() != DataType::U8),
Usama Arif9e631c22019-05-14 17:10:40 +010078 "Only data_types supported [in] F32 -> [out] QASYMM8, F16, S32, U8");
79
Luca Foschianidaa3aba2020-01-08 15:55:08 +000080 ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::S32 && (output->data_type() != DataType::QASYMM8_SIGNED && output->data_type() != DataType::QASYMM8
81 && output->data_type() != DataType::F16
82 && output->data_type() != DataType::F32 && output->data_type() != DataType::U8),
Usama Arif9e631c22019-05-14 17:10:40 +010083 "Only data_types supported [in] S32 -> [out] QASYMM8, F16, F32, U8");
Michele Di Giorgio3e570db2018-08-24 18:28:48 +010084
85 // Validate in case of configured output
86 if(output->total_size() > 0)
87 {
88 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output);
89 }
90
91 return Status{};
92}
93
94std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output)
95{
96 constexpr unsigned int num_elems_processed_per_iteration = 16;
97
98 Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration));
99
100 AccessWindowHorizontal input_access(input, 0, num_elems_processed_per_iteration);
101 AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration);
102 bool window_changed = update_window_and_padding(win, input_access, output_access);
103 output_access.set_valid_region(win, output->valid_region());
104
105 Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
106 return std::make_pair(err, win);
107}
108} // namespace
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100109
Giorgio Arena04a8f8c2017-11-23 11:45:24 +0000110NEDepthConvertLayerKernel::NEDepthConvertLayerKernel()
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100111 : _input(nullptr), _output(nullptr), _policy(), _shift(0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100112{
113}
114
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100115void NEDepthConvertLayerKernel::configure(const ITensor *input, ITensor *output, ConvertPolicy policy, uint32_t shift)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100116{
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100117 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
118
119 // Auto initialize output shape if not initialized (We can only auto-configure the shape, datatype must be given)
120 set_shape_if_empty(*output->info(), input->info()->tensor_shape());
Georgios Pinitase2229412017-07-12 12:30:40 +0100121
122 _input = input;
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100123 _output = output;
Georgios Pinitase2229412017-07-12 12:30:40 +0100124 _policy = policy;
125 _shift = shift;
126
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100127 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), policy, shift));
Georgios Pinitase2229412017-07-12 12:30:40 +0100128
129 // Configure kernel window
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100130 auto win_config = validate_and_configure_window(input->info(), output->info());
131 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
132 ICPPKernel::configure(win_config.second);
133}
Georgios Pinitase2229412017-07-12 12:30:40 +0100134
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100135Status NEDepthConvertLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output, ConvertPolicy policy, uint32_t shift)
136{
137 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, policy, shift));
138 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get()).first);
139
140 return Status{};
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100141}
142
Giorgio Arena04a8f8c2017-11-23 11:45:24 +0000143void NEDepthConvertLayerKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100144{
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100145 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100146 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
Georgios Pinitase2229412017-07-12 12:30:40 +0100147 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window);
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100148 ARM_COMPUTE_ERROR_ON_NULLPTR(_input, _output);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100149 ARM_COMPUTE_ERROR_ON(_input == _output);
150
151 Iterator input(_input, window);
152 Iterator output(_output, window);
153
154 switch(_input->info()->data_type())
155 {
Luca Foschianidaa3aba2020-01-08 15:55:08 +0000156 case DataType::QASYMM8_SIGNED:
157 {
158 const int16x8_t b = vdupq_n_s16(_shift);
159
160 switch(_output->info()->data_type())
161 {
162 case DataType::S16:
163 {
164 /* Up-conversion QASYMM8_SIGNED -> S16 */
165 execute_window_loop(window, [&](const Coordinates &)
166 {
167 const int8x16_t texels_s8 = vld1q_s8(reinterpret_cast<int8_t *>(input.ptr()));
168
169 const int16x8x2_t texels =
170 {
171 {
172 vshlq_s16(vmovl_s8(vget_low_s8(texels_s8)), b),
173 vshlq_s16(vmovl_s8(vget_high_s8(texels_s8)), b)
174 }
175 };
176
177 vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()), texels.val[0]);
178 vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()) + 8, texels.val[1]);
179 },
180 input, output);
181 break;
182 }
183 case DataType::S32:
184 {
185 /* Up-conversion QASYMM8_SIGNED -> S32 */
186 execute_window_loop(window, [&](const Coordinates &)
187 {
188 const int8x16_t texels_s8 = vld1q_s8(reinterpret_cast<int8_t *>(input.ptr()));
189
190 const int16x8x2_t texels =
191 {
192 {
193 vshlq_s16(vmovl_s8(vget_low_s8(texels_s8)), b),
194 vshlq_s16(vmovl_s8(vget_high_s8(texels_s8)), b)
195 }
196 };
197
198 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()), vmovl_s16(vget_low_s16(texels.val[0])));
199 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 4, vmovl_s16(vget_high_s16(texels.val[0])));
200 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 8, vmovl_s16(vget_low_s16(texels.val[1])));
201 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 12, vmovl_s16(vget_high_s16(texels.val[1])));
202 },
203 input, output);
204 break;
205 }
206 case DataType::F32:
207 {
208 /* Up-conversion QASYMM8_SIGNED -> F32 */
209 execute_window_loop(window, [&](const Coordinates &)
210 {
211 const int8x16_t texels_s8 = vld1q_s8(reinterpret_cast<int8_t *>(input.ptr()));
212
213 const int16x8x2_t texels =
214 {
215 {
216 vshlq_s16(vmovl_s8(vget_low_s8(texels_s8)), b),
217 vshlq_s16(vmovl_s8(vget_high_s8(texels_s8)), b)
218 }
219 };
220 vst1q_f32(reinterpret_cast<float *>(output.ptr()), vcvtq_f32_s32(vmovl_s16(vget_low_s16(texels.val[0]))));
221 vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 4, vcvtq_f32_s32(vmovl_s16(vget_high_s16(texels.val[0]))));
222 vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 8, vcvtq_f32_s32(vmovl_s16(vget_low_s16(texels.val[1]))));
223 vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 12, vcvtq_f32_s32(vmovl_s16(vget_high_s16(texels.val[1]))));
224 },
225 input, output);
226 break;
227 }
228#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
229 case DataType::F16:
230 {
231 /* Up-conversion QASYMM8_SIGNED -> F16 */
232 execute_window_loop(window, [&](const Coordinates &)
233 {
234 const int8x16_t texels_s8 = vld1q_s8(reinterpret_cast<int8_t *>(input.ptr()));
235
236 const int16x8x2_t texels =
237 {
238 {
239 vshlq_s16(vmovl_s8(vget_low_s8(texels_s8)), b),
240 vshlq_s16(vmovl_s8(vget_high_s8(texels_s8)), b)
241 }
242 };
243 vst1q_f16(reinterpret_cast<float16_t *>(output.ptr()), vcvtq_f16_s16(texels.val[0]));
244 vst1q_f16(reinterpret_cast<float16_t *>(output.ptr()) + 8, vcvtq_f16_s16(texels.val[1]));
245 },
246 input, output);
247 break;
248 }
249#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
250
251 default:
252 ARM_COMPUTE_ERROR("Output data type not supported");
253 }
254 break;
255 }
256
Michalis Spyroue2588182018-12-13 18:31:18 +0000257 case DataType::QASYMM8:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100258 case DataType::U8:
259 {
260 const int16x8_t b = vdupq_n_s16(_shift);
261
262 switch(_output->info()->data_type())
263 {
264 case DataType::S16:
265 {
266 /* Up-conversion U8 -> S16 */
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100267 execute_window_loop(window, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100268 {
269 const uint8x16_t texels_u8 = vld1q_u8(input.ptr());
270
271 const int16x8x2_t texels =
272 {
273 {
274 vshlq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(texels_u8))), b),
275 vshlq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(texels_u8))), b)
276 }
277 };
278
279 vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()), texels.val[0]);
280 vst1q_s16(reinterpret_cast<int16_t *>(output.ptr()) + 8, texels.val[1]);
281 },
282 input, output);
283 break;
284 }
285 case DataType::S32:
286 {
287 /* Up-conversion U8 -> S32 */
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100288 execute_window_loop(window, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100289 {
290 const uint8x16_t texels_u8 = vld1q_u8(input.ptr());
291
292 const int16x8x2_t texels =
293 {
294 {
295 vshlq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(texels_u8))), b),
296 vshlq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(texels_u8))), b)
297 }
298 };
299
300 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()), vmovl_s16(vget_low_s16(texels.val[0])));
301 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 4, vmovl_s16(vget_high_s16(texels.val[0])));
302 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 8, vmovl_s16(vget_low_s16(texels.val[1])));
303 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 12, vmovl_s16(vget_high_s16(texels.val[1])));
304 },
305 input, output);
306 break;
307 }
Usama Arif9e631c22019-05-14 17:10:40 +0100308 case DataType::F32:
309 {
310 /* Up-conversion U8 -> F32 */
311 execute_window_loop(window, [&](const Coordinates &)
312 {
313 const uint8x16_t texels_u8 = vld1q_u8(input.ptr());
314
315 const int16x8x2_t texels =
316 {
317 {
318 vshlq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(texels_u8))), b),
319 vshlq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(texels_u8))), b)
320 }
321 };
322 vst1q_f32(reinterpret_cast<float *>(output.ptr()), vcvtq_f32_s32(vmovl_s16(vget_low_s16(texels.val[0]))));
323 vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 4, vcvtq_f32_s32(vmovl_s16(vget_high_s16(texels.val[0]))));
324 vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 8, vcvtq_f32_s32(vmovl_s16(vget_low_s16(texels.val[1]))));
325 vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 12, vcvtq_f32_s32(vmovl_s16(vget_high_s16(texels.val[1]))));
326 },
327 input, output);
328 break;
329 }
330#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
331 case DataType::F16:
332 {
333 /* Up-conversion U8 -> F16 */
334 execute_window_loop(window, [&](const Coordinates &)
335 {
336 const uint8x16_t texels_u8 = vld1q_u8(input.ptr());
337
338 const int16x8x2_t texels =
339 {
340 {
341 vshlq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(texels_u8))), b),
342 vshlq_s16(vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(texels_u8))), b)
343 }
344 };
345 vst1q_f16(reinterpret_cast<float16_t *>(output.ptr()), vcvtq_f16_s16(texels.val[0]));
346 vst1q_f16(reinterpret_cast<float16_t *>(output.ptr()) + 8, vcvtq_f16_s16(texels.val[1]));
347 },
348 input, output);
349 break;
350 }
351#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
352
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100353 case DataType::U16:
354 {
355 /* Up-conversion U8 -> U16 */
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100356 execute_window_loop(window, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100357 {
358 const uint8x16_t texels_u8 = vld1q_u8(input.ptr());
359
360 const uint16x8x2_t texels =
361 {
362 {
363 vshlq_u16(vmovl_u8(vget_low_u8(texels_u8)), b),
364 vshlq_u16(vmovl_u8(vget_high_u8(texels_u8)), b)
365 }
366 };
367
368 vst1q_u16(reinterpret_cast<uint16_t *>(output.ptr()), texels.val[0]);
369 vst1q_u16(reinterpret_cast<uint16_t *>(output.ptr()) + 8, texels.val[1]);
370 },
371 input, output);
372 break;
373 }
374 default:
375 ARM_COMPUTE_ERROR("Output data type not supported");
376 }
377 break;
378 }
379 case DataType::S16:
380 {
381 switch(_output->info()->data_type())
382 {
Luca Foschianidaa3aba2020-01-08 15:55:08 +0000383 case DataType::QASYMM8_SIGNED:
384 {
385 const int16x8_t b = vdupq_n_s16(-static_cast<int16_t>(_shift));
386
387 /* Down-conversion S16 -> QASYMM8_SIGNED */
388 if(ConvertPolicy::SATURATE == _policy)
389 {
390 execute_window_loop(window, [&](const Coordinates &)
391 {
392 const int16x8x2_t texels =
393 {
394 {
395 vqshlq_s16(vld1q_s16(reinterpret_cast<int16_t *>(input.ptr())), b),
396 vqshlq_s16(vld1q_s16(reinterpret_cast<int16_t *>(input.ptr()) + 8), b)
397 }
398 };
399
400 vst1q_s8(reinterpret_cast<int8_t *>(output.ptr()), vcombine_s8(vqmovn_s16(texels.val[0]), vqmovn_s16(texels.val[1])));
401 },
402 input, output);
403 }
404 else
405 {
406 execute_window_loop(window, [&](const Coordinates &)
407 {
408 const int16x8x2_t texels =
409 {
410 {
411 vshlq_s16(vld1q_s16(reinterpret_cast<int16_t *>(input.ptr())), b),
412 vshlq_s16(vld1q_s16(reinterpret_cast<int16_t *>(input.ptr()) + 8), b)
413 }
414 };
415
416 vst1q_s8(reinterpret_cast<int8_t *>(output.ptr()), vcombine_s8(vmovn_s16(texels.val[0]), vmovn_s16(texels.val[1])));
417 },
418 input, output);
419 }
420 break;
421 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100422 case DataType::U8:
423 {
424 const int16x8_t b = vdupq_n_s16(-static_cast<int16_t>(_shift));
425
426 /* Down-conversion S16 -> U8 */
427 if(ConvertPolicy::SATURATE == _policy)
428 {
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100429 execute_window_loop(window, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100430 {
431 const int16x8x2_t texels =
432 {
433 {
434 vqshlq_s16(vld1q_s16(reinterpret_cast<int16_t *>(input.ptr())), b),
435 vqshlq_s16(vld1q_s16(reinterpret_cast<int16_t *>(input.ptr()) + 8), b)
436 }
437 };
438
439 vst1q_u8(output.ptr(), vcombine_u8(vqmovun_s16(texels.val[0]), vqmovun_s16(texels.val[1])));
440 },
441 input, output);
442 }
443 else
444 {
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100445 execute_window_loop(window, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100446 {
447 const int16x8x2_t texels =
448 {
449 {
450 vshlq_s16(vld1q_s16(reinterpret_cast<int16_t *>(input.ptr())), b),
451 vshlq_s16(vld1q_s16(reinterpret_cast<int16_t *>(input.ptr()) + 8), b)
452 }
453 };
454
455 vst1q_u8(output.ptr(), vcombine_u8(vmovn_u16(vreinterpretq_u16_s16(texels.val[0])),
456 vmovn_u16(vreinterpretq_u16_s16(texels.val[1]))));
457 },
458 input, output);
459 }
460 break;
461 }
462 case DataType::S32:
463 {
464 const int32x4_t b = vdupq_n_s32(_shift);
465
466 /* Up-conversion S16 -> S32 */
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100467 execute_window_loop(window, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100468 {
469 const int16x8x2_t texels =
470 {
471 {
472 vld1q_s16(reinterpret_cast<int16_t *>(input.ptr())),
473 vld1q_s16(reinterpret_cast<int16_t *>(input.ptr()) + 8)
474 }
475 };
476
477 const int32x4x4_t texels_s32 =
478 {
479 {
480 vshlq_s32(vmovl_s16(vget_low_s16(texels.val[0])), b),
481 vshlq_s32(vmovl_s16(vget_high_s16(texels.val[0])), b),
482 vshlq_s32(vmovl_s16(vget_low_s16(texels.val[1])), b),
483 vshlq_s32(vmovl_s16(vget_high_s16(texels.val[1])), b)
484 }
485 };
486
487 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()), texels_s32.val[0]);
488 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 4, texels_s32.val[1]);
489 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 8, texels_s32.val[2]);
490 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 12, texels_s32.val[3]);
491 },
492 input, output);
493 break;
494 }
495 default:
496 ARM_COMPUTE_ERROR("Output data type not supported");
497 }
498 break;
499 }
500 case DataType::U16:
501 {
502 switch(_output->info()->data_type())
503 {
504 case DataType::U8:
505 {
506 const int16x8_t b = vdupq_n_s16(-static_cast<int16_t>(_shift));
507
508 /* Down-conversion U16 -> U8 */
509 if(ConvertPolicy::SATURATE == _policy)
510 {
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100511 execute_window_loop(window, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100512 {
513 const uint16x8x2_t texels =
514 {
515 {
516 vqshlq_u16(vld1q_u16(reinterpret_cast<uint16_t *>(input.ptr())), b),
517 vqshlq_u16(vld1q_u16(reinterpret_cast<uint16_t *>(input.ptr()) + 8), b)
518 }
519 };
520
521 vst1q_u8(output.ptr(), vcombine_u8(vqmovn_u16(texels.val[0]), vqmovn_u16(texels.val[1])));
522 },
523 input, output);
524 }
525 else
526 {
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100527 execute_window_loop(window, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100528 {
529 const uint16x8x2_t texels =
530 {
531 {
532 vshlq_u16(vld1q_u16(reinterpret_cast<uint16_t *>(input.ptr())), b),
533 vshlq_u16(vld1q_u16(reinterpret_cast<uint16_t *>(input.ptr()) + 8), b)
534 }
535 };
536
537 vst1q_u8(output.ptr(), vcombine_u8(vmovn_u16(texels.val[0]), vmovn_u16(texels.val[1])));
538 },
539 input, output);
540 }
541 break;
542 }
543 case DataType::U32:
544 {
545 const int32x4_t b = vdupq_n_s32(_shift);
546
547 /* Up-conversion U16 -> U32 */
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100548 execute_window_loop(window, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100549 {
550 const uint16x8x2_t texels =
551 {
552 {
553 vld1q_u16(reinterpret_cast<uint16_t *>(input.ptr())),
554 vld1q_u16(reinterpret_cast<uint16_t *>(input.ptr()) + 8)
555 }
556 };
557
558 vst1q_u32(reinterpret_cast<uint32_t *>(output.ptr()), vshlq_u32(vmovl_u16(vget_low_u16(texels.val[0])), b));
559 vst1q_u32(reinterpret_cast<uint32_t *>(output.ptr()) + 4, vshlq_u32(vmovl_u16(vget_high_u16(texels.val[0])), b));
560 vst1q_u32(reinterpret_cast<uint32_t *>(output.ptr()) + 8, vshlq_u32(vmovl_u16(vget_low_u16(texels.val[1])), b));
561 vst1q_u32(reinterpret_cast<uint32_t *>(output.ptr()) + 12, vshlq_u32(vmovl_u16(vget_high_u16(texels.val[1])), b));
562 },
563 input, output);
564 break;
565 }
566 default:
567 ARM_COMPUTE_ERROR("Output data type not supported");
568 }
569 break;
570 }
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100571#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
572 case DataType::F16:
573 switch(_output->info()->data_type())
574 {
Luca Foschianidaa3aba2020-01-08 15:55:08 +0000575 case DataType::QASYMM8_SIGNED:
576 {
577 const float16x8_t scale = vdupq_n_f16(1 << _shift);
578
579 /* Up-conversion F16 -> QASYMM8_SIGNED */
580 execute_window_loop(window, [&](const Coordinates &)
581 {
582 const float16x8x2_t texels =
583 {
584 {
585 vmulq_f16(vld1q_f16(reinterpret_cast<float16_t *>(input.ptr())), scale),
586 vmulq_f16(vld1q_f16(reinterpret_cast<float16_t *>(input.ptr()) + 8), scale),
587 }
588 };
589
590 vst1q_s8(reinterpret_cast<int8_t *>(output.ptr()), vcombine_s8(vqmovn_s16(vcvtq_s16_f16(texels.val[0])), vqmovn_s16(vcvtq_s16_f16(texels.val[1]))));
591 },
592 input, output);
593 break;
594 }
Michalis Spyroue2588182018-12-13 18:31:18 +0000595 case DataType::QASYMM8:
Usama Arif9e631c22019-05-14 17:10:40 +0100596 case DataType::U8:
Michalis Spyroue2588182018-12-13 18:31:18 +0000597 {
Usama Arif9e631c22019-05-14 17:10:40 +0100598 const float16x8_t scale = vdupq_n_f16(1 << _shift);
Michalis Spyroue2588182018-12-13 18:31:18 +0000599
Usama Arif9e631c22019-05-14 17:10:40 +0100600 /* Up-conversion F16 -> U8 */
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100601 execute_window_loop(window, [&](const Coordinates &)
Michalis Spyroue2588182018-12-13 18:31:18 +0000602 {
603 const float16x8x2_t texels =
604 {
605 {
606 vmulq_f16(vld1q_f16(reinterpret_cast<float16_t *>(input.ptr())), scale),
607 vmulq_f16(vld1q_f16(reinterpret_cast<float16_t *>(input.ptr()) + 8), scale),
608 }
609 };
610
Usama Arif9e631c22019-05-14 17:10:40 +0100611 vst1q_u8(reinterpret_cast<uint8_t *>(output.ptr()), vcombine_u8(vqmovun_s16(vcvtq_s16_f16(texels.val[0])), vqmovun_s16(vcvtq_s16_f16(texels.val[1]))));
Michalis Spyroue2588182018-12-13 18:31:18 +0000612 },
613 input, output);
614 break;
615 }
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100616 case DataType::F32:
617 {
618 const float32x4_t scale = vdupq_n_f32(1 << _shift);
619
620 /* Up-conversion F16 -> F32 */
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100621 execute_window_loop(window, [&](const Coordinates &)
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100622 {
623 const float16x8x2_t texels =
624 {
625 {
626 vld1q_f16(reinterpret_cast<float16_t *>(input.ptr())),
627 vld1q_f16(reinterpret_cast<float16_t *>(input.ptr()) + 8)
628 }
629 };
630
631 vst1q_f32(reinterpret_cast<float *>(output.ptr()), vmulq_f32(vcvt_f32_f16(vget_low_f16(texels.val[0])), scale));
632 vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 4, vmulq_f32(vcvt_f32_f16(vget_high_f16(texels.val[0])), scale));
633 vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 8, vmulq_f32(vcvt_f32_f16(vget_low_f16(texels.val[1])), scale));
634 vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 12, vmulq_f32(vcvt_f32_f16(vget_high_f16(texels.val[1])), scale));
635 },
636 input, output);
637 break;
638 }
Usama Arif9e631c22019-05-14 17:10:40 +0100639 case DataType::S32:
640 {
641 const float32x4_t scale = vdupq_n_f32(1 << _shift);
642
643 /* Up-conversion F16 -> S32 */
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100644 execute_window_loop(window, [&](const Coordinates &)
Usama Arif9e631c22019-05-14 17:10:40 +0100645 {
646 const float16x8x2_t texels =
647 {
648 {
649 vld1q_f16(reinterpret_cast<float16_t *>(input.ptr())),
650 vld1q_f16(reinterpret_cast<float16_t *>(input.ptr()) + 8)
651 }
652 };
653
654 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()), vcvtq_s32_f32(vmulq_f32(vcvt_f32_f16(vget_low_f16(texels.val[0])), scale)));
655 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 4, vcvtq_s32_f32(vmulq_f32(vcvt_f32_f16(vget_high_f16(texels.val[0])), scale)));
656 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 8, vcvtq_s32_f32(vmulq_f32(vcvt_f32_f16(vget_low_f16(texels.val[1])), scale)));
657 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 12, vcvtq_s32_f32(vmulq_f32(vcvt_f32_f16(vget_high_f16(texels.val[1])), scale)));
658 },
659 input, output);
660 break;
661 }
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100662 default:
663 ARM_COMPUTE_ERROR("Output data type not supported");
664 }
665 break;
Michalis Spyroue2588182018-12-13 18:31:18 +0000666#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100667 case DataType::F32:
668 switch(_output->info()->data_type())
669 {
Michalis Spyroue2588182018-12-13 18:31:18 +0000670#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100671 case DataType::F16:
672 {
673 const float32x4_t scale = vdupq_n_f32(1.f / (1 << _shift));
674
675 /* Down-conversion F32 -> F16 */
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100676 execute_window_loop(window, [&](const Coordinates &)
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100677 {
678 const float32x4x4_t texels =
679 {
680 {
681 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr())), scale),
682 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 4), scale),
683 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 8), scale),
684 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 12), scale)
685 }
686 };
687
688 vst1q_f16(reinterpret_cast<float16_t *>(output.ptr()), vcombine_f16(vcvt_f16_f32(texels.val[0]), vcvt_f16_f32(texels.val[1])));
689 vst1q_f16(reinterpret_cast<float16_t *>(output.ptr()) + 8, vcombine_f16(vcvt_f16_f32(texels.val[2]), vcvt_f16_f32(texels.val[3])));
690 },
691 input, output);
692 break;
693 }
Michalis Spyroue2588182018-12-13 18:31:18 +0000694#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Usama Arif9e631c22019-05-14 17:10:40 +0100695 case DataType::S32:
696 {
697 const float32x4_t scale = vdupq_n_f32(1.f / (1 << _shift));
698
699 /* Conversion F32 -> S32 */
700 execute_window_loop(window, [&](const Coordinates &)
701 {
702 const float32x4x4_t texels =
703 {
704 {
705 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr())), scale),
706 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 4), scale),
707 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 8), scale),
708 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 12), scale),
709 }
710 };
711
712 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()), vcvtq_s32_f32(texels.val[0]));
713 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 4, vcvtq_s32_f32(texels.val[1]));
714 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 8, vcvtq_s32_f32(texels.val[2]));
715 vst1q_s32(reinterpret_cast<int32_t *>(output.ptr()) + 12, vcvtq_s32_f32(texels.val[3]));
716 },
717 input, output);
718 break;
719 }
720 case DataType::QASYMM8:
721 case DataType::U8:
722 {
723 const float32x4_t scale = vdupq_n_f32(1.f / (1 << _shift));
724
725 /* Down-conversion F32 -> U8 */
726 execute_window_loop(window, [&](const Coordinates &)
727 {
728 const float32x4x4_t texels =
729 {
730 {
731 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr())), scale),
732 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 4), scale),
733 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 8), scale),
734 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 12), scale),
735 }
736 };
737
738 vst1_u8(reinterpret_cast<uint8_t *>(output.ptr()), vqmovn_u16(vcombine_u16(vqmovun_s32(vcvtq_s32_f32(texels.val[0])), vqmovun_s32(vcvtq_s32_f32(texels.val[1])))));
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100739 vst1_u8(reinterpret_cast<uint8_t *>(output.ptr()) + 8, vqmovn_u16(vcombine_u16(vqmovun_s32(vcvtq_s32_f32(texels.val[2])), vqmovun_s32(vcvtq_s32_f32(texels.val[3])))));
Usama Arif9e631c22019-05-14 17:10:40 +0100740 },
741 input, output);
742 break;
743 }
Luca Foschianidaa3aba2020-01-08 15:55:08 +0000744 case DataType::QASYMM8_SIGNED:
745 {
746 const float32x4_t scale = vdupq_n_f32(1.f / (1 << _shift));
747
748 /* Down-conversion F32 -> QASYMM8_SIGNED */
749 execute_window_loop(window, [&](const Coordinates &)
750 {
751 const float32x4x4_t texels =
752 {
753 {
754 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr())), scale),
755 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 4), scale),
756 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 8), scale),
757 vmulq_f32(vld1q_f32(reinterpret_cast<float *>(input.ptr()) + 12), scale),
758 }
759 };
760
761 vst1_s8(reinterpret_cast<int8_t *>(output.ptr()), vqmovn_s16(vcombine_s16(vqmovn_s32(vcvtq_s32_f32(texels.val[0])), vqmovn_s32(vcvtq_s32_f32(texels.val[1])))));
762 vst1_s8(reinterpret_cast<int8_t *>(output.ptr()) + 8, vqmovn_s16(vcombine_s16(vqmovn_s32(vcvtq_s32_f32(texels.val[2])), vqmovn_s32(vcvtq_s32_f32(texels.val[3])))));
763 },
764 input, output);
765 break;
766 }
Usama Arif9e631c22019-05-14 17:10:40 +0100767
Usama Arif9e631c22019-05-14 17:10:40 +0100768 default:
769 ARM_COMPUTE_ERROR("Output data type not supported");
770 }
771 break;
772
773 case DataType::S32:
774 switch(_output->info()->data_type())
775 {
776#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
777 case DataType::F16:
778 {
779 const float32x4_t scale = vdupq_n_f32(1.f / (1 << _shift));
780
781 /* Down-conversion S32 -> F16 */
782 execute_window_loop(window, [&](const Coordinates &)
783 {
784 const float32x4x4_t texels =
785 {
786 {
787 vmulq_f32(vcvtq_f32_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()))), scale),
788 vmulq_f32(vcvtq_f32_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 4)), scale),
789 vmulq_f32(vcvtq_f32_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 8)), scale),
790 vmulq_f32(vcvtq_f32_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 12)), scale)
791 }
792 };
793
794 vst1q_f16(reinterpret_cast<float16_t *>(output.ptr()), vcombine_f16(vcvt_f16_f32(texels.val[0]), vcvt_f16_f32(texels.val[1])));
795 vst1q_f16(reinterpret_cast<float16_t *>(output.ptr()) + 8, vcombine_f16(vcvt_f16_f32(texels.val[2]), vcvt_f16_f32(texels.val[3])));
796 },
797 input, output);
798 break;
799 }
800#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
801 case DataType::F32:
802 {
803 const int32x4_t scale = vdupq_n_s32(1.f / (1 << _shift));
804
805 /* Conversion S32 -> F32 */
806 execute_window_loop(window, [&](const Coordinates &)
807 {
808 const int32x4x4_t texels =
809 {
810 {
811 vmulq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr())), scale),
812 vmulq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 4), scale),
813 vmulq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 8), scale),
814 vmulq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 12), scale),
815 }
816 };
817
818 vst1q_f32(reinterpret_cast<float *>(output.ptr()), vcvtq_f32_s32(texels.val[0]));
819 vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 4, vcvtq_f32_s32(texels.val[1]));
820 vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 8, vcvtq_f32_s32(texels.val[2]));
821 vst1q_f32(reinterpret_cast<float *>(output.ptr()) + 12, vcvtq_f32_s32(texels.val[3]));
822 },
823 input, output);
824 break;
825 }
Luca Foschianidaa3aba2020-01-08 15:55:08 +0000826 case DataType::QASYMM8_SIGNED:
827 {
828 const int32x4_t b = vdupq_n_s32(-static_cast<int32_t>(_shift));
829
830 /* Down-conversion S32 -> QASYMM8_SIGNED */
831 if(ConvertPolicy::SATURATE == _policy)
832 {
833 execute_window_loop(window, [&](const Coordinates &)
834 {
835 const int32x4x4_t texels =
836 {
837 {
838 vqshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr())), b),
839 vqshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 4), b),
840 vqshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 8), b),
841 vqshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 12), b)
842 }
843 };
844 vst1_s8(reinterpret_cast<int8_t *>(output.ptr()), vqmovn_s16(vcombine_s16(vqmovn_s32(texels.val[0]), vqmovn_s32(texels.val[1]))));
845 vst1_s8(reinterpret_cast<int8_t *>(output.ptr()) + 8, vqmovn_s16(vcombine_s16(vqmovn_s32(texels.val[2]), vqmovn_s32(texels.val[3]))));
846 },
847 input, output);
848 }
849 else
850 {
851 execute_window_loop(window, [&](const Coordinates &)
852 {
853 const int32x4x4_t texels =
854 {
855 {
856 vshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr())), b),
857 vshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 4), b),
858 vshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 8), b),
859 vshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 12), b)
860 }
861 };
862
863 vst1_s8(reinterpret_cast<int8_t *>(output.ptr()), vmovn_s16(vcombine_s16(vmovn_s32(texels.val[0]), vmovn_s32(texels.val[1]))));
864 vst1_s8(reinterpret_cast<int8_t *>(output.ptr()) + 8, vmovn_s16(vcombine_s16(vmovn_s32(texels.val[2]), vmovn_s32(texels.val[3]))));
865 },
866 input, output);
867 }
868 break;
869 }
Usama Arif9e631c22019-05-14 17:10:40 +0100870 case DataType::QASYMM8:
871 case DataType::U8:
872 {
873 const int32x4_t b = vdupq_n_s32(-static_cast<int32_t>(_shift));
874
875 /* Down-conversion S32 -> U8 */
876 if(ConvertPolicy::SATURATE == _policy)
877 {
878 execute_window_loop(window, [&](const Coordinates &)
879 {
880 const int32x4x4_t texels =
881 {
882 {
883 vqshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr())), b),
884 vqshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 4), b),
885 vqshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 8), b),
886 vqshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 12), b)
887 }
888 };
Usama Arifc5c750d2019-05-24 11:13:20 +0100889 vst1_u8(reinterpret_cast<uint8_t *>(output.ptr()), vqmovn_u16(vcombine_u16(vqmovun_s32(texels.val[0]), vqmovun_s32(texels.val[1]))));
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100890 vst1_u8(reinterpret_cast<uint8_t *>(output.ptr()) + 8, vqmovn_u16(vcombine_u16(vqmovun_s32(texels.val[2]), vqmovun_s32(texels.val[3]))));
Usama Arif9e631c22019-05-14 17:10:40 +0100891 },
892 input, output);
893 }
894 else
895 {
896 execute_window_loop(window, [&](const Coordinates &)
897 {
898 const int32x4x4_t texels =
899 {
900 {
901 vshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr())), b),
902 vshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 4), b),
903 vshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 8), b),
904 vshlq_s32(vld1q_s32(reinterpret_cast<int32_t *>(input.ptr()) + 12), b)
905 }
906 };
907
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100908 vst1_u8(reinterpret_cast<uint8_t *>(output.ptr()), vmovn_u16(vcombine_u16(vmovn_u32(vreinterpretq_u32_s32(texels.val[0])), vmovn_u32(vreinterpretq_u32_s32(texels.val[1])))));
909 vst1_u8(reinterpret_cast<uint8_t *>(output.ptr()) + 8, vmovn_u16(vcombine_u16(vmovn_u32(vreinterpretq_u32_s32(texels.val[2])), vmovn_u32(vreinterpretq_u32_s32(texels.val[3])))));
Usama Arif9e631c22019-05-14 17:10:40 +0100910 },
911 input, output);
912 }
913 break;
914 }
Michele Di Giorgio3e570db2018-08-24 18:28:48 +0100915 default:
916 ARM_COMPUTE_ERROR("Output data type not supported");
917 }
918 break;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100919 default:
920 ARM_COMPUTE_ERROR("Not supported");
921 }
922}