Debian Codegraph @

src/f16-igemm/gen/f16-igemm-4x8-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_4x8__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 <= 4);
35 assert(nc != 0);
36 assert(kc != 0);
37 assert(kc % sizeof(uint16_t) == 0);
38 assert(ks != 0);
39 assert(ks % (4 * 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
59 do {
60 float16x8_t vacc0x0 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
61 float16x8_t vacc1x0 = vacc0x0;
62 float16x8_t vacc2x0 = vacc0x0;
63 float16x8_t vacc3x0 = vacc0x0;
64
65 size_t p = ks;
66 do {
67 const uint16_t* restrict a0 = (const uint16_t*) a[0];
68 assert(a0 != NULL);
69 if XNN_UNPREDICTABLE(a0 != (const uint16_t*) zero) {
70 a0 = (const uint16_t*) ((uintptr_t) a0 + a_offset);
71 }
72 const uint16_t* restrict a1 = (const uint16_t*) a[1];
73 assert(a1 != NULL);
74 if XNN_UNPREDICTABLE(a1 != (const uint16_t*) zero) {
75 a1 = (const uint16_t*) ((uintptr_t) a1 + a_offset);
76 }
77 const uint16_t* restrict a2 = (const uint16_t*) a[2];
78 assert(a2 != NULL);
79 if XNN_UNPREDICTABLE(a2 != (const uint16_t*) zero) {
80 a2 = (const uint16_t*) ((uintptr_t) a2 + a_offset);
81 }
82 const uint16_t* restrict a3 = (const uint16_t*) a[3];
83 assert(a3 != NULL);
84 if XNN_UNPREDICTABLE(a3 != (const uint16_t*) zero) {
85 a3 = (const uint16_t*) ((uintptr_t) a3 + a_offset);
86 }
87 a += 4;
88
89 size_t k = kc;
90 for (; k >= 4 * sizeof(uint16_t); k -= 4 * sizeof(uint16_t)) {
91 const float16x4_t va0 = vreinterpret_f16_u16(vld1_u16(a0)); a0 += 4;
92 const float16x4_t va1 = vreinterpret_f16_u16(vld1_u16(a1)); a1 += 4;
93 const float16x4_t va2 = vreinterpret_f16_u16(vld1_u16(a2)); a2 += 4;
94 const float16x4_t va3 = vreinterpret_f16_u16(vld1_u16(a3)); a3 += 4;
95
96 const float16x8_t vb0c0 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
97
98 #if XNN_ARCH_ARM64
99 vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c0, va0, 0);
100 vacc1x0 = vfmaq_lane_f16(vacc1x0, vb0c0, va1, 0);
101 vacc2x0 = vfmaq_lane_f16(vacc2x0, vb0c0, va2, 0);
102 vacc3x0 = vfmaq_lane_f16(vacc3x0, vb0c0, va3, 0);
103 #else
104 vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c0, va0, 0);
105 vacc1x0 = vmlaq_lane_f16(vacc1x0, vb0c0, va1, 0);
106 vacc2x0 = vmlaq_lane_f16(vacc2x0, vb0c0, va2, 0);
107 vacc3x0 = vmlaq_lane_f16(vacc3x0, vb0c0, va3, 0);
108 #endif
109 const float16x8_t vb0c1 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
110
111 #if XNN_ARCH_ARM64
112 vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c1, va0, 1);
113 vacc1x0 = vfmaq_lane_f16(vacc1x0, vb0c1, va1, 1);
114 vacc2x0 = vfmaq_lane_f16(vacc2x0, vb0c1, va2, 1);
115 vacc3x0 = vfmaq_lane_f16(vacc3x0, vb0c1, va3, 1);
116 #else
117 vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c1, va0, 1);
118 vacc1x0 = vmlaq_lane_f16(vacc1x0, vb0c1, va1, 1);
119 vacc2x0 = vmlaq_lane_f16(vacc2x0, vb0c1, va2, 1);
120 vacc3x0 = vmlaq_lane_f16(vacc3x0, vb0c1, va3, 1);
121 #endif
122 const float16x8_t vb0c2 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
123
124 #if XNN_ARCH_ARM64
125 vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c2, va0, 2);
126 vacc1x0 = vfmaq_lane_f16(vacc1x0, vb0c2, va1, 2);
127 vacc2x0 = vfmaq_lane_f16(vacc2x0, vb0c2, va2, 2);
128 vacc3x0 = vfmaq_lane_f16(vacc3x0, vb0c2, va3, 2);
129 #else
130 vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c2, va0, 2);
131 vacc1x0 = vmlaq_lane_f16(vacc1x0, vb0c2, va1, 2);
132 vacc2x0 = vmlaq_lane_f16(vacc2x0, vb0c2, va2, 2);
133 vacc3x0 = vmlaq_lane_f16(vacc3x0, vb0c2, va3, 2);
134 #endif
135 const float16x8_t vb0c3 = 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, vb0c3, va0, 3);
139 vacc1x0 = vfmaq_lane_f16(vacc1x0, vb0c3, va1, 3);
140 vacc2x0 = vfmaq_lane_f16(vacc2x0, vb0c3, va2, 3);
141 vacc3x0 = vfmaq_lane_f16(vacc3x0, vb0c3, va3, 3);
142 #else
143 vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c3, va0, 3);
144 vacc1x0 = vmlaq_lane_f16(vacc1x0, vb0c3, va1, 3);
145 vacc2x0 = vmlaq_lane_f16(vacc2x0, vb0c3, va2, 3);
146 vacc3x0 = vmlaq_lane_f16(vacc3x0, vb0c3, va3, 3);
147 #endif
148 }
149 if XNN_UNLIKELY(k != 0) {
150 do {
151 const float16x8_t va0 = vreinterpretq_f16_u16(vld1q_dup_u16(a0)); a0 += 1;
152 const float16x8_t va1 = vreinterpretq_f16_u16(vld1q_dup_u16(a1)); a1 += 1;
153 const float16x8_t va2 = vreinterpretq_f16_u16(vld1q_dup_u16(a2)); a2 += 1;
154 const float16x8_t va3 = vreinterpretq_f16_u16(vld1q_dup_u16(a3)); a3 += 1;
155
156 const float16x8_t vb0 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8;
157
158 vacc0x0 = vfmaq_f16(vacc0x0, va0, vb0);
159 vacc1x0 = vfmaq_f16(vacc1x0, va1, vb0);
160 vacc2x0 = vfmaq_f16(vacc2x0, va2, vb0);
161 vacc3x0 = vfmaq_f16(vacc3x0, va3, vb0);
162
163 k -= sizeof(uint16_t);
164 } while (k != 0);
165 }
166 p -= 4 * sizeof(void*);
167 } while (p != 0);
168
169
170 const float16x8_t vmin = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.min));
171 vacc0x0 = vmaxq_f16(vacc0x0, vmin);
172 vacc1x0 = vmaxq_f16(vacc1x0, vmin);
173 vacc2x0 = vmaxq_f16(vacc2x0, vmin);
174 vacc3x0 = vmaxq_f16(vacc3x0, vmin);
175
176 const float16x8_t vmax = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.max));
177 vacc0x0 = vminq_f16(vacc0x0, vmax);
178 vacc1x0 = vminq_f16(vacc1x0, vmax);
179 vacc2x0 = vminq_f16(vacc2x0, vmax);
180 vacc3x0 = vminq_f16(vacc3x0, vmax);
181
182 if XNN_LIKELY(nc >= 8) {
183 vst1q_u16(c3, vreinterpretq_u16_f16(vacc3x0));
184 c3 = (uint16_t*) ((uintptr_t) c3 + cn_stride);
185 vst1q_u16(c2, vreinterpretq_u16_f16(vacc2x0));
186 c2 = (uint16_t*) ((uintptr_t) c2 + cn_stride);
187 vst1q_u16(c1, vreinterpretq_u16_f16(vacc1x0));
188 c1 = (uint16_t*) ((uintptr_t) c1 + cn_stride);
189 vst1q_u16(c0, vreinterpretq_u16_f16(vacc0x0));
190 c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride);
191
192 a = (const xnn_float16**restrict) ((uintptr_t) a - ks);
193 nc -= 8;
194 } else {
195 float16x4_t vacc3 = vget_low_f16(vacc3x0);
196 float16x4_t vacc2 = vget_low_f16(vacc2x0);
197 float16x4_t vacc1 = vget_low_f16(vacc1x0);
198 float16x4_t vacc0 = vget_low_f16(vacc0x0);
199 if (nc & 4) {
200 vst1_u16(c3, vreinterpret_u16_f16(vacc3)); c3 += 4;
201 vst1_u16(c2, vreinterpret_u16_f16(vacc2)); c2 += 4;
202 vst1_u16(c1, vreinterpret_u16_f16(vacc1)); c1 += 4;
203 vst1_u16(c0, vreinterpret_u16_f16(vacc0)); c0 += 4;
204
205 vacc3 = vget_high_f16(vacc3x0);
206 vacc2 = vget_high_f16(vacc2x0);
207 vacc1 = vget_high_f16(vacc1x0);
208 vacc0 = vget_high_f16(vacc0x0);
209 }
210 if (nc & 2) {
211 vst1_lane_u32((void*) c3, vreinterpret_u32_f16(vacc3), 0); c3 += 2;
212 vst1_lane_u32((void*) c2, vreinterpret_u32_f16(vacc2), 0); c2 += 2;
213 vst1_lane_u32((void*) c1, vreinterpret_u32_f16(vacc1), 0); c1 += 2;
214 vst1_lane_u32((void*) c0, vreinterpret_u32_f16(vacc0), 0); c0 += 2;
215
216 vacc3 = vext_f16(vacc3, vacc3, 2);
217 vacc2 = vext_f16(vacc2, vacc2, 2);
218 vacc1 = vext_f16(vacc1, vacc1, 2);
219 vacc0 = vext_f16(vacc0, vacc0, 2);
220 }
221 if (nc & 1) {
222 vst1_lane_u16(c3, vreinterpret_u16_f16(vacc3), 0);
223 vst1_lane_u16(c2, vreinterpret_u16_f16(vacc2), 0);
224 vst1_lane_u16(c1, vreinterpret_u16_f16(vacc1), 0);
225 vst1_lane_u16(c0, vreinterpret_u16_f16(vacc0), 0);
226 }
227
228 nc = 0;
229 }
230 } while (nc != 0);
231 }