xref: /aosp_15_r20/external/XNNPACK/src/qs8-igemm/gen/8x8c4-minmax-rndnu-neondot.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-igemm/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/igemm.h>
15 #include <xnnpack/math.h>
16 
17 
xnn_qs8_igemm_minmax_rndnu_ukernel_8x8c4__neondot(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)])18 void xnn_qs8_igemm_minmax_rndnu_ukernel_8x8c4__neondot(
19     size_t mr,
20     size_t nc,
21     size_t kc,
22     size_t ks,
23     const int8_t** restrict a,
24     const void* restrict w,
25     int8_t* restrict c,
26     size_t cm_stride,
27     size_t cn_stride,
28     size_t a_offset,
29     const int8_t* zero,
30     const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
31 {
32   assert(mr != 0);
33   assert(mr <= 8);
34   assert(nc != 0);
35   assert(kc != 0);
36   assert(ks != 0);
37   assert(ks % (8 * sizeof(void*)) == 0);
38   assert(a_offset % sizeof(int8_t) == 0);
39   assert(a != NULL);
40   assert(w != NULL);
41   assert(c != NULL);
42 
43   kc = round_up_po2(kc, 4 * sizeof(int8_t));
44   int8_t* c0 = c;
45   int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
46   if XNN_UNPREDICTABLE(mr < 2) {
47     c1 = c0;
48   }
49   int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
50   if XNN_UNPREDICTABLE(mr <= 2) {
51     c2 = c1;
52   }
53   int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride);
54   if XNN_UNPREDICTABLE(mr < 4) {
55     c3 = c2;
56   }
57   int8_t* c4 = (int8_t*) ((uintptr_t) c3 + cm_stride);
58   if XNN_UNPREDICTABLE(mr <= 4) {
59     c4 = c3;
60   }
61   int8_t* c5 = (int8_t*) ((uintptr_t) c4 + cm_stride);
62   if XNN_UNPREDICTABLE(mr < 6) {
63     c5 = c4;
64   }
65   int8_t* c6 = (int8_t*) ((uintptr_t) c5 + cm_stride);
66   if XNN_UNPREDICTABLE(mr <= 6) {
67     c6 = c5;
68   }
69   int8_t* c7 = (int8_t*) ((uintptr_t) c6 + cm_stride);
70   if XNN_UNPREDICTABLE(mr != 8) {
71     c7 = c6;
72   }
73 
74   do {
75     int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
76     int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
77     int32x4_t vacc1x0123 = vacc0x0123;
78     int32x4_t vacc1x4567 = vacc0x4567;
79     int32x4_t vacc2x0123 = vacc0x0123;
80     int32x4_t vacc2x4567 = vacc0x4567;
81     int32x4_t vacc3x0123 = vacc0x0123;
82     int32x4_t vacc3x4567 = vacc0x4567;
83     int32x4_t vacc4x0123 = vacc0x0123;
84     int32x4_t vacc4x4567 = vacc0x4567;
85     int32x4_t vacc5x0123 = vacc0x0123;
86     int32x4_t vacc5x4567 = vacc0x4567;
87     int32x4_t vacc6x0123 = vacc0x0123;
88     int32x4_t vacc6x4567 = vacc0x4567;
89     int32x4_t vacc7x0123 = vacc0x0123;
90     int32x4_t vacc7x4567 = vacc0x4567;
91 
92     size_t p = ks;
93     do {
94       const int8_t* restrict a0 = a[0];
95       if XNN_UNPREDICTABLE(a0 != zero) {
96         a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
97       }
98       const int8_t* restrict a1 = a[1];
99       if XNN_UNPREDICTABLE(a1 != zero) {
100         a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
101       }
102       const int8_t* restrict a2 = a[2];
103       if XNN_UNPREDICTABLE(a2 != zero) {
104         a2 = (const int8_t*) ((uintptr_t) a2 + a_offset);
105       }
106       const int8_t* restrict a3 = a[3];
107       if XNN_UNPREDICTABLE(a3 != zero) {
108         a3 = (const int8_t*) ((uintptr_t) a3 + a_offset);
109       }
110       const int8_t* restrict a4 = a[4];
111       if XNN_UNPREDICTABLE(a4 != zero) {
112         a4 = (const int8_t*) ((uintptr_t) a4 + a_offset);
113       }
114       const int8_t* restrict a5 = a[5];
115       if XNN_UNPREDICTABLE(a5 != zero) {
116         a5 = (const int8_t*) ((uintptr_t) a5 + a_offset);
117       }
118       const int8_t* restrict a6 = a[6];
119       if XNN_UNPREDICTABLE(a6 != zero) {
120         a6 = (const int8_t*) ((uintptr_t) a6 + a_offset);
121       }
122       const int8_t* restrict a7 = a[7];
123       if XNN_UNPREDICTABLE(a7 != zero) {
124         a7 = (const int8_t*) ((uintptr_t) a7 + a_offset);
125       }
126       a += 8;
127 
128       // Inner accumulation loop along the 8 columns.
129       size_t k = kc;
130       // 2x partial unrolled loop to load 8 bytes at a time.
131       while (k >= 8 * sizeof(int8_t)) {
132         // Load a 8x8 block of activations.
133         const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8;
134         const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8;
135         const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8;
136         const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8;
137         const int8x8_t va4x01234567 = vld1_s8(a4); a4 += 8;
138         const int8x8_t va5x01234567 = vld1_s8(a5); a5 += 8;
139         const int8x8_t va6x01234567 = vld1_s8(a6); a6 += 8;
140         const int8x8_t va7x01234567 = vld1_s8(a7); a7 += 8;
141 
142         // Load a 8x8 block of weights.
143         const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
144         const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
145         const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
146         const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
147 
148         // Multiply-accumulate: 8x8 * 8x8 --> 8x8.
149         vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
150         vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
151         vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
152         vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
153         vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0);
154         vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0);
155         vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0);
156         vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0);
157         vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb0123x0123, va4x01234567, 0);
158         vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb0123x4567, va4x01234567, 0);
159         vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb0123x0123, va5x01234567, 0);
160         vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb0123x4567, va5x01234567, 0);
161         vacc6x0123 = vdotq_lane_s32(vacc6x0123, vb0123x0123, va6x01234567, 0);
162         vacc6x4567 = vdotq_lane_s32(vacc6x4567, vb0123x4567, va6x01234567, 0);
163         vacc7x0123 = vdotq_lane_s32(vacc7x0123, vb0123x0123, va7x01234567, 0);
164         vacc7x4567 = vdotq_lane_s32(vacc7x4567, vb0123x4567, va7x01234567, 0);
165         vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1);
166         vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1);
167         vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1);
168         vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1);
169         vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1);
170         vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1);
171         vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1);
172         vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1);
173         vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb4567x0123, va4x01234567, 1);
174         vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb4567x4567, va4x01234567, 1);
175         vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb4567x0123, va5x01234567, 1);
176         vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb4567x4567, va5x01234567, 1);
177         vacc6x0123 = vdotq_lane_s32(vacc6x0123, vb4567x0123, va6x01234567, 1);
178         vacc6x4567 = vdotq_lane_s32(vacc6x4567, vb4567x4567, va6x01234567, 1);
179         vacc7x0123 = vdotq_lane_s32(vacc7x0123, vb4567x0123, va7x01234567, 1);
180         vacc7x4567 = vdotq_lane_s32(vacc7x4567, vb4567x4567, va7x01234567, 1);
181 
182         k -= 8 * sizeof(int8_t);
183       }
184       // Handle up to 4 final positions of `k`
185       if XNN_UNLIKELY(k != 0) {
186         // Load a 8x4 block of activations.
187         const int8x8_t va0x01234567 = vld1_s8(a0);
188         const int8x8_t va1x01234567 = vld1_s8(a1);
189         const int8x8_t va2x01234567 = vld1_s8(a2);
190         const int8x8_t va3x01234567 = vld1_s8(a3);
191         const int8x8_t va4x01234567 = vld1_s8(a4);
192         const int8x8_t va5x01234567 = vld1_s8(a5);
193         const int8x8_t va6x01234567 = vld1_s8(a6);
194         const int8x8_t va7x01234567 = vld1_s8(a7);
195 
196         // Load a 4x8 block of weights.
197         const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
198         const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
199 
200         // Multiply-accumulate: 8x4 * 4x8 --> 8x8.
201         vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
202         vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
203         vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
204         vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
205         vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0);
206         vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0);
207         vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0);
208         vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0);
209         vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb0123x0123, va4x01234567, 0);
210         vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb0123x4567, va4x01234567, 0);
211         vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb0123x0123, va5x01234567, 0);
212         vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb0123x4567, va5x01234567, 0);
213         vacc6x0123 = vdotq_lane_s32(vacc6x0123, vb0123x0123, va6x01234567, 0);
214         vacc6x4567 = vdotq_lane_s32(vacc6x4567, vb0123x4567, va6x01234567, 0);
215         vacc7x0123 = vdotq_lane_s32(vacc7x0123, vb0123x0123, va7x01234567, 0);
216         vacc7x4567 = vdotq_lane_s32(vacc7x4567, vb0123x4567, va7x01234567, 0);
217       }
218       p -= 8 * sizeof(void*);
219     } while (p != 0);
220 
221     const int32x4_t vright_pre_shift = vld1q_dup_s32(&params->rndnu_neon.right_pre_shift);
222     const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
223     const int32x4_t vright_post_shift = vld1q_dup_s32(&params->rndnu_neon.right_post_shift);
224 
225     vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift);
226     vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift);
227     vacc1x0123 = vshlq_s32(vacc1x0123, vright_pre_shift);
228     vacc1x4567 = vshlq_s32(vacc1x4567, vright_pre_shift);
229     vacc2x0123 = vshlq_s32(vacc2x0123, vright_pre_shift);
230     vacc2x4567 = vshlq_s32(vacc2x4567, vright_pre_shift);
231     vacc3x0123 = vshlq_s32(vacc3x0123, vright_pre_shift);
232     vacc3x4567 = vshlq_s32(vacc3x4567, vright_pre_shift);
233     vacc4x0123 = vshlq_s32(vacc4x0123, vright_pre_shift);
234     vacc4x4567 = vshlq_s32(vacc4x4567, vright_pre_shift);
235     vacc5x0123 = vshlq_s32(vacc5x0123, vright_pre_shift);
236     vacc5x4567 = vshlq_s32(vacc5x4567, vright_pre_shift);
237     vacc6x0123 = vshlq_s32(vacc6x0123, vright_pre_shift);
238     vacc6x4567 = vshlq_s32(vacc6x4567, vright_pre_shift);
239     vacc7x0123 = vshlq_s32(vacc7x0123, vright_pre_shift);
240     vacc7x4567 = vshlq_s32(vacc7x4567, vright_pre_shift);
241 
242     vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
243     vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
244     vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
245     vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
246     vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier);
247     vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier);
248     vacc3x0123 = vqdmulhq_s32(vacc3x0123, vmultiplier);
249     vacc3x4567 = vqdmulhq_s32(vacc3x4567, vmultiplier);
250     vacc4x0123 = vqdmulhq_s32(vacc4x0123, vmultiplier);
251     vacc4x4567 = vqdmulhq_s32(vacc4x4567, vmultiplier);
252     vacc5x0123 = vqdmulhq_s32(vacc5x0123, vmultiplier);
253     vacc5x4567 = vqdmulhq_s32(vacc5x4567, vmultiplier);
254     vacc6x0123 = vqdmulhq_s32(vacc6x0123, vmultiplier);
255     vacc6x4567 = vqdmulhq_s32(vacc6x4567, vmultiplier);
256     vacc7x0123 = vqdmulhq_s32(vacc7x0123, vmultiplier);
257     vacc7x4567 = vqdmulhq_s32(vacc7x4567, vmultiplier);
258 
259     vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
260     vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
261     vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
262     vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
263     vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift);
264     vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift);
265     vacc3x0123 = vrshlq_s32(vacc3x0123, vright_post_shift);
266     vacc3x4567 = vrshlq_s32(vacc3x4567, vright_post_shift);
267     vacc4x0123 = vrshlq_s32(vacc4x0123, vright_post_shift);
268     vacc4x4567 = vrshlq_s32(vacc4x4567, vright_post_shift);
269     vacc5x0123 = vrshlq_s32(vacc5x0123, vright_post_shift);
270     vacc5x4567 = vrshlq_s32(vacc5x4567, vright_post_shift);
271     vacc6x0123 = vrshlq_s32(vacc6x0123, vright_post_shift);
272     vacc6x4567 = vrshlq_s32(vacc6x4567, vright_post_shift);
273     vacc7x0123 = vrshlq_s32(vacc7x0123, vright_post_shift);
274     vacc7x4567 = vrshlq_s32(vacc7x4567, vright_post_shift);
275 
276     const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
277 #if XNN_ARCH_ARM64
278     const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point);
279     const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point);
280     const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point);
281     const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point);
282     const int16x8_t vacc4x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc4x0123), vacc4x4567), voutput_zero_point);
283     const int16x8_t vacc5x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc5x0123), vacc5x4567), voutput_zero_point);
284     const int16x8_t vacc6x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc6x0123), vacc6x4567), voutput_zero_point);
285     const int16x8_t vacc7x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc7x0123), vacc7x4567), voutput_zero_point);
286 
287     int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567);
288     int8x16_t vout2x01234567_3x01234567 = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc3x01234567);
289     int8x16_t vout4x01234567_5x01234567 = vqmovn_high_s16(vqmovn_s16(vacc4x01234567), vacc5x01234567);
290     int8x16_t vout6x01234567_7x01234567 = vqmovn_high_s16(vqmovn_s16(vacc6x01234567), vacc7x01234567);
291 #else
292     const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point);
293     const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point);
294     const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point);
295     const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point);
296     const int16x8_t vacc4x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc4x0123), vqmovn_s32(vacc4x4567)), voutput_zero_point);
297     const int16x8_t vacc5x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc5x0123), vqmovn_s32(vacc5x4567)), voutput_zero_point);
298     const int16x8_t vacc6x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc6x0123), vqmovn_s32(vacc6x4567)), voutput_zero_point);
299     const int16x8_t vacc7x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc7x0123), vqmovn_s32(vacc7x4567)), voutput_zero_point);
300 
301     int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567));
302     int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc3x01234567));
303     int8x16_t vout4x01234567_5x01234567 = vcombine_s8(vqmovn_s16(vacc4x01234567), vqmovn_s16(vacc5x01234567));
304     int8x16_t vout6x01234567_7x01234567 = vcombine_s8(vqmovn_s16(vacc6x01234567), vqmovn_s16(vacc7x01234567));
305 #endif
306     const int8x16_t voutput_min = vld1q_dup_s8(&params->rndnu_neon.output_min);
307     const int8x16_t voutput_max = vld1q_dup_s8(&params->rndnu_neon.output_max);
308 
309     vout6x01234567_7x01234567 = vmaxq_s8(vout6x01234567_7x01234567, voutput_min);
310     vout4x01234567_5x01234567 = vmaxq_s8(vout4x01234567_5x01234567, voutput_min);
311     vout2x01234567_3x01234567 = vmaxq_s8(vout2x01234567_3x01234567, voutput_min);
312     vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min);
313 
314     vout6x01234567_7x01234567 = vminq_s8(vout6x01234567_7x01234567, voutput_max);
315     vout4x01234567_5x01234567 = vminq_s8(vout4x01234567_5x01234567, voutput_max);
316     vout2x01234567_3x01234567 = vminq_s8(vout2x01234567_3x01234567, voutput_max);
317     vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max);
318 
319     if (nc >= 8) {
320       vst1_s8(c7 + 0, vget_high_s8(vout6x01234567_7x01234567));
321       vst1_s8(c6 + 0, vget_low_s8(vout6x01234567_7x01234567));
322       vst1_s8(c5 + 0, vget_high_s8(vout4x01234567_5x01234567));
323       vst1_s8(c4 + 0, vget_low_s8(vout4x01234567_5x01234567));
324       vst1_s8(c3 + 0, vget_high_s8(vout2x01234567_3x01234567));
325       vst1_s8(c2 + 0, vget_low_s8(vout2x01234567_3x01234567));
326       vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567));
327       vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567));
328 
329       c7 = (int8_t*) ((uintptr_t) c7 + cn_stride);
330       c6 = (int8_t*) ((uintptr_t) c6 + cn_stride);
331       c5 = (int8_t*) ((uintptr_t) c5 + cn_stride);
332       c4 = (int8_t*) ((uintptr_t) c4 + cn_stride);
333       c3 = (int8_t*) ((uintptr_t) c3 + cn_stride);
334       c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
335       c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
336       c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
337 
338       a = (const int8_t**restrict) ((uintptr_t) a - ks);
339 
340       nc -= 8;
341     } else {
342       if (nc & 4) {
343         vst1q_lane_u32((void*) c7, vreinterpretq_u32_s8(vout6x01234567_7x01234567), 2); c7 += 4;
344         vst1q_lane_u32((void*) c6, vreinterpretq_u32_s8(vout6x01234567_7x01234567), 0); c6 += 4;
345         vst1q_lane_u32((void*) c5, vreinterpretq_u32_s8(vout4x01234567_5x01234567), 2); c5 += 4;
346         vst1q_lane_u32((void*) c4, vreinterpretq_u32_s8(vout4x01234567_5x01234567), 0); c4 += 4;
347         vst1q_lane_u32((void*) c3, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4;
348         vst1q_lane_u32((void*) c2, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4;
349         vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
350         vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
351         vout6x01234567_7x01234567 = vextq_s8(vout6x01234567_7x01234567, vout6x01234567_7x01234567, 4);
352         vout4x01234567_5x01234567 = vextq_s8(vout4x01234567_5x01234567, vout4x01234567_5x01234567, 4);
353         vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4);
354         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
355       }
356       if (nc & 2) {
357         vst1q_lane_u16((void*) c7, vreinterpretq_u16_s8(vout6x01234567_7x01234567), 4); c7 += 2;
358         vst1q_lane_u16((void*) c6, vreinterpretq_u16_s8(vout6x01234567_7x01234567), 0); c6 += 2;
359         vst1q_lane_u16((void*) c5, vreinterpretq_u16_s8(vout4x01234567_5x01234567), 4); c5 += 2;
360         vst1q_lane_u16((void*) c4, vreinterpretq_u16_s8(vout4x01234567_5x01234567), 0); c4 += 2;
361         vst1q_lane_u16((void*) c3, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2;
362         vst1q_lane_u16((void*) c2, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2;
363         vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
364         vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
365         vout6x01234567_7x01234567 = vextq_s8(vout6x01234567_7x01234567, vout6x01234567_7x01234567, 2);
366         vout4x01234567_5x01234567 = vextq_s8(vout4x01234567_5x01234567, vout4x01234567_5x01234567, 2);
367         vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2);
368         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
369       }
370       if (nc & 1) {
371         vst1q_lane_s8(c7, vout6x01234567_7x01234567, 8);
372         vst1q_lane_s8(c6, vout6x01234567_7x01234567, 0);
373         vst1q_lane_s8(c5, vout4x01234567_5x01234567, 8);
374         vst1q_lane_s8(c4, vout4x01234567_5x01234567, 0);
375         vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8);
376         vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0);
377         vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
378         vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
379       }
380 
381       nc = 0;
382     }
383   } while (nc != 0);
384 }
385