| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/qs8-igemm/c2-neon-mull-shuffle.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2021 Google LLC |
| 6 |
// |
| 7 |
// This source code is licensed under the BSD-style license found in the |
| 8 |
// LICENSE file in the root directory of this source tree. |
| 9 |
|
| 10 |
#include <assert.h> |
| 11 |
|
| 12 |
#include <arm_neon.h> |
| 13 |
|
| 14 |
#include "xnnpack/gemm.h" |
| 15 |
#include "xnnpack/math.h" |
| 16 |
|
| 17 |
|
| 18 |
void xnn_qd8_f16_qc8w_igemm_minmax_ukernel_1x8c2s4__neonfp16arith( |
| 19 |
size_t mr, |
| 20 |
size_t nc, |
| 21 |
size_t kc, |
| 22 |
size_t ks, |
| 23 |
const int8_t** restrict a, |
| 24 |
const void* restrict w, |
| 25 |
xnn_float16* restrict c, |
| 26 |
size_t cm_stride, |
| 27 |
size_t cn_stride, |
| 28 |
size_t a_offset, |
| 29 |
const int8_t* zero, |
| 30 |
const int8_t* zero_data, |
| 31 |
const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)], |
| 32 |
const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 33 |
{ |
| 34 |
assert(mr != 0); |
| 35 |
assert(mr <= 1); |
| 36 |
assert(nc != 0); |
| 37 |
assert(kc != 0); |
| 38 |
assert(ks != 0); |
| 39 |
assert(ks % (1 * sizeof(void*)) == 0); |
| 40 |
assert(a_offset % sizeof(int8_t) == 0); |
| 41 |
assert(a != NULL); |
| 42 |
assert(w != NULL); |
| 43 |
assert(c != NULL); |
| 44 |
|
| 45 |
uint16_t* c0 = (uint16_t*) c; |
| 46 |
|
| 47 |
const int32x4_t vinput_zero_point = vld1q_dup_s32(&quantization_params->zero_point); |
| 48 |
const float32x4_t vinput_scale = vld1q_dup_f32(&quantization_params->inv_scale); |
| 49 |
kc = round_up_po2(kc, 8 * sizeof(int8_t)); |
| 50 |
do { |
| 51 |
const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4; |
| 52 |
int32x4_t vacc0x0123 = vmulq_s32(vksum0123, vinput_zero_point); |
| 53 |
const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4; |
| 54 |
int32x4_t vacc0x4567 = vmulq_s32(vksum4567, vinput_zero_point); |
| 55 |
|
| 56 |
size_t p = ks; |
| 57 |
do { |
| 58 |
const int8_t* restrict a0 = a[0]; |
| 59 |
if XNN_UNPREDICTABLE(a0 != zero) { |
| 60 |
a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); |
| 61 |
} else { |
| 62 |
a0 = zero_data; |
| 63 |
} |
| 64 |
a += 1; |
| 65 |
|
| 66 |
size_t k = kc; |
| 67 |
while (k >= 16 * sizeof(int8_t)) { |
| 68 |
int8x8_t va0x0 = vld1_s8(a0); a0 += 8; |
| 69 |
int8x8_t va0x1 = vld1_s8(a0); a0 += 8; |
| 70 |
|
| 71 |
const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 72 |
const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 73 |
const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 74 |
const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 75 |
const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 76 |
const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 77 |
const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 78 |
const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 79 |
|
| 80 |
int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0x0); |
| 81 |
const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 82 |
vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0x1); |
| 83 |
vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); |
| 84 |
int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0x0); |
| 85 |
const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 86 |
vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0x1); |
| 87 |
vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); |
| 88 |
va0x0 = vext_s8(va0x0, va0x0, 2); |
| 89 |
va0x1 = vext_s8(va0x1, va0x1, 2); |
| 90 |
int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0x0); |
| 91 |
const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 92 |
vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0x1); |
| 93 |
vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); |
| 94 |
int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0x0); |
| 95 |
const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 96 |
vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0x1); |
| 97 |
vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); |
| 98 |
va0x0 = vext_s8(va0x0, va0x0, 2); |
| 99 |
va0x1 = vext_s8(va0x1, va0x1, 2); |
| 100 |
int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0x0); |
| 101 |
const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 102 |
vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0x1); |
| 103 |
vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); |
| 104 |
int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0x0); |
| 105 |
const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 106 |
vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0x1); |
| 107 |
vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); |
| 108 |
va0x0 = vext_s8(va0x0, va0x0, 2); |
| 109 |
va0x1 = vext_s8(va0x1, va0x1, 2); |
| 110 |
int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0x0); |
| 111 |
const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 112 |
vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0x1); |
| 113 |
vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3); |
| 114 |
int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0x0); |
| 115 |
const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 116 |
vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0x1); |
| 117 |
vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3); |
| 118 |
|
| 119 |
k -= 16 * sizeof(int8_t); |
| 120 |
} |
| 121 |
if (k != 0) { |
| 122 |
int8x8_t va0x0 = vld1_s8(a0); a0 += 8; |
| 123 |
|
| 124 |
const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 125 |
const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 126 |
const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 127 |
const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 128 |
const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 129 |
const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 130 |
const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 131 |
const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const int8_t*) w + 8; |
| 132 |
|
| 133 |
int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0x0); |
| 134 |
vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); |
| 135 |
int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0x0); |
| 136 |
vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); |
| 137 |
va0x0 = vext_s8(va0x0, va0x0, 2); |
| 138 |
int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0x0); |
| 139 |
vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); |
| 140 |
int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0x0); |
| 141 |
vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); |
| 142 |
va0x0 = vext_s8(va0x0, va0x0, 2); |
| 143 |
int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0x0); |
| 144 |
vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); |
| 145 |
int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0x0); |
| 146 |
vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); |
| 147 |
va0x0 = vext_s8(va0x0, va0x0, 2); |
| 148 |
int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0x0); |
| 149 |
vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3); |
| 150 |
int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0x0); |
| 151 |
vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3); |
| 152 |
|
| 153 |
} |
| 154 |
|
| 155 |
p -= 1 * sizeof(void*); |
| 156 |
} while (p != 0); |
| 157 |
|
| 158 |
float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123); |
| 159 |
float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567); |
| 160 |
|
| 161 |
vout0x0123 = vmulq_f32(vout0x0123, vinput_scale); |
| 162 |
vout0x4567 = vmulq_f32(vout0x4567, vinput_scale); |
| 163 |
|
| 164 |
const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4; |
| 165 |
const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4; |
| 166 |
|
| 167 |
const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4; |
| 168 |
#if XNN_ARCH_ARM64 |
| 169 |
vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123); |
| 170 |
#else |
| 171 |
vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123); |
| 172 |
#endif |
| 173 |
const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4; |
| 174 |
#if XNN_ARCH_ARM64 |
| 175 |
vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567); |
| 176 |
#else |
| 177 |
vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567); |
| 178 |
#endif |
| 179 |
|
| 180 |
float16x8_t vfp16out0x01234567 = vcombine_f16(vcvt_f16_f32(vout0x0123), vcvt_f16_f32(vout0x4567)); |
| 181 |
#if XNN_ARCH_ARM64 |
| 182 |
const uint16x8x2_t voutput_minmax = vld2q_dup_u16((const uint16_t*) ¶ms->scalar.min); |
| 183 |
const float16x8_t voutput_min = vreinterpretq_f16_u16(voutput_minmax.val[0]); |
| 184 |
const float16x8_t voutput_max = vreinterpretq_f16_u16(voutput_minmax.val[1]); |
| 185 |
#else |
| 186 |
// vld2_dup is to work around aarch32 clang bug with vld1q_dup |
| 187 |
const uint16x4x2_t vminmax = vld2_dup_u16((const uint16_t*) ¶ms->scalar.min); |
| 188 |
const float16x8_t voutput_min = vreinterpretq_f16_u16(vcombine_u16(vminmax.val[0], vminmax.val[0])); |
| 189 |
const float16x8_t voutput_max = vreinterpretq_f16_u16(vcombine_u16(vminmax.val[1], vminmax.val[1])); |
| 190 |
#endif |
| 191 |
vfp16out0x01234567 = vmaxq_f16(vfp16out0x01234567, voutput_min); |
| 192 |
vfp16out0x01234567 = vminq_f16(vfp16out0x01234567, voutput_max); |
| 193 |
if XNN_LIKELY(nc >= 8) { |
| 194 |
vst1q_u16(c0, vreinterpretq_u16_f16(vfp16out0x01234567)); |
| 195 |
|
| 196 |
a = (const int8_t**restrict) ((uintptr_t) a - ks); |
| 197 |
|
| 198 |
c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride); |
| 199 |
|
| 200 |
nc -= 8; |
| 201 |
} else { |
| 202 |
float16x4_t vfp16out0x0123 = vget_low_f16(vfp16out0x01234567); |
| 203 |
if (nc & 4) { |
| 204 |
vst1_u16(c0, vreinterpret_u16_f16(vfp16out0x0123)); c0 += 4; |
| 205 |
vfp16out0x0123 = vget_high_f16(vfp16out0x01234567); |
| 206 |
} |
| 207 |
if (nc & 2) { |
| 208 |
vst1_lane_u32((void*) c0, vreinterpret_u32_f16(vfp16out0x0123), 0); c0 += 2; |
| 209 |
vfp16out0x0123 = vext_f16(vfp16out0x0123, vfp16out0x0123, 2); |
| 210 |
} |
| 211 |
if (nc & 1) { |
| 212 |
vst1_lane_u16(c0, vreinterpret_u16_f16(vfp16out0x0123), 0); |
| 213 |
} |
| 214 |
nc = 0; |
| 215 |
} |
| 216 |
} while (nc != 0); |
| 217 |
} |