1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/c2-neon-mull-dup.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 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
xnn_qs8_igemm_minmax_rndnu_ukernel_3x8c2__neon_mull_ld4r(size_t mr,size_t nc,size_t kc,size_t ks,const int8_t ** restrict a,const void * restrict w,int8_t * restrict c,size_t cm_stride,size_t cn_stride,size_t a_offset,const int8_t * zero,const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_qs8_igemm_minmax_rndnu_ukernel_3x8c2__neon_mull_ld4r(
18 size_t mr,
19 size_t nc,
20 size_t kc,
21 size_t ks,
22 const int8_t** restrict a,
23 const void* restrict w,
24 int8_t* restrict c,
25 size_t cm_stride,
26 size_t cn_stride,
27 size_t a_offset,
28 const int8_t* zero,
29 const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
30 {
31 assert(mr != 0);
32 assert(mr <= 3);
33 assert(nc != 0);
34 assert(kc != 0);
35 assert(ks != 0);
36 assert(ks % (3 * sizeof(void*)) == 0);
37 assert(a_offset % sizeof(int8_t) == 0);
38 assert(a != NULL);
39 assert(w != NULL);
40 assert(c != NULL);
41
42 kc = round_up_po2(kc, 2 * sizeof(int8_t));
43 int8_t* c0 = c;
44 int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
45 if XNN_UNPREDICTABLE(mr < 2) {
46 c1 = c0;
47 }
48 int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
49 if XNN_UNPREDICTABLE(mr <= 2) {
50 c2 = c1;
51 }
52
53 do {
54 int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
55 int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
56 int32x4_t vacc1x0123 = vacc0x0123;
57 int32x4_t vacc1x4567 = vacc0x4567;
58 int32x4_t vacc2x0123 = vacc0x0123;
59 int32x4_t vacc2x4567 = vacc0x4567;
60
61 size_t p = ks;
62 do {
63 const int8_t* restrict a0 = a[0];
64 if XNN_UNPREDICTABLE(a0 != zero) {
65 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
66 }
67 const int8_t* restrict a1 = a[1];
68 if XNN_UNPREDICTABLE(a1 != zero) {
69 a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
70 }
71 const int8_t* restrict a2 = a[2];
72 if XNN_UNPREDICTABLE(a2 != zero) {
73 a2 = (const int8_t*) ((uintptr_t) a2 + a_offset);
74 }
75 a += 3;
76
77 size_t k = kc;
78
79
80 while (k >= 8 * sizeof(int8_t)) {
81 const int16x4x4_t va0 = vld4_dup_s16((const void*)a0); a0 += 8;
82 const int16x4x4_t va1 = vld4_dup_s16((const void*)a1); a1 += 8;
83 const int16x4x4_t va2 = vld4_dup_s16((const void*)a2); a2 += 8;
84
85 const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
86 const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
87 const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
88 const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
89 const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
90 const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
91 const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
92 const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
93
94 const int8x8_t va0c0 = vreinterpret_s8_s16(va0.val[0]);
95 const int8x8_t va1c0 = vreinterpret_s8_s16(va1.val[0]);
96 const int8x8_t va2c0 = vreinterpret_s8_s16(va2.val[0]);
97
98 const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
99 const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
100 const int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0, va2c0);
101 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
102 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
103 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
104 const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
105 const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
106 const int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0, va2c0);
107 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
108 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
109 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
110 const int8x8_t va0c1 = vreinterpret_s8_s16(va0.val[1]);
111 const int8x8_t va1c1 = vreinterpret_s8_s16(va1.val[1]);
112 const int8x8_t va2c1 = vreinterpret_s8_s16(va2.val[1]);
113
114 const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
115 const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
116 const int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1, va2c1);
117 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
118 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
119 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
120 const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
121 const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
122 const int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1, va2c1);
123 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
124 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
125 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
126 const int8x8_t va0c2 = vreinterpret_s8_s16(va0.val[2]);
127 const int8x8_t va1c2 = vreinterpret_s8_s16(va1.val[2]);
128 const int8x8_t va2c2 = vreinterpret_s8_s16(va2.val[2]);
129
130 const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
131 const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
132 const int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2, va2c2);
133 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
134 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
135 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
136 const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
137 const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
138 const int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2, va2c2);
139 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
140 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
141 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
142 const int8x8_t va0c3 = vreinterpret_s8_s16(va0.val[3]);
143 const int8x8_t va1c3 = vreinterpret_s8_s16(va1.val[3]);
144 const int8x8_t va2c3 = vreinterpret_s8_s16(va2.val[3]);
145
146 const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3);
147 const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, va1c3);
148 const int16x8_t vprod2x0123c3 = vmull_s8(vb0123c3, va2c3);
149 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
150 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
151 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c3);
152 const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3);
153 const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, va1c3);
154 const int16x8_t vprod2x4567c3 = vmull_s8(vb4567c3, va2c3);
155 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
156 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
157 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c3);
158
159 k -= 8 * sizeof(int8_t);
160 }
161
162 if XNN_UNLIKELY(k != 0) {
163 const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
164 const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
165 const int8x8_t va2 = vld1_s8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k);
166
167 const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
168 const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
169
170 const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
171 const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
172 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
173 const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
174 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
175 const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0));
176 const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
177 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
178 const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
179 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
180 const int8x8_t va2c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 0));
181 const int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0, va2c0);
182 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
183 const int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0, va2c0);
184 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
185
186 if (k > 2 * sizeof(int8_t)) {
187 const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
188 const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
189
190 const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
191 const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
192 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
193 const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
194 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
195 const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1));
196 const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
197 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
198 const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
199 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
200 const int8x8_t va2c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 1));
201 const int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1, va2c1);
202 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
203 const int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1, va2c1);
204 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
205
206 if (k > 4 * sizeof(int8_t)) {
207 const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
208 const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
209
210 const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
211 const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
212 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
213 const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
214 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
215 const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2));
216 const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
217 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
218 const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
219 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
220 const int8x8_t va2c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 2));
221 const int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2, va2c2);
222 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
223 const int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2, va2c2);
224 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
225 }
226 }
227 }
228 p -= 3 * sizeof(void*);
229 } while (p != 0);
230
231 const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift);
232 const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier);
233 const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift);
234
235 vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
236 vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
237 vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
238 vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
239 vacc2x0123 = vqshlq_s32(vacc2x0123, vright_pre_shift);
240 vacc2x4567 = vqshlq_s32(vacc2x4567, vright_pre_shift);
241
242 vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
243 vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
244 vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
245 vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
246 vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier);
247 vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier);
248
249 vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
250 vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
251 vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
252 vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
253 vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift);
254 vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift);
255
256 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point);
257 #if XNN_ARCH_ARM64
258 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
259 int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
260 int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567);
261
262 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
263 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
264 vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
265
266 int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567);
267 int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567);
268 #else
269 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
270 int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
271 int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567));
272
273 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
274 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
275 vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
276
277 int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567));
278 int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567);
279 #endif
280
281 const int8x16_t voutput_min = vld1q_dup_s8(¶ms->rndnu_neon.output_min);
282 vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min);
283 vout2x01234567 = vmax_s8(vout2x01234567, vget_low_s8(voutput_min));
284
285 const int8x16_t voutput_max = vld1q_dup_s8(¶ms->rndnu_neon.output_max);
286 vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max);
287 vout2x01234567 = vmin_s8(vout2x01234567, vget_low_s8(voutput_max));
288
289 if (nc >= 8) {
290 vst1_s8(c2 + 0, vout2x01234567);
291 vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567));
292 vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567));
293
294 c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
295 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
296 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
297
298 a = (const int8_t**restrict) ((uintptr_t) a - ks);
299
300 nc -= 8;
301 } else {
302 if (nc & 4) {
303 vst1_lane_u32((void*) c2, vreinterpret_u32_s8(vout2x01234567), 0); c2 += 4;
304 vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
305 vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
306 vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 4);
307 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
308 }
309 if (nc & 2) {
310 vst1_lane_u16((void*) c2, vreinterpret_u16_s8(vout2x01234567), 0); c2 += 2;
311 vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
312 vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
313 vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 2);
314 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
315 }
316 if (nc & 1) {
317 vst1_lane_s8(c2, vout2x01234567, 0);
318 vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
319 vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
320 }
321
322 nc = 0;
323 }
324 } while (nc != 0);
325 }
326