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