Path: blob/main/contrib/arm-optimized-routines/math/aarch64/advsimd/atanh.c
48378 views
/*1* Double-precision vector atanh(x) function.2*3* Copyright (c) 2022-2024, Arm Limited.4* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception5*/67#include "v_math.h"8#include "test_sig.h"9#include "test_defs.h"1011#define WANT_V_LOG1P_K0_SHORTCUT 012#include "v_log1p_inline.h"1314const static struct data15{16struct v_log1p_data log1p_consts;17uint64x2_t one;18uint64x2_t sign_mask;19} data = { .log1p_consts = V_LOG1P_CONSTANTS_TABLE,20.one = V2 (0x3ff0000000000000),21.sign_mask = V2 (0x8000000000000000) };2223static float64x2_t VPCS_ATTR NOINLINE24special_case (float64x2_t x, float64x2_t halfsign, float64x2_t y,25uint64x2_t special, const struct data *d)26{27y = log1p_inline (y, &d->log1p_consts);28return v_call_f64 (atanh, vbslq_f64 (d->sign_mask, halfsign, x),29vmulq_f64 (halfsign, y), special);30}3132/* Approximation for vector double-precision atanh(x) using modified log1p.33The greatest observed error is 3.31 ULP:34_ZGVnN2v_atanh(0x1.ffae6288b601p-6) got 0x1.ffd8ff31b5019p-635want 0x1.ffd8ff31b501cp-6. */36VPCS_ATTR37float64x2_t V_NAME_D1 (atanh) (float64x2_t x)38{39const struct data *d = ptr_barrier (&data);4041float64x2_t halfsign = vbslq_f64 (d->sign_mask, x, v_f64 (0.5));42float64x2_t ax = vabsq_f64 (x);43uint64x2_t ia = vreinterpretq_u64_f64 (ax);44uint64x2_t special = vcgeq_u64 (ia, d->one);4546#if WANT_SIMD_EXCEPT47ax = v_zerofy_f64 (ax, special);48#endif4950float64x2_t y;51y = vaddq_f64 (ax, ax);52y = vdivq_f64 (y, vsubq_f64 (vreinterpretq_f64_u64 (d->one), ax));5354if (unlikely (v_any_u64 (special)))55#if WANT_SIMD_EXCEPT56return special_case (x, halfsign, y, special, d);57#else58return special_case (ax, halfsign, y, special, d);59#endif6061y = log1p_inline (y, &d->log1p_consts);62return vmulq_f64 (y, halfsign);63}6465TEST_SIG (V, D, 1, atanh, -1.0, 1.0)66TEST_DISABLE_FENV_IF_NOT (V_NAME_D1 (atanh), WANT_SIMD_EXCEPT)67TEST_ULP (V_NAME_D1 (atanh), 3.32)68TEST_SYM_INTERVAL (V_NAME_D1 (atanh), 0, 0x1p-23, 10000)69TEST_SYM_INTERVAL (V_NAME_D1 (atanh), 0x1p-23, 1, 90000)70TEST_SYM_INTERVAL (V_NAME_D1 (atanh), 1, inf, 100)71/* atanh is asymptotic at 1, which is the default control value - have to set72-c 0 specially to ensure fp exceptions are triggered correctly (choice of73control lane is irrelevant if fp exceptions are disabled). */74TEST_CONTROL_VALUE (V_NAME_D1 (atanh), 0)757677