1 /* 2 * Single-precision vector acosh(x) function. 3 * Copyright (c) 2023, Arm Limited. 4 * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception 5 */ 6 7 #include "v_math.h" 8 #include "pl_sig.h" 9 #include "pl_test.h" 10 11 #define WANT_V_LOG1P_K0_SHORTCUT 1 12 #include "v_log1p_inline.h" 13 14 #define BigBoundTop 0x5fe /* top12 (asuint64 (0x1p511)). */ 15 16 #if V_SUPPORTED 17 18 static NOINLINE VPCS_ATTR v_f64_t 19 special_case (v_f64_t x) 20 { 21 return v_call_f64 (acosh, x, x, v_u64 (-1)); 22 } 23 24 /* Vector approximation for double-precision acosh, based on log1p. 25 The largest observed error is 3.02 ULP in the region where the 26 argument to log1p falls in the k=0 interval, i.e. x close to 1: 27 __v_acosh(0x1.00798aaf80739p+0) got 0x1.f2d6d823bc9dfp-5 28 want 0x1.f2d6d823bc9e2p-5. */ 29 VPCS_ATTR v_f64_t V_NAME (acosh) (v_f64_t x) 30 { 31 v_u64_t itop = v_as_u64_f64 (x) >> 52; 32 v_u64_t special = v_cond_u64 ((itop - OneTop) >= (BigBoundTop - OneTop)); 33 34 /* Fall back to scalar routine for all lanes if any of them are special. */ 35 if (unlikely (v_any_u64 (special))) 36 return special_case (x); 37 38 v_f64_t xm1 = x - 1; 39 v_f64_t u = xm1 * (x + 1); 40 return log1p_inline (xm1 + v_sqrt_f64 (u)); 41 } 42 VPCS_ALIAS 43 44 PL_SIG (V, D, 1, acosh, 1.0, 10.0) 45 PL_TEST_ULP (V_NAME (acosh), 2.53) 46 PL_TEST_EXPECT_FENV_ALWAYS (V_NAME (acosh)) 47 PL_TEST_INTERVAL (V_NAME (acosh), 1, 0x1p511, 90000) 48 PL_TEST_INTERVAL (V_NAME (acosh), 0x1p511, inf, 10000) 49 PL_TEST_INTERVAL (V_NAME (acosh), 0, 1, 1000) 50 PL_TEST_INTERVAL (V_NAME (acosh), -0, -inf, 10000) 51 #endif 52