1 // Auto-generated file. Do not edit!
2 // Template: src/f32-raddstoreexpminusmax/avx512f-rr1-p5-scalef.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/intrinsics-polyfill.h>
15 #include <xnnpack/raddstoreexpminusmax.h>
16
17
xnn_f32_raddstoreexpminusmax_ukernel__avx512f_rr1_p5_scalef_x128_acc2(size_t elements,const float * input,const float * max,float * output,float * sum,const union xnn_f32_expminus_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_raddstoreexpminusmax_ukernel__avx512f_rr1_p5_scalef_x128_acc2(
19 size_t elements,
20 const float* input,
21 const float* max,
22 float* output,
23 float* sum,
24 const union xnn_f32_expminus_params params[restrict XNN_MIN_ELEMENTS(1)])
25 {
26 assert(elements % sizeof(float) == 0);
27
28 const __m512 vi_max = _mm512_set1_ps(*max);
29 const __m512 vlog2e = _mm512_set1_ps(params->avx512_rr1_p5.log2e);
30 const __m512 vminus_ln2 = _mm512_set1_ps(params->avx512_rr1_p5.minus_ln2);
31 const __m512 vc5 = _mm512_set1_ps(params->avx512_rr1_p5.c5);
32 const __m512 vc4 = _mm512_set1_ps(params->avx512_rr1_p5.c4);
33 const __m512 vc3 = _mm512_set1_ps(params->avx512_rr1_p5.c3);
34 const __m512 vc2 = _mm512_set1_ps(params->avx512_rr1_p5.c2);
35 const __m512 vc1 = _mm512_set1_ps(params->avx512_rr1_p5.c1);
36 const __m512 vc0 = _mm512_set1_ps(params->avx512_rr1_p5.c0);
37
38 __m512 vacc0 = _mm512_setzero_ps();
39 __m512 vacc1 = _mm512_setzero_ps();
40 for (; elements >= 128 * sizeof(float); elements -= 128 * sizeof(float)) {
41 const __m512 vi0 = _mm512_loadu_ps(input);
42 const __m512 vi1 = _mm512_loadu_ps(input + 16);
43 const __m512 vi2 = _mm512_loadu_ps(input + 32);
44 const __m512 vi3 = _mm512_loadu_ps(input + 48);
45 const __m512 vi4 = _mm512_loadu_ps(input + 64);
46 const __m512 vi5 = _mm512_loadu_ps(input + 80);
47 const __m512 vi6 = _mm512_loadu_ps(input + 96);
48 const __m512 vi7 = _mm512_loadu_ps(input + 112);
49 input += 128;
50
51 const __m512 vx0 = _mm512_sub_ps(vi0, vi_max);
52 const __m512 vx1 = _mm512_sub_ps(vi1, vi_max);
53 const __m512 vx2 = _mm512_sub_ps(vi2, vi_max);
54 const __m512 vx3 = _mm512_sub_ps(vi3, vi_max);
55 const __m512 vx4 = _mm512_sub_ps(vi4, vi_max);
56 const __m512 vx5 = _mm512_sub_ps(vi5, vi_max);
57 const __m512 vx6 = _mm512_sub_ps(vi6, vi_max);
58 const __m512 vx7 = _mm512_sub_ps(vi7, vi_max);
59
60 const __m512 vn0 = _mm512_roundscale_ps(_mm512_mul_ps(vx0, vlog2e), 0);
61 const __m512 vn1 = _mm512_roundscale_ps(_mm512_mul_ps(vx1, vlog2e), 0);
62 const __m512 vn2 = _mm512_roundscale_ps(_mm512_mul_ps(vx2, vlog2e), 0);
63 const __m512 vn3 = _mm512_roundscale_ps(_mm512_mul_ps(vx3, vlog2e), 0);
64 const __m512 vn4 = _mm512_roundscale_ps(_mm512_mul_ps(vx4, vlog2e), 0);
65 const __m512 vn5 = _mm512_roundscale_ps(_mm512_mul_ps(vx5, vlog2e), 0);
66 const __m512 vn6 = _mm512_roundscale_ps(_mm512_mul_ps(vx6, vlog2e), 0);
67 const __m512 vn7 = _mm512_roundscale_ps(_mm512_mul_ps(vx7, vlog2e), 0);
68
69 const __m512 vt0 = _mm512_fmadd_ps(vn0, vminus_ln2, vx0);
70 const __m512 vt1 = _mm512_fmadd_ps(vn1, vminus_ln2, vx1);
71 const __m512 vt2 = _mm512_fmadd_ps(vn2, vminus_ln2, vx2);
72 const __m512 vt3 = _mm512_fmadd_ps(vn3, vminus_ln2, vx3);
73 const __m512 vt4 = _mm512_fmadd_ps(vn4, vminus_ln2, vx4);
74 const __m512 vt5 = _mm512_fmadd_ps(vn5, vminus_ln2, vx5);
75 const __m512 vt6 = _mm512_fmadd_ps(vn6, vminus_ln2, vx6);
76 const __m512 vt7 = _mm512_fmadd_ps(vn7, vminus_ln2, vx7);
77
78 __m512 vp0 = _mm512_fmadd_ps(vc5, vt0, vc4);
79 __m512 vp1 = _mm512_fmadd_ps(vc5, vt1, vc4);
80 __m512 vp2 = _mm512_fmadd_ps(vc5, vt2, vc4);
81 __m512 vp3 = _mm512_fmadd_ps(vc5, vt3, vc4);
82 __m512 vp4 = _mm512_fmadd_ps(vc5, vt4, vc4);
83 __m512 vp5 = _mm512_fmadd_ps(vc5, vt5, vc4);
84 __m512 vp6 = _mm512_fmadd_ps(vc5, vt6, vc4);
85 __m512 vp7 = _mm512_fmadd_ps(vc5, vt7, vc4);
86
87 vp0 = _mm512_fmadd_ps(vp0, vt0, vc3);
88 vp1 = _mm512_fmadd_ps(vp1, vt1, vc3);
89 vp2 = _mm512_fmadd_ps(vp2, vt2, vc3);
90 vp3 = _mm512_fmadd_ps(vp3, vt3, vc3);
91 vp4 = _mm512_fmadd_ps(vp4, vt4, vc3);
92 vp5 = _mm512_fmadd_ps(vp5, vt5, vc3);
93 vp6 = _mm512_fmadd_ps(vp6, vt6, vc3);
94 vp7 = _mm512_fmadd_ps(vp7, vt7, vc3);
95
96 vp0 = _mm512_fmadd_ps(vp0, vt0, vc2);
97 vp1 = _mm512_fmadd_ps(vp1, vt1, vc2);
98 vp2 = _mm512_fmadd_ps(vp2, vt2, vc2);
99 vp3 = _mm512_fmadd_ps(vp3, vt3, vc2);
100 vp4 = _mm512_fmadd_ps(vp4, vt4, vc2);
101 vp5 = _mm512_fmadd_ps(vp5, vt5, vc2);
102 vp6 = _mm512_fmadd_ps(vp6, vt6, vc2);
103 vp7 = _mm512_fmadd_ps(vp7, vt7, vc2);
104
105 vp0 = _mm512_fmadd_ps(vp0, vt0, vc1);
106 vp1 = _mm512_fmadd_ps(vp1, vt1, vc1);
107 vp2 = _mm512_fmadd_ps(vp2, vt2, vc1);
108 vp3 = _mm512_fmadd_ps(vp3, vt3, vc1);
109 vp4 = _mm512_fmadd_ps(vp4, vt4, vc1);
110 vp5 = _mm512_fmadd_ps(vp5, vt5, vc1);
111 vp6 = _mm512_fmadd_ps(vp6, vt6, vc1);
112 vp7 = _mm512_fmadd_ps(vp7, vt7, vc1);
113
114 vp0 = _mm512_fmadd_ps(vp0, vt0, vc0);
115 vp1 = _mm512_fmadd_ps(vp1, vt1, vc0);
116 vp2 = _mm512_fmadd_ps(vp2, vt2, vc0);
117 vp3 = _mm512_fmadd_ps(vp3, vt3, vc0);
118 vp4 = _mm512_fmadd_ps(vp4, vt4, vc0);
119 vp5 = _mm512_fmadd_ps(vp5, vt5, vc0);
120 vp6 = _mm512_fmadd_ps(vp6, vt6, vc0);
121 vp7 = _mm512_fmadd_ps(vp7, vt7, vc0);
122
123 const __m512 vf0 = _mm512_scalef_ps(vp0, vn0);
124 const __m512 vf1 = _mm512_scalef_ps(vp1, vn1);
125 const __m512 vf2 = _mm512_scalef_ps(vp2, vn2);
126 const __m512 vf3 = _mm512_scalef_ps(vp3, vn3);
127 const __m512 vf4 = _mm512_scalef_ps(vp4, vn4);
128 const __m512 vf5 = _mm512_scalef_ps(vp5, vn5);
129 const __m512 vf6 = _mm512_scalef_ps(vp6, vn6);
130 const __m512 vf7 = _mm512_scalef_ps(vp7, vn7);
131
132 _mm512_storeu_ps(output, vf0);
133 _mm512_storeu_ps(output + 16, vf1);
134 _mm512_storeu_ps(output + 32, vf2);
135 _mm512_storeu_ps(output + 48, vf3);
136 _mm512_storeu_ps(output + 64, vf4);
137 _mm512_storeu_ps(output + 80, vf5);
138 _mm512_storeu_ps(output + 96, vf6);
139 _mm512_storeu_ps(output + 112, vf7);
140 output += 128;
141
142 vacc0 = _mm512_add_ps(vacc0, vf0);
143 vacc1 = _mm512_add_ps(vacc1, vf1);
144 vacc0 = _mm512_add_ps(vacc0, vf2);
145 vacc1 = _mm512_add_ps(vacc1, vf3);
146 vacc0 = _mm512_add_ps(vacc0, vf4);
147 vacc1 = _mm512_add_ps(vacc1, vf5);
148 vacc0 = _mm512_add_ps(vacc0, vf6);
149 vacc1 = _mm512_add_ps(vacc1, vf7);
150 }
151 vacc0 = _mm512_add_ps(vacc0, vacc1);
152
153 __m512 vacc = vacc0;
154 for (; elements >= 16 * sizeof(float); elements -= 16 * sizeof(float)) {
155 const __m512 vi = _mm512_loadu_ps(input);
156 input += 16;
157
158 const __m512 vx = _mm512_sub_ps(vi, vi_max);
159
160 const __m512 vn = _mm512_roundscale_ps(_mm512_mul_ps(vx, vlog2e), 0);
161
162 const __m512 vt = _mm512_fmadd_ps(vn, vminus_ln2, vx);
163
164 __m512 vp = _mm512_fmadd_ps(vc5, vt, vc4);
165 vp = _mm512_fmadd_ps(vp, vt, vc3);
166 vp = _mm512_fmadd_ps(vp, vt, vc2);
167 vp = _mm512_fmadd_ps(vp, vt, vc1);
168 vp = _mm512_fmadd_ps(vp, vt, vc0);
169
170 const __m512 vf = _mm512_scalef_ps(vp, vn);
171
172 _mm512_storeu_ps(output, vf);
173 output += 16;
174
175 vacc = _mm512_add_ps(vacc, vf);
176 }
177 if (elements != 0) {
178 // Prepare mask for valid 32-bit elements (depends on elements).
179 elements >>= 2 /* log2(sizeof(float)) */;
180 const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << elements) - UINT32_C(1)));
181
182 const __m512 vi = _mm512_maskz_loadu_ps(vmask, input);
183
184 const __m512 vx = _mm512_sub_ps(vi, vi_max);
185
186 const __m512 vn = _mm512_roundscale_ps(_mm512_mul_ps(vx, vlog2e), 0);
187
188 const __m512 vt = _mm512_fmadd_ps(vn, vminus_ln2, vx);
189
190 __m512 vp = _mm512_fmadd_ps(vc5, vt, vc4);
191 vp = _mm512_fmadd_ps(vp, vt, vc3);
192 vp = _mm512_fmadd_ps(vp, vt, vc2);
193 vp = _mm512_fmadd_ps(vp, vt, vc1);
194 vp = _mm512_fmadd_ps(vp, vt, vc0);
195
196 const __m512 vf = _mm512_scalef_ps(vp, vn);
197
198 _mm512_mask_storeu_ps(output, vmask, vf);
199
200 vacc = _mm512_mask_add_ps(vacc, vmask, vacc, vf);
201 }
202 *sum = _mm512_reduce_add_ps(vacc);
203 }
204