1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-dwconv/up-avx512.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 #include <assert.h>
11 
12 #include <immintrin.h>
13 
14 #include <xnnpack/dwconv.h>
15 #include <xnnpack/intrinsics-polyfill.h>
16 
17 
xnn_f32_dwconv_minmax_ukernel_up32x9__avx512f(size_t channels,size_t output_width,const float ** input,const float * weights,float * output,size_t input_stride,size_t output_increment,size_t input_offset,const float * zero,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_dwconv_minmax_ukernel_up32x9__avx512f(
19     size_t channels,
20     size_t output_width,
21     const float** input,
22     const float* weights,
23     float* output,
24     size_t input_stride,
25     size_t output_increment,
26     size_t input_offset,
27     const float* zero,
28     const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30   assert(channels != 0);
31   assert(output_width != 0);
32 
33   const __m512 vmax = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.max));
34   const __m512 vmin = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.min));
35   do {
36     const float* i0 = input[0];
37     assert(i0 != NULL);
38     if XNN_UNPREDICTABLE(i0 != zero) {
39       i0 = (const float*) ((uintptr_t) i0 + input_offset);
40     }
41     const float* i1 = input[1];
42     assert(i1 != NULL);
43     if XNN_UNPREDICTABLE(i1 != zero) {
44       i1 = (const float*) ((uintptr_t) i1 + input_offset);
45     }
46     const float* i2 = input[2];
47     assert(i2 != NULL);
48     if XNN_UNPREDICTABLE(i2 != zero) {
49       i2 = (const float*) ((uintptr_t) i2 + input_offset);
50     }
51     const float* i3 = input[3];
52     assert(i3 != NULL);
53     if XNN_UNPREDICTABLE(i3 != zero) {
54       i3 = (const float*) ((uintptr_t) i3 + input_offset);
55     }
56     const float* i4 = input[4];
57     assert(i4 != NULL);
58     if XNN_UNPREDICTABLE(i4 != zero) {
59       i4 = (const float*) ((uintptr_t) i4 + input_offset);
60     }
61     const float* i5 = input[5];
62     assert(i5 != NULL);
63     if XNN_UNPREDICTABLE(i5 != zero) {
64       i5 = (const float*) ((uintptr_t) i5 + input_offset);
65     }
66     const float* i6 = input[6];
67     assert(i6 != NULL);
68     if XNN_UNPREDICTABLE(i6 != zero) {
69       i6 = (const float*) ((uintptr_t) i6 + input_offset);
70     }
71     const float* i7 = input[7];
72     assert(i7 != NULL);
73     if XNN_UNPREDICTABLE(i7 != zero) {
74       i7 = (const float*) ((uintptr_t) i7 + input_offset);
75     }
76     const float* i8 = input[8];
77     assert(i8 != NULL);
78     if XNN_UNPREDICTABLE(i8 != zero) {
79       i8 = (const float*) ((uintptr_t) i8 + input_offset);
80     }
81     input = (const float**) ((uintptr_t) input + input_stride);
82 
83     size_t c = channels;
84     const float* w = weights;
85     for (; c >= 32; c -= 32) {
86       __m512 vacc0123456789ABCDEFp0 = _mm512_load_ps(w);
87       __m512 vaccGHIJKLMNOPQRSTUVp0 = _mm512_load_ps(w + 16);
88 
89 
90       const __m512 vi0x0123456789ABCDEF = _mm512_loadu_ps(i0);
91       const __m512 vi0xGHIJKLMNOPQRSTUV = _mm512_loadu_ps(i0 + 16);
92       i0 += 32;
93 
94       const __m512 vk0x0123456789ABCDEF = _mm512_load_ps(w + 32);
95       const __m512 vk0xGHIJKLMNOPQRSTUV = _mm512_load_ps(w + 48);
96       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi0x0123456789ABCDEF, vk0x0123456789ABCDEF, vacc0123456789ABCDEFp0);
97       vaccGHIJKLMNOPQRSTUVp0 = _mm512_fmadd_ps(vi0xGHIJKLMNOPQRSTUV, vk0xGHIJKLMNOPQRSTUV, vaccGHIJKLMNOPQRSTUVp0);
98 
99       const __m512 vi1x0123456789ABCDEF = _mm512_loadu_ps(i1);
100       const __m512 vi1xGHIJKLMNOPQRSTUV = _mm512_loadu_ps(i1 + 16);
101       i1 += 32;
102 
103       const __m512 vk1x0123456789ABCDEF = _mm512_load_ps(w + 64);
104       const __m512 vk1xGHIJKLMNOPQRSTUV = _mm512_load_ps(w + 80);
105       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi1x0123456789ABCDEF, vk1x0123456789ABCDEF, vacc0123456789ABCDEFp0);
106       vaccGHIJKLMNOPQRSTUVp0 = _mm512_fmadd_ps(vi1xGHIJKLMNOPQRSTUV, vk1xGHIJKLMNOPQRSTUV, vaccGHIJKLMNOPQRSTUVp0);
107 
108       const __m512 vi2x0123456789ABCDEF = _mm512_loadu_ps(i2);
109       const __m512 vi2xGHIJKLMNOPQRSTUV = _mm512_loadu_ps(i2 + 16);
110       i2 += 32;
111 
112       const __m512 vk2x0123456789ABCDEF = _mm512_load_ps(w + 96);
113       const __m512 vk2xGHIJKLMNOPQRSTUV = _mm512_load_ps(w + 112);
114       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi2x0123456789ABCDEF, vk2x0123456789ABCDEF, vacc0123456789ABCDEFp0);
115       vaccGHIJKLMNOPQRSTUVp0 = _mm512_fmadd_ps(vi2xGHIJKLMNOPQRSTUV, vk2xGHIJKLMNOPQRSTUV, vaccGHIJKLMNOPQRSTUVp0);
116 
117       const __m512 vi3x0123456789ABCDEF = _mm512_loadu_ps(i3);
118       const __m512 vi3xGHIJKLMNOPQRSTUV = _mm512_loadu_ps(i3 + 16);
119       i3 += 32;
120 
121       const __m512 vk3x0123456789ABCDEF = _mm512_load_ps(w + 128);
122       const __m512 vk3xGHIJKLMNOPQRSTUV = _mm512_load_ps(w + 144);
123       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi3x0123456789ABCDEF, vk3x0123456789ABCDEF, vacc0123456789ABCDEFp0);
124       vaccGHIJKLMNOPQRSTUVp0 = _mm512_fmadd_ps(vi3xGHIJKLMNOPQRSTUV, vk3xGHIJKLMNOPQRSTUV, vaccGHIJKLMNOPQRSTUVp0);
125 
126       const __m512 vi4x0123456789ABCDEF = _mm512_loadu_ps(i4);
127       const __m512 vi4xGHIJKLMNOPQRSTUV = _mm512_loadu_ps(i4 + 16);
128       i4 += 32;
129 
130       const __m512 vk4x0123456789ABCDEF = _mm512_load_ps(w + 160);
131       const __m512 vk4xGHIJKLMNOPQRSTUV = _mm512_load_ps(w + 176);
132       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi4x0123456789ABCDEF, vk4x0123456789ABCDEF, vacc0123456789ABCDEFp0);
133       vaccGHIJKLMNOPQRSTUVp0 = _mm512_fmadd_ps(vi4xGHIJKLMNOPQRSTUV, vk4xGHIJKLMNOPQRSTUV, vaccGHIJKLMNOPQRSTUVp0);
134 
135       const __m512 vi5x0123456789ABCDEF = _mm512_loadu_ps(i5);
136       const __m512 vi5xGHIJKLMNOPQRSTUV = _mm512_loadu_ps(i5 + 16);
137       i5 += 32;
138 
139       const __m512 vk5x0123456789ABCDEF = _mm512_load_ps(w + 192);
140       const __m512 vk5xGHIJKLMNOPQRSTUV = _mm512_load_ps(w + 208);
141       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi5x0123456789ABCDEF, vk5x0123456789ABCDEF, vacc0123456789ABCDEFp0);
142       vaccGHIJKLMNOPQRSTUVp0 = _mm512_fmadd_ps(vi5xGHIJKLMNOPQRSTUV, vk5xGHIJKLMNOPQRSTUV, vaccGHIJKLMNOPQRSTUVp0);
143 
144       const __m512 vi6x0123456789ABCDEF = _mm512_loadu_ps(i6);
145       const __m512 vi6xGHIJKLMNOPQRSTUV = _mm512_loadu_ps(i6 + 16);
146       i6 += 32;
147 
148       const __m512 vk6x0123456789ABCDEF = _mm512_load_ps(w + 224);
149       const __m512 vk6xGHIJKLMNOPQRSTUV = _mm512_load_ps(w + 240);
150       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi6x0123456789ABCDEF, vk6x0123456789ABCDEF, vacc0123456789ABCDEFp0);
151       vaccGHIJKLMNOPQRSTUVp0 = _mm512_fmadd_ps(vi6xGHIJKLMNOPQRSTUV, vk6xGHIJKLMNOPQRSTUV, vaccGHIJKLMNOPQRSTUVp0);
152 
153       const __m512 vi7x0123456789ABCDEF = _mm512_loadu_ps(i7);
154       const __m512 vi7xGHIJKLMNOPQRSTUV = _mm512_loadu_ps(i7 + 16);
155       i7 += 32;
156 
157       const __m512 vk7x0123456789ABCDEF = _mm512_load_ps(w + 256);
158       const __m512 vk7xGHIJKLMNOPQRSTUV = _mm512_load_ps(w + 272);
159       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi7x0123456789ABCDEF, vk7x0123456789ABCDEF, vacc0123456789ABCDEFp0);
160       vaccGHIJKLMNOPQRSTUVp0 = _mm512_fmadd_ps(vi7xGHIJKLMNOPQRSTUV, vk7xGHIJKLMNOPQRSTUV, vaccGHIJKLMNOPQRSTUVp0);
161 
162       const __m512 vi8x0123456789ABCDEF = _mm512_loadu_ps(i8);
163       const __m512 vi8xGHIJKLMNOPQRSTUV = _mm512_loadu_ps(i8 + 16);
164       i8 += 32;
165 
166       const __m512 vk8x0123456789ABCDEF = _mm512_load_ps(w + 288);
167       const __m512 vk8xGHIJKLMNOPQRSTUV = _mm512_load_ps(w + 304);
168       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi8x0123456789ABCDEF, vk8x0123456789ABCDEF, vacc0123456789ABCDEFp0);
169       vaccGHIJKLMNOPQRSTUVp0 = _mm512_fmadd_ps(vi8xGHIJKLMNOPQRSTUV, vk8xGHIJKLMNOPQRSTUV, vaccGHIJKLMNOPQRSTUVp0);
170 
171       w += 320;
172 
173 
174       __m512 vacc0123456789ABCDEF = _mm512_max_ps(vacc0123456789ABCDEFp0, vmin);
175       __m512 vaccGHIJKLMNOPQRSTUV = _mm512_max_ps(vaccGHIJKLMNOPQRSTUVp0, vmin);
176       vacc0123456789ABCDEF = _mm512_min_ps(vacc0123456789ABCDEF, vmax);
177       vaccGHIJKLMNOPQRSTUV = _mm512_min_ps(vaccGHIJKLMNOPQRSTUV, vmax);
178 
179       _mm512_storeu_ps(output, vacc0123456789ABCDEF);
180       _mm512_storeu_ps(output + 16, vaccGHIJKLMNOPQRSTUV);
181       output += 32;
182     }
183     for (; c >= 16; c -= 16) {
184       __m512 vacc0123456789ABCDEFp0 = _mm512_load_ps(w);
185 
186       const __m512 vi0x0123456789ABCDEF = _mm512_loadu_ps(i0);
187       i0 += 16;
188 
189       const __m512 vk0x0123456789ABCDEF = _mm512_load_ps(w + 32);
190       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi0x0123456789ABCDEF, vk0x0123456789ABCDEF, vacc0123456789ABCDEFp0);
191 
192       const __m512 vi1x0123456789ABCDEF = _mm512_loadu_ps(i1);
193       i1 += 16;
194 
195       const __m512 vk1x0123456789ABCDEF = _mm512_load_ps(w + 64);
196       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi1x0123456789ABCDEF, vk1x0123456789ABCDEF, vacc0123456789ABCDEFp0);
197 
198       const __m512 vi2x0123456789ABCDEF = _mm512_loadu_ps(i2);
199       i2 += 16;
200 
201       const __m512 vk2x0123456789ABCDEF = _mm512_load_ps(w + 96);
202       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi2x0123456789ABCDEF, vk2x0123456789ABCDEF, vacc0123456789ABCDEFp0);
203 
204       const __m512 vi3x0123456789ABCDEF = _mm512_loadu_ps(i3);
205       i3 += 16;
206 
207       const __m512 vk3x0123456789ABCDEF = _mm512_load_ps(w + 128);
208       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi3x0123456789ABCDEF, vk3x0123456789ABCDEF, vacc0123456789ABCDEFp0);
209 
210       const __m512 vi4x0123456789ABCDEF = _mm512_loadu_ps(i4);
211       i4 += 16;
212 
213       const __m512 vk4x0123456789ABCDEF = _mm512_load_ps(w + 160);
214       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi4x0123456789ABCDEF, vk4x0123456789ABCDEF, vacc0123456789ABCDEFp0);
215 
216       const __m512 vi5x0123456789ABCDEF = _mm512_loadu_ps(i5);
217       i5 += 16;
218 
219       const __m512 vk5x0123456789ABCDEF = _mm512_load_ps(w + 192);
220       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi5x0123456789ABCDEF, vk5x0123456789ABCDEF, vacc0123456789ABCDEFp0);
221 
222       const __m512 vi6x0123456789ABCDEF = _mm512_loadu_ps(i6);
223       i6 += 16;
224 
225       const __m512 vk6x0123456789ABCDEF = _mm512_load_ps(w + 224);
226       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi6x0123456789ABCDEF, vk6x0123456789ABCDEF, vacc0123456789ABCDEFp0);
227 
228       const __m512 vi7x0123456789ABCDEF = _mm512_loadu_ps(i7);
229       i7 += 16;
230 
231       const __m512 vk7x0123456789ABCDEF = _mm512_load_ps(w + 256);
232       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi7x0123456789ABCDEF, vk7x0123456789ABCDEF, vacc0123456789ABCDEFp0);
233 
234       const __m512 vi8x0123456789ABCDEF = _mm512_loadu_ps(i8);
235       i8 += 16;
236 
237       const __m512 vk8x0123456789ABCDEF = _mm512_load_ps(w + 288);
238       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi8x0123456789ABCDEF, vk8x0123456789ABCDEF, vacc0123456789ABCDEFp0);
239 
240       w += 16;
241 
242 
243       __m512 vacc0123456789ABCDEF = _mm512_max_ps(vacc0123456789ABCDEFp0, vmin);
244       vacc0123456789ABCDEF = _mm512_min_ps(vacc0123456789ABCDEF, vmax);
245 
246       _mm512_storeu_ps(output, vacc0123456789ABCDEF);
247       output += 16;
248     }
249     if XNN_UNLIKELY(c != 0) {
250       assert(c >= 1);
251       assert(c <= 16);
252       // Prepare mask for valid 32-bit elements (depends on nc).
253       const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << c) - UINT32_C(1)));
254 
255       __m512 vacc0123456789ABCDEFp0 = _mm512_maskz_loadu_ps(vmask, w);
256 
257       const __m512 vi0x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, i0);
258       const __m512 vk0x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, w + 32);
259       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi0x0123456789ABCDEF, vk0x0123456789ABCDEF, vacc0123456789ABCDEFp0);
260 
261       const __m512 vi1x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, i1);
262       const __m512 vk1x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, w + 64);
263       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi1x0123456789ABCDEF, vk1x0123456789ABCDEF, vacc0123456789ABCDEFp0);
264 
265       const __m512 vi2x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, i2);
266       const __m512 vk2x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, w + 96);
267       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi2x0123456789ABCDEF, vk2x0123456789ABCDEF, vacc0123456789ABCDEFp0);
268 
269       const __m512 vi3x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, i3);
270       const __m512 vk3x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, w + 128);
271       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi3x0123456789ABCDEF, vk3x0123456789ABCDEF, vacc0123456789ABCDEFp0);
272 
273       const __m512 vi4x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, i4);
274       const __m512 vk4x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, w + 160);
275       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi4x0123456789ABCDEF, vk4x0123456789ABCDEF, vacc0123456789ABCDEFp0);
276 
277       const __m512 vi5x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, i5);
278       const __m512 vk5x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, w + 192);
279       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi5x0123456789ABCDEF, vk5x0123456789ABCDEF, vacc0123456789ABCDEFp0);
280 
281       const __m512 vi6x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, i6);
282       const __m512 vk6x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, w + 224);
283       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi6x0123456789ABCDEF, vk6x0123456789ABCDEF, vacc0123456789ABCDEFp0);
284 
285       const __m512 vi7x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, i7);
286       const __m512 vk7x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, w + 256);
287       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi7x0123456789ABCDEF, vk7x0123456789ABCDEF, vacc0123456789ABCDEFp0);
288 
289       const __m512 vi8x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, i8);
290       const __m512 vk8x0123456789ABCDEF = _mm512_maskz_loadu_ps(vmask, w + 288);
291       vacc0123456789ABCDEFp0 = _mm512_fmadd_ps(vi8x0123456789ABCDEF, vk8x0123456789ABCDEF, vacc0123456789ABCDEFp0);
292 
293 
294       __m512 vacc0123456789ABCDEF = _mm512_max_ps(vacc0123456789ABCDEFp0, vmin);
295       vacc0123456789ABCDEF = _mm512_min_ps(vacc0123456789ABCDEF, vmax);
296 
297       _mm512_mask_storeu_ps(output, vmask, vacc0123456789ABCDEF);
298       output += c;
299     }
300 
301     output = (float*) ((uintptr_t) output + output_increment);
302   } while (--output_width != 0);
303 }
304