1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/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_gemm_minmax_rndnu_ukernel_3x8c2__neon_mlal_ld2r(size_t mr,size_t nc,size_t kc,const int8_t * restrict a,size_t a_stride,const void * restrict w,int8_t * restrict c,size_t cm_stride,size_t cn_stride,const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_qs8_gemm_minmax_rndnu_ukernel_3x8c2__neon_mlal_ld2r(
18 size_t mr,
19 size_t nc,
20 size_t kc,
21 const int8_t* restrict a,
22 size_t a_stride,
23 const void* restrict w,
24 int8_t* restrict c,
25 size_t cm_stride,
26 size_t cn_stride,
27 const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
28 {
29 assert(mr != 0);
30 assert(mr <= 3);
31 assert(nc != 0);
32 assert(kc != 0);
33 assert(kc % sizeof(int8_t) == 0);
34 assert(a != NULL);
35 assert(w != NULL);
36 assert(c != NULL);
37
38 kc = round_up_po2(kc, 2 * sizeof(int8_t));
39 const int8_t* a0 = a;
40 int8_t* c0 = c;
41 const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
42 int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
43 if XNN_UNPREDICTABLE(mr < 2) {
44 a1 = a0;
45 c1 = c0;
46 }
47 const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride);
48 int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
49 if XNN_UNPREDICTABLE(mr <= 2) {
50 a2 = a1;
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 k = kc;
63
64 while (k >= 16 * sizeof(int8_t)) {
65 const int16x4x2_t va00x0 = vld2_dup_s16((const void*)a0);
66 const int16x4x2_t va01x0 = vld2_dup_s16((const void*)(a0 + 4)); a0 += 8;
67 const int16x4x2_t va00x1 = vld2_dup_s16((const void*)a0);
68 const int16x4x2_t va01x1 = vld2_dup_s16((const void*)(a0 + 4)); a0 += 8;
69 const int16x4x2_t va10x0 = vld2_dup_s16((const void*)a1);
70 const int16x4x2_t va11x0 = vld2_dup_s16((const void*)(a1 + 4)); a1 += 8;
71 const int16x4x2_t va10x1 = vld2_dup_s16((const void*)a1);
72 const int16x4x2_t va11x1 = vld2_dup_s16((const void*)(a1 + 4)); a1 += 8;
73 const int16x4x2_t va20x0 = vld2_dup_s16((const void*)a2);
74 const int16x4x2_t va21x0 = vld2_dup_s16((const void*)(a2 + 4)); a2 += 8;
75 const int16x4x2_t va20x1 = vld2_dup_s16((const void*)a2);
76 const int16x4x2_t va21x1 = vld2_dup_s16((const void*)(a2 + 4)); a2 += 8;
77 const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
78 const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
79 const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
80 const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
81 const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
82 const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
83 const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
84 const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
85
86 const int8x8_t va0c0x0 = vreinterpret_s8_s16(va00x0.val[0]);
87 const int8x8_t va0c0x1 = vreinterpret_s8_s16(va00x1.val[0]);
88 const int8x8_t va1c0x0 = vreinterpret_s8_s16(va10x0.val[0]);
89 const int8x8_t va1c0x1 = vreinterpret_s8_s16(va10x1.val[0]);
90 const int8x8_t va2c0x0 = vreinterpret_s8_s16(va20x0.val[0]);
91 const int8x8_t va2c0x1 = vreinterpret_s8_s16(va20x1.val[0]);
92
93 int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0c0x0);
94 int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1c0x0);
95 int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0x0, va2c0x0);
96 const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
97 vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0c0x1);
98 vprod1x0123c0 = vmlal_s8(vprod1x0123c0, vb0123c0x1, va1c0x1);
99 vprod2x0123c0 = vmlal_s8(vprod2x0123c0, vb0123c0x1, va2c0x1);
100 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
101 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
102 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
103 int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0c0x0);
104 int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1c0x0);
105 int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0x0, va2c0x0);
106 const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
107 vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0c0x1);
108 vprod1x4567c0 = vmlal_s8(vprod1x4567c0, vb4567c0x1, va1c0x1);
109 vprod2x4567c0 = vmlal_s8(vprod2x4567c0, vb4567c0x1, va2c0x1);
110 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
111 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
112 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
113 const int8x8_t va0c1x0 = vreinterpret_s8_s16(va00x0.val[1]);
114 const int8x8_t va0c1x1 = vreinterpret_s8_s16(va00x1.val[1]);
115 const int8x8_t va1c1x0 = vreinterpret_s8_s16(va10x0.val[1]);
116 const int8x8_t va1c1x1 = vreinterpret_s8_s16(va10x1.val[1]);
117 const int8x8_t va2c1x0 = vreinterpret_s8_s16(va20x0.val[1]);
118 const int8x8_t va2c1x1 = vreinterpret_s8_s16(va20x1.val[1]);
119
120 int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0c1x0);
121 int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1c1x0);
122 int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1x0, va2c1x0);
123 const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
124 vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0c1x1);
125 vprod1x0123c1 = vmlal_s8(vprod1x0123c1, vb0123c1x1, va1c1x1);
126 vprod2x0123c1 = vmlal_s8(vprod2x0123c1, vb0123c1x1, va2c1x1);
127 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
128 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
129 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
130 int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0c1x0);
131 int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1c1x0);
132 int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1x0, va2c1x0);
133 const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
134 vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0c1x1);
135 vprod1x4567c1 = vmlal_s8(vprod1x4567c1, vb4567c1x1, va1c1x1);
136 vprod2x4567c1 = vmlal_s8(vprod2x4567c1, vb4567c1x1, va2c1x1);
137 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
138 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
139 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
140 const int8x8_t va0c2x0 = vreinterpret_s8_s16(va01x0.val[0]);
141 const int8x8_t va0c2x1 = vreinterpret_s8_s16(va01x1.val[0]);
142 const int8x8_t va1c2x0 = vreinterpret_s8_s16(va11x0.val[0]);
143 const int8x8_t va1c2x1 = vreinterpret_s8_s16(va11x1.val[0]);
144 const int8x8_t va2c2x0 = vreinterpret_s8_s16(va21x0.val[0]);
145 const int8x8_t va2c2x1 = vreinterpret_s8_s16(va21x1.val[0]);
146
147 int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0c2x0);
148 int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1c2x0);
149 int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2x0, va2c2x0);
150 const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
151 vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0c2x1);
152 vprod1x0123c2 = vmlal_s8(vprod1x0123c2, vb0123c2x1, va1c2x1);
153 vprod2x0123c2 = vmlal_s8(vprod2x0123c2, vb0123c2x1, va2c2x1);
154 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
155 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
156 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
157 int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0c2x0);
158 int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1c2x0);
159 int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2x0, va2c2x0);
160 const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
161 vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0c2x1);
162 vprod1x4567c2 = vmlal_s8(vprod1x4567c2, vb4567c2x1, va1c2x1);
163 vprod2x4567c2 = vmlal_s8(vprod2x4567c2, vb4567c2x1, va2c2x1);
164 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
165 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
166 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
167 const int8x8_t va0c3x0 = vreinterpret_s8_s16(va01x0.val[1]);
168 const int8x8_t va0c3x1 = vreinterpret_s8_s16(va01x1.val[1]);
169 const int8x8_t va1c3x0 = vreinterpret_s8_s16(va11x0.val[1]);
170 const int8x8_t va1c3x1 = vreinterpret_s8_s16(va11x1.val[1]);
171 const int8x8_t va2c3x0 = vreinterpret_s8_s16(va21x0.val[1]);
172 const int8x8_t va2c3x1 = vreinterpret_s8_s16(va21x1.val[1]);
173
174 int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0c3x0);
175 int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1c3x0);
176 int16x8_t vprod2x0123c3 = vmull_s8(vb0123c3x0, va2c3x0);
177 const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
178 vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0c3x1);
179 vprod1x0123c3 = vmlal_s8(vprod1x0123c3, vb0123c3x1, va1c3x1);
180 vprod2x0123c3 = vmlal_s8(vprod2x0123c3, vb0123c3x1, va2c3x1);
181 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
182 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
183 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c3);
184 int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0c3x0);
185 int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1c3x0);
186 int16x8_t vprod2x4567c3 = vmull_s8(vb4567c3x0, va2c3x0);
187 const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
188 vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0c3x1);
189 vprod1x4567c3 = vmlal_s8(vprod1x4567c3, vb4567c3x1, va1c3x1);
190 vprod2x4567c3 = vmlal_s8(vprod2x4567c3, vb4567c3x1, va2c3x1);
191 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
192 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
193 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c3);
194
195 k -= 16 * sizeof(int8_t);
196 }
197
198 if (k >= 8 * sizeof(int8_t)) {
199 const int16x4x2_t va00 = vld2_dup_s16((const void*)a0);
200 const int16x4x2_t va01 = vld2_dup_s16((const void*)(a0 + 4)); a0 += 8;
201 const int16x4x2_t va10 = vld2_dup_s16((const void*)a1);
202 const int16x4x2_t va11 = vld2_dup_s16((const void*)(a1 + 4)); a1 += 8;
203 const int16x4x2_t va20 = vld2_dup_s16((const void*)a2);
204 const int16x4x2_t va21 = vld2_dup_s16((const void*)(a2 + 4)); a2 += 8;
205
206 const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
207 const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
208 const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
209 const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
210 const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
211 const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
212 const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
213 const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
214
215 const int8x8_t va0c0 = vreinterpret_s8_s16(va00.val[0]);
216 const int8x8_t va1c0 = vreinterpret_s8_s16(va10.val[0]);
217 const int8x8_t va2c0 = vreinterpret_s8_s16(va20.val[0]);
218
219 const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
220 const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
221 const int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0, va2c0);
222 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
223 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
224 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
225 const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
226 const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
227 const int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0, va2c0);
228 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
229 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
230 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
231 const int8x8_t va0c1 = vreinterpret_s8_s16(va00.val[1]);
232 const int8x8_t va1c1 = vreinterpret_s8_s16(va10.val[1]);
233 const int8x8_t va2c1 = vreinterpret_s8_s16(va20.val[1]);
234
235 const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
236 const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
237 const int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1, va2c1);
238 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
239 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
240 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
241 const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
242 const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
243 const int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1, va2c1);
244 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
245 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
246 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
247 const int8x8_t va0c2 = vreinterpret_s8_s16(va01.val[0]);
248 const int8x8_t va1c2 = vreinterpret_s8_s16(va11.val[0]);
249 const int8x8_t va2c2 = vreinterpret_s8_s16(va21.val[0]);
250
251 const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
252 const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
253 const int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2, va2c2);
254 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
255 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
256 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
257 const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
258 const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
259 const int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2, va2c2);
260 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
261 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
262 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
263 const int8x8_t va0c3 = vreinterpret_s8_s16(va01.val[1]);
264 const int8x8_t va1c3 = vreinterpret_s8_s16(va11.val[1]);
265 const int8x8_t va2c3 = vreinterpret_s8_s16(va21.val[1]);
266
267 const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3);
268 const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, va1c3);
269 const int16x8_t vprod2x0123c3 = vmull_s8(vb0123c3, va2c3);
270 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
271 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
272 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c3);
273 const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3);
274 const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, va1c3);
275 const int16x8_t vprod2x4567c3 = vmull_s8(vb4567c3, va2c3);
276 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
277 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
278 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c3);
279
280 k -= 8 * sizeof(int8_t);
281 }
282
283 if XNN_UNLIKELY(k != 0) {
284 const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
285 const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
286 const int8x8_t va2 = vld1_s8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k);
287
288 const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
289 const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
290
291 const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
292 const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
293 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
294 const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
295 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
296 const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0));
297 const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
298 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
299 const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
300 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
301 const int8x8_t va2c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 0));
302 const int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0, va2c0);
303 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
304 const int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0, va2c0);
305 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
306
307 if (k > 2 * sizeof(int8_t)) {
308 const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
309 const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
310
311 const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
312 const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
313 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
314 const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
315 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
316 const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1));
317 const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
318 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
319 const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
320 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
321 const int8x8_t va2c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 1));
322 const int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1, va2c1);
323 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
324 const int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1, va2c1);
325 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
326
327 if (k > 4 * sizeof(int8_t)) {
328 const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
329 const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
330
331 const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
332 const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
333 vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
334 const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
335 vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
336 const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2));
337 const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
338 vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
339 const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
340 vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
341 const int8x8_t va2c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 2));
342 const int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2, va2c2);
343 vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
344 const int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2, va2c2);
345 vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
346 }
347 }
348 }
349
350 const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift);
351 const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier);
352 const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift);
353
354 vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
355 vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
356 vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
357 vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
358 vacc2x0123 = vqshlq_s32(vacc2x0123, vright_pre_shift);
359 vacc2x4567 = vqshlq_s32(vacc2x4567, vright_pre_shift);
360
361 vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
362 vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
363 vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
364 vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
365 vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier);
366 vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier);
367
368 vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
369 vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
370 vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
371 vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
372 vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift);
373 vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift);
374
375 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point);
376 #if XNN_ARCH_ARM64
377 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
378 int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
379 int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567);
380
381 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
382 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
383 vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
384
385 int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567);
386 int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567);
387 #else
388 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
389 int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
390 int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567));
391
392 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
393 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
394 vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
395
396 int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567));
397 int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567);
398 #endif
399
400 const int8x16_t voutput_min = vld1q_dup_s8(¶ms->rndnu_neon.output_min);
401 vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min);
402 vout2x01234567 = vmax_s8(vout2x01234567, vget_low_s8(voutput_min));
403
404 const int8x16_t voutput_max = vld1q_dup_s8(¶ms->rndnu_neon.output_max);
405 vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max);
406 vout2x01234567 = vmin_s8(vout2x01234567, vget_low_s8(voutput_max));
407
408 if (nc >= 8) {
409 vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567));
410 vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567));
411 vst1_s8(c2 + 0, vout2x01234567);
412
413 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
414 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
415 c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
416
417 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
418 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
419 a2 = (const int8_t*) ((uintptr_t) a2 - kc);
420
421 nc -= 8;
422 } else {
423 // Final case where not all of the 8 columns fit in the destination.
424 if (nc & 4) {
425 vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
426 vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
427 vst1_lane_u32((void*) c2, vreinterpret_u32_s8(vout2x01234567), 0); c2 += 4;
428 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
429 vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 4);
430 }
431 if (nc & 2) {
432 vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
433 vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
434 vst1_lane_u16((void*) c2, vreinterpret_u16_s8(vout2x01234567), 0); c2 += 2;
435 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
436 vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 2);
437 }
438 if (nc & 1) {
439 vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
440 vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
441 vst1_lane_s8(c2, vout2x01234567, 0);
442 }
443
444 nc = 0;
445 }
446 } while (nc != 0);
447 }
448