• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-gemm/c4-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 
17 
xnn_qs8_gemm_minmax_rndnu_ukernel_3x8c4__neon_mlal_dup(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)])18 void xnn_qs8_gemm_minmax_rndnu_ukernel_3x8c4__neon_mlal_dup(
19     size_t mr,
20     size_t nc,
21     size_t kc,
22     const int8_t* restrict a,
23     size_t a_stride,
24     const void* restrict w,
25     int8_t* restrict c,
26     size_t cm_stride,
27     size_t cn_stride,
28     const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
29 {
30   assert(mr != 0);
31   assert(mr <= 3);
32   assert(nc != 0);
33   assert(kc != 0);
34   assert(kc % sizeof(int8_t) == 0);
35   assert(a != NULL);
36   assert(w != NULL);
37   assert(c != NULL);
38 
39   kc = round_up_po2(kc, 4 * sizeof(int8_t));
40   const int8_t* a0 = a;
41   int8_t* c0 = c;
42   const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
43   int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
44   if XNN_UNPREDICTABLE(mr < 2) {
45     a1 = a0;
46     c1 = c0;
47   }
48   const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride);
49   int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
50   if XNN_UNPREDICTABLE(mr <= 2) {
51     a2 = a1;
52     c2 = c1;
53   }
54 
55   do {
56     int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t));
57     int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t));
58     int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t));
59     int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t));
60     int32x4_t vacc1x01 = vacc0x01;
61     int32x4_t vacc1x23 = vacc0x23;
62     int32x4_t vacc1x45 = vacc0x45;
63     int32x4_t vacc1x67 = vacc0x67;
64     int32x4_t vacc2x01 = vacc0x01;
65     int32x4_t vacc2x23 = vacc0x23;
66     int32x4_t vacc2x45 = vacc0x45;
67     int32x4_t vacc2x67 = vacc0x67;
68 
69     size_t k = kc;
70 
71     while (k >= 16 * sizeof(int8_t)) {
72       const int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
73       const int8x8_t va0x1 = vld1_s8(a0); a0 += 8;
74       const int8x8_t va1x0 = vld1_s8(a1); a1 += 8;
75       const int8x8_t va1x1 = vld1_s8(a1); a1 += 8;
76       const int8x8_t va2x0 = vld1_s8(a2); a2 += 8;
77       const int8x8_t va2x1 = vld1_s8(a2); a2 += 8;
78 
79       const int8x8_t vb01c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
80       const int8x8_t vb23c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
81       const int8x8_t vb45c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
82       const int8x8_t vb67c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
83       const int8x8_t vb01c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
84       const int8x8_t vb23c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
85       const int8x8_t vb45c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
86       const int8x8_t vb67c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
87 
88       const int8x8_t va0c0x0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0x0), 0));
89       const int8x8_t va0c0x1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0x1), 0));
90       const int8x8_t va1c0x0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1x0), 0));
91       const int8x8_t va1c0x1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1x1), 0));
92       const int8x8_t va2c0x0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va2x0), 0));
93       const int8x8_t va2c0x1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va2x1), 0));
94 
95       int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0c0x0);
96       int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1c0x0);
97       int16x8_t vprod2x01c0 = vmull_s8(vb01c0x0, va2c0x0);
98       const int8x8_t vb01c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
99       vprod0x01c0 = vmlal_s8(vprod0x01c0, vb01c0x1, va0c0x1);
100       vprod1x01c0 = vmlal_s8(vprod1x01c0, vb01c0x1, va1c0x1);
101       vprod2x01c0 = vmlal_s8(vprod2x01c0, vb01c0x1, va2c0x1);
102       vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0);
103       vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0);
104       vacc2x01 = vpadalq_s16(vacc2x01, vprod2x01c0);
105       int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0c0x0);
106       int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1c0x0);
107       int16x8_t vprod2x23c0 = vmull_s8(vb23c0x0, va2c0x0);
108       const int8x8_t vb23c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
109       vprod0x23c0 = vmlal_s8(vprod0x23c0, vb23c0x1, va0c0x1);
110       vprod1x23c0 = vmlal_s8(vprod1x23c0, vb23c0x1, va1c0x1);
111       vprod2x23c0 = vmlal_s8(vprod2x23c0, vb23c0x1, va2c0x1);
112       vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0);
113       vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0);
114       vacc2x23 = vpadalq_s16(vacc2x23, vprod2x23c0);
115       int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0c0x0);
116       int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1c0x0);
117       int16x8_t vprod2x45c0 = vmull_s8(vb45c0x0, va2c0x0);
118       const int8x8_t vb45c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
119       vprod0x45c0 = vmlal_s8(vprod0x45c0, vb45c0x1, va0c0x1);
120       vprod1x45c0 = vmlal_s8(vprod1x45c0, vb45c0x1, va1c0x1);
121       vprod2x45c0 = vmlal_s8(vprod2x45c0, vb45c0x1, va2c0x1);
122       vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0);
123       vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0);
124       vacc2x45 = vpadalq_s16(vacc2x45, vprod2x45c0);
125       int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0c0x0);
126       int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1c0x0);
127       int16x8_t vprod2x67c0 = vmull_s8(vb67c0x0, va2c0x0);
128       const int8x8_t vb67c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
129       vprod0x67c0 = vmlal_s8(vprod0x67c0, vb67c0x1, va0c0x1);
130       vprod1x67c0 = vmlal_s8(vprod1x67c0, vb67c0x1, va1c0x1);
131       vprod2x67c0 = vmlal_s8(vprod2x67c0, vb67c0x1, va2c0x1);
132       vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0);
133       vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0);
134       vacc2x67 = vpadalq_s16(vacc2x67, vprod2x67c0);
135       const int8x8_t va0c1x0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0x0), 1));
136       const int8x8_t va0c1x1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0x1), 1));
137       const int8x8_t va1c1x0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1x0), 1));
138       const int8x8_t va1c1x1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1x1), 1));
139       const int8x8_t va2c1x0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va2x0), 1));
140       const int8x8_t va2c1x1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va2x1), 1));
141 
142       int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0c1x0);
143       int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1c1x0);
144       int16x8_t vprod2x01c1 = vmull_s8(vb01c1x0, va2c1x0);
145       const int8x8_t vb01c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
146       vprod0x01c1 = vmlal_s8(vprod0x01c1, vb01c1x1, va0c1x1);
147       vprod1x01c1 = vmlal_s8(vprod1x01c1, vb01c1x1, va1c1x1);
148       vprod2x01c1 = vmlal_s8(vprod2x01c1, vb01c1x1, va2c1x1);
149       vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1);
150       vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1);
151       vacc2x01 = vpadalq_s16(vacc2x01, vprod2x01c1);
152       int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0c1x0);
153       int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1c1x0);
154       int16x8_t vprod2x23c1 = vmull_s8(vb23c1x0, va2c1x0);
155       const int8x8_t vb23c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
156       vprod0x23c1 = vmlal_s8(vprod0x23c1, vb23c1x1, va0c1x1);
157       vprod1x23c1 = vmlal_s8(vprod1x23c1, vb23c1x1, va1c1x1);
158       vprod2x23c1 = vmlal_s8(vprod2x23c1, vb23c1x1, va2c1x1);
159       vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1);
160       vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1);
161       vacc2x23 = vpadalq_s16(vacc2x23, vprod2x23c1);
162       int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0c1x0);
163       int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1c1x0);
164       int16x8_t vprod2x45c1 = vmull_s8(vb45c1x0, va2c1x0);
165       const int8x8_t vb45c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
166       vprod0x45c1 = vmlal_s8(vprod0x45c1, vb45c1x1, va0c1x1);
167       vprod1x45c1 = vmlal_s8(vprod1x45c1, vb45c1x1, va1c1x1);
168       vprod2x45c1 = vmlal_s8(vprod2x45c1, vb45c1x1, va2c1x1);
169       vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1);
170       vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1);
171       vacc2x45 = vpadalq_s16(vacc2x45, vprod2x45c1);
172       int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0c1x0);
173       int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1c1x0);
174       int16x8_t vprod2x67c1 = vmull_s8(vb67c1x0, va2c1x0);
175       const int8x8_t vb67c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
176       vprod0x67c1 = vmlal_s8(vprod0x67c1, vb67c1x1, va0c1x1);
177       vprod1x67c1 = vmlal_s8(vprod1x67c1, vb67c1x1, va1c1x1);
178       vprod2x67c1 = vmlal_s8(vprod2x67c1, vb67c1x1, va2c1x1);
179       vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1);
180       vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1);
181       vacc2x67 = vpadalq_s16(vacc2x67, vprod2x67c1);
182 
183       k -= 16 * sizeof(int8_t);
184     }
185 
186     if (k >= 8 * sizeof(int8_t)) {
187       const int8x8_t va0 = vld1_s8(a0); a0 += 8;
188       const int8x8_t va1 = vld1_s8(a1); a1 += 8;
189       const int8x8_t va2 = vld1_s8(a2); a2 += 8;
190 
191       const int8x8_t vb01c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
192       const int8x8_t vb23c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
193       const int8x8_t vb45c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
194       const int8x8_t vb67c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
195       const int8x8_t vb01c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
196       const int8x8_t vb23c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
197       const int8x8_t vb45c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
198       const int8x8_t vb67c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
199 
200       const int8x8_t va0c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0), 0));
201       const int8x8_t va1c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1), 0));
202       const int8x8_t va2c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va2), 0));
203 
204       const int16x8_t vprod0x01c0 = vmull_s8(vb01c0, va0c0);
205       const int16x8_t vprod1x01c0 = vmull_s8(vb01c0, va1c0);
206       const int16x8_t vprod2x01c0 = vmull_s8(vb01c0, va2c0);
207       vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0);
208       vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0);
209       vacc2x01 = vpadalq_s16(vacc2x01, vprod2x01c0);
210       const int16x8_t vprod0x23c0 = vmull_s8(vb23c0, va0c0);
211       const int16x8_t vprod1x23c0 = vmull_s8(vb23c0, va1c0);
212       const int16x8_t vprod2x23c0 = vmull_s8(vb23c0, va2c0);
213       vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0);
214       vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0);
215       vacc2x23 = vpadalq_s16(vacc2x23, vprod2x23c0);
216       const int16x8_t vprod0x45c0 = vmull_s8(vb45c0, va0c0);
217       const int16x8_t vprod1x45c0 = vmull_s8(vb45c0, va1c0);
218       const int16x8_t vprod2x45c0 = vmull_s8(vb45c0, va2c0);
219       vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0);
220       vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0);
221       vacc2x45 = vpadalq_s16(vacc2x45, vprod2x45c0);
222       const int16x8_t vprod0x67c0 = vmull_s8(vb67c0, va0c0);
223       const int16x8_t vprod1x67c0 = vmull_s8(vb67c0, va1c0);
224       const int16x8_t vprod2x67c0 = vmull_s8(vb67c0, va2c0);
225       vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0);
226       vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0);
227       vacc2x67 = vpadalq_s16(vacc2x67, vprod2x67c0);
228       const int8x8_t va0c1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0), 1));
229       const int8x8_t va1c1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1), 1));
230       const int8x8_t va2c1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va2), 1));
231 
232       const int16x8_t vprod0x01c1 = vmull_s8(vb01c1, va0c1);
233       const int16x8_t vprod1x01c1 = vmull_s8(vb01c1, va1c1);
234       const int16x8_t vprod2x01c1 = vmull_s8(vb01c1, va2c1);
235       vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1);
236       vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1);
237       vacc2x01 = vpadalq_s16(vacc2x01, vprod2x01c1);
238       const int16x8_t vprod0x23c1 = vmull_s8(vb23c1, va0c1);
239       const int16x8_t vprod1x23c1 = vmull_s8(vb23c1, va1c1);
240       const int16x8_t vprod2x23c1 = vmull_s8(vb23c1, va2c1);
241       vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1);
242       vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1);
243       vacc2x23 = vpadalq_s16(vacc2x23, vprod2x23c1);
244       const int16x8_t vprod0x45c1 = vmull_s8(vb45c1, va0c1);
245       const int16x8_t vprod1x45c1 = vmull_s8(vb45c1, va1c1);
246       const int16x8_t vprod2x45c1 = vmull_s8(vb45c1, va2c1);
247       vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1);
248       vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1);
249       vacc2x45 = vpadalq_s16(vacc2x45, vprod2x45c1);
250       const int16x8_t vprod0x67c1 = vmull_s8(vb67c1, va0c1);
251       const int16x8_t vprod1x67c1 = vmull_s8(vb67c1, va1c1);
252       const int16x8_t vprod2x67c1 = vmull_s8(vb67c1, va2c1);
253       vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1);
254       vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1);
255       vacc2x67 = vpadalq_s16(vacc2x67, vprod2x67c1);
256 
257       k -= 8 * sizeof(int8_t);
258     }
259 
260     if XNN_UNLIKELY(k != 0) {
261       const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
262       const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
263       const int8x8_t va2 = vld1_s8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k);
264 
265       const int8x8_t vb01c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
266       const int8x8_t vb23c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
267       const int8x8_t vb45c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
268       const int8x8_t vb67c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
269 
270       const int8x8_t va0c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0), 0));
271       const int16x8_t vprod0x01c0 = vmull_s8(vb01c0, va0c0);
272       vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0);
273       const int16x8_t vprod0x23c0 = vmull_s8(vb23c0, va0c0);
274       vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0);
275       const int16x8_t vprod0x45c0 = vmull_s8(vb45c0, va0c0);
276       vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0);
277       const int16x8_t vprod0x67c0 = vmull_s8(vb67c0, va0c0);
278       vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0);
279       const int8x8_t va1c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1), 0));
280       const int16x8_t vprod1x01c0 = vmull_s8(vb01c0, va1c0);
281       vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0);
282       const int16x8_t vprod1x23c0 = vmull_s8(vb23c0, va1c0);
283       vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0);
284       const int16x8_t vprod1x45c0 = vmull_s8(vb45c0, va1c0);
285       vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0);
286       const int16x8_t vprod1x67c0 = vmull_s8(vb67c0, va1c0);
287       vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0);
288       const int8x8_t va2c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va2), 0));
289       const int16x8_t vprod2x01c0 = vmull_s8(vb01c0, va2c0);
290       vacc2x01 = vpadalq_s16(vacc2x01, vprod2x01c0);
291       const int16x8_t vprod2x23c0 = vmull_s8(vb23c0, va2c0);
292       vacc2x23 = vpadalq_s16(vacc2x23, vprod2x23c0);
293       const int16x8_t vprod2x45c0 = vmull_s8(vb45c0, va2c0);
294       vacc2x45 = vpadalq_s16(vacc2x45, vprod2x45c0);
295       const int16x8_t vprod2x67c0 = vmull_s8(vb67c0, va2c0);
296       vacc2x67 = vpadalq_s16(vacc2x67, vprod2x67c0);
297     }
298 
299 #if XNN_ARCH_ARM64
300     int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23);
301     int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67);
302     int32x4_t vacc1x0123 = vpaddq_s32(vacc1x01, vacc1x23);
303     int32x4_t vacc1x4567 = vpaddq_s32(vacc1x45, vacc1x67);
304     int32x4_t vacc2x0123 = vpaddq_s32(vacc2x01, vacc2x23);
305     int32x4_t vacc2x4567 = vpaddq_s32(vacc2x45, vacc2x67);
306 #else
307     const int32x2_t vsum0x01 = vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01));
308     const int32x2_t vsum0x23 = vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23));
309     int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23);
310     const int32x2_t vsum0x45 = vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45));
311     const int32x2_t vsum0x67 = vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67));
312     int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67);
313     const int32x2_t vsum1x01 = vpadd_s32(vget_low_s32(vacc1x01), vget_high_s32(vacc1x01));
314     const int32x2_t vsum1x23 = vpadd_s32(vget_low_s32(vacc1x23), vget_high_s32(vacc1x23));
315     int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23);
316     const int32x2_t vsum1x45 = vpadd_s32(vget_low_s32(vacc1x45), vget_high_s32(vacc1x45));
317     const int32x2_t vsum1x67 = vpadd_s32(vget_low_s32(vacc1x67), vget_high_s32(vacc1x67));
318     int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67);
319     const int32x2_t vsum2x01 = vpadd_s32(vget_low_s32(vacc2x01), vget_high_s32(vacc2x01));
320     const int32x2_t vsum2x23 = vpadd_s32(vget_low_s32(vacc2x23), vget_high_s32(vacc2x23));
321     int32x4_t vacc2x0123 = vcombine_s32(vsum2x01, vsum2x23);
322     const int32x2_t vsum2x45 = vpadd_s32(vget_low_s32(vacc2x45), vget_high_s32(vacc2x45));
323     const int32x2_t vsum2x67 = vpadd_s32(vget_low_s32(vacc2x67), vget_high_s32(vacc2x67));
324     int32x4_t vacc2x4567 = vcombine_s32(vsum2x45, vsum2x67);
325 #endif
326 
327     const int32x4_t vright_pre_shift = vld1q_dup_s32(&params->rndnu_neon.right_pre_shift);
328     const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
329     const int32x4_t vright_post_shift = vld1q_dup_s32(&params->rndnu_neon.right_post_shift);
330 
331     vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
332     vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
333     vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
334     vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
335     vacc2x0123 = vqshlq_s32(vacc2x0123, vright_pre_shift);
336     vacc2x4567 = vqshlq_s32(vacc2x4567, vright_pre_shift);
337 
338     vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
339     vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
340     vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
341     vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
342     vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier);
343     vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier);
344 
345     vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
346     vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
347     vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
348     vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
349     vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift);
350     vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift);
351 
352     const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
353 #if XNN_ARCH_ARM64
354     int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
355     int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
356     int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567);
357 
358     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
359     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
360     vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
361 
362     int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567);
363     int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567);
364 #else
365     int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
366     int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
367     int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567));
368 
369     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
370     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
371     vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
372 
373     int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567));
374     int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567);
375 #endif
376 
377     const int8x16_t voutput_min = vld1q_dup_s8(&params->rndnu_neon.output_min);
378     vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min);
379     vout2x01234567 = vmax_s8(vout2x01234567, vget_low_s8(voutput_min));
380 
381     const int8x16_t voutput_max = vld1q_dup_s8(&params->rndnu_neon.output_max);
382     vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max);
383     vout2x01234567 = vmin_s8(vout2x01234567, vget_low_s8(voutput_max));
384 
385     if (nc >= 8) {
386       vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567));
387       vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567));
388       vst1_s8(c2 + 0, vout2x01234567);
389 
390       c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
391       c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
392       c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
393 
394       a0 = (const int8_t*) ((uintptr_t) a0 - kc);
395       a1 = (const int8_t*) ((uintptr_t) a1 - kc);
396       a2 = (const int8_t*) ((uintptr_t) a2 - kc);
397 
398       nc -= 8;
399     } else {
400       // Final case where not all of the 8 columns fit in the destination.
401       if (nc & 4) {
402         vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
403         vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
404         vst1_lane_u32((void*) c2, vreinterpret_u32_s8(vout2x01234567), 0); c2 += 4;
405         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
406         vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 4);
407       }
408       if (nc & 2) {
409         vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
410         vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
411         vst1_lane_u16((void*) c2, vreinterpret_u16_s8(vout2x01234567), 0); c2 += 2;
412         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
413         vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 2);
414       }
415       if (nc & 1) {
416         vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
417         vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
418         vst1_lane_s8(c2, vout2x01234567, 0);
419       }
420 
421       nc = 0;
422     }
423   } while (nc != 0);
424 }
425