• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_4x8c2__neon_mlal_dup(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_4x8c2__neon_mlal_dup(
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 <= 4);
33   assert(nc != 0);
34   assert(kc != 0);
35   assert(ks != 0);
36   assert(ks % (4 * 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   int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
49   if XNN_UNPREDICTABLE(mr <= 2) {
50     c2 = c1;
51   }
52   int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride);
53   if XNN_UNPREDICTABLE(mr != 4) {
54     c3 = c2;
55   }
56 
57   do {
58     int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
59     int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
60     int32x4_t vacc1x0123 = vacc0x0123;
61     int32x4_t vacc1x4567 = vacc0x4567;
62     int32x4_t vacc2x0123 = vacc0x0123;
63     int32x4_t vacc2x4567 = vacc0x4567;
64     int32x4_t vacc3x0123 = vacc0x0123;
65     int32x4_t vacc3x4567 = vacc0x4567;
66 
67     size_t p = ks;
68     do {
69       const int8_t* restrict a0 = a[0];
70       if XNN_UNPREDICTABLE(a0 != zero) {
71         a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
72       }
73       const int8_t* restrict a1 = a[1];
74       if XNN_UNPREDICTABLE(a1 != zero) {
75         a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
76       }
77       const int8_t* restrict a2 = a[2];
78       if XNN_UNPREDICTABLE(a2 != zero) {
79         a2 = (const int8_t*) ((uintptr_t) a2 + a_offset);
80       }
81       const int8_t* restrict a3 = a[3];
82       if XNN_UNPREDICTABLE(a3 != zero) {
83         a3 = (const int8_t*) ((uintptr_t) a3 + a_offset);
84       }
85       a += 4;
86 
87       size_t k = kc;
88 
89       while (k >= 16 * sizeof(int8_t)) {
90         const int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
91         const int8x8_t va0x1 = vld1_s8(a0); a0 += 8;
92         const int8x8_t va1x0 = vld1_s8(a1); a1 += 8;
93         const int8x8_t va1x1 = vld1_s8(a1); a1 += 8;
94         const int8x8_t va2x0 = vld1_s8(a2); a2 += 8;
95         const int8x8_t va2x1 = vld1_s8(a2); a2 += 8;
96         const int8x8_t va3x0 = vld1_s8(a3); a3 += 8;
97         const int8x8_t va3x1 = vld1_s8(a3); a3 += 8;
98 
99         const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
100         const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
101         const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
102         const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
103         const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
104         const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
105         const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
106         const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
107 
108         const int8x8_t va0c0x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 0));
109         const int8x8_t va0c0x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 0));
110         const int8x8_t va1c0x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 0));
111         const int8x8_t va1c0x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 0));
112         const int8x8_t va2c0x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x0), 0));
113         const int8x8_t va2c0x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x1), 0));
114         const int8x8_t va3c0x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3x0), 0));
115         const int8x8_t va3c0x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3x1), 0));
116 
117         int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0c0x0);
118         int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1c0x0);
119         int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0x0, va2c0x0);
120         int16x8_t vprod3x0123c0 = vmull_s8(vb0123c0x0, va3c0x0);
121         const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
122         vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0c0x1);
123         vprod1x0123c0 = vmlal_s8(vprod1x0123c0, vb0123c0x1, va1c0x1);
124         vprod2x0123c0 = vmlal_s8(vprod2x0123c0, vb0123c0x1, va2c0x1);
125         vprod3x0123c0 = vmlal_s8(vprod3x0123c0, vb0123c0x1, va3c0x1);
126         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
127         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
128         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
129         vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c0);
130         int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0c0x0);
131         int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1c0x0);
132         int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0x0, va2c0x0);
133         int16x8_t vprod3x4567c0 = vmull_s8(vb4567c0x0, va3c0x0);
134         const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
135         vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0c0x1);
136         vprod1x4567c0 = vmlal_s8(vprod1x4567c0, vb4567c0x1, va1c0x1);
137         vprod2x4567c0 = vmlal_s8(vprod2x4567c0, vb4567c0x1, va2c0x1);
138         vprod3x4567c0 = vmlal_s8(vprod3x4567c0, vb4567c0x1, va3c0x1);
139         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
140         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
141         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
142         vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c0);
143         const int8x8_t va0c1x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 1));
144         const int8x8_t va0c1x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 1));
145         const int8x8_t va1c1x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 1));
146         const int8x8_t va1c1x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 1));
147         const int8x8_t va2c1x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x0), 1));
148         const int8x8_t va2c1x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x1), 1));
149         const int8x8_t va3c1x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3x0), 1));
150         const int8x8_t va3c1x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3x1), 1));
151 
152         int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0c1x0);
153         int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1c1x0);
154         int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1x0, va2c1x0);
155         int16x8_t vprod3x0123c1 = vmull_s8(vb0123c1x0, va3c1x0);
156         const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
157         vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0c1x1);
158         vprod1x0123c1 = vmlal_s8(vprod1x0123c1, vb0123c1x1, va1c1x1);
159         vprod2x0123c1 = vmlal_s8(vprod2x0123c1, vb0123c1x1, va2c1x1);
160         vprod3x0123c1 = vmlal_s8(vprod3x0123c1, vb0123c1x1, va3c1x1);
161         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
162         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
163         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
164         vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c1);
165         int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0c1x0);
166         int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1c1x0);
167         int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1x0, va2c1x0);
168         int16x8_t vprod3x4567c1 = vmull_s8(vb4567c1x0, va3c1x0);
169         const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
170         vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0c1x1);
171         vprod1x4567c1 = vmlal_s8(vprod1x4567c1, vb4567c1x1, va1c1x1);
172         vprod2x4567c1 = vmlal_s8(vprod2x4567c1, vb4567c1x1, va2c1x1);
173         vprod3x4567c1 = vmlal_s8(vprod3x4567c1, vb4567c1x1, va3c1x1);
174         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
175         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
176         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
177         vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c1);
178         const int8x8_t va0c2x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 2));
179         const int8x8_t va0c2x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 2));
180         const int8x8_t va1c2x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 2));
181         const int8x8_t va1c2x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 2));
182         const int8x8_t va2c2x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x0), 2));
183         const int8x8_t va2c2x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x1), 2));
184         const int8x8_t va3c2x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3x0), 2));
185         const int8x8_t va3c2x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3x1), 2));
186 
187         int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0c2x0);
188         int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1c2x0);
189         int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2x0, va2c2x0);
190         int16x8_t vprod3x0123c2 = vmull_s8(vb0123c2x0, va3c2x0);
191         const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
192         vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0c2x1);
193         vprod1x0123c2 = vmlal_s8(vprod1x0123c2, vb0123c2x1, va1c2x1);
194         vprod2x0123c2 = vmlal_s8(vprod2x0123c2, vb0123c2x1, va2c2x1);
195         vprod3x0123c2 = vmlal_s8(vprod3x0123c2, vb0123c2x1, va3c2x1);
196         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
197         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
198         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
199         vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c2);
200         int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0c2x0);
201         int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1c2x0);
202         int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2x0, va2c2x0);
203         int16x8_t vprod3x4567c2 = vmull_s8(vb4567c2x0, va3c2x0);
204         const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
205         vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0c2x1);
206         vprod1x4567c2 = vmlal_s8(vprod1x4567c2, vb4567c2x1, va1c2x1);
207         vprod2x4567c2 = vmlal_s8(vprod2x4567c2, vb4567c2x1, va2c2x1);
208         vprod3x4567c2 = vmlal_s8(vprod3x4567c2, vb4567c2x1, va3c2x1);
209         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
210         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
211         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
212         vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c2);
213         const int8x8_t va0c3x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 3));
214         const int8x8_t va0c3x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 3));
215         const int8x8_t va1c3x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 3));
216         const int8x8_t va1c3x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 3));
217         const int8x8_t va2c3x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x0), 3));
218         const int8x8_t va2c3x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x1), 3));
219         const int8x8_t va3c3x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3x0), 3));
220         const int8x8_t va3c3x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3x1), 3));
221 
222         int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0c3x0);
223         int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1c3x0);
224         int16x8_t vprod2x0123c3 = vmull_s8(vb0123c3x0, va2c3x0);
225         int16x8_t vprod3x0123c3 = vmull_s8(vb0123c3x0, va3c3x0);
226         const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
227         vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0c3x1);
228         vprod1x0123c3 = vmlal_s8(vprod1x0123c3, vb0123c3x1, va1c3x1);
229         vprod2x0123c3 = vmlal_s8(vprod2x0123c3, vb0123c3x1, va2c3x1);
230         vprod3x0123c3 = vmlal_s8(vprod3x0123c3, vb0123c3x1, va3c3x1);
231         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
232         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
233         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c3);
234         vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c3);
235         int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0c3x0);
236         int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1c3x0);
237         int16x8_t vprod2x4567c3 = vmull_s8(vb4567c3x0, va2c3x0);
238         int16x8_t vprod3x4567c3 = vmull_s8(vb4567c3x0, va3c3x0);
239         const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
240         vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0c3x1);
241         vprod1x4567c3 = vmlal_s8(vprod1x4567c3, vb4567c3x1, va1c3x1);
242         vprod2x4567c3 = vmlal_s8(vprod2x4567c3, vb4567c3x1, va2c3x1);
243         vprod3x4567c3 = vmlal_s8(vprod3x4567c3, vb4567c3x1, va3c3x1);
244         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
245         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
246         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c3);
247         vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c3);
248 
249         k -= 16 * sizeof(int8_t);
250       }
251 
252       if (k >= 8 * sizeof(int8_t)) {
253         const int8x8_t va0 = vld1_s8(a0); a0 += 8;
254         const int8x8_t va1 = vld1_s8(a1); a1 += 8;
255         const int8x8_t va2 = vld1_s8(a2); a2 += 8;
256         const int8x8_t va3 = vld1_s8(a3); a3 += 8;
257 
258         const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
259         const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
260         const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
261         const int8x8_t vb4567c1 = 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 vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
265         const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
266 
267         const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
268         const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0));
269         const int8x8_t va2c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 0));
270         const int8x8_t va3c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3), 0));
271 
272         const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
273         const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
274         const int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0, va2c0);
275         const int16x8_t vprod3x0123c0 = vmull_s8(vb0123c0, va3c0);
276         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
277         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
278         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
279         vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c0);
280         const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
281         const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
282         const int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0, va2c0);
283         const int16x8_t vprod3x4567c0 = vmull_s8(vb4567c0, va3c0);
284         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
285         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
286         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
287         vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c0);
288         const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
289         const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1));
290         const int8x8_t va2c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 1));
291         const int8x8_t va3c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3), 1));
292 
293         const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
294         const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
295         const int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1, va2c1);
296         const int16x8_t vprod3x0123c1 = vmull_s8(vb0123c1, va3c1);
297         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
298         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
299         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
300         vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c1);
301         const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
302         const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
303         const int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1, va2c1);
304         const int16x8_t vprod3x4567c1 = vmull_s8(vb4567c1, va3c1);
305         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
306         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
307         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
308         vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c1);
309         const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
310         const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2));
311         const int8x8_t va2c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 2));
312         const int8x8_t va3c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3), 2));
313 
314         const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
315         const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
316         const int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2, va2c2);
317         const int16x8_t vprod3x0123c2 = vmull_s8(vb0123c2, va3c2);
318         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
319         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
320         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
321         vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c2);
322         const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
323         const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
324         const int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2, va2c2);
325         const int16x8_t vprod3x4567c2 = vmull_s8(vb4567c2, va3c2);
326         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
327         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
328         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
329         vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c2);
330         const int8x8_t va0c3 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 3));
331         const int8x8_t va1c3 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 3));
332         const int8x8_t va2c3 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 3));
333         const int8x8_t va3c3 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3), 3));
334 
335         const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3);
336         const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, va1c3);
337         const int16x8_t vprod2x0123c3 = vmull_s8(vb0123c3, va2c3);
338         const int16x8_t vprod3x0123c3 = vmull_s8(vb0123c3, va3c3);
339         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
340         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
341         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c3);
342         vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c3);
343         const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3);
344         const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, va1c3);
345         const int16x8_t vprod2x4567c3 = vmull_s8(vb4567c3, va2c3);
346         const int16x8_t vprod3x4567c3 = vmull_s8(vb4567c3, va3c3);
347         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
348         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
349         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c3);
350         vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c3);
351 
352         k -= 8 * sizeof(int8_t);
353       }
354 
355       if XNN_UNLIKELY(k != 0) {
356         const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
357         const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
358         const int8x8_t va2 = vld1_s8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k);
359         const int8x8_t va3 = vld1_s8(a3); a3 = (const int8_t*) ((uintptr_t) a3 + k);
360 
361         const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
362         const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
363 
364         const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
365         const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
366         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
367         const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
368         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
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 int8x8_t va2c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 0));
375         const int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0, va2c0);
376         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
377         const int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0, va2c0);
378         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
379         const int8x8_t va3c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3), 0));
380         const int16x8_t vprod3x0123c0 = vmull_s8(vb0123c0, va3c0);
381         vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c0);
382         const int16x8_t vprod3x4567c0 = vmull_s8(vb4567c0, va3c0);
383         vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c0);
384 
385         if (k > 2 * sizeof(int8_t)) {
386           const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
387           const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
388 
389           const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
390           const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
391           vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
392           const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
393           vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
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 int8x8_t va2c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 1));
400           const int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1, va2c1);
401           vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
402           const int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1, va2c1);
403           vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
404           const int8x8_t va3c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3), 1));
405           const int16x8_t vprod3x0123c1 = vmull_s8(vb0123c1, va3c1);
406           vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c1);
407           const int16x8_t vprod3x4567c1 = vmull_s8(vb4567c1, va3c1);
408           vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c1);
409 
410           if (k > 4 * sizeof(int8_t)) {
411             const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
412             const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
413 
414             const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
415             const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
416             vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
417             const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
418             vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
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 int8x8_t va2c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 2));
425             const int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2, va2c2);
426             vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
427             const int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2, va2c2);
428             vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
429             const int8x8_t va3c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3), 2));
430             const int16x8_t vprod3x0123c2 = vmull_s8(vb0123c2, va3c2);
431             vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c2);
432             const int16x8_t vprod3x4567c2 = vmull_s8(vb4567c2, va3c2);
433             vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c2);
434           }
435         }
436       }
437       p -= 4 * sizeof(void*);
438     } while (p != 0);
439 
440     const int32x4_t vright_pre_shift = vld1q_dup_s32(&params->rndnu_neon.right_pre_shift);
441     const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
442     const int32x4_t vright_post_shift = vld1q_dup_s32(&params->rndnu_neon.right_post_shift);
443 
444     vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
445     vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
446     vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
447     vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
448     vacc2x0123 = vqshlq_s32(vacc2x0123, vright_pre_shift);
449     vacc2x4567 = vqshlq_s32(vacc2x4567, vright_pre_shift);
450     vacc3x0123 = vqshlq_s32(vacc3x0123, vright_pre_shift);
451     vacc3x4567 = vqshlq_s32(vacc3x4567, vright_pre_shift);
452 
453     vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
454     vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
455     vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
456     vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
457     vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier);
458     vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier);
459     vacc3x0123 = vqdmulhq_s32(vacc3x0123, vmultiplier);
460     vacc3x4567 = vqdmulhq_s32(vacc3x4567, vmultiplier);
461 
462     vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
463     vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
464     vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
465     vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
466     vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift);
467     vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift);
468     vacc3x0123 = vrshlq_s32(vacc3x0123, vright_post_shift);
469     vacc3x4567 = vrshlq_s32(vacc3x4567, vright_post_shift);
470 
471     const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
472 #if XNN_ARCH_ARM64
473     int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
474     int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
475     int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567);
476     int16x8_t vacc3x01234567 = vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567);
477 
478     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
479     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
480     vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
481     vacc3x01234567 = vqaddq_s16(vacc3x01234567, voutput_zero_point);
482 
483     int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567);
484     int8x16_t vout2x01234567_3x01234567 = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc3x01234567);
485 #else
486     int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
487     int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
488     int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567));
489     int16x8_t vacc3x01234567 = vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567));
490 
491     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
492     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
493     vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
494     vacc3x01234567 = vqaddq_s16(vacc3x01234567, voutput_zero_point);
495 
496     int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567));
497     int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc3x01234567));
498 #endif
499 
500     const int8x16_t voutput_min = vld1q_dup_s8(&params->rndnu_neon.output_min);
501     vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min);
502     vout2x01234567_3x01234567 = vmaxq_s8(vout2x01234567_3x01234567, voutput_min);
503 
504     const int8x16_t voutput_max = vld1q_dup_s8(&params->rndnu_neon.output_max);
505     vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max);
506     vout2x01234567_3x01234567 = vminq_s8(vout2x01234567_3x01234567, voutput_max);
507 
508     if (nc >= 8) {
509       vst1_s8(c3 + 0, vget_high_s8(vout2x01234567_3x01234567));
510       vst1_s8(c2 + 0, vget_low_s8(vout2x01234567_3x01234567));
511       vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567));
512       vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567));
513 
514       c3 = (int8_t*) ((uintptr_t) c3 + cn_stride);
515       c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
516       c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
517       c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
518 
519       a = (const int8_t**restrict) ((uintptr_t) a - ks);
520 
521       nc -= 8;
522     } else {
523       if (nc & 4) {
524         vst1q_lane_u32((void*) c3, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4;
525         vst1q_lane_u32((void*) c2, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4;
526         vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
527         vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
528         vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4);
529         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
530       }
531       if (nc & 2) {
532         vst1q_lane_u16((void*) c3, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2;
533         vst1q_lane_u16((void*) c2, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2;
534         vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
535         vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
536         vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2);
537         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
538       }
539       if (nc & 1) {
540         vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8);
541         vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0);
542         vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
543         vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
544       }
545 
546       nc = 0;
547     }
548   } while (nc != 0);
549 }
550