Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x8c8-minmax-neondot-ld64.c

raw
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_1x8c8__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 int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x0123))));
51 int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x0123))));
52 int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x4567))));
53 int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x4567))));
54
55 size_t k = kc;
56 do {
57 const int8x16_t va0c01234567 = vreinterpretq_s8_u64(vld1q_dup_u64((const void*) a0)); a0 += 8;
58
59 const int8x16_t vb01c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
60 const int8x16_t vb23c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
61 const int8x16_t vb45c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
62 const int8x16_t vb67c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
63
64 vacc0x01 = vdotq_s32(vacc0x01, vb01c01234567, va0c01234567);
65 vacc0x23 = vdotq_s32(vacc0x23, vb23c01234567, va0c01234567);
66 vacc0x45 = vdotq_s32(vacc0x45, vb45c01234567, va0c01234567);
67 vacc0x67 = vdotq_s32(vacc0x67, vb67c01234567, va0c01234567);
68
69 k -= 8 * sizeof(int8_t);
70 } while (k != 0);
71
72 #if XNN_ARCH_ARM64
73 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23);
74 int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67);
75 #else
76 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)));
77 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)));
78 #endif
79
80 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
81 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
82
83 const float32x4_t vinput_scale0 = vld1q_dup_f32(&quantization_params[0].inv_scale);
84 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale0);
85 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale0);
86
87 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
88 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
89
90 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
91 #if XNN_ARCH_ARM64
92 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
93 #else
94 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
95 #endif
96 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
97 #if XNN_ARCH_ARM64
98 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
99 #else
100 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
101 #endif
102
103 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
104 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
105 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
106
107 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
108 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
109 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
110
111 if XNN_LIKELY(nc >= 8) {
112 vst1q_f32(c0, vout0x0123);
113 vst1q_f32(c0 + 4, vout0x4567);
114
115 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
116
117 c0 = (float*) ((uintptr_t) c0 + cn_stride);
118
119 nc -= 8;
120 } else {
121 if (nc & 4) {
122 vst1q_f32(c0, vout0x0123); c0 += 4;
123 vout0x0123 = vout0x4567;
124 }
125 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
126 if (nc & 2) {
127 vst1_f32(c0, vout0x01); c0 += 2;
128 vout0x01 = vget_high_f32(vout0x0123);
129 }
130 if (nc & 1) {
131 vst1_lane_f32(c0, vout0x01, 0);
132 }
133 nc = 0;
134 }
135 } while (nc != 0);
136 }