Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2020 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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 | */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 24 | #include "arm_compute/core/NEON/kernels/NEDepthConvertLayerKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 25 | |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/CPP/Validate.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #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 Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 31 | #include "arm_compute/core/NEON/NEMath.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | #include "arm_compute/core/TensorInfo.h" |
| 33 | #include "arm_compute/core/Validate.h" |
| 34 | |
| 35 | #include <arm_neon.h> |
| 36 | |
| 37 | using namespace arm_compute; |
| 38 | |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 39 | namespace |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 40 | { |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 41 | Status 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 Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 47 | 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 Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 50 | ARM_COMPUTE_RETURN_ERROR_ON(shift >= 8); |
| 51 | |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 52 | 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 Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 56 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::QASYMM8 && (output->data_type() != DataType::S16 && output->data_type() != DataType::U16 |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 57 | && output->data_type() != DataType::S32 && output->data_type() != DataType::F16 && output->data_type() != DataType::F32), |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 58 | "Only data_types supported [in] QASYMM8 -> [out] U16, S16, S32, F16, F32"); |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 59 | |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 60 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::U8 && (output->data_type() != DataType::S16 && output->data_type() != DataType::U16 |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 61 | && 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 Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 63 | |
| 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 Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 67 | 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 Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 68 | "Only data_types supported [in] S16 -> [out] U8, S32"); |
| 69 | |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 70 | 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 Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 73 | "Only data_types supported [in] F16 -> [out] QASYMM8, F32, S32, U8"); |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 74 | |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 75 | 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 Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 78 | "Only data_types supported [in] F32 -> [out] QASYMM8, F16, S32, U8"); |
| 79 | |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 80 | 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 Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 83 | "Only data_types supported [in] S32 -> [out] QASYMM8, F16, F32, U8"); |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 84 | |
| 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 | |
| 94 | std::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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 109 | |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 110 | NEDepthConvertLayerKernel::NEDepthConvertLayerKernel() |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 111 | : _input(nullptr), _output(nullptr), _policy(), _shift(0) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 112 | { |
| 113 | } |
| 114 | |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 115 | void NEDepthConvertLayerKernel::configure(const ITensor *input, ITensor *output, ConvertPolicy policy, uint32_t shift) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 116 | { |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 117 | 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 Pinitas | e222941 | 2017-07-12 12:30:40 +0100 | [diff] [blame] | 121 | |
| 122 | _input = input; |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 123 | _output = output; |
Georgios Pinitas | e222941 | 2017-07-12 12:30:40 +0100 | [diff] [blame] | 124 | _policy = policy; |
| 125 | _shift = shift; |
| 126 | |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 127 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), policy, shift)); |
Georgios Pinitas | e222941 | 2017-07-12 12:30:40 +0100 | [diff] [blame] | 128 | |
| 129 | // Configure kernel window |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 130 | 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 Pinitas | e222941 | 2017-07-12 12:30:40 +0100 | [diff] [blame] | 134 | |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 135 | Status 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 141 | } |
| 142 | |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 143 | void NEDepthConvertLayerKernel::run(const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 144 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 145 | ARM_COMPUTE_UNUSED(info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 146 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Georgios Pinitas | e222941 | 2017-07-12 12:30:40 +0100 | [diff] [blame] | 147 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 148 | ARM_COMPUTE_ERROR_ON_NULLPTR(_input, _output); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 149 | 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 Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 156 | 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 Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 257 | case DataType::QASYMM8: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 258 | 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 Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 267 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 268 | { |
| 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 Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 288 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 289 | { |
| 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 Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 308 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 353 | case DataType::U16: |
| 354 | { |
| 355 | /* Up-conversion U8 -> U16 */ |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 356 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 357 | { |
| 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 Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 383 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 422 | 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 Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 429 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 430 | { |
| 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 Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 445 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 446 | { |
| 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 Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 467 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 468 | { |
| 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 Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 511 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 512 | { |
| 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 Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 527 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 528 | { |
| 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 Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 548 | execute_window_loop(window, [&](const Coordinates &) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 549 | { |
| 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 Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 571 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 572 | case DataType::F16: |
| 573 | switch(_output->info()->data_type()) |
| 574 | { |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 575 | 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 Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 595 | case DataType::QASYMM8: |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 596 | case DataType::U8: |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 597 | { |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 598 | const float16x8_t scale = vdupq_n_f16(1 << _shift); |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 599 | |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 600 | /* Up-conversion F16 -> U8 */ |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 601 | execute_window_loop(window, [&](const Coordinates &) |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 602 | { |
| 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 Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 611 | 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 Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 612 | }, |
| 613 | input, output); |
| 614 | break; |
| 615 | } |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 616 | case DataType::F32: |
| 617 | { |
| 618 | const float32x4_t scale = vdupq_n_f32(1 << _shift); |
| 619 | |
| 620 | /* Up-conversion F16 -> F32 */ |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 621 | execute_window_loop(window, [&](const Coordinates &) |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 622 | { |
| 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 Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 639 | case DataType::S32: |
| 640 | { |
| 641 | const float32x4_t scale = vdupq_n_f32(1 << _shift); |
| 642 | |
| 643 | /* Up-conversion F16 -> S32 */ |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 644 | execute_window_loop(window, [&](const Coordinates &) |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 645 | { |
| 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 Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 662 | default: |
| 663 | ARM_COMPUTE_ERROR("Output data type not supported"); |
| 664 | } |
| 665 | break; |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 666 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 667 | case DataType::F32: |
| 668 | switch(_output->info()->data_type()) |
| 669 | { |
Michalis Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 670 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 671 | case DataType::F16: |
| 672 | { |
| 673 | const float32x4_t scale = vdupq_n_f32(1.f / (1 << _shift)); |
| 674 | |
| 675 | /* Down-conversion F32 -> F16 */ |
Michalis Spyrou | a4f378d | 2019-04-26 14:54:54 +0100 | [diff] [blame] | 676 | execute_window_loop(window, [&](const Coordinates &) |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 677 | { |
| 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 Spyrou | e258818 | 2018-12-13 18:31:18 +0000 | [diff] [blame] | 694 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 695 | 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 Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 739 | 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 Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 740 | }, |
| 741 | input, output); |
| 742 | break; |
| 743 | } |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 744 | 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 Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 767 | |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 768 | 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 Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 826 | 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 Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 870 | 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 Arif | c5c750d | 2019-05-24 11:13:20 +0100 | [diff] [blame] | 889 | vst1_u8(reinterpret_cast<uint8_t *>(output.ptr()), vqmovn_u16(vcombine_u16(vqmovun_s32(texels.val[0]), vqmovun_s32(texels.val[1])))); |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 890 | vst1_u8(reinterpret_cast<uint8_t *>(output.ptr()) + 8, vqmovn_u16(vcombine_u16(vqmovun_s32(texels.val[2]), vqmovun_s32(texels.val[3])))); |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 891 | }, |
| 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 Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 908 | 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 Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 910 | }, |
| 911 | input, output); |
| 912 | } |
| 913 | break; |
| 914 | } |
Michele Di Giorgio | 3e570db | 2018-08-24 18:28:48 +0100 | [diff] [blame] | 915 | default: |
| 916 | ARM_COMPUTE_ERROR("Output data type not supported"); |
| 917 | } |
| 918 | break; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 919 | default: |
| 920 | ARM_COMPUTE_ERROR("Not supported"); |
| 921 | } |
| 922 | } |