xref: /aosp_15_r20/external/XNNPACK/src/f16-dwconv/gen/up32x9-minmax-neonfp16arith.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/f16-dwconv/up-neonfp16arith.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2020 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 #include <assert.h>
11 
12 #include <arm_neon.h>
13 
14 #include <xnnpack/dwconv.h>
15 
16 
xnn_f16_dwconv_minmax_ukernel_up32x9__neonfp16arith(size_t channels,size_t output_width,const void ** input,const void * weights,void * output_ptr,size_t input_stride,size_t output_increment,size_t input_offset,const void * zero,const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f16_dwconv_minmax_ukernel_up32x9__neonfp16arith(
18     size_t channels,
19     size_t output_width,
20     const void** input,
21     const void* weights,
22     void* output_ptr,
23     size_t input_stride,
24     size_t output_increment,
25     size_t input_offset,
26     const void* zero,
27     const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
28 {
29   assert(channels != 0);
30   assert(output_width != 0);
31 
32   __fp16* output = (__fp16*) output_ptr;
33   const float16x8_t vmax = vreinterpretq_f16_u16(vld1q_dup_u16(&params->neon.max));
34   const float16x8_t vmin = vreinterpretq_f16_u16(vld1q_dup_u16(&params->neon.min));
35   do {
36     const __fp16* i0 = (const __fp16*) input[0];
37     assert(i0 != NULL);
38     if XNN_UNPREDICTABLE(i0 != (const __fp16*) zero) {
39       i0 = (const __fp16*) ((uintptr_t) i0 + input_offset);
40     }
41     const __fp16* i1 = (const __fp16*) input[1];
42     assert(i1 != NULL);
43     if XNN_UNPREDICTABLE(i1 != (const __fp16*) zero) {
44       i1 = (const __fp16*) ((uintptr_t) i1 + input_offset);
45     }
46     const __fp16* i2 = (const __fp16*) input[2];
47     assert(i2 != NULL);
48     if XNN_UNPREDICTABLE(i2 != (const __fp16*) zero) {
49       i2 = (const __fp16*) ((uintptr_t) i2 + input_offset);
50     }
51     const __fp16* i3 = (const __fp16*) input[3];
52     assert(i3 != NULL);
53     if XNN_UNPREDICTABLE(i3 != (const __fp16*) zero) {
54       i3 = (const __fp16*) ((uintptr_t) i3 + input_offset);
55     }
56     const __fp16* i4 = (const __fp16*) input[4];
57     assert(i4 != NULL);
58     if XNN_UNPREDICTABLE(i4 != (const __fp16*) zero) {
59       i4 = (const __fp16*) ((uintptr_t) i4 + input_offset);
60     }
61     const __fp16* i5 = (const __fp16*) input[5];
62     assert(i5 != NULL);
63     if XNN_UNPREDICTABLE(i5 != (const __fp16*) zero) {
64       i5 = (const __fp16*) ((uintptr_t) i5 + input_offset);
65     }
66     const __fp16* i6 = (const __fp16*) input[6];
67     assert(i6 != NULL);
68     if XNN_UNPREDICTABLE(i6 != (const __fp16*) zero) {
69       i6 = (const __fp16*) ((uintptr_t) i6 + input_offset);
70     }
71     const __fp16* i7 = (const __fp16*) input[7];
72     assert(i7 != NULL);
73     if XNN_UNPREDICTABLE(i7 != (const __fp16*) zero) {
74       i7 = (const __fp16*) ((uintptr_t) i7 + input_offset);
75     }
76     const __fp16* i8 = (const __fp16*) input[8];
77     assert(i8 != NULL);
78     if XNN_UNPREDICTABLE(i8 != (const __fp16*) zero) {
79       i8 = (const __fp16*) ((uintptr_t) i8 + input_offset);
80     }
81 
82     input = (const void**) ((uintptr_t) input + input_stride);
83 
84     size_t c = channels;
85     const __fp16* w = (const __fp16*) weights;
86     for (; c >= 32; c -= 32) {
87       float16x8_t vacc01234567p0 = vld1q_f16(w); w += 8;
88       float16x8_t vacc89ABCDEFp0 = vld1q_f16(w); w += 8;
89       float16x8_t vaccGHIJKLMNp0 = vld1q_f16(w); w += 8;
90       float16x8_t vaccOPQRSTUVp0 = vld1q_f16(w); w += 8;
91 
92 
93       const float16x8_t vi0x01234567 = vld1q_f16(i0); i0 += 8;
94       const float16x8_t vi0x89ABCDEF = vld1q_f16(i0); i0 += 8;
95       const float16x8_t vi0xGHIJKLMN = vld1q_f16(i0); i0 += 8;
96       const float16x8_t vi0xOPQRSTUV = vld1q_f16(i0); i0 += 8;
97       const float16x8_t vk0x01234567 = vld1q_f16(w); w += 8;
98       const float16x8_t vk0x89ABCDEF = vld1q_f16(w); w += 8;
99       const float16x8_t vk0xGHIJKLMN = vld1q_f16(w); w += 8;
100       const float16x8_t vk0xOPQRSTUV = vld1q_f16(w); w += 8;
101       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi0x01234567, vk0x01234567);
102       vacc89ABCDEFp0 = vfmaq_f16(vacc89ABCDEFp0, vi0x89ABCDEF, vk0x89ABCDEF);
103       vaccGHIJKLMNp0 = vfmaq_f16(vaccGHIJKLMNp0, vi0xGHIJKLMN, vk0xGHIJKLMN);
104       vaccOPQRSTUVp0 = vfmaq_f16(vaccOPQRSTUVp0, vi0xOPQRSTUV, vk0xOPQRSTUV);
105 
106       const float16x8_t vi1x01234567 = vld1q_f16(i1); i1 += 8;
107       const float16x8_t vi1x89ABCDEF = vld1q_f16(i1); i1 += 8;
108       const float16x8_t vi1xGHIJKLMN = vld1q_f16(i1); i1 += 8;
109       const float16x8_t vi1xOPQRSTUV = vld1q_f16(i1); i1 += 8;
110       const float16x8_t vk1x01234567 = vld1q_f16(w); w += 8;
111       const float16x8_t vk1x89ABCDEF = vld1q_f16(w); w += 8;
112       const float16x8_t vk1xGHIJKLMN = vld1q_f16(w); w += 8;
113       const float16x8_t vk1xOPQRSTUV = vld1q_f16(w); w += 8;
114       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi1x01234567, vk1x01234567);
115       vacc89ABCDEFp0 = vfmaq_f16(vacc89ABCDEFp0, vi1x89ABCDEF, vk1x89ABCDEF);
116       vaccGHIJKLMNp0 = vfmaq_f16(vaccGHIJKLMNp0, vi1xGHIJKLMN, vk1xGHIJKLMN);
117       vaccOPQRSTUVp0 = vfmaq_f16(vaccOPQRSTUVp0, vi1xOPQRSTUV, vk1xOPQRSTUV);
118 
119       const float16x8_t vi2x01234567 = vld1q_f16(i2); i2 += 8;
120       const float16x8_t vi2x89ABCDEF = vld1q_f16(i2); i2 += 8;
121       const float16x8_t vi2xGHIJKLMN = vld1q_f16(i2); i2 += 8;
122       const float16x8_t vi2xOPQRSTUV = vld1q_f16(i2); i2 += 8;
123       const float16x8_t vk2x01234567 = vld1q_f16(w); w += 8;
124       const float16x8_t vk2x89ABCDEF = vld1q_f16(w); w += 8;
125       const float16x8_t vk2xGHIJKLMN = vld1q_f16(w); w += 8;
126       const float16x8_t vk2xOPQRSTUV = vld1q_f16(w); w += 8;
127       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi2x01234567, vk2x01234567);
128       vacc89ABCDEFp0 = vfmaq_f16(vacc89ABCDEFp0, vi2x89ABCDEF, vk2x89ABCDEF);
129       vaccGHIJKLMNp0 = vfmaq_f16(vaccGHIJKLMNp0, vi2xGHIJKLMN, vk2xGHIJKLMN);
130       vaccOPQRSTUVp0 = vfmaq_f16(vaccOPQRSTUVp0, vi2xOPQRSTUV, vk2xOPQRSTUV);
131 
132       const float16x8_t vi3x01234567 = vld1q_f16(i3); i3 += 8;
133       const float16x8_t vi3x89ABCDEF = vld1q_f16(i3); i3 += 8;
134       const float16x8_t vi3xGHIJKLMN = vld1q_f16(i3); i3 += 8;
135       const float16x8_t vi3xOPQRSTUV = vld1q_f16(i3); i3 += 8;
136       const float16x8_t vk3x01234567 = vld1q_f16(w); w += 8;
137       const float16x8_t vk3x89ABCDEF = vld1q_f16(w); w += 8;
138       const float16x8_t vk3xGHIJKLMN = vld1q_f16(w); w += 8;
139       const float16x8_t vk3xOPQRSTUV = vld1q_f16(w); w += 8;
140       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi3x01234567, vk3x01234567);
141       vacc89ABCDEFp0 = vfmaq_f16(vacc89ABCDEFp0, vi3x89ABCDEF, vk3x89ABCDEF);
142       vaccGHIJKLMNp0 = vfmaq_f16(vaccGHIJKLMNp0, vi3xGHIJKLMN, vk3xGHIJKLMN);
143       vaccOPQRSTUVp0 = vfmaq_f16(vaccOPQRSTUVp0, vi3xOPQRSTUV, vk3xOPQRSTUV);
144 
145       const float16x8_t vi4x01234567 = vld1q_f16(i4); i4 += 8;
146       const float16x8_t vi4x89ABCDEF = vld1q_f16(i4); i4 += 8;
147       const float16x8_t vi4xGHIJKLMN = vld1q_f16(i4); i4 += 8;
148       const float16x8_t vi4xOPQRSTUV = vld1q_f16(i4); i4 += 8;
149       const float16x8_t vk4x01234567 = vld1q_f16(w); w += 8;
150       const float16x8_t vk4x89ABCDEF = vld1q_f16(w); w += 8;
151       const float16x8_t vk4xGHIJKLMN = vld1q_f16(w); w += 8;
152       const float16x8_t vk4xOPQRSTUV = vld1q_f16(w); w += 8;
153       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi4x01234567, vk4x01234567);
154       vacc89ABCDEFp0 = vfmaq_f16(vacc89ABCDEFp0, vi4x89ABCDEF, vk4x89ABCDEF);
155       vaccGHIJKLMNp0 = vfmaq_f16(vaccGHIJKLMNp0, vi4xGHIJKLMN, vk4xGHIJKLMN);
156       vaccOPQRSTUVp0 = vfmaq_f16(vaccOPQRSTUVp0, vi4xOPQRSTUV, vk4xOPQRSTUV);
157 
158       const float16x8_t vi5x01234567 = vld1q_f16(i5); i5 += 8;
159       const float16x8_t vi5x89ABCDEF = vld1q_f16(i5); i5 += 8;
160       const float16x8_t vi5xGHIJKLMN = vld1q_f16(i5); i5 += 8;
161       const float16x8_t vi5xOPQRSTUV = vld1q_f16(i5); i5 += 8;
162       const float16x8_t vk5x01234567 = vld1q_f16(w); w += 8;
163       const float16x8_t vk5x89ABCDEF = vld1q_f16(w); w += 8;
164       const float16x8_t vk5xGHIJKLMN = vld1q_f16(w); w += 8;
165       const float16x8_t vk5xOPQRSTUV = vld1q_f16(w); w += 8;
166       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi5x01234567, vk5x01234567);
167       vacc89ABCDEFp0 = vfmaq_f16(vacc89ABCDEFp0, vi5x89ABCDEF, vk5x89ABCDEF);
168       vaccGHIJKLMNp0 = vfmaq_f16(vaccGHIJKLMNp0, vi5xGHIJKLMN, vk5xGHIJKLMN);
169       vaccOPQRSTUVp0 = vfmaq_f16(vaccOPQRSTUVp0, vi5xOPQRSTUV, vk5xOPQRSTUV);
170 
171       const float16x8_t vi6x01234567 = vld1q_f16(i6); i6 += 8;
172       const float16x8_t vi6x89ABCDEF = vld1q_f16(i6); i6 += 8;
173       const float16x8_t vi6xGHIJKLMN = vld1q_f16(i6); i6 += 8;
174       const float16x8_t vi6xOPQRSTUV = vld1q_f16(i6); i6 += 8;
175       const float16x8_t vk6x01234567 = vld1q_f16(w); w += 8;
176       const float16x8_t vk6x89ABCDEF = vld1q_f16(w); w += 8;
177       const float16x8_t vk6xGHIJKLMN = vld1q_f16(w); w += 8;
178       const float16x8_t vk6xOPQRSTUV = vld1q_f16(w); w += 8;
179       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi6x01234567, vk6x01234567);
180       vacc89ABCDEFp0 = vfmaq_f16(vacc89ABCDEFp0, vi6x89ABCDEF, vk6x89ABCDEF);
181       vaccGHIJKLMNp0 = vfmaq_f16(vaccGHIJKLMNp0, vi6xGHIJKLMN, vk6xGHIJKLMN);
182       vaccOPQRSTUVp0 = vfmaq_f16(vaccOPQRSTUVp0, vi6xOPQRSTUV, vk6xOPQRSTUV);
183 
184       const float16x8_t vi7x01234567 = vld1q_f16(i7); i7 += 8;
185       const float16x8_t vi7x89ABCDEF = vld1q_f16(i7); i7 += 8;
186       const float16x8_t vi7xGHIJKLMN = vld1q_f16(i7); i7 += 8;
187       const float16x8_t vi7xOPQRSTUV = vld1q_f16(i7); i7 += 8;
188       const float16x8_t vk7x01234567 = vld1q_f16(w); w += 8;
189       const float16x8_t vk7x89ABCDEF = vld1q_f16(w); w += 8;
190       const float16x8_t vk7xGHIJKLMN = vld1q_f16(w); w += 8;
191       const float16x8_t vk7xOPQRSTUV = vld1q_f16(w); w += 8;
192       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi7x01234567, vk7x01234567);
193       vacc89ABCDEFp0 = vfmaq_f16(vacc89ABCDEFp0, vi7x89ABCDEF, vk7x89ABCDEF);
194       vaccGHIJKLMNp0 = vfmaq_f16(vaccGHIJKLMNp0, vi7xGHIJKLMN, vk7xGHIJKLMN);
195       vaccOPQRSTUVp0 = vfmaq_f16(vaccOPQRSTUVp0, vi7xOPQRSTUV, vk7xOPQRSTUV);
196 
197       const float16x8_t vi8x01234567 = vld1q_f16(i8); i8 += 8;
198       const float16x8_t vi8x89ABCDEF = vld1q_f16(i8); i8 += 8;
199       const float16x8_t vi8xGHIJKLMN = vld1q_f16(i8); i8 += 8;
200       const float16x8_t vi8xOPQRSTUV = vld1q_f16(i8); i8 += 8;
201       const float16x8_t vk8x01234567 = vld1q_f16(w); w += 8;
202       const float16x8_t vk8x89ABCDEF = vld1q_f16(w); w += 8;
203       const float16x8_t vk8xGHIJKLMN = vld1q_f16(w); w += 8;
204       const float16x8_t vk8xOPQRSTUV = vld1q_f16(w); w += 8;
205       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi8x01234567, vk8x01234567);
206       vacc89ABCDEFp0 = vfmaq_f16(vacc89ABCDEFp0, vi8x89ABCDEF, vk8x89ABCDEF);
207       vaccGHIJKLMNp0 = vfmaq_f16(vaccGHIJKLMNp0, vi8xGHIJKLMN, vk8xGHIJKLMN);
208       vaccOPQRSTUVp0 = vfmaq_f16(vaccOPQRSTUVp0, vi8xOPQRSTUV, vk8xOPQRSTUV);
209 
210 
211       float16x8_t vacc01234567 = vmaxq_f16(vacc01234567p0, vmin);
212       float16x8_t vacc89ABCDEF = vmaxq_f16(vacc89ABCDEFp0, vmin);
213       float16x8_t vaccGHIJKLMN = vmaxq_f16(vaccGHIJKLMNp0, vmin);
214       float16x8_t vaccOPQRSTUV = vmaxq_f16(vaccOPQRSTUVp0, vmin);
215       vacc01234567 = vminq_f16(vacc01234567, vmax);
216       vacc89ABCDEF = vminq_f16(vacc89ABCDEF, vmax);
217       vaccGHIJKLMN = vminq_f16(vaccGHIJKLMN, vmax);
218       vaccOPQRSTUV = vminq_f16(vaccOPQRSTUV, vmax);
219 
220       vst1q_f16(output, vacc01234567); output += 8;
221       vst1q_f16(output, vacc89ABCDEF); output += 8;
222       vst1q_f16(output, vaccGHIJKLMN); output += 8;
223       vst1q_f16(output, vaccOPQRSTUV); output += 8;
224     }
225     for (; c >= 8; c -= 8) {
226       float16x8_t vacc01234567p0 = vld1q_f16(w); w += 8;
227 
228 
229       const float16x8_t vi0x01234567 = vld1q_f16(i0); i0 += 8;
230       const float16x8_t vk0x01234567 = vld1q_f16(w + 24);
231       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi0x01234567, vk0x01234567);
232 
233       const float16x8_t vi1x01234567 = vld1q_f16(i1); i1 += 8;
234       const float16x8_t vk1x01234567 = vld1q_f16(w + 56);
235       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi1x01234567, vk1x01234567);
236 
237       const float16x8_t vi2x01234567 = vld1q_f16(i2); i2 += 8;
238       const float16x8_t vk2x01234567 = vld1q_f16(w + 88);
239       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi2x01234567, vk2x01234567);
240 
241       const float16x8_t vi3x01234567 = vld1q_f16(i3); i3 += 8;
242       const float16x8_t vk3x01234567 = vld1q_f16(w + 120);
243       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi3x01234567, vk3x01234567);
244 
245       const float16x8_t vi4x01234567 = vld1q_f16(i4); i4 += 8;
246       const float16x8_t vk4x01234567 = vld1q_f16(w + 152);
247       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi4x01234567, vk4x01234567);
248 
249       const float16x8_t vi5x01234567 = vld1q_f16(i5); i5 += 8;
250       const float16x8_t vk5x01234567 = vld1q_f16(w + 184);
251       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi5x01234567, vk5x01234567);
252 
253       const float16x8_t vi6x01234567 = vld1q_f16(i6); i6 += 8;
254       const float16x8_t vk6x01234567 = vld1q_f16(w + 216);
255       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi6x01234567, vk6x01234567);
256 
257       const float16x8_t vi7x01234567 = vld1q_f16(i7); i7 += 8;
258       const float16x8_t vk7x01234567 = vld1q_f16(w + 248);
259       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi7x01234567, vk7x01234567);
260 
261       const float16x8_t vi8x01234567 = vld1q_f16(i8); i8 += 8;
262       const float16x8_t vk8x01234567 = vld1q_f16(w + 280);
263       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi8x01234567, vk8x01234567);
264 
265 
266       float16x8_t vacc01234567 = vmaxq_f16(vacc01234567p0, vmin);
267       vacc01234567 = vminq_f16(vacc01234567, vmax);
268 
269       vst1q_f16(output, vacc01234567); output += 8;
270     }
271     if XNN_UNLIKELY(c != 0) {
272       float16x8_t vacc01234567p0 = vld1q_f16(w);
273 
274 
275       const float16x8_t vi0x01234567 = vld1q_f16(i0);
276       const float16x8_t vk0x01234567 = vld1q_f16(w + 32);
277       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi0x01234567, vk0x01234567);
278 
279       const float16x8_t vi1x01234567 = vld1q_f16(i1);
280       const float16x8_t vk1x01234567 = vld1q_f16(w + 64);
281       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi1x01234567, vk1x01234567);
282 
283       const float16x8_t vi2x01234567 = vld1q_f16(i2);
284       const float16x8_t vk2x01234567 = vld1q_f16(w + 96);
285       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi2x01234567, vk2x01234567);
286 
287       const float16x8_t vi3x01234567 = vld1q_f16(i3);
288       const float16x8_t vk3x01234567 = vld1q_f16(w + 128);
289       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi3x01234567, vk3x01234567);
290 
291       const float16x8_t vi4x01234567 = vld1q_f16(i4);
292       const float16x8_t vk4x01234567 = vld1q_f16(w + 160);
293       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi4x01234567, vk4x01234567);
294 
295       const float16x8_t vi5x01234567 = vld1q_f16(i5);
296       const float16x8_t vk5x01234567 = vld1q_f16(w + 192);
297       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi5x01234567, vk5x01234567);
298 
299       const float16x8_t vi6x01234567 = vld1q_f16(i6);
300       const float16x8_t vk6x01234567 = vld1q_f16(w + 224);
301       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi6x01234567, vk6x01234567);
302 
303       const float16x8_t vi7x01234567 = vld1q_f16(i7);
304       const float16x8_t vk7x01234567 = vld1q_f16(w + 256);
305       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi7x01234567, vk7x01234567);
306 
307       const float16x8_t vi8x01234567 = vld1q_f16(i8);
308       const float16x8_t vk8x01234567 = vld1q_f16(w + 288);
309       vacc01234567p0 = vfmaq_f16(vacc01234567p0, vi8x01234567, vk8x01234567);
310 
311 
312       float16x8_t vacc01234567 = vmaxq_f16(vacc01234567p0, vmin);
313       vacc01234567 = vminq_f16(vacc01234567, vmax);
314 
315       float16x4_t vacc0123 = vget_low_f16(vacc01234567);
316       if (c & 4) {
317         vst1_f16(output, vacc0123); output += 4;
318         vacc0123 = vget_high_f16(vacc01234567);
319       }
320       if (c & 2) {
321         vst1_lane_u32((void*) output, vreinterpret_u32_f16(vacc0123), 0); output += 2;
322         vacc0123 = vext_f16(vacc0123, vacc0123, 2);
323       }
324       if (c & 1) {
325         vst1_lane_f16(output, vacc0123, 0); output += 1;
326       }
327     }
328 
329     output = (__fp16*) ((uintptr_t) output + output_increment);
330   } while (--output_width != 0);
331 }
332