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