Debian Codegraph @

src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8-minmax-fp32-neonv8-mlal-lane-prfm.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/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
11 #include <assert.h>
12
13 #include <arm_neon.h>
14
15 #include "xnnpack/common.h"
16 #include "xnnpack/igemm.h"
17 #include "xnnpack/intrinsics-polyfill.h"
18 #include "xnnpack/prefetch.h"
19
20
21 void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8__neonv8_mlal_lane_prfm(
22 size_t mr,
23 size_t nc,
24 size_t kc,
25 size_t ks,
26 const int8_t** restrict a,
27 const void* restrict w,
28 int8_t* restrict c,
29 size_t cm_stride,
30 size_t cn_stride,
31 size_t a_offset,
32 const int8_t* zero,
33 const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
34 {
35 assert(mr != 0);
36 assert(mr <= 2);
37 assert(nc != 0);
38 assert(kc != 0);
39 assert(ks != 0);
40 assert(ks % (2 * sizeof(void*)) == 0);
41 assert(a_offset % sizeof(int8_t) == 0);
42 assert(a != NULL);
43 assert(w != NULL);
44 assert(c != NULL);
45
46 int8_t* c0 = c;
47 int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
48 if XNN_UNPREDICTABLE(mr != 2) {
49 c1 = c0;
50 }
51
52 do {
53 int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
54 int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
55 int32x4_t vacc1x0123 = vacc0x0123;
56 int32x4_t vacc1x4567 = vacc0x4567;
57
58 size_t p = ks;
59 do {
60 const int8_t* restrict a0 = a[0];
61 if XNN_UNPREDICTABLE(a0 != zero) {
62 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
63 }
64 const int8_t* restrict a1 = a[1];
65 if XNN_UNPREDICTABLE(a1 != zero) {
66 a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
67 }
68 a += 2;
69
70 size_t k = kc;
71 while (k >= 8 * sizeof(int8_t)) {
72 const int8x8_t va0 = vld1_s8(a0); a0 += 8;
73 const int16x8_t vxa0 = vmovl_s8(va0);
74 const int8x8_t va1 = vld1_s8(a1); a1 += 8;
75 const int16x8_t vxa1 = vmovl_s8(va1);
76
77 const int8x8_t vb01234567c0 = vld1_s8(w); w = (const int8_t*) w + 8;
78 const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0);
79
80 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
81 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
82 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0);
83 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0);
84 const int8x8_t vb01234567c1 = vld1_s8(w); w = (const int8_t*) w + 8;
85 const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1);
86
87 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
88 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
89 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1);
90 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1);
91 const int8x8_t vb01234567c2 = vld1_s8(w); w = (const int8_t*) w + 8;
92 const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2);
93
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 const int8x8_t vb01234567c3 = vld1_s8(w); w = (const int8_t*) w + 8;
99 const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3);
100
101 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
102 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
103 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3);
104 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3);
105
106 xnn_prefetch_to_l1((const int8_t*) w + 448);
107
108 const int8x8_t vb01234567c4 = vld1_s8(w); w = (const int8_t*) w + 8;
109 const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4);
110
111 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
112 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
113 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0);
114 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0);
115 const int8x8_t vb01234567c5 = vld1_s8(w); w = (const int8_t*) w + 8;
116 const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5);
117
118 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
119 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
120 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1);
121 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1);
122 const int8x8_t vb01234567c6 = vld1_s8(w); w = (const int8_t*) w + 8;
123 const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6);
124
125 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
126 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
127 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2);
128 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2);
129 const int8x8_t vb01234567c7 = vld1_s8(w); w = (const int8_t*) w + 8;
130 const int16x8_t vxb01234567c7 = vmovl_s8(vb01234567c7);
131
132 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
133 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa0), 3);
134 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa1), 3);
135 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa1), 3);
136
137 k -= 8 * sizeof(int8_t);
138 }
139 if XNN_UNLIKELY(k != 0) {
140 const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
141 const int16x8_t vxa0 = vmovl_s8(va0);
142 const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
143 const int16x8_t vxa1 = vmovl_s8(va1);
144
145 const int8x8_t vb01234567c0 = vld1_s8(w); w = (const int8_t*) w + 8;
146 const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0);
147
148 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
149 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0);
150 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0);
151 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0);
152
153 if (k >= 2 * sizeof(int8_t)) {
154 const int8x8_t vb01234567c1 = vld1_s8(w); w = (const int8_t*) w + 8;
155 const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1);
156
157 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
158 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1);
159 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1);
160 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1);
161
162 if (k > 2 * sizeof(int8_t)) {
163 const int8x8_t vb01234567c2 = vld1_s8(w); w = (const int8_t*) w + 8;
164 const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2);
165
166 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
167 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2);
168 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2);
169 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2);
170
171 if (k >= 4 * sizeof(int8_t)) {
172 const int8x8_t vb01234567c3 = vld1_s8(w); w = (const int8_t*) w + 8;
173 const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3);
174
175 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
176 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3);
177 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3);
178 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3);
179
180 if (k > 4 * sizeof(int8_t)) {
181 const int8x8_t vb01234567c4 = vld1_s8(w); w = (const int8_t*) w + 8;
182 const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4);
183
184 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
185 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0);
186 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0);
187 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0);
188
189 if (k >= 6 * sizeof(int8_t)) {
190 const int8x8_t vb01234567c5 = vld1_s8(w); w = (const int8_t*) w + 8;
191 const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5);
192
193 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
194 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1);
195 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1);
196 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1);
197
198 if (k > 6 * sizeof(int8_t)) {
199 const int8x8_t vb01234567c6 = vld1_s8(w); w = (const int8_t*) w + 8;
200 const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6);
201
202 vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
203 vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2);
204 vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2);
205 vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2);
206 }
207 }
208 }
209 }
210 }
211 }
212 }
213 p -= 2 * sizeof(void*);
214 } while (p != 0);
215
216 // Post-accumulation work
217 float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123);
218 float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567);
219 float32x4_t vfpacc1x0123 = vcvtq_f32_s32(vacc1x0123);
220 float32x4_t vfpacc1x4567 = vcvtq_f32_s32(vacc1x4567);
221
222 const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const float*) w + 4;
223 vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123);
224 vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123);
225 const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const float*) w + 4;
226 vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567);
227 vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567);
228
229 vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123);
230 vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567);
231 vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123);
232 vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567);
233
234 const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point);
235 #if XNN_ARCH_ARM64
236 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
237 int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
238
239 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
240 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
241
242 int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567);
243 #else
244 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
245 int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
246
247 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
248 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
249
250 int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567));
251 #endif
252
253 const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min);
254 vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min);
255
256 const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max);
257 vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max);
258
259 if (nc >= 8) {
260 vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567));
261 vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567));
262
263 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
264 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
265
266 a = (const int8_t**restrict) ((uintptr_t) a - ks);
267
268 nc -= 8;
269 } else {
270 if (nc & 4) {
271 vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
272 vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
273 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
274 }
275 if (nc & 2) {
276 vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
277 vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
278 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
279 }
280 if (nc & 1) {
281 vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
282 vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
283 }
284
285 nc = 0;
286 }
287 } while (nc != 0);
288 }