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