Path: blob/main/contrib/arm-optimized-routines/math/aarch64/sve/coshf.c
48375 views
/*1* Single-precision SVE cosh(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"10#include "sv_expf_inline.h"1112static const struct data13{14struct sv_expf_data expf_consts;15float special_bound;16} data = {17.expf_consts = SV_EXPF_DATA,18/* 0x1.5a92d8p+6: expf overflows above this, so have to use special case. */19.special_bound = 0x1.5a92d8p+6,20};2122static svfloat32_t NOINLINE23special_case (svfloat32_t x, svfloat32_t half_e, svfloat32_t half_over_e,24svbool_t pg)25{26return sv_call_f32 (coshf, x, svadd_x (svptrue_b32 (), half_e, half_over_e),27pg);28}2930/* Single-precision vector cosh, using vector expf.31Maximum error is 2.77 ULP:32_ZGVsMxv_coshf(-0x1.5b38f4p+1) got 0x1.e45946p+233want 0x1.e4594cp+2. */34svfloat32_t SV_NAME_F1 (cosh) (svfloat32_t x, svbool_t pg)35{36const struct data *d = ptr_barrier (&data);3738svbool_t special = svacge (pg, x, d->special_bound);3940/* Calculate cosh by exp(x) / 2 + exp(-x) / 2.41Note that x is passed to exp here, rather than |x|. This is to avoid using42destructive unary ABS for better register usage. However it means the43routine is not exactly symmetrical, as the exp helper is slightly less44accurate in the negative range. */45svfloat32_t e = expf_inline (x, pg, &d->expf_consts);46svfloat32_t half_e = svmul_x (svptrue_b32 (), e, 0.5);47svfloat32_t half_over_e = svdivr_x (pg, e, 0.5);4849if (unlikely (svptest_any (pg, special)))50return special_case (x, half_e, half_over_e, special);5152return svadd_x (svptrue_b32 (), half_e, half_over_e);53}5455TEST_SIG (SV, F, 1, cosh, -10.0, 10.0)56TEST_ULP (SV_NAME_F1 (cosh), 2.28)57TEST_DISABLE_FENV (SV_NAME_F1 (cosh))58TEST_SYM_INTERVAL (SV_NAME_F1 (cosh), 0, 0x1p-63, 100)59TEST_SYM_INTERVAL (SV_NAME_F1 (cosh), 0, 0x1.5a92d8p+6, 80000)60TEST_SYM_INTERVAL (SV_NAME_F1 (cosh), 0x1.5a92d8p+6, inf, 2000)61CLOSE_SVE_ATTR626364