Debian Codegraph @

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