• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-igemm/c2-neon-mull-padal-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 
17 
xnn_qs8_igemm_minmax_ukernel_3x8c2__neon_mlal_padal_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_gemm_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qs8_igemm_minmax_ukernel_3x8c2__neon_mlal_padal_dup(
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_gemm_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
31 {
32   assert(mr != 0);
33   assert(mr <= 3);
34   assert(nc != 0);
35   assert(kc != 0);
36   assert(ks != 0);
37   assert(ks % (3 * 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, 2);
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 
54   do {
55     int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
56     int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
57     int32x4_t vacc1x0123 = vacc0x0123;
58     int32x4_t vacc1x4567 = vacc0x4567;
59     int32x4_t vacc2x0123 = vacc0x0123;
60     int32x4_t vacc2x4567 = vacc0x4567;
61 
62     size_t p = ks;
63     do {
64       const int8_t* restrict a0 = a[0];
65       if XNN_UNPREDICTABLE(a0 != zero) {
66         a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
67       }
68       const int8_t* restrict a1 = a[1];
69       if XNN_UNPREDICTABLE(a1 != zero) {
70         a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
71       }
72       const int8_t* restrict a2 = a[2];
73       if XNN_UNPREDICTABLE(a2 != zero) {
74         a2 = (const int8_t*) ((uintptr_t) a2 + a_offset);
75       }
76       a += 3;
77 
78       size_t k = kc;
79 
80       while (k >= 16 * sizeof(int8_t)) {
81         const int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
82         const int8x8_t va0x1 = vld1_s8(a0); a0 += 8;
83         const int8x8_t va1x0 = vld1_s8(a1); a1 += 8;
84         const int8x8_t va1x1 = vld1_s8(a1); a1 += 8;
85         const int8x8_t va2x0 = vld1_s8(a2); a2 += 8;
86         const int8x8_t va2x1 = vld1_s8(a2); a2 += 8;
87 
88         const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
89         const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
90         const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
91         const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
92         const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
93         const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
94         const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
95         const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
96 
97         int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 0)));
98         int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 0)));
99         int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x0), 0)));
100         const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
101         vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 0)));
102         vprod1x0123c0 = vmlal_s8(vprod1x0123c0, vb0123c0x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 0)));
103         vprod2x0123c0 = vmlal_s8(vprod2x0123c0, vb0123c0x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x1), 0)));
104         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
105         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
106         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
107         int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 0)));
108         int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 0)));
109         int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x0), 0)));
110         const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
111         vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 0)));
112         vprod1x4567c0 = vmlal_s8(vprod1x4567c0, vb4567c0x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 0)));
113         vprod2x4567c0 = vmlal_s8(vprod2x4567c0, vb4567c0x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x1), 0)));
114         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
115         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
116         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
117         int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 1)));
118         int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 1)));
119         int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x0), 1)));
120         const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
121         vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 1)));
122         vprod1x0123c1 = vmlal_s8(vprod1x0123c1, vb0123c1x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 1)));
123         vprod2x0123c1 = vmlal_s8(vprod2x0123c1, vb0123c1x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x1), 1)));
124         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
125         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
126         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
127         int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 1)));
128         int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 1)));
129         int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x0), 1)));
130         const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
131         vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 1)));
132         vprod1x4567c1 = vmlal_s8(vprod1x4567c1, vb4567c1x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 1)));
133         vprod2x4567c1 = vmlal_s8(vprod2x4567c1, vb4567c1x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x1), 1)));
134         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
135         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
136         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
137         int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 2)));
138         int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 2)));
139         int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x0), 2)));
140         const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
141         vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 2)));
142         vprod1x0123c2 = vmlal_s8(vprod1x0123c2, vb0123c2x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 2)));
143         vprod2x0123c2 = vmlal_s8(vprod2x0123c2, vb0123c2x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x1), 2)));
144         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
145         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
146         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
147         int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 2)));
148         int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 2)));
149         int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x0), 2)));
150         const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
151         vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 2)));
152         vprod1x4567c2 = vmlal_s8(vprod1x4567c2, vb4567c2x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 2)));
153         vprod2x4567c2 = vmlal_s8(vprod2x4567c2, vb4567c2x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x1), 2)));
154         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
155         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
156         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
157         int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 3)));
158         int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 3)));
159         int16x8_t vprod2x0123c3 = vmull_s8(vb0123c3x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x0), 3)));
160         const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
161         vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 3)));
162         vprod1x0123c3 = vmlal_s8(vprod1x0123c3, vb0123c3x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 3)));
163         vprod2x0123c3 = vmlal_s8(vprod2x0123c3, vb0123c3x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x1), 3)));
164         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
165         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
166         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c3);
167         int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 3)));
168         int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 3)));
169         int16x8_t vprod2x4567c3 = vmull_s8(vb4567c3x0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x0), 3)));
170         const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
171         vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 3)));
172         vprod1x4567c3 = vmlal_s8(vprod1x4567c3, vb4567c3x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 3)));
173         vprod2x4567c3 = vmlal_s8(vprod2x4567c3, vb4567c3x1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2x1), 3)));
174         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
175         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
176         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c3);
177 
178         k -= 16 * sizeof(int8_t);
179       }
180 
181       if (k >= 8 * sizeof(int8_t)) {
182         const int8x8_t va0 = vld1_s8(a0); a0 += 8;
183         const int8x8_t va1 = vld1_s8(a1); a1 += 8;
184         const int8x8_t va2 = vld1_s8(a2); a2 += 8;
185 
186         const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
187         const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
188         const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
189         const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
190         const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
191         const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
192         const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
193         const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
194 
195         const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0)));
196         const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1)));
197         const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2)));
198         const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 3)));
199         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
200         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
201         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
202         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
203         const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0)));
204         const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1)));
205         const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2)));
206         const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 3)));
207         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
208         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
209         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
210         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
211         const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0)));
212         const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1)));
213         const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2)));
214         const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 3)));
215         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
216         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
217         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
218         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
219         const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0)));
220         const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1)));
221         const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2)));
222         const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 3)));
223         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
224         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
225         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
226         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
227         const int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 0)));
228         const int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 1)));
229         const int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 2)));
230         const int16x8_t vprod2x0123c3 = vmull_s8(vb0123c3, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 3)));
231         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
232         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
233         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
234         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c3);
235         const int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 0)));
236         const int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 1)));
237         const int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 2)));
238         const int16x8_t vprod2x4567c3 = vmull_s8(vb4567c3, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 3)));
239         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
240         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
241         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
242         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c3);
243 
244         k -= 8 * sizeof(int8_t);
245       }
246 
247       if XNN_UNLIKELY(k != 0) {
248         const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
249         const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
250         const int8x8_t va2 = vld1_s8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k);
251 
252         const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
253         const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
254 
255         const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0)));
256         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
257         const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0)));
258         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
259         const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0)));
260         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
261         const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0)));
262         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
263         const int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 0)));
264         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
265         const int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 0)));
266         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
267 
268         if (k > 2 * sizeof(int8_t)) {
269           const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
270           const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
271 
272           const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1)));
273           vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
274           const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1)));
275           vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
276           const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1)));
277           vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
278           const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1)));
279           vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
280           const int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 1)));
281           vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
282           const int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 1)));
283           vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
284 
285           if (k > 4 * sizeof(int8_t)) {
286             const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
287             const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
288 
289             const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2)));
290             vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
291             const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2)));
292             vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
293             const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2)));
294             vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
295             const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2)));
296             vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
297             const int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 2)));
298             vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
299             const int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 2)));
300             vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
301           }
302         }
303       }
304       p -= 3 * sizeof(void*);
305     } while (p != 0);
306 
307     const int32x4_t vmultiplier = vld1q_dup_s32(&params->neon.multiplier);
308     vacc0x0123 = vqrdmulhq_s32(vacc0x0123, vmultiplier);
309     vacc0x4567 = vqrdmulhq_s32(vacc0x4567, vmultiplier);
310     vacc1x0123 = vqrdmulhq_s32(vacc1x0123, vmultiplier);
311     vacc1x4567 = vqrdmulhq_s32(vacc1x4567, vmultiplier);
312     vacc2x0123 = vqrdmulhq_s32(vacc2x0123, vmultiplier);
313     vacc2x4567 = vqrdmulhq_s32(vacc2x4567, vmultiplier);
314 
315     const int32x4_t vright_shift = vld1q_dup_s32(&params->neon.right_shift);
316     const int32x4_t vzero_shift_mask = vreinterpretq_s32_u32(vceqq_s32(vright_shift, vmovq_n_s32(0)));
317     vacc0x0123 = vsraq_n_s32(vacc0x0123, vbicq_s32(vacc0x0123, vzero_shift_mask), 31);
318     vacc0x4567 = vsraq_n_s32(vacc0x4567, vbicq_s32(vacc0x4567, vzero_shift_mask), 31);
319     vacc1x0123 = vsraq_n_s32(vacc1x0123, vbicq_s32(vacc1x0123, vzero_shift_mask), 31);
320     vacc1x4567 = vsraq_n_s32(vacc1x4567, vbicq_s32(vacc1x4567, vzero_shift_mask), 31);
321     vacc2x0123 = vsraq_n_s32(vacc2x0123, vbicq_s32(vacc2x0123, vzero_shift_mask), 31);
322     vacc2x4567 = vsraq_n_s32(vacc2x4567, vbicq_s32(vacc2x4567, vzero_shift_mask), 31);
323 
324     vacc0x0123 = vrshlq_s32(vacc0x0123, vright_shift);
325     vacc0x4567 = vrshlq_s32(vacc0x4567, vright_shift);
326     vacc1x0123 = vrshlq_s32(vacc1x0123, vright_shift);
327     vacc1x4567 = vrshlq_s32(vacc1x4567, vright_shift);
328     vacc2x0123 = vrshlq_s32(vacc2x0123, vright_shift);
329     vacc2x4567 = vrshlq_s32(vacc2x4567, vright_shift);
330 
331     const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->neon.output_zero_point);
332 #if XNN_ARCH_ARM64
333     const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point);
334     const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point);
335     const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point);
336 
337     int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567);
338     int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567);
339 #else
340     const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point);
341     const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point);
342     const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point);
343 
344     int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567));
345     int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567);
346 #endif
347     const int8x16_t voutput_min = vld1q_dup_s8(&params->neon.output_min);
348     const int8x16_t voutput_max = vld1q_dup_s8(&params->neon.output_max);
349 
350     vout2x01234567 = vmax_s8(vout2x01234567, vget_low_s8(voutput_min));
351     vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min);
352 
353     vout2x01234567 = vmin_s8(vout2x01234567, vget_low_s8(voutput_max));
354     vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max);
355 
356     if (nc >= 8) {
357       vst1_s8(c2 + 0, vout2x01234567);
358       vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567));
359       vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567));
360 
361       c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
362       c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
363       c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
364 
365       a = (const int8_t**restrict) ((uintptr_t) a - ks);
366 
367       nc -= 8;
368     } else {
369       if (nc & 4) {
370         vst1_lane_u32(__builtin_assume_aligned(c2, 1), vreinterpret_u32_s8(vout2x01234567), 0); c2 += 4;
371         vst1q_lane_u32(__builtin_assume_aligned(c1, 1), vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
372         vst1q_lane_u32(__builtin_assume_aligned(c0, 1), vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
373         vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 4);
374         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
375       }
376       if (nc & 2) {
377         vst1_lane_u16(__builtin_assume_aligned(c2, 1), vreinterpret_u16_s8(vout2x01234567), 0); c2 += 2;
378         vst1q_lane_u16(__builtin_assume_aligned(c1, 1), vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
379         vst1q_lane_u16(__builtin_assume_aligned(c0, 1), vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
380         vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 2);
381         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
382       }
383       if (nc & 1) {
384         vst1_lane_s8(c2, vout2x01234567, 0);
385         vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
386         vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
387       }
388 
389       nc = 0;
390     }
391   } while (nc != 0);
392 }
393