Debian Codegraph @

src/f16-igemm/gen/f16-igemm-8x8-minmax-neonfp16arith-ld64.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-igemm/neonfp16arith-ld64.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2019 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/igemm.h"
16 #include "xnnpack/intrinsics-polyfill.h"
17
18
19 void xnn_f16_igemm_minmax_ukernel_8x8__neonfp16arith_ld64(
20 size_t mr,
21 size_t nc,
22 size_t kc,
23 size_t ks,
24 const xnn_float16** restrict a,
25 const xnn_float16* restrict w,
26 xnn_float16* restrict c,
27 size_t cm_stride,
28 size_t cn_stride,
29 size_t a_offset,
30 const xnn_float16* zero,
31 const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
32 {
33 assert(mr != 0);
34 assert(mr <= 8);
35 assert(nc != 0);
36 assert(kc != 0);
37 assert(kc % sizeof(uint16_t) == 0);
38 assert(ks != 0);
39 assert(ks % (8 * sizeof(void*)) == 0);
40 assert(a_offset % sizeof(uint16_t) == 0);
41 assert(a != NULL);
42 assert(w != NULL);
43 assert(c != NULL);
44
45 uint16_t* c0 = (uint16_t*) c;
46 uint16_t* c1 = (uint16_t*) ((uintptr_t) c0 + cm_stride);
47 if XNN_UNPREDICTABLE(mr < 2) {
48 c1 = c0;
49 }
50 uint16_t* c2 = (uint16_t*) ((uintptr_t) c1 + cm_stride);
51 if XNN_UNPREDICTABLE(mr <= 2) {
52 c2 = c1;
53 }
54 uint16_t* c3 = (uint16_t*) ((uintptr_t) c2 + cm_stride);
55 if XNN_UNPREDICTABLE(mr < 4) {
56 c3 = c2;
57 }
58 uint16_t* c4 = (uint16_t*) ((uintptr_t) c3 + cm_stride);
59 if XNN_UNPREDICTABLE(mr <= 4) {
60 c4 = c3;
61 }
62 uint16_t* c5 = (uint16_t*) ((uintptr_t) c4 + cm_stride);
63 if XNN_UNPREDICTABLE(mr < 6) {
64 c5 = c4;
65 }
66 uint16_t* c6 = (uint16_t*) ((uintptr_t) c5 + cm_stride);
67 if XNN_UNPREDICTABLE(mr <= 6) {
68 c6 = c5;
69 }
70 uint16_t* c7 = (uint16_t*) ((uintptr_t) c6 + cm_stride);
71 if XNN_UNPREDICTABLE(mr != 8) {
72 c7 = c6;
73 }
74
75 do {
76 float16x8_t vacc0x0 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
77 float16x8_t vacc1x0 = vacc0x0;
78 float16x8_t vacc2x0 = vacc0x0;
79 float16x8_t vacc3x0 = vacc0x0;
80 float16x8_t vacc4x0 = vacc0x0;
81 float16x8_t vacc5x0 = vacc0x0;
82 float16x8_t vacc6x0 = vacc0x0;
83 float16x8_t vacc7x0 = vacc0x0;
84
85 size_t p = ks;
86 do {
87 const uint16_t* restrict a0 = (const uint16_t*) a[0];
88 assert(a0 != NULL);
89 if XNN_UNPREDICTABLE(a0 != (const uint16_t*) zero) {
90 a0 = (const uint16_t*) ((uintptr_t) a0 + a_offset);
91 }
92 const uint16_t* restrict a1 = (const uint16_t*) a[1];
93 assert(a1 != NULL);
94 if XNN_UNPREDICTABLE(a1 != (const uint16_t*) zero) {
95 a1 = (const uint16_t*) ((uintptr_t) a1 + a_offset);
96 }
97 const uint16_t* restrict a2 = (const uint16_t*) a[2];
98 assert(a2 != NULL);
99 if XNN_UNPREDICTABLE(a2 != (const uint16_t*) zero) {
100 a2 = (const uint16_t*) ((uintptr_t) a2 + a_offset);
101 }
102 const uint16_t* restrict a3 = (const uint16_t*) a[3];
103 assert(a3 != NULL);
104 if XNN_UNPREDICTABLE(a3 != (const uint16_t*) zero) {
105 a3 = (const uint16_t*) ((uintptr_t) a3 + a_offset);
106 }
107 const uint16_t* restrict a4 = (const uint16_t*) a[4];
108 assert(a4 != NULL);
109 if XNN_UNPREDICTABLE(a4 != (const uint16_t*) zero) {
110 a4 = (const uint16_t*) ((uintptr_t) a4 + a_offset);
111 }
112 const uint16_t* restrict a5 = (const uint16_t*) a[5];
113 assert(a5 != NULL);
114 if XNN_UNPREDICTABLE(a5 != (const uint16_t*) zero) {
115 a5 = (const uint16_t*) ((uintptr_t) a5 + a_offset);
116 }
117 const uint16_t* restrict a6 = (const uint16_t*) a[6];
118 assert(a6 != NULL);
119 if XNN_UNPREDICTABLE(a6 != (const uint16_t*) zero) {
120 a6 = (const uint16_t*) ((uintptr_t) a6 + a_offset);
121 }
122 const uint16_t* restrict a7 = (const uint16_t*) a[7];
123 assert(a7 != NULL);
124 if XNN_UNPREDICTABLE(a7 != (const uint16_t*) zero) {
125 a7 = (const uint16_t*) ((uintptr_t) a7 + a_offset);
126 }
127 a += 8;
128
129 size_t k = kc;
130 for (; k >= 4 * sizeof(uint16_t); k -= 4 * sizeof(uint16_t)) {
131 const float16x4_t va0 = vreinterpret_f16_u16(vld1_u16(a0)); a0 += 4;
132 const float16x4_t va1 = vreinterpret_f16_u16(vld1_u16(a1)); a1 += 4;
133 const float16x4_t va2 = vreinterpret_f16_u16(vld1_u16(a2)); a2 += 4;
134 const float16x4_t va3 = vreinterpret_f16_u16(vld1_u16(a3)); a3 += 4;
135 const float16x4_t va4 = vreinterpret_f16_u16(vld1_u16(a4)); a4 += 4;
136 const float16x4_t va5 = vreinterpret_f16_u16(vld1_u16(a5)); a5 += 4;
137 const float16x4_t va6 = vreinterpret_f16_u16(vld1_u16(a6)); a6 += 4;
138 const float16x4_t va7 = vreinterpret_f16_u16(vld1_u16(a7)); a7 += 4;
139
140 const float16x8_t vb0c0 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
141
142 #if XNN_ARCH_ARM64
143 vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c0, va0, 0);
144 vacc1x0 = vfmaq_lane_f16(vacc1x0, vb0c0, va1, 0);
145 vacc2x0 = vfmaq_lane_f16(vacc2x0, vb0c0, va2, 0);
146 vacc3x0 = vfmaq_lane_f16(vacc3x0, vb0c0, va3, 0);
147 vacc4x0 = vfmaq_lane_f16(vacc4x0, vb0c0, va4, 0);
148 vacc5x0 = vfmaq_lane_f16(vacc5x0, vb0c0, va5, 0);
149 vacc6x0 = vfmaq_lane_f16(vacc6x0, vb0c0, va6, 0);
150 vacc7x0 = vfmaq_lane_f16(vacc7x0, vb0c0, va7, 0);
151 #else
152 vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c0, va0, 0);
153 vacc1x0 = vmlaq_lane_f16(vacc1x0, vb0c0, va1, 0);
154 vacc2x0 = vmlaq_lane_f16(vacc2x0, vb0c0, va2, 0);
155 vacc3x0 = vmlaq_lane_f16(vacc3x0, vb0c0, va3, 0);
156 vacc4x0 = vmlaq_lane_f16(vacc4x0, vb0c0, va4, 0);
157 vacc5x0 = vmlaq_lane_f16(vacc5x0, vb0c0, va5, 0);
158 vacc6x0 = vmlaq_lane_f16(vacc6x0, vb0c0, va6, 0);
159 vacc7x0 = vmlaq_lane_f16(vacc7x0, vb0c0, va7, 0);
160 #endif
161 const float16x8_t vb0c1 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
162
163 #if XNN_ARCH_ARM64
164 vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c1, va0, 1);
165 vacc1x0 = vfmaq_lane_f16(vacc1x0, vb0c1, va1, 1);
166 vacc2x0 = vfmaq_lane_f16(vacc2x0, vb0c1, va2, 1);
167 vacc3x0 = vfmaq_lane_f16(vacc3x0, vb0c1, va3, 1);
168 vacc4x0 = vfmaq_lane_f16(vacc4x0, vb0c1, va4, 1);
169 vacc5x0 = vfmaq_lane_f16(vacc5x0, vb0c1, va5, 1);
170 vacc6x0 = vfmaq_lane_f16(vacc6x0, vb0c1, va6, 1);
171 vacc7x0 = vfmaq_lane_f16(vacc7x0, vb0c1, va7, 1);
172 #else
173 vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c1, va0, 1);
174 vacc1x0 = vmlaq_lane_f16(vacc1x0, vb0c1, va1, 1);
175 vacc2x0 = vmlaq_lane_f16(vacc2x0, vb0c1, va2, 1);
176 vacc3x0 = vmlaq_lane_f16(vacc3x0, vb0c1, va3, 1);
177 vacc4x0 = vmlaq_lane_f16(vacc4x0, vb0c1, va4, 1);
178 vacc5x0 = vmlaq_lane_f16(vacc5x0, vb0c1, va5, 1);
179 vacc6x0 = vmlaq_lane_f16(vacc6x0, vb0c1, va6, 1);
180 vacc7x0 = vmlaq_lane_f16(vacc7x0, vb0c1, va7, 1);
181 #endif
182 const float16x8_t vb0c2 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
183
184 #if XNN_ARCH_ARM64
185 vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c2, va0, 2);
186 vacc1x0 = vfmaq_lane_f16(vacc1x0, vb0c2, va1, 2);
187 vacc2x0 = vfmaq_lane_f16(vacc2x0, vb0c2, va2, 2);
188 vacc3x0 = vfmaq_lane_f16(vacc3x0, vb0c2, va3, 2);
189 vacc4x0 = vfmaq_lane_f16(vacc4x0, vb0c2, va4, 2);
190 vacc5x0 = vfmaq_lane_f16(vacc5x0, vb0c2, va5, 2);
191 vacc6x0 = vfmaq_lane_f16(vacc6x0, vb0c2, va6, 2);
192 vacc7x0 = vfmaq_lane_f16(vacc7x0, vb0c2, va7, 2);
193 #else
194 vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c2, va0, 2);
195 vacc1x0 = vmlaq_lane_f16(vacc1x0, vb0c2, va1, 2);
196 vacc2x0 = vmlaq_lane_f16(vacc2x0, vb0c2, va2, 2);
197 vacc3x0 = vmlaq_lane_f16(vacc3x0, vb0c2, va3, 2);
198 vacc4x0 = vmlaq_lane_f16(vacc4x0, vb0c2, va4, 2);
199 vacc5x0 = vmlaq_lane_f16(vacc5x0, vb0c2, va5, 2);
200 vacc6x0 = vmlaq_lane_f16(vacc6x0, vb0c2, va6, 2);
201 vacc7x0 = vmlaq_lane_f16(vacc7x0, vb0c2, va7, 2);
202 #endif
203 const float16x8_t vb0c3 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
204
205 #if XNN_ARCH_ARM64
206 vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c3, va0, 3);
207 vacc1x0 = vfmaq_lane_f16(vacc1x0, vb0c3, va1, 3);
208 vacc2x0 = vfmaq_lane_f16(vacc2x0, vb0c3, va2, 3);
209 vacc3x0 = vfmaq_lane_f16(vacc3x0, vb0c3, va3, 3);
210 vacc4x0 = vfmaq_lane_f16(vacc4x0, vb0c3, va4, 3);
211 vacc5x0 = vfmaq_lane_f16(vacc5x0, vb0c3, va5, 3);
212 vacc6x0 = vfmaq_lane_f16(vacc6x0, vb0c3, va6, 3);
213 vacc7x0 = vfmaq_lane_f16(vacc7x0, vb0c3, va7, 3);
214 #else
215 vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c3, va0, 3);
216 vacc1x0 = vmlaq_lane_f16(vacc1x0, vb0c3, va1, 3);
217 vacc2x0 = vmlaq_lane_f16(vacc2x0, vb0c3, va2, 3);
218 vacc3x0 = vmlaq_lane_f16(vacc3x0, vb0c3, va3, 3);
219 vacc4x0 = vmlaq_lane_f16(vacc4x0, vb0c3, va4, 3);
220 vacc5x0 = vmlaq_lane_f16(vacc5x0, vb0c3, va5, 3);
221 vacc6x0 = vmlaq_lane_f16(vacc6x0, vb0c3, va6, 3);
222 vacc7x0 = vmlaq_lane_f16(vacc7x0, vb0c3, va7, 3);
223 #endif
224 }
225 if XNN_UNLIKELY(k != 0) {
226 do {
227 const float16x8_t va0 = vreinterpretq_f16_u16(vld1q_dup_u16(a0)); a0 += 1;
228 const float16x8_t va1 = vreinterpretq_f16_u16(vld1q_dup_u16(a1)); a1 += 1;
229 const float16x8_t va2 = vreinterpretq_f16_u16(vld1q_dup_u16(a2)); a2 += 1;
230 const float16x8_t va3 = vreinterpretq_f16_u16(vld1q_dup_u16(a3)); a3 += 1;
231 const float16x8_t va4 = vreinterpretq_f16_u16(vld1q_dup_u16(a4)); a4 += 1;
232 const float16x8_t va5 = vreinterpretq_f16_u16(vld1q_dup_u16(a5)); a5 += 1;
233 const float16x8_t va6 = vreinterpretq_f16_u16(vld1q_dup_u16(a6)); a6 += 1;
234 const float16x8_t va7 = vreinterpretq_f16_u16(vld1q_dup_u16(a7)); a7 += 1;
235
236 const float16x8_t vb0 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
237
238 vacc0x0 = vfmaq_f16(vacc0x0, va0, vb0);
239 vacc1x0 = vfmaq_f16(vacc1x0, va1, vb0);
240 vacc2x0 = vfmaq_f16(vacc2x0, va2, vb0);
241 vacc3x0 = vfmaq_f16(vacc3x0, va3, vb0);
242 vacc4x0 = vfmaq_f16(vacc4x0, va4, vb0);
243 vacc5x0 = vfmaq_f16(vacc5x0, va5, vb0);
244 vacc6x0 = vfmaq_f16(vacc6x0, va6, vb0);
245 vacc7x0 = vfmaq_f16(vacc7x0, va7, vb0);
246
247 k -= sizeof(uint16_t);
248 } while (k != 0);
249 }
250 p -= 8 * sizeof(void*);
251 } while (p != 0);
252
253
254 const float16x8_t vmin = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.min));
255 vacc0x0 = vmaxq_f16(vacc0x0, vmin);
256 vacc1x0 = vmaxq_f16(vacc1x0, vmin);
257 vacc2x0 = vmaxq_f16(vacc2x0, vmin);
258 vacc3x0 = vmaxq_f16(vacc3x0, vmin);
259 vacc4x0 = vmaxq_f16(vacc4x0, vmin);
260 vacc5x0 = vmaxq_f16(vacc5x0, vmin);
261 vacc6x0 = vmaxq_f16(vacc6x0, vmin);
262 vacc7x0 = vmaxq_f16(vacc7x0, vmin);
263
264 const float16x8_t vmax = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.max));
265 vacc0x0 = vminq_f16(vacc0x0, vmax);
266 vacc1x0 = vminq_f16(vacc1x0, vmax);
267 vacc2x0 = vminq_f16(vacc2x0, vmax);
268 vacc3x0 = vminq_f16(vacc3x0, vmax);
269 vacc4x0 = vminq_f16(vacc4x0, vmax);
270 vacc5x0 = vminq_f16(vacc5x0, vmax);
271 vacc6x0 = vminq_f16(vacc6x0, vmax);
272 vacc7x0 = vminq_f16(vacc7x0, vmax);
273
274 if XNN_LIKELY(nc >= 8) {
275 vst1q_u16(c7, vreinterpretq_u16_f16(vacc7x0));
276 c7 = (uint16_t*) ((uintptr_t) c7 + cn_stride);
277 vst1q_u16(c6, vreinterpretq_u16_f16(vacc6x0));
278 c6 = (uint16_t*) ((uintptr_t) c6 + cn_stride);
279 vst1q_u16(c5, vreinterpretq_u16_f16(vacc5x0));
280 c5 = (uint16_t*) ((uintptr_t) c5 + cn_stride);
281 vst1q_u16(c4, vreinterpretq_u16_f16(vacc4x0));
282 c4 = (uint16_t*) ((uintptr_t) c4 + cn_stride);
283 vst1q_u16(c3, vreinterpretq_u16_f16(vacc3x0));
284 c3 = (uint16_t*) ((uintptr_t) c3 + cn_stride);
285 vst1q_u16(c2, vreinterpretq_u16_f16(vacc2x0));
286 c2 = (uint16_t*) ((uintptr_t) c2 + cn_stride);
287 vst1q_u16(c1, vreinterpretq_u16_f16(vacc1x0));
288 c1 = (uint16_t*) ((uintptr_t) c1 + cn_stride);
289 vst1q_u16(c0, vreinterpretq_u16_f16(vacc0x0));
290 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
291
292 a = (const xnn_float16**restrict) ((uintptr_t) a - ks);
293 nc -= 8;
294 } else {
295 float16x4_t vacc7 = vget_low_f16(vacc7x0);
296 float16x4_t vacc6 = vget_low_f16(vacc6x0);
297 float16x4_t vacc5 = vget_low_f16(vacc5x0);
298 float16x4_t vacc4 = vget_low_f16(vacc4x0);
299 float16x4_t vacc3 = vget_low_f16(vacc3x0);
300 float16x4_t vacc2 = vget_low_f16(vacc2x0);
301 float16x4_t vacc1 = vget_low_f16(vacc1x0);
302 float16x4_t vacc0 = vget_low_f16(vacc0x0);
303 if (nc & 4) {
304 vst1_u16(c7, vreinterpret_u16_f16(vacc7)); c7 += 4;
305 vst1_u16(c6, vreinterpret_u16_f16(vacc6)); c6 += 4;
306 vst1_u16(c5, vreinterpret_u16_f16(vacc5)); c5 += 4;
307 vst1_u16(c4, vreinterpret_u16_f16(vacc4)); c4 += 4;
308 vst1_u16(c3, vreinterpret_u16_f16(vacc3)); c3 += 4;
309 vst1_u16(c2, vreinterpret_u16_f16(vacc2)); c2 += 4;
310 vst1_u16(c1, vreinterpret_u16_f16(vacc1)); c1 += 4;
311 vst1_u16(c0, vreinterpret_u16_f16(vacc0)); c0 += 4;
312
313 vacc7 = vget_high_f16(vacc7x0);
314 vacc6 = vget_high_f16(vacc6x0);
315 vacc5 = vget_high_f16(vacc5x0);
316 vacc4 = vget_high_f16(vacc4x0);
317 vacc3 = vget_high_f16(vacc3x0);
318 vacc2 = vget_high_f16(vacc2x0);
319 vacc1 = vget_high_f16(vacc1x0);
320 vacc0 = vget_high_f16(vacc0x0);
321 }
322 if (nc & 2) {
323 vst1_lane_u32((void*) c7, vreinterpret_u32_f16(vacc7), 0); c7 += 2;
324 vst1_lane_u32((void*) c6, vreinterpret_u32_f16(vacc6), 0); c6 += 2;
325 vst1_lane_u32((void*) c5, vreinterpret_u32_f16(vacc5), 0); c5 += 2;
326 vst1_lane_u32((void*) c4, vreinterpret_u32_f16(vacc4), 0); c4 += 2;
327 vst1_lane_u32((void*) c3, vreinterpret_u32_f16(vacc3), 0); c3 += 2;
328 vst1_lane_u32((void*) c2, vreinterpret_u32_f16(vacc2), 0); c2 += 2;
329 vst1_lane_u32((void*) c1, vreinterpret_u32_f16(vacc1), 0); c1 += 2;
330 vst1_lane_u32((void*) c0, vreinterpret_u32_f16(vacc0), 0); c0 += 2;
331
332 vacc7 = vext_f16(vacc7, vacc7, 2);
333 vacc6 = vext_f16(vacc6, vacc6, 2);
334 vacc5 = vext_f16(vacc5, vacc5, 2);
335 vacc4 = vext_f16(vacc4, vacc4, 2);
336 vacc3 = vext_f16(vacc3, vacc3, 2);
337 vacc2 = vext_f16(vacc2, vacc2, 2);
338 vacc1 = vext_f16(vacc1, vacc1, 2);
339 vacc0 = vext_f16(vacc0, vacc0, 2);
340 }
341 if (nc & 1) {
342 vst1_lane_u16(c7, vreinterpret_u16_f16(vacc7), 0);
343 vst1_lane_u16(c6, vreinterpret_u16_f16(vacc6), 0);
344 vst1_lane_u16(c5, vreinterpret_u16_f16(vacc5), 0);
345 vst1_lane_u16(c4, vreinterpret_u16_f16(vacc4), 0);
346 vst1_lane_u16(c3, vreinterpret_u16_f16(vacc3), 0);
347 vst1_lane_u16(c2, vreinterpret_u16_f16(vacc2), 0);
348 vst1_lane_u16(c1, vreinterpret_u16_f16(vacc1), 0);
349 vst1_lane_u16(c0, vreinterpret_u16_f16(vacc0), 0);
350 }
351
352 nc = 0;
353 }
354 } while (nc != 0);
355 }