Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-2x8-minmax-neon-mlal-lane-prfm.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/neon-mlal-lane.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/common.h"
15 #include "xnnpack/gemm.h"
16 #include "xnnpack/prefetch.h"
17
18
19 void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_2x8__neon_mlal_lane_prfm(
20 size_t mr,
21 size_t nc,
22 size_t kc,
23 const int8_t* restrict a,
24 size_t a_stride,
25 const void* restrict w,
26 float* restrict c,
27 size_t cm_stride,
28 size_t cn_stride,
29 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
30 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
31 {
32 assert(mr != 0);
33 assert(mr <= 2);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(kc % sizeof(int8_t) == 0);
37 assert(a != NULL);
38 assert(w != NULL);
39 assert(c != NULL);
40
41 const int8_t* a0 = a;
42 float* c0 = c;
43 const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
44 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
45 if XNN_UNPREDICTABLE(mr != 2) {
46 a1 = a0;
47 c1 = c0;
48 }
49
50 do {
51 int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
52 int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
53 const int32x4_t vzp01 = vld1q_s32(&quantization_params[0].zero_point);
54 int32x4_t vacc0x0123 = vmulq_lane_s32(vksum0123, vget_low_s32(vzp01), 0);
55 int32x4_t vacc1x0123 = vmulq_lane_s32(vksum0123, vget_high_s32(vzp01), 0);
56 int32x4_t vacc0x4567 = vmulq_lane_s32(vksum4567, vget_low_s32(vzp01), 0);
57 int32x4_t vacc1x4567 = vmulq_lane_s32(vksum4567, vget_high_s32(vzp01), 0);
58
59 size_t k = kc;
60 while (k >= 8 * sizeof(int8_t)) {
61 const int8x8_t va0 = vld1_s8(a0); a0 += 8;
62 const int16x8_t vxa0 = vmovl_s8(va0);
63 const int8x8_t va1 = vld1_s8(a1); a1 += 8;
64 const int16x8_t vxa1 = vmovl_s8(va1);
65
66 const int8x8_t vb01234567c0 = vld1_s8(w); w = (const int8_t*) w + 8;
67 const int8x8_t vb01234567c1 = vld1_s8(w); w = (const int8_t*) w + 8;
68 const int8x8_t vb01234567c2 = vld1_s8(w); w = (const int8_t*) w + 8;
69 const int8x8_t vb01234567c3 = vld1_s8(w); w = (const int8_t*) w + 8;
70 const int8x8_t vb01234567c4 = vld1_s8(w); w = (const int8_t*) w + 8;
71 const int8x8_t vb01234567c5 = vld1_s8(w); w = (const int8_t*) w + 8;
72 const int8x8_t vb01234567c6 = vld1_s8(w); w = (const int8_t*) w + 8;
73 const int8x8_t vb01234567c7 = vld1_s8(w); w = (const int8_t*) w + 8;
74
75 const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0);
76 const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1);
77 const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2);
78 const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3);
79 const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4);
80 const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5);
81 const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6);
82 const int16x8_t vxb01234567c7 = vmovl_s8(vb01234567c7);
83
84 xnn_prefetch_to_l1((const int8_t*) w + 448);
85
86 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
87 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
88 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0);
89 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0);
90 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
91 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
92 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1);
93 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1);
94 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
95 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
96 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2);
97 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2);
98 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
99 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
100 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3);
101 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3);
102
103 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
104 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
105 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0);
106 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0);
107 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
108 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
109 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1);
110 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1);
111 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
112 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
113 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2);
114 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2);
115 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
116 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
117 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa1), 3);
118 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa1), 3);
119
120 k -= 8 * sizeof(int8_t);
121 }
122 if XNN_UNLIKELY(k != 0) {
123 const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
124 const int16x8_t vxa0 = vmovl_s8(va0);
125 const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
126 const int16x8_t vxa1 = vmovl_s8(va1);
127
128 const int8x8_t vb01234567c0 = vld1_s8(w); w = (const int8_t*) w + 8;
129
130 const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0);
131
132 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
133 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
134 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0);
135 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0);
136
137 if (k >= 2 * sizeof(int8_t)) {
138 const int8x8_t vb01234567c1 = vld1_s8(w); w = (const int8_t*) w + 8;
139 const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1);
140
141 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
142 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
143 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1);
144 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1);
145
146 if (k > 2 * sizeof(int8_t)) {
147 const int8x8_t vb01234567c2 = vld1_s8(w); w = (const int8_t*) w + 8;
148 const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2);
149
150 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
151 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
152 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2);
153 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2);
154
155 if (k >= 4 * sizeof(int8_t)) {
156 const int8x8_t vb01234567c3 = vld1_s8(w); w = (const int8_t*) w + 8;
157 const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3);
158
159 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
160 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
161 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3);
162 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3);
163
164 if (k > 4 * sizeof(int8_t)) {
165 const int8x8_t vb01234567c4 = vld1_s8(w); w = (const int8_t*) w + 8;
166 const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4);
167
168 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
169 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
170 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0);
171 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0);
172
173 if (k >= 6 * sizeof(int8_t)) {
174 const int8x8_t vb01234567c5 = vld1_s8(w); w = (const int8_t*) w + 8;
175 const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5);
176
177 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
178 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
179 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1);
180 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1);
181
182 if (k > 6 * sizeof(int8_t)) {
183 const int8x8_t vb01234567c6 = vld1_s8(w); w = (const int8_t*) w + 8;
184 const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6);
185
186 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
187 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
188 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2);
189 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2);
190 }
191 }
192 }
193 }
194 }
195 }
196 }
197
198 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
199 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
200 float32x4_t vout1x0123 = vcvtq_f32_s32(vacc1x0123);
201 float32x4_t vout1x4567 = vcvtq_f32_s32(vacc1x4567);
202
203 const float32x4_t vinput_scale01 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[0].zero_point));
204 vout0x0123 = vmulq_lane_f32(vout0x0123, vget_low_f32(vinput_scale01), 1);
205 vout1x0123 = vmulq_lane_f32(vout1x0123, vget_high_f32(vinput_scale01), 1);
206 vout0x4567 = vmulq_lane_f32(vout0x4567, vget_low_f32(vinput_scale01), 1);
207 vout1x4567 = vmulq_lane_f32(vout1x4567, vget_high_f32(vinput_scale01), 1);
208
209 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
210 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
211
212 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
213 #if XNN_ARCH_ARM64
214 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
215 vout1x0123 = vfmaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
216 #else
217 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
218 vout1x0123 = vmlaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
219 #endif
220 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
221 #if XNN_ARCH_ARM64
222 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
223 vout1x4567 = vfmaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
224 #else
225 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
226 vout1x4567 = vmlaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
227 #endif
228
229 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
230 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
231 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
232 vout1x0123 = vmaxq_f32(vout1x0123, voutput_min);
233 vout1x4567 = vmaxq_f32(vout1x4567, voutput_min);
234
235 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
236 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
237 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
238 vout1x0123 = vminq_f32(vout1x0123, voutput_max);
239 vout1x4567 = vminq_f32(vout1x4567, voutput_max);
240
241 if XNN_LIKELY(nc >= 8) {
242 vst1q_f32(&c0[0], vout0x0123);
243 vst1q_f32(&c0[4], vout0x4567);
244 vst1q_f32(&c1[0], vout1x0123);
245 vst1q_f32(&c1[4], vout1x4567);
246
247 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
248 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
249
250 c0 = (float*) ((uintptr_t) c0 + cn_stride);
251 c1 = (float*) ((uintptr_t) c1 + cn_stride);
252
253 nc -= 8;
254 } else {
255 if (nc & 4) {
256 vst1q_f32(c0, vout0x0123); c0 += 4;
257 vout0x0123 = vout0x4567;
258 vst1q_f32(c1, vout1x0123); c1 += 4;
259 vout1x0123 = vout1x4567;
260 }
261 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
262 float32x2_t vout1x01 = vget_low_f32(vout1x0123);
263 if (nc & 2) {
264 vst1_f32(c0, vout0x01); c0 += 2;
265 vst1_f32(c1, vout1x01); c1 += 2;
266 vout0x01 = vget_high_f32(vout0x0123);
267 vout1x01 = vget_high_f32(vout1x0123);
268 }
269 if (nc & 1) {
270 vst1_lane_f32(c0, vout0x01, 0);
271 vst1_lane_f32(c1, vout1x01, 0);
272 }
273 nc = 0;
274 }
275 } while (nc != 0);
276 }