1 // Auto-generated file. Do not edit!
2 // Template: src/f32-dwconv/up-avx.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
16
17 static const int32_t mask_table[14] = {-1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0};
18
xnn_f32_dwconv_ukernel_up8x25__avx(size_t channels,size_t output_width,const float ** input,const float * weights,float * output,size_t input_stride,size_t output_increment,const union xnn_f32_output_params params[restrict static1])19 void xnn_f32_dwconv_ukernel_up8x25__avx(
20 size_t channels,
21 size_t output_width,
22 const float** input,
23 const float* weights,
24 float* output,
25 size_t input_stride,
26 size_t output_increment,
27 const union xnn_f32_output_params params[restrict static 1])
28 {
29 assert(channels != 0);
30 assert(output_width != 0);
31
32 const __m256 vmax = _mm256_broadcast_ps((const __m128*) params->sse.max);
33 const __m256 vmin = _mm256_broadcast_ps((const __m128*) params->sse.min);
34 do {
35 const float* i0 = input[0];
36 assert(i0 != NULL);
37 const float* i1 = input[1];
38 assert(i1 != NULL);
39 const float* i2 = input[2];
40 assert(i2 != NULL);
41 const float* i3 = input[3];
42 assert(i3 != NULL);
43 const float* i4 = input[4];
44 assert(i4 != NULL);
45 const float* i5 = input[5];
46 assert(i5 != NULL);
47 const float* i6 = input[6];
48 assert(i6 != NULL);
49 const float* i7 = input[7];
50 assert(i7 != NULL);
51 const float* i8 = input[8];
52 assert(i8 != NULL);
53 const float* i9 = input[9];
54 assert(i9 != NULL);
55 const float* i10 = input[10];
56 assert(i10 != NULL);
57 const float* i11 = input[11];
58 assert(i11 != NULL);
59 const float* i12 = input[12];
60 assert(i12 != NULL);
61 const float* i13 = input[13];
62 assert(i13 != NULL);
63 const float* i14 = input[14];
64 assert(i14 != NULL);
65 const float* i15 = input[15];
66 assert(i15 != NULL);
67 const float* i16 = input[16];
68 assert(i16 != NULL);
69 const float* i17 = input[17];
70 assert(i17 != NULL);
71 const float* i18 = input[18];
72 assert(i18 != NULL);
73 const float* i19 = input[19];
74 assert(i19 != NULL);
75 const float* i20 = input[20];
76 assert(i20 != NULL);
77 const float* i21 = input[21];
78 assert(i21 != NULL);
79 const float* i22 = input[22];
80 assert(i22 != NULL);
81 const float* i23 = input[23];
82 assert(i23 != NULL);
83 const float* i24 = input[24];
84 assert(i24 != NULL);
85 input = (const float**) ((uintptr_t) input + input_stride);
86
87 size_t c = channels;
88 const float* w = weights;
89 for (; c >= 8; c -= 8) {
90 __m256 vacc01234567p0 = _mm256_load_ps(w);
91
92
93 const __m256 vi0x01234567 = _mm256_loadu_ps(i0);
94 i0 += 8;
95
96 const __m256 vk0x01234567 = _mm256_load_ps(w + 8);
97 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi0x01234567, vk0x01234567));
98
99 const __m256 vi1x01234567 = _mm256_loadu_ps(i1);
100 i1 += 8;
101
102 const __m256 vk1x01234567 = _mm256_load_ps(w + 16);
103 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi1x01234567, vk1x01234567));
104
105 const __m256 vi2x01234567 = _mm256_loadu_ps(i2);
106 i2 += 8;
107
108 const __m256 vk2x01234567 = _mm256_load_ps(w + 24);
109 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi2x01234567, vk2x01234567));
110
111 const __m256 vi3x01234567 = _mm256_loadu_ps(i3);
112 i3 += 8;
113
114 const __m256 vk3x01234567 = _mm256_load_ps(w + 32);
115 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi3x01234567, vk3x01234567));
116
117 const __m256 vi4x01234567 = _mm256_loadu_ps(i4);
118 i4 += 8;
119
120 const __m256 vk4x01234567 = _mm256_load_ps(w + 40);
121 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi4x01234567, vk4x01234567));
122
123 const __m256 vi5x01234567 = _mm256_loadu_ps(i5);
124 i5 += 8;
125
126 const __m256 vk5x01234567 = _mm256_load_ps(w + 48);
127 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi5x01234567, vk5x01234567));
128
129 const __m256 vi6x01234567 = _mm256_loadu_ps(i6);
130 i6 += 8;
131
132 const __m256 vk6x01234567 = _mm256_load_ps(w + 56);
133 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi6x01234567, vk6x01234567));
134
135 const __m256 vi7x01234567 = _mm256_loadu_ps(i7);
136 i7 += 8;
137
138 const __m256 vk7x01234567 = _mm256_load_ps(w + 64);
139 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi7x01234567, vk7x01234567));
140
141 const __m256 vi8x01234567 = _mm256_loadu_ps(i8);
142 i8 += 8;
143
144 const __m256 vk8x01234567 = _mm256_load_ps(w + 72);
145 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi8x01234567, vk8x01234567));
146
147 const __m256 vi9x01234567 = _mm256_loadu_ps(i9);
148 i9 += 8;
149
150 const __m256 vk9x01234567 = _mm256_load_ps(w + 80);
151 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi9x01234567, vk9x01234567));
152
153 const __m256 vi10x01234567 = _mm256_loadu_ps(i10);
154 i10 += 8;
155
156 const __m256 vk10x01234567 = _mm256_load_ps(w + 88);
157 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi10x01234567, vk10x01234567));
158
159 const __m256 vi11x01234567 = _mm256_loadu_ps(i11);
160 i11 += 8;
161
162 const __m256 vk11x01234567 = _mm256_load_ps(w + 96);
163 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi11x01234567, vk11x01234567));
164
165 const __m256 vi12x01234567 = _mm256_loadu_ps(i12);
166 i12 += 8;
167
168 const __m256 vk12x01234567 = _mm256_load_ps(w + 104);
169 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi12x01234567, vk12x01234567));
170
171 const __m256 vi13x01234567 = _mm256_loadu_ps(i13);
172 i13 += 8;
173
174 const __m256 vk13x01234567 = _mm256_load_ps(w + 112);
175 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi13x01234567, vk13x01234567));
176
177 const __m256 vi14x01234567 = _mm256_loadu_ps(i14);
178 i14 += 8;
179
180 const __m256 vk14x01234567 = _mm256_load_ps(w + 120);
181 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi14x01234567, vk14x01234567));
182
183 const __m256 vi15x01234567 = _mm256_loadu_ps(i15);
184 i15 += 8;
185
186 const __m256 vk15x01234567 = _mm256_load_ps(w + 128);
187 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi15x01234567, vk15x01234567));
188
189 const __m256 vi16x01234567 = _mm256_loadu_ps(i16);
190 i16 += 8;
191
192 const __m256 vk16x01234567 = _mm256_load_ps(w + 136);
193 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi16x01234567, vk16x01234567));
194
195 const __m256 vi17x01234567 = _mm256_loadu_ps(i17);
196 i17 += 8;
197
198 const __m256 vk17x01234567 = _mm256_load_ps(w + 144);
199 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi17x01234567, vk17x01234567));
200
201 const __m256 vi18x01234567 = _mm256_loadu_ps(i18);
202 i18 += 8;
203
204 const __m256 vk18x01234567 = _mm256_load_ps(w + 152);
205 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi18x01234567, vk18x01234567));
206
207 const __m256 vi19x01234567 = _mm256_loadu_ps(i19);
208 i19 += 8;
209
210 const __m256 vk19x01234567 = _mm256_load_ps(w + 160);
211 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi19x01234567, vk19x01234567));
212
213 const __m256 vi20x01234567 = _mm256_loadu_ps(i20);
214 i20 += 8;
215
216 const __m256 vk20x01234567 = _mm256_load_ps(w + 168);
217 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi20x01234567, vk20x01234567));
218
219 const __m256 vi21x01234567 = _mm256_loadu_ps(i21);
220 i21 += 8;
221
222 const __m256 vk21x01234567 = _mm256_load_ps(w + 176);
223 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi21x01234567, vk21x01234567));
224
225 const __m256 vi22x01234567 = _mm256_loadu_ps(i22);
226 i22 += 8;
227
228 const __m256 vk22x01234567 = _mm256_load_ps(w + 184);
229 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi22x01234567, vk22x01234567));
230
231 const __m256 vi23x01234567 = _mm256_loadu_ps(i23);
232 i23 += 8;
233
234 const __m256 vk23x01234567 = _mm256_load_ps(w + 192);
235 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi23x01234567, vk23x01234567));
236
237 const __m256 vi24x01234567 = _mm256_loadu_ps(i24);
238 i24 += 8;
239
240 const __m256 vk24x01234567 = _mm256_load_ps(w + 200);
241 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi24x01234567, vk24x01234567));
242
243 w += 208;
244
245
246 __m256 vacc01234567 = _mm256_max_ps(vacc01234567p0, vmin);
247 vacc01234567 = _mm256_min_ps(vacc01234567, vmax);
248
249 _mm256_storeu_ps(output, vacc01234567);
250 output += 8;
251 }
252 if XNN_UNLIKELY(c != 0) {
253 assert(c >= 1);
254 assert(c <= 7);
255 __m256i vmask = _mm256_loadu_si256((const __m256i*) &mask_table[7 - c]);
256
257 __m256 vacc01234567p0 = _mm256_load_ps(w);
258
259 const __m256 vi0x01234567 = _mm256_maskload_ps(i0, vmask);
260 const __m256 vk0x01234567 = _mm256_load_ps(w + 8);
261 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi0x01234567, vk0x01234567));
262
263 const __m256 vi1x01234567 = _mm256_maskload_ps(i1, vmask);
264 const __m256 vk1x01234567 = _mm256_load_ps(w + 16);
265 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi1x01234567, vk1x01234567));
266
267 const __m256 vi2x01234567 = _mm256_maskload_ps(i2, vmask);
268 const __m256 vk2x01234567 = _mm256_load_ps(w + 24);
269 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi2x01234567, vk2x01234567));
270
271 const __m256 vi3x01234567 = _mm256_maskload_ps(i3, vmask);
272 const __m256 vk3x01234567 = _mm256_load_ps(w + 32);
273 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi3x01234567, vk3x01234567));
274
275 const __m256 vi4x01234567 = _mm256_maskload_ps(i4, vmask);
276 const __m256 vk4x01234567 = _mm256_load_ps(w + 40);
277 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi4x01234567, vk4x01234567));
278
279 const __m256 vi5x01234567 = _mm256_maskload_ps(i5, vmask);
280 const __m256 vk5x01234567 = _mm256_load_ps(w + 48);
281 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi5x01234567, vk5x01234567));
282
283 const __m256 vi6x01234567 = _mm256_maskload_ps(i6, vmask);
284 const __m256 vk6x01234567 = _mm256_load_ps(w + 56);
285 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi6x01234567, vk6x01234567));
286
287 const __m256 vi7x01234567 = _mm256_maskload_ps(i7, vmask);
288 const __m256 vk7x01234567 = _mm256_load_ps(w + 64);
289 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi7x01234567, vk7x01234567));
290
291 const __m256 vi8x01234567 = _mm256_maskload_ps(i8, vmask);
292 const __m256 vk8x01234567 = _mm256_load_ps(w + 72);
293 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi8x01234567, vk8x01234567));
294
295 const __m256 vi9x01234567 = _mm256_maskload_ps(i9, vmask);
296 const __m256 vk9x01234567 = _mm256_load_ps(w + 80);
297 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi9x01234567, vk9x01234567));
298
299 const __m256 vi10x01234567 = _mm256_maskload_ps(i10, vmask);
300 const __m256 vk10x01234567 = _mm256_load_ps(w + 88);
301 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi10x01234567, vk10x01234567));
302
303 const __m256 vi11x01234567 = _mm256_maskload_ps(i11, vmask);
304 const __m256 vk11x01234567 = _mm256_load_ps(w + 96);
305 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi11x01234567, vk11x01234567));
306
307 const __m256 vi12x01234567 = _mm256_maskload_ps(i12, vmask);
308 const __m256 vk12x01234567 = _mm256_load_ps(w + 104);
309 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi12x01234567, vk12x01234567));
310
311 const __m256 vi13x01234567 = _mm256_maskload_ps(i13, vmask);
312 const __m256 vk13x01234567 = _mm256_load_ps(w + 112);
313 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi13x01234567, vk13x01234567));
314
315 const __m256 vi14x01234567 = _mm256_maskload_ps(i14, vmask);
316 const __m256 vk14x01234567 = _mm256_load_ps(w + 120);
317 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi14x01234567, vk14x01234567));
318
319 const __m256 vi15x01234567 = _mm256_maskload_ps(i15, vmask);
320 const __m256 vk15x01234567 = _mm256_load_ps(w + 128);
321 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi15x01234567, vk15x01234567));
322
323 const __m256 vi16x01234567 = _mm256_maskload_ps(i16, vmask);
324 const __m256 vk16x01234567 = _mm256_load_ps(w + 136);
325 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi16x01234567, vk16x01234567));
326
327 const __m256 vi17x01234567 = _mm256_maskload_ps(i17, vmask);
328 const __m256 vk17x01234567 = _mm256_load_ps(w + 144);
329 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi17x01234567, vk17x01234567));
330
331 const __m256 vi18x01234567 = _mm256_maskload_ps(i18, vmask);
332 const __m256 vk18x01234567 = _mm256_load_ps(w + 152);
333 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi18x01234567, vk18x01234567));
334
335 const __m256 vi19x01234567 = _mm256_maskload_ps(i19, vmask);
336 const __m256 vk19x01234567 = _mm256_load_ps(w + 160);
337 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi19x01234567, vk19x01234567));
338
339 const __m256 vi20x01234567 = _mm256_maskload_ps(i20, vmask);
340 const __m256 vk20x01234567 = _mm256_load_ps(w + 168);
341 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi20x01234567, vk20x01234567));
342
343 const __m256 vi21x01234567 = _mm256_maskload_ps(i21, vmask);
344 const __m256 vk21x01234567 = _mm256_load_ps(w + 176);
345 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi21x01234567, vk21x01234567));
346
347 const __m256 vi22x01234567 = _mm256_maskload_ps(i22, vmask);
348 const __m256 vk22x01234567 = _mm256_load_ps(w + 184);
349 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi22x01234567, vk22x01234567));
350
351 const __m256 vi23x01234567 = _mm256_maskload_ps(i23, vmask);
352 const __m256 vk23x01234567 = _mm256_load_ps(w + 192);
353 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi23x01234567, vk23x01234567));
354
355 const __m256 vi24x01234567 = _mm256_maskload_ps(i24, vmask);
356 const __m256 vk24x01234567 = _mm256_load_ps(w + 200);
357 vacc01234567p0 = _mm256_add_ps(vacc01234567p0, _mm256_mul_ps(vi24x01234567, vk24x01234567));
358
359
360 __m256 vacc01234567 = _mm256_max_ps(vacc01234567p0, vmin);
361 vacc01234567 = _mm256_min_ps(vacc01234567, vmax);
362
363 // _mm256_maskstore_ps(output, vmask, vacc01234567); output += c; could be used here, but triggers msan failures (probably an msan bug).
364 __m128 vacc0123 = _mm256_castps256_ps128(vacc01234567);
365 if (c & 4) {
366 _mm_storeu_ps(output, vacc0123);
367 vacc0123 = _mm256_extractf128_ps(vacc01234567, 1);
368 output += 4;
369 }
370 if (c & 2) {
371 _mm_storel_pi((__m64*) output, vacc0123);
372 vacc0123 = _mm_movehl_ps(vacc0123, vacc0123);
373 output += 2;
374 }
375 if (c & 1) {
376 _mm_store_ss(output, vacc0123);
377 output += 1;
378 }
379 }
380
381 output = (float*) ((uintptr_t) output + output_increment);
382 } while (--output_width != 0);
383 }
384