xref: /aosp_15_r20/external/XNNPACK/src/qs8-igemm/gen/2x16c2-minmax-rndnu-neon-mlal-ld1r.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-igemm/c2-neon-mull-dup.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2021 Google LLC
6 //
7 // This source code is licensed under the BSD-style license found in the
8 // LICENSE file in the root directory of this source tree.
9 
10 #include <assert.h>
11 
12 #include <arm_neon.h>
13 
14 #include <xnnpack/gemm.h>
15 #include <xnnpack/math.h>
16 
xnn_qs8_igemm_minmax_rndnu_ukernel_2x16c2__neon_mlal_ld1r(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)])17 void xnn_qs8_igemm_minmax_rndnu_ukernel_2x16c2__neon_mlal_ld1r(
18     size_t mr,
19     size_t nc,
20     size_t kc,
21     size_t ks,
22     const int8_t** restrict a,
23     const void* restrict w,
24     int8_t* restrict c,
25     size_t cm_stride,
26     size_t cn_stride,
27     size_t a_offset,
28     const int8_t* zero,
29     const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
30 {
31   assert(mr != 0);
32   assert(mr <= 2);
33   assert(nc != 0);
34   assert(kc != 0);
35   assert(ks != 0);
36   assert(ks % (2 * sizeof(void*)) == 0);
37   assert(a_offset % sizeof(int8_t) == 0);
38   assert(a != NULL);
39   assert(w != NULL);
40   assert(c != NULL);
41 
42   kc = round_up_po2(kc, 2 * sizeof(int8_t));
43   int8_t* c0 = c;
44   int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
45   if XNN_UNPREDICTABLE(mr != 2) {
46     c1 = c0;
47   }
48 
49   do {
50     int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
51     int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
52     int32x4_t vacc0x89AB = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
53     int32x4_t vacc0xCDEF = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
54     int32x4_t vacc1x0123 = vacc0x0123;
55     int32x4_t vacc1x4567 = vacc0x4567;
56     int32x4_t vacc1x89AB = vacc0x89AB;
57     int32x4_t vacc1xCDEF = vacc0xCDEF;
58 
59     size_t p = ks;
60     do {
61       const int8_t* restrict a0 = a[0];
62       if XNN_UNPREDICTABLE(a0 != zero) {
63         a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
64       }
65       const int8_t* restrict a1 = a[1];
66       if XNN_UNPREDICTABLE(a1 != zero) {
67         a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
68       }
69       a += 2;
70 
71       size_t k = kc;
72 
73       while (k >= 16 * sizeof(int8_t)) {
74         const int16x4_t va00x0 = vld1_dup_s16((const void*)a0);
75         const int16x4_t va01x0 = vld1_dup_s16((const void*)(a0 + 2));
76         const int16x4_t va02x0 = vld1_dup_s16((const void*)(a0 + 4));
77         const int16x4_t va03x0 = vld1_dup_s16((const void*)(a0 + 6)); a0 += 8;
78         const int16x4_t va00x1 = vld1_dup_s16((const void*)a0);
79         const int16x4_t va01x1 = vld1_dup_s16((const void*)(a0 + 2));
80         const int16x4_t va02x1 = vld1_dup_s16((const void*)(a0 + 4));
81         const int16x4_t va03x1 = vld1_dup_s16((const void*)(a0 + 6)); a0 += 8;
82         const int16x4_t va10x0 = vld1_dup_s16((const void*)a1);
83         const int16x4_t va11x0 = vld1_dup_s16((const void*)(a1 + 2));
84         const int16x4_t va12x0 = vld1_dup_s16((const void*)(a1 + 4));
85         const int16x4_t va13x0 = vld1_dup_s16((const void*)(a1 + 6)); a1 += 8;
86         const int16x4_t va10x1 = vld1_dup_s16((const void*)a1);
87         const int16x4_t va11x1 = vld1_dup_s16((const void*)(a1 + 2));
88         const int16x4_t va12x1 = vld1_dup_s16((const void*)(a1 + 4));
89         const int16x4_t va13x1 = vld1_dup_s16((const void*)(a1 + 6)); a1 += 8;
90 
91         const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
92         const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
93         const int8x8_t vb89ABc0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
94         const int8x8_t vbCDEFc0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
95         const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
96         const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
97         const int8x8_t vb89ABc1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
98         const int8x8_t vbCDEFc1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
99         const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
100         const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
101         const int8x8_t vb89ABc2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
102         const int8x8_t vbCDEFc2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
103         const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
104         const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
105         const int8x8_t vb89ABc3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
106         const int8x8_t vbCDEFc3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
107 
108         const int8x8_t va0c0x0 = vreinterpret_s8_s16(va00x0);
109         const int8x8_t va0c0x1 = vreinterpret_s8_s16(va00x1);
110         const int8x8_t va1c0x0 = vreinterpret_s8_s16(va10x0);
111         const int8x8_t va1c0x1 = vreinterpret_s8_s16(va10x1);
112 
113         int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0c0x0);
114         int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1c0x0);
115         const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
116         vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0c0x1);
117         vprod1x0123c0 = vmlal_s8(vprod1x0123c0, vb0123c0x1, va1c0x1);
118         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
119         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
120         int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0c0x0);
121         int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1c0x0);
122         const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
123         vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0c0x1);
124         vprod1x4567c0 = vmlal_s8(vprod1x4567c0, vb4567c0x1, va1c0x1);
125         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
126         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
127         int16x8_t vprod0x89ABc0 = vmull_s8(vb89ABc0x0, va0c0x0);
128         int16x8_t vprod1x89ABc0 = vmull_s8(vb89ABc0x0, va1c0x0);
129         const int8x8_t vb89ABc0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
130         vprod0x89ABc0 = vmlal_s8(vprod0x89ABc0, vb89ABc0x1, va0c0x1);
131         vprod1x89ABc0 = vmlal_s8(vprod1x89ABc0, vb89ABc0x1, va1c0x1);
132         vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc0);
133         vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc0);
134         int16x8_t vprod0xCDEFc0 = vmull_s8(vbCDEFc0x0, va0c0x0);
135         int16x8_t vprod1xCDEFc0 = vmull_s8(vbCDEFc0x0, va1c0x0);
136         const int8x8_t vbCDEFc0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
137         vprod0xCDEFc0 = vmlal_s8(vprod0xCDEFc0, vbCDEFc0x1, va0c0x1);
138         vprod1xCDEFc0 = vmlal_s8(vprod1xCDEFc0, vbCDEFc0x1, va1c0x1);
139         vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc0);
140         vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc0);
141         const int8x8_t va0c1x0 = vreinterpret_s8_s16(va01x0);
142         const int8x8_t va0c1x1 = vreinterpret_s8_s16(va01x1);
143         const int8x8_t va1c1x0 = vreinterpret_s8_s16(va11x0);
144         const int8x8_t va1c1x1 = vreinterpret_s8_s16(va11x1);
145 
146         int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0c1x0);
147         int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1c1x0);
148         const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
149         vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0c1x1);
150         vprod1x0123c1 = vmlal_s8(vprod1x0123c1, vb0123c1x1, va1c1x1);
151         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
152         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
153         int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0c1x0);
154         int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1c1x0);
155         const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
156         vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0c1x1);
157         vprod1x4567c1 = vmlal_s8(vprod1x4567c1, vb4567c1x1, va1c1x1);
158         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
159         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
160         int16x8_t vprod0x89ABc1 = vmull_s8(vb89ABc1x0, va0c1x0);
161         int16x8_t vprod1x89ABc1 = vmull_s8(vb89ABc1x0, va1c1x0);
162         const int8x8_t vb89ABc1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
163         vprod0x89ABc1 = vmlal_s8(vprod0x89ABc1, vb89ABc1x1, va0c1x1);
164         vprod1x89ABc1 = vmlal_s8(vprod1x89ABc1, vb89ABc1x1, va1c1x1);
165         vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc1);
166         vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc1);
167         int16x8_t vprod0xCDEFc1 = vmull_s8(vbCDEFc1x0, va0c1x0);
168         int16x8_t vprod1xCDEFc1 = vmull_s8(vbCDEFc1x0, va1c1x0);
169         const int8x8_t vbCDEFc1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
170         vprod0xCDEFc1 = vmlal_s8(vprod0xCDEFc1, vbCDEFc1x1, va0c1x1);
171         vprod1xCDEFc1 = vmlal_s8(vprod1xCDEFc1, vbCDEFc1x1, va1c1x1);
172         vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc1);
173         vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc1);
174         const int8x8_t va0c2x0 = vreinterpret_s8_s16(va02x0);
175         const int8x8_t va0c2x1 = vreinterpret_s8_s16(va02x1);
176         const int8x8_t va1c2x0 = vreinterpret_s8_s16(va12x0);
177         const int8x8_t va1c2x1 = vreinterpret_s8_s16(va12x1);
178 
179         int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0c2x0);
180         int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1c2x0);
181         const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
182         vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0c2x1);
183         vprod1x0123c2 = vmlal_s8(vprod1x0123c2, vb0123c2x1, va1c2x1);
184         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
185         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
186         int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0c2x0);
187         int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1c2x0);
188         const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
189         vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0c2x1);
190         vprod1x4567c2 = vmlal_s8(vprod1x4567c2, vb4567c2x1, va1c2x1);
191         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
192         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
193         int16x8_t vprod0x89ABc2 = vmull_s8(vb89ABc2x0, va0c2x0);
194         int16x8_t vprod1x89ABc2 = vmull_s8(vb89ABc2x0, va1c2x0);
195         const int8x8_t vb89ABc2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
196         vprod0x89ABc2 = vmlal_s8(vprod0x89ABc2, vb89ABc2x1, va0c2x1);
197         vprod1x89ABc2 = vmlal_s8(vprod1x89ABc2, vb89ABc2x1, va1c2x1);
198         vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc2);
199         vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc2);
200         int16x8_t vprod0xCDEFc2 = vmull_s8(vbCDEFc2x0, va0c2x0);
201         int16x8_t vprod1xCDEFc2 = vmull_s8(vbCDEFc2x0, va1c2x0);
202         const int8x8_t vbCDEFc2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
203         vprod0xCDEFc2 = vmlal_s8(vprod0xCDEFc2, vbCDEFc2x1, va0c2x1);
204         vprod1xCDEFc2 = vmlal_s8(vprod1xCDEFc2, vbCDEFc2x1, va1c2x1);
205         vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc2);
206         vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc2);
207         const int8x8_t va0c3x0 = vreinterpret_s8_s16(va03x0);
208         const int8x8_t va0c3x1 = vreinterpret_s8_s16(va03x1);
209         const int8x8_t va1c3x0 = vreinterpret_s8_s16(va13x0);
210         const int8x8_t va1c3x1 = vreinterpret_s8_s16(va13x1);
211 
212         int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0c3x0);
213         int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1c3x0);
214         const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
215         vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0c3x1);
216         vprod1x0123c3 = vmlal_s8(vprod1x0123c3, vb0123c3x1, va1c3x1);
217         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
218         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
219         int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0c3x0);
220         int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1c3x0);
221         const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
222         vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0c3x1);
223         vprod1x4567c3 = vmlal_s8(vprod1x4567c3, vb4567c3x1, va1c3x1);
224         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
225         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
226         int16x8_t vprod0x89ABc3 = vmull_s8(vb89ABc3x0, va0c3x0);
227         int16x8_t vprod1x89ABc3 = vmull_s8(vb89ABc3x0, va1c3x0);
228         const int8x8_t vb89ABc3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
229         vprod0x89ABc3 = vmlal_s8(vprod0x89ABc3, vb89ABc3x1, va0c3x1);
230         vprod1x89ABc3 = vmlal_s8(vprod1x89ABc3, vb89ABc3x1, va1c3x1);
231         vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc3);
232         vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc3);
233         int16x8_t vprod0xCDEFc3 = vmull_s8(vbCDEFc3x0, va0c3x0);
234         int16x8_t vprod1xCDEFc3 = vmull_s8(vbCDEFc3x0, va1c3x0);
235         const int8x8_t vbCDEFc3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
236         vprod0xCDEFc3 = vmlal_s8(vprod0xCDEFc3, vbCDEFc3x1, va0c3x1);
237         vprod1xCDEFc3 = vmlal_s8(vprod1xCDEFc3, vbCDEFc3x1, va1c3x1);
238         vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc3);
239         vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc3);
240 
241         k -= 16 * sizeof(int8_t);
242       }
243 
244       if (k >= 8 * sizeof(int8_t)) {
245         const int16x4_t va00 = vld1_dup_s16((const void*)a0);
246         const int16x4_t va01 = vld1_dup_s16((const void*)(a0 + 2));
247         const int16x4_t va02 = vld1_dup_s16((const void*)(a0 + 4));
248         const int16x4_t va03 = vld1_dup_s16((const void*)(a0 + 6)); a0 += 8;
249         const int16x4_t va10 = vld1_dup_s16((const void*)a1);
250         const int16x4_t va11 = vld1_dup_s16((const void*)(a1 + 2));
251         const int16x4_t va12 = vld1_dup_s16((const void*)(a1 + 4));
252         const int16x4_t va13 = vld1_dup_s16((const void*)(a1 + 6)); a1 += 8;
253 
254         const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
255         const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
256         const int8x8_t vb89ABc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
257         const int8x8_t vbCDEFc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
258         const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
259         const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
260         const int8x8_t vb89ABc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
261         const int8x8_t vbCDEFc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
262         const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
263         const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
264         const int8x8_t vb89ABc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
265         const int8x8_t vbCDEFc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
266         const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
267         const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
268         const int8x8_t vb89ABc3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
269         const int8x8_t vbCDEFc3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
270 
271         const int8x8_t va0c0 = vreinterpret_s8_s16(va00);
272         const int8x8_t va1c0 = vreinterpret_s8_s16(va10);
273 
274         const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
275         const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
276         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
277         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
278         const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
279         const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
280         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
281         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
282         const int16x8_t vprod0x89ABc0 = vmull_s8(vb89ABc0, va0c0);
283         const int16x8_t vprod1x89ABc0 = vmull_s8(vb89ABc0, va1c0);
284         vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc0);
285         vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc0);
286         const int16x8_t vprod0xCDEFc0 = vmull_s8(vbCDEFc0, va0c0);
287         const int16x8_t vprod1xCDEFc0 = vmull_s8(vbCDEFc0, va1c0);
288         vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc0);
289         vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc0);
290         const int8x8_t va0c1 = vreinterpret_s8_s16(va01);
291         const int8x8_t va1c1 = vreinterpret_s8_s16(va11);
292 
293         const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
294         const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
295         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
296         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
297         const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
298         const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
299         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
300         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
301         const int16x8_t vprod0x89ABc1 = vmull_s8(vb89ABc1, va0c1);
302         const int16x8_t vprod1x89ABc1 = vmull_s8(vb89ABc1, va1c1);
303         vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc1);
304         vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc1);
305         const int16x8_t vprod0xCDEFc1 = vmull_s8(vbCDEFc1, va0c1);
306         const int16x8_t vprod1xCDEFc1 = vmull_s8(vbCDEFc1, va1c1);
307         vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc1);
308         vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc1);
309         const int8x8_t va0c2 = vreinterpret_s8_s16(va02);
310         const int8x8_t va1c2 = vreinterpret_s8_s16(va12);
311 
312         const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
313         const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
314         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
315         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
316         const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
317         const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
318         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
319         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
320         const int16x8_t vprod0x89ABc2 = vmull_s8(vb89ABc2, va0c2);
321         const int16x8_t vprod1x89ABc2 = vmull_s8(vb89ABc2, va1c2);
322         vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc2);
323         vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc2);
324         const int16x8_t vprod0xCDEFc2 = vmull_s8(vbCDEFc2, va0c2);
325         const int16x8_t vprod1xCDEFc2 = vmull_s8(vbCDEFc2, va1c2);
326         vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc2);
327         vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc2);
328         const int8x8_t va0c3 = vreinterpret_s8_s16(va03);
329         const int8x8_t va1c3 = vreinterpret_s8_s16(va13);
330 
331         const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3);
332         const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, va1c3);
333         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
334         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
335         const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3);
336         const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, va1c3);
337         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
338         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
339         const int16x8_t vprod0x89ABc3 = vmull_s8(vb89ABc3, va0c3);
340         const int16x8_t vprod1x89ABc3 = vmull_s8(vb89ABc3, va1c3);
341         vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc3);
342         vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc3);
343         const int16x8_t vprod0xCDEFc3 = vmull_s8(vbCDEFc3, va0c3);
344         const int16x8_t vprod1xCDEFc3 = vmull_s8(vbCDEFc3, va1c3);
345         vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc3);
346         vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc3);
347 
348         k -= 8 * sizeof(int8_t);
349       }
350 
351       if XNN_UNLIKELY(k != 0) {
352         const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
353         const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
354 
355         const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
356         const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
357         const int8x8_t vb89ABc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
358         const int8x8_t vbCDEFc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
359 
360         const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
361         const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
362         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
363         const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
364         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
365         const int16x8_t vprod0x89ABc0 = vmull_s8(vb89ABc0, va0c0);
366         vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc0);
367         const int16x8_t vprod0xCDEFc0 = vmull_s8(vbCDEFc0, va0c0);
368         vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc0);
369         const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0));
370         const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
371         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
372         const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
373         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
374         const int16x8_t vprod1x89ABc0 = vmull_s8(vb89ABc0, va1c0);
375         vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc0);
376         const int16x8_t vprod1xCDEFc0 = vmull_s8(vbCDEFc0, va1c0);
377         vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc0);
378 
379         if (k > 2 * sizeof(int8_t)) {
380           const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
381           const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
382           const int8x8_t vb89ABc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
383           const int8x8_t vbCDEFc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
384 
385           const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
386           const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
387           vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
388           const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
389           vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
390           const int16x8_t vprod0x89ABc1 = vmull_s8(vb89ABc1, va0c1);
391           vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc1);
392           const int16x8_t vprod0xCDEFc1 = vmull_s8(vbCDEFc1, va0c1);
393           vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc1);
394           const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1));
395           const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
396           vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
397           const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
398           vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
399           const int16x8_t vprod1x89ABc1 = vmull_s8(vb89ABc1, va1c1);
400           vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc1);
401           const int16x8_t vprod1xCDEFc1 = vmull_s8(vbCDEFc1, va1c1);
402           vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc1);
403 
404           if (k > 4 * sizeof(int8_t)) {
405             const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
406             const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
407             const int8x8_t vb89ABc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
408             const int8x8_t vbCDEFc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
409 
410             const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
411             const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
412             vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
413             const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
414             vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
415             const int16x8_t vprod0x89ABc2 = vmull_s8(vb89ABc2, va0c2);
416             vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc2);
417             const int16x8_t vprod0xCDEFc2 = vmull_s8(vbCDEFc2, va0c2);
418             vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc2);
419             const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2));
420             const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
421             vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
422             const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
423             vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
424             const int16x8_t vprod1x89ABc2 = vmull_s8(vb89ABc2, va1c2);
425             vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc2);
426             const int16x8_t vprod1xCDEFc2 = vmull_s8(vbCDEFc2, va1c2);
427             vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc2);
428           }
429         }
430       }
431       p -= 2 * sizeof(void*);
432     } while (p != 0);
433 
434     const int32x4_t vright_pre_shift = vld1q_dup_s32(&params->rndnu_neon.right_pre_shift);
435     const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
436     const int32x4_t vright_post_shift = vld1q_dup_s32(&params->rndnu_neon.right_post_shift);
437 
438     vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
439     vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
440     vacc0x89AB = vqshlq_s32(vacc0x89AB, vright_pre_shift);
441     vacc0xCDEF = vqshlq_s32(vacc0xCDEF, vright_pre_shift);
442     vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
443     vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
444     vacc1x89AB = vqshlq_s32(vacc1x89AB, vright_pre_shift);
445     vacc1xCDEF = vqshlq_s32(vacc1xCDEF, vright_pre_shift);
446 
447     vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
448     vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
449     vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier);
450     vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier);
451     vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
452     vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
453     vacc1x89AB = vqdmulhq_s32(vacc1x89AB, vmultiplier);
454     vacc1xCDEF = vqdmulhq_s32(vacc1xCDEF, vmultiplier);
455 
456     vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
457     vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
458     vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift);
459     vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift);
460     vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
461     vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
462     vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_post_shift);
463     vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_post_shift);
464 
465     const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
466 #if XNN_ARCH_ARM64
467     int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
468     int16x8_t vacc0x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF);
469     int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
470     int16x8_t vacc1x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF);
471 
472     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
473     vacc0x89ABCDEF = vqaddq_s16(vacc0x89ABCDEF, voutput_zero_point);
474     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
475     vacc1x89ABCDEF = vqaddq_s16(vacc1x89ABCDEF, voutput_zero_point);
476 
477     int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF);
478     int8x16_t vout1x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc1x01234567), vacc1x89ABCDEF);
479 #else
480     int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
481     int16x8_t vacc0x89ABCDEF = vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF));
482     int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
483     int16x8_t vacc1x89ABCDEF = vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF));
484 
485     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
486     vacc0x89ABCDEF = vqaddq_s16(vacc0x89ABCDEF, voutput_zero_point);
487     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
488     vacc1x89ABCDEF = vqaddq_s16(vacc1x89ABCDEF, voutput_zero_point);
489 
490     int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF));
491     int8x16_t vout1x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc1x01234567), vqmovn_s16(vacc1x89ABCDEF));
492 #endif
493 
494     const int8x16_t voutput_min = vld1q_dup_s8(&params->rndnu_neon.output_min);
495     vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min);
496     vout1x0123456789ABCDEF = vmaxq_s8(vout1x0123456789ABCDEF, voutput_min);
497 
498     const int8x16_t voutput_max = vld1q_dup_s8(&params->rndnu_neon.output_max);
499     vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max);
500     vout1x0123456789ABCDEF = vminq_s8(vout1x0123456789ABCDEF, voutput_max);
501 
502     if (nc >= 16) {
503       vst1q_s8(c1 + 0, vout1x0123456789ABCDEF);
504       vst1q_s8(c0 + 0, vout0x0123456789ABCDEF);
505 
506       c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
507       c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
508 
509       a = (const int8_t**restrict) ((uintptr_t) a - ks);
510 
511       nc -= 16;
512     } else {
513       int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vget_low_s8(vout0x0123456789ABCDEF), vget_low_s8(vout1x0123456789ABCDEF));
514       if (nc & 8) {
515         vst1_s8(c1, vget_high_s8(vout0x01234567_1x01234567)); c1 += 8;
516         vst1_s8(c0, vget_low_s8(vout0x01234567_1x01234567)); c0 += 8;
517         vout0x01234567_1x01234567 = vcombine_s8(vget_high_s8(vout0x0123456789ABCDEF), vget_high_s8(vout1x0123456789ABCDEF));
518       }
519       if (nc & 4) {
520         vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
521         vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
522         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
523       }
524       if (nc & 2) {
525         vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
526         vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
527         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
528       }
529       if (nc & 1) {
530         vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
531         vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
532       }
533 
534       nc = 0;
535     }
536   } while (nc != 0);
537 }
538