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