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