1 /* 2 * Single-precision vector e^x function. 3 * 4 * Copyright (c) 2019-2024, Arm Limited. 5 * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception 6 */ 7 8 #include "sv_math.h" 9 #include "test_sig.h" 10 #include "test_defs.h" 11 #include "sv_expf_inline.h" 12 13 /* Roughly 87.3. For x < -Thres, the result is subnormal and not handled 14 correctly by FEXPA. */ 15 #define Thres 0x1.5d5e2ap+6f 16 17 static const struct data 18 { 19 struct sv_expf_data d; 20 float thres; 21 } data = { 22 .d = SV_EXPF_DATA, 23 .thres = Thres, 24 }; 25 26 static svfloat32_t NOINLINE 27 special_case (svfloat32_t x, svbool_t special, const struct sv_expf_data *d) 28 { 29 return sv_call_f32 (expf, x, expf_inline (x, svptrue_b32 (), d), special); 30 } 31 32 /* Optimised single-precision SVE exp function. 33 Worst-case error is 1.04 ulp: 34 SV_NAME_F1 (exp)(0x1.a8eda4p+1) got 0x1.ba74bcp+4 35 want 0x1.ba74bap+4. */ 36 svfloat32_t SV_NAME_F1 (exp) (svfloat32_t x, const svbool_t pg) 37 { 38 const struct data *d = ptr_barrier (&data); 39 svbool_t is_special_case = svacgt (pg, x, d->thres); 40 if (unlikely (svptest_any (pg, is_special_case))) 41 return special_case (x, is_special_case, &d->d); 42 return expf_inline (x, pg, &d->d); 43 } 44 45 TEST_SIG (SV, F, 1, exp, -9.9, 9.9) 46 TEST_ULP (SV_NAME_F1 (exp), 0.55) 47 TEST_DISABLE_FENV (SV_NAME_F1 (exp)) 48 TEST_SYM_INTERVAL (SV_NAME_F1 (exp), 0, Thres, 50000) 49 TEST_SYM_INTERVAL (SV_NAME_F1 (exp), Thres, inf, 50000) 50 CLOSE_SVE_ATTR 51