Path: blob/main/contrib/arm-optimized-routines/math/aarch64/advsimd/atanhf.c
48378 views
/*1* Single-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"10#include "v_log1pf_inline.h"1112const static struct data13{14struct v_log1pf_data log1pf_consts;15uint32x4_t one;16#if WANT_SIMD_EXCEPT17uint32x4_t tiny_bound;18#endif19} data = {20.log1pf_consts = V_LOG1PF_CONSTANTS_TABLE,21.one = V4 (0x3f800000),22#if WANT_SIMD_EXCEPT23/* 0x1p-12, below which atanhf(x) rounds to x. */24.tiny_bound = V4 (0x39800000),25#endif26};2728#define AbsMask v_u32 (0x7fffffff)29#define Half v_u32 (0x3f000000)3031static float32x4_t NOINLINE VPCS_ATTR32special_case (float32x4_t x, float32x4_t halfsign, float32x4_t y,33uint32x4_t special)34{35return v_call_f32 (atanhf, vbslq_f32 (AbsMask, x, halfsign),36vmulq_f32 (halfsign, y), special);37}3839/* Approximation for vector single-precision atanh(x) using modified log1p.40The maximum error is 2.93 ULP:41_ZGVnN4v_atanhf(0x1.f43d7p-5) got 0x1.f4dcfep-542want 0x1.f4dcf8p-5. */43float32x4_t VPCS_ATTR NOINLINE V_NAME_F1 (atanh) (float32x4_t x)44{45const struct data *d = ptr_barrier (&data);4647float32x4_t halfsign = vbslq_f32 (AbsMask, v_f32 (0.5), x);48float32x4_t ax = vabsq_f32 (x);49uint32x4_t iax = vreinterpretq_u32_f32 (ax);5051#if WANT_SIMD_EXCEPT52uint32x4_t special53= vorrq_u32 (vcgeq_u32 (iax, d->one), vcltq_u32 (iax, d->tiny_bound));54/* Side-step special cases by setting those lanes to 0, which will trigger no55exceptions. These will be fixed up later. */56if (unlikely (v_any_u32 (special)))57ax = v_zerofy_f32 (ax, special);58#else59uint32x4_t special = vcgeq_u32 (iax, d->one);60#endif6162float32x4_t y = vdivq_f32 (vaddq_f32 (ax, ax),63vsubq_f32 (vreinterpretq_f32_u32 (d->one), ax));64y = log1pf_inline (y, &d->log1pf_consts);6566/* If exceptions not required, pass ax to special-case for shorter dependency67chain. If exceptions are required ax will have been zerofied, so have to68pass x. */69if (unlikely (v_any_u32 (special)))70#if WANT_SIMD_EXCEPT71return special_case (x, halfsign, y, special);72#else73return special_case (ax, halfsign, y, special);74#endif75return vmulq_f32 (halfsign, y);76}7778HALF_WIDTH_ALIAS_F1 (atanh)7980TEST_SIG (V, F, 1, atanh, -1.0, 1.0)81TEST_ULP (V_NAME_F1 (atanh), 2.44)82TEST_DISABLE_FENV_IF_NOT (V_NAME_F1 (atanh), WANT_SIMD_EXCEPT)83TEST_SYM_INTERVAL (V_NAME_F1 (atanh), 0, 0x1p-12, 500)84TEST_SYM_INTERVAL (V_NAME_F1 (atanh), 0x1p-12, 1, 200000)85TEST_SYM_INTERVAL (V_NAME_F1 (atanh), 1, inf, 1000)86/* atanh is asymptotic at 1, which is the default control value - have to set87-c 0 specially to ensure fp exceptions are triggered correctly (choice of88control lane is irrelevant if fp exceptions are disabled). */89TEST_CONTROL_VALUE (V_NAME_F1 (atanh), 0)909192