Marat Dukhan | 80fc932 | 2019-09-29 21:06:36 -0700 | [diff] [blame^] | 1 | // Copyright (c) Facebook, Inc. and its affiliates. |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Copyright 2019 Google LLC |
| 5 | // |
| 6 | // This source code is licensed under the BSD-style license found in the |
| 7 | // LICENSE file in the root directory of this source tree. |
XNNPACK Team | b455b12 | 2019-09-27 18:10:33 -0700 | [diff] [blame] | 8 | |
| 9 | #include <assert.h> |
| 10 | |
| 11 | #include <arm_neon.h> |
| 12 | |
| 13 | #include <xnnpack/igemm.h> |
| 14 | |
| 15 | |
| 16 | void xnn_q8_igemm_ukernel_4x8__neon( |
| 17 | size_t mr, |
| 18 | size_t nc, |
| 19 | size_t kc, |
| 20 | size_t ks, |
| 21 | const uint8_t** restrict a, |
| 22 | const void* restrict w, |
| 23 | uint8_t* restrict c, |
| 24 | size_t cm_stride, |
| 25 | size_t cn_stride, |
| 26 | size_t a_offset, |
| 27 | const uint8_t* zero, |
| 28 | const union xnn_q8_gemm_params params[restrict static 1]) |
| 29 | { |
| 30 | assert(mr != 0); |
| 31 | assert(mr <= 4); |
| 32 | assert(nc != 0); |
| 33 | assert(kc != 0); |
| 34 | assert(ks != 0); |
| 35 | assert(ks % (4 * sizeof(void*)) == 0); |
| 36 | |
| 37 | uint8_t* c0 = c; |
| 38 | uint8_t* c1 = (uint8_t*) ((uintptr_t) c0 + cm_stride); |
| 39 | if XNN_UNPREDICTABLE(mr < 2) { |
| 40 | c1 = c0; |
| 41 | } |
| 42 | uint8_t* c2 = (uint8_t*) ((uintptr_t) c1 + cm_stride); |
| 43 | if XNN_UNPREDICTABLE(mr <= 2) { |
| 44 | c2 = c1; |
| 45 | } |
| 46 | uint8_t* c3 = (uint8_t*) ((uintptr_t) c2 + cm_stride); |
| 47 | if (mr != 4) { |
| 48 | c3 = c2; |
| 49 | } |
| 50 | |
| 51 | const uint8x8_t vb_zero_point = vld1_dup_u8((const uint8_t*) ¶ms->neon.kernel_zero_point); |
| 52 | |
| 53 | do { |
| 54 | int32x4_t vacc0x0123 = vld1q_s32(w); w = (void*) ((uintptr_t) w + sizeof(int32x4_t)); |
| 55 | int32x4_t vacc0x4567 = vld1q_s32(w); w = (void*) ((uintptr_t) w + sizeof(int32x4_t)); |
| 56 | int32x4_t vacc1x0123 = vacc0x0123; |
| 57 | int32x4_t vacc1x4567 = vacc0x4567; |
| 58 | int32x4_t vacc2x0123 = vacc0x0123; |
| 59 | int32x4_t vacc2x4567 = vacc0x4567; |
| 60 | int32x4_t vacc3x0123 = vacc0x0123; |
| 61 | int32x4_t vacc3x4567 = vacc0x4567; |
| 62 | |
| 63 | size_t p = ks; |
| 64 | do { |
| 65 | const uint8_t* restrict a0 = a[0]; |
| 66 | if XNN_UNPREDICTABLE(a0 != zero) { |
| 67 | a0 = (const uint8_t*) ((uintptr_t) a0 + a_offset); |
| 68 | } |
| 69 | const uint8_t* restrict a1 = a[1]; |
| 70 | if XNN_UNPREDICTABLE(a1 != zero) { |
| 71 | a1 = (const uint8_t*) ((uintptr_t) a1 + a_offset); |
| 72 | } |
| 73 | const uint8_t* restrict a2 = a[2]; |
| 74 | if XNN_UNPREDICTABLE(a2 != zero) { |
| 75 | a2 = (const uint8_t*) ((uintptr_t) a2 + a_offset); |
| 76 | } |
| 77 | const uint8_t* restrict a3 = a[3]; |
| 78 | if XNN_UNPREDICTABLE(a3 != zero) { |
| 79 | a3 = (const uint8_t*) ((uintptr_t) a3 + a_offset); |
| 80 | } |
| 81 | a += 4; |
| 82 | |
| 83 | size_t k = kc; |
| 84 | while (k >= 8 * sizeof(uint8_t)) { |
| 85 | const uint8x8_t va0 = vld1_u8(a0); a0 += 8; |
| 86 | const uint8x8_t va1 = vld1_u8(a1); a1 += 8; |
| 87 | const uint8x8_t va2 = vld1_u8(a2); a2 += 8; |
| 88 | const uint8x8_t va3 = vld1_u8(a3); a3 += 8; |
| 89 | const int16x8_t vxa0 = vreinterpretq_s16_u16(vmovl_u8(va0)); |
| 90 | const int16x8_t vxa1 = vreinterpretq_s16_u16(vmovl_u8(va1)); |
| 91 | const int16x8_t vxa2 = vreinterpretq_s16_u16(vmovl_u8(va2)); |
| 92 | const int16x8_t vxa3 = vreinterpretq_s16_u16(vmovl_u8(va3)); |
| 93 | |
| 94 | { |
| 95 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 96 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 97 | |
| 98 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa0), 0); |
| 99 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa0), 0); |
| 100 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa1), 0); |
| 101 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa1), 0); |
| 102 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa2), 0); |
| 103 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa2), 0); |
| 104 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa3), 0); |
| 105 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa3), 0); |
| 106 | } |
| 107 | |
| 108 | { |
| 109 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 110 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 111 | |
| 112 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa0), 1); |
| 113 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa0), 1); |
| 114 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa1), 1); |
| 115 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa1), 1); |
| 116 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa2), 1); |
| 117 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa2), 1); |
| 118 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa3), 1); |
| 119 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa3), 1); |
| 120 | } |
| 121 | |
| 122 | { |
| 123 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 124 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 125 | |
| 126 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa0), 2); |
| 127 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa0), 2); |
| 128 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa1), 2); |
| 129 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa1), 2); |
| 130 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa2), 2); |
| 131 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa2), 2); |
| 132 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa3), 2); |
| 133 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa3), 2); |
| 134 | } |
| 135 | |
| 136 | { |
| 137 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 138 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 139 | |
| 140 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa0), 3); |
| 141 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa0), 3); |
| 142 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa1), 3); |
| 143 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa1), 3); |
| 144 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa2), 3); |
| 145 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa2), 3); |
| 146 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa3), 3); |
| 147 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa3), 3); |
| 148 | } |
| 149 | |
| 150 | { |
| 151 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 152 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 153 | |
| 154 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa0), 0); |
| 155 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa0), 0); |
| 156 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa1), 0); |
| 157 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa1), 0); |
| 158 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa2), 0); |
| 159 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa2), 0); |
| 160 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa3), 0); |
| 161 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa3), 0); |
| 162 | } |
| 163 | |
| 164 | { |
| 165 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 166 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 167 | |
| 168 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa0), 1); |
| 169 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa0), 1); |
| 170 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa1), 1); |
| 171 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa1), 1); |
| 172 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa2), 1); |
| 173 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa2), 1); |
| 174 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa3), 1); |
| 175 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa3), 1); |
| 176 | } |
| 177 | |
| 178 | { |
| 179 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 180 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 181 | |
| 182 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa0), 2); |
| 183 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa0), 2); |
| 184 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa1), 2); |
| 185 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa1), 2); |
| 186 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa2), 2); |
| 187 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa2), 2); |
| 188 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa3), 2); |
| 189 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa3), 2); |
| 190 | } |
| 191 | |
| 192 | { |
| 193 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 194 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 195 | |
| 196 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa0), 3); |
| 197 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa0), 3); |
| 198 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa1), 3); |
| 199 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa1), 3); |
| 200 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa2), 3); |
| 201 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa2), 3); |
| 202 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa3), 3); |
| 203 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa3), 3); |
| 204 | } |
| 205 | |
| 206 | k -= 8 * sizeof(uint8_t); |
| 207 | } |
| 208 | if (k != 0) { |
| 209 | const uint8x8_t va0 = vld1_u8(a0); |
| 210 | const uint8x8_t va1 = vld1_u8(a1); |
| 211 | const uint8x8_t va2 = vld1_u8(a2); |
| 212 | const uint8x8_t va3 = vld1_u8(a3); |
| 213 | const int16x8_t vxa0 = vreinterpretq_s16_u16(vmovl_u8(va0)); |
| 214 | const int16x8_t vxa1 = vreinterpretq_s16_u16(vmovl_u8(va1)); |
| 215 | const int16x8_t vxa2 = vreinterpretq_s16_u16(vmovl_u8(va2)); |
| 216 | const int16x8_t vxa3 = vreinterpretq_s16_u16(vmovl_u8(va3)); |
| 217 | |
| 218 | { |
| 219 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 220 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 221 | |
| 222 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa0), 0); |
| 223 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa0), 0); |
| 224 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa1), 0); |
| 225 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa1), 0); |
| 226 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa2), 0); |
| 227 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa2), 0); |
| 228 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa3), 0); |
| 229 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa3), 0); |
| 230 | } |
| 231 | |
| 232 | if (k >= 2 * sizeof(uint8_t)) { |
| 233 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 234 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 235 | |
| 236 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa0), 1); |
| 237 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa0), 1); |
| 238 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa1), 1); |
| 239 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa1), 1); |
| 240 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa2), 1); |
| 241 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa2), 1); |
| 242 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa3), 1); |
| 243 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa3), 1); |
| 244 | |
| 245 | if (k > 2 * sizeof(uint8_t)) { |
| 246 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 247 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 248 | |
| 249 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa0), 2); |
| 250 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa0), 2); |
| 251 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa1), 2); |
| 252 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa1), 2); |
| 253 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa2), 2); |
| 254 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa2), 2); |
| 255 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa3), 2); |
| 256 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa3), 2); |
| 257 | |
| 258 | if (k >= 4 * sizeof(uint8_t)) { |
| 259 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 260 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 261 | |
| 262 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa0), 3); |
| 263 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa0), 3); |
| 264 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa1), 3); |
| 265 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa1), 3); |
| 266 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa2), 3); |
| 267 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa2), 3); |
| 268 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_low_s16(vxa3), 3); |
| 269 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_low_s16(vxa3), 3); |
| 270 | |
| 271 | if (k > 4 * sizeof(uint8_t)) { |
| 272 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 273 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 274 | |
| 275 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa0), 0); |
| 276 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa0), 0); |
| 277 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa1), 0); |
| 278 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa1), 0); |
| 279 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa2), 0); |
| 280 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa2), 0); |
| 281 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa3), 0); |
| 282 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa3), 0); |
| 283 | |
| 284 | if (k >= 6 * sizeof(uint8_t)) { |
| 285 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 286 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 287 | |
| 288 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa0), 1); |
| 289 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa0), 1); |
| 290 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa1), 1); |
| 291 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa1), 1); |
| 292 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa2), 1); |
| 293 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa2), 1); |
| 294 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa3), 1); |
| 295 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa3), 1); |
| 296 | |
| 297 | if (k > 6 * sizeof(uint8_t)) { |
| 298 | const uint8x8_t vb01234567 = vld1_u8(w); w = (void*) ((uintptr_t) w + sizeof(uint8x8_t)); |
| 299 | const int16x8_t vxb01234567 = vreinterpretq_s16_u16(vsubl_u8(vb01234567, vb_zero_point)); |
| 300 | |
| 301 | vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa0), 2); |
| 302 | vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa0), 2); |
| 303 | vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa1), 2); |
| 304 | vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa1), 2); |
| 305 | vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa2), 2); |
| 306 | vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa2), 2); |
| 307 | vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567), vget_high_s16(vxa3), 2); |
| 308 | vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567), vget_high_s16(vxa3), 2); |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | p -= 4 * sizeof(void*); |
| 317 | } while (p != 0); |
| 318 | |
| 319 | const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->neon.multiplier); |
| 320 | vacc0x0123 = vqrdmulhq_s32(vacc0x0123, vmultiplier); |
| 321 | vacc0x4567 = vqrdmulhq_s32(vacc0x4567, vmultiplier); |
| 322 | vacc1x0123 = vqrdmulhq_s32(vacc1x0123, vmultiplier); |
| 323 | vacc1x4567 = vqrdmulhq_s32(vacc1x4567, vmultiplier); |
| 324 | vacc2x0123 = vqrdmulhq_s32(vacc2x0123, vmultiplier); |
| 325 | vacc2x4567 = vqrdmulhq_s32(vacc2x4567, vmultiplier); |
| 326 | vacc3x0123 = vqrdmulhq_s32(vacc3x0123, vmultiplier); |
| 327 | vacc3x4567 = vqrdmulhq_s32(vacc3x4567, vmultiplier); |
| 328 | |
| 329 | const int32x4_t vright_shift = vld1q_dup_s32(¶ms->neon.right_shift); |
| 330 | const int32x4_t vzero_shift_mask = vreinterpretq_s32_u32(vceqq_s32(vright_shift, vmovq_n_s32(0))); |
| 331 | vacc0x0123 = vsraq_n_s32(vacc0x0123, vbicq_s32(vacc0x0123, vzero_shift_mask), 31); |
| 332 | vacc0x4567 = vsraq_n_s32(vacc0x4567, vbicq_s32(vacc0x4567, vzero_shift_mask), 31); |
| 333 | vacc1x0123 = vsraq_n_s32(vacc1x0123, vbicq_s32(vacc1x0123, vzero_shift_mask), 31); |
| 334 | vacc1x4567 = vsraq_n_s32(vacc1x4567, vbicq_s32(vacc1x4567, vzero_shift_mask), 31); |
| 335 | vacc2x0123 = vsraq_n_s32(vacc2x0123, vbicq_s32(vacc2x0123, vzero_shift_mask), 31); |
| 336 | vacc2x4567 = vsraq_n_s32(vacc2x4567, vbicq_s32(vacc2x4567, vzero_shift_mask), 31); |
| 337 | vacc3x0123 = vsraq_n_s32(vacc3x0123, vbicq_s32(vacc3x0123, vzero_shift_mask), 31); |
| 338 | vacc3x4567 = vsraq_n_s32(vacc3x4567, vbicq_s32(vacc3x4567, vzero_shift_mask), 31); |
| 339 | |
| 340 | vacc0x0123 = vrshlq_s32(vacc0x0123, vright_shift); |
| 341 | vacc0x4567 = vrshlq_s32(vacc0x4567, vright_shift); |
| 342 | vacc1x0123 = vrshlq_s32(vacc1x0123, vright_shift); |
| 343 | vacc1x4567 = vrshlq_s32(vacc1x4567, vright_shift); |
| 344 | vacc2x0123 = vrshlq_s32(vacc2x0123, vright_shift); |
| 345 | vacc2x4567 = vrshlq_s32(vacc2x4567, vright_shift); |
| 346 | vacc3x0123 = vrshlq_s32(vacc3x0123, vright_shift); |
| 347 | vacc3x4567 = vrshlq_s32(vacc3x4567, vright_shift); |
| 348 | |
| 349 | const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->neon.output_zero_point); |
| 350 | #ifdef __aarch64__ |
| 351 | const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); |
| 352 | const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point); |
| 353 | const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point); |
| 354 | const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point); |
| 355 | |
| 356 | uint8x16_t vout0x01234567_1x01234567 = vqmovun_high_s16(vqmovun_s16(vacc0x01234567), vacc1x01234567); |
| 357 | uint8x16_t vout2x01234567_3x01234567 = vqmovun_high_s16(vqmovun_s16(vacc2x01234567), vacc3x01234567); |
| 358 | #else |
| 359 | const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); |
| 360 | const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point); |
| 361 | const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point); |
| 362 | const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point); |
| 363 | |
| 364 | uint8x16_t vout0x01234567_1x01234567 = vcombine_u8(vqmovun_s16(vacc0x01234567), vqmovun_s16(vacc1x01234567)); |
| 365 | uint8x16_t vout2x01234567_3x01234567 = vcombine_u8(vqmovun_s16(vacc2x01234567), vqmovun_s16(vacc3x01234567)); |
| 366 | #endif |
| 367 | const uint8x16_t voutput_min = vld1q_dup_u8(¶ms->neon.output_min); |
| 368 | const uint8x16_t voutput_max = vld1q_dup_u8(¶ms->neon.output_max); |
| 369 | |
| 370 | vout0x01234567_1x01234567 = vmaxq_u8(vout0x01234567_1x01234567, voutput_min); |
| 371 | vout2x01234567_3x01234567 = vmaxq_u8(vout2x01234567_3x01234567, voutput_min); |
| 372 | vout0x01234567_1x01234567 = vminq_u8(vout0x01234567_1x01234567, voutput_max); |
| 373 | vout2x01234567_3x01234567 = vminq_u8(vout2x01234567_3x01234567, voutput_max); |
| 374 | |
| 375 | if XNN_LIKELY(nc >= 8) { |
| 376 | vst1_u8(c3, vget_high_u8(vout2x01234567_3x01234567)); c3 += cn_stride; |
| 377 | vst1_u8(c2, vget_low_u8(vout2x01234567_3x01234567)); c2 += cn_stride; |
| 378 | vst1_u8(c1, vget_high_u8(vout0x01234567_1x01234567)); c1 += cn_stride; |
| 379 | vst1_u8(c0, vget_low_u8(vout0x01234567_1x01234567)); c0 += cn_stride; |
| 380 | |
| 381 | a = (const uint8_t**restrict) ((uintptr_t) a - ks); |
| 382 | nc -= 8; |
| 383 | } else { |
| 384 | if (nc & 4) { |
| 385 | vst1q_lane_u32(__builtin_assume_aligned(c3, 1), vreinterpretq_u32_u8(vout2x01234567_3x01234567), 2); c3 += 4; |
| 386 | vst1q_lane_u32(__builtin_assume_aligned(c2, 1), vreinterpretq_u32_u8(vout2x01234567_3x01234567), 0); c2 += 4; |
| 387 | vst1q_lane_u32(__builtin_assume_aligned(c1, 1), vreinterpretq_u32_u8(vout0x01234567_1x01234567), 2); c1 += 4; |
| 388 | vst1q_lane_u32(__builtin_assume_aligned(c0, 1), vreinterpretq_u32_u8(vout0x01234567_1x01234567), 0); c0 += 4; |
| 389 | vout0x01234567_1x01234567 = vextq_u8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); |
| 390 | vout2x01234567_3x01234567 = vextq_u8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4); |
| 391 | } |
| 392 | if (nc & 2) { |
| 393 | vst1q_lane_u16(__builtin_assume_aligned(c3, 1), vreinterpretq_u16_u8(vout2x01234567_3x01234567), 4); c3 += 2; |
| 394 | vst1q_lane_u16(__builtin_assume_aligned(c2, 1), vreinterpretq_u16_u8(vout2x01234567_3x01234567), 0); c2 += 2; |
| 395 | vst1q_lane_u16(__builtin_assume_aligned(c1, 1), vreinterpretq_u16_u8(vout0x01234567_1x01234567), 4); c1 += 2; |
| 396 | vst1q_lane_u16(__builtin_assume_aligned(c0, 1), vreinterpretq_u16_u8(vout0x01234567_1x01234567), 0); c0 += 2; |
| 397 | vout0x01234567_1x01234567 = vextq_u8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); |
| 398 | vout2x01234567_3x01234567 = vextq_u8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2); |
| 399 | } |
| 400 | if (nc & 1) { |
| 401 | vst1q_lane_u8(c3, vout2x01234567_3x01234567, 8); |
| 402 | vst1q_lane_u8(c2, vout2x01234567_3x01234567, 0); |
| 403 | vst1q_lane_u8(c1, vout0x01234567_1x01234567, 8); |
| 404 | vst1q_lane_u8(c0, vout0x01234567_1x01234567, 0); |
| 405 | } |
| 406 | |
| 407 | nc = 0; |
| 408 | } |
| 409 | } while (nc != 0); |
| 410 | } |