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_x144(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_x144(
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 >= 144 * sizeof(float); elements -= 144 * 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 input += 144;
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 const __m512 vx8 = _mm512_sub_ps(vi8, vi_max);
60
61 const __m512 vn0 = _mm512_roundscale_ps(_mm512_mul_ps(vx0, vlog2e), 0);
62 const __m512 vn1 = _mm512_roundscale_ps(_mm512_mul_ps(vx1, vlog2e), 0);
63 const __m512 vn2 = _mm512_roundscale_ps(_mm512_mul_ps(vx2, vlog2e), 0);
64 const __m512 vn3 = _mm512_roundscale_ps(_mm512_mul_ps(vx3, vlog2e), 0);
65 const __m512 vn4 = _mm512_roundscale_ps(_mm512_mul_ps(vx4, vlog2e), 0);
66 const __m512 vn5 = _mm512_roundscale_ps(_mm512_mul_ps(vx5, vlog2e), 0);
67 const __m512 vn6 = _mm512_roundscale_ps(_mm512_mul_ps(vx6, vlog2e), 0);
68 const __m512 vn7 = _mm512_roundscale_ps(_mm512_mul_ps(vx7, vlog2e), 0);
69 const __m512 vn8 = _mm512_roundscale_ps(_mm512_mul_ps(vx8, vlog2e), 0);
70
71 const __m512 vt0 = _mm512_fmadd_ps(vn0, vminus_ln2, vx0);
72 const __m512 vt1 = _mm512_fmadd_ps(vn1, vminus_ln2, vx1);
73 const __m512 vt2 = _mm512_fmadd_ps(vn2, vminus_ln2, vx2);
74 const __m512 vt3 = _mm512_fmadd_ps(vn3, vminus_ln2, vx3);
75 const __m512 vt4 = _mm512_fmadd_ps(vn4, vminus_ln2, vx4);
76 const __m512 vt5 = _mm512_fmadd_ps(vn5, vminus_ln2, vx5);
77 const __m512 vt6 = _mm512_fmadd_ps(vn6, vminus_ln2, vx6);
78 const __m512 vt7 = _mm512_fmadd_ps(vn7, vminus_ln2, vx7);
79 const __m512 vt8 = _mm512_fmadd_ps(vn8, vminus_ln2, vx8);
80
81 __m512 vp0 = _mm512_fmadd_ps(vc5, vt0, vc4);
82 __m512 vp1 = _mm512_fmadd_ps(vc5, vt1, vc4);
83 __m512 vp2 = _mm512_fmadd_ps(vc5, vt2, vc4);
84 __m512 vp3 = _mm512_fmadd_ps(vc5, vt3, vc4);
85 __m512 vp4 = _mm512_fmadd_ps(vc5, vt4, vc4);
86 __m512 vp5 = _mm512_fmadd_ps(vc5, vt5, vc4);
87 __m512 vp6 = _mm512_fmadd_ps(vc5, vt6, vc4);
88 __m512 vp7 = _mm512_fmadd_ps(vc5, vt7, vc4);
89 __m512 vp8 = _mm512_fmadd_ps(vc5, vt8, vc4);
90
91 vp0 = _mm512_fmadd_ps(vp0, vt0, vc3);
92 vp1 = _mm512_fmadd_ps(vp1, vt1, vc3);
93 vp2 = _mm512_fmadd_ps(vp2, vt2, vc3);
94 vp3 = _mm512_fmadd_ps(vp3, vt3, vc3);
95 vp4 = _mm512_fmadd_ps(vp4, vt4, vc3);
96 vp5 = _mm512_fmadd_ps(vp5, vt5, vc3);
97 vp6 = _mm512_fmadd_ps(vp6, vt6, vc3);
98 vp7 = _mm512_fmadd_ps(vp7, vt7, vc3);
99 vp8 = _mm512_fmadd_ps(vp8, vt8, vc3);
100
101 vp0 = _mm512_fmadd_ps(vp0, vt0, vc2);
102 vp1 = _mm512_fmadd_ps(vp1, vt1, vc2);
103 vp2 = _mm512_fmadd_ps(vp2, vt2, vc2);
104 vp3 = _mm512_fmadd_ps(vp3, vt3, vc2);
105 vp4 = _mm512_fmadd_ps(vp4, vt4, vc2);
106 vp5 = _mm512_fmadd_ps(vp5, vt5, vc2);
107 vp6 = _mm512_fmadd_ps(vp6, vt6, vc2);
108 vp7 = _mm512_fmadd_ps(vp7, vt7, vc2);
109 vp8 = _mm512_fmadd_ps(vp8, vt8, vc2);
110
111 vp0 = _mm512_fmadd_ps(vp0, vt0, vc1);
112 vp1 = _mm512_fmadd_ps(vp1, vt1, vc1);
113 vp2 = _mm512_fmadd_ps(vp2, vt2, vc1);
114 vp3 = _mm512_fmadd_ps(vp3, vt3, vc1);
115 vp4 = _mm512_fmadd_ps(vp4, vt4, vc1);
116 vp5 = _mm512_fmadd_ps(vp5, vt5, vc1);
117 vp6 = _mm512_fmadd_ps(vp6, vt6, vc1);
118 vp7 = _mm512_fmadd_ps(vp7, vt7, vc1);
119 vp8 = _mm512_fmadd_ps(vp8, vt8, vc1);
120
121 vp0 = _mm512_fmadd_ps(vp0, vt0, vc0);
122 vp1 = _mm512_fmadd_ps(vp1, vt1, vc0);
123 vp2 = _mm512_fmadd_ps(vp2, vt2, vc0);
124 vp3 = _mm512_fmadd_ps(vp3, vt3, vc0);
125 vp4 = _mm512_fmadd_ps(vp4, vt4, vc0);
126 vp5 = _mm512_fmadd_ps(vp5, vt5, vc0);
127 vp6 = _mm512_fmadd_ps(vp6, vt6, vc0);
128 vp7 = _mm512_fmadd_ps(vp7, vt7, vc0);
129 vp8 = _mm512_fmadd_ps(vp8, vt8, vc0);
130
131 const __m512 vf0 = _mm512_scalef_ps(vp0, vn0);
132 const __m512 vf1 = _mm512_scalef_ps(vp1, vn1);
133 const __m512 vf2 = _mm512_scalef_ps(vp2, vn2);
134 const __m512 vf3 = _mm512_scalef_ps(vp3, vn3);
135 const __m512 vf4 = _mm512_scalef_ps(vp4, vn4);
136 const __m512 vf5 = _mm512_scalef_ps(vp5, vn5);
137 const __m512 vf6 = _mm512_scalef_ps(vp6, vn6);
138 const __m512 vf7 = _mm512_scalef_ps(vp7, vn7);
139 const __m512 vf8 = _mm512_scalef_ps(vp8, vn8);
140
141 _mm512_storeu_ps(output, vf0);
142 _mm512_storeu_ps(output + 16, vf1);
143 _mm512_storeu_ps(output + 32, vf2);
144 _mm512_storeu_ps(output + 48, vf3);
145 _mm512_storeu_ps(output + 64, vf4);
146 _mm512_storeu_ps(output + 80, vf5);
147 _mm512_storeu_ps(output + 96, vf6);
148 _mm512_storeu_ps(output + 112, vf7);
149 _mm512_storeu_ps(output + 128, vf8);
150 output += 144;
151
152 vacc0 = _mm512_add_ps(vacc0, vf0);
153 vacc0 = _mm512_add_ps(vacc0, vf1);
154 vacc0 = _mm512_add_ps(vacc0, vf2);
155 vacc0 = _mm512_add_ps(vacc0, vf3);
156 vacc0 = _mm512_add_ps(vacc0, vf4);
157 vacc0 = _mm512_add_ps(vacc0, vf5);
158 vacc0 = _mm512_add_ps(vacc0, vf6);
159 vacc0 = _mm512_add_ps(vacc0, vf7);
160 vacc0 = _mm512_add_ps(vacc0, vf8);
161 }
162
163 __m512 vacc = vacc0;
164 for (; elements >= 16 * sizeof(float); elements -= 16 * sizeof(float)) {
165 const __m512 vi = _mm512_loadu_ps(input);
166 input += 16;
167
168 const __m512 vx = _mm512_sub_ps(vi, vi_max);
169
170 const __m512 vn = _mm512_roundscale_ps(_mm512_mul_ps(vx, vlog2e), 0);
171
172 const __m512 vt = _mm512_fmadd_ps(vn, vminus_ln2, vx);
173
174 __m512 vp = _mm512_fmadd_ps(vc5, vt, vc4);
175 vp = _mm512_fmadd_ps(vp, vt, vc3);
176 vp = _mm512_fmadd_ps(vp, vt, vc2);
177 vp = _mm512_fmadd_ps(vp, vt, vc1);
178 vp = _mm512_fmadd_ps(vp, vt, vc0);
179
180 const __m512 vf = _mm512_scalef_ps(vp, vn);
181
182 _mm512_storeu_ps(output, vf);
183 output += 16;
184
185 vacc = _mm512_add_ps(vacc, vf);
186 }
187 if (elements != 0) {
188 // Prepare mask for valid 32-bit elements (depends on elements).
189 elements >>= 2 /* log2(sizeof(float)) */;
190 const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << elements) - UINT32_C(1)));
191
192 const __m512 vi = _mm512_maskz_loadu_ps(vmask, input);
193
194 const __m512 vx = _mm512_sub_ps(vi, vi_max);
195
196 const __m512 vn = _mm512_roundscale_ps(_mm512_mul_ps(vx, vlog2e), 0);
197
198 const __m512 vt = _mm512_fmadd_ps(vn, vminus_ln2, vx);
199
200 __m512 vp = _mm512_fmadd_ps(vc5, vt, vc4);
201 vp = _mm512_fmadd_ps(vp, vt, vc3);
202 vp = _mm512_fmadd_ps(vp, vt, vc2);
203 vp = _mm512_fmadd_ps(vp, vt, vc1);
204 vp = _mm512_fmadd_ps(vp, vt, vc0);
205
206 const __m512 vf = _mm512_scalef_ps(vp, vn);
207
208 _mm512_mask_storeu_ps(output, vmask, vf);
209
210 vacc = _mm512_mask_add_ps(vacc, vmask, vacc, vf);
211 }
212 *sum = _mm512_reduce_add_ps(vacc);
213 }
214