| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/qs8-gemm/c8-neondot.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2023 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_f32_qc8w_gemm_minmax_ukernel_1x16c8__neondot_ld64( |
| 19 |
size_t mr, |
| 20 |
size_t nc, |
| 21 |
size_t kc, |
| 22 |
const int8_t* restrict a, |
| 23 |
size_t a_stride, |
| 24 |
const void* restrict w, |
| 25 |
float* restrict c, |
| 26 |
size_t cm_stride, |
| 27 |
size_t cn_stride, |
| 28 |
const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)], |
| 29 |
const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 30 |
{ |
| 31 |
assert(mr != 0); |
| 32 |
assert(mr <= 1); |
| 33 |
assert(nc != 0); |
| 34 |
assert(kc != 0); |
| 35 |
assert(kc % sizeof(int8_t) == 0); |
| 36 |
assert(a != NULL); |
| 37 |
assert(w != NULL); |
| 38 |
assert(c != NULL); |
| 39 |
|
| 40 |
kc = round_up_po2(kc, 8 * sizeof(int8_t)); |
| 41 |
const int8_t* a0 = a; |
| 42 |
float* c0 = c; |
| 43 |
|
| 44 |
do { |
| 45 |
const int32x4_t vinput_zero_point0 = vld1q_dup_s32(&quantization_params[0].zero_point); |
| 46 |
const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4; |
| 47 |
const int32x4_t vinit0x0123 = vmulq_s32(vksum0123, vinput_zero_point0); |
| 48 |
const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4; |
| 49 |
const int32x4_t vinit0x4567 = vmulq_s32(vksum4567, vinput_zero_point0); |
| 50 |
const int32x4_t vksum89AB = vld1q_s32(w); w = (const int32_t*) w + 4; |
| 51 |
const int32x4_t vinit0x89AB = vmulq_s32(vksum89AB, vinput_zero_point0); |
| 52 |
const int32x4_t vksumCDEF = vld1q_s32(w); w = (const int32_t*) w + 4; |
| 53 |
const int32x4_t vinit0xCDEF = vmulq_s32(vksumCDEF, vinput_zero_point0); |
| 54 |
int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x0123)))); |
| 55 |
int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x0123)))); |
| 56 |
int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x4567)))); |
| 57 |
int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x4567)))); |
| 58 |
int32x4_t vacc0x89 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x89AB)))); |
| 59 |
int32x4_t vacc0xAB = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x89AB)))); |
| 60 |
int32x4_t vacc0xCD = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0xCDEF)))); |
| 61 |
int32x4_t vacc0xEF = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0xCDEF)))); |
| 62 |
|
| 63 |
size_t k = kc; |
| 64 |
do { |
| 65 |
const int8x16_t va0c01234567 = vreinterpretq_s8_u64(vld1q_dup_u64((const void*) a0)); a0 += 8; |
| 66 |
|
| 67 |
const int8x16_t vb01c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 68 |
const int8x16_t vb23c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 69 |
const int8x16_t vb45c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 70 |
const int8x16_t vb67c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 71 |
const int8x16_t vb89c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 72 |
const int8x16_t vbABc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 73 |
const int8x16_t vbCDc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 74 |
const int8x16_t vbEFc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16; |
| 75 |
|
| 76 |
vacc0x01 = vdotq_s32(vacc0x01, vb01c01234567, va0c01234567); |
| 77 |
vacc0x23 = vdotq_s32(vacc0x23, vb23c01234567, va0c01234567); |
| 78 |
vacc0x45 = vdotq_s32(vacc0x45, vb45c01234567, va0c01234567); |
| 79 |
vacc0x67 = vdotq_s32(vacc0x67, vb67c01234567, va0c01234567); |
| 80 |
vacc0x89 = vdotq_s32(vacc0x89, vb89c01234567, va0c01234567); |
| 81 |
vacc0xAB = vdotq_s32(vacc0xAB, vbABc01234567, va0c01234567); |
| 82 |
vacc0xCD = vdotq_s32(vacc0xCD, vbCDc01234567, va0c01234567); |
| 83 |
vacc0xEF = vdotq_s32(vacc0xEF, vbEFc01234567, va0c01234567); |
| 84 |
|
| 85 |
k -= 8 * sizeof(int8_t); |
| 86 |
} while (k != 0); |
| 87 |
|
| 88 |
#if XNN_ARCH_ARM64 |
| 89 |
int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23); |
| 90 |
int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67); |
| 91 |
int32x4_t vacc0x89AB = vpaddq_s32(vacc0x89, vacc0xAB); |
| 92 |
int32x4_t vacc0xCDEF = vpaddq_s32(vacc0xCD, vacc0xEF); |
| 93 |
#else |
| 94 |
int32x4_t vacc0x0123 = vcombine_s32(vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01)), vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23))); |
| 95 |
int32x4_t vacc0x4567 = vcombine_s32(vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45)), vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67))); |
| 96 |
int32x4_t vacc0x89AB = vcombine_s32(vpadd_s32(vget_low_s32(vacc0x89), vget_high_s32(vacc0x89)), vpadd_s32(vget_low_s32(vacc0xAB), vget_high_s32(vacc0xAB))); |
| 97 |
int32x4_t vacc0xCDEF = vcombine_s32(vpadd_s32(vget_low_s32(vacc0xCD), vget_high_s32(vacc0xCD)), vpadd_s32(vget_low_s32(vacc0xEF), vget_high_s32(vacc0xEF))); |
| 98 |
#endif |
| 99 |
|
| 100 |
float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123); |
| 101 |
float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567); |
| 102 |
float32x4_t vout0x89AB = vcvtq_f32_s32(vacc0x89AB); |
| 103 |
float32x4_t vout0xCDEF = vcvtq_f32_s32(vacc0xCDEF); |
| 104 |
|
| 105 |
const float32x4_t vinput_scale0 = vld1q_dup_f32(&quantization_params[0].inv_scale); |
| 106 |
vout0x0123 = vmulq_f32(vout0x0123, vinput_scale0); |
| 107 |
vout0x4567 = vmulq_f32(vout0x4567, vinput_scale0); |
| 108 |
vout0x89AB = vmulq_f32(vout0x89AB, vinput_scale0); |
| 109 |
vout0xCDEF = vmulq_f32(vout0xCDEF, vinput_scale0); |
| 110 |
|
| 111 |
const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4; |
| 112 |
const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4; |
| 113 |
const float32x4_t vfilter_output_scale89AB = vld1q_f32(w); w = (const float*) w + 4; |
| 114 |
const float32x4_t vfilter_output_scaleCDEF = vld1q_f32(w); w = (const float*) w + 4; |
| 115 |
|
| 116 |
const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4; |
| 117 |
#if XNN_ARCH_ARM64 |
| 118 |
vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123); |
| 119 |
#else |
| 120 |
vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123); |
| 121 |
#endif |
| 122 |
const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4; |
| 123 |
#if XNN_ARCH_ARM64 |
| 124 |
vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567); |
| 125 |
#else |
| 126 |
vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567); |
| 127 |
#endif |
| 128 |
const float32x4_t vbias89AB = vld1q_f32(w); w = (const float*) w + 4; |
| 129 |
#if XNN_ARCH_ARM64 |
| 130 |
vout0x89AB = vfmaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB); |
| 131 |
#else |
| 132 |
vout0x89AB = vmlaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB); |
| 133 |
#endif |
| 134 |
const float32x4_t vbiasCDEF = vld1q_f32(w); w = (const float*) w + 4; |
| 135 |
#if XNN_ARCH_ARM64 |
| 136 |
vout0xCDEF = vfmaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF); |
| 137 |
#else |
| 138 |
vout0xCDEF = vmlaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF); |
| 139 |
#endif |
| 140 |
|
| 141 |
const float32x4_t voutput_min = vld1q_dup_f32(¶ms->scalar.min); |
| 142 |
vout0x0123 = vmaxq_f32(vout0x0123, voutput_min); |
| 143 |
vout0x4567 = vmaxq_f32(vout0x4567, voutput_min); |
| 144 |
vout0x89AB = vmaxq_f32(vout0x89AB, voutput_min); |
| 145 |
vout0xCDEF = vmaxq_f32(vout0xCDEF, voutput_min); |
| 146 |
|
| 147 |
const float32x4_t voutput_max = vld1q_dup_f32(¶ms->scalar.max); |
| 148 |
vout0x0123 = vminq_f32(vout0x0123, voutput_max); |
| 149 |
vout0x4567 = vminq_f32(vout0x4567, voutput_max); |
| 150 |
vout0x89AB = vminq_f32(vout0x89AB, voutput_max); |
| 151 |
vout0xCDEF = vminq_f32(vout0xCDEF, voutput_max); |
| 152 |
|
| 153 |
if XNN_LIKELY(nc >= 16) { |
| 154 |
vst1q_f32(c0, vout0x0123); |
| 155 |
vst1q_f32(c0 + 4, vout0x4567); |
| 156 |
vst1q_f32(c0 + 8, vout0x89AB); |
| 157 |
vst1q_f32(c0 + 12, vout0xCDEF); |
| 158 |
|
| 159 |
a0 = (const int8_t*) ((uintptr_t) a0 - kc); |
| 160 |
|
| 161 |
c0 = (float*) ((uintptr_t) c0 + cn_stride); |
| 162 |
|
| 163 |
nc -= 16; |
| 164 |
} else { |
| 165 |
if (nc & 8) { |
| 166 |
vst1q_f32(c0, vout0x0123); c0 += 4; |
| 167 |
vout0x0123 = vout0x89AB; |
| 168 |
vst1q_f32(c0, vout0x4567); c0 += 4; |
| 169 |
vout0x4567 = vout0xCDEF; |
| 170 |
} |
| 171 |
if (nc & 4) { |
| 172 |
vst1q_f32(c0, vout0x0123); c0 += 4; |
| 173 |
vout0x0123 = vout0x4567; |
| 174 |
} |
| 175 |
float32x2_t vout0x01 = vget_low_f32(vout0x0123); |
| 176 |
if (nc & 2) { |
| 177 |
vst1_f32(c0, vout0x01); c0 += 2; |
| 178 |
vout0x01 = vget_high_f32(vout0x0123); |
| 179 |
} |
| 180 |
if (nc & 1) { |
| 181 |
vst1_lane_f32(c0, vout0x01, 0); |
| 182 |
} |
| 183 |
nc = 0; |
| 184 |
} |
| 185 |
} while (nc != 0); |
| 186 |
} |