xref: /freebsd/contrib/arm-optimized-routines/math/aarch64/sve/atanhf.c (revision f3087bef11543b42e0d69b708f367097a4118d24)
1*f3087befSAndrew Turner /*
2*f3087befSAndrew Turner  * Single-precision vector atanh(x) function.
3*f3087befSAndrew Turner  *
4*f3087befSAndrew Turner  * Copyright (c) 2023-2024, Arm Limited.
5*f3087befSAndrew Turner  * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
6*f3087befSAndrew Turner  */
7*f3087befSAndrew Turner 
8*f3087befSAndrew Turner #include "sv_math.h"
9*f3087befSAndrew Turner #include "test_sig.h"
10*f3087befSAndrew Turner #include "test_defs.h"
11*f3087befSAndrew Turner 
12*f3087befSAndrew Turner #include "sv_log1pf_inline.h"
13*f3087befSAndrew Turner 
14*f3087befSAndrew Turner #define One (0x3f800000)
15*f3087befSAndrew Turner #define Half (0x3f000000)
16*f3087befSAndrew Turner 
17*f3087befSAndrew Turner static svfloat32_t NOINLINE
special_case(svuint32_t iax,svuint32_t sign,svfloat32_t halfsign,svfloat32_t y,svbool_t special)18*f3087befSAndrew Turner special_case (svuint32_t iax, svuint32_t sign, svfloat32_t halfsign,
19*f3087befSAndrew Turner 	      svfloat32_t y, svbool_t special)
20*f3087befSAndrew Turner {
21*f3087befSAndrew Turner   svfloat32_t x = svreinterpret_f32 (sveor_x (svptrue_b32 (), iax, sign));
22*f3087befSAndrew Turner   y = svmul_x (svptrue_b32 (), halfsign, y);
23*f3087befSAndrew Turner   return sv_call_f32 (atanhf, x, y, special);
24*f3087befSAndrew Turner }
25*f3087befSAndrew Turner 
26*f3087befSAndrew Turner /* Approximation for vector single-precision atanh(x) using modified log1p.
27*f3087befSAndrew Turner    The maximum error is 1.99 ULP:
28*f3087befSAndrew Turner    _ZGVsMxv_atanhf(0x1.f1583p-5) got 0x1.f1f4fap-5
29*f3087befSAndrew Turner 				want 0x1.f1f4f6p-5.  */
SV_NAME_F1(atanh)30*f3087befSAndrew Turner svfloat32_t SV_NAME_F1 (atanh) (svfloat32_t x, const svbool_t pg)
31*f3087befSAndrew Turner {
32*f3087befSAndrew Turner   svfloat32_t ax = svabs_x (pg, x);
33*f3087befSAndrew Turner   svuint32_t iax = svreinterpret_u32 (ax);
34*f3087befSAndrew Turner   svuint32_t sign = sveor_x (pg, svreinterpret_u32 (x), iax);
35*f3087befSAndrew Turner   svfloat32_t halfsign = svreinterpret_f32 (svorr_x (pg, sign, Half));
36*f3087befSAndrew Turner   svbool_t special = svcmpge (pg, iax, One);
37*f3087befSAndrew Turner 
38*f3087befSAndrew Turner   /* Computation is performed based on the following sequence of equality:
39*f3087befSAndrew Turner    * (1+x)/(1-x) = 1 + 2x/(1-x).  */
40*f3087befSAndrew Turner   svfloat32_t y = svadd_x (pg, ax, ax);
41*f3087befSAndrew Turner   y = svdiv_x (pg, y, svsub_x (pg, sv_f32 (1), ax));
42*f3087befSAndrew Turner   /* ln((1+x)/(1-x)) = ln(1+2x/(1-x)) = ln(1 + y).  */
43*f3087befSAndrew Turner   y = sv_log1pf_inline (y, pg);
44*f3087befSAndrew Turner 
45*f3087befSAndrew Turner   if (unlikely (svptest_any (pg, special)))
46*f3087befSAndrew Turner     return special_case (iax, sign, halfsign, y, special);
47*f3087befSAndrew Turner 
48*f3087befSAndrew Turner   return svmul_x (pg, halfsign, y);
49*f3087befSAndrew Turner }
50*f3087befSAndrew Turner 
51*f3087befSAndrew Turner TEST_SIG (SV, F, 1, atanh, -1.0, 1.0)
52*f3087befSAndrew Turner TEST_ULP (SV_NAME_F1 (atanh), 1.50)
53*f3087befSAndrew Turner TEST_DISABLE_FENV (SV_NAME_F1 (atanh))
54*f3087befSAndrew Turner TEST_SYM_INTERVAL (SV_NAME_F1 (atanh), 0, 0x1p-12, 1000)
55*f3087befSAndrew Turner TEST_SYM_INTERVAL (SV_NAME_F1 (atanh), 0x1p-12, 1, 20000)
56*f3087befSAndrew Turner TEST_SYM_INTERVAL (SV_NAME_F1 (atanh), 1, inf, 1000)
57*f3087befSAndrew Turner /* atanh is asymptotic at 1, which is the default control value - have to set
58*f3087befSAndrew Turner  -c 0 specially to ensure fp exceptions are triggered correctly (choice of
59*f3087befSAndrew Turner  control lane is irrelevant if fp exceptions are disabled).  */
60*f3087befSAndrew Turner TEST_CONTROL_VALUE (SV_NAME_F1 (atanh), 0)
61*f3087befSAndrew Turner CLOSE_SVE_ATTR
62