Debian Codegraph @

src/qd8-f32-qc8w-igemm/gen/qd8-f32-qc8w-igemm-2x16c4-minmax-neondot.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/c4-neondot.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 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/igemm.h"
15 #include "xnnpack/math.h"
16
17
18 void xnn_qd8_f32_qc8w_igemm_minmax_ukernel_2x16c4__neondot(
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 <= 2);
36 assert(nc != 0);
37 assert(kc != 0);
38 assert(ks != 0);
39 assert(ks % (2 * 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, 4 * sizeof(int8_t));
46 float* c0 = c;
47 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
48 if XNN_UNPREDICTABLE(mr != 2) {
49 c1 = c0;
50 }
51
52 do {
53 const int32x4_t vinput_zero_point = vld1q_dup_s32(&quantization_params->zero_point);
54 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
55 int32x4_t vacc0x0123 = vmulq_s32(vksum0123, vinput_zero_point);
56 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
57 int32x4_t vacc0x4567 = vmulq_s32(vksum4567, vinput_zero_point);
58 const int32x4_t vksum89AB = vld1q_s32(w); w = (const int32_t*) w + 4;
59 int32x4_t vacc0x89AB = vmulq_s32(vksum89AB, vinput_zero_point);
60 const int32x4_t vksumCDEF = vld1q_s32(w); w = (const int32_t*) w + 4;
61 int32x4_t vacc0xCDEF = vmulq_s32(vksumCDEF, vinput_zero_point);
62 int32x4_t vacc1x0123 = vacc0x0123;
63 int32x4_t vacc1x4567 = vacc0x4567;
64 int32x4_t vacc1x89AB = vacc0x89AB;
65 int32x4_t vacc1xCDEF = vacc0xCDEF;
66
67 size_t p = ks;
68 do {
69 const int8_t* restrict a0 = a[0];
70 if XNN_UNPREDICTABLE(a0 != zero) {
71 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
72 } else {
73 a0 = zero_data;
74 }
75 const int8_t* restrict a1 = a[1];
76 if XNN_UNPREDICTABLE(a1 != zero) {
77 a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
78 } else {
79 a1 = zero_data;
80 }
81 a += 2;
82
83 // Inner accumulation loop along the 16 columns.
84 size_t k = kc;
85 // 2x partial unrolled loop to load 8 bytes at a time.
86 while (k >= 8 * sizeof(int8_t)) {
87 // Load a 2x8 block of activations.
88 const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8;
89 const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8;
90
91 // Load a 8x16 block of weights.
92 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
93 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
94 const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
95 const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
96 const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
97 const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
98 const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
99 const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
100
101 // Multiply-accumulate: 2x8 * 8x16 --> 2x16.
102 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
103 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
104 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0);
105 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
106 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
107 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
108 vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0);
109 vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0);
110 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1);
111 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1);
112 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1);
113 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1);
114 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1);
115 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1);
116 vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb4567x89AB, va1x01234567, 1);
117 vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb4567xCDEF, va1x01234567, 1);
118
119 k -= 8 * sizeof(int8_t);
120 }
121 // Handle up to 4 final positions of `k`
122 if XNN_UNLIKELY(k != 0) {
123 // Load a 2x4 block of activations.
124 const int8x8_t va0x01234567 = vld1_s8(a0);
125 const int8x8_t va1x01234567 = vld1_s8(a1);
126
127 // Load a 4x16 block of weights.
128 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
129 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
130 const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
131 const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
132
133 // Multiply-accumulate: 2x4 * 4x16 --> 2x16.
134 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
135 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
136 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0);
137 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
138 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
139 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
140 vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0);
141 vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0);
142 }
143 p -= 2 * sizeof(void*);
144 } while (p != 0);
145
146 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
147 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
148 float32x4_t vout0x89AB = vcvtq_f32_s32(vacc0x89AB);
149 float32x4_t vout0xCDEF = vcvtq_f32_s32(vacc0xCDEF);
150 float32x4_t vout1x0123 = vcvtq_f32_s32(vacc1x0123);
151 float32x4_t vout1x4567 = vcvtq_f32_s32(vacc1x4567);
152 float32x4_t vout1x89AB = vcvtq_f32_s32(vacc1x89AB);
153 float32x4_t vout1xCDEF = vcvtq_f32_s32(vacc1xCDEF);
154 const float32x4_t vinput_scale = vld1q_dup_f32(&quantization_params->inv_scale);
155 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale);
156 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale);
157 vout0x89AB = vmulq_f32(vout0x89AB, vinput_scale);
158 vout0xCDEF = vmulq_f32(vout0xCDEF, vinput_scale);
159 vout1x0123 = vmulq_f32(vout1x0123, vinput_scale);
160 vout1x4567 = vmulq_f32(vout1x4567, vinput_scale);
161 vout1x89AB = vmulq_f32(vout1x89AB, vinput_scale);
162 vout1xCDEF = vmulq_f32(vout1xCDEF, 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 const float32x4_t vfilter_output_scale89AB = vld1q_f32(w); w = (const float*) w + 4;
167 const float32x4_t vfilter_output_scaleCDEF = vld1q_f32(w); w = (const float*) w + 4;
168
169 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
170 #if XNN_ARCH_ARM64
171 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
172 vout1x0123 = vfmaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
173 #else
174 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
175 vout1x0123 = vmlaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
176 #endif
177 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
178 #if XNN_ARCH_ARM64
179 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
180 vout1x4567 = vfmaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
181 #else
182 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
183 vout1x4567 = vmlaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
184 #endif
185 const float32x4_t vbias89AB = vld1q_f32(w); w = (const float*) w + 4;
186 #if XNN_ARCH_ARM64
187 vout0x89AB = vfmaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
188 vout1x89AB = vfmaq_f32(vbias89AB, vout1x89AB, vfilter_output_scale89AB);
189 #else
190 vout0x89AB = vmlaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
191 vout1x89AB = vmlaq_f32(vbias89AB, vout1x89AB, vfilter_output_scale89AB);
192 #endif
193 const float32x4_t vbiasCDEF = vld1q_f32(w); w = (const float*) w + 4;
194 #if XNN_ARCH_ARM64
195 vout0xCDEF = vfmaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
196 vout1xCDEF = vfmaq_f32(vbiasCDEF, vout1xCDEF, vfilter_output_scaleCDEF);
197 #else
198 vout0xCDEF = vmlaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
199 vout1xCDEF = vmlaq_f32(vbiasCDEF, vout1xCDEF, vfilter_output_scaleCDEF);
200 #endif
201
202 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
203 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
204 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
205 vout0x89AB = vmaxq_f32(vout0x89AB, voutput_min);
206 vout0xCDEF = vmaxq_f32(vout0xCDEF, voutput_min);
207 vout1x0123 = vmaxq_f32(vout1x0123, voutput_min);
208 vout1x4567 = vmaxq_f32(vout1x4567, voutput_min);
209 vout1x89AB = vmaxq_f32(vout1x89AB, voutput_min);
210 vout1xCDEF = vmaxq_f32(vout1xCDEF, voutput_min);
211
212 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
213 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
214 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
215 vout0x89AB = vminq_f32(vout0x89AB, voutput_max);
216 vout0xCDEF = vminq_f32(vout0xCDEF, voutput_max);
217 vout1x0123 = vminq_f32(vout1x0123, voutput_max);
218 vout1x4567 = vminq_f32(vout1x4567, voutput_max);
219 vout1x89AB = vminq_f32(vout1x89AB, voutput_max);
220 vout1xCDEF = vminq_f32(vout1xCDEF, voutput_max);
221
222 if XNN_LIKELY(nc >= 16) {
223 vst1q_f32(c1, vout1x0123);
224 vst1q_f32(c1 + 4, vout1x4567);
225 vst1q_f32(c1 + 8, vout1x89AB);
226 vst1q_f32(c1 + 12, vout1xCDEF);
227 vst1q_f32(c0, vout0x0123);
228 vst1q_f32(c0 + 4, vout0x4567);
229 vst1q_f32(c0 + 8, vout0x89AB);
230 vst1q_f32(c0 + 12, vout0xCDEF);
231
232 a = (const int8_t**restrict) ((uintptr_t) a - ks);
233
234 c0 = (float*) ((uintptr_t) c0 + cn_stride);
235 c1 = (float*) ((uintptr_t) c1 + cn_stride);
236
237 nc -= 16;
238 } else {
239 if (nc & 8) {
240 vst1q_f32(c1, vout1x0123); c1 += 4;
241 vout1x0123 = vout1x89AB;
242 vst1q_f32(c0, vout0x0123); c0 += 4;
243 vout0x0123 = vout0x89AB;
244 vst1q_f32(c1, vout1x4567); c1 += 4;
245 vout1x4567 = vout1xCDEF;
246 vst1q_f32(c0, vout0x4567); c0 += 4;
247 vout0x4567 = vout0xCDEF;
248 }
249 if (nc & 4) {
250 vst1q_f32(c1, vout1x0123); c1 += 4;
251 vout1x0123 = vout1x4567;
252 vst1q_f32(c0, vout0x0123); c0 += 4;
253 vout0x0123 = vout0x4567;
254 }
255 float32x2_t vout1x01 = vget_low_f32(vout1x0123);
256 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
257 if (nc & 2) {
258 vst1_f32(c1, vout1x01); c1 += 2;
259 vst1_f32(c0, vout0x01); c0 += 2;
260 vout1x01 = vget_high_f32(vout1x0123);
261 vout0x01 = vget_high_f32(vout0x0123);
262 }
263 if (nc & 1) {
264 vst1_lane_f32(c1, vout1x01, 0);
265 vst1_lane_f32(c0, vout0x01, 0);
266 }
267 nc = 0;
268 }
269 } while (nc != 0);
270 }