2 * Single-precision vector 2^x function.
4 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 * See https://llvm.org/LICENSE.txt for license information.
6 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13 static const float Poly
[] = {
14 /* maxerr: 0.878 ulp. */
15 0x1.416b5ep
-13f
, 0x1.5f082ep
-10f
, 0x1.3b2dep
-7f
, 0x1.c6af7cp
-5f
, 0x1.ebfbdcp
-3f
, 0x1.62e43p
-1f
17 #define C0 v_f32 (Poly[0])
18 #define C1 v_f32 (Poly[1])
19 #define C2 v_f32 (Poly[2])
20 #define C3 v_f32 (Poly[3])
21 #define C4 v_f32 (Poly[4])
22 #define C5 v_f32 (Poly[5])
24 #define Shift v_f32 (0x1.8p23f)
25 #define InvLn2 v_f32 (0x1.715476p+0f)
26 #define Ln2hi v_f32 (0x1.62e4p-1f)
27 #define Ln2lo v_f32 (0x1.7f7d1cp-20f)
31 specialcase (v_f32_t poly
, v_f32_t n
, v_u32_t e
, v_f32_t absn
)
33 /* 2^n may overflow, break it up into s1*s2. */
34 v_u32_t b
= v_cond_u32 (n
<= v_f32 (0.0f
)) & v_u32 (0x83000000);
35 v_f32_t s1
= v_as_f32_u32 (v_u32 (0x7f000000) + b
);
36 v_f32_t s2
= v_as_f32_u32 (e
- b
);
37 v_u32_t cmp
= v_cond_u32 (absn
> v_f32 (192.0f
));
39 v_f32_t r0
= poly
* s1
* s2
;
40 return v_as_f32_u32 ((cmp
& v_as_u32_f32 (r1
)) | (~cmp
& v_as_u32_f32 (r0
)));
45 V_NAME(exp2f_1u
) (v_f32_t x
)
47 v_f32_t n
, r
, scale
, poly
, absn
;
50 /* exp2(x) = 2^n * poly(r), with poly(r) in [1/sqrt(2),sqrt(2)]
51 x = n + r, with r in [-1/2, 1/2]. */
57 e
= v_as_u32_f32 (z
) << 23;
61 e
= v_as_u32_s32 (v_round_s32 (x
)) << 23;
63 scale
= v_as_f32_u32 (e
+ v_u32 (0x3f800000));
65 cmp
= v_cond_u32 (absn
> v_f32 (126.0f
));
66 poly
= v_fma_f32 (C0
, r
, C1
);
67 poly
= v_fma_f32 (poly
, r
, C2
);
68 poly
= v_fma_f32 (poly
, r
, C3
);
69 poly
= v_fma_f32 (poly
, r
, C4
);
70 poly
= v_fma_f32 (poly
, r
, C5
);
71 poly
= v_fma_f32 (poly
, r
, v_f32 (1.0f
));
72 if (unlikely (v_any_u32 (cmp
)))
73 return specialcase (poly
, n
, e
, absn
);