1*f3087befSAndrew Turner /*
2*f3087befSAndrew Turner * Double-precision vector acosh(x) function.
3*f3087befSAndrew Turner * Copyright (c) 2023-2024, Arm Limited.
4*f3087befSAndrew Turner * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
5*f3087befSAndrew Turner */
6*f3087befSAndrew Turner
7*f3087befSAndrew Turner #include "v_math.h"
8*f3087befSAndrew Turner #include "test_sig.h"
9*f3087befSAndrew Turner #include "test_defs.h"
10*f3087befSAndrew Turner
11*f3087befSAndrew Turner #define WANT_V_LOG1P_K0_SHORTCUT 1
12*f3087befSAndrew Turner #include "v_log1p_inline.h"
13*f3087befSAndrew Turner
14*f3087befSAndrew Turner const static struct data
15*f3087befSAndrew Turner {
16*f3087befSAndrew Turner struct v_log1p_data log1p_consts;
17*f3087befSAndrew Turner uint64x2_t one, thresh;
18*f3087befSAndrew Turner } data = {
19*f3087befSAndrew Turner .log1p_consts = V_LOG1P_CONSTANTS_TABLE,
20*f3087befSAndrew Turner .one = V2 (0x3ff0000000000000),
21*f3087befSAndrew Turner .thresh = V2 (0x1ff0000000000000) /* asuint64(0x1p511) - asuint64(1). */
22*f3087befSAndrew Turner };
23*f3087befSAndrew Turner
24*f3087befSAndrew Turner static float64x2_t NOINLINE VPCS_ATTR
special_case(float64x2_t x,float64x2_t y,uint64x2_t special,const struct v_log1p_data * d)25*f3087befSAndrew Turner special_case (float64x2_t x, float64x2_t y, uint64x2_t special,
26*f3087befSAndrew Turner const struct v_log1p_data *d)
27*f3087befSAndrew Turner {
28*f3087befSAndrew Turner return v_call_f64 (acosh, x, log1p_inline (y, d), special);
29*f3087befSAndrew Turner }
30*f3087befSAndrew Turner
31*f3087befSAndrew Turner /* Vector approximation for double-precision acosh, based on log1p.
32*f3087befSAndrew Turner The largest observed error is 3.02 ULP in the region where the
33*f3087befSAndrew Turner argument to log1p falls in the k=0 interval, i.e. x close to 1:
34*f3087befSAndrew Turner _ZGVnN2v_acosh(0x1.00798aaf80739p+0) got 0x1.f2d6d823bc9dfp-5
35*f3087befSAndrew Turner want 0x1.f2d6d823bc9e2p-5. */
V_NAME_D1(acosh)36*f3087befSAndrew Turner VPCS_ATTR float64x2_t V_NAME_D1 (acosh) (float64x2_t x)
37*f3087befSAndrew Turner {
38*f3087befSAndrew Turner const struct data *d = ptr_barrier (&data);
39*f3087befSAndrew Turner uint64x2_t special
40*f3087befSAndrew Turner = vcgeq_u64 (vsubq_u64 (vreinterpretq_u64_f64 (x), d->one), d->thresh);
41*f3087befSAndrew Turner float64x2_t special_arg = x;
42*f3087befSAndrew Turner
43*f3087befSAndrew Turner #if WANT_SIMD_EXCEPT
44*f3087befSAndrew Turner if (unlikely (v_any_u64 (special)))
45*f3087befSAndrew Turner x = vbslq_f64 (special, vreinterpretq_f64_u64 (d->one), x);
46*f3087befSAndrew Turner #endif
47*f3087befSAndrew Turner
48*f3087befSAndrew Turner float64x2_t xm1 = vsubq_f64 (x, v_f64 (1.0));
49*f3087befSAndrew Turner float64x2_t y = vaddq_f64 (x, v_f64 (1.0));
50*f3087befSAndrew Turner y = vmulq_f64 (y, xm1);
51*f3087befSAndrew Turner y = vsqrtq_f64 (y);
52*f3087befSAndrew Turner y = vaddq_f64 (xm1, y);
53*f3087befSAndrew Turner
54*f3087befSAndrew Turner if (unlikely (v_any_u64 (special)))
55*f3087befSAndrew Turner return special_case (special_arg, y, special, &d->log1p_consts);
56*f3087befSAndrew Turner return log1p_inline (y, &d->log1p_consts);
57*f3087befSAndrew Turner }
58*f3087befSAndrew Turner
59*f3087befSAndrew Turner TEST_SIG (V, D, 1, acosh, 1.0, 10.0)
60*f3087befSAndrew Turner TEST_ULP (V_NAME_D1 (acosh), 2.53)
61*f3087befSAndrew Turner TEST_DISABLE_FENV_IF_NOT (V_NAME_D1 (acosh), WANT_SIMD_EXCEPT)
62*f3087befSAndrew Turner TEST_INTERVAL (V_NAME_D1 (acosh), 1, 0x1p511, 90000)
63*f3087befSAndrew Turner TEST_INTERVAL (V_NAME_D1 (acosh), 0x1p511, inf, 10000)
64*f3087befSAndrew Turner TEST_INTERVAL (V_NAME_D1 (acosh), 0, 1, 1000)
65*f3087befSAndrew Turner TEST_INTERVAL (V_NAME_D1 (acosh), -0, -inf, 10000)
66