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_mlal_ld1r(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_mlal_ld1r(
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 while (k >= 16 * sizeof(int8_t)) {
80 const int16x4_t va00x0 = vld1_dup_s16((const void*)a0);
81 const int16x4_t va01x0 = vld1_dup_s16((const void*)(a0 + 2));
82 const int16x4_t va02x0 = vld1_dup_s16((const void*)(a0 + 4));
83 const int16x4_t va03x0 = vld1_dup_s16((const void*)(a0 + 6)); a0 += 8;
84 const int16x4_t va00x1 = vld1_dup_s16((const void*)a0);
85 const int16x4_t va01x1 = vld1_dup_s16((const void*)(a0 + 2));
86 const int16x4_t va02x1 = vld1_dup_s16((const void*)(a0 + 4));
87 const int16x4_t va03x1 = vld1_dup_s16((const void*)(a0 + 6)); a0 += 8;
88 const int16x4_t va10x0 = vld1_dup_s16((const void*)a1);
89 const int16x4_t va11x0 = vld1_dup_s16((const void*)(a1 + 2));
90 const int16x4_t va12x0 = vld1_dup_s16((const void*)(a1 + 4));
91 const int16x4_t va13x0 = vld1_dup_s16((const void*)(a1 + 6)); a1 += 8;
92 const int16x4_t va10x1 = vld1_dup_s16((const void*)a1);
93 const int16x4_t va11x1 = vld1_dup_s16((const void*)(a1 + 2));
94 const int16x4_t va12x1 = vld1_dup_s16((const void*)(a1 + 4));
95 const int16x4_t va13x1 = vld1_dup_s16((const void*)(a1 + 6)); a1 += 8;
96 const int16x4_t va20x0 = vld1_dup_s16((const void*)a2);
97 const int16x4_t va21x0 = vld1_dup_s16((const void*)(a2 + 2));
98 const int16x4_t va22x0 = vld1_dup_s16((const void*)(a2 + 4));
99 const int16x4_t va23x0 = vld1_dup_s16((const void*)(a2 + 6)); a2 += 8;
100 const int16x4_t va20x1 = vld1_dup_s16((const void*)a2);
101 const int16x4_t va21x1 = vld1_dup_s16((const void*)(a2 + 2));
102 const int16x4_t va22x1 = vld1_dup_s16((const void*)(a2 + 4));
103 const int16x4_t va23x1 = vld1_dup_s16((const void*)(a2 + 6)); a2 += 8;
104
105 const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
106 const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
107 const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
108 const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
109 const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
110 const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
111 const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
112 const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
113
114 const int8x8_t va0c0x0 = vreinterpret_s8_s16(va00x0);
115 const int8x8_t va0c0x1 = vreinterpret_s8_s16(va00x1);
116 const int8x8_t va1c0x0 = vreinterpret_s8_s16(va10x0);
117 const int8x8_t va1c0x1 = vreinterpret_s8_s16(va10x1);
118 const int8x8_t va2c0x0 = vreinterpret_s8_s16(va20x0);
119 const int8x8_t va2c0x1 = vreinterpret_s8_s16(va20x1);
120
121 int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0c0x0);
122 int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1c0x0);
123 int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0x0, va2c0x0);
124 const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
125 vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0c0x1);
126 vprod1x0123c0 = vmlal_s8(vprod1x0123c0, vb0123c0x1, va1c0x1);
127 vprod2x0123c0 = vmlal_s8(vprod2x0123c0, vb0123c0x1, va2c0x1);
128 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
129 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
130 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
131 int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0c0x0);
132 int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1c0x0);
133 int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0x0, va2c0x0);
134 const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
135 vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0c0x1);
136 vprod1x4567c0 = vmlal_s8(vprod1x4567c0, vb4567c0x1, va1c0x1);
137 vprod2x4567c0 = vmlal_s8(vprod2x4567c0, vb4567c0x1, va2c0x1);
138 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
139 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
140 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
141 const int8x8_t va0c1x0 = vreinterpret_s8_s16(va01x0);
142 const int8x8_t va0c1x1 = vreinterpret_s8_s16(va01x1);
143 const int8x8_t va1c1x0 = vreinterpret_s8_s16(va11x0);
144 const int8x8_t va1c1x1 = vreinterpret_s8_s16(va11x1);
145 const int8x8_t va2c1x0 = vreinterpret_s8_s16(va21x0);
146 const int8x8_t va2c1x1 = vreinterpret_s8_s16(va21x1);
147
148 int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0c1x0);
149 int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1c1x0);
150 int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1x0, va2c1x0);
151 const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
152 vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0c1x1);
153 vprod1x0123c1 = vmlal_s8(vprod1x0123c1, vb0123c1x1, va1c1x1);
154 vprod2x0123c1 = vmlal_s8(vprod2x0123c1, vb0123c1x1, va2c1x1);
155 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
156 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
157 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
158 int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0c1x0);
159 int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1c1x0);
160 int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1x0, va2c1x0);
161 const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
162 vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0c1x1);
163 vprod1x4567c1 = vmlal_s8(vprod1x4567c1, vb4567c1x1, va1c1x1);
164 vprod2x4567c1 = vmlal_s8(vprod2x4567c1, vb4567c1x1, va2c1x1);
165 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
166 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
167 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
168 const int8x8_t va0c2x0 = vreinterpret_s8_s16(va02x0);
169 const int8x8_t va0c2x1 = vreinterpret_s8_s16(va02x1);
170 const int8x8_t va1c2x0 = vreinterpret_s8_s16(va12x0);
171 const int8x8_t va1c2x1 = vreinterpret_s8_s16(va12x1);
172 const int8x8_t va2c2x0 = vreinterpret_s8_s16(va22x0);
173 const int8x8_t va2c2x1 = vreinterpret_s8_s16(va22x1);
174
175 int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0c2x0);
176 int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1c2x0);
177 int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2x0, va2c2x0);
178 const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
179 vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0c2x1);
180 vprod1x0123c2 = vmlal_s8(vprod1x0123c2, vb0123c2x1, va1c2x1);
181 vprod2x0123c2 = vmlal_s8(vprod2x0123c2, vb0123c2x1, va2c2x1);
182 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
183 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
184 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
185 int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0c2x0);
186 int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1c2x0);
187 int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2x0, va2c2x0);
188 const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
189 vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0c2x1);
190 vprod1x4567c2 = vmlal_s8(vprod1x4567c2, vb4567c2x1, va1c2x1);
191 vprod2x4567c2 = vmlal_s8(vprod2x4567c2, vb4567c2x1, va2c2x1);
192 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
193 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
194 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
195 const int8x8_t va0c3x0 = vreinterpret_s8_s16(va03x0);
196 const int8x8_t va0c3x1 = vreinterpret_s8_s16(va03x1);
197 const int8x8_t va1c3x0 = vreinterpret_s8_s16(va13x0);
198 const int8x8_t va1c3x1 = vreinterpret_s8_s16(va13x1);
199 const int8x8_t va2c3x0 = vreinterpret_s8_s16(va23x0);
200 const int8x8_t va2c3x1 = vreinterpret_s8_s16(va23x1);
201
202 int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0c3x0);
203 int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1c3x0);
204 int16x8_t vprod2x0123c3 = vmull_s8(vb0123c3x0, va2c3x0);
205 const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
206 vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0c3x1);
207 vprod1x0123c3 = vmlal_s8(vprod1x0123c3, vb0123c3x1, va1c3x1);
208 vprod2x0123c3 = vmlal_s8(vprod2x0123c3, vb0123c3x1, va2c3x1);
209 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
210 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
211 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c3);
212 int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0c3x0);
213 int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1c3x0);
214 int16x8_t vprod2x4567c3 = vmull_s8(vb4567c3x0, va2c3x0);
215 const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
216 vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0c3x1);
217 vprod1x4567c3 = vmlal_s8(vprod1x4567c3, vb4567c3x1, va1c3x1);
218 vprod2x4567c3 = vmlal_s8(vprod2x4567c3, vb4567c3x1, va2c3x1);
219 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
220 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
221 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c3);
222
223 k -= 16 * sizeof(int8_t);
224 }
225
226 if (k >= 8 * sizeof(int8_t)) {
227 const int16x4_t va00 = vld1_dup_s16((const void*)a0);
228 const int16x4_t va01 = vld1_dup_s16((const void*)(a0 + 2));
229 const int16x4_t va02 = vld1_dup_s16((const void*)(a0 + 4));
230 const int16x4_t va03 = vld1_dup_s16((const void*)(a0 + 6)); a0 += 8;
231 const int16x4_t va10 = vld1_dup_s16((const void*)a1);
232 const int16x4_t va11 = vld1_dup_s16((const void*)(a1 + 2));
233 const int16x4_t va12 = vld1_dup_s16((const void*)(a1 + 4));
234 const int16x4_t va13 = vld1_dup_s16((const void*)(a1 + 6)); a1 += 8;
235 const int16x4_t va20 = vld1_dup_s16((const void*)a2);
236 const int16x4_t va21 = vld1_dup_s16((const void*)(a2 + 2));
237 const int16x4_t va22 = vld1_dup_s16((const void*)(a2 + 4));
238 const int16x4_t va23 = vld1_dup_s16((const void*)(a2 + 6)); a2 += 8;
239
240 const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
241 const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
242 const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
243 const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
244 const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
245 const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
246 const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
247 const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
248
249 const int8x8_t va0c0 = vreinterpret_s8_s16(va00);
250 const int8x8_t va1c0 = vreinterpret_s8_s16(va10);
251 const int8x8_t va2c0 = vreinterpret_s8_s16(va20);
252
253 const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
254 const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
255 const int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0, va2c0);
256 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
257 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
258 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
259 const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
260 const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
261 const int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0, va2c0);
262 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
263 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
264 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
265 const int8x8_t va0c1 = vreinterpret_s8_s16(va01);
266 const int8x8_t va1c1 = vreinterpret_s8_s16(va11);
267 const int8x8_t va2c1 = vreinterpret_s8_s16(va21);
268
269 const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
270 const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
271 const int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1, va2c1);
272 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
273 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
274 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
275 const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
276 const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
277 const int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1, va2c1);
278 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
279 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
280 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
281 const int8x8_t va0c2 = vreinterpret_s8_s16(va02);
282 const int8x8_t va1c2 = vreinterpret_s8_s16(va12);
283 const int8x8_t va2c2 = vreinterpret_s8_s16(va22);
284
285 const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
286 const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
287 const int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2, va2c2);
288 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
289 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
290 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
291 const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
292 const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
293 const int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2, va2c2);
294 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
295 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
296 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
297 const int8x8_t va0c3 = vreinterpret_s8_s16(va03);
298 const int8x8_t va1c3 = vreinterpret_s8_s16(va13);
299 const int8x8_t va2c3 = vreinterpret_s8_s16(va23);
300
301 const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3);
302 const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, va1c3);
303 const int16x8_t vprod2x0123c3 = vmull_s8(vb0123c3, va2c3);
304 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
305 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
306 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c3);
307 const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3);
308 const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, va1c3);
309 const int16x8_t vprod2x4567c3 = vmull_s8(vb4567c3, va2c3);
310 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
311 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
312 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c3);
313
314 k -= 8 * sizeof(int8_t);
315 }
316
317 if XNN_UNLIKELY(k != 0) {
318 const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
319 const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
320 const int8x8_t va2 = vld1_s8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k);
321
322 const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
323 const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
324
325 const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
326 const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
327 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
328 const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
329 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
330 const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0));
331 const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
332 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
333 const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
334 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
335 const int8x8_t va2c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 0));
336 const int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0, va2c0);
337 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
338 const int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0, va2c0);
339 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
340
341 if (k > 2 * sizeof(int8_t)) {
342 const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
343 const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
344
345 const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
346 const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
347 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
348 const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
349 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
350 const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1));
351 const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
352 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
353 const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
354 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
355 const int8x8_t va2c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 1));
356 const int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1, va2c1);
357 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
358 const int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1, va2c1);
359 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
360
361 if (k > 4 * sizeof(int8_t)) {
362 const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
363 const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
364
365 const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
366 const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
367 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
368 const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
369 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
370 const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2));
371 const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
372 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
373 const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
374 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
375 const int8x8_t va2c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 2));
376 const int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2, va2c2);
377 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
378 const int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2, va2c2);
379 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
380 }
381 }
382 }
383 p -= 3 * sizeof(void*);
384 } while (p != 0);
385
386 const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift);
387 const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier);
388 const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift);
389
390 vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
391 vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
392 vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
393 vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
394 vacc2x0123 = vqshlq_s32(vacc2x0123, vright_pre_shift);
395 vacc2x4567 = vqshlq_s32(vacc2x4567, vright_pre_shift);
396
397 vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
398 vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
399 vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
400 vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
401 vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier);
402 vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier);
403
404 vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
405 vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
406 vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
407 vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
408 vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift);
409 vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift);
410
411 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point);
412 #if XNN_ARCH_ARM64
413 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
414 int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
415 int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567);
416
417 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
418 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
419 vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
420
421 int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567);
422 int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567);
423 #else
424 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
425 int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
426 int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567));
427
428 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
429 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
430 vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
431
432 int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567));
433 int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567);
434 #endif
435
436 const int8x16_t voutput_min = vld1q_dup_s8(¶ms->rndnu_neon.output_min);
437 vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min);
438 vout2x01234567 = vmax_s8(vout2x01234567, vget_low_s8(voutput_min));
439
440 const int8x16_t voutput_max = vld1q_dup_s8(¶ms->rndnu_neon.output_max);
441 vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max);
442 vout2x01234567 = vmin_s8(vout2x01234567, vget_low_s8(voutput_max));
443
444 if (nc >= 8) {
445 vst1_s8(c2 + 0, vout2x01234567);
446 vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567));
447 vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567));
448
449 c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
450 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
451 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
452
453 a = (const int8_t**restrict) ((uintptr_t) a - ks);
454
455 nc -= 8;
456 } else {
457 if (nc & 4) {
458 vst1_lane_u32((void*) c2, vreinterpret_u32_s8(vout2x01234567), 0); c2 += 4;
459 vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
460 vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
461 vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 4);
462 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
463 }
464 if (nc & 2) {
465 vst1_lane_u16((void*) c2, vreinterpret_u16_s8(vout2x01234567), 0); c2 += 2;
466 vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
467 vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
468 vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 2);
469 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
470 }
471 if (nc & 1) {
472 vst1_lane_s8(c2, vout2x01234567, 0);
473 vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
474 vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
475 }
476
477 nc = 0;
478 }
479 } while (nc != 0);
480 }
481