Path: blob/main/contrib/arm-optimized-routines/math/aarch64/sve/atanh.c
48375 views
/*1* Double-precision SVE atanh(x) function.2*3* Copyright (c) 2023-2024, Arm Limited.4* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception5*/67#include "sv_math.h"8#include "test_sig.h"9#include "test_defs.h"1011#define WANT_SV_LOG1P_K0_SHORTCUT 012#include "sv_log1p_inline.h"1314#define One (0x3ff0000000000000)15#define Half (0x3fe0000000000000)1617static svfloat64_t NOINLINE18special_case (svfloat64_t x, svfloat64_t y, svbool_t special)19{20return sv_call_f64 (atanh, x, y, special);21}2223/* SVE approximation for double-precision atanh, based on log1p.24The greatest observed error is 2.81 ULP:25_ZGVsMxv_atanh(0x1.ffae6288b601p-6) got 0x1.ffd8ff31b5019p-626want 0x1.ffd8ff31b501cp-6. */27svfloat64_t SV_NAME_D1 (atanh) (svfloat64_t x, const svbool_t pg)28{2930svfloat64_t ax = svabs_x (pg, x);31svuint64_t iax = svreinterpret_u64 (ax);32svuint64_t sign = sveor_x (pg, svreinterpret_u64 (x), iax);33svfloat64_t halfsign = svreinterpret_f64 (svorr_x (pg, sign, Half));3435/* It is special if iax >= 1. */36svbool_t special = svacge (pg, x, 1.0);3738/* Computation is performed based on the following sequence of equality:39(1+x)/(1-x) = 1 + 2x/(1-x). */40svfloat64_t y;41y = svadd_x (pg, ax, ax);42y = svdiv_x (pg, y, svsub_x (pg, sv_f64 (1), ax));43/* ln((1+x)/(1-x)) = ln(1+2x/(1-x)) = ln(1 + y). */44y = sv_log1p_inline (y, pg);4546if (unlikely (svptest_any (pg, special)))47return special_case (x, svmul_x (pg, halfsign, y), special);48return svmul_x (pg, halfsign, y);49}5051TEST_SIG (SV, D, 1, atanh, -1.0, 1.0)52TEST_ULP (SV_NAME_D1 (atanh), 3.32)53TEST_DISABLE_FENV (SV_NAME_D1 (atanh))54TEST_SYM_INTERVAL (SV_NAME_D1 (atanh), 0, 0x1p-23, 10000)55TEST_SYM_INTERVAL (SV_NAME_D1 (atanh), 0x1p-23, 1, 90000)56TEST_SYM_INTERVAL (SV_NAME_D1 (atanh), 1, inf, 100)57/* atanh is asymptotic at 1, which is the default control value - have to set58-c 0 specially to ensure fp exceptions are triggered correctly (choice of59control lane is irrelevant if fp exceptions are disabled). */60TEST_CONTROL_VALUE (SV_NAME_D1 (atanh), 0)61CLOSE_SVE_ATTR626364