xref: /aosp_15_r20/external/XNNPACK/src/qs8-gemm/gen/4x16c4-minmax-rndnu-neondot.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-gemm/c4-neondot.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2020 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_4x16c4__neondot(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_4x16c4__neondot(
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 <= 4);
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   const int8_t* a3 = (const int8_t*) ((uintptr_t) a2 + a_stride);
55   int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride);
56   if XNN_UNPREDICTABLE(mr != 4) {
57     a3 = a2;
58     c3 = c2;
59   }
60 
61   // Loop over groups of 16 columns.
62   do {
63     // Initialize accumulators with bias. 16 bias values are loaded from the
64     // weight matrix, at the start of the group of 16 columns.
65     int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
66     int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
67     int32x4_t vacc0x89AB = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
68     int32x4_t vacc0xCDEF = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
69     int32x4_t vacc1x0123 = vacc0x0123;
70     int32x4_t vacc1x4567 = vacc0x4567;
71     int32x4_t vacc1x89AB = vacc0x89AB;
72     int32x4_t vacc1xCDEF = vacc0xCDEF;
73     int32x4_t vacc2x0123 = vacc0x0123;
74     int32x4_t vacc2x4567 = vacc0x4567;
75     int32x4_t vacc2x89AB = vacc0x89AB;
76     int32x4_t vacc2xCDEF = vacc0xCDEF;
77     int32x4_t vacc3x0123 = vacc0x0123;
78     int32x4_t vacc3x4567 = vacc0x4567;
79     int32x4_t vacc3x89AB = vacc0x89AB;
80     int32x4_t vacc3xCDEF = vacc0xCDEF;
81 
82     // Inner accumulation loop along the 16 columns.
83     size_t k = kc;
84     // 2x partial unrolled loop to load 8 bytes at a time.
85     while (k >= 8 * sizeof(int8_t)) {
86       // Load a 4x8 block of activations.
87       const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8;
88       const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8;
89       const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8;
90       const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8;
91 
92       // Load a 8x16 block of weights.
93       const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
94       const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
95       const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
96       const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
97       const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
98       const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
99       const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
100       const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
101 
102       // Multiply-accumulate: 4x8 * 8x16 --> 4x16.
103       vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
104       vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
105       vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0);
106       vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
107       vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
108       vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
109       vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0);
110       vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0);
111       vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0);
112       vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0);
113       vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0);
114       vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0);
115       vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0);
116       vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0);
117       vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb0123x89AB, va3x01234567, 0);
118       vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb0123xCDEF, va3x01234567, 0);
119       vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1);
120       vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1);
121       vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1);
122       vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1);
123       vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1);
124       vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1);
125       vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb4567x89AB, va1x01234567, 1);
126       vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb4567xCDEF, va1x01234567, 1);
127       vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1);
128       vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1);
129       vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb4567x89AB, va2x01234567, 1);
130       vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb4567xCDEF, va2x01234567, 1);
131       vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1);
132       vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1);
133       vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb4567x89AB, va3x01234567, 1);
134       vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb4567xCDEF, va3x01234567, 1);
135 
136       k -= 8 * sizeof(int8_t);
137     }
138     // Handle up to 4 final positions of `k`
139     if XNN_UNLIKELY(k != 0) {
140       // Load a 4x4 block of activations.
141       const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4;
142       const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 4;
143       const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 4;
144       const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 4;
145 
146       // Load a 4x16 block of weights.
147       const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
148       const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
149       const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
150       const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
151 
152       // Multiply-accumulate: 4x4 * 4x16 --> 4x16.
153       vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
154       vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
155       vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0);
156       vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
157       vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
158       vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
159       vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0);
160       vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0);
161       vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0);
162       vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0);
163       vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0);
164       vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0);
165       vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0);
166       vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0);
167       vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb0123x89AB, va3x01234567, 0);
168       vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb0123xCDEF, va3x01234567, 0);
169     }
170 
171     const int32x4_t vright_pre_shift = vld1q_dup_s32(&params->rndnu_neon.right_pre_shift);
172     const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
173     const int32x4_t vright_post_shift = vld1q_dup_s32(&params->rndnu_neon.right_post_shift);
174 
175     vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
176     vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
177     vacc0x89AB = vqshlq_s32(vacc0x89AB, vright_pre_shift);
178     vacc0xCDEF = vqshlq_s32(vacc0xCDEF, vright_pre_shift);
179     vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
180     vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
181     vacc1x89AB = vqshlq_s32(vacc1x89AB, vright_pre_shift);
182     vacc1xCDEF = vqshlq_s32(vacc1xCDEF, vright_pre_shift);
183     vacc2x0123 = vqshlq_s32(vacc2x0123, vright_pre_shift);
184     vacc2x4567 = vqshlq_s32(vacc2x4567, vright_pre_shift);
185     vacc2x89AB = vqshlq_s32(vacc2x89AB, vright_pre_shift);
186     vacc2xCDEF = vqshlq_s32(vacc2xCDEF, vright_pre_shift);
187     vacc3x0123 = vqshlq_s32(vacc3x0123, vright_pre_shift);
188     vacc3x4567 = vqshlq_s32(vacc3x4567, vright_pre_shift);
189     vacc3x89AB = vqshlq_s32(vacc3x89AB, vright_pre_shift);
190     vacc3xCDEF = vqshlq_s32(vacc3xCDEF, vright_pre_shift);
191 
192     vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
193     vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
194     vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier);
195     vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier);
196     vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
197     vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
198     vacc1x89AB = vqdmulhq_s32(vacc1x89AB, vmultiplier);
199     vacc1xCDEF = vqdmulhq_s32(vacc1xCDEF, vmultiplier);
200     vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier);
201     vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier);
202     vacc2x89AB = vqdmulhq_s32(vacc2x89AB, vmultiplier);
203     vacc2xCDEF = vqdmulhq_s32(vacc2xCDEF, vmultiplier);
204     vacc3x0123 = vqdmulhq_s32(vacc3x0123, vmultiplier);
205     vacc3x4567 = vqdmulhq_s32(vacc3x4567, vmultiplier);
206     vacc3x89AB = vqdmulhq_s32(vacc3x89AB, vmultiplier);
207     vacc3xCDEF = vqdmulhq_s32(vacc3xCDEF, vmultiplier);
208 
209     vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
210     vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
211     vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift);
212     vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift);
213     vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
214     vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
215     vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_post_shift);
216     vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_post_shift);
217     vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift);
218     vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift);
219     vacc2x89AB = vrshlq_s32(vacc2x89AB, vright_post_shift);
220     vacc2xCDEF = vrshlq_s32(vacc2xCDEF, vright_post_shift);
221     vacc3x0123 = vrshlq_s32(vacc3x0123, vright_post_shift);
222     vacc3x4567 = vrshlq_s32(vacc3x4567, vright_post_shift);
223     vacc3x89AB = vrshlq_s32(vacc3x89AB, vright_post_shift);
224     vacc3xCDEF = vrshlq_s32(vacc3xCDEF, vright_post_shift);
225 
226     const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
227 #if XNN_ARCH_ARM64
228     const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point);
229     const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point);
230     const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point);
231     const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF), voutput_zero_point);
232     const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point);
233     const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x89AB), vacc2xCDEF), voutput_zero_point);
234     const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point);
235     const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x89AB), vacc3xCDEF), voutput_zero_point);
236 
237     int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF);
238     int8x16_t vout1x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc1x01234567), vacc1x89ABCDEF);
239     int8x16_t vout2x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc2x89ABCDEF);
240     int8x16_t vout3x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc3x01234567), vacc3x89ABCDEF);
241 #else
242     const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point);
243     const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point);
244     const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point);
245     const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF)), voutput_zero_point);
246     const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point);
247     const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x89AB), vqmovn_s32(vacc2xCDEF)), voutput_zero_point);
248     const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point);
249     const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x89AB), vqmovn_s32(vacc3xCDEF)), voutput_zero_point);
250 
251     int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF));
252     int8x16_t vout1x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc1x01234567), vqmovn_s16(vacc1x89ABCDEF));
253     int8x16_t vout2x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc2x89ABCDEF));
254     int8x16_t vout3x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc3x01234567), vqmovn_s16(vacc3x89ABCDEF));
255 #endif
256     const int8x16_t voutput_min = vld1q_dup_s8(&params->rndnu_neon.output_min);
257     const int8x16_t voutput_max = vld1q_dup_s8(&params->rndnu_neon.output_max);
258 
259     vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min);
260     vout1x0123456789ABCDEF = vmaxq_s8(vout1x0123456789ABCDEF, voutput_min);
261     vout2x0123456789ABCDEF = vmaxq_s8(vout2x0123456789ABCDEF, voutput_min);
262     vout3x0123456789ABCDEF = vmaxq_s8(vout3x0123456789ABCDEF, voutput_min);
263 
264     vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max);
265     vout1x0123456789ABCDEF = vminq_s8(vout1x0123456789ABCDEF, voutput_max);
266     vout2x0123456789ABCDEF = vminq_s8(vout2x0123456789ABCDEF, voutput_max);
267     vout3x0123456789ABCDEF = vminq_s8(vout3x0123456789ABCDEF, voutput_max);
268 
269     if (nc >= 16) {
270       // Main case where there the 16 columns fit in the destination.
271       vst1q_s8(c0 + 0, vout0x0123456789ABCDEF);
272       vst1q_s8(c1 + 0, vout1x0123456789ABCDEF);
273       vst1q_s8(c2 + 0, vout2x0123456789ABCDEF);
274       vst1q_s8(c3 + 0, vout3x0123456789ABCDEF);
275 
276       // Advance to the next 16 columns.
277       c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
278       c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
279       c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
280       c3 = (int8_t*) ((uintptr_t) c3 + cn_stride);
281 
282       a0 = (const int8_t*) ((uintptr_t) a0 - kc);
283       a1 = (const int8_t*) ((uintptr_t) a1 - kc);
284       a2 = (const int8_t*) ((uintptr_t) a2 - kc);
285       a3 = (const int8_t*) ((uintptr_t) a3 - kc);
286 
287       nc -= 16;
288     } else {
289       // Final case where not all of the 16 columns fit in the destination.
290       int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vget_low_s8(vout0x0123456789ABCDEF), vget_low_s8(vout1x0123456789ABCDEF));
291       int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vget_low_s8(vout2x0123456789ABCDEF), vget_low_s8(vout3x0123456789ABCDEF));
292       if (nc & 8) {
293         vst1_s8(c0, vget_low_s8(vout0x01234567_1x01234567)); c0 += 8;
294         vst1_s8(c1, vget_high_s8(vout0x01234567_1x01234567)); c1 += 8;
295         vst1_s8(c2, vget_low_s8(vout2x01234567_3x01234567)); c2 += 8;
296         vst1_s8(c3, vget_high_s8(vout2x01234567_3x01234567)); c3 += 8;
297         vout0x01234567_1x01234567 = vcombine_s8(vget_high_s8(vout0x0123456789ABCDEF), vget_high_s8(vout1x0123456789ABCDEF));
298         vout2x01234567_3x01234567 = vcombine_s8(vget_high_s8(vout2x0123456789ABCDEF), vget_high_s8(vout3x0123456789ABCDEF));
299       }
300       if (nc & 4) {
301         vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
302         vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
303         vst1q_lane_u32((void*) c2, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4;
304         vst1q_lane_u32((void*) c3, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4;
305         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
306         vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4);
307       }
308       if (nc & 2) {
309         vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
310         vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
311         vst1q_lane_u16((void*) c2, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2;
312         vst1q_lane_u16((void*) c3, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2;
313         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
314         vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2);
315       }
316       if (nc & 1) {
317         vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
318         vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
319         vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0);
320         vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8);
321       }
322 
323       nc = 0;
324     }
325   } while (nc != 0);
326 }
327