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_3x16c2__neon_mull_ld2r(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_3x16c2__neon_mull_ld2r(
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 vacc0x89AB = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
57 int32x4_t vacc0xCDEF = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
58 int32x4_t vacc1x0123 = vacc0x0123;
59 int32x4_t vacc1x4567 = vacc0x4567;
60 int32x4_t vacc1x89AB = vacc0x89AB;
61 int32x4_t vacc1xCDEF = vacc0xCDEF;
62 int32x4_t vacc2x0123 = vacc0x0123;
63 int32x4_t vacc2x4567 = vacc0x4567;
64 int32x4_t vacc2x89AB = vacc0x89AB;
65 int32x4_t vacc2xCDEF = 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 }
73 const int8_t* restrict a1 = a[1];
74 if XNN_UNPREDICTABLE(a1 != zero) {
75 a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
76 }
77 const int8_t* restrict a2 = a[2];
78 if XNN_UNPREDICTABLE(a2 != zero) {
79 a2 = (const int8_t*) ((uintptr_t) a2 + a_offset);
80 }
81 a += 3;
82
83 size_t k = kc;
84
85
86 while (k >= 8 * sizeof(int8_t)) {
87 const int16x4x2_t va00 = vld2_dup_s16((const void*)a0);
88 const int16x4x2_t va01 = vld2_dup_s16((const void*)(a0 + 4)); a0 += 8;
89 const int16x4x2_t va10 = vld2_dup_s16((const void*)a1);
90 const int16x4x2_t va11 = vld2_dup_s16((const void*)(a1 + 4)); a1 += 8;
91 const int16x4x2_t va20 = vld2_dup_s16((const void*)a2);
92 const int16x4x2_t va21 = vld2_dup_s16((const void*)(a2 + 4)); a2 += 8;
93
94 const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
95 const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
96 const int8x8_t vb89ABc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
97 const int8x8_t vbCDEFc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
98 const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
99 const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
100 const int8x8_t vb89ABc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
101 const int8x8_t vbCDEFc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
102 const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
103 const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
104 const int8x8_t vb89ABc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
105 const int8x8_t vbCDEFc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
106 const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
107 const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
108 const int8x8_t vb89ABc3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
109 const int8x8_t vbCDEFc3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
110
111 const int8x8_t va0c0 = vreinterpret_s8_s16(va00.val[0]);
112 const int8x8_t va1c0 = vreinterpret_s8_s16(va10.val[0]);
113 const int8x8_t va2c0 = vreinterpret_s8_s16(va20.val[0]);
114
115 const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
116 const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
117 const int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0, va2c0);
118 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
119 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
120 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
121 const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
122 const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
123 const int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0, va2c0);
124 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
125 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
126 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
127 const int16x8_t vprod0x89ABc0 = vmull_s8(vb89ABc0, va0c0);
128 const int16x8_t vprod1x89ABc0 = vmull_s8(vb89ABc0, va1c0);
129 const int16x8_t vprod2x89ABc0 = vmull_s8(vb89ABc0, va2c0);
130 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc0);
131 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc0);
132 vacc2x89AB = vpadalq_s16(vacc2x89AB, vprod2x89ABc0);
133 const int16x8_t vprod0xCDEFc0 = vmull_s8(vbCDEFc0, va0c0);
134 const int16x8_t vprod1xCDEFc0 = vmull_s8(vbCDEFc0, va1c0);
135 const int16x8_t vprod2xCDEFc0 = vmull_s8(vbCDEFc0, va2c0);
136 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc0);
137 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc0);
138 vacc2xCDEF = vpadalq_s16(vacc2xCDEF, vprod2xCDEFc0);
139 const int8x8_t va0c1 = vreinterpret_s8_s16(va00.val[1]);
140 const int8x8_t va1c1 = vreinterpret_s8_s16(va10.val[1]);
141 const int8x8_t va2c1 = vreinterpret_s8_s16(va20.val[1]);
142
143 const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
144 const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
145 const int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1, va2c1);
146 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
147 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
148 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
149 const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
150 const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
151 const int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1, va2c1);
152 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
153 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
154 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
155 const int16x8_t vprod0x89ABc1 = vmull_s8(vb89ABc1, va0c1);
156 const int16x8_t vprod1x89ABc1 = vmull_s8(vb89ABc1, va1c1);
157 const int16x8_t vprod2x89ABc1 = vmull_s8(vb89ABc1, va2c1);
158 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc1);
159 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc1);
160 vacc2x89AB = vpadalq_s16(vacc2x89AB, vprod2x89ABc1);
161 const int16x8_t vprod0xCDEFc1 = vmull_s8(vbCDEFc1, va0c1);
162 const int16x8_t vprod1xCDEFc1 = vmull_s8(vbCDEFc1, va1c1);
163 const int16x8_t vprod2xCDEFc1 = vmull_s8(vbCDEFc1, va2c1);
164 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc1);
165 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc1);
166 vacc2xCDEF = vpadalq_s16(vacc2xCDEF, vprod2xCDEFc1);
167 const int8x8_t va0c2 = vreinterpret_s8_s16(va01.val[0]);
168 const int8x8_t va1c2 = vreinterpret_s8_s16(va11.val[0]);
169 const int8x8_t va2c2 = vreinterpret_s8_s16(va21.val[0]);
170
171 const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
172 const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
173 const int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2, va2c2);
174 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
175 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
176 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
177 const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
178 const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
179 const int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2, va2c2);
180 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
181 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
182 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
183 const int16x8_t vprod0x89ABc2 = vmull_s8(vb89ABc2, va0c2);
184 const int16x8_t vprod1x89ABc2 = vmull_s8(vb89ABc2, va1c2);
185 const int16x8_t vprod2x89ABc2 = vmull_s8(vb89ABc2, va2c2);
186 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc2);
187 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc2);
188 vacc2x89AB = vpadalq_s16(vacc2x89AB, vprod2x89ABc2);
189 const int16x8_t vprod0xCDEFc2 = vmull_s8(vbCDEFc2, va0c2);
190 const int16x8_t vprod1xCDEFc2 = vmull_s8(vbCDEFc2, va1c2);
191 const int16x8_t vprod2xCDEFc2 = vmull_s8(vbCDEFc2, va2c2);
192 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc2);
193 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc2);
194 vacc2xCDEF = vpadalq_s16(vacc2xCDEF, vprod2xCDEFc2);
195 const int8x8_t va0c3 = vreinterpret_s8_s16(va01.val[1]);
196 const int8x8_t va1c3 = vreinterpret_s8_s16(va11.val[1]);
197 const int8x8_t va2c3 = vreinterpret_s8_s16(va21.val[1]);
198
199 const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3);
200 const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, va1c3);
201 const int16x8_t vprod2x0123c3 = vmull_s8(vb0123c3, va2c3);
202 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
203 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
204 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c3);
205 const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3);
206 const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, va1c3);
207 const int16x8_t vprod2x4567c3 = vmull_s8(vb4567c3, va2c3);
208 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
209 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
210 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c3);
211 const int16x8_t vprod0x89ABc3 = vmull_s8(vb89ABc3, va0c3);
212 const int16x8_t vprod1x89ABc3 = vmull_s8(vb89ABc3, va1c3);
213 const int16x8_t vprod2x89ABc3 = vmull_s8(vb89ABc3, va2c3);
214 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc3);
215 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc3);
216 vacc2x89AB = vpadalq_s16(vacc2x89AB, vprod2x89ABc3);
217 const int16x8_t vprod0xCDEFc3 = vmull_s8(vbCDEFc3, va0c3);
218 const int16x8_t vprod1xCDEFc3 = vmull_s8(vbCDEFc3, va1c3);
219 const int16x8_t vprod2xCDEFc3 = vmull_s8(vbCDEFc3, va2c3);
220 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc3);
221 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc3);
222 vacc2xCDEF = vpadalq_s16(vacc2xCDEF, vprod2xCDEFc3);
223
224 k -= 8 * sizeof(int8_t);
225 }
226
227 if XNN_UNLIKELY(k != 0) {
228 const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
229 const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
230 const int8x8_t va2 = vld1_s8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k);
231
232 const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
233 const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
234 const int8x8_t vb89ABc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
235 const int8x8_t vbCDEFc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
236
237 const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
238 const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
239 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
240 const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
241 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
242 const int16x8_t vprod0x89ABc0 = vmull_s8(vb89ABc0, va0c0);
243 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc0);
244 const int16x8_t vprod0xCDEFc0 = vmull_s8(vbCDEFc0, va0c0);
245 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc0);
246 const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0));
247 const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
248 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
249 const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
250 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
251 const int16x8_t vprod1x89ABc0 = vmull_s8(vb89ABc0, va1c0);
252 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc0);
253 const int16x8_t vprod1xCDEFc0 = vmull_s8(vbCDEFc0, va1c0);
254 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc0);
255 const int8x8_t va2c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 0));
256 const int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0, va2c0);
257 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
258 const int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0, va2c0);
259 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
260 const int16x8_t vprod2x89ABc0 = vmull_s8(vb89ABc0, va2c0);
261 vacc2x89AB = vpadalq_s16(vacc2x89AB, vprod2x89ABc0);
262 const int16x8_t vprod2xCDEFc0 = vmull_s8(vbCDEFc0, va2c0);
263 vacc2xCDEF = vpadalq_s16(vacc2xCDEF, vprod2xCDEFc0);
264
265 if (k > 2 * sizeof(int8_t)) {
266 const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
267 const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
268 const int8x8_t vb89ABc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
269 const int8x8_t vbCDEFc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
270
271 const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
272 const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
273 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
274 const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
275 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
276 const int16x8_t vprod0x89ABc1 = vmull_s8(vb89ABc1, va0c1);
277 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc1);
278 const int16x8_t vprod0xCDEFc1 = vmull_s8(vbCDEFc1, va0c1);
279 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc1);
280 const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1));
281 const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
282 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
283 const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
284 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
285 const int16x8_t vprod1x89ABc1 = vmull_s8(vb89ABc1, va1c1);
286 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc1);
287 const int16x8_t vprod1xCDEFc1 = vmull_s8(vbCDEFc1, va1c1);
288 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc1);
289 const int8x8_t va2c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 1));
290 const int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1, va2c1);
291 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
292 const int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1, va2c1);
293 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
294 const int16x8_t vprod2x89ABc1 = vmull_s8(vb89ABc1, va2c1);
295 vacc2x89AB = vpadalq_s16(vacc2x89AB, vprod2x89ABc1);
296 const int16x8_t vprod2xCDEFc1 = vmull_s8(vbCDEFc1, va2c1);
297 vacc2xCDEF = vpadalq_s16(vacc2xCDEF, vprod2xCDEFc1);
298
299 if (k > 4 * sizeof(int8_t)) {
300 const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
301 const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
302 const int8x8_t vb89ABc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
303 const int8x8_t vbCDEFc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
304
305 const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
306 const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
307 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
308 const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
309 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
310 const int16x8_t vprod0x89ABc2 = vmull_s8(vb89ABc2, va0c2);
311 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc2);
312 const int16x8_t vprod0xCDEFc2 = vmull_s8(vbCDEFc2, va0c2);
313 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc2);
314 const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2));
315 const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
316 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
317 const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
318 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
319 const int16x8_t vprod1x89ABc2 = vmull_s8(vb89ABc2, va1c2);
320 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc2);
321 const int16x8_t vprod1xCDEFc2 = vmull_s8(vbCDEFc2, va1c2);
322 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc2);
323 const int8x8_t va2c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 2));
324 const int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2, va2c2);
325 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
326 const int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2, va2c2);
327 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
328 const int16x8_t vprod2x89ABc2 = vmull_s8(vb89ABc2, va2c2);
329 vacc2x89AB = vpadalq_s16(vacc2x89AB, vprod2x89ABc2);
330 const int16x8_t vprod2xCDEFc2 = vmull_s8(vbCDEFc2, va2c2);
331 vacc2xCDEF = vpadalq_s16(vacc2xCDEF, vprod2xCDEFc2);
332 }
333 }
334 }
335 p -= 3 * sizeof(void*);
336 } while (p != 0);
337
338 const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift);
339 const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier);
340 const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift);
341
342 vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
343 vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
344 vacc0x89AB = vqshlq_s32(vacc0x89AB, vright_pre_shift);
345 vacc0xCDEF = vqshlq_s32(vacc0xCDEF, vright_pre_shift);
346 vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
347 vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
348 vacc1x89AB = vqshlq_s32(vacc1x89AB, vright_pre_shift);
349 vacc1xCDEF = vqshlq_s32(vacc1xCDEF, vright_pre_shift);
350 vacc2x0123 = vqshlq_s32(vacc2x0123, vright_pre_shift);
351 vacc2x4567 = vqshlq_s32(vacc2x4567, vright_pre_shift);
352 vacc2x89AB = vqshlq_s32(vacc2x89AB, vright_pre_shift);
353 vacc2xCDEF = vqshlq_s32(vacc2xCDEF, vright_pre_shift);
354
355 vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
356 vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
357 vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier);
358 vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier);
359 vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
360 vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
361 vacc1x89AB = vqdmulhq_s32(vacc1x89AB, vmultiplier);
362 vacc1xCDEF = vqdmulhq_s32(vacc1xCDEF, vmultiplier);
363 vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier);
364 vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier);
365 vacc2x89AB = vqdmulhq_s32(vacc2x89AB, vmultiplier);
366 vacc2xCDEF = vqdmulhq_s32(vacc2xCDEF, vmultiplier);
367
368 vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
369 vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
370 vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift);
371 vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift);
372 vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
373 vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
374 vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_post_shift);
375 vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_post_shift);
376 vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift);
377 vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift);
378 vacc2x89AB = vrshlq_s32(vacc2x89AB, vright_post_shift);
379 vacc2xCDEF = vrshlq_s32(vacc2xCDEF, vright_post_shift);
380
381 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point);
382 #if XNN_ARCH_ARM64
383 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
384 int16x8_t vacc0x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF);
385 int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
386 int16x8_t vacc1x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF);
387 int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567);
388 int16x8_t vacc2x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc2x89AB), vacc2xCDEF);
389
390 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
391 vacc0x89ABCDEF = vqaddq_s16(vacc0x89ABCDEF, voutput_zero_point);
392 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
393 vacc1x89ABCDEF = vqaddq_s16(vacc1x89ABCDEF, voutput_zero_point);
394 vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
395 vacc2x89ABCDEF = vqaddq_s16(vacc2x89ABCDEF, voutput_zero_point);
396
397 int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF);
398 int8x16_t vout1x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc1x01234567), vacc1x89ABCDEF);
399 int8x16_t vout2x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc2x89ABCDEF);
400 #else
401 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
402 int16x8_t vacc0x89ABCDEF = vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF));
403 int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
404 int16x8_t vacc1x89ABCDEF = vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF));
405 int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567));
406 int16x8_t vacc2x89ABCDEF = vcombine_s16(vqmovn_s32(vacc2x89AB), vqmovn_s32(vacc2xCDEF));
407
408 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
409 vacc0x89ABCDEF = vqaddq_s16(vacc0x89ABCDEF, voutput_zero_point);
410 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
411 vacc1x89ABCDEF = vqaddq_s16(vacc1x89ABCDEF, voutput_zero_point);
412 vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
413 vacc2x89ABCDEF = vqaddq_s16(vacc2x89ABCDEF, voutput_zero_point);
414
415 int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF));
416 int8x16_t vout1x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc1x01234567), vqmovn_s16(vacc1x89ABCDEF));
417 int8x16_t vout2x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc2x89ABCDEF));
418 #endif
419
420 const int8x16_t voutput_min = vld1q_dup_s8(¶ms->rndnu_neon.output_min);
421 vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min);
422 vout1x0123456789ABCDEF = vmaxq_s8(vout1x0123456789ABCDEF, voutput_min);
423 vout2x0123456789ABCDEF = vmaxq_s8(vout2x0123456789ABCDEF, voutput_min);
424
425 const int8x16_t voutput_max = vld1q_dup_s8(¶ms->rndnu_neon.output_max);
426 vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max);
427 vout1x0123456789ABCDEF = vminq_s8(vout1x0123456789ABCDEF, voutput_max);
428 vout2x0123456789ABCDEF = vminq_s8(vout2x0123456789ABCDEF, voutput_max);
429
430 if (nc >= 16) {
431 vst1q_s8(c2 + 0, vout2x0123456789ABCDEF);
432 vst1q_s8(c1 + 0, vout1x0123456789ABCDEF);
433 vst1q_s8(c0 + 0, vout0x0123456789ABCDEF);
434
435 c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
436 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
437 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
438
439 a = (const int8_t**restrict) ((uintptr_t) a - ks);
440
441 nc -= 16;
442 } else {
443 int8x8_t vout2x01234567 = vget_low_s8(vout2x0123456789ABCDEF);
444 int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vget_low_s8(vout0x0123456789ABCDEF), vget_low_s8(vout1x0123456789ABCDEF));
445 if (nc & 8) {
446 vst1_s8(c2, vout2x01234567); c2 += 8;
447 vst1_s8(c1, vget_high_s8(vout0x01234567_1x01234567)); c1 += 8;
448 vst1_s8(c0, vget_low_s8(vout0x01234567_1x01234567)); c0 += 8;
449 vout2x01234567 = vget_high_s8(vout2x0123456789ABCDEF);
450 vout0x01234567_1x01234567 = vcombine_s8(vget_high_s8(vout0x0123456789ABCDEF), vget_high_s8(vout1x0123456789ABCDEF));
451 }
452 if (nc & 4) {
453 vst1_lane_u32((void*) c2, vreinterpret_u32_s8(vout2x01234567), 0); c2 += 4;
454 vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
455 vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
456 vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 4);
457 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
458 }
459 if (nc & 2) {
460 vst1_lane_u16((void*) c2, vreinterpret_u16_s8(vout2x01234567), 0); c2 += 2;
461 vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
462 vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
463 vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 2);
464 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
465 }
466 if (nc & 1) {
467 vst1_lane_s8(c2, vout2x01234567, 0);
468 vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
469 vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
470 }
471
472 nc = 0;
473 }
474 } while (nc != 0);
475 }
476