• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-gemm/c8-neon-mull.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_2x16c8__neon_mlal(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_2x16c8__neon_mlal(
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 <= 2);
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, 8 * 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 
49   do {
50     int32x4_t vacc0x0 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
51     int32x4_t vacc0x1 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
52     int32x4_t vacc0x2 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
53     int32x4_t vacc0x3 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
54     int32x4_t vacc0x4 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
55     int32x4_t vacc0x5 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
56     int32x4_t vacc0x6 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
57     int32x4_t vacc0x7 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
58     int32x4_t vacc0x8 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
59     int32x4_t vacc0x9 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
60     int32x4_t vacc0x10 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
61     int32x4_t vacc0x11 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
62     int32x4_t vacc0x12 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
63     int32x4_t vacc0x13 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
64     int32x4_t vacc0x14 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
65     int32x4_t vacc0x15 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
66     int32x4_t vacc1x0 = vacc0x0;
67     int32x4_t vacc1x1 = vacc0x1;
68     int32x4_t vacc1x2 = vacc0x2;
69     int32x4_t vacc1x3 = vacc0x3;
70     int32x4_t vacc1x4 = vacc0x4;
71     int32x4_t vacc1x5 = vacc0x5;
72     int32x4_t vacc1x6 = vacc0x6;
73     int32x4_t vacc1x7 = vacc0x7;
74     int32x4_t vacc1x8 = vacc0x8;
75     int32x4_t vacc1x9 = vacc0x9;
76     int32x4_t vacc1x10 = vacc0x10;
77     int32x4_t vacc1x11 = vacc0x11;
78     int32x4_t vacc1x12 = vacc0x12;
79     int32x4_t vacc1x13 = vacc0x13;
80     int32x4_t vacc1x14 = vacc0x14;
81     int32x4_t vacc1x15 = vacc0x15;
82 
83     size_t k = kc;
84     // 2x partial unrolled loop to load 16 bytes at a time using MLA.
85     while (k >= 16 * sizeof(int8_t)) {
86       const int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
87       const int8x8_t va0x1 = vld1_s8(a0); a0 += 8;
88       const int8x8_t va1x0 = vld1_s8(a1); a1 += 8;
89       const int8x8_t va1x1 = vld1_s8(a1); a1 += 8;
90 
91       const int8x8_t vb0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
92       const int8x8_t vb1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
93       const int8x8_t vb2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
94       const int8x8_t vb3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
95       const int8x8_t vb4x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
96       const int8x8_t vb5x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
97       const int8x8_t vb6x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
98       const int8x8_t vb7x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
99       const int8x8_t vb8x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
100       const int8x8_t vb9x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
101       const int8x8_t vb10x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
102       const int8x8_t vb11x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
103       const int8x8_t vb12x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
104       const int8x8_t vb13x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
105       const int8x8_t vb14x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
106       const int8x8_t vb15x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
107 
108       const int8x8_t vb0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
109       int16x8_t vprod0x0 = vmull_s8(vb0x0, va0x0);
110       int16x8_t vprod1x0 = vmull_s8(vb0x0, va1x0);
111       vprod0x0 = vmlal_s8(vprod0x0, vb0x1, va0x1);
112       vprod1x0 = vmlal_s8(vprod1x0, vb0x1, va1x1);
113       vacc0x0 = vpadalq_s16(vacc0x0, vprod0x0);
114       vacc1x0 = vpadalq_s16(vacc1x0, vprod1x0);
115       const int8x8_t vb1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
116       int16x8_t vprod0x1 = vmull_s8(vb1x0, va0x0);
117       int16x8_t vprod1x1 = vmull_s8(vb1x0, va1x0);
118       vprod0x1 = vmlal_s8(vprod0x1, vb1x1, va0x1);
119       vprod1x1 = vmlal_s8(vprod1x1, vb1x1, va1x1);
120       vacc0x1 = vpadalq_s16(vacc0x1, vprod0x1);
121       vacc1x1 = vpadalq_s16(vacc1x1, vprod1x1);
122       const int8x8_t vb2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
123       int16x8_t vprod0x2 = vmull_s8(vb2x0, va0x0);
124       int16x8_t vprod1x2 = vmull_s8(vb2x0, va1x0);
125       vprod0x2 = vmlal_s8(vprod0x2, vb2x1, va0x1);
126       vprod1x2 = vmlal_s8(vprod1x2, vb2x1, va1x1);
127       vacc0x2 = vpadalq_s16(vacc0x2, vprod0x2);
128       vacc1x2 = vpadalq_s16(vacc1x2, vprod1x2);
129       const int8x8_t vb3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
130       int16x8_t vprod0x3 = vmull_s8(vb3x0, va0x0);
131       int16x8_t vprod1x3 = vmull_s8(vb3x0, va1x0);
132       vprod0x3 = vmlal_s8(vprod0x3, vb3x1, va0x1);
133       vprod1x3 = vmlal_s8(vprod1x3, vb3x1, va1x1);
134       vacc0x3 = vpadalq_s16(vacc0x3, vprod0x3);
135       vacc1x3 = vpadalq_s16(vacc1x3, vprod1x3);
136       const int8x8_t vb4x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
137       int16x8_t vprod0x4 = vmull_s8(vb4x0, va0x0);
138       int16x8_t vprod1x4 = vmull_s8(vb4x0, va1x0);
139       vprod0x4 = vmlal_s8(vprod0x4, vb4x1, va0x1);
140       vprod1x4 = vmlal_s8(vprod1x4, vb4x1, va1x1);
141       vacc0x4 = vpadalq_s16(vacc0x4, vprod0x4);
142       vacc1x4 = vpadalq_s16(vacc1x4, vprod1x4);
143       const int8x8_t vb5x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
144       int16x8_t vprod0x5 = vmull_s8(vb5x0, va0x0);
145       int16x8_t vprod1x5 = vmull_s8(vb5x0, va1x0);
146       vprod0x5 = vmlal_s8(vprod0x5, vb5x1, va0x1);
147       vprod1x5 = vmlal_s8(vprod1x5, vb5x1, va1x1);
148       vacc0x5 = vpadalq_s16(vacc0x5, vprod0x5);
149       vacc1x5 = vpadalq_s16(vacc1x5, vprod1x5);
150       const int8x8_t vb6x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
151       int16x8_t vprod0x6 = vmull_s8(vb6x0, va0x0);
152       int16x8_t vprod1x6 = vmull_s8(vb6x0, va1x0);
153       vprod0x6 = vmlal_s8(vprod0x6, vb6x1, va0x1);
154       vprod1x6 = vmlal_s8(vprod1x6, vb6x1, va1x1);
155       vacc0x6 = vpadalq_s16(vacc0x6, vprod0x6);
156       vacc1x6 = vpadalq_s16(vacc1x6, vprod1x6);
157       const int8x8_t vb7x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
158       int16x8_t vprod0x7 = vmull_s8(vb7x0, va0x0);
159       int16x8_t vprod1x7 = vmull_s8(vb7x0, va1x0);
160       vprod0x7 = vmlal_s8(vprod0x7, vb7x1, va0x1);
161       vprod1x7 = vmlal_s8(vprod1x7, vb7x1, va1x1);
162       vacc0x7 = vpadalq_s16(vacc0x7, vprod0x7);
163       vacc1x7 = vpadalq_s16(vacc1x7, vprod1x7);
164       const int8x8_t vb8x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
165       int16x8_t vprod0x8 = vmull_s8(vb8x0, va0x0);
166       int16x8_t vprod1x8 = vmull_s8(vb8x0, va1x0);
167       vprod0x8 = vmlal_s8(vprod0x8, vb8x1, va0x1);
168       vprod1x8 = vmlal_s8(vprod1x8, vb8x1, va1x1);
169       vacc0x8 = vpadalq_s16(vacc0x8, vprod0x8);
170       vacc1x8 = vpadalq_s16(vacc1x8, vprod1x8);
171       const int8x8_t vb9x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
172       int16x8_t vprod0x9 = vmull_s8(vb9x0, va0x0);
173       int16x8_t vprod1x9 = vmull_s8(vb9x0, va1x0);
174       vprod0x9 = vmlal_s8(vprod0x9, vb9x1, va0x1);
175       vprod1x9 = vmlal_s8(vprod1x9, vb9x1, va1x1);
176       vacc0x9 = vpadalq_s16(vacc0x9, vprod0x9);
177       vacc1x9 = vpadalq_s16(vacc1x9, vprod1x9);
178       const int8x8_t vb10x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
179       int16x8_t vprod0x10 = vmull_s8(vb10x0, va0x0);
180       int16x8_t vprod1x10 = vmull_s8(vb10x0, va1x0);
181       vprod0x10 = vmlal_s8(vprod0x10, vb10x1, va0x1);
182       vprod1x10 = vmlal_s8(vprod1x10, vb10x1, va1x1);
183       vacc0x10 = vpadalq_s16(vacc0x10, vprod0x10);
184       vacc1x10 = vpadalq_s16(vacc1x10, vprod1x10);
185       const int8x8_t vb11x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
186       int16x8_t vprod0x11 = vmull_s8(vb11x0, va0x0);
187       int16x8_t vprod1x11 = vmull_s8(vb11x0, va1x0);
188       vprod0x11 = vmlal_s8(vprod0x11, vb11x1, va0x1);
189       vprod1x11 = vmlal_s8(vprod1x11, vb11x1, va1x1);
190       vacc0x11 = vpadalq_s16(vacc0x11, vprod0x11);
191       vacc1x11 = vpadalq_s16(vacc1x11, vprod1x11);
192       const int8x8_t vb12x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
193       int16x8_t vprod0x12 = vmull_s8(vb12x0, va0x0);
194       int16x8_t vprod1x12 = vmull_s8(vb12x0, va1x0);
195       vprod0x12 = vmlal_s8(vprod0x12, vb12x1, va0x1);
196       vprod1x12 = vmlal_s8(vprod1x12, vb12x1, va1x1);
197       vacc0x12 = vpadalq_s16(vacc0x12, vprod0x12);
198       vacc1x12 = vpadalq_s16(vacc1x12, vprod1x12);
199       const int8x8_t vb13x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
200       int16x8_t vprod0x13 = vmull_s8(vb13x0, va0x0);
201       int16x8_t vprod1x13 = vmull_s8(vb13x0, va1x0);
202       vprod0x13 = vmlal_s8(vprod0x13, vb13x1, va0x1);
203       vprod1x13 = vmlal_s8(vprod1x13, vb13x1, va1x1);
204       vacc0x13 = vpadalq_s16(vacc0x13, vprod0x13);
205       vacc1x13 = vpadalq_s16(vacc1x13, vprod1x13);
206       const int8x8_t vb14x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
207       int16x8_t vprod0x14 = vmull_s8(vb14x0, va0x0);
208       int16x8_t vprod1x14 = vmull_s8(vb14x0, va1x0);
209       vprod0x14 = vmlal_s8(vprod0x14, vb14x1, va0x1);
210       vprod1x14 = vmlal_s8(vprod1x14, vb14x1, va1x1);
211       vacc0x14 = vpadalq_s16(vacc0x14, vprod0x14);
212       vacc1x14 = vpadalq_s16(vacc1x14, vprod1x14);
213       const int8x8_t vb15x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(  int8_t));
214       int16x8_t vprod0x15 = vmull_s8(vb15x0, va0x0);
215       int16x8_t vprod1x15 = vmull_s8(vb15x0, va1x0);
216       vprod0x15 = vmlal_s8(vprod0x15, vb15x1, va0x1);
217       vprod1x15 = vmlal_s8(vprod1x15, vb15x1, va1x1);
218       vacc0x15 = vpadalq_s16(vacc0x15, vprod0x15);
219       vacc1x15 = vpadalq_s16(vacc1x15, vprod1x15);
220 
221       k -= 16 * sizeof(int8_t);
222     }
223 
224     // Handle 8 bytes at a time using MUL.
225     if (k != 0) {
226       const int8x8_t va0 = vld1_s8(a0); a0 += 8;
227       const int8x8_t va1 = vld1_s8(a1); a1 += 8;
228 
229       const int8x8_t vb0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
230       const int16x8_t vprod0x0 = vmull_s8(vb0, va0);
231       const int16x8_t vprod1x0 = vmull_s8(vb0, va1);
232       vacc0x0 = vpadalq_s16(vacc0x0, vprod0x0);
233       vacc1x0 = vpadalq_s16(vacc1x0, vprod1x0);
234       const int8x8_t vb1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
235       const int16x8_t vprod0x1 = vmull_s8(vb1, va0);
236       const int16x8_t vprod1x1 = vmull_s8(vb1, va1);
237       vacc0x1 = vpadalq_s16(vacc0x1, vprod0x1);
238       vacc1x1 = vpadalq_s16(vacc1x1, vprod1x1);
239       const int8x8_t vb2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
240       const int16x8_t vprod0x2 = vmull_s8(vb2, va0);
241       const int16x8_t vprod1x2 = vmull_s8(vb2, va1);
242       vacc0x2 = vpadalq_s16(vacc0x2, vprod0x2);
243       vacc1x2 = vpadalq_s16(vacc1x2, vprod1x2);
244       const int8x8_t vb3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
245       const int16x8_t vprod0x3 = vmull_s8(vb3, va0);
246       const int16x8_t vprod1x3 = vmull_s8(vb3, va1);
247       vacc0x3 = vpadalq_s16(vacc0x3, vprod0x3);
248       vacc1x3 = vpadalq_s16(vacc1x3, vprod1x3);
249       const int8x8_t vb4 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
250       const int16x8_t vprod0x4 = vmull_s8(vb4, va0);
251       const int16x8_t vprod1x4 = vmull_s8(vb4, va1);
252       vacc0x4 = vpadalq_s16(vacc0x4, vprod0x4);
253       vacc1x4 = vpadalq_s16(vacc1x4, vprod1x4);
254       const int8x8_t vb5 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
255       const int16x8_t vprod0x5 = vmull_s8(vb5, va0);
256       const int16x8_t vprod1x5 = vmull_s8(vb5, va1);
257       vacc0x5 = vpadalq_s16(vacc0x5, vprod0x5);
258       vacc1x5 = vpadalq_s16(vacc1x5, vprod1x5);
259       const int8x8_t vb6 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
260       const int16x8_t vprod0x6 = vmull_s8(vb6, va0);
261       const int16x8_t vprod1x6 = vmull_s8(vb6, va1);
262       vacc0x6 = vpadalq_s16(vacc0x6, vprod0x6);
263       vacc1x6 = vpadalq_s16(vacc1x6, vprod1x6);
264       const int8x8_t vb7 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
265       const int16x8_t vprod0x7 = vmull_s8(vb7, va0);
266       const int16x8_t vprod1x7 = vmull_s8(vb7, va1);
267       vacc0x7 = vpadalq_s16(vacc0x7, vprod0x7);
268       vacc1x7 = vpadalq_s16(vacc1x7, vprod1x7);
269       const int8x8_t vb8 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
270       const int16x8_t vprod0x8 = vmull_s8(vb8, va0);
271       const int16x8_t vprod1x8 = vmull_s8(vb8, va1);
272       vacc0x8 = vpadalq_s16(vacc0x8, vprod0x8);
273       vacc1x8 = vpadalq_s16(vacc1x8, vprod1x8);
274       const int8x8_t vb9 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
275       const int16x8_t vprod0x9 = vmull_s8(vb9, va0);
276       const int16x8_t vprod1x9 = vmull_s8(vb9, va1);
277       vacc0x9 = vpadalq_s16(vacc0x9, vprod0x9);
278       vacc1x9 = vpadalq_s16(vacc1x9, vprod1x9);
279       const int8x8_t vb10 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
280       const int16x8_t vprod0x10 = vmull_s8(vb10, va0);
281       const int16x8_t vprod1x10 = vmull_s8(vb10, va1);
282       vacc0x10 = vpadalq_s16(vacc0x10, vprod0x10);
283       vacc1x10 = vpadalq_s16(vacc1x10, vprod1x10);
284       const int8x8_t vb11 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
285       const int16x8_t vprod0x11 = vmull_s8(vb11, va0);
286       const int16x8_t vprod1x11 = vmull_s8(vb11, va1);
287       vacc0x11 = vpadalq_s16(vacc0x11, vprod0x11);
288       vacc1x11 = vpadalq_s16(vacc1x11, vprod1x11);
289       const int8x8_t vb12 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
290       const int16x8_t vprod0x12 = vmull_s8(vb12, va0);
291       const int16x8_t vprod1x12 = vmull_s8(vb12, va1);
292       vacc0x12 = vpadalq_s16(vacc0x12, vprod0x12);
293       vacc1x12 = vpadalq_s16(vacc1x12, vprod1x12);
294       const int8x8_t vb13 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
295       const int16x8_t vprod0x13 = vmull_s8(vb13, va0);
296       const int16x8_t vprod1x13 = vmull_s8(vb13, va1);
297       vacc0x13 = vpadalq_s16(vacc0x13, vprod0x13);
298       vacc1x13 = vpadalq_s16(vacc1x13, vprod1x13);
299       const int8x8_t vb14 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
300       const int16x8_t vprod0x14 = vmull_s8(vb14, va0);
301       const int16x8_t vprod1x14 = vmull_s8(vb14, va1);
302       vacc0x14 = vpadalq_s16(vacc0x14, vprod0x14);
303       vacc1x14 = vpadalq_s16(vacc1x14, vprod1x14);
304       const int8x8_t vb15 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
305       const int16x8_t vprod0x15 = vmull_s8(vb15, va0);
306       const int16x8_t vprod1x15 = vmull_s8(vb15, va1);
307       vacc0x15 = vpadalq_s16(vacc0x15, vprod0x15);
308       vacc1x15 = vpadalq_s16(vacc1x15, vprod1x15);
309 
310       k -= 8 * sizeof(int8_t);
311     }
312 
313 #if XNN_ARCH_ARM64
314     const int32x4_t vsum0x01 = vpaddq_s32(vacc0x0, vacc0x1);
315     const int32x4_t vsum0x23 = vpaddq_s32(vacc0x2, vacc0x3);
316     const int32x4_t vsum0x45 = vpaddq_s32(vacc0x4, vacc0x5);
317     const int32x4_t vsum0x67 = vpaddq_s32(vacc0x6, vacc0x7);
318     const int32x4_t vsum0x89 = vpaddq_s32(vacc0x8, vacc0x9);
319     const int32x4_t vsum0xAB = vpaddq_s32(vacc0x10, vacc0x11);
320     const int32x4_t vsum0xCD = vpaddq_s32(vacc0x12, vacc0x13);
321     const int32x4_t vsum0xEF = vpaddq_s32(vacc0x14, vacc0x15);
322     const int32x4_t vsum1x01 = vpaddq_s32(vacc1x0, vacc1x1);
323     const int32x4_t vsum1x23 = vpaddq_s32(vacc1x2, vacc1x3);
324     const int32x4_t vsum1x45 = vpaddq_s32(vacc1x4, vacc1x5);
325     const int32x4_t vsum1x67 = vpaddq_s32(vacc1x6, vacc1x7);
326     const int32x4_t vsum1x89 = vpaddq_s32(vacc1x8, vacc1x9);
327     const int32x4_t vsum1xAB = vpaddq_s32(vacc1x10, vacc1x11);
328     const int32x4_t vsum1xCD = vpaddq_s32(vacc1x12, vacc1x13);
329     const int32x4_t vsum1xEF = vpaddq_s32(vacc1x14, vacc1x15);
330 
331     int32x4_t vacc0x0123 = vpaddq_s32(vsum0x01, vsum0x23);
332     int32x4_t vacc0x4567 = vpaddq_s32(vsum0x45, vsum0x67);
333     int32x4_t vacc0x89AB = vpaddq_s32(vsum0x89, vsum0xAB);
334     int32x4_t vacc0xCDEF = vpaddq_s32(vsum0xCD, vsum0xEF);
335     int32x4_t vacc1x0123 = vpaddq_s32(vsum1x01, vsum1x23);
336     int32x4_t vacc1x4567 = vpaddq_s32(vsum1x45, vsum1x67);
337     int32x4_t vacc1x89AB = vpaddq_s32(vsum1x89, vsum1xAB);
338     int32x4_t vacc1xCDEF = vpaddq_s32(vsum1xCD, vsum1xEF);
339 #else
340     const int32x2_t vpsum0x0 = vadd_s32(vget_low_s32(vacc0x0), vget_high_s32(vacc0x0));
341     const int32x2_t vpsum0x1 = vadd_s32(vget_low_s32(vacc0x1), vget_high_s32(vacc0x1));
342     const int32x2_t vpsum0x2 = vadd_s32(vget_low_s32(vacc0x2), vget_high_s32(vacc0x2));
343     const int32x2_t vpsum0x3 = vadd_s32(vget_low_s32(vacc0x3), vget_high_s32(vacc0x3));
344     const int32x2_t vsum0x01 = vpadd_s32(vpsum0x0, vpsum0x1);
345     const int32x2_t vsum0x23 = vpadd_s32(vpsum0x2, vpsum0x3);
346     int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23 );
347     const int32x2_t vpsum0x4 = vadd_s32(vget_low_s32(vacc0x4), vget_high_s32(vacc0x4));
348     const int32x2_t vpsum0x5 = vadd_s32(vget_low_s32(vacc0x5), vget_high_s32(vacc0x5));
349     const int32x2_t vpsum0x6 = vadd_s32(vget_low_s32(vacc0x6), vget_high_s32(vacc0x6));
350     const int32x2_t vpsum0x7 = vadd_s32(vget_low_s32(vacc0x7), vget_high_s32(vacc0x7));
351     const int32x2_t vsum0x45 = vpadd_s32(vpsum0x4, vpsum0x5);
352     const int32x2_t vsum0x67 = vpadd_s32(vpsum0x6, vpsum0x7);
353     int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67 );
354     const int32x2_t vpsum0x8 = vadd_s32(vget_low_s32(vacc0x8), vget_high_s32(vacc0x8));
355     const int32x2_t vpsum0x9 = vadd_s32(vget_low_s32(vacc0x9), vget_high_s32(vacc0x9));
356     const int32x2_t vpsum0xA = vadd_s32(vget_low_s32(vacc0x10), vget_high_s32(vacc0x10));
357     const int32x2_t vpsum0xB = vadd_s32(vget_low_s32(vacc0x11), vget_high_s32(vacc0x11));
358     const int32x2_t vsum0x89 = vpadd_s32(vpsum0x8, vpsum0x9);
359     const int32x2_t vsum0xAB = vpadd_s32(vpsum0xA, vpsum0xB);
360     int32x4_t vacc0x89AB = vcombine_s32(vsum0x89, vsum0xAB );
361     const int32x2_t vpsum0xC = vadd_s32(vget_low_s32(vacc0x12), vget_high_s32(vacc0x12));
362     const int32x2_t vpsum0xD = vadd_s32(vget_low_s32(vacc0x13), vget_high_s32(vacc0x13));
363     const int32x2_t vpsum0xE = vadd_s32(vget_low_s32(vacc0x14), vget_high_s32(vacc0x14));
364     const int32x2_t vpsum0xF = vadd_s32(vget_low_s32(vacc0x15), vget_high_s32(vacc0x15));
365     const int32x2_t vsum0xCD = vpadd_s32(vpsum0xC, vpsum0xD);
366     const int32x2_t vsum0xEF = vpadd_s32(vpsum0xE, vpsum0xF);
367     int32x4_t vacc0xCDEF = vcombine_s32(vsum0xCD, vsum0xEF );
368     const int32x2_t vpsum1x0 = vadd_s32(vget_low_s32(vacc1x0), vget_high_s32(vacc1x0));
369     const int32x2_t vpsum1x1 = vadd_s32(vget_low_s32(vacc1x1), vget_high_s32(vacc1x1));
370     const int32x2_t vpsum1x2 = vadd_s32(vget_low_s32(vacc1x2), vget_high_s32(vacc1x2));
371     const int32x2_t vpsum1x3 = vadd_s32(vget_low_s32(vacc1x3), vget_high_s32(vacc1x3));
372     const int32x2_t vsum1x01 = vpadd_s32(vpsum1x0, vpsum1x1);
373     const int32x2_t vsum1x23 = vpadd_s32(vpsum1x2, vpsum1x3);
374     int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23 );
375     const int32x2_t vpsum1x4 = vadd_s32(vget_low_s32(vacc1x4), vget_high_s32(vacc1x4));
376     const int32x2_t vpsum1x5 = vadd_s32(vget_low_s32(vacc1x5), vget_high_s32(vacc1x5));
377     const int32x2_t vpsum1x6 = vadd_s32(vget_low_s32(vacc1x6), vget_high_s32(vacc1x6));
378     const int32x2_t vpsum1x7 = vadd_s32(vget_low_s32(vacc1x7), vget_high_s32(vacc1x7));
379     const int32x2_t vsum1x45 = vpadd_s32(vpsum1x4, vpsum1x5);
380     const int32x2_t vsum1x67 = vpadd_s32(vpsum1x6, vpsum1x7);
381     int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67 );
382     const int32x2_t vpsum1x8 = vadd_s32(vget_low_s32(vacc1x8), vget_high_s32(vacc1x8));
383     const int32x2_t vpsum1x9 = vadd_s32(vget_low_s32(vacc1x9), vget_high_s32(vacc1x9));
384     const int32x2_t vpsum1xA = vadd_s32(vget_low_s32(vacc1x10), vget_high_s32(vacc1x10));
385     const int32x2_t vpsum1xB = vadd_s32(vget_low_s32(vacc1x11), vget_high_s32(vacc1x11));
386     const int32x2_t vsum1x89 = vpadd_s32(vpsum1x8, vpsum1x9);
387     const int32x2_t vsum1xAB = vpadd_s32(vpsum1xA, vpsum1xB);
388     int32x4_t vacc1x89AB = vcombine_s32(vsum1x89, vsum1xAB );
389     const int32x2_t vpsum1xC = vadd_s32(vget_low_s32(vacc1x12), vget_high_s32(vacc1x12));
390     const int32x2_t vpsum1xD = vadd_s32(vget_low_s32(vacc1x13), vget_high_s32(vacc1x13));
391     const int32x2_t vpsum1xE = vadd_s32(vget_low_s32(vacc1x14), vget_high_s32(vacc1x14));
392     const int32x2_t vpsum1xF = vadd_s32(vget_low_s32(vacc1x15), vget_high_s32(vacc1x15));
393     const int32x2_t vsum1xCD = vpadd_s32(vpsum1xC, vpsum1xD);
394     const int32x2_t vsum1xEF = vpadd_s32(vpsum1xE, vpsum1xF);
395     int32x4_t vacc1xCDEF = vcombine_s32(vsum1xCD, vsum1xEF );
396 #endif
397 
398     const int32x4_t vright_pre_shift = vld1q_dup_s32(&params->rndnu_neon.right_pre_shift);
399     const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
400     const int32x4_t vright_post_shift = vld1q_dup_s32(&params->rndnu_neon.right_post_shift);
401 
402     vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
403     vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
404     vacc0x89AB = vqshlq_s32(vacc0x89AB, vright_pre_shift);
405     vacc0xCDEF = vqshlq_s32(vacc0xCDEF, vright_pre_shift);
406     vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
407     vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
408     vacc1x89AB = vqshlq_s32(vacc1x89AB, vright_pre_shift);
409     vacc1xCDEF = vqshlq_s32(vacc1xCDEF, vright_pre_shift);
410 
411     vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
412     vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
413     vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier);
414     vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier);
415     vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
416     vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
417     vacc1x89AB = vqdmulhq_s32(vacc1x89AB, vmultiplier);
418     vacc1xCDEF = vqdmulhq_s32(vacc1xCDEF, vmultiplier);
419 
420     vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
421     vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
422     vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift);
423     vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift);
424     vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
425     vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
426     vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_post_shift);
427     vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_post_shift);
428 
429     const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
430 #if XNN_ARCH_ARM64
431     int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
432     int16x8_t vacc0x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF);
433     int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
434     int16x8_t vacc1x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF);
435 
436     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
437     vacc0x89ABCDEF = vqaddq_s16(vacc0x89ABCDEF, voutput_zero_point);
438     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
439     vacc1x89ABCDEF = vqaddq_s16(vacc1x89ABCDEF, voutput_zero_point);
440 
441     int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF);
442     int8x16_t vout1x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc1x01234567), vacc1x89ABCDEF);
443 #else
444     int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
445     int16x8_t vacc0x89ABCDEF = vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF));
446     int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
447     int16x8_t vacc1x89ABCDEF = vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF));
448 
449     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
450     vacc0x89ABCDEF = vqaddq_s16(vacc0x89ABCDEF, voutput_zero_point);
451     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
452     vacc1x89ABCDEF = vqaddq_s16(vacc1x89ABCDEF, voutput_zero_point);
453 
454     int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF));
455     int8x16_t vout1x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc1x01234567), vqmovn_s16(vacc1x89ABCDEF));
456 #endif
457 
458     const int8x16_t voutput_min = vld1q_dup_s8(&params->rndnu_neon.output_min);
459     vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min);
460     vout1x0123456789ABCDEF = vmaxq_s8(vout1x0123456789ABCDEF, voutput_min);
461 
462     const int8x16_t voutput_max = vld1q_dup_s8(&params->rndnu_neon.output_max);
463     vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max);
464     vout1x0123456789ABCDEF = vminq_s8(vout1x0123456789ABCDEF, voutput_max);
465 
466     if (nc >= 16) {
467       vst1q_s8(c0 + 0, vout0x0123456789ABCDEF);
468       vst1q_s8(c1 + 0, vout1x0123456789ABCDEF);
469 
470       c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
471       c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
472 
473       a0 = (const int8_t*) ((uintptr_t) a0 - kc);
474       a1 = (const int8_t*) ((uintptr_t) a1 - kc);
475 
476       nc -= 16;
477     } else {
478       // Final case where not all of the 16 columns fit in the destination.
479       int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vget_low_s8(vout0x0123456789ABCDEF), vget_low_s8(vout1x0123456789ABCDEF));
480       if (nc & 8) {
481         vst1_s8(c0, vget_low_s8(vout0x01234567_1x01234567)); c0 += 8;
482         vst1_s8(c1, vget_high_s8(vout0x01234567_1x01234567)); c1 += 8;
483         vout0x01234567_1x01234567 = vcombine_s8(vget_high_s8(vout0x0123456789ABCDEF), vget_high_s8(vout1x0123456789ABCDEF));
484       }
485       if (nc & 4) {
486         vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
487         vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
488         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
489       }
490       if (nc & 2) {
491         vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
492         vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
493         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
494       }
495       if (nc & 1) {
496         vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
497         vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
498       }
499 
500       nc = 0;
501     }
502   } while (nc != 0);
503 }
504