Path: blob/main/contrib/arm-optimized-routines/math/aarch64/advsimd/acoshf.c
48378 views
/*1* Single-precision vector acosh(x) function.2* Copyright (c) 2023-2024, Arm Limited.3* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception4*/56#include "v_math.h"7#include "test_sig.h"8#include "test_defs.h"9#include "v_log1pf_inline.h"1011#define SquareLim 0x1p641213const static struct data14{15struct v_log1pf_data log1pf_consts;16uint32x4_t one;17} data = { .log1pf_consts = V_LOG1PF_CONSTANTS_TABLE, .one = V4 (0x3f800000) };1819#define Thresh vdup_n_u16 (0x2000) /* top(asuint(SquareLim) - asuint(1)). */2021static float32x4_t NOINLINE VPCS_ATTR22special_case (float32x4_t x, float32x4_t y, uint16x4_t special,23const struct v_log1pf_data *d)24{25return v_call_f32 (acoshf, x, log1pf_inline (y, d), vmovl_u16 (special));26}2728/* Vector approximation for single-precision acosh, based on log1p. Maximum29error depends on WANT_SIMD_EXCEPT. With SIMD fp exceptions enabled, it30is 3.00 ULP:31_ZGVnN4v_acoshf(0x1.01df3ap+0) got 0x1.ef0a82p-432want 0x1.ef0a7cp-4.33With exceptions disabled, we can compute u with a shorter dependency chain,34which gives maximum error of 3.22 ULP:35_ZGVnN4v_acoshf(0x1.007ef2p+0) got 0x1.fdcdccp-536want 0x1.fdcdd2p-5. */3738float32x4_t VPCS_ATTR NOINLINE V_NAME_F1 (acosh) (float32x4_t x)39{40const struct data *d = ptr_barrier (&data);41uint32x4_t ix = vreinterpretq_u32_f32 (x);42uint16x4_t special = vcge_u16 (vsubhn_u32 (ix, d->one), Thresh);4344#if WANT_SIMD_EXCEPT45/* Mask special lanes with 1 to side-step spurious invalid or overflow. Use46only xm1 to calculate u, as operating on x will trigger invalid for NaN.47Widening sign-extend special predicate in order to mask with it. */48uint32x4_t p49= vreinterpretq_u32_s32 (vmovl_s16 (vreinterpret_s16_u16 (special)));50float32x4_t xm1 = v_zerofy_f32 (vsubq_f32 (x, v_f32 (1)), p);51float32x4_t u = vfmaq_f32 (vaddq_f32 (xm1, xm1), xm1, xm1);52#else53float32x4_t xm1 = vsubq_f32 (x, vreinterpretq_f32_u32 (d->one));54float32x4_t u55= vmulq_f32 (xm1, vaddq_f32 (x, vreinterpretq_f32_u32 (d->one)));56#endif5758float32x4_t y = vaddq_f32 (xm1, vsqrtq_f32 (u));5960if (unlikely (v_any_u16h (special)))61return special_case (x, y, special, &d->log1pf_consts);62return log1pf_inline (y, &d->log1pf_consts);63}6465HALF_WIDTH_ALIAS_F1 (acosh)6667TEST_SIG (V, F, 1, acosh, 1.0, 10.0)68#if WANT_SIMD_EXCEPT69TEST_ULP (V_NAME_F1 (acosh), 2.50)70#else71TEST_ULP (V_NAME_F1 (acosh), 2.78)72#endif73TEST_DISABLE_FENV_IF_NOT (V_NAME_F1 (acosh), WANT_SIMD_EXCEPT)74TEST_INTERVAL (V_NAME_F1 (acosh), 0, 1, 500)75TEST_INTERVAL (V_NAME_F1 (acosh), 1, SquareLim, 100000)76TEST_INTERVAL (V_NAME_F1 (acosh), SquareLim, inf, 1000)77TEST_INTERVAL (V_NAME_F1 (acosh), -0, -inf, 1000)787980