Path: blob/main/contrib/arm-optimized-routines/math/aarch64/advsimd/asinhf.c
48375 views
/*1* Single-precision vector asinh(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;15float32x4_t one;16uint32x4_t big_bound;17#if WANT_SIMD_EXCEPT18uint32x4_t tiny_bound;19#endif20} data = {21.one = V4 (1),22.log1pf_consts = V_LOG1PF_CONSTANTS_TABLE,23.big_bound = V4 (0x5f800000), /* asuint(0x1p64). */24#if WANT_SIMD_EXCEPT25.tiny_bound = V4 (0x30800000) /* asuint(0x1p-30). */26#endif27};2829static float32x4_t NOINLINE VPCS_ATTR30special_case (float32x4_t x, uint32x4_t sign, float32x4_t y,31uint32x4_t special, const struct data *d)32{33return v_call_f32 (34asinhf, x,35vreinterpretq_f32_u32 (veorq_u32 (36sign, vreinterpretq_u32_f32 (log1pf_inline (y, &d->log1pf_consts)))),37special);38}3940/* Single-precision implementation of vector asinh(x), using vector log1p.41Worst-case error is 2.59 ULP:42_ZGVnN4v_asinhf(0x1.d86124p-3) got 0x1.d449bep-343want 0x1.d449c4p-3. */44float32x4_t VPCS_ATTR NOINLINE V_NAME_F1 (asinh) (float32x4_t x)45{46const struct data *dat = ptr_barrier (&data);47float32x4_t ax = vabsq_f32 (x);48uint32x4_t iax = vreinterpretq_u32_f32 (ax);49uint32x4_t special = vcgeq_u32 (iax, dat->big_bound);50uint32x4_t sign = veorq_u32 (vreinterpretq_u32_f32 (x), iax);51float32x4_t special_arg = x;5253#if WANT_SIMD_EXCEPT54/* Sidestep tiny and large values to avoid inadvertently triggering55under/overflow. */56special = vorrq_u32 (special, vcltq_u32 (iax, dat->tiny_bound));57if (unlikely (v_any_u32 (special)))58{59ax = v_zerofy_f32 (ax, special);60x = v_zerofy_f32 (x, special);61}62#endif6364/* asinh(x) = log(x + sqrt(x * x + 1)).65For positive x, asinh(x) = log1p(x + x * x / (1 + sqrt(x * x + 1))). */66float32x4_t d67= vaddq_f32 (v_f32 (1), vsqrtq_f32 (vfmaq_f32 (dat->one, ax, ax)));68float32x4_t y = vaddq_f32 (ax, vdivq_f32 (vmulq_f32 (ax, ax), d));6970if (unlikely (v_any_u32 (special)))71return special_case (special_arg, sign, y, special, dat);72return vreinterpretq_f32_u32 (veorq_u32 (73sign, vreinterpretq_u32_f32 (log1pf_inline (y, &dat->log1pf_consts))));74}7576HALF_WIDTH_ALIAS_F1 (asinh)7778TEST_SIG (V, F, 1, asinh, -10.0, 10.0)79TEST_ULP (V_NAME_F1 (asinh), 2.10)80TEST_DISABLE_FENV_IF_NOT (V_NAME_F1 (asinh), WANT_SIMD_EXCEPT)81TEST_INTERVAL (V_NAME_F1 (asinh), 0, 0x1p-12, 40000)82TEST_INTERVAL (V_NAME_F1 (asinh), 0x1p-12, 1.0, 40000)83TEST_INTERVAL (V_NAME_F1 (asinh), 1.0, 0x1p11, 40000)84TEST_INTERVAL (V_NAME_F1 (asinh), 0x1p11, inf, 40000)85TEST_INTERVAL (V_NAME_F1 (asinh), -0, -0x1p-12, 20000)86TEST_INTERVAL (V_NAME_F1 (asinh), -0x1p-12, -1.0, 20000)87TEST_INTERVAL (V_NAME_F1 (asinh), -1.0, -0x1p11, 20000)88TEST_INTERVAL (V_NAME_F1 (asinh), -0x1p11, -inf, 20000)899091