xref: /aosp_15_r20/external/XNNPACK/src/f32-raddextexp/gen/avx2-p5-x72-acc3.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-raddextexp/avx2-p5.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 #include <math.h>
12 
13 #include <immintrin.h>
14 
15 #include <xnnpack/raddextexp.h>
16 
17 
18 static const int32_t mask_table[14] = {-1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0};
19 
xnn_f32_raddextexp_ukernel__avx2_p5_x72_acc3(size_t elements,const float * x,float * sum)20 void xnn_f32_raddextexp_ukernel__avx2_p5_x72_acc3(
21     size_t elements,
22     const float* x,
23     float* sum)
24 {
25   assert(elements % sizeof(float) == 0);
26 
27   const __m256 vlog2e = _mm256_set1_ps(0x1.715476p+0f);
28   const __m256 vminus_ln2_hi = _mm256_set1_ps(-0x1.62E43p-1f);
29   const __m256 vminus_ln2_lo = _mm256_set1_ps(0x1.05C61p-29f);
30 
31   // The smallest elements such that 2**elements is considered non-negligible.
32   // For smaller elements, 2**elements is replaced with zero.
33   const __m256 vmin_exponent = _mm256_set1_ps(-127.0f);
34   const __m256 vmagic_bias = _mm256_set1_ps(0x1.8000FEp23f);
35   const __m256 vminus_inf = _mm256_set1_ps(-INFINITY);
36 
37   const __m256 vc0 = _mm256_set1_ps(1.0f);
38   const __m256 vc1 = _mm256_set1_ps(0x1.FFFFF6p-1f);
39   const __m256 vc2 = _mm256_set1_ps(0x1.FFFDC6p-2f);
40   const __m256 vc3 = _mm256_set1_ps(0x1.555A80p-3f);
41   const __m256 vc4 = _mm256_set1_ps(0x1.573A1Ap-5f);
42   const __m256 vc5 = _mm256_set1_ps(0x1.0F9F9Cp-7f);
43 
44   __m256 vaccv0 = _mm256_setzero_ps();
45   __m256 vaccv1 = _mm256_setzero_ps();
46   __m256 vaccv2 = _mm256_setzero_ps();
47   __m256 vacce0 = vminus_inf;
48   __m256 vacce1 = vminus_inf;
49   __m256 vacce2 = vminus_inf;
50   for (; elements >= 72 * sizeof(float); elements -= 72 * sizeof(float)) {
51     // Load 72 (9x8) inputs at a time.
52     const __m256 vx0 = _mm256_loadu_ps(x);
53     const __m256 vx1 = _mm256_loadu_ps(x + 8);
54     const __m256 vx2 = _mm256_loadu_ps(x + 16);
55     const __m256 vx3 = _mm256_loadu_ps(x + 24);
56     const __m256 vx4 = _mm256_loadu_ps(x + 32);
57     const __m256 vx5 = _mm256_loadu_ps(x + 40);
58     const __m256 vx6 = _mm256_loadu_ps(x + 48);
59     const __m256 vx7 = _mm256_loadu_ps(x + 56);
60     const __m256 vx8 = _mm256_loadu_ps(x + 64);
61     x += 72;
62 
63     // Compute reduced argument elements := round(x / log(2)).
64     const __m256 vn0 = _mm256_round_ps(_mm256_mul_ps(vx0, vlog2e), _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
65     const __m256 vn1 = _mm256_round_ps(_mm256_mul_ps(vx1, vlog2e), _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
66     const __m256 vn2 = _mm256_round_ps(_mm256_mul_ps(vx2, vlog2e), _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
67     const __m256 vn3 = _mm256_round_ps(_mm256_mul_ps(vx3, vlog2e), _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
68     const __m256 vn4 = _mm256_round_ps(_mm256_mul_ps(vx4, vlog2e), _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
69     const __m256 vn5 = _mm256_round_ps(_mm256_mul_ps(vx5, vlog2e), _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
70     const __m256 vn6 = _mm256_round_ps(_mm256_mul_ps(vx6, vlog2e), _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
71     const __m256 vn7 = _mm256_round_ps(_mm256_mul_ps(vx7, vlog2e), _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
72     const __m256 vn8 = _mm256_round_ps(_mm256_mul_ps(vx8, vlog2e), _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
73 
74     // Compute reduced argument t := x - elements * log(2).
75     // Use Cody-Waite range reduction method (note two constants to represent log(2)) to improve accuracy.
76     __m256 vt0 = _mm256_fmadd_ps(vn0, vminus_ln2_hi, vx0);
77     __m256 vt1 = _mm256_fmadd_ps(vn1, vminus_ln2_hi, vx1);
78     __m256 vt2 = _mm256_fmadd_ps(vn2, vminus_ln2_hi, vx2);
79     __m256 vt3 = _mm256_fmadd_ps(vn3, vminus_ln2_hi, vx3);
80     __m256 vt4 = _mm256_fmadd_ps(vn4, vminus_ln2_hi, vx4);
81     __m256 vt5 = _mm256_fmadd_ps(vn5, vminus_ln2_hi, vx5);
82     __m256 vt6 = _mm256_fmadd_ps(vn6, vminus_ln2_hi, vx6);
83     __m256 vt7 = _mm256_fmadd_ps(vn7, vminus_ln2_hi, vx7);
84     __m256 vt8 = _mm256_fmadd_ps(vn8, vminus_ln2_hi, vx8);
85 
86     vt0 = _mm256_fmadd_ps(vn0, vminus_ln2_lo, vt0);
87     vt1 = _mm256_fmadd_ps(vn1, vminus_ln2_lo, vt1);
88     vt2 = _mm256_fmadd_ps(vn2, vminus_ln2_lo, vt2);
89     vt3 = _mm256_fmadd_ps(vn3, vminus_ln2_lo, vt3);
90     vt4 = _mm256_fmadd_ps(vn4, vminus_ln2_lo, vt4);
91     vt5 = _mm256_fmadd_ps(vn5, vminus_ln2_lo, vt5);
92     vt6 = _mm256_fmadd_ps(vn6, vminus_ln2_lo, vt6);
93     vt7 = _mm256_fmadd_ps(vn7, vminus_ln2_lo, vt7);
94     vt8 = _mm256_fmadd_ps(vn8, vminus_ln2_lo, vt8);
95 
96     // Compute degree-5 polynomial approximation for exp(t) on [-log(2)/2, log(2)/2].
97     __m256 vp0 = _mm256_fmadd_ps(vc5, vt0, vc4);
98     __m256 vp1 = _mm256_fmadd_ps(vc5, vt1, vc4);
99     __m256 vp2 = _mm256_fmadd_ps(vc5, vt2, vc4);
100     __m256 vp3 = _mm256_fmadd_ps(vc5, vt3, vc4);
101     __m256 vp4 = _mm256_fmadd_ps(vc5, vt4, vc4);
102     __m256 vp5 = _mm256_fmadd_ps(vc5, vt5, vc4);
103     __m256 vp6 = _mm256_fmadd_ps(vc5, vt6, vc4);
104     __m256 vp7 = _mm256_fmadd_ps(vc5, vt7, vc4);
105     __m256 vp8 = _mm256_fmadd_ps(vc5, vt8, vc4);
106 
107     vp0 = _mm256_fmadd_ps(vp0, vt0, vc3);
108     vp1 = _mm256_fmadd_ps(vp1, vt1, vc3);
109     vp2 = _mm256_fmadd_ps(vp2, vt2, vc3);
110     vp3 = _mm256_fmadd_ps(vp3, vt3, vc3);
111     vp4 = _mm256_fmadd_ps(vp4, vt4, vc3);
112     vp5 = _mm256_fmadd_ps(vp5, vt5, vc3);
113     vp6 = _mm256_fmadd_ps(vp6, vt6, vc3);
114     vp7 = _mm256_fmadd_ps(vp7, vt7, vc3);
115     vp8 = _mm256_fmadd_ps(vp8, vt8, vc3);
116 
117     vp0 = _mm256_fmadd_ps(vp0, vt0, vc2);
118     vp1 = _mm256_fmadd_ps(vp1, vt1, vc2);
119     vp2 = _mm256_fmadd_ps(vp2, vt2, vc2);
120     vp3 = _mm256_fmadd_ps(vp3, vt3, vc2);
121     vp4 = _mm256_fmadd_ps(vp4, vt4, vc2);
122     vp5 = _mm256_fmadd_ps(vp5, vt5, vc2);
123     vp6 = _mm256_fmadd_ps(vp6, vt6, vc2);
124     vp7 = _mm256_fmadd_ps(vp7, vt7, vc2);
125     vp8 = _mm256_fmadd_ps(vp8, vt8, vc2);
126 
127     vp0 = _mm256_fmadd_ps(vp0, vt0, vc1);
128     vp1 = _mm256_fmadd_ps(vp1, vt1, vc1);
129     vp2 = _mm256_fmadd_ps(vp2, vt2, vc1);
130     vp3 = _mm256_fmadd_ps(vp3, vt3, vc1);
131     vp4 = _mm256_fmadd_ps(vp4, vt4, vc1);
132     vp5 = _mm256_fmadd_ps(vp5, vt5, vc1);
133     vp6 = _mm256_fmadd_ps(vp6, vt6, vc1);
134     vp7 = _mm256_fmadd_ps(vp7, vt7, vc1);
135     vp8 = _mm256_fmadd_ps(vp8, vt8, vc1);
136 
137     vp0 = _mm256_fmadd_ps(vp0, vt0, vc0);
138     vp1 = _mm256_fmadd_ps(vp1, vt1, vc0);
139     vp2 = _mm256_fmadd_ps(vp2, vt2, vc0);
140     vp3 = _mm256_fmadd_ps(vp3, vt3, vc0);
141     vp4 = _mm256_fmadd_ps(vp4, vt4, vc0);
142     vp5 = _mm256_fmadd_ps(vp5, vt5, vc0);
143     vp6 = _mm256_fmadd_ps(vp6, vt6, vc0);
144     vp7 = _mm256_fmadd_ps(vp7, vt7, vc0);
145     vp8 = _mm256_fmadd_ps(vp8, vt8, vc0);
146 
147     // Accumulate "extended" floating-point numbers in ("mantissa", "exponent") representation where
148     //  - vnX is "exponent"
149     //  - vpX is "mantissa"
150     //
151     // exp2(ae) * av + exp2(be) * bv =
152     //   = exp2(max(ae, be)) * exp2(ae - max(ae, be)) * av + exp2(max(ae, be)) * exp2(be - max(ae, be)) * bv
153     //   = exp2(max_e) * (exp2(ae - max_e) * av + exp2(be - max_e) * bv)
154     //   = exp2(max_e) * (exp2(delta_ae) * av + exp2(delta_be) * bv)
155     //
156     // For computational efficiency we may add several "extended" floating-point numbers at a time.
157     __m256 vmax_e0 = _mm256_max_ps(vacce0, vn0);
158     __m256 vmax_e1 = _mm256_max_ps(vacce1, vn1);
159     __m256 vmax_e2 = _mm256_max_ps(vacce2, vn2);
160     vmax_e0 = _mm256_max_ps(vmax_e0, vn3);
161     vmax_e1 = _mm256_max_ps(vmax_e1, vn4);
162     vmax_e2 = _mm256_max_ps(vmax_e2, vn5);
163     vmax_e0 = _mm256_max_ps(vmax_e0, vn6);
164     vmax_e1 = _mm256_max_ps(vmax_e1, vn7);
165     vmax_e2 = _mm256_max_ps(vmax_e2, vn8);
166 
167     // For computational efficiency, replace exp2(delta_e) with 0.0f when delta_e <= -127.0.
168     // This replacement is done in two steps:
169     // 1. Clamp minimum delta_e at -127.0.
170     // 2. Map delta_e to scale factor 0.0 when delta_e == -127.0
171     const __m256 vdelta_acce0 = _mm256_max_ps(_mm256_sub_ps(vacce0, vmax_e0), vmin_exponent);
172     const __m256 vdelta_acce1 = _mm256_max_ps(_mm256_sub_ps(vacce1, vmax_e1), vmin_exponent);
173     const __m256 vdelta_acce2 = _mm256_max_ps(_mm256_sub_ps(vacce2, vmax_e2), vmin_exponent);
174     const __m256 vdelta_e0 = _mm256_max_ps(_mm256_sub_ps(vn0, vmax_e0), vmin_exponent);
175     const __m256 vdelta_e1 = _mm256_max_ps(_mm256_sub_ps(vn1, vmax_e1), vmin_exponent);
176     const __m256 vdelta_e2 = _mm256_max_ps(_mm256_sub_ps(vn2, vmax_e2), vmin_exponent);
177     const __m256 vdelta_e3 = _mm256_max_ps(_mm256_sub_ps(vn3, vmax_e0), vmin_exponent);
178     const __m256 vdelta_e4 = _mm256_max_ps(_mm256_sub_ps(vn4, vmax_e1), vmin_exponent);
179     const __m256 vdelta_e5 = _mm256_max_ps(_mm256_sub_ps(vn5, vmax_e2), vmin_exponent);
180     const __m256 vdelta_e6 = _mm256_max_ps(_mm256_sub_ps(vn6, vmax_e0), vmin_exponent);
181     const __m256 vdelta_e7 = _mm256_max_ps(_mm256_sub_ps(vn7, vmax_e1), vmin_exponent);
182     const __m256 vdelta_e8 = _mm256_max_ps(_mm256_sub_ps(vn8, vmax_e2), vmin_exponent);
183 
184     // Convert delta-exponents into scale factors:
185     // - s = exp2(delta_e) when delta_e > -127.0
186     // - s = 0.0 when delta_e <= -127.0
187     //
188     // Note: delta-exponents can not exceed 0.0, thus scale factors can not exceed 1.0.
189     const __m256 vaccs0 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_acce0, vmagic_bias)), 23));
190     const __m256 vaccs1 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_acce1, vmagic_bias)), 23));
191     const __m256 vaccs2 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_acce2, vmagic_bias)), 23));
192     const __m256 vs0 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_e0, vmagic_bias)), 23));
193     const __m256 vs1 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_e1, vmagic_bias)), 23));
194     const __m256 vs2 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_e2, vmagic_bias)), 23));
195     const __m256 vs3 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_e3, vmagic_bias)), 23));
196     const __m256 vs4 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_e4, vmagic_bias)), 23));
197     const __m256 vs5 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_e5, vmagic_bias)), 23));
198     const __m256 vs6 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_e6, vmagic_bias)), 23));
199     const __m256 vs7 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_e7, vmagic_bias)), 23));
200     const __m256 vs8 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_e8, vmagic_bias)), 23));
201 
202     // Update accumulated "mantissa" and "exponent" values
203     vaccv0 = _mm256_mul_ps(vaccv0, vaccs0);
204     vaccv1 = _mm256_mul_ps(vaccv1, vaccs1);
205     vaccv2 = _mm256_mul_ps(vaccv2, vaccs2);
206     vaccv0 = _mm256_fmadd_ps(vp0, vs0, vaccv0);
207     vaccv1 = _mm256_fmadd_ps(vp1, vs1, vaccv1);
208     vaccv2 = _mm256_fmadd_ps(vp2, vs2, vaccv2);
209     vaccv0 = _mm256_fmadd_ps(vp3, vs3, vaccv0);
210     vaccv1 = _mm256_fmadd_ps(vp4, vs4, vaccv1);
211     vaccv2 = _mm256_fmadd_ps(vp5, vs5, vaccv2);
212     vaccv0 = _mm256_fmadd_ps(vp6, vs6, vaccv0);
213     vaccv1 = _mm256_fmadd_ps(vp7, vs7, vaccv1);
214     vaccv2 = _mm256_fmadd_ps(vp8, vs8, vaccv2);
215 
216     vacce0 = vmax_e0;
217     vacce1 = vmax_e1;
218     vacce2 = vmax_e2;
219   }
220 
221   // Reduce partial sums of "extended" floating-point numbers into a single "extended" SIMD vector of sums.
222   const __m256 vmax_acce01 = _mm256_max_ps(vacce0, vacce1);
223   const __m256 vmax_acce2 = vacce2;
224   const __m256 vmax_acce012 = _mm256_max_ps(vmax_acce01, vmax_acce2);
225 
226   const __m256 vdelta_acce0 = _mm256_max_ps(_mm256_sub_ps(vacce0, vmax_acce012), vmin_exponent);
227   const __m256 vdelta_acce1 = _mm256_max_ps(_mm256_sub_ps(vacce1, vmax_acce012), vmin_exponent);
228   const __m256 vdelta_acce2 = _mm256_max_ps(_mm256_sub_ps(vacce2, vmax_acce012), vmin_exponent);
229 
230   const __m256 vaccs0 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_acce0, vmagic_bias)), 23));
231   const __m256 vaccs1 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_acce1, vmagic_bias)), 23));
232   const __m256 vaccs2 = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_acce2, vmagic_bias)), 23));
233 
234   __m256 vaccv = _mm256_mul_ps(vaccv0, vaccs0);
235   vaccv = _mm256_fmadd_ps(vaccv1, vaccs1, vaccv);
236   vaccv = _mm256_fmadd_ps(vaccv2, vaccs2, vaccv);
237   __m256 vacce = vmax_acce012;
238 
239   for (; elements >= 8 * sizeof(float); elements -= 8 * sizeof(float)) {
240     // Load 8 inputs at a time.
241     const __m256 vx = _mm256_loadu_ps(x);
242     x += 8;
243 
244     // Compute reduced argument elements := round(x / log(2)).
245     const __m256 vn = _mm256_round_ps(_mm256_mul_ps(vx, vlog2e), _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
246 
247     // Compute reduced argument t := x - elements * log(2).
248     // Use Cody-Waite range reduction method (note two constants to represent log(2)) to improve accuracy.
249     __m256 vt = _mm256_fmadd_ps(vn, vminus_ln2_hi, vx);
250     vt = _mm256_fmadd_ps(vn, vminus_ln2_lo, vt);
251 
252     // Compute degree-5 polynomial approximation for exp(t) on [-log(2)/2, log(2)/2].
253     __m256 vp = _mm256_fmadd_ps(vc5, vt, vc4);
254     vp = _mm256_fmadd_ps(vp, vt, vc3);
255     vp = _mm256_fmadd_ps(vp, vt, vc2);
256     vp = _mm256_fmadd_ps(vp, vt, vc1);
257     vp = _mm256_fmadd_ps(vp, vt, vc0);
258 
259     // Accumulate "extended" floating-point numbers in ("mantissa", "exponent") representation.
260     const __m256 vmax_e = _mm256_max_ps(vacce, vn);
261 
262     // For computational efficiency, clamp minimum exp2(delta_e) at -127.0. It will be mapped to 0.0 scale factor later.
263     const __m256 vdelta_acce = _mm256_max_ps(_mm256_sub_ps(vacce, vmax_e), vmin_exponent);
264     const __m256 vdelta_e = _mm256_max_ps(_mm256_sub_ps(vn, vmax_e), vmin_exponent);
265 
266     // Convert exponents into scale factors.
267     const __m256 vaccs = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_acce, vmagic_bias)), 23));
268     const __m256 vs = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_e, vmagic_bias)), 23));
269 
270     // Update accumulated "mantissa" and "exponent" values.
271     vaccv = _mm256_mul_ps(vaccv, vaccs);
272     vaccv = _mm256_fmadd_ps(vp, vs, vaccv);
273 
274     vacce = vmax_e;
275   }
276   if XNN_UNLIKELY(elements != 0) {
277     assert(elements >= 1 * sizeof(float));
278     assert(elements <= 7 * sizeof(float));
279     const __m256i vmask = _mm256_loadu_si256((const __m256i*) ((uintptr_t) &mask_table[7] - elements));
280 
281     // Load up to 7 inputs at a time.
282     const __m256 vx = _mm256_maskload_ps(x, vmask);
283 
284     // Compute reduced argument elements := round(x / log(2)).
285     __m256 vn = _mm256_round_ps(_mm256_mul_ps(vx, vlog2e), _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
286 
287     // Compute reduced argument t := x - elements * log(2).
288     // Use Cody-Waite range reduction method (note two constants to represent log(2)) to improve accuracy.
289     __m256 vt = _mm256_fmadd_ps(vn, vminus_ln2_hi, vx);
290     vt = _mm256_fmadd_ps(vn, vminus_ln2_lo, vt);
291 
292     // Correct reduced argument elements for masked out elements.
293     vn = _mm256_blendv_ps(vacce, vn, _mm256_castsi256_ps(vmask));
294 
295     // Compute degree-5 polynomial approximation for exp(t) on [-log(2)/2, log(2)/2].
296     __m256 vp = _mm256_fmadd_ps(vc5, vt, vc4);
297     vp = _mm256_fmadd_ps(vp, vt, vc3);
298     vp = _mm256_fmadd_ps(vp, vt, vc2);
299     vp = _mm256_fmadd_ps(vp, vt, vc1);
300     vp = _mm256_fmadd_ps(vp, vt, vc0);
301     vp = _mm256_and_ps(vp, _mm256_castsi256_ps(vmask));
302 
303     // Accumulate "extended" floating-point numbers in ("mantissa", "exponent") representation.
304     const __m256 vmax_e = _mm256_max_ps(vacce, vn);
305 
306     // For computational efficiency, clamp minimum exp2(delta_e) at -127.0. It will be mapped to 0.0 scale factor later.
307     const __m256 vdelta_e = _mm256_max_ps(_mm256_sub_ps(vn, vmax_e), vmin_exponent);
308     const __m256 vdelta_acce = _mm256_max_ps(_mm256_sub_ps(vacce, vmax_e), vmin_exponent);
309 
310     // Convert exponents into scale factors.
311     const __m256 vs = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_e, vmagic_bias)), 23));
312     const __m256 vaccs = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_acce, vmagic_bias)), 23));
313 
314     // Update accumulated "mantissa" and "exponent" values.
315     vaccv = _mm256_mul_ps(vaccv, vaccs);
316     vaccv = _mm256_fmadd_ps(vp, vs, vaccv);
317 
318     vacce = vmax_e;
319   }
320 
321   // Reduce partial sums of "extended" floating-point numbers into a single "extended" floating-point sum.
322   __m256 vmax_acce = _mm256_max_ps(vacce, _mm256_permute2f128_ps(vacce, vacce, 1));
323   vmax_acce = _mm256_max_ps(vmax_acce, _mm256_shuffle_ps(vmax_acce, vmax_acce, _MM_SHUFFLE(1, 0, 3, 2)));
324   vmax_acce = _mm256_max_ps(vmax_acce, _mm256_shuffle_ps(vmax_acce, vmax_acce, _MM_SHUFFLE(2, 3, 0, 1)));
325   const __m256 vdelta_acce = _mm256_max_ps(_mm256_sub_ps(vacce, vmax_acce), vmin_exponent);
326   const __m256 vaccs = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(_mm256_add_ps(vdelta_acce, vmagic_bias)), 23));
327 
328   vaccv = _mm256_mul_ps(vaccv, vaccs);
329   __m128 vaccv_sum = _mm_add_ps(_mm256_castps256_ps128(vaccv), _mm256_extractf128_ps(vaccv, 1));
330   vaccv_sum = _mm_add_ps(vaccv_sum, _mm_movehl_ps(vaccv_sum, vaccv_sum));
331   vaccv_sum = _mm_add_ss(vaccv_sum, _mm_movehdup_ps(vaccv_sum));
332 
333   _mm_store_ss(&sum[0], vaccv_sum);
334   _mm_store_ss(&sum[1], _mm256_castps256_ps128(vmax_acce));
335 
336   _mm256_zeroupper();
337 }
338