1 // Auto-generated file. Do not edit!
2 // Template: src/f32-prelu/avx512f.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 <immintrin.h>
13
14 #include <xnnpack/intrinsics-polyfill.h>
15 #include <xnnpack/math.h>
16 #include <xnnpack/prelu.h>
17
18
xnn_f32_prelu_ukernel__avx512f_2x16(size_t rows,size_t channels,const float * restrict input,size_t input_stride,const float * restrict weights,float * restrict output,size_t output_stride)19 void xnn_f32_prelu_ukernel__avx512f_2x16(
20 size_t rows,
21 size_t channels,
22 const float*restrict input,
23 size_t input_stride,
24 const float*restrict weights,
25 float*restrict output,
26 size_t output_stride)
27 {
28 assert(rows != 0);
29 assert(channels != 0);
30 assert(channels % sizeof(float) == 0);
31
32 const float* i0 = input;
33 float* o0 = output;
34 const float* i1 = (const float*) ((uintptr_t) i0 + input_stride);
35 float* o1 = (float*) ((uintptr_t) o0 + output_stride);
36 if XNN_UNPREDICTABLE(rows < 2) {
37 i1 = i0;
38 o1 = o0;
39 }
40
41 const size_t input_increment = input_stride * 2 - channels;
42 const size_t output_increment = output_stride * 2 - channels;
43
44 const __m512 vzero = _mm512_setzero_ps();
45 do {
46 const float* w = weights;
47 size_t c = channels;
48 for (; c >= 16 * sizeof(float); c -= 16 * sizeof(float)) {
49 const __m512 vw0123456789ABCDEF = _mm512_load_ps(w);
50 w += 16;
51
52 const __m512 vi0x0123456789ABCDEF = _mm512_loadu_ps(i0);
53 i0 += 16;
54 const __m512 vi1x0123456789ABCDEF = _mm512_loadu_ps(i1);
55 i1 += 16;
56
57 const __mmask16 vsign0x0123456789ABCDEF = _mm512_cmp_ps_mask(vi0x0123456789ABCDEF, vzero, _CMP_LT_OQ);
58 const __m512 vacc0x0123456789ABCDEF = _mm512_mask_mul_ps(vi0x0123456789ABCDEF, vsign0x0123456789ABCDEF, vi0x0123456789ABCDEF, vw0123456789ABCDEF);
59 const __mmask16 vsign1x0123456789ABCDEF = _mm512_cmp_ps_mask(vi1x0123456789ABCDEF, vzero, _CMP_LT_OQ);
60 const __m512 vacc1x0123456789ABCDEF = _mm512_mask_mul_ps(vi1x0123456789ABCDEF, vsign1x0123456789ABCDEF, vi1x0123456789ABCDEF, vw0123456789ABCDEF);
61
62 _mm512_storeu_ps(o0, vacc0x0123456789ABCDEF);
63 o0 += 16;
64 _mm512_storeu_ps(o1, vacc1x0123456789ABCDEF);
65 o1 += 16;
66 }
67 if XNN_UNLIKELY(c != 0) {
68 assert(c >= 1 * sizeof(float));
69 assert(c <= 15 * sizeof(float));
70 // Prepare mask for valid 32-bit elements (depends on c).
71 const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << (c >> 2 /* log2(sizeof(float))*/)) - UINT32_C(1)));
72
73 const __m512 vw = _mm512_maskz_loadu_ps(vmask, w);
74
75 const __m512 vi0 = _mm512_maskz_loadu_ps(vmask, i0);
76 i0 = (const float*) ((uintptr_t) i0 + c);
77 const __m512 vi1 = _mm512_maskz_loadu_ps(vmask, i1);
78 i1 = (const float*) ((uintptr_t) i1 + c);
79
80 const __mmask16 vsign0 = _mm512_cmp_ps_mask(vi0, vzero, _CMP_LT_OQ);
81 const __m512 vacc0 = _mm512_mask_mul_ps(vi0, vsign0, vi0, vw);
82 const __mmask16 vsign1 = _mm512_cmp_ps_mask(vi1, vzero, _CMP_LT_OQ);
83 const __m512 vacc1 = _mm512_mask_mul_ps(vi1, vsign1, vi1, vw);
84
85 _mm512_mask_storeu_ps(o0, vmask, vacc0);
86 o0 = (float*) ((uintptr_t) o0 + c);
87 _mm512_mask_storeu_ps(o1, vmask, vacc1);
88 o1 = (float*) ((uintptr_t) o1 + c);
89 }
90 i0 = (const float*) ((uintptr_t) i0 + input_increment);
91 o0 = (float*) ((uintptr_t) o0 + output_increment);
92 i1 = (const float*) ((uintptr_t) i1 + input_increment);
93 o1 = (float*) ((uintptr_t) o1 + output_increment);
94 if XNN_UNPREDICTABLE(rows < 4) {
95 i1 = i0;
96 o1 = o0;
97 }
98 rows = doz(rows, 2);
99 } while (rows != 0);
100 }
101