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