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