diff options
author | Joe Ramsay <Joe.Ramsay@arm.com> | 2022-09-06 15:00:22 +0100 |
---|---|---|
committer | Joe Ramsay <joe.ramsay@arm.com> | 2022-09-06 15:00:22 +0100 |
commit | 251a040bd28ee232a63480b4036346b81995047e (patch) | |
tree | b4f73fe046684ce3cf89447d882a447b9a4db968 /pl/math | |
parent | 375526b26e3535091ae4bdba0a5703fa0d4a4bb7 (diff) | |
download | arm-optimized-routines-251a040bd28ee232a63480b4036346b81995047e.tar.gz |
pl/math: Add vector/SVE logf
New routine is SVE port of the Neon algorithm in math/, and is
accurate to 3.4 ULP.
Diffstat (limited to 'pl/math')
-rw-r--r-- | pl/math/include/mathlib.h | 2 | ||||
-rw-r--r-- | pl/math/math_config.h | 3 | ||||
-rw-r--r-- | pl/math/sv_logf_3u4.c | 66 | ||||
-rw-r--r-- | pl/math/sv_logf_data.c | 12 | ||||
-rw-r--r-- | pl/math/test/mathbench_funcs.h | 3 | ||||
-rwxr-xr-x | pl/math/test/runulp.sh | 12 | ||||
-rw-r--r-- | pl/math/test/ulp_funcs.h | 2 | ||||
-rw-r--r-- | pl/math/test/ulp_wrappers.h | 1 |
8 files changed, 101 insertions, 0 deletions
diff --git a/pl/math/include/mathlib.h b/pl/math/include/mathlib.h index 0d6077d..1765c9d 100644 --- a/pl/math/include/mathlib.h +++ b/pl/math/include/mathlib.h @@ -110,6 +110,7 @@ svfloat64_t __sv_atan_x (svfloat64_t, svbool_t); svfloat64_t __sv_atan2_x (svfloat64_t, svfloat64_t, svbool_t); svfloat32_t __sv_cosf_x (svfloat32_t, svbool_t); svfloat64_t __sv_cos_x (svfloat64_t, svbool_t); +svfloat32_t __sv_logf_x (svfloat32_t, svbool_t); svfloat32_t __sv_log10f_x (svfloat32_t, svbool_t); svfloat64_t __sv_log10_x (svfloat64_t, svbool_t); svfloat32_t __sv_sinf_x (svfloat32_t, svbool_t); @@ -121,6 +122,7 @@ svfloat64_t _ZGVsMxv_atan (svfloat64_t, svbool_t); svfloat64_t _ZGVsMxvv_atan2 (svfloat64_t, svfloat64_t, svbool_t); svfloat32_t _ZGVsMxv_cosf (svfloat32_t, svbool_t); svfloat64_t _ZGVsMxv_cos (svfloat64_t, svbool_t); +svfloat32_t _ZGVsMxv_logf (svfloat32_t, svbool_t); svfloat32_t _ZGVsMxv_log10f (svfloat32_t, svbool_t); svfloat64_t _ZGVsMxv_log10 (svfloat64_t, svbool_t); svfloat32_t _ZGVsMxv_sinf (svfloat32_t, svbool_t); diff --git a/pl/math/math_config.h b/pl/math/math_config.h index 10bbd9b..5e22349 100644 --- a/pl/math/math_config.h +++ b/pl/math/math_config.h @@ -511,4 +511,7 @@ extern const struct v_log10_data #define V_LOG10F_POLY_ORDER 9 extern const float __v_log10f_poly[V_LOG10F_POLY_ORDER - 1] HIDDEN; +#define SV_LOGF_POLY_ORDER 8 +extern const float __sv_logf_poly[SV_LOGF_POLY_ORDER - 1] HIDDEN; + #endif diff --git a/pl/math/sv_logf_3u4.c b/pl/math/sv_logf_3u4.c new file mode 100644 index 0000000..125f806 --- /dev/null +++ b/pl/math/sv_logf_3u4.c @@ -0,0 +1,66 @@ +/* + * Single-precision vector log function. + * + * Copyright (c) 2019-2022, Arm Limited. + * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception + */ + +#include "sv_math.h" +#if SV_SUPPORTED + +#define P(i) __sv_logf_poly[i] + +#define Ln2 (0x1.62e43p-1f) /* 0x3f317218 */ +#define Min (0x00800000) +#define Max (0x7f800000) +#define Mask (0x007fffff) +#define Off (0x3f2aaaab) /* 0.666667 */ + +float +optr_aor_log_f32 (float); + +static NOINLINE sv_f32_t +__sv_logf_specialcase (sv_f32_t x, sv_f32_t y, svbool_t cmp) +{ + return sv_call_f32 (optr_aor_log_f32, x, y, cmp); +} + +/* Optimised implementation of SVE logf, using the same algorithm and polynomial + as the Neon routine in math/. Maximum error is 3.34 ULPs: + __sv_logf(0x1.557298p+0) got 0x1.26edecp-2 + want 0x1.26ede6p-2. */ +sv_f32_t +__sv_logf_x (sv_f32_t x, const svbool_t pg) +{ + sv_u32_t u = sv_as_u32_f32 (x); + svbool_t cmp + = svcmpge_u32 (pg, svsub_n_u32_x (pg, u, Min), sv_u32 (Max - Min)); + + /* x = 2^n * (1+r), where 2/3 < 1+r < 4/3. */ + u = svsub_n_u32_x (pg, u, Off); + sv_f32_t n = sv_to_f32_s32_x (pg, svasr_n_s32_x (pg, sv_as_s32_u32 (u), + 23)); /* Sign-extend. */ + u = svand_n_u32_x (pg, u, Mask); + u = svadd_n_u32_x (pg, u, Off); + sv_f32_t r = svsub_n_f32_x (pg, sv_as_f32_u32 (u), 1.0f); + + /* y = log(1+r) + n*ln2. */ + sv_f32_t r2 = svmul_f32_x (pg, r, r); + /* n*ln2 + r + r2*(P6 + r*P5 + r2*(P4 + r*P3 + r2*(P2 + r*P1 + r2*P0))). */ + sv_f32_t p = sv_fma_n_f32_x (pg, P (1), r, sv_f32 (P (2))); + sv_f32_t q = sv_fma_n_f32_x (pg, P (3), r, sv_f32 (P (4))); + sv_f32_t y = sv_fma_n_f32_x (pg, P (5), r, sv_f32 (P (6))); + p = sv_fma_n_f32_x (pg, P (0), r2, p); + q = sv_fma_f32_x (pg, p, r2, q); + y = sv_fma_f32_x (pg, q, r2, y); + p = sv_fma_n_f32_x (pg, Ln2, n, r); + y = sv_fma_f32_x (pg, y, r2, p); + + if (unlikely (svptest_any (pg, cmp))) + return __sv_logf_specialcase (x, y, cmp); + return y; +} + +strong_alias (__sv_logf_x, _ZGVsMxv_logf) + +#endif // SV_SUPPORTED diff --git a/pl/math/sv_logf_data.c b/pl/math/sv_logf_data.c new file mode 100644 index 0000000..0082ee3 --- /dev/null +++ b/pl/math/sv_logf_data.c @@ -0,0 +1,12 @@ +/* + * Coefficients for single-precision SVE log function. + * + * Copyright (c) 2019-2022, Arm Limited. + * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception + */ + +const float __sv_logf_poly[] = { + /* Copied from coeffs for the Neon routine in math/. */ + -0x1.3e737cp-3f, 0x1.5a9aa2p-3f, -0x1.4f9934p-3f, 0x1.961348p-3f, + -0x1.00187cp-2f, 0x1.555d7cp-2f, -0x1.ffffc8p-2f, +}; diff --git a/pl/math/test/mathbench_funcs.h b/pl/math/test/mathbench_funcs.h index 076340e..1ecd1d4 100644 --- a/pl/math/test/mathbench_funcs.h +++ b/pl/math/test/mathbench_funcs.h @@ -117,6 +117,9 @@ SVF (_ZGVsMxv_cosf, -3.1, 3.1) SVF (__sv_sinf_x, -3.1, 3.1) SVF (_ZGVsMxv_sinf, -3.1, 3.1) +SVF (__sv_logf_x, 0.01, 11.1) +SVF (_ZGVsMxv_logf, 0.01, 11.1) + SVF (__sv_log10f_x, 0.01, 11.1) SVF (_ZGVsMxv_log10f, 0.01, 11.1) SVD (__sv_log10_x, 0.01, 11.1) diff --git a/pl/math/test/runulp.sh b/pl/math/test/runulp.sh index 3475adb..656d7a7 100755 --- a/pl/math/test/runulp.sh +++ b/pl/math/test/runulp.sh @@ -332,6 +332,15 @@ range_sve_log10f=' 100 inf 50000 ' +range_sve_logf=' + -0.0 -0x1p126 100 + 0x1p-149 0x1p-126 4000 + 0x1p-126 0x1p-23 50000 + 0x1p-23 1.0 50000 + 1.0 100 50000 + 100 inf 50000 +' + # error limits L_erfc=3.7 L_erfcf=1.0 @@ -359,6 +368,7 @@ L_sve_atan2f=3.0 L_sve_atan2=2.0 L_sve_log10=2.5 L_sve_log10f=3.5 +L_sve_logf=3.5 while read G F R do @@ -446,6 +456,8 @@ sve_atanf __sv_atanf $runsv sve_atanf _ZGVsMxv_atanf $runsv sve_log10f __sv_log10f $runsv sve_log10f _ZGVsMxv_log10f $runsv +sve_logf __sv_logf $runsv +sve_logf _ZGVsMxv_logf $runsv sve_cos __sv_cos $runsv sve_cos _ZGVsMxv_cos $runsv diff --git a/pl/math/test/ulp_funcs.h b/pl/math/test/ulp_funcs.h index 78fddac..01d7bd1 100644 --- a/pl/math/test/ulp_funcs.h +++ b/pl/math/test/ulp_funcs.h @@ -75,6 +75,8 @@ SVF1 (cos) ZSVF1 (cos) SVD1 (cos) ZSVD1 (cos) +SVF1 (log) +ZSVF1 (log) SVF1 (log10) ZSVF1 (log10) SVD1 (log10) diff --git a/pl/math/test/ulp_wrappers.h b/pl/math/test/ulp_wrappers.h index d275271..07fa077 100644 --- a/pl/math/test/ulp_wrappers.h +++ b/pl/math/test/ulp_wrappers.h @@ -88,6 +88,7 @@ ZVND1_WRAP(log2) ZSVNF2_WRAP(atan2) ZSVNF1_WRAP(atan) ZSVNF1_WRAP(cos) +ZSVNF1_WRAP(log) ZSVNF1_WRAP(log10) ZSVNF1_WRAP(sin) |