xref: /freebsd/contrib/arm-optimized-routines/pl/math/sv_acosh_3u5.c (revision f5f40dd63bc7acbb5312b26ac1ea1103c12352a6)
1 /*
2  * Double-precision SVE acosh(x) function.
3  * Copyright (c) 2023, Arm Limited.
4  * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
5  */
6 
7 #include "sv_math.h"
8 #include "pl_sig.h"
9 #include "pl_test.h"
10 
11 #define WANT_SV_LOG1P_K0_SHORTCUT 1
12 #include "sv_log1p_inline.h"
13 
14 #define BigBoundTop 0x5fe /* top12 (asuint64 (0x1p511)).  */
15 #define OneTop 0x3ff
16 
17 static NOINLINE svfloat64_t
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.  */
28 svfloat64_t SV_NAME_D1 (acosh) (svfloat64_t x, const svbool_t pg)
29 {
30   svuint64_t itop = svlsr_x (pg, svreinterpret_u64 (x), 52);
31   /* (itop - OneTop) >= (BigBoundTop - OneTop).  */
32   svbool_t special = svcmpge (pg, svsub_x (pg, itop, OneTop), sv_u64 (0x1ff));
33 
34   svfloat64_t xm1 = svsub_x (pg, x, 1);
35   svfloat64_t u = svmul_x (pg, xm1, svadd_x (pg, x, 1));
36   svfloat64_t y = sv_log1p_inline (svadd_x (pg, xm1, svsqrt_x (pg, u)), pg);
37 
38   /* Fall back to scalar routine for special lanes.  */
39   if (unlikely (svptest_any (pg, special)))
40     return special_case (x, y, special);
41 
42   return y;
43 }
44 
45 PL_SIG (SV, D, 1, acosh, 1.0, 10.0)
46 PL_TEST_ULP (SV_NAME_D1 (acosh), 2.69)
47 PL_TEST_INTERVAL (SV_NAME_D1 (acosh), 1, 0x1p511, 90000)
48 PL_TEST_INTERVAL (SV_NAME_D1 (acosh), 0x1p511, inf, 10000)
49 PL_TEST_INTERVAL (SV_NAME_D1 (acosh), 0, 1, 1000)
50 PL_TEST_INTERVAL (SV_NAME_D1 (acosh), -0, -inf, 10000)
51