1 // Auto-generated file. Do not edit!
2 // Template: src/bf16-gemm/c8-neon.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2022 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
11 #include <assert.h>
12
13 #include <arm_neon.h>
14
15 #include <xnnpack/gemm.h>
16
17
xnn_bf16_gemm_minmax_ukernel_5x4c8__neonfma_shland(size_t mr,size_t nc,size_t kc,const void * restrict a,size_t a_stride,const void * restrict w_ptr,void * restrict c,size_t cm_stride,size_t cn_stride,const union xnn_bf16_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_bf16_gemm_minmax_ukernel_5x4c8__neonfma_shland(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 const void* restrict a,
23 size_t a_stride,
24 const void* restrict w_ptr,
25 void* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 const union xnn_bf16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30 assert(mr != 0);
31 assert(mr <= 5);
32 assert(nc != 0);
33 assert(kc != 0);
34 assert(kc % sizeof(uint16_t) == 0);
35 assert(a != NULL);
36 assert(w_ptr != NULL);
37 assert(c != NULL);
38
39 const uint16_t* a0 = (const uint16_t*) a;
40 uint16_t* c0 = (uint16_t*) c;
41 const uint16_t* a1 = (const uint16_t*) ((uintptr_t) a0 + a_stride);
42 uint16_t* c1 = (uint16_t*) ((uintptr_t) c0 + cm_stride);
43 if XNN_UNPREDICTABLE(mr < 2) {
44 a1 = a0;
45 c1 = c0;
46 }
47 const uint16_t* a2 = (const uint16_t*) ((uintptr_t) a1 + a_stride);
48 uint16_t* c2 = (uint16_t*) ((uintptr_t) c1 + cm_stride);
49 if XNN_UNPREDICTABLE(mr <= 2) {
50 a2 = a1;
51 c2 = c1;
52 }
53 const uint16_t* a3 = (const uint16_t*) ((uintptr_t) a2 + a_stride);
54 uint16_t* c3 = (uint16_t*) ((uintptr_t) c2 + cm_stride);
55 if XNN_UNPREDICTABLE(mr < 4) {
56 a3 = a2;
57 c3 = c2;
58 }
59 const uint16_t* a4 = (const uint16_t*) ((uintptr_t) a3 + a_stride);
60 uint16_t* c4 = (uint16_t*) ((uintptr_t) c3 + cm_stride);
61 if XNN_UNPREDICTABLE(mr <= 4) {
62 a4 = a3;
63 c4 = c3;
64 }
65
66 const uint16_t* w = (const uint16_t*) w_ptr;
67 const uint16x8_t vmask = vreinterpretq_u16_u32(vmovq_n_u32(UINT32_C(0xFFFF0000)));
68 do {
69 float32x4_t vacc0x0 = vreinterpretq_f32_u32(vshll_n_u16(vld1_lane_u16(w, vdup_n_u16(0), 0), 16)); w += 1;
70 float32x4_t vacc0x1 = vreinterpretq_f32_u32(vshll_n_u16(vld1_lane_u16(w, vdup_n_u16(0), 0), 16)); w += 1;
71 float32x4_t vacc0x2 = vreinterpretq_f32_u32(vshll_n_u16(vld1_lane_u16(w, vdup_n_u16(0), 0), 16)); w += 1;
72 float32x4_t vacc0x3 = vreinterpretq_f32_u32(vshll_n_u16(vld1_lane_u16(w, vdup_n_u16(0), 0), 16)); w += 1;
73 float32x4_t vacc1x0 = vacc0x0;
74 float32x4_t vacc1x1 = vacc0x1;
75 float32x4_t vacc1x2 = vacc0x2;
76 float32x4_t vacc1x3 = vacc0x3;
77 float32x4_t vacc2x0 = vacc0x0;
78 float32x4_t vacc2x1 = vacc0x1;
79 float32x4_t vacc2x2 = vacc0x2;
80 float32x4_t vacc2x3 = vacc0x3;
81 float32x4_t vacc3x0 = vacc0x0;
82 float32x4_t vacc3x1 = vacc0x1;
83 float32x4_t vacc3x2 = vacc0x2;
84 float32x4_t vacc3x3 = vacc0x3;
85 float32x4_t vacc4x0 = vacc0x0;
86 float32x4_t vacc4x1 = vacc0x1;
87 float32x4_t vacc4x2 = vacc0x2;
88 float32x4_t vacc4x3 = vacc0x3;
89
90 size_t k = kc;
91 for (; k >= 8 * sizeof(uint16_t); k -= 8 * sizeof(uint16_t)) {
92 const uint16x8_t va0 = vld1q_u16(a0); a0 += 8;
93 const uint16x8_t va1 = vld1q_u16(a1); a1 += 8;
94 const uint16x8_t va2 = vld1q_u16(a2); a2 += 8;
95 const uint16x8_t va3 = vld1q_u16(a3); a3 += 8;
96 const uint16x8_t va4 = vld1q_u16(a4); a4 += 8;
97
98 const uint16x8_t vb0 = vld1q_u16(w); w += 8;
99 const uint16x8_t vb1 = vld1q_u16(w); w += 8;
100 const uint16x8_t vb2 = vld1q_u16(w); w += 8;
101 const uint16x8_t vb3 = vld1q_u16(w); w += 8;
102
103 const float32x4_t va0e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va0), 16));
104 const float32x4_t va1e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va1), 16));
105 const float32x4_t va2e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va2), 16));
106 const float32x4_t va3e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va3), 16));
107 const float32x4_t va4e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va4), 16));
108
109 const float32x4_t vb0e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(vb0), 16));
110 const float32x4_t vb1e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(vb1), 16));
111 const float32x4_t vb2e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(vb2), 16));
112 const float32x4_t vb3e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(vb3), 16));
113
114 vacc0x0 = vfmaq_f32(vacc0x0, va0e, vb0e);
115 vacc1x0 = vfmaq_f32(vacc1x0, va1e, vb0e);
116 vacc2x0 = vfmaq_f32(vacc2x0, va2e, vb0e);
117 vacc3x0 = vfmaq_f32(vacc3x0, va3e, vb0e);
118 vacc4x0 = vfmaq_f32(vacc4x0, va4e, vb0e);
119 vacc0x1 = vfmaq_f32(vacc0x1, va0e, vb1e);
120 vacc1x1 = vfmaq_f32(vacc1x1, va1e, vb1e);
121 vacc2x1 = vfmaq_f32(vacc2x1, va2e, vb1e);
122 vacc3x1 = vfmaq_f32(vacc3x1, va3e, vb1e);
123 vacc4x1 = vfmaq_f32(vacc4x1, va4e, vb1e);
124 vacc0x2 = vfmaq_f32(vacc0x2, va0e, vb2e);
125 vacc1x2 = vfmaq_f32(vacc1x2, va1e, vb2e);
126 vacc2x2 = vfmaq_f32(vacc2x2, va2e, vb2e);
127 vacc3x2 = vfmaq_f32(vacc3x2, va3e, vb2e);
128 vacc4x2 = vfmaq_f32(vacc4x2, va4e, vb2e);
129 vacc0x3 = vfmaq_f32(vacc0x3, va0e, vb3e);
130 vacc1x3 = vfmaq_f32(vacc1x3, va1e, vb3e);
131 vacc2x3 = vfmaq_f32(vacc2x3, va2e, vb3e);
132 vacc3x3 = vfmaq_f32(vacc3x3, va3e, vb3e);
133 vacc4x3 = vfmaq_f32(vacc4x3, va4e, vb3e);
134
135 const float32x4_t va0o = vreinterpretq_f32_u16(vandq_u16(va0, vmask));
136 const float32x4_t va1o = vreinterpretq_f32_u16(vandq_u16(va1, vmask));
137 const float32x4_t va2o = vreinterpretq_f32_u16(vandq_u16(va2, vmask));
138 const float32x4_t va3o = vreinterpretq_f32_u16(vandq_u16(va3, vmask));
139 const float32x4_t va4o = vreinterpretq_f32_u16(vandq_u16(va4, vmask));
140
141 const float32x4_t vb0o = vreinterpretq_f32_u16(vandq_u16(vb0, vmask));
142 const float32x4_t vb1o = vreinterpretq_f32_u16(vandq_u16(vb1, vmask));
143 const float32x4_t vb2o = vreinterpretq_f32_u16(vandq_u16(vb2, vmask));
144 const float32x4_t vb3o = vreinterpretq_f32_u16(vandq_u16(vb3, vmask));
145
146 vacc0x0 = vfmaq_f32(vacc0x0, va0o, vb0o);
147 vacc1x0 = vfmaq_f32(vacc1x0, va1o, vb0o);
148 vacc2x0 = vfmaq_f32(vacc2x0, va2o, vb0o);
149 vacc3x0 = vfmaq_f32(vacc3x0, va3o, vb0o);
150 vacc4x0 = vfmaq_f32(vacc4x0, va4o, vb0o);
151 vacc0x1 = vfmaq_f32(vacc0x1, va0o, vb1o);
152 vacc1x1 = vfmaq_f32(vacc1x1, va1o, vb1o);
153 vacc2x1 = vfmaq_f32(vacc2x1, va2o, vb1o);
154 vacc3x1 = vfmaq_f32(vacc3x1, va3o, vb1o);
155 vacc4x1 = vfmaq_f32(vacc4x1, va4o, vb1o);
156 vacc0x2 = vfmaq_f32(vacc0x2, va0o, vb2o);
157 vacc1x2 = vfmaq_f32(vacc1x2, va1o, vb2o);
158 vacc2x2 = vfmaq_f32(vacc2x2, va2o, vb2o);
159 vacc3x2 = vfmaq_f32(vacc3x2, va3o, vb2o);
160 vacc4x2 = vfmaq_f32(vacc4x2, va4o, vb2o);
161 vacc0x3 = vfmaq_f32(vacc0x3, va0o, vb3o);
162 vacc1x3 = vfmaq_f32(vacc1x3, va1o, vb3o);
163 vacc2x3 = vfmaq_f32(vacc2x3, va2o, vb3o);
164 vacc3x3 = vfmaq_f32(vacc3x3, va3o, vb3o);
165 vacc4x3 = vfmaq_f32(vacc4x3, va4o, vb3o);
166 }
167 if XNN_UNLIKELY(k != 0) {
168 const uint16x8_t va0 = vld1q_u16(a0); a0 = (const uint16_t*) ((uintptr_t) a0 + k);
169 const uint16x8_t va1 = vld1q_u16(a1); a1 = (const uint16_t*) ((uintptr_t) a1 + k);
170 const uint16x8_t va2 = vld1q_u16(a2); a2 = (const uint16_t*) ((uintptr_t) a2 + k);
171 const uint16x8_t va3 = vld1q_u16(a3); a3 = (const uint16_t*) ((uintptr_t) a3 + k);
172 const uint16x8_t va4 = vld1q_u16(a4); a4 = (const uint16_t*) ((uintptr_t) a4 + k);
173
174 const uint16x8_t vb0 = vld1q_u16(w); w += 8;
175 const uint16x8_t vb1 = vld1q_u16(w); w += 8;
176 const uint16x8_t vb2 = vld1q_u16(w); w += 8;
177 const uint16x8_t vb3 = vld1q_u16(w); w += 8;
178
179 const uint16x8_t vm0 = vceqq_u16(vb0, vmovq_n_u16(0));
180 const uint16x8_t vm1 = vceqq_u16(vb1, vmovq_n_u16(0));
181 const uint16x8_t vm2 = vceqq_u16(vb2, vmovq_n_u16(0));
182 const uint16x8_t vm3 = vceqq_u16(vb3, vmovq_n_u16(0));
183
184 const float32x4_t vb0e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(vb0), 16));
185 const float32x4_t vb1e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(vb1), 16));
186 const float32x4_t vb2e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(vb2), 16));
187 const float32x4_t vb3e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(vb3), 16));
188
189 const uint16x8_t va0x0 = vbicq_u16(va0, vm0);
190 const uint16x8_t va1x0 = vbicq_u16(va1, vm0);
191 const uint16x8_t va2x0 = vbicq_u16(va2, vm0);
192 const uint16x8_t va3x0 = vbicq_u16(va3, vm0);
193 const uint16x8_t va4x0 = vbicq_u16(va4, vm0);
194 const uint16x8_t va0x1 = vbicq_u16(va0, vm1);
195 const uint16x8_t va1x1 = vbicq_u16(va1, vm1);
196 const uint16x8_t va2x1 = vbicq_u16(va2, vm1);
197 const uint16x8_t va3x1 = vbicq_u16(va3, vm1);
198 const uint16x8_t va4x1 = vbicq_u16(va4, vm1);
199 const uint16x8_t va0x2 = vbicq_u16(va0, vm2);
200 const uint16x8_t va1x2 = vbicq_u16(va1, vm2);
201 const uint16x8_t va2x2 = vbicq_u16(va2, vm2);
202 const uint16x8_t va3x2 = vbicq_u16(va3, vm2);
203 const uint16x8_t va4x2 = vbicq_u16(va4, vm2);
204 const uint16x8_t va0x3 = vbicq_u16(va0, vm3);
205 const uint16x8_t va1x3 = vbicq_u16(va1, vm3);
206 const uint16x8_t va2x3 = vbicq_u16(va2, vm3);
207 const uint16x8_t va3x3 = vbicq_u16(va3, vm3);
208 const uint16x8_t va4x3 = vbicq_u16(va4, vm3);
209
210 const float32x4_t va0x0e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va0x0), 16));
211 const float32x4_t va1x0e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va1x0), 16));
212 const float32x4_t va2x0e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va2x0), 16));
213 const float32x4_t va3x0e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va3x0), 16));
214 const float32x4_t va4x0e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va4x0), 16));
215 const float32x4_t va0x1e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va0x1), 16));
216 const float32x4_t va1x1e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va1x1), 16));
217 const float32x4_t va2x1e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va2x1), 16));
218 const float32x4_t va3x1e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va3x1), 16));
219 const float32x4_t va4x1e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va4x1), 16));
220 const float32x4_t va0x2e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va0x2), 16));
221 const float32x4_t va1x2e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va1x2), 16));
222 const float32x4_t va2x2e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va2x2), 16));
223 const float32x4_t va3x2e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va3x2), 16));
224 const float32x4_t va4x2e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va4x2), 16));
225 const float32x4_t va0x3e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va0x3), 16));
226 const float32x4_t va1x3e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va1x3), 16));
227 const float32x4_t va2x3e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va2x3), 16));
228 const float32x4_t va3x3e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va3x3), 16));
229 const float32x4_t va4x3e = vreinterpretq_f32_u32(vshlq_n_u32(vreinterpretq_u32_u16(va4x3), 16));
230
231 vacc0x0 = vfmaq_f32(vacc0x0, va0x0e, vb0e);
232 vacc1x0 = vfmaq_f32(vacc1x0, va1x0e, vb0e);
233 vacc2x0 = vfmaq_f32(vacc2x0, va2x0e, vb0e);
234 vacc3x0 = vfmaq_f32(vacc3x0, va3x0e, vb0e);
235 vacc4x0 = vfmaq_f32(vacc4x0, va4x0e, vb0e);
236 vacc0x1 = vfmaq_f32(vacc0x1, va0x1e, vb1e);
237 vacc1x1 = vfmaq_f32(vacc1x1, va1x1e, vb1e);
238 vacc2x1 = vfmaq_f32(vacc2x1, va2x1e, vb1e);
239 vacc3x1 = vfmaq_f32(vacc3x1, va3x1e, vb1e);
240 vacc4x1 = vfmaq_f32(vacc4x1, va4x1e, vb1e);
241 vacc0x2 = vfmaq_f32(vacc0x2, va0x2e, vb2e);
242 vacc1x2 = vfmaq_f32(vacc1x2, va1x2e, vb2e);
243 vacc2x2 = vfmaq_f32(vacc2x2, va2x2e, vb2e);
244 vacc3x2 = vfmaq_f32(vacc3x2, va3x2e, vb2e);
245 vacc4x2 = vfmaq_f32(vacc4x2, va4x2e, vb2e);
246 vacc0x3 = vfmaq_f32(vacc0x3, va0x3e, vb3e);
247 vacc1x3 = vfmaq_f32(vacc1x3, va1x3e, vb3e);
248 vacc2x3 = vfmaq_f32(vacc2x3, va2x3e, vb3e);
249 vacc3x3 = vfmaq_f32(vacc3x3, va3x3e, vb3e);
250 vacc4x3 = vfmaq_f32(vacc4x3, va4x3e, vb3e);
251
252 const float32x4_t vb0o = vreinterpretq_f32_u16(vandq_u16(vb0, vmask));
253 const float32x4_t vb1o = vreinterpretq_f32_u16(vandq_u16(vb1, vmask));
254 const float32x4_t vb2o = vreinterpretq_f32_u16(vandq_u16(vb2, vmask));
255 const float32x4_t vb3o = vreinterpretq_f32_u16(vandq_u16(vb3, vmask));
256
257 const float32x4_t va0x0o = vreinterpretq_f32_u16(vandq_u16(va0x0, vmask));
258 const float32x4_t va1x0o = vreinterpretq_f32_u16(vandq_u16(va1x0, vmask));
259 const float32x4_t va2x0o = vreinterpretq_f32_u16(vandq_u16(va2x0, vmask));
260 const float32x4_t va3x0o = vreinterpretq_f32_u16(vandq_u16(va3x0, vmask));
261 const float32x4_t va4x0o = vreinterpretq_f32_u16(vandq_u16(va4x0, vmask));
262 const float32x4_t va0x1o = vreinterpretq_f32_u16(vandq_u16(va0x1, vmask));
263 const float32x4_t va1x1o = vreinterpretq_f32_u16(vandq_u16(va1x1, vmask));
264 const float32x4_t va2x1o = vreinterpretq_f32_u16(vandq_u16(va2x1, vmask));
265 const float32x4_t va3x1o = vreinterpretq_f32_u16(vandq_u16(va3x1, vmask));
266 const float32x4_t va4x1o = vreinterpretq_f32_u16(vandq_u16(va4x1, vmask));
267 const float32x4_t va0x2o = vreinterpretq_f32_u16(vandq_u16(va0x2, vmask));
268 const float32x4_t va1x2o = vreinterpretq_f32_u16(vandq_u16(va1x2, vmask));
269 const float32x4_t va2x2o = vreinterpretq_f32_u16(vandq_u16(va2x2, vmask));
270 const float32x4_t va3x2o = vreinterpretq_f32_u16(vandq_u16(va3x2, vmask));
271 const float32x4_t va4x2o = vreinterpretq_f32_u16(vandq_u16(va4x2, vmask));
272 const float32x4_t va0x3o = vreinterpretq_f32_u16(vandq_u16(va0x3, vmask));
273 const float32x4_t va1x3o = vreinterpretq_f32_u16(vandq_u16(va1x3, vmask));
274 const float32x4_t va2x3o = vreinterpretq_f32_u16(vandq_u16(va2x3, vmask));
275 const float32x4_t va3x3o = vreinterpretq_f32_u16(vandq_u16(va3x3, vmask));
276 const float32x4_t va4x3o = vreinterpretq_f32_u16(vandq_u16(va4x3, vmask));
277
278 vacc0x0 = vfmaq_f32(vacc0x0, va0x0o, vb0o);
279 vacc1x0 = vfmaq_f32(vacc1x0, va1x0o, vb0o);
280 vacc2x0 = vfmaq_f32(vacc2x0, va2x0o, vb0o);
281 vacc3x0 = vfmaq_f32(vacc3x0, va3x0o, vb0o);
282 vacc4x0 = vfmaq_f32(vacc4x0, va4x0o, vb0o);
283 vacc0x1 = vfmaq_f32(vacc0x1, va0x1o, vb1o);
284 vacc1x1 = vfmaq_f32(vacc1x1, va1x1o, vb1o);
285 vacc2x1 = vfmaq_f32(vacc2x1, va2x1o, vb1o);
286 vacc3x1 = vfmaq_f32(vacc3x1, va3x1o, vb1o);
287 vacc4x1 = vfmaq_f32(vacc4x1, va4x1o, vb1o);
288 vacc0x2 = vfmaq_f32(vacc0x2, va0x2o, vb2o);
289 vacc1x2 = vfmaq_f32(vacc1x2, va1x2o, vb2o);
290 vacc2x2 = vfmaq_f32(vacc2x2, va2x2o, vb2o);
291 vacc3x2 = vfmaq_f32(vacc3x2, va3x2o, vb2o);
292 vacc4x2 = vfmaq_f32(vacc4x2, va4x2o, vb2o);
293 vacc0x3 = vfmaq_f32(vacc0x3, va0x3o, vb3o);
294 vacc1x3 = vfmaq_f32(vacc1x3, va1x3o, vb3o);
295 vacc2x3 = vfmaq_f32(vacc2x3, va2x3o, vb3o);
296 vacc3x3 = vfmaq_f32(vacc3x3, va3x3o, vb3o);
297 vacc4x3 = vfmaq_f32(vacc4x3, va4x3o, vb3o);
298 }
299
300 #if XNN_ARCH_ARM64
301 const float32x4_t vacc0x01 = vpaddq_f32(vacc0x0, vacc0x1);
302 const float32x4_t vacc1x01 = vpaddq_f32(vacc1x0, vacc1x1);
303 const float32x4_t vacc2x01 = vpaddq_f32(vacc2x0, vacc2x1);
304 const float32x4_t vacc3x01 = vpaddq_f32(vacc3x0, vacc3x1);
305 const float32x4_t vacc4x01 = vpaddq_f32(vacc4x0, vacc4x1);
306 const float32x4_t vacc0x23 = vpaddq_f32(vacc0x2, vacc0x3);
307 const float32x4_t vacc1x23 = vpaddq_f32(vacc1x2, vacc1x3);
308 const float32x4_t vacc2x23 = vpaddq_f32(vacc2x2, vacc2x3);
309 const float32x4_t vacc3x23 = vpaddq_f32(vacc3x2, vacc3x3);
310 const float32x4_t vacc4x23 = vpaddq_f32(vacc4x2, vacc4x3);
311
312 float32x4_t vacc0x0123 = vpaddq_f32(vacc0x01, vacc0x23);
313 float32x4_t vacc1x0123 = vpaddq_f32(vacc1x01, vacc1x23);
314 float32x4_t vacc2x0123 = vpaddq_f32(vacc2x01, vacc2x23);
315 float32x4_t vacc3x0123 = vpaddq_f32(vacc3x01, vacc3x23);
316 float32x4_t vacc4x0123 = vpaddq_f32(vacc4x01, vacc4x23);
317 #else
318 const float32x2_t vsum0x0 = vadd_f32(vget_low_f32(vacc0x0), vget_high_f32(vacc0x0));
319 const float32x2_t vsum1x0 = vadd_f32(vget_low_f32(vacc1x0), vget_high_f32(vacc1x0));
320 const float32x2_t vsum2x0 = vadd_f32(vget_low_f32(vacc2x0), vget_high_f32(vacc2x0));
321 const float32x2_t vsum3x0 = vadd_f32(vget_low_f32(vacc3x0), vget_high_f32(vacc3x0));
322 const float32x2_t vsum4x0 = vadd_f32(vget_low_f32(vacc4x0), vget_high_f32(vacc4x0));
323 const float32x2_t vsum0x1 = vadd_f32(vget_low_f32(vacc0x1), vget_high_f32(vacc0x1));
324 const float32x2_t vsum1x1 = vadd_f32(vget_low_f32(vacc1x1), vget_high_f32(vacc1x1));
325 const float32x2_t vsum2x1 = vadd_f32(vget_low_f32(vacc2x1), vget_high_f32(vacc2x1));
326 const float32x2_t vsum3x1 = vadd_f32(vget_low_f32(vacc3x1), vget_high_f32(vacc3x1));
327 const float32x2_t vsum4x1 = vadd_f32(vget_low_f32(vacc4x1), vget_high_f32(vacc4x1));
328 const float32x2_t vsum0x2 = vadd_f32(vget_low_f32(vacc0x2), vget_high_f32(vacc0x2));
329 const float32x2_t vsum1x2 = vadd_f32(vget_low_f32(vacc1x2), vget_high_f32(vacc1x2));
330 const float32x2_t vsum2x2 = vadd_f32(vget_low_f32(vacc2x2), vget_high_f32(vacc2x2));
331 const float32x2_t vsum3x2 = vadd_f32(vget_low_f32(vacc3x2), vget_high_f32(vacc3x2));
332 const float32x2_t vsum4x2 = vadd_f32(vget_low_f32(vacc4x2), vget_high_f32(vacc4x2));
333 const float32x2_t vsum0x3 = vadd_f32(vget_low_f32(vacc0x3), vget_high_f32(vacc0x3));
334 const float32x2_t vsum1x3 = vadd_f32(vget_low_f32(vacc1x3), vget_high_f32(vacc1x3));
335 const float32x2_t vsum2x3 = vadd_f32(vget_low_f32(vacc2x3), vget_high_f32(vacc2x3));
336 const float32x2_t vsum3x3 = vadd_f32(vget_low_f32(vacc3x3), vget_high_f32(vacc3x3));
337 const float32x2_t vsum4x3 = vadd_f32(vget_low_f32(vacc4x3), vget_high_f32(vacc4x3));
338
339 float32x4_t vacc0x0123 = vcombine_f32(vpadd_f32(vsum0x0, vsum0x1), vpadd_f32(vsum0x2, vsum0x3));
340 float32x4_t vacc1x0123 = vcombine_f32(vpadd_f32(vsum1x0, vsum1x1), vpadd_f32(vsum1x2, vsum1x3));
341 float32x4_t vacc2x0123 = vcombine_f32(vpadd_f32(vsum2x0, vsum2x1), vpadd_f32(vsum2x2, vsum2x3));
342 float32x4_t vacc3x0123 = vcombine_f32(vpadd_f32(vsum3x0, vsum3x1), vpadd_f32(vsum3x2, vsum3x3));
343 float32x4_t vacc4x0123 = vcombine_f32(vpadd_f32(vsum4x0, vsum4x1), vpadd_f32(vsum4x2, vsum4x3));
344 #endif
345
346 const float32x4_t vmax = vld1q_dup_f32(¶ms->scalar.max);
347 vacc0x0123 = vminq_f32(vacc0x0123, vmax);
348 vacc1x0123 = vminq_f32(vacc1x0123, vmax);
349 vacc2x0123 = vminq_f32(vacc2x0123, vmax);
350 vacc3x0123 = vminq_f32(vacc3x0123, vmax);
351 vacc4x0123 = vminq_f32(vacc4x0123, vmax);
352
353 const float32x4_t vmin = vld1q_dup_f32(¶ms->scalar.min);
354 vacc0x0123 = vmaxq_f32(vacc0x0123, vmin);
355 vacc1x0123 = vmaxq_f32(vacc1x0123, vmin);
356 vacc2x0123 = vmaxq_f32(vacc2x0123, vmin);
357 vacc3x0123 = vmaxq_f32(vacc3x0123, vmin);
358 vacc4x0123 = vmaxq_f32(vacc4x0123, vmin);
359
360 uint16x4_t vout0x0123 = vshrn_n_u32(vreinterpretq_u32_f32(vacc0x0123), 16);
361 uint16x4_t vout1x0123 = vshrn_n_u32(vreinterpretq_u32_f32(vacc1x0123), 16);
362 uint16x4_t vout2x0123 = vshrn_n_u32(vreinterpretq_u32_f32(vacc2x0123), 16);
363 uint16x4_t vout3x0123 = vshrn_n_u32(vreinterpretq_u32_f32(vacc3x0123), 16);
364 uint16x4_t vout4x0123 = vshrn_n_u32(vreinterpretq_u32_f32(vacc4x0123), 16);
365
366 if XNN_LIKELY(nc >= 4) {
367 vst1_u16(c0, vout0x0123);
368 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
369 vst1_u16(c1, vout1x0123);
370 c1 = (uint16_t*) ((uintptr_t) c1 + cn_stride);
371 vst1_u16(c2, vout2x0123);
372 c2 = (uint16_t*) ((uintptr_t) c2 + cn_stride);
373 vst1_u16(c3, vout3x0123);
374 c3 = (uint16_t*) ((uintptr_t) c3 + cn_stride);
375 vst1_u16(c4, vout4x0123);
376 c4 = (uint16_t*) ((uintptr_t) c4 + cn_stride);
377
378 a0 = (const uint16_t*) ((uintptr_t) a0 - kc);
379 a1 = (const uint16_t*) ((uintptr_t) a1 - kc);
380 a2 = (const uint16_t*) ((uintptr_t) a2 - kc);
381 a3 = (const uint16_t*) ((uintptr_t) a3 - kc);
382 a4 = (const uint16_t*) ((uintptr_t) a4 - kc);
383
384 nc -= 4;
385 } else {
386 if (nc & 2) {
387 vst1_lane_u32((void*) c0, vreinterpret_u32_u16(vout0x0123), 0); c0 += 2;
388 vst1_lane_u32((void*) c1, vreinterpret_u32_u16(vout1x0123), 0); c1 += 2;
389 vst1_lane_u32((void*) c2, vreinterpret_u32_u16(vout2x0123), 0); c2 += 2;
390 vst1_lane_u32((void*) c3, vreinterpret_u32_u16(vout3x0123), 0); c3 += 2;
391 vst1_lane_u32((void*) c4, vreinterpret_u32_u16(vout4x0123), 0); c4 += 2;
392
393 vout0x0123 = vext_u16(vout0x0123, vout0x0123, 2);
394 vout1x0123 = vext_u16(vout1x0123, vout1x0123, 2);
395 vout2x0123 = vext_u16(vout2x0123, vout2x0123, 2);
396 vout3x0123 = vext_u16(vout3x0123, vout3x0123, 2);
397 vout4x0123 = vext_u16(vout4x0123, vout4x0123, 2);
398 }
399 if (nc & 1) {
400 vst1_lane_u16(c0, vout0x0123, 0);
401 vst1_lane_u16(c1, vout1x0123, 0);
402 vst1_lane_u16(c2, vout2x0123, 0);
403 vst1_lane_u16(c3, vout3x0123, 0);
404 vst1_lane_u16(c4, vout4x0123, 0);
405 }
406
407 nc = 0;
408 }
409 } while (nc != 0);
410 }
411