1*f3087befSAndrew Turner /*
2*f3087befSAndrew Turner * Single-precision SVE asinh(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 BigBound 0x5f800000 /* asuint(0x1p64). */
15*f3087befSAndrew Turner
16*f3087befSAndrew Turner static svfloat32_t NOINLINE
special_case(svuint32_t iax,svuint32_t sign,svfloat32_t y,svbool_t special)17*f3087befSAndrew Turner special_case (svuint32_t iax, svuint32_t sign, svfloat32_t y, svbool_t special)
18*f3087befSAndrew Turner {
19*f3087befSAndrew Turner svfloat32_t x = svreinterpret_f32 (sveor_x (svptrue_b32 (), iax, sign));
20*f3087befSAndrew Turner y = svreinterpret_f32 (
21*f3087befSAndrew Turner svorr_x (svptrue_b32 (), sign, svreinterpret_u32 (y)));
22*f3087befSAndrew Turner return sv_call_f32 (asinhf, x, y, special);
23*f3087befSAndrew Turner }
24*f3087befSAndrew Turner
25*f3087befSAndrew Turner /* Single-precision SVE asinh(x) routine. Implements the same algorithm as
26*f3087befSAndrew Turner vector asinhf and log1p.
27*f3087befSAndrew Turner
28*f3087befSAndrew Turner Maximum error is 1.92 ULPs:
29*f3087befSAndrew Turner SV_NAME_F1 (asinh) (-0x1.0922ecp-1) got -0x1.fd0bccp-2
30*f3087befSAndrew Turner want -0x1.fd0bc8p-2. */
SV_NAME_F1(asinh)31*f3087befSAndrew Turner svfloat32_t SV_NAME_F1 (asinh) (svfloat32_t x, const svbool_t pg)
32*f3087befSAndrew Turner {
33*f3087befSAndrew Turner svfloat32_t ax = svabs_x (pg, x);
34*f3087befSAndrew Turner svuint32_t iax = svreinterpret_u32 (ax);
35*f3087befSAndrew Turner svuint32_t sign = sveor_x (pg, svreinterpret_u32 (x), iax);
36*f3087befSAndrew Turner svbool_t special = svcmpge (pg, iax, BigBound);
37*f3087befSAndrew Turner
38*f3087befSAndrew Turner /* asinh(x) = log(x + sqrt(x * x + 1)).
39*f3087befSAndrew Turner For positive x, asinh(x) = log1p(x + x * x / (1 + sqrt(x * x + 1))). */
40*f3087befSAndrew Turner svfloat32_t ax2 = svmul_x (pg, ax, ax);
41*f3087befSAndrew Turner svfloat32_t d = svadd_x (pg, svsqrt_x (pg, svadd_x (pg, ax2, 1.0f)), 1.0f);
42*f3087befSAndrew Turner svfloat32_t y
43*f3087befSAndrew Turner = sv_log1pf_inline (svadd_x (pg, ax, svdiv_x (pg, ax2, d)), pg);
44*f3087befSAndrew Turner
45*f3087befSAndrew Turner if (unlikely (svptest_any (pg, special)))
46*f3087befSAndrew Turner return special_case (iax, sign, y, special);
47*f3087befSAndrew Turner return svreinterpret_f32 (svorr_x (pg, sign, svreinterpret_u32 (y)));
48*f3087befSAndrew Turner }
49*f3087befSAndrew Turner
50*f3087befSAndrew Turner TEST_SIG (SV, F, 1, asinh, -10.0, 10.0)
51*f3087befSAndrew Turner TEST_ULP (SV_NAME_F1 (asinh), 1.43)
52*f3087befSAndrew Turner TEST_DISABLE_FENV (SV_NAME_F1 (asinh))
53*f3087befSAndrew Turner TEST_SYM_INTERVAL (SV_NAME_F1 (asinh), 0, 0x1p-12, 4000)
54*f3087befSAndrew Turner TEST_SYM_INTERVAL (SV_NAME_F1 (asinh), 0x1p-12, 1.0, 20000)
55*f3087befSAndrew Turner TEST_SYM_INTERVAL (SV_NAME_F1 (asinh), 1.0, 0x1p64, 20000)
56*f3087befSAndrew Turner TEST_SYM_INTERVAL (SV_NAME_F1 (asinh), 0x1p64, inf, 4000)
57*f3087befSAndrew Turner CLOSE_SVE_ATTR
58