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