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
17
xnn_f16_igemm_minmax_ukernel_4x16__neonfp16arith_ld64(size_t mr,size_t nc,size_t kc,size_t ks,const void ** restrict a,const void * restrict w,void * restrict c,size_t cm_stride,size_t cn_stride,size_t a_offset,const void * zero,const struct xnn_f16_scaleminmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f16_igemm_minmax_ukernel_4x16__neonfp16arith_ld64(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 size_t ks,
23 const void** restrict a,
24 const void* restrict w,
25 void* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 size_t a_offset,
29 const void* zero,
30 const struct xnn_f16_scaleminmax_params params[restrict XNN_MIN_ELEMENTS(1)])
31 {
32 assert(mr != 0);
33 assert(mr <= 4);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(kc % sizeof(__fp16) == 0);
37 assert(ks != 0);
38 assert(ks % (4 * sizeof(void*)) == 0);
39 assert(a_offset % sizeof(__fp16) == 0);
40 assert(a != NULL);
41 assert(w != NULL);
42 assert(c != NULL);
43
44 __fp16* c0 = (__fp16*) c;
45 __fp16* c1 = (__fp16*) ((uintptr_t) c0 + cm_stride);
46 if XNN_UNPREDICTABLE(mr < 2) {
47 c1 = c0;
48 }
49 __fp16* c2 = (__fp16*) ((uintptr_t) c1 + cm_stride);
50 if XNN_UNPREDICTABLE(mr <= 2) {
51 c2 = c1;
52 }
53 __fp16* c3 = (__fp16*) ((uintptr_t) c2 + cm_stride);
54 if XNN_UNPREDICTABLE(mr != 4) {
55 c3 = c2;
56 }
57
58 do {
59 float16x8_t vacc0x01234567 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
60 float16x8_t vacc0x89ABCDEF = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
61 float16x8_t vacc1x01234567 = vacc0x01234567;
62 float16x8_t vacc1x89ABCDEF = vacc0x89ABCDEF;
63 float16x8_t vacc2x01234567 = vacc0x01234567;
64 float16x8_t vacc2x89ABCDEF = vacc0x89ABCDEF;
65 float16x8_t vacc3x01234567 = vacc0x01234567;
66 float16x8_t vacc3x89ABCDEF = vacc0x89ABCDEF;
67
68 size_t p = ks;
69 do {
70 const __fp16* restrict a0 = (const __fp16*) a[0];
71 assert(a0 != NULL);
72 if XNN_UNPREDICTABLE(a0 != zero) {
73 a0 = (const __fp16*) ((uintptr_t) a0 + a_offset);
74 }
75 const __fp16* restrict a1 = (const __fp16*) a[1];
76 assert(a1 != NULL);
77 if XNN_UNPREDICTABLE(a1 != zero) {
78 a1 = (const __fp16*) ((uintptr_t) a1 + a_offset);
79 }
80 const __fp16* restrict a2 = (const __fp16*) a[2];
81 assert(a2 != NULL);
82 if XNN_UNPREDICTABLE(a2 != zero) {
83 a2 = (const __fp16*) ((uintptr_t) a2 + a_offset);
84 }
85 const __fp16* restrict a3 = (const __fp16*) a[3];
86 assert(a3 != NULL);
87 if XNN_UNPREDICTABLE(a3 != zero) {
88 a3 = (const __fp16*) ((uintptr_t) a3 + a_offset);
89 }
90 a += 4;
91
92 size_t k = kc;
93 for (; k >= 4 * sizeof(__fp16); k -= 4 * sizeof(__fp16)) {
94 const float16x4_t va0 = vld1_f16(a0); a0 += 4;
95 const float16x4_t va1 = vld1_f16(a1); a1 += 4;
96 const float16x4_t va2 = vld1_f16(a2); a2 += 4;
97 const float16x4_t va3 = vld1_f16(a3); a3 += 4;
98
99 const float16x8_t vb01234567c0 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof( float16x8_t));
100 const float16x8_t vb89ABCDEFc0 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof( float16x8_t));
101
102 #if XNN_ARCH_ARM64
103 vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c0, va0, 0);
104 vacc1x01234567 = vfmaq_lane_f16(vacc1x01234567, vb01234567c0, va1, 0);
105 vacc2x01234567 = vfmaq_lane_f16(vacc2x01234567, vb01234567c0, va2, 0);
106 vacc3x01234567 = vfmaq_lane_f16(vacc3x01234567, vb01234567c0, va3, 0);
107 vacc0x89ABCDEF = vfmaq_lane_f16(vacc0x89ABCDEF, vb89ABCDEFc0, va0, 0);
108 vacc1x89ABCDEF = vfmaq_lane_f16(vacc1x89ABCDEF, vb89ABCDEFc0, va1, 0);
109 vacc2x89ABCDEF = vfmaq_lane_f16(vacc2x89ABCDEF, vb89ABCDEFc0, va2, 0);
110 vacc3x89ABCDEF = vfmaq_lane_f16(vacc3x89ABCDEF, vb89ABCDEFc0, va3, 0);
111 #else
112 const float16x8_t va0c0 = vdupq_lane_f16(va0, 0);
113 const float16x8_t va1c0 = vdupq_lane_f16(va1, 0);
114 const float16x8_t va2c0 = vdupq_lane_f16(va2, 0);
115 const float16x8_t va3c0 = vdupq_lane_f16(va3, 0);
116
117 vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0c0, vb01234567c0);
118 vacc1x01234567 = vfmaq_f16(vacc1x01234567, va1c0, vb01234567c0);
119 vacc2x01234567 = vfmaq_f16(vacc2x01234567, va2c0, vb01234567c0);
120 vacc3x01234567 = vfmaq_f16(vacc3x01234567, va3c0, vb01234567c0);
121 vacc0x89ABCDEF = vfmaq_f16(vacc0x89ABCDEF, va0c0, vb89ABCDEFc0);
122 vacc1x89ABCDEF = vfmaq_f16(vacc1x89ABCDEF, va1c0, vb89ABCDEFc0);
123 vacc2x89ABCDEF = vfmaq_f16(vacc2x89ABCDEF, va2c0, vb89ABCDEFc0);
124 vacc3x89ABCDEF = vfmaq_f16(vacc3x89ABCDEF, va3c0, vb89ABCDEFc0);
125 #endif
126 const float16x8_t vb01234567c1 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof( float16x8_t));
127 const float16x8_t vb89ABCDEFc1 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof( float16x8_t));
128
129 #if XNN_ARCH_ARM64
130 vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c1, va0, 1);
131 vacc1x01234567 = vfmaq_lane_f16(vacc1x01234567, vb01234567c1, va1, 1);
132 vacc2x01234567 = vfmaq_lane_f16(vacc2x01234567, vb01234567c1, va2, 1);
133 vacc3x01234567 = vfmaq_lane_f16(vacc3x01234567, vb01234567c1, va3, 1);
134 vacc0x89ABCDEF = vfmaq_lane_f16(vacc0x89ABCDEF, vb89ABCDEFc1, va0, 1);
135 vacc1x89ABCDEF = vfmaq_lane_f16(vacc1x89ABCDEF, vb89ABCDEFc1, va1, 1);
136 vacc2x89ABCDEF = vfmaq_lane_f16(vacc2x89ABCDEF, vb89ABCDEFc1, va2, 1);
137 vacc3x89ABCDEF = vfmaq_lane_f16(vacc3x89ABCDEF, vb89ABCDEFc1, va3, 1);
138 #else
139 const float16x8_t va0c1 = vdupq_lane_f16(va0, 1);
140 const float16x8_t va1c1 = vdupq_lane_f16(va1, 1);
141 const float16x8_t va2c1 = vdupq_lane_f16(va2, 1);
142 const float16x8_t va3c1 = vdupq_lane_f16(va3, 1);
143
144 vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0c1, vb01234567c1);
145 vacc1x01234567 = vfmaq_f16(vacc1x01234567, va1c1, vb01234567c1);
146 vacc2x01234567 = vfmaq_f16(vacc2x01234567, va2c1, vb01234567c1);
147 vacc3x01234567 = vfmaq_f16(vacc3x01234567, va3c1, vb01234567c1);
148 vacc0x89ABCDEF = vfmaq_f16(vacc0x89ABCDEF, va0c1, vb89ABCDEFc1);
149 vacc1x89ABCDEF = vfmaq_f16(vacc1x89ABCDEF, va1c1, vb89ABCDEFc1);
150 vacc2x89ABCDEF = vfmaq_f16(vacc2x89ABCDEF, va2c1, vb89ABCDEFc1);
151 vacc3x89ABCDEF = vfmaq_f16(vacc3x89ABCDEF, va3c1, vb89ABCDEFc1);
152 #endif
153 const float16x8_t vb01234567c2 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof( float16x8_t));
154 const float16x8_t vb89ABCDEFc2 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof( float16x8_t));
155
156 #if XNN_ARCH_ARM64
157 vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c2, va0, 2);
158 vacc1x01234567 = vfmaq_lane_f16(vacc1x01234567, vb01234567c2, va1, 2);
159 vacc2x01234567 = vfmaq_lane_f16(vacc2x01234567, vb01234567c2, va2, 2);
160 vacc3x01234567 = vfmaq_lane_f16(vacc3x01234567, vb01234567c2, va3, 2);
161 vacc0x89ABCDEF = vfmaq_lane_f16(vacc0x89ABCDEF, vb89ABCDEFc2, va0, 2);
162 vacc1x89ABCDEF = vfmaq_lane_f16(vacc1x89ABCDEF, vb89ABCDEFc2, va1, 2);
163 vacc2x89ABCDEF = vfmaq_lane_f16(vacc2x89ABCDEF, vb89ABCDEFc2, va2, 2);
164 vacc3x89ABCDEF = vfmaq_lane_f16(vacc3x89ABCDEF, vb89ABCDEFc2, va3, 2);
165 #else
166 const float16x8_t va0c2 = vdupq_lane_f16(va0, 2);
167 const float16x8_t va1c2 = vdupq_lane_f16(va1, 2);
168 const float16x8_t va2c2 = vdupq_lane_f16(va2, 2);
169 const float16x8_t va3c2 = vdupq_lane_f16(va3, 2);
170
171 vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0c2, vb01234567c2);
172 vacc1x01234567 = vfmaq_f16(vacc1x01234567, va1c2, vb01234567c2);
173 vacc2x01234567 = vfmaq_f16(vacc2x01234567, va2c2, vb01234567c2);
174 vacc3x01234567 = vfmaq_f16(vacc3x01234567, va3c2, vb01234567c2);
175 vacc0x89ABCDEF = vfmaq_f16(vacc0x89ABCDEF, va0c2, vb89ABCDEFc2);
176 vacc1x89ABCDEF = vfmaq_f16(vacc1x89ABCDEF, va1c2, vb89ABCDEFc2);
177 vacc2x89ABCDEF = vfmaq_f16(vacc2x89ABCDEF, va2c2, vb89ABCDEFc2);
178 vacc3x89ABCDEF = vfmaq_f16(vacc3x89ABCDEF, va3c2, vb89ABCDEFc2);
179 #endif
180 const float16x8_t vb01234567c3 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof( float16x8_t));
181 const float16x8_t vb89ABCDEFc3 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof( float16x8_t));
182
183 #if XNN_ARCH_ARM64
184 vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c3, va0, 3);
185 vacc1x01234567 = vfmaq_lane_f16(vacc1x01234567, vb01234567c3, va1, 3);
186 vacc2x01234567 = vfmaq_lane_f16(vacc2x01234567, vb01234567c3, va2, 3);
187 vacc3x01234567 = vfmaq_lane_f16(vacc3x01234567, vb01234567c3, va3, 3);
188 vacc0x89ABCDEF = vfmaq_lane_f16(vacc0x89ABCDEF, vb89ABCDEFc3, va0, 3);
189 vacc1x89ABCDEF = vfmaq_lane_f16(vacc1x89ABCDEF, vb89ABCDEFc3, va1, 3);
190 vacc2x89ABCDEF = vfmaq_lane_f16(vacc2x89ABCDEF, vb89ABCDEFc3, va2, 3);
191 vacc3x89ABCDEF = vfmaq_lane_f16(vacc3x89ABCDEF, vb89ABCDEFc3, va3, 3);
192 #else
193 const float16x8_t va0c3 = vdupq_lane_f16(va0, 3);
194 const float16x8_t va1c3 = vdupq_lane_f16(va1, 3);
195 const float16x8_t va2c3 = vdupq_lane_f16(va2, 3);
196 const float16x8_t va3c3 = vdupq_lane_f16(va3, 3);
197
198 vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0c3, vb01234567c3);
199 vacc1x01234567 = vfmaq_f16(vacc1x01234567, va1c3, vb01234567c3);
200 vacc2x01234567 = vfmaq_f16(vacc2x01234567, va2c3, vb01234567c3);
201 vacc3x01234567 = vfmaq_f16(vacc3x01234567, va3c3, vb01234567c3);
202 vacc0x89ABCDEF = vfmaq_f16(vacc0x89ABCDEF, va0c3, vb89ABCDEFc3);
203 vacc1x89ABCDEF = vfmaq_f16(vacc1x89ABCDEF, va1c3, vb89ABCDEFc3);
204 vacc2x89ABCDEF = vfmaq_f16(vacc2x89ABCDEF, va2c3, vb89ABCDEFc3);
205 vacc3x89ABCDEF = vfmaq_f16(vacc3x89ABCDEF, va3c3, vb89ABCDEFc3);
206 #endif
207 }
208 if XNN_UNLIKELY(k != 0) {
209 do {
210 const float16x8_t va0 = vld1q_dup_f16(a0); a0 += 1;
211 const float16x8_t va1 = vld1q_dup_f16(a1); a1 += 1;
212 const float16x8_t va2 = vld1q_dup_f16(a2); a2 += 1;
213 const float16x8_t va3 = vld1q_dup_f16(a3); a3 += 1;
214
215 const float16x8_t vb01234567 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
216 const float16x8_t vb89ABCDEF = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
217
218 vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0, vb01234567);
219 vacc1x01234567 = vfmaq_f16(vacc1x01234567, va1, vb01234567);
220 vacc2x01234567 = vfmaq_f16(vacc2x01234567, va2, vb01234567);
221 vacc3x01234567 = vfmaq_f16(vacc3x01234567, va3, vb01234567);
222 vacc0x89ABCDEF = vfmaq_f16(vacc0x89ABCDEF, va0, vb89ABCDEF);
223 vacc1x89ABCDEF = vfmaq_f16(vacc1x89ABCDEF, va1, vb89ABCDEF);
224 vacc2x89ABCDEF = vfmaq_f16(vacc2x89ABCDEF, va2, vb89ABCDEF);
225 vacc3x89ABCDEF = vfmaq_f16(vacc3x89ABCDEF, va3, vb89ABCDEF);
226
227 k -= sizeof(__fp16);
228 } while (k != 0);
229 }
230 p -= 4 * sizeof(void*);
231 } while (p != 0);
232
233 const float16x8_t vscale = vld1q_dup_f16((const __fp16*) ¶ms->scale);
234 vacc0x01234567 = vmulq_f16(vacc0x01234567, vscale);
235 vacc1x01234567 = vmulq_f16(vacc1x01234567, vscale);
236 vacc2x01234567 = vmulq_f16(vacc2x01234567, vscale);
237 vacc3x01234567 = vmulq_f16(vacc3x01234567, vscale);
238 vacc0x89ABCDEF = vmulq_f16(vacc0x89ABCDEF, vscale);
239 vacc1x89ABCDEF = vmulq_f16(vacc1x89ABCDEF, vscale);
240 vacc2x89ABCDEF = vmulq_f16(vacc2x89ABCDEF, vscale);
241 vacc3x89ABCDEF = vmulq_f16(vacc3x89ABCDEF, vscale);
242
243 const float16x8_t vmax = vld1q_dup_f16((const __fp16*) ¶ms->max);
244 vacc0x01234567 = vminq_f16(vacc0x01234567, vmax);
245 vacc1x01234567 = vminq_f16(vacc1x01234567, vmax);
246 vacc2x01234567 = vminq_f16(vacc2x01234567, vmax);
247 vacc3x01234567 = vminq_f16(vacc3x01234567, vmax);
248 vacc0x89ABCDEF = vminq_f16(vacc0x89ABCDEF, vmax);
249 vacc1x89ABCDEF = vminq_f16(vacc1x89ABCDEF, vmax);
250 vacc2x89ABCDEF = vminq_f16(vacc2x89ABCDEF, vmax);
251 vacc3x89ABCDEF = vminq_f16(vacc3x89ABCDEF, vmax);
252
253 const float16x8_t vmin = vld1q_dup_f16((const __fp16*) ¶ms->min);
254 vacc0x01234567 = vmaxq_f16(vacc0x01234567, vmin);
255 vacc1x01234567 = vmaxq_f16(vacc1x01234567, vmin);
256 vacc2x01234567 = vmaxq_f16(vacc2x01234567, vmin);
257 vacc3x01234567 = vmaxq_f16(vacc3x01234567, vmin);
258 vacc0x89ABCDEF = vmaxq_f16(vacc0x89ABCDEF, vmin);
259 vacc1x89ABCDEF = vmaxq_f16(vacc1x89ABCDEF, vmin);
260 vacc2x89ABCDEF = vmaxq_f16(vacc2x89ABCDEF, vmin);
261 vacc3x89ABCDEF = vmaxq_f16(vacc3x89ABCDEF, vmin);
262
263 if XNN_LIKELY(nc >= 16) {
264 vst1q_f16(c3, vacc3x01234567);
265 vst1q_f16(c3 + 8, vacc3x89ABCDEF);
266 c3 = (__fp16*) ((uintptr_t) c3 + cn_stride);
267 vst1q_f16(c2, vacc2x01234567);
268 vst1q_f16(c2 + 8, vacc2x89ABCDEF);
269 c2 = (__fp16*) ((uintptr_t) c2 + cn_stride);
270 vst1q_f16(c1, vacc1x01234567);
271 vst1q_f16(c1 + 8, vacc1x89ABCDEF);
272 c1 = (__fp16*) ((uintptr_t) c1 + cn_stride);
273 vst1q_f16(c0, vacc0x01234567);
274 vst1q_f16(c0 + 8, vacc0x89ABCDEF);
275 c0 = (__fp16*) ((uintptr_t) c0 + cn_stride);
276
277 a = (const void**restrict) ((uintptr_t) a - ks);
278 nc -= 16;
279 } else {
280 if (nc & 8) {
281 vst1q_f16(c3, vacc3x01234567); c3 += 8;
282 vst1q_f16(c2, vacc2x01234567); c2 += 8;
283 vst1q_f16(c1, vacc1x01234567); c1 += 8;
284 vst1q_f16(c0, vacc0x01234567); c0 += 8;
285
286 vacc3x01234567 = vacc3x89ABCDEF;
287 vacc2x01234567 = vacc2x89ABCDEF;
288 vacc1x01234567 = vacc1x89ABCDEF;
289 vacc0x01234567 = vacc0x89ABCDEF;
290 }
291 float16x4_t vacc3x0123 = vget_low_f16(vacc3x01234567);
292 float16x4_t vacc2x0123 = vget_low_f16(vacc2x01234567);
293 float16x4_t vacc1x0123 = vget_low_f16(vacc1x01234567);
294 float16x4_t vacc0x0123 = vget_low_f16(vacc0x01234567);
295 if (nc & 4) {
296 vst1_f16(c3, vacc3x0123); c3 += 4;
297 vst1_f16(c2, vacc2x0123); c2 += 4;
298 vst1_f16(c1, vacc1x0123); c1 += 4;
299 vst1_f16(c0, vacc0x0123); c0 += 4;
300
301 vacc3x0123 = vget_high_f16(vacc3x01234567);
302 vacc2x0123 = vget_high_f16(vacc2x01234567);
303 vacc1x0123 = vget_high_f16(vacc1x01234567);
304 vacc0x0123 = vget_high_f16(vacc0x01234567);
305 }
306 if (nc & 2) {
307 vst1_lane_u32(__builtin_assume_aligned(c3, 1), vreinterpret_u32_f16(vacc3x0123), 0); c3 += 2;
308 vst1_lane_u32(__builtin_assume_aligned(c2, 1), vreinterpret_u32_f16(vacc2x0123), 0); c2 += 2;
309 vst1_lane_u32(__builtin_assume_aligned(c1, 1), vreinterpret_u32_f16(vacc1x0123), 0); c1 += 2;
310 vst1_lane_u32(__builtin_assume_aligned(c0, 1), vreinterpret_u32_f16(vacc0x0123), 0); c0 += 2;
311
312 vacc3x0123 = vext_f16(vacc3x0123, vacc3x0123, 2);
313 vacc2x0123 = vext_f16(vacc2x0123, vacc2x0123, 2);
314 vacc1x0123 = vext_f16(vacc1x0123, vacc1x0123, 2);
315 vacc0x0123 = vext_f16(vacc0x0123, vacc0x0123, 2);
316 }
317 if (nc & 1) {
318 vst1_lane_f16(c3, vacc3x0123, 0);
319 vst1_lane_f16(c2, vacc2x0123, 0);
320 vst1_lane_f16(c1, vacc1x0123, 0);
321 vst1_lane_f16(c0, vacc0x0123, 0);
322 }
323
324 nc = 0;
325 }
326 } while (nc != 0);
327 }
328