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_x192(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_x192(
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 for (; elements >= 192 * sizeof(float); elements -= 192 * sizeof(float)) {
40 const __m512 vi0 = _mm512_loadu_ps(input);
41 const __m512 vi1 = _mm512_loadu_ps(input + 16);
42 const __m512 vi2 = _mm512_loadu_ps(input + 32);
43 const __m512 vi3 = _mm512_loadu_ps(input + 48);
44 const __m512 vi4 = _mm512_loadu_ps(input + 64);
45 const __m512 vi5 = _mm512_loadu_ps(input + 80);
46 const __m512 vi6 = _mm512_loadu_ps(input + 96);
47 const __m512 vi7 = _mm512_loadu_ps(input + 112);
48 const __m512 vi8 = _mm512_loadu_ps(input + 128);
49 const __m512 vi9 = _mm512_loadu_ps(input + 144);
50 const __m512 vi10 = _mm512_loadu_ps(input + 160);
51 const __m512 vi11 = _mm512_loadu_ps(input + 176);
52 input += 192;
53
54 const __m512 vx0 = _mm512_sub_ps(vi0, vi_max);
55 const __m512 vx1 = _mm512_sub_ps(vi1, vi_max);
56 const __m512 vx2 = _mm512_sub_ps(vi2, vi_max);
57 const __m512 vx3 = _mm512_sub_ps(vi3, vi_max);
58 const __m512 vx4 = _mm512_sub_ps(vi4, vi_max);
59 const __m512 vx5 = _mm512_sub_ps(vi5, vi_max);
60 const __m512 vx6 = _mm512_sub_ps(vi6, vi_max);
61 const __m512 vx7 = _mm512_sub_ps(vi7, vi_max);
62 const __m512 vx8 = _mm512_sub_ps(vi8, vi_max);
63 const __m512 vx9 = _mm512_sub_ps(vi9, vi_max);
64 const __m512 vx10 = _mm512_sub_ps(vi10, vi_max);
65 const __m512 vx11 = _mm512_sub_ps(vi11, vi_max);
66
67 const __m512 vn0 = _mm512_roundscale_ps(_mm512_mul_ps(vx0, vlog2e), 0);
68 const __m512 vn1 = _mm512_roundscale_ps(_mm512_mul_ps(vx1, vlog2e), 0);
69 const __m512 vn2 = _mm512_roundscale_ps(_mm512_mul_ps(vx2, vlog2e), 0);
70 const __m512 vn3 = _mm512_roundscale_ps(_mm512_mul_ps(vx3, vlog2e), 0);
71 const __m512 vn4 = _mm512_roundscale_ps(_mm512_mul_ps(vx4, vlog2e), 0);
72 const __m512 vn5 = _mm512_roundscale_ps(_mm512_mul_ps(vx5, vlog2e), 0);
73 const __m512 vn6 = _mm512_roundscale_ps(_mm512_mul_ps(vx6, vlog2e), 0);
74 const __m512 vn7 = _mm512_roundscale_ps(_mm512_mul_ps(vx7, vlog2e), 0);
75 const __m512 vn8 = _mm512_roundscale_ps(_mm512_mul_ps(vx8, vlog2e), 0);
76 const __m512 vn9 = _mm512_roundscale_ps(_mm512_mul_ps(vx9, vlog2e), 0);
77 const __m512 vn10 = _mm512_roundscale_ps(_mm512_mul_ps(vx10, vlog2e), 0);
78 const __m512 vn11 = _mm512_roundscale_ps(_mm512_mul_ps(vx11, vlog2e), 0);
79
80 const __m512 vt0 = _mm512_fmadd_ps(vn0, vminus_ln2, vx0);
81 const __m512 vt1 = _mm512_fmadd_ps(vn1, vminus_ln2, vx1);
82 const __m512 vt2 = _mm512_fmadd_ps(vn2, vminus_ln2, vx2);
83 const __m512 vt3 = _mm512_fmadd_ps(vn3, vminus_ln2, vx3);
84 const __m512 vt4 = _mm512_fmadd_ps(vn4, vminus_ln2, vx4);
85 const __m512 vt5 = _mm512_fmadd_ps(vn5, vminus_ln2, vx5);
86 const __m512 vt6 = _mm512_fmadd_ps(vn6, vminus_ln2, vx6);
87 const __m512 vt7 = _mm512_fmadd_ps(vn7, vminus_ln2, vx7);
88 const __m512 vt8 = _mm512_fmadd_ps(vn8, vminus_ln2, vx8);
89 const __m512 vt9 = _mm512_fmadd_ps(vn9, vminus_ln2, vx9);
90 const __m512 vt10 = _mm512_fmadd_ps(vn10, vminus_ln2, vx10);
91 const __m512 vt11 = _mm512_fmadd_ps(vn11, vminus_ln2, vx11);
92
93 __m512 vp0 = _mm512_fmadd_ps(vc5, vt0, vc4);
94 __m512 vp1 = _mm512_fmadd_ps(vc5, vt1, vc4);
95 __m512 vp2 = _mm512_fmadd_ps(vc5, vt2, vc4);
96 __m512 vp3 = _mm512_fmadd_ps(vc5, vt3, vc4);
97 __m512 vp4 = _mm512_fmadd_ps(vc5, vt4, vc4);
98 __m512 vp5 = _mm512_fmadd_ps(vc5, vt5, vc4);
99 __m512 vp6 = _mm512_fmadd_ps(vc5, vt6, vc4);
100 __m512 vp7 = _mm512_fmadd_ps(vc5, vt7, vc4);
101 __m512 vp8 = _mm512_fmadd_ps(vc5, vt8, vc4);
102 __m512 vp9 = _mm512_fmadd_ps(vc5, vt9, vc4);
103 __m512 vp10 = _mm512_fmadd_ps(vc5, vt10, vc4);
104 __m512 vp11 = _mm512_fmadd_ps(vc5, vt11, vc4);
105
106 vp0 = _mm512_fmadd_ps(vp0, vt0, vc3);
107 vp1 = _mm512_fmadd_ps(vp1, vt1, vc3);
108 vp2 = _mm512_fmadd_ps(vp2, vt2, vc3);
109 vp3 = _mm512_fmadd_ps(vp3, vt3, vc3);
110 vp4 = _mm512_fmadd_ps(vp4, vt4, vc3);
111 vp5 = _mm512_fmadd_ps(vp5, vt5, vc3);
112 vp6 = _mm512_fmadd_ps(vp6, vt6, vc3);
113 vp7 = _mm512_fmadd_ps(vp7, vt7, vc3);
114 vp8 = _mm512_fmadd_ps(vp8, vt8, vc3);
115 vp9 = _mm512_fmadd_ps(vp9, vt9, vc3);
116 vp10 = _mm512_fmadd_ps(vp10, vt10, vc3);
117 vp11 = _mm512_fmadd_ps(vp11, vt11, vc3);
118
119 vp0 = _mm512_fmadd_ps(vp0, vt0, vc2);
120 vp1 = _mm512_fmadd_ps(vp1, vt1, vc2);
121 vp2 = _mm512_fmadd_ps(vp2, vt2, vc2);
122 vp3 = _mm512_fmadd_ps(vp3, vt3, vc2);
123 vp4 = _mm512_fmadd_ps(vp4, vt4, vc2);
124 vp5 = _mm512_fmadd_ps(vp5, vt5, vc2);
125 vp6 = _mm512_fmadd_ps(vp6, vt6, vc2);
126 vp7 = _mm512_fmadd_ps(vp7, vt7, vc2);
127 vp8 = _mm512_fmadd_ps(vp8, vt8, vc2);
128 vp9 = _mm512_fmadd_ps(vp9, vt9, vc2);
129 vp10 = _mm512_fmadd_ps(vp10, vt10, vc2);
130 vp11 = _mm512_fmadd_ps(vp11, vt11, vc2);
131
132 vp0 = _mm512_fmadd_ps(vp0, vt0, vc1);
133 vp1 = _mm512_fmadd_ps(vp1, vt1, vc1);
134 vp2 = _mm512_fmadd_ps(vp2, vt2, vc1);
135 vp3 = _mm512_fmadd_ps(vp3, vt3, vc1);
136 vp4 = _mm512_fmadd_ps(vp4, vt4, vc1);
137 vp5 = _mm512_fmadd_ps(vp5, vt5, vc1);
138 vp6 = _mm512_fmadd_ps(vp6, vt6, vc1);
139 vp7 = _mm512_fmadd_ps(vp7, vt7, vc1);
140 vp8 = _mm512_fmadd_ps(vp8, vt8, vc1);
141 vp9 = _mm512_fmadd_ps(vp9, vt9, vc1);
142 vp10 = _mm512_fmadd_ps(vp10, vt10, vc1);
143 vp11 = _mm512_fmadd_ps(vp11, vt11, vc1);
144
145 vp0 = _mm512_fmadd_ps(vp0, vt0, vc0);
146 vp1 = _mm512_fmadd_ps(vp1, vt1, vc0);
147 vp2 = _mm512_fmadd_ps(vp2, vt2, vc0);
148 vp3 = _mm512_fmadd_ps(vp3, vt3, vc0);
149 vp4 = _mm512_fmadd_ps(vp4, vt4, vc0);
150 vp5 = _mm512_fmadd_ps(vp5, vt5, vc0);
151 vp6 = _mm512_fmadd_ps(vp6, vt6, vc0);
152 vp7 = _mm512_fmadd_ps(vp7, vt7, vc0);
153 vp8 = _mm512_fmadd_ps(vp8, vt8, vc0);
154 vp9 = _mm512_fmadd_ps(vp9, vt9, vc0);
155 vp10 = _mm512_fmadd_ps(vp10, vt10, vc0);
156 vp11 = _mm512_fmadd_ps(vp11, vt11, vc0);
157
158 const __m512 vf0 = _mm512_scalef_ps(vp0, vn0);
159 const __m512 vf1 = _mm512_scalef_ps(vp1, vn1);
160 const __m512 vf2 = _mm512_scalef_ps(vp2, vn2);
161 const __m512 vf3 = _mm512_scalef_ps(vp3, vn3);
162 const __m512 vf4 = _mm512_scalef_ps(vp4, vn4);
163 const __m512 vf5 = _mm512_scalef_ps(vp5, vn5);
164 const __m512 vf6 = _mm512_scalef_ps(vp6, vn6);
165 const __m512 vf7 = _mm512_scalef_ps(vp7, vn7);
166 const __m512 vf8 = _mm512_scalef_ps(vp8, vn8);
167 const __m512 vf9 = _mm512_scalef_ps(vp9, vn9);
168 const __m512 vf10 = _mm512_scalef_ps(vp10, vn10);
169 const __m512 vf11 = _mm512_scalef_ps(vp11, vn11);
170
171 _mm512_storeu_ps(output, vf0);
172 _mm512_storeu_ps(output + 16, vf1);
173 _mm512_storeu_ps(output + 32, vf2);
174 _mm512_storeu_ps(output + 48, vf3);
175 _mm512_storeu_ps(output + 64, vf4);
176 _mm512_storeu_ps(output + 80, vf5);
177 _mm512_storeu_ps(output + 96, vf6);
178 _mm512_storeu_ps(output + 112, vf7);
179 _mm512_storeu_ps(output + 128, vf8);
180 _mm512_storeu_ps(output + 144, vf9);
181 _mm512_storeu_ps(output + 160, vf10);
182 _mm512_storeu_ps(output + 176, vf11);
183 output += 192;
184
185 vacc0 = _mm512_add_ps(vacc0, vf0);
186 vacc0 = _mm512_add_ps(vacc0, vf1);
187 vacc0 = _mm512_add_ps(vacc0, vf2);
188 vacc0 = _mm512_add_ps(vacc0, vf3);
189 vacc0 = _mm512_add_ps(vacc0, vf4);
190 vacc0 = _mm512_add_ps(vacc0, vf5);
191 vacc0 = _mm512_add_ps(vacc0, vf6);
192 vacc0 = _mm512_add_ps(vacc0, vf7);
193 vacc0 = _mm512_add_ps(vacc0, vf8);
194 vacc0 = _mm512_add_ps(vacc0, vf9);
195 vacc0 = _mm512_add_ps(vacc0, vf10);
196 vacc0 = _mm512_add_ps(vacc0, vf11);
197 }
198
199 __m512 vacc = vacc0;
200 for (; elements >= 16 * sizeof(float); elements -= 16 * sizeof(float)) {
201 const __m512 vi = _mm512_loadu_ps(input);
202 input += 16;
203
204 const __m512 vx = _mm512_sub_ps(vi, vi_max);
205
206 const __m512 vn = _mm512_roundscale_ps(_mm512_mul_ps(vx, vlog2e), 0);
207
208 const __m512 vt = _mm512_fmadd_ps(vn, vminus_ln2, vx);
209
210 __m512 vp = _mm512_fmadd_ps(vc5, vt, vc4);
211 vp = _mm512_fmadd_ps(vp, vt, vc3);
212 vp = _mm512_fmadd_ps(vp, vt, vc2);
213 vp = _mm512_fmadd_ps(vp, vt, vc1);
214 vp = _mm512_fmadd_ps(vp, vt, vc0);
215
216 const __m512 vf = _mm512_scalef_ps(vp, vn);
217
218 _mm512_storeu_ps(output, vf);
219 output += 16;
220
221 vacc = _mm512_add_ps(vacc, vf);
222 }
223 if (elements != 0) {
224 // Prepare mask for valid 32-bit elements (depends on elements).
225 elements >>= 2 /* log2(sizeof(float)) */;
226 const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << elements) - UINT32_C(1)));
227
228 const __m512 vi = _mm512_maskz_loadu_ps(vmask, input);
229
230 const __m512 vx = _mm512_sub_ps(vi, vi_max);
231
232 const __m512 vn = _mm512_roundscale_ps(_mm512_mul_ps(vx, vlog2e), 0);
233
234 const __m512 vt = _mm512_fmadd_ps(vn, vminus_ln2, vx);
235
236 __m512 vp = _mm512_fmadd_ps(vc5, vt, vc4);
237 vp = _mm512_fmadd_ps(vp, vt, vc3);
238 vp = _mm512_fmadd_ps(vp, vt, vc2);
239 vp = _mm512_fmadd_ps(vp, vt, vc1);
240 vp = _mm512_fmadd_ps(vp, vt, vc0);
241
242 const __m512 vf = _mm512_scalef_ps(vp, vn);
243
244 _mm512_mask_storeu_ps(output, vmask, vf);
245
246 vacc = _mm512_mask_add_ps(vacc, vmask, vacc, vf);
247 }
248 *sum = _mm512_reduce_add_ps(vacc);
249 }
250