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