xref: /freebsd/contrib/arm-optimized-routines/pl/math/sv_acoshf_2u8.c (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*
2  * Single-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 One 0x3f800000
12 #define Thres 0x20000000 /* asuint(0x1p64) - One.  */
13 
14 #include "sv_log1pf_inline.h"
15 
16 static svfloat32_t NOINLINE
17 special_case (svfloat32_t x, svfloat32_t y, svbool_t special)
18 {
19   return sv_call_f32 (acoshf, x, y, special);
20 }
21 
22 /* Single-precision SVE acosh(x) routine. Implements the same algorithm as
23    vector acoshf and log1p.
24 
25    Maximum error is 2.78 ULPs:
26    SV_NAME_F1 (acosh) (0x1.01e996p+0) got 0x1.f45b42p-4
27 				     want 0x1.f45b3cp-4.  */
28 svfloat32_t SV_NAME_F1 (acosh) (svfloat32_t x, const svbool_t pg)
29 {
30   svuint32_t ix = svreinterpret_u32 (x);
31   svbool_t special = svcmpge (pg, svsub_x (pg, ix, One), Thres);
32 
33   svfloat32_t xm1 = svsub_x (pg, x, 1.0f);
34   svfloat32_t u = svmul_x (pg, xm1, svadd_x (pg, x, 1.0f));
35   svfloat32_t y = sv_log1pf_inline (svadd_x (pg, xm1, svsqrt_x (pg, u)), pg);
36 
37   if (unlikely (svptest_any (pg, special)))
38     return special_case (x, y, special);
39   return y;
40 }
41 
42 PL_SIG (SV, F, 1, acosh, 1.0, 10.0)
43 PL_TEST_ULP (SV_NAME_F1 (acosh), 2.29)
44 PL_TEST_INTERVAL (SV_NAME_F1 (acosh), 0, 1, 500)
45 PL_TEST_INTERVAL (SV_NAME_F1 (acosh), 1, 0x1p64, 100000)
46 PL_TEST_INTERVAL (SV_NAME_F1 (acosh), 0x1p64, inf, 1000)
47 PL_TEST_INTERVAL (SV_NAME_F1 (acosh), -0, -inf, 1000)
48