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