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