Debian Codegraph @

src/f16-igemm/gen/f16-igemm-6x8-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_6x8__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 <= 6);
35 assert(nc != 0);
36 assert(kc != 0);
37 assert(kc % sizeof(uint16_t) == 0);
38 assert(ks != 0);
39 assert(ks % (6 * 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
67 do {
68 float16x8_t vacc0x0 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
69 float16x8_t vacc1x0 = vacc0x0;
70 float16x8_t vacc2x0 = vacc0x0;
71 float16x8_t vacc3x0 = vacc0x0;
72 float16x8_t vacc4x0 = vacc0x0;
73 float16x8_t vacc5x0 = vacc0x0;
74
75 size_t p = ks;
76 do {
77 const uint16_t* restrict a0 = (const uint16_t*) a[0];
78 assert(a0 != NULL);
79 if XNN_UNPREDICTABLE(a0 != (const uint16_t*) zero) {
80 a0 = (const uint16_t*) ((uintptr_t) a0 + a_offset);
81 }
82 const uint16_t* restrict a1 = (const uint16_t*) a[1];
83 assert(a1 != NULL);
84 if XNN_UNPREDICTABLE(a1 != (const uint16_t*) zero) {
85 a1 = (const uint16_t*) ((uintptr_t) a1 + a_offset);
86 }
87 const uint16_t* restrict a2 = (const uint16_t*) a[2];
88 assert(a2 != NULL);
89 if XNN_UNPREDICTABLE(a2 != (const uint16_t*) zero) {
90 a2 = (const uint16_t*) ((uintptr_t) a2 + a_offset);
91 }
92 const uint16_t* restrict a3 = (const uint16_t*) a[3];
93 assert(a3 != NULL);
94 if XNN_UNPREDICTABLE(a3 != (const uint16_t*) zero) {
95 a3 = (const uint16_t*) ((uintptr_t) a3 + a_offset);
96 }
97 const uint16_t* restrict a4 = (const uint16_t*) a[4];
98 assert(a4 != NULL);
99 if XNN_UNPREDICTABLE(a4 != (const uint16_t*) zero) {
100 a4 = (const uint16_t*) ((uintptr_t) a4 + a_offset);
101 }
102 const uint16_t* restrict a5 = (const uint16_t*) a[5];
103 assert(a5 != NULL);
104 if XNN_UNPREDICTABLE(a5 != (const uint16_t*) zero) {
105 a5 = (const uint16_t*) ((uintptr_t) a5 + a_offset);
106 }
107 a += 6;
108
109 size_t k = kc;
110 for (; k >= 4 * sizeof(uint16_t); k -= 4 * sizeof(uint16_t)) {
111 const float16x4_t va0 = vreinterpret_f16_u16(vld1_u16(a0)); a0 += 4;
112 const float16x4_t va1 = vreinterpret_f16_u16(vld1_u16(a1)); a1 += 4;
113 const float16x4_t va2 = vreinterpret_f16_u16(vld1_u16(a2)); a2 += 4;
114 const float16x4_t va3 = vreinterpret_f16_u16(vld1_u16(a3)); a3 += 4;
115 const float16x4_t va4 = vreinterpret_f16_u16(vld1_u16(a4)); a4 += 4;
116 const float16x4_t va5 = vreinterpret_f16_u16(vld1_u16(a5)); a5 += 4;
117
118 const float16x8_t vb0c0 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
119
120 #if XNN_ARCH_ARM64
121 vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c0, va0, 0);
122 vacc1x0 = vfmaq_lane_f16(vacc1x0, vb0c0, va1, 0);
123 vacc2x0 = vfmaq_lane_f16(vacc2x0, vb0c0, va2, 0);
124 vacc3x0 = vfmaq_lane_f16(vacc3x0, vb0c0, va3, 0);
125 vacc4x0 = vfmaq_lane_f16(vacc4x0, vb0c0, va4, 0);
126 vacc5x0 = vfmaq_lane_f16(vacc5x0, vb0c0, va5, 0);
127 #else
128 vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c0, va0, 0);
129 vacc1x0 = vmlaq_lane_f16(vacc1x0, vb0c0, va1, 0);
130 vacc2x0 = vmlaq_lane_f16(vacc2x0, vb0c0, va2, 0);
131 vacc3x0 = vmlaq_lane_f16(vacc3x0, vb0c0, va3, 0);
132 vacc4x0 = vmlaq_lane_f16(vacc4x0, vb0c0, va4, 0);
133 vacc5x0 = vmlaq_lane_f16(vacc5x0, vb0c0, va5, 0);
134 #endif
135 const float16x8_t vb0c1 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
136
137 #if XNN_ARCH_ARM64
138 vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c1, va0, 1);
139 vacc1x0 = vfmaq_lane_f16(vacc1x0, vb0c1, va1, 1);
140 vacc2x0 = vfmaq_lane_f16(vacc2x0, vb0c1, va2, 1);
141 vacc3x0 = vfmaq_lane_f16(vacc3x0, vb0c1, va3, 1);
142 vacc4x0 = vfmaq_lane_f16(vacc4x0, vb0c1, va4, 1);
143 vacc5x0 = vfmaq_lane_f16(vacc5x0, vb0c1, va5, 1);
144 #else
145 vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c1, va0, 1);
146 vacc1x0 = vmlaq_lane_f16(vacc1x0, vb0c1, va1, 1);
147 vacc2x0 = vmlaq_lane_f16(vacc2x0, vb0c1, va2, 1);
148 vacc3x0 = vmlaq_lane_f16(vacc3x0, vb0c1, va3, 1);
149 vacc4x0 = vmlaq_lane_f16(vacc4x0, vb0c1, va4, 1);
150 vacc5x0 = vmlaq_lane_f16(vacc5x0, vb0c1, va5, 1);
151 #endif
152 const float16x8_t vb0c2 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
153
154 #if XNN_ARCH_ARM64
155 vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c2, va0, 2);
156 vacc1x0 = vfmaq_lane_f16(vacc1x0, vb0c2, va1, 2);
157 vacc2x0 = vfmaq_lane_f16(vacc2x0, vb0c2, va2, 2);
158 vacc3x0 = vfmaq_lane_f16(vacc3x0, vb0c2, va3, 2);
159 vacc4x0 = vfmaq_lane_f16(vacc4x0, vb0c2, va4, 2);
160 vacc5x0 = vfmaq_lane_f16(vacc5x0, vb0c2, va5, 2);
161 #else
162 vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c2, va0, 2);
163 vacc1x0 = vmlaq_lane_f16(vacc1x0, vb0c2, va1, 2);
164 vacc2x0 = vmlaq_lane_f16(vacc2x0, vb0c2, va2, 2);
165 vacc3x0 = vmlaq_lane_f16(vacc3x0, vb0c2, va3, 2);
166 vacc4x0 = vmlaq_lane_f16(vacc4x0, vb0c2, va4, 2);
167 vacc5x0 = vmlaq_lane_f16(vacc5x0, vb0c2, va5, 2);
168 #endif
169 const float16x8_t vb0c3 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
170
171 #if XNN_ARCH_ARM64
172 vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c3, va0, 3);
173 vacc1x0 = vfmaq_lane_f16(vacc1x0, vb0c3, va1, 3);
174 vacc2x0 = vfmaq_lane_f16(vacc2x0, vb0c3, va2, 3);
175 vacc3x0 = vfmaq_lane_f16(vacc3x0, vb0c3, va3, 3);
176 vacc4x0 = vfmaq_lane_f16(vacc4x0, vb0c3, va4, 3);
177 vacc5x0 = vfmaq_lane_f16(vacc5x0, vb0c3, va5, 3);
178 #else
179 vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c3, va0, 3);
180 vacc1x0 = vmlaq_lane_f16(vacc1x0, vb0c3, va1, 3);
181 vacc2x0 = vmlaq_lane_f16(vacc2x0, vb0c3, va2, 3);
182 vacc3x0 = vmlaq_lane_f16(vacc3x0, vb0c3, va3, 3);
183 vacc4x0 = vmlaq_lane_f16(vacc4x0, vb0c3, va4, 3);
184 vacc5x0 = vmlaq_lane_f16(vacc5x0, vb0c3, va5, 3);
185 #endif
186 }
187 if XNN_UNLIKELY(k != 0) {
188 do {
189 const float16x8_t va0 = vreinterpretq_f16_u16(vld1q_dup_u16(a0)); a0 += 1;
190 const float16x8_t va1 = vreinterpretq_f16_u16(vld1q_dup_u16(a1)); a1 += 1;
191 const float16x8_t va2 = vreinterpretq_f16_u16(vld1q_dup_u16(a2)); a2 += 1;
192 const float16x8_t va3 = vreinterpretq_f16_u16(vld1q_dup_u16(a3)); a3 += 1;
193 const float16x8_t va4 = vreinterpretq_f16_u16(vld1q_dup_u16(a4)); a4 += 1;
194 const float16x8_t va5 = vreinterpretq_f16_u16(vld1q_dup_u16(a5)); a5 += 1;
195
196 const float16x8_t vb0 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
197
198 vacc0x0 = vfmaq_f16(vacc0x0, va0, vb0);
199 vacc1x0 = vfmaq_f16(vacc1x0, va1, vb0);
200 vacc2x0 = vfmaq_f16(vacc2x0, va2, vb0);
201 vacc3x0 = vfmaq_f16(vacc3x0, va3, vb0);
202 vacc4x0 = vfmaq_f16(vacc4x0, va4, vb0);
203 vacc5x0 = vfmaq_f16(vacc5x0, va5, vb0);
204
205 k -= sizeof(uint16_t);
206 } while (k != 0);
207 }
208 p -= 6 * sizeof(void*);
209 } while (p != 0);
210
211
212 const float16x8_t vmin = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.min));
213 vacc0x0 = vmaxq_f16(vacc0x0, vmin);
214 vacc1x0 = vmaxq_f16(vacc1x0, vmin);
215 vacc2x0 = vmaxq_f16(vacc2x0, vmin);
216 vacc3x0 = vmaxq_f16(vacc3x0, vmin);
217 vacc4x0 = vmaxq_f16(vacc4x0, vmin);
218 vacc5x0 = vmaxq_f16(vacc5x0, vmin);
219
220 const float16x8_t vmax = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.max));
221 vacc0x0 = vminq_f16(vacc0x0, vmax);
222 vacc1x0 = vminq_f16(vacc1x0, vmax);
223 vacc2x0 = vminq_f16(vacc2x0, vmax);
224 vacc3x0 = vminq_f16(vacc3x0, vmax);
225 vacc4x0 = vminq_f16(vacc4x0, vmax);
226 vacc5x0 = vminq_f16(vacc5x0, vmax);
227
228 if XNN_LIKELY(nc >= 8) {
229 vst1q_u16(c5, vreinterpretq_u16_f16(vacc5x0));
230 c5 = (uint16_t*) ((uintptr_t) c5 + cn_stride);
231 vst1q_u16(c4, vreinterpretq_u16_f16(vacc4x0));
232 c4 = (uint16_t*) ((uintptr_t) c4 + cn_stride);
233 vst1q_u16(c3, vreinterpretq_u16_f16(vacc3x0));
234 c3 = (uint16_t*) ((uintptr_t) c3 + cn_stride);
235 vst1q_u16(c2, vreinterpretq_u16_f16(vacc2x0));
236 c2 = (uint16_t*) ((uintptr_t) c2 + cn_stride);
237 vst1q_u16(c1, vreinterpretq_u16_f16(vacc1x0));
238 c1 = (uint16_t*) ((uintptr_t) c1 + cn_stride);
239 vst1q_u16(c0, vreinterpretq_u16_f16(vacc0x0));
240 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
241
242 a = (const xnn_float16**restrict) ((uintptr_t) a - ks);
243 nc -= 8;
244 } else {
245 float16x4_t vacc5 = vget_low_f16(vacc5x0);
246 float16x4_t vacc4 = vget_low_f16(vacc4x0);
247 float16x4_t vacc3 = vget_low_f16(vacc3x0);
248 float16x4_t vacc2 = vget_low_f16(vacc2x0);
249 float16x4_t vacc1 = vget_low_f16(vacc1x0);
250 float16x4_t vacc0 = vget_low_f16(vacc0x0);
251 if (nc & 4) {
252 vst1_u16(c5, vreinterpret_u16_f16(vacc5)); c5 += 4;
253 vst1_u16(c4, vreinterpret_u16_f16(vacc4)); c4 += 4;
254 vst1_u16(c3, vreinterpret_u16_f16(vacc3)); c3 += 4;
255 vst1_u16(c2, vreinterpret_u16_f16(vacc2)); c2 += 4;
256 vst1_u16(c1, vreinterpret_u16_f16(vacc1)); c1 += 4;
257 vst1_u16(c0, vreinterpret_u16_f16(vacc0)); c0 += 4;
258
259 vacc5 = vget_high_f16(vacc5x0);
260 vacc4 = vget_high_f16(vacc4x0);
261 vacc3 = vget_high_f16(vacc3x0);
262 vacc2 = vget_high_f16(vacc2x0);
263 vacc1 = vget_high_f16(vacc1x0);
264 vacc0 = vget_high_f16(vacc0x0);
265 }
266 if (nc & 2) {
267 vst1_lane_u32((void*) c5, vreinterpret_u32_f16(vacc5), 0); c5 += 2;
268 vst1_lane_u32((void*) c4, vreinterpret_u32_f16(vacc4), 0); c4 += 2;
269 vst1_lane_u32((void*) c3, vreinterpret_u32_f16(vacc3), 0); c3 += 2;
270 vst1_lane_u32((void*) c2, vreinterpret_u32_f16(vacc2), 0); c2 += 2;
271 vst1_lane_u32((void*) c1, vreinterpret_u32_f16(vacc1), 0); c1 += 2;
272 vst1_lane_u32((void*) c0, vreinterpret_u32_f16(vacc0), 0); c0 += 2;
273
274 vacc5 = vext_f16(vacc5, vacc5, 2);
275 vacc4 = vext_f16(vacc4, vacc4, 2);
276 vacc3 = vext_f16(vacc3, vacc3, 2);
277 vacc2 = vext_f16(vacc2, vacc2, 2);
278 vacc1 = vext_f16(vacc1, vacc1, 2);
279 vacc0 = vext_f16(vacc0, vacc0, 2);
280 }
281 if (nc & 1) {
282 vst1_lane_u16(c5, vreinterpret_u16_f16(vacc5), 0);
283 vst1_lane_u16(c4, vreinterpret_u16_f16(vacc4), 0);
284 vst1_lane_u16(c3, vreinterpret_u16_f16(vacc3), 0);
285 vst1_lane_u16(c2, vreinterpret_u16_f16(vacc2), 0);
286 vst1_lane_u16(c1, vreinterpret_u16_f16(vacc1), 0);
287 vst1_lane_u16(c0, vreinterpret_u16_f16(vacc0), 0);
288 }
289
290 nc = 0;
291 }
292 } while (nc != 0);
293 }