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