Path: blob/main/contrib/arm-optimized-routines/math/aarch64/experimental/asinhf_3u5.c
48375 views
/*1* Single-precision 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 "poly_scalar_f32.h"8#include "math_config.h"9#include "test_sig.h"10#include "test_defs.h"1112#define AbsMask (0x7fffffff)13#define SqrtFltMax (0x1.749e96p+10f)14#define Ln2 (0x1.62e4p-1f)15#define One (0x3f8)16#define ExpM12 (0x398)1718/* asinhf approximation using a variety of approaches on different intervals:1920|x| < 2^-12: Return x. Function is exactly rounded in this region.2122|x| < 1.0: Use custom order-8 polynomial. The largest observed23error in this region is 1.3ulps:24asinhf(0x1.f0f74cp-1) got 0x1.b88de4p-1 want 0x1.b88de2p-1.2526|x| <= SqrtFltMax: Calculate the result directly using the27definition of asinh(x) = ln(x + sqrt(x*x + 1)). The largest28observed error in this region is 1.99ulps.29asinhf(0x1.00e358p+0) got 0x1.c4849ep-1 want 0x1.c484a2p-1.3031|x| > SqrtFltMax: We cannot square x without overflow at a low32cost. At very large x, asinh(x) ~= ln(2x). At huge x we cannot33even double x without overflow, so calculate this as ln(x) +34ln(2). This largest observed error in this region is 3.39ulps.35asinhf(0x1.749e9ep+10) got 0x1.fffff8p+2 want 0x1.fffffep+2. */36float37asinhf (float x)38{39uint32_t ix = asuint (x);40uint32_t ia = ix & AbsMask;41uint32_t ia12 = ia >> 20;42float ax = asfloat (ia);43uint32_t sign = ix & ~AbsMask;4445if (unlikely (ia12 < ExpM12 || ia == 0x7f800000))46return x;4748if (unlikely (ia12 >= 0x7f8))49return __math_invalidf (x);5051if (ia12 < One)52{53float x2 = ax * ax;54float p = estrin_7_f32 (ax, x2, x2 * x2, __asinhf_data.coeffs);55float y = fmaf (x2, p, ax);56return asfloat (asuint (y) | sign);57}5859if (unlikely (ax > SqrtFltMax))60{61return asfloat (asuint (logf (ax) + Ln2) | sign);62}6364return asfloat (asuint (logf (ax + sqrtf (ax * ax + 1))) | sign);65}6667TEST_SIG (S, F, 1, asinh, -10.0, 10.0)68TEST_ULP (asinhf, 2.9)69TEST_INTERVAL (asinhf, 0, 0x1p-12, 5000)70TEST_INTERVAL (asinhf, 0x1p-12, 1.0, 50000)71TEST_INTERVAL (asinhf, 1.0, 0x1p11, 50000)72TEST_INTERVAL (asinhf, 0x1p11, 0x1p127, 20000)737475