xref: /freebsd/contrib/arm-optimized-routines/math/aarch64/sve/acosh.c (revision f3087bef11543b42e0d69b708f367097a4118d24)
1 /*
2  * Double-precision SVE acosh(x) function.
3  * Copyright (c) 2024, Arm Limited.
4  * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
5  */
6 
7 #include "sv_math.h"
8 #include "test_sig.h"
9 #include "test_defs.h"
10 
11 #define WANT_SV_LOG1P_K0_SHORTCUT 1
12 #include "sv_log1p_inline.h"
13 
14 #define One (0x3ff0000000000000)
15 #define Thres (0x1ff0000000000000) /* asuint64 (0x1p511) - One.  */
16 
17 static svfloat64_t NOINLINE
special_case(svfloat64_t x,svfloat64_t y,svbool_t special)18 special_case (svfloat64_t x, svfloat64_t y, svbool_t special)
19 {
20   return sv_call_f64 (acosh, x, y, special);
21 }
22 
23 /* SVE approximation for double-precision acosh, based on log1p.
24    The largest observed error is 3.19 ULP in the region where the
25    argument to log1p falls in the k=0 interval, i.e. x close to 1:
26    SV_NAME_D1 (acosh)(0x1.1e4388d4ca821p+0) got 0x1.ed23399f5137p-2
27 					   want 0x1.ed23399f51373p-2.  */
SV_NAME_D1(acosh)28 svfloat64_t SV_NAME_D1 (acosh) (svfloat64_t x, const svbool_t pg)
29 {
30   /* (ix - One) >= (BigBound - One).  */
31   svuint64_t ix = svreinterpret_u64 (x);
32   svbool_t special = svcmpge (pg, svsub_x (pg, ix, One), Thres);
33 
34   svfloat64_t xm1 = svsub_x (pg, x, 1.0);
35   svfloat64_t u = svmul_x (pg, xm1, svadd_x (pg, x, 1.0));
36   svfloat64_t y = svadd_x (pg, xm1, svsqrt_x (pg, u));
37 
38   /* Fall back to scalar routine for special lanes.  */
39   if (unlikely (svptest_any (pg, special)))
40     return special_case (x, sv_log1p_inline (y, pg), special);
41   return sv_log1p_inline (y, pg);
42 }
43 
44 TEST_SIG (SV, D, 1, acosh, 1.0, 10.0)
45 TEST_ULP (SV_NAME_D1 (acosh), 2.69)
46 TEST_DISABLE_FENV (SV_NAME_D1 (acosh))
47 TEST_INTERVAL (SV_NAME_D1 (acosh), 1, 0x1p511, 90000)
48 TEST_INTERVAL (SV_NAME_D1 (acosh), 0x1p511, inf, 10000)
49 TEST_INTERVAL (SV_NAME_D1 (acosh), 0, 1, 1000)
50 TEST_INTERVAL (SV_NAME_D1 (acosh), -0, -inf, 10000)
51 CLOSE_SVE_ATTR
52