Debian Codegraph @

src/qd8-f32-qc8w-igemm/gen/qd8-f32-qc8w-igemm-1x16c8-minmax-aarch64-neondot-ld128.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/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_igemm_minmax_ukernel_1x16c8__aarch64_neondot_ld128(
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 float* 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_f32_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 kc = round_up_po2(kc, 8 * sizeof(int8_t));
46 float* c0 = c;
47
48 const int32x4_t vinput_zero_point = vld1q_dup_s32(&quantization_params->zero_point);
49 const float32x4_t vinput_scale = vld1q_dup_f32(&quantization_params->inv_scale);
50 do {
51 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
52 const int32x4_t vinit0x0123 = vmulq_s32(vksum0123, vinput_zero_point);
53 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
54 const int32x4_t vinit0x4567 = vmulq_s32(vksum4567, vinput_zero_point);
55 const int32x4_t vksum89AB = vld1q_s32(w); w = (const int32_t*) w + 4;
56 const int32x4_t vinit0x89AB = vmulq_s32(vksum89AB, vinput_zero_point);
57 const int32x4_t vksumCDEF = vld1q_s32(w); w = (const int32_t*) w + 4;
58 const int32x4_t vinit0xCDEF = vmulq_s32(vksumCDEF, vinput_zero_point);
59 int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x0123))));
60 int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x0123))));
61 int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x4567))));
62 int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x4567))));
63 int32x4_t vacc0x89 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x89AB))));
64 int32x4_t vacc0xAB = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x89AB))));
65 int32x4_t vacc0xCD = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0xCDEF))));
66 int32x4_t vacc0xEF = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0xCDEF))));
67
68 size_t p = ks;
69 do {
70 const int8_t* restrict a0 = a[0];
71 if XNN_UNPREDICTABLE(a0 != zero) {
72 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
73 } else {
74 a0 = zero_data;
75 }
76 a += 1;
77
78 size_t k = kc;
79 for (; k >= 16 * sizeof(int8_t); k -= 16 * sizeof(int8_t)) {
80 const uint64x2x2_t va0c0123456789ABCDEF = vld2q_dup_u64((const void*) a0); a0 += 16;
81
82 const int8x16_t vb01c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
83 const int8x16_t vb23c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
84 const int8x16_t vb45c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
85 const int8x16_t vb67c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
86 const int8x16_t vb89c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
87 const int8x16_t vbABc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
88 const int8x16_t vbCDc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
89 const int8x16_t vbEFc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
90
91 vacc0x01 = vdotq_s32(vacc0x01, vb01c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
92 vacc0x23 = vdotq_s32(vacc0x23, vb23c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
93 vacc0x45 = vdotq_s32(vacc0x45, vb45c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
94 vacc0x67 = vdotq_s32(vacc0x67, vb67c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
95 vacc0x89 = vdotq_s32(vacc0x89, vb89c01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
96 vacc0xAB = vdotq_s32(vacc0xAB, vbABc01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
97 vacc0xCD = vdotq_s32(vacc0xCD, vbCDc01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
98 vacc0xEF = vdotq_s32(vacc0xEF, vbEFc01234567, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[0]));
99
100 const int8x16_t vb01c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
101 const int8x16_t vb23c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
102 const int8x16_t vb45c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
103 const int8x16_t vb67c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
104 const int8x16_t vb89c89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
105 const int8x16_t vbABc89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
106 const int8x16_t vbCDc89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
107 const int8x16_t vbEFc89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
108
109 vacc0x01 = vdotq_s32(vacc0x01, vb01c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
110 vacc0x23 = vdotq_s32(vacc0x23, vb23c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
111 vacc0x45 = vdotq_s32(vacc0x45, vb45c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
112 vacc0x67 = vdotq_s32(vacc0x67, vb67c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
113 vacc0x89 = vdotq_s32(vacc0x89, vb89c89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
114 vacc0xAB = vdotq_s32(vacc0xAB, vbABc89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
115 vacc0xCD = vdotq_s32(vacc0xCD, vbCDc89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
116 vacc0xEF = vdotq_s32(vacc0xEF, vbEFc89ABCDEF, vreinterpretq_s8_u64(va0c0123456789ABCDEF.val[1]));
117 }
118 if XNN_LIKELY(k != 0) {
119 assert(k == 8 * sizeof(int8_t));
120
121 const int8x16_t va0c01234567 = vreinterpretq_s8_u64(vld1q_dup_u64((const void*) a0)); a0 += 8;
122
123 const int8x16_t vb01c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
124 const int8x16_t vb23c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
125 const int8x16_t vb45c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
126 const int8x16_t vb67c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
127 const int8x16_t vb89c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
128 const int8x16_t vbABc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
129 const int8x16_t vbCDc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
130 const int8x16_t vbEFc01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
131
132 vacc0x01 = vdotq_s32(vacc0x01, vb01c01234567, va0c01234567);
133 vacc0x23 = vdotq_s32(vacc0x23, vb23c01234567, va0c01234567);
134 vacc0x45 = vdotq_s32(vacc0x45, vb45c01234567, va0c01234567);
135 vacc0x67 = vdotq_s32(vacc0x67, vb67c01234567, va0c01234567);
136 vacc0x89 = vdotq_s32(vacc0x89, vb89c01234567, va0c01234567);
137 vacc0xAB = vdotq_s32(vacc0xAB, vbABc01234567, va0c01234567);
138 vacc0xCD = vdotq_s32(vacc0xCD, vbCDc01234567, va0c01234567);
139 vacc0xEF = vdotq_s32(vacc0xEF, vbEFc01234567, va0c01234567);
140 }
141 p -= 1 * sizeof(void*);
142 } while (p != 0);
143
144 #if XNN_ARCH_ARM64
145 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23);
146 int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67);
147 int32x4_t vacc0x89AB = vpaddq_s32(vacc0x89, vacc0xAB);
148 int32x4_t vacc0xCDEF = vpaddq_s32(vacc0xCD, vacc0xEF);
149 #else
150 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)));
151 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)));
152 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)));
153 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)));
154 #endif
155 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
156 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
157 float32x4_t vout0x89AB = vcvtq_f32_s32(vacc0x89AB);
158 float32x4_t vout0xCDEF = vcvtq_f32_s32(vacc0xCDEF);
159
160 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale);
161 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale);
162 vout0x89AB = vmulq_f32(vout0x89AB, vinput_scale);
163 vout0xCDEF = vmulq_f32(vout0xCDEF, vinput_scale);
164
165 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
166 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
167 const float32x4_t vfilter_output_scale89AB = vld1q_f32(w); w = (const float*) w + 4;
168 const float32x4_t vfilter_output_scaleCDEF = vld1q_f32(w); w = (const float*) w + 4;
169
170 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
171 #if XNN_ARCH_ARM64
172 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
173 #else
174 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
175 #endif
176 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
177 #if XNN_ARCH_ARM64
178 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
179 #else
180 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
181 #endif
182 const float32x4_t vbias89AB = vld1q_f32(w); w = (const float*) w + 4;
183 #if XNN_ARCH_ARM64
184 vout0x89AB = vfmaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
185 #else
186 vout0x89AB = vmlaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
187 #endif
188 const float32x4_t vbiasCDEF = vld1q_f32(w); w = (const float*) w + 4;
189 #if XNN_ARCH_ARM64
190 vout0xCDEF = vfmaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
191 #else
192 vout0xCDEF = vmlaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
193 #endif
194
195 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
196 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
197 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
198 vout0x89AB = vmaxq_f32(vout0x89AB, voutput_min);
199 vout0xCDEF = vmaxq_f32(vout0xCDEF, voutput_min);
200
201 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
202 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
203 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
204 vout0x89AB = vminq_f32(vout0x89AB, voutput_max);
205 vout0xCDEF = vminq_f32(vout0xCDEF, voutput_max);
206
207 if XNN_LIKELY(nc >= 16) {
208 vst1q_f32(c0, vout0x0123);
209 vst1q_f32(c0 + 4, vout0x4567);
210 vst1q_f32(c0 + 8, vout0x89AB);
211 vst1q_f32(c0 + 12, vout0xCDEF);
212
213 a = (const int8_t**restrict) ((uintptr_t) a - ks);
214
215 c0 = (float*) ((uintptr_t) c0 + cn_stride);
216
217 nc -= 16;
218 } else {
219 if (nc & 8) {
220 vst1q_f32(c0, vout0x0123); c0 += 4;
221 vout0x0123 = vout0x89AB;
222 vst1q_f32(c0, vout0x4567); c0 += 4;
223 vout0x4567 = vout0xCDEF;
224 }
225 if (nc & 4) {
226 vst1q_f32(c0, vout0x0123); c0 += 4;
227 vout0x0123 = vout0x4567;
228 }
229 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
230 if (nc & 2) {
231 vst1_f32(c0, vout0x01); c0 += 2;
232 vout0x01 = vget_high_f32(vout0x0123);
233 }
234 if (nc & 1) {
235 vst1_lane_f32(c0, vout0x01, 0);
236 }
237 nc = 0;
238 }
239 } while (nc != 0);
240 }