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_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_2x16c2__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 <= 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 int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
75 const int8x8_t va0x1 = vld1_s8(a0); a0 += 8;
76 const int8x8_t va1x0 = vld1_s8(a1); a1 += 8;
77 const int8x8_t va1x1 = vld1_s8(a1); a1 += 8;
78
79 const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
80 const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
81 const int8x8_t vb89ABc0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
82 const int8x8_t vbCDEFc0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
83 const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
84 const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
85 const int8x8_t vb89ABc1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
86 const int8x8_t vbCDEFc1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
87 const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
88 const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
89 const int8x8_t vb89ABc2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
90 const int8x8_t vbCDEFc2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
91 const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
92 const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
93 const int8x8_t vb89ABc3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
94 const int8x8_t vbCDEFc3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
95
96 const int8x8_t va0c0x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 0));
97 const int8x8_t va0c0x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 0));
98 const int8x8_t va1c0x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 0));
99 const int8x8_t va1c0x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 0));
100
101 int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0c0x0);
102 int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1c0x0);
103 const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
104 vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0c0x1);
105 vprod1x0123c0 = vmlal_s8(vprod1x0123c0, vb0123c0x1, va1c0x1);
106 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
107 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
108 int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0c0x0);
109 int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1c0x0);
110 const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
111 vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0c0x1);
112 vprod1x4567c0 = vmlal_s8(vprod1x4567c0, vb4567c0x1, va1c0x1);
113 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
114 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
115 int16x8_t vprod0x89ABc0 = vmull_s8(vb89ABc0x0, va0c0x0);
116 int16x8_t vprod1x89ABc0 = vmull_s8(vb89ABc0x0, va1c0x0);
117 const int8x8_t vb89ABc0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
118 vprod0x89ABc0 = vmlal_s8(vprod0x89ABc0, vb89ABc0x1, va0c0x1);
119 vprod1x89ABc0 = vmlal_s8(vprod1x89ABc0, vb89ABc0x1, va1c0x1);
120 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc0);
121 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc0);
122 int16x8_t vprod0xCDEFc0 = vmull_s8(vbCDEFc0x0, va0c0x0);
123 int16x8_t vprod1xCDEFc0 = vmull_s8(vbCDEFc0x0, va1c0x0);
124 const int8x8_t vbCDEFc0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
125 vprod0xCDEFc0 = vmlal_s8(vprod0xCDEFc0, vbCDEFc0x1, va0c0x1);
126 vprod1xCDEFc0 = vmlal_s8(vprod1xCDEFc0, vbCDEFc0x1, va1c0x1);
127 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc0);
128 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc0);
129 const int8x8_t va0c1x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 1));
130 const int8x8_t va0c1x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 1));
131 const int8x8_t va1c1x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 1));
132 const int8x8_t va1c1x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 1));
133
134 int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0c1x0);
135 int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1c1x0);
136 const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
137 vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0c1x1);
138 vprod1x0123c1 = vmlal_s8(vprod1x0123c1, vb0123c1x1, va1c1x1);
139 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
140 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
141 int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0c1x0);
142 int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1c1x0);
143 const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
144 vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0c1x1);
145 vprod1x4567c1 = vmlal_s8(vprod1x4567c1, vb4567c1x1, va1c1x1);
146 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
147 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
148 int16x8_t vprod0x89ABc1 = vmull_s8(vb89ABc1x0, va0c1x0);
149 int16x8_t vprod1x89ABc1 = vmull_s8(vb89ABc1x0, va1c1x0);
150 const int8x8_t vb89ABc1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
151 vprod0x89ABc1 = vmlal_s8(vprod0x89ABc1, vb89ABc1x1, va0c1x1);
152 vprod1x89ABc1 = vmlal_s8(vprod1x89ABc1, vb89ABc1x1, va1c1x1);
153 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc1);
154 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc1);
155 int16x8_t vprod0xCDEFc1 = vmull_s8(vbCDEFc1x0, va0c1x0);
156 int16x8_t vprod1xCDEFc1 = vmull_s8(vbCDEFc1x0, va1c1x0);
157 const int8x8_t vbCDEFc1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
158 vprod0xCDEFc1 = vmlal_s8(vprod0xCDEFc1, vbCDEFc1x1, va0c1x1);
159 vprod1xCDEFc1 = vmlal_s8(vprod1xCDEFc1, vbCDEFc1x1, va1c1x1);
160 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc1);
161 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc1);
162 const int8x8_t va0c2x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 2));
163 const int8x8_t va0c2x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 2));
164 const int8x8_t va1c2x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 2));
165 const int8x8_t va1c2x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 2));
166
167 int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0c2x0);
168 int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1c2x0);
169 const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
170 vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0c2x1);
171 vprod1x0123c2 = vmlal_s8(vprod1x0123c2, vb0123c2x1, va1c2x1);
172 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
173 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
174 int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0c2x0);
175 int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1c2x0);
176 const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
177 vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0c2x1);
178 vprod1x4567c2 = vmlal_s8(vprod1x4567c2, vb4567c2x1, va1c2x1);
179 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
180 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
181 int16x8_t vprod0x89ABc2 = vmull_s8(vb89ABc2x0, va0c2x0);
182 int16x8_t vprod1x89ABc2 = vmull_s8(vb89ABc2x0, va1c2x0);
183 const int8x8_t vb89ABc2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
184 vprod0x89ABc2 = vmlal_s8(vprod0x89ABc2, vb89ABc2x1, va0c2x1);
185 vprod1x89ABc2 = vmlal_s8(vprod1x89ABc2, vb89ABc2x1, va1c2x1);
186 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc2);
187 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc2);
188 int16x8_t vprod0xCDEFc2 = vmull_s8(vbCDEFc2x0, va0c2x0);
189 int16x8_t vprod1xCDEFc2 = vmull_s8(vbCDEFc2x0, va1c2x0);
190 const int8x8_t vbCDEFc2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
191 vprod0xCDEFc2 = vmlal_s8(vprod0xCDEFc2, vbCDEFc2x1, va0c2x1);
192 vprod1xCDEFc2 = vmlal_s8(vprod1xCDEFc2, vbCDEFc2x1, va1c2x1);
193 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc2);
194 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc2);
195 const int8x8_t va0c3x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 3));
196 const int8x8_t va0c3x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 3));
197 const int8x8_t va1c3x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 3));
198 const int8x8_t va1c3x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 3));
199
200 int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0c3x0);
201 int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1c3x0);
202 const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
203 vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0c3x1);
204 vprod1x0123c3 = vmlal_s8(vprod1x0123c3, vb0123c3x1, va1c3x1);
205 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
206 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
207 int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0c3x0);
208 int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1c3x0);
209 const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
210 vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0c3x1);
211 vprod1x4567c3 = vmlal_s8(vprod1x4567c3, vb4567c3x1, va1c3x1);
212 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
213 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
214 int16x8_t vprod0x89ABc3 = vmull_s8(vb89ABc3x0, va0c3x0);
215 int16x8_t vprod1x89ABc3 = vmull_s8(vb89ABc3x0, va1c3x0);
216 const int8x8_t vb89ABc3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
217 vprod0x89ABc3 = vmlal_s8(vprod0x89ABc3, vb89ABc3x1, va0c3x1);
218 vprod1x89ABc3 = vmlal_s8(vprod1x89ABc3, vb89ABc3x1, va1c3x1);
219 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc3);
220 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc3);
221 int16x8_t vprod0xCDEFc3 = vmull_s8(vbCDEFc3x0, va0c3x0);
222 int16x8_t vprod1xCDEFc3 = vmull_s8(vbCDEFc3x0, va1c3x0);
223 const int8x8_t vbCDEFc3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
224 vprod0xCDEFc3 = vmlal_s8(vprod0xCDEFc3, vbCDEFc3x1, va0c3x1);
225 vprod1xCDEFc3 = vmlal_s8(vprod1xCDEFc3, vbCDEFc3x1, va1c3x1);
226 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc3);
227 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc3);
228
229 k -= 16 * sizeof(int8_t);
230 }
231
232 if (k >= 8 * sizeof(int8_t)) {
233 const int8x8_t va0 = vld1_s8(a0); a0 += 8;
234 const int8x8_t va1 = vld1_s8(a1); a1 += 8;
235
236 const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
237 const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
238 const int8x8_t vb89ABc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
239 const int8x8_t vbCDEFc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
240 const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
241 const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
242 const int8x8_t vb89ABc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
243 const int8x8_t vbCDEFc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
244 const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
245 const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
246 const int8x8_t vb89ABc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
247 const int8x8_t vbCDEFc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
248 const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
249 const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
250 const int8x8_t vb89ABc3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
251 const int8x8_t vbCDEFc3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
252
253 const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
254 const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0));
255
256 const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
257 const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
258 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
259 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
260 const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
261 const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
262 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
263 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
264 const int16x8_t vprod0x89ABc0 = vmull_s8(vb89ABc0, va0c0);
265 const int16x8_t vprod1x89ABc0 = vmull_s8(vb89ABc0, va1c0);
266 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc0);
267 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc0);
268 const int16x8_t vprod0xCDEFc0 = vmull_s8(vbCDEFc0, va0c0);
269 const int16x8_t vprod1xCDEFc0 = vmull_s8(vbCDEFc0, va1c0);
270 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc0);
271 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc0);
272 const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
273 const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1));
274
275 const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
276 const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
277 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
278 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
279 const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
280 const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
281 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
282 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
283 const int16x8_t vprod0x89ABc1 = vmull_s8(vb89ABc1, va0c1);
284 const int16x8_t vprod1x89ABc1 = vmull_s8(vb89ABc1, va1c1);
285 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc1);
286 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc1);
287 const int16x8_t vprod0xCDEFc1 = vmull_s8(vbCDEFc1, va0c1);
288 const int16x8_t vprod1xCDEFc1 = vmull_s8(vbCDEFc1, va1c1);
289 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc1);
290 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc1);
291 const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
292 const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2));
293
294 const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
295 const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
296 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
297 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
298 const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
299 const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
300 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
301 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
302 const int16x8_t vprod0x89ABc2 = vmull_s8(vb89ABc2, va0c2);
303 const int16x8_t vprod1x89ABc2 = vmull_s8(vb89ABc2, va1c2);
304 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc2);
305 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc2);
306 const int16x8_t vprod0xCDEFc2 = vmull_s8(vbCDEFc2, va0c2);
307 const int16x8_t vprod1xCDEFc2 = vmull_s8(vbCDEFc2, va1c2);
308 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc2);
309 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc2);
310 const int8x8_t va0c3 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 3));
311 const int8x8_t va1c3 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 3));
312
313 const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3);
314 const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, va1c3);
315 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
316 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
317 const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3);
318 const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, va1c3);
319 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
320 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
321 const int16x8_t vprod0x89ABc3 = vmull_s8(vb89ABc3, va0c3);
322 const int16x8_t vprod1x89ABc3 = vmull_s8(vb89ABc3, va1c3);
323 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc3);
324 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc3);
325 const int16x8_t vprod0xCDEFc3 = vmull_s8(vbCDEFc3, va0c3);
326 const int16x8_t vprod1xCDEFc3 = vmull_s8(vbCDEFc3, va1c3);
327 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc3);
328 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc3);
329
330 k -= 8 * sizeof(int8_t);
331 }
332
333 if XNN_UNLIKELY(k != 0) {
334 const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
335 const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
336
337 const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
338 const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
339 const int8x8_t vb89ABc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
340 const int8x8_t vbCDEFc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
341
342 const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
343 const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
344 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
345 const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
346 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
347 const int16x8_t vprod0x89ABc0 = vmull_s8(vb89ABc0, va0c0);
348 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc0);
349 const int16x8_t vprod0xCDEFc0 = vmull_s8(vbCDEFc0, va0c0);
350 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc0);
351 const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0));
352 const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
353 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
354 const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
355 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
356 const int16x8_t vprod1x89ABc0 = vmull_s8(vb89ABc0, va1c0);
357 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc0);
358 const int16x8_t vprod1xCDEFc0 = vmull_s8(vbCDEFc0, va1c0);
359 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc0);
360
361 if (k > 2 * sizeof(int8_t)) {
362 const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
363 const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
364 const int8x8_t vb89ABc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
365 const int8x8_t vbCDEFc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
366
367 const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
368 const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
369 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
370 const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
371 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
372 const int16x8_t vprod0x89ABc1 = vmull_s8(vb89ABc1, va0c1);
373 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc1);
374 const int16x8_t vprod0xCDEFc1 = vmull_s8(vbCDEFc1, va0c1);
375 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc1);
376 const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1));
377 const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
378 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
379 const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
380 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
381 const int16x8_t vprod1x89ABc1 = vmull_s8(vb89ABc1, va1c1);
382 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc1);
383 const int16x8_t vprod1xCDEFc1 = vmull_s8(vbCDEFc1, va1c1);
384 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc1);
385
386 if (k > 4 * sizeof(int8_t)) {
387 const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
388 const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
389 const int8x8_t vb89ABc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
390 const int8x8_t vbCDEFc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
391
392 const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
393 const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
394 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
395 const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
396 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
397 const int16x8_t vprod0x89ABc2 = vmull_s8(vb89ABc2, va0c2);
398 vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc2);
399 const int16x8_t vprod0xCDEFc2 = vmull_s8(vbCDEFc2, va0c2);
400 vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc2);
401 const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2));
402 const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
403 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
404 const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
405 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
406 const int16x8_t vprod1x89ABc2 = vmull_s8(vb89ABc2, va1c2);
407 vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc2);
408 const int16x8_t vprod1xCDEFc2 = vmull_s8(vbCDEFc2, va1c2);
409 vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc2);
410 }
411 }
412 }
413 p -= 2 * sizeof(void*);
414 } while (p != 0);
415
416 const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift);
417 const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier);
418 const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift);
419
420 vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
421 vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
422 vacc0x89AB = vqshlq_s32(vacc0x89AB, vright_pre_shift);
423 vacc0xCDEF = vqshlq_s32(vacc0xCDEF, vright_pre_shift);
424 vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
425 vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
426 vacc1x89AB = vqshlq_s32(vacc1x89AB, vright_pre_shift);
427 vacc1xCDEF = vqshlq_s32(vacc1xCDEF, vright_pre_shift);
428
429 vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
430 vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
431 vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier);
432 vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier);
433 vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
434 vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
435 vacc1x89AB = vqdmulhq_s32(vacc1x89AB, vmultiplier);
436 vacc1xCDEF = vqdmulhq_s32(vacc1xCDEF, vmultiplier);
437
438 vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
439 vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
440 vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift);
441 vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift);
442 vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
443 vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
444 vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_post_shift);
445 vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_post_shift);
446
447 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point);
448 #if XNN_ARCH_ARM64
449 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
450 int16x8_t vacc0x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF);
451 int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
452 int16x8_t vacc1x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF);
453
454 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
455 vacc0x89ABCDEF = vqaddq_s16(vacc0x89ABCDEF, voutput_zero_point);
456 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
457 vacc1x89ABCDEF = vqaddq_s16(vacc1x89ABCDEF, voutput_zero_point);
458
459 int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF);
460 int8x16_t vout1x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc1x01234567), vacc1x89ABCDEF);
461 #else
462 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
463 int16x8_t vacc0x89ABCDEF = vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF));
464 int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
465 int16x8_t vacc1x89ABCDEF = vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF));
466
467 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
468 vacc0x89ABCDEF = vqaddq_s16(vacc0x89ABCDEF, voutput_zero_point);
469 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
470 vacc1x89ABCDEF = vqaddq_s16(vacc1x89ABCDEF, voutput_zero_point);
471
472 int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF));
473 int8x16_t vout1x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc1x01234567), vqmovn_s16(vacc1x89ABCDEF));
474 #endif
475
476 const int8x16_t voutput_min = vld1q_dup_s8(¶ms->rndnu_neon.output_min);
477 vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min);
478 vout1x0123456789ABCDEF = vmaxq_s8(vout1x0123456789ABCDEF, voutput_min);
479
480 const int8x16_t voutput_max = vld1q_dup_s8(¶ms->rndnu_neon.output_max);
481 vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max);
482 vout1x0123456789ABCDEF = vminq_s8(vout1x0123456789ABCDEF, voutput_max);
483
484 if (nc >= 16) {
485 vst1q_s8(c1 + 0, vout1x0123456789ABCDEF);
486 vst1q_s8(c0 + 0, vout0x0123456789ABCDEF);
487
488 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
489 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
490
491 a = (const int8_t**restrict) ((uintptr_t) a - ks);
492
493 nc -= 16;
494 } else {
495 int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vget_low_s8(vout0x0123456789ABCDEF), vget_low_s8(vout1x0123456789ABCDEF));
496 if (nc & 8) {
497 vst1_s8(c1, vget_high_s8(vout0x01234567_1x01234567)); c1 += 8;
498 vst1_s8(c0, vget_low_s8(vout0x01234567_1x01234567)); c0 += 8;
499 vout0x01234567_1x01234567 = vcombine_s8(vget_high_s8(vout0x0123456789ABCDEF), vget_high_s8(vout1x0123456789ABCDEF));
500 }
501 if (nc & 4) {
502 vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
503 vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
504 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
505 }
506 if (nc & 2) {
507 vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
508 vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
509 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
510 }
511 if (nc & 1) {
512 vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
513 vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
514 }
515
516 nc = 0;
517 }
518 } while (nc != 0);
519 }
520