Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, 2017 ARM Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #include "arm_compute/core/NEON/kernels/NEGEMMLowpMatrixMultiplyKernel.h" |
| 25 | |
| 26 | #include "arm_compute/core/Error.h" |
| 27 | #include "arm_compute/core/Helpers.h" |
| 28 | #include "arm_compute/core/ITensor.h" |
| 29 | #include "arm_compute/core/TensorInfo.h" |
| 30 | #include "arm_compute/core/Types.h" |
| 31 | #include "arm_compute/core/Utils.h" |
| 32 | #include "arm_compute/core/Validate.h" |
| 33 | #include "arm_compute/core/Window.h" |
| 34 | |
| 35 | #include <arm_neon.h> |
| 36 | #include <cstddef> |
| 37 | #include <cstdint> |
| 38 | #include <tuple> |
| 39 | |
| 40 | using namespace arm_compute; |
| 41 | |
| 42 | namespace arm_compute |
| 43 | { |
| 44 | class Coordinates; |
| 45 | } // namespace arm_compute |
| 46 | |
| 47 | NEGEMMLowpMatrixMultiplyKernel::NEGEMMLowpMatrixMultiplyKernel() |
| 48 | : _input0(nullptr), _input1(nullptr), _output(nullptr), _a_offset(0), _b_offset(0), _output_offset(0), _output_mult_int(0), _shift(0) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | void NEGEMMLowpMatrixMultiplyKernel::configure(const ITensor *input0, const ITensor *input1, ITensor *output, |
| 53 | int32_t a_offset, int32_t b_offset, int32_t output_offset, int32_t output_mult_int, int32_t shift) |
| 54 | { |
| 55 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input0, 1, DataType::U8); |
| 56 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input1, 1, DataType::U8); |
| 57 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U8); |
| 58 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input0, input1, output); |
| 59 | |
| 60 | _input0 = input0; |
| 61 | _input1 = input1; |
| 62 | _output = output; |
| 63 | _a_offset = a_offset; |
| 64 | _b_offset = b_offset; |
| 65 | _output_offset = output_offset; |
| 66 | _output_mult_int = output_mult_int; |
| 67 | _shift = shift; |
| 68 | |
| 69 | constexpr unsigned int num_elems_processed_per_iteration_x = 16; |
| 70 | constexpr unsigned int num_elems_processed_per_iteration_y = 4; |
| 71 | |
| 72 | Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration_x, num_elems_processed_per_iteration_y)); |
| 73 | |
| 74 | AccessWindowRectangle output_access(output->info(), 0, 0, num_elems_processed_per_iteration_x, num_elems_processed_per_iteration_y); |
| 75 | AccessWindowHorizontal in0_access(input0->info(), 0, num_elems_processed_per_iteration_x); |
| 76 | AccessWindowHorizontal in1_access(input1->info(), 0, num_elems_processed_per_iteration_x); |
| 77 | |
| 78 | update_window_and_padding(win, in0_access, in1_access, output_access); |
| 79 | |
| 80 | output_access.set_valid_region(win, ValidRegion(Coordinates(0, 0), output->info()->tensor_shape())); |
| 81 | INEKernel::configure(win); |
| 82 | } |
| 83 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 84 | void NEGEMMLowpMatrixMultiplyKernel::run(const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 85 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 86 | ARM_COMPUTE_UNUSED(info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 87 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 88 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 89 | |
| 90 | const size_t in_b_stride = _input1->info()->strides_in_bytes()[1]; |
| 91 | const size_t out_stride = _output->info()->strides_in_bytes()[1]; |
| 92 | |
| 93 | /* Set step_x and step_y for matrix A. Scale by a factor of 4 the Y range as the input interleaved matrix A has 4 times less the rows of the output matrix */ |
| 94 | Window win_a(window); |
| 95 | win_a.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 96 | win_a.set(Window::DimY, Window::Dimension(window.y().start() >> 2, window.y().end() >> 2, 1)); |
| 97 | |
| 98 | /* Set step_x and step_y for matrix B. Scale by a factor of 16 the X range as the input transposed matrix A has 16 times less the cols of the output matrix */ |
| 99 | Window win_b(window); |
| 100 | win_b.set(Window::DimX, Window::Dimension(window.x().start() >> 4, window.x().end() >> 4, in_b_stride)); |
| 101 | win_b.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 102 | |
| 103 | /* The step x and step y for the output matrix has been already set using in configure() */ |
| 104 | Iterator ina(_input0, win_a); |
| 105 | Iterator inb(_input1, win_b); |
| 106 | Iterator out(_output, window); |
| 107 | |
| 108 | const int32x4_t voffset_a = vdupq_n_s32(_a_offset); |
| 109 | const int32x4_t voffset_b = vdupq_n_s32(_b_offset); |
| 110 | const int32x4_t vshiftr = vdupq_n_s32(-_shift); |
| 111 | |
| 112 | const int width_b = _input1->info()->dimension(0); |
| 113 | |
| 114 | // The implementation assumes that the matrix A and Matrix B have been reshaped respectively with NEGEMMInterleave4x4 and NEGEMMTranspose1xW |
| 115 | // The reshaping of the matrices helps to have a cache friendly implementation and helps to avoid the data re-arrangements needed for computing 16x4 elements per iteration |
| 116 | // All the values needed for computing a single 4x4 block will be read from consecutive memory positions |
| 117 | execute_window_loop(window, [&](const Coordinates &) |
| 118 | { |
| 119 | const uint8_t *mtx_a0 = ina.ptr(); |
| 120 | const uint8_t *mtx_b0 = inb.ptr(); |
| 121 | |
| 122 | // Accumulators for the block 0 |
| 123 | int32x4x4_t c0 = |
| 124 | { |
| 125 | { |
| 126 | vdupq_n_s32(_output_offset), |
| 127 | vdupq_n_s32(_output_offset), |
| 128 | vdupq_n_s32(_output_offset), |
| 129 | vdupq_n_s32(_output_offset) |
| 130 | } |
| 131 | }; |
| 132 | |
| 133 | // Accumulators for the block 1 |
| 134 | int32x4x4_t c1 = |
| 135 | { |
| 136 | { |
| 137 | vdupq_n_s32(_output_offset), |
| 138 | vdupq_n_s32(_output_offset), |
| 139 | vdupq_n_s32(_output_offset), |
| 140 | vdupq_n_s32(_output_offset) |
| 141 | } |
| 142 | }; |
| 143 | |
| 144 | // Accumulators for the block 2 |
| 145 | int32x4x4_t c2 = |
| 146 | { |
| 147 | { |
| 148 | vdupq_n_s32(_output_offset), |
| 149 | vdupq_n_s32(_output_offset), |
| 150 | vdupq_n_s32(_output_offset), |
| 151 | vdupq_n_s32(_output_offset) |
| 152 | } |
| 153 | }; |
| 154 | |
| 155 | // Accumulators for the block 3 |
| 156 | int32x4x4_t c3 = |
| 157 | { |
| 158 | { |
| 159 | vdupq_n_s32(_output_offset), |
| 160 | vdupq_n_s32(_output_offset), |
| 161 | vdupq_n_s32(_output_offset), |
| 162 | vdupq_n_s32(_output_offset) |
| 163 | } |
| 164 | }; |
| 165 | |
| 166 | int k = 0; |
| 167 | // This for loop performs 4 accumulations per iteration |
| 168 | for(; k <= (width_b - 64); k += 64, mtx_a0 += 16, mtx_b0 += 64) |
| 169 | { |
| 170 | const uint8x8_t p00 = vld1_u8(mtx_a0 + 0); |
| 171 | const uint8x8_t p01 = vld1_u8(mtx_a0 + 8); |
| 172 | const uint8x8_t q00l = vld1_u8(mtx_b0 + 0); |
| 173 | const uint8x8_t q00h = vld1_u8(mtx_b0 + 8); |
| 174 | const uint8x8_t q01l = vld1_u8(mtx_b0 + 16); |
| 175 | const uint8x8_t q01h = vld1_u8(mtx_b0 + 24); |
| 176 | const uint8x8_t q02l = vld1_u8(mtx_b0 + 32); |
| 177 | const uint8x8_t q02h = vld1_u8(mtx_b0 + 40); |
| 178 | const uint8x8_t q03l = vld1_u8(mtx_b0 + 48); |
| 179 | const uint8x8_t q03h = vld1_u8(mtx_b0 + 56); |
| 180 | |
| 181 | const int32x4_t ia0l = vaddw_s16(voffset_a, vreinterpret_s16_u16(vget_low_u16(vmovl_u8(p00)))); |
| 182 | const int32x4_t ia0h = vaddw_s16(voffset_a, vreinterpret_s16_u16(vget_high_u16(vmovl_u8(p00)))); |
| 183 | const int32x4_t ia1l = vaddw_s16(voffset_a, vreinterpret_s16_u16(vget_low_u16(vmovl_u8(p01)))); |
| 184 | const int32x4_t ia1h = vaddw_s16(voffset_a, vreinterpret_s16_u16(vget_high_u16(vmovl_u8(p01)))); |
| 185 | |
| 186 | const int32x2x4_t ia0 = |
| 187 | { |
| 188 | { |
| 189 | vget_low_s32(ia0l), |
| 190 | vget_high_s32(ia0l), |
| 191 | vget_low_s32(ia0h), |
| 192 | vget_high_s32(ia0h) |
| 193 | } |
| 194 | }; |
| 195 | |
| 196 | const int32x2x4_t ia1 = |
| 197 | { |
| 198 | { |
| 199 | vget_low_s32(ia1l), |
| 200 | vget_high_s32(ia1l), |
| 201 | vget_low_s32(ia1h), |
| 202 | vget_high_s32(ia1h) |
| 203 | } |
| 204 | }; |
| 205 | |
| 206 | const int32x4x4_t ib0 = |
| 207 | { |
| 208 | { |
| 209 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_low_u16(vmovl_u8(q00l)))), |
| 210 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_high_u16(vmovl_u8(q00l)))), |
| 211 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_low_u16(vmovl_u8(q00h)))), |
| 212 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_high_u16(vmovl_u8(q00h)))) |
| 213 | } |
| 214 | }; |
| 215 | |
| 216 | const int32x4x4_t ib1 = |
| 217 | { |
| 218 | { |
| 219 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_low_u16(vmovl_u8(q01l)))), |
| 220 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_high_u16(vmovl_u8(q01l)))), |
| 221 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_low_u16(vmovl_u8(q01h)))), |
| 222 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_high_u16(vmovl_u8(q01h)))) |
| 223 | } |
| 224 | }; |
| 225 | |
| 226 | const int32x4x4_t ib2 = |
| 227 | { |
| 228 | { |
| 229 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_low_u16(vmovl_u8(q02l)))), |
| 230 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_high_u16(vmovl_u8(q02l)))), |
| 231 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_low_u16(vmovl_u8(q02h)))), |
| 232 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_high_u16(vmovl_u8(q02h)))) |
| 233 | } |
| 234 | }; |
| 235 | |
| 236 | const int32x4x4_t ib3 = |
| 237 | { |
| 238 | { |
| 239 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_low_u16(vmovl_u8(q03l)))), |
| 240 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_high_u16(vmovl_u8(q03l)))), |
| 241 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_low_u16(vmovl_u8(q03h)))), |
| 242 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_high_u16(vmovl_u8(q03h)))) |
| 243 | } |
| 244 | }; |
| 245 | |
| 246 | // 4x4 block 0 - Accumulation 0 |
| 247 | c0.val[0] = vmlaq_lane_s32(c0.val[0], ib0.val[0], ia0.val[0], 0); |
| 248 | c0.val[1] = vmlaq_lane_s32(c0.val[1], ib0.val[0], ia0.val[0], 1); |
| 249 | c0.val[2] = vmlaq_lane_s32(c0.val[2], ib0.val[0], ia0.val[1], 0); |
| 250 | c0.val[3] = vmlaq_lane_s32(c0.val[3], ib0.val[0], ia0.val[1], 1); |
| 251 | // 4x4 block 0 - Accumulation 1 |
| 252 | c0.val[0] = vmlaq_lane_s32(c0.val[0], ib1.val[0], ia0.val[2], 0); |
| 253 | c0.val[1] = vmlaq_lane_s32(c0.val[1], ib1.val[0], ia0.val[2], 1); |
| 254 | c0.val[2] = vmlaq_lane_s32(c0.val[2], ib1.val[0], ia0.val[3], 0); |
| 255 | c0.val[3] = vmlaq_lane_s32(c0.val[3], ib1.val[0], ia0.val[3], 1); |
| 256 | // 4x4 block 0 - Accumulation 2 |
| 257 | c0.val[0] = vmlaq_lane_s32(c0.val[0], ib2.val[0], ia1.val[0], 0); |
| 258 | c0.val[1] = vmlaq_lane_s32(c0.val[1], ib2.val[0], ia1.val[0], 1); |
| 259 | c0.val[2] = vmlaq_lane_s32(c0.val[2], ib2.val[0], ia1.val[1], 0); |
| 260 | c0.val[3] = vmlaq_lane_s32(c0.val[3], ib2.val[0], ia1.val[1], 1); |
| 261 | // 4x4 block 0 - Accumulation 3 |
| 262 | c0.val[0] = vmlaq_lane_s32(c0.val[0], ib3.val[0], ia1.val[2], 0); |
| 263 | c0.val[1] = vmlaq_lane_s32(c0.val[1], ib3.val[0], ia1.val[2], 1); |
| 264 | c0.val[2] = vmlaq_lane_s32(c0.val[2], ib3.val[0], ia1.val[3], 0); |
| 265 | c0.val[3] = vmlaq_lane_s32(c0.val[3], ib3.val[0], ia1.val[3], 1); |
| 266 | |
| 267 | // 4x4 block 1 - Accumulation 0 |
| 268 | c1.val[0] = vmlaq_lane_s32(c1.val[0], ib0.val[1], ia0.val[0], 0); |
| 269 | c1.val[1] = vmlaq_lane_s32(c1.val[1], ib0.val[1], ia0.val[0], 1); |
| 270 | c1.val[2] = vmlaq_lane_s32(c1.val[2], ib0.val[1], ia0.val[1], 0); |
| 271 | c1.val[3] = vmlaq_lane_s32(c1.val[3], ib0.val[1], ia0.val[1], 1); |
| 272 | // 4x4 block 1 - Accumulation 1 |
| 273 | c1.val[0] = vmlaq_lane_s32(c1.val[0], ib1.val[1], ia0.val[2], 0); |
| 274 | c1.val[1] = vmlaq_lane_s32(c1.val[1], ib1.val[1], ia0.val[2], 1); |
| 275 | c1.val[2] = vmlaq_lane_s32(c1.val[2], ib1.val[1], ia0.val[3], 0); |
| 276 | c1.val[3] = vmlaq_lane_s32(c1.val[3], ib1.val[1], ia0.val[3], 1); |
| 277 | // 4x4 block 1 - Accumulation 2 |
| 278 | c1.val[0] = vmlaq_lane_s32(c1.val[0], ib2.val[1], ia1.val[0], 0); |
| 279 | c1.val[1] = vmlaq_lane_s32(c1.val[1], ib2.val[1], ia1.val[0], 1); |
| 280 | c1.val[2] = vmlaq_lane_s32(c1.val[2], ib2.val[1], ia1.val[1], 0); |
| 281 | c1.val[3] = vmlaq_lane_s32(c1.val[3], ib2.val[1], ia1.val[1], 1); |
| 282 | // 4x4 block 1 - Accumulation 3 |
| 283 | c1.val[0] = vmlaq_lane_s32(c1.val[0], ib3.val[1], ia1.val[2], 0); |
| 284 | c1.val[1] = vmlaq_lane_s32(c1.val[1], ib3.val[1], ia1.val[2], 1); |
| 285 | c1.val[2] = vmlaq_lane_s32(c1.val[2], ib3.val[1], ia1.val[3], 0); |
| 286 | c1.val[3] = vmlaq_lane_s32(c1.val[3], ib3.val[1], ia1.val[3], 1); |
| 287 | |
| 288 | // 4x4 block 2 - Accumulation 0 |
| 289 | c2.val[0] = vmlaq_lane_s32(c2.val[0], ib0.val[2], ia0.val[0], 0); |
| 290 | c2.val[1] = vmlaq_lane_s32(c2.val[1], ib0.val[2], ia0.val[0], 1); |
| 291 | c2.val[2] = vmlaq_lane_s32(c2.val[2], ib0.val[2], ia0.val[1], 0); |
| 292 | c2.val[3] = vmlaq_lane_s32(c2.val[3], ib0.val[2], ia0.val[1], 1); |
| 293 | // 4x4 block 2 - Accumulation 1 |
| 294 | c2.val[0] = vmlaq_lane_s32(c2.val[0], ib1.val[2], ia0.val[2], 0); |
| 295 | c2.val[1] = vmlaq_lane_s32(c2.val[1], ib1.val[2], ia0.val[2], 1); |
| 296 | c2.val[2] = vmlaq_lane_s32(c2.val[2], ib1.val[2], ia0.val[3], 0); |
| 297 | c2.val[3] = vmlaq_lane_s32(c2.val[3], ib1.val[2], ia0.val[3], 1); |
| 298 | // 4x4 block 2 - Accumulation 2 |
| 299 | c2.val[0] = vmlaq_lane_s32(c2.val[0], ib2.val[2], ia1.val[0], 0); |
| 300 | c2.val[1] = vmlaq_lane_s32(c2.val[1], ib2.val[2], ia1.val[0], 1); |
| 301 | c2.val[2] = vmlaq_lane_s32(c2.val[2], ib2.val[2], ia1.val[1], 0); |
| 302 | c2.val[3] = vmlaq_lane_s32(c2.val[3], ib2.val[2], ia1.val[1], 1); |
| 303 | // 4x4 block 2 - Accumulation 3 |
| 304 | c2.val[0] = vmlaq_lane_s32(c2.val[0], ib3.val[2], ia1.val[2], 0); |
| 305 | c2.val[1] = vmlaq_lane_s32(c2.val[1], ib3.val[2], ia1.val[2], 1); |
| 306 | c2.val[2] = vmlaq_lane_s32(c2.val[2], ib3.val[2], ia1.val[3], 0); |
| 307 | c2.val[3] = vmlaq_lane_s32(c2.val[3], ib3.val[2], ia1.val[3], 1); |
| 308 | |
| 309 | // 4x4 block 3 - Accumulation 0 |
| 310 | c3.val[0] = vmlaq_lane_s32(c3.val[0], ib0.val[3], ia0.val[0], 0); |
| 311 | c3.val[1] = vmlaq_lane_s32(c3.val[1], ib0.val[3], ia0.val[0], 1); |
| 312 | c3.val[2] = vmlaq_lane_s32(c3.val[2], ib0.val[3], ia0.val[1], 0); |
| 313 | c3.val[3] = vmlaq_lane_s32(c3.val[3], ib0.val[3], ia0.val[1], 1); |
| 314 | // 4x4 block 3 - Accumulation 1 |
| 315 | c3.val[0] = vmlaq_lane_s32(c3.val[0], ib1.val[3], ia0.val[2], 0); |
| 316 | c3.val[1] = vmlaq_lane_s32(c3.val[1], ib1.val[3], ia0.val[2], 1); |
| 317 | c3.val[2] = vmlaq_lane_s32(c3.val[2], ib1.val[3], ia0.val[3], 0); |
| 318 | c3.val[3] = vmlaq_lane_s32(c3.val[3], ib1.val[3], ia0.val[3], 1); |
| 319 | // 4x4 block 3 - Accumulation 2 |
| 320 | c3.val[0] = vmlaq_lane_s32(c3.val[0], ib2.val[3], ia1.val[0], 0); |
| 321 | c3.val[1] = vmlaq_lane_s32(c3.val[1], ib2.val[3], ia1.val[0], 1); |
| 322 | c3.val[2] = vmlaq_lane_s32(c3.val[2], ib2.val[3], ia1.val[1], 0); |
| 323 | c3.val[3] = vmlaq_lane_s32(c3.val[3], ib2.val[3], ia1.val[1], 1); |
| 324 | // 4x4 block 3 - Accumulation 3 |
| 325 | c3.val[0] = vmlaq_lane_s32(c3.val[0], ib3.val[3], ia1.val[2], 0); |
| 326 | c3.val[1] = vmlaq_lane_s32(c3.val[1], ib3.val[3], ia1.val[2], 1); |
| 327 | c3.val[2] = vmlaq_lane_s32(c3.val[2], ib3.val[3], ia1.val[3], 0); |
| 328 | c3.val[3] = vmlaq_lane_s32(c3.val[3], ib3.val[3], ia1.val[3], 1); |
| 329 | } |
| 330 | |
| 331 | // This for loop handles the left-over accumulations |
| 332 | for(; k < width_b; k += 16, mtx_a0 += 4, mtx_b0 += 16) |
| 333 | { |
| 334 | const uint8x8_t p00 = vld1_u8(mtx_a0); |
| 335 | const uint8x8_t q00l = vld1_u8(mtx_b0); |
| 336 | const uint8x8_t q00h = vld1_u8(mtx_b0 + 8); |
| 337 | |
| 338 | const int32x4_t ia0 = vaddw_s16(voffset_a, vreinterpret_s16_u16(vget_low_u16(vmovl_u8(p00)))); |
| 339 | |
| 340 | const int32x2x2_t ia = |
| 341 | { |
| 342 | { |
| 343 | vget_low_s32(ia0), |
| 344 | vget_high_s32(ia0) |
| 345 | } |
| 346 | }; |
| 347 | |
| 348 | const int32x4x4_t ib0 = |
| 349 | { |
| 350 | { |
| 351 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_low_u16(vmovl_u8(q00l)))), |
| 352 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_high_u16(vmovl_u8(q00l)))), |
| 353 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_low_u16(vmovl_u8(q00h)))), |
| 354 | vaddw_s16(voffset_b, vreinterpret_s16_u16(vget_high_u16(vmovl_u8(q00h)))) |
| 355 | } |
| 356 | }; |
| 357 | |
| 358 | // 4x4 block 0 |
| 359 | c0.val[0] = vmlaq_lane_s32(c0.val[0], ib0.val[0], ia.val[0], 0); |
| 360 | c0.val[1] = vmlaq_lane_s32(c0.val[1], ib0.val[0], ia.val[0], 1); |
| 361 | c0.val[2] = vmlaq_lane_s32(c0.val[2], ib0.val[0], ia.val[1], 0); |
| 362 | c0.val[3] = vmlaq_lane_s32(c0.val[3], ib0.val[0], ia.val[1], 1); |
| 363 | |
| 364 | // 4x4 block 1 |
| 365 | c1.val[0] = vmlaq_lane_s32(c1.val[0], ib0.val[1], ia.val[0], 0); |
| 366 | c1.val[1] = vmlaq_lane_s32(c1.val[1], ib0.val[1], ia.val[0], 1); |
| 367 | c1.val[2] = vmlaq_lane_s32(c1.val[2], ib0.val[1], ia.val[1], 0); |
| 368 | c1.val[3] = vmlaq_lane_s32(c1.val[3], ib0.val[1], ia.val[1], 1); |
| 369 | |
| 370 | // 4x4 block 2 |
| 371 | c2.val[0] = vmlaq_lane_s32(c2.val[0], ib0.val[2], ia.val[0], 0); |
| 372 | c2.val[1] = vmlaq_lane_s32(c2.val[1], ib0.val[2], ia.val[0], 1); |
| 373 | c2.val[2] = vmlaq_lane_s32(c2.val[2], ib0.val[2], ia.val[1], 0); |
| 374 | c2.val[3] = vmlaq_lane_s32(c2.val[3], ib0.val[2], ia.val[1], 1); |
| 375 | |
| 376 | // 4x4 block 3 |
| 377 | c3.val[0] = vmlaq_lane_s32(c3.val[0], ib0.val[3], ia.val[0], 0); |
| 378 | c3.val[1] = vmlaq_lane_s32(c3.val[1], ib0.val[3], ia.val[0], 1); |
| 379 | c3.val[2] = vmlaq_lane_s32(c3.val[2], ib0.val[3], ia.val[1], 0); |
| 380 | c3.val[3] = vmlaq_lane_s32(c3.val[3], ib0.val[3], ia.val[1], 1); |
| 381 | } |
| 382 | |
| 383 | c0.val[0] = vshlq_s32(vmulq_n_s32(c0.val[0], _output_mult_int), vshiftr); |
| 384 | c0.val[1] = vshlq_s32(vmulq_n_s32(c0.val[1], _output_mult_int), vshiftr); |
| 385 | c0.val[2] = vshlq_s32(vmulq_n_s32(c0.val[2], _output_mult_int), vshiftr); |
| 386 | c0.val[3] = vshlq_s32(vmulq_n_s32(c0.val[3], _output_mult_int), vshiftr); |
| 387 | |
| 388 | c1.val[0] = vshlq_s32(vmulq_n_s32(c1.val[0], _output_mult_int), vshiftr); |
| 389 | c1.val[1] = vshlq_s32(vmulq_n_s32(c1.val[1], _output_mult_int), vshiftr); |
| 390 | c1.val[2] = vshlq_s32(vmulq_n_s32(c1.val[2], _output_mult_int), vshiftr); |
| 391 | c1.val[3] = vshlq_s32(vmulq_n_s32(c1.val[3], _output_mult_int), vshiftr); |
| 392 | |
| 393 | c2.val[0] = vshlq_s32(vmulq_n_s32(c2.val[0], _output_mult_int), vshiftr); |
| 394 | c2.val[1] = vshlq_s32(vmulq_n_s32(c2.val[1], _output_mult_int), vshiftr); |
| 395 | c2.val[2] = vshlq_s32(vmulq_n_s32(c2.val[2], _output_mult_int), vshiftr); |
| 396 | c2.val[3] = vshlq_s32(vmulq_n_s32(c2.val[3], _output_mult_int), vshiftr); |
| 397 | |
| 398 | c3.val[0] = vshlq_s32(vmulq_n_s32(c3.val[0], _output_mult_int), vshiftr); |
| 399 | c3.val[1] = vshlq_s32(vmulq_n_s32(c3.val[1], _output_mult_int), vshiftr); |
| 400 | c3.val[2] = vshlq_s32(vmulq_n_s32(c3.val[2], _output_mult_int), vshiftr); |
| 401 | c3.val[3] = vshlq_s32(vmulq_n_s32(c3.val[3], _output_mult_int), vshiftr); |
| 402 | |
| 403 | const uint8x16x4_t r = |
| 404 | { |
| 405 | { |
| 406 | vcombine_u8(vqmovun_s16(vcombine_s16(vqmovn_s32(c0.val[0]), vqmovn_s32(c1.val[0]))), |
| 407 | vqmovun_s16(vcombine_s16(vqmovn_s32(c2.val[0]), vqmovn_s32(c3.val[0])))), |
| 408 | vcombine_u8(vqmovun_s16(vcombine_s16(vqmovn_s32(c0.val[1]), vqmovn_s32(c1.val[1]))), |
| 409 | vqmovun_s16(vcombine_s16(vqmovn_s32(c2.val[1]), vqmovn_s32(c3.val[1])))), |
| 410 | vcombine_u8(vqmovun_s16(vcombine_s16(vqmovn_s32(c0.val[2]), vqmovn_s32(c1.val[2]))), |
| 411 | vqmovun_s16(vcombine_s16(vqmovn_s32(c2.val[2]), vqmovn_s32(c3.val[2])))), |
| 412 | vcombine_u8(vqmovun_s16(vcombine_s16(vqmovn_s32(c0.val[3]), vqmovn_s32(c1.val[3]))), |
| 413 | vqmovun_s16(vcombine_s16(vqmovn_s32(c2.val[3]), vqmovn_s32(c3.val[3])))) |
| 414 | } |
| 415 | }; |
| 416 | |
| 417 | uint8_t *const mtx_out = out.ptr(); |
| 418 | vst1q_u8(mtx_out + 0 * out_stride, r.val[0]); |
| 419 | vst1q_u8(mtx_out + 1 * out_stride, r.val[1]); |
| 420 | vst1q_u8(mtx_out + 2 * out_stride, r.val[2]); |
| 421 | vst1q_u8(mtx_out + 3 * out_stride, r.val[3]); |
| 422 | }, |
| 423 | ina, inb, out); |
| 424 | } |