From cda6bb41a2030689dfae885d06c042111e5b07f3 Mon Sep 17 00:00:00 2001 From: Joe Ramsay Date: Wed, 19 Oct 2022 14:21:00 +0100 Subject: pl/math: Add vector/SVE erfc New routine is an SVE port of the Neon routine, including the exp_tail helper. It is accurate to 4 ULP. --- pl/math/sv_exp_tail.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 pl/math/sv_exp_tail.h (limited to 'pl/math/sv_exp_tail.h') diff --git a/pl/math/sv_exp_tail.h b/pl/math/sv_exp_tail.h new file mode 100644 index 0000000..846fe97 --- /dev/null +++ b/pl/math/sv_exp_tail.h @@ -0,0 +1,79 @@ +/* + * Double-precision SVE e^(x+tail) function. + * + * Copyright (c) 2021-2022, Arm Limited. + * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception + */ + +#ifndef SV_EXP_TAIL_H +#define SV_EXP_TAIL_H + +#include "sv_math.h" +#if SV_SUPPORTED + +#include "v_exp_tail.h" + +#define C1 sv_f64 (C1_scal) +#define C2 sv_f64 (C2_scal) +#define C3 sv_f64 (C3_scal) +#define MinusLn2hi (-Ln2hi_scal) +#define MinusLn2lo (-Ln2lo_scal) + +#define N (1 << V_EXP_TAIL_TABLE_BITS) +#define Tab __v_exp_tail_data +#define IndexMask (N - 1) +#define Shift sv_f64 (0x1.8p+52) +#define Thres 704.0 + +static inline sv_f64_t +sv_exp_tail_special_case (svbool_t pg, sv_f64_t s, sv_f64_t y, sv_f64_t n) +{ + sv_f64_t absn = svabs_f64_x (pg, n); + + /* 2^(n/N) may overflow, break it up into s1*s2. */ + sv_u64_t b = svsel_u64 (svcmple_n_f64 (pg, n, 0), sv_u64 (0x6000000000000000), + sv_u64 (0)); + sv_f64_t s1 = sv_as_f64_u64 (svsubr_n_u64_x (pg, b, 0x7000000000000000)); + sv_f64_t s2 = sv_as_f64_u64 ( + svadd_u64_x (pg, svsub_n_u64_x (pg, sv_as_u64_f64 (s), 0x3010000000000000), + b)); + + svbool_t cmp = svcmpgt_n_f64 (pg, absn, 1280.0 * N); + sv_f64_t r1 = svmul_f64_x (pg, s1, s1); + sv_f64_t r0 = svmul_f64_x (pg, sv_fma_f64_x (pg, y, s2, s2), s1); + return svsel_f64 (cmp, r1, r0); +} + +static inline sv_f64_t +sv_exp_tail (const svbool_t pg, sv_f64_t x, sv_f64_t xtail) +{ + /* Calculate exp(x + xtail). */ + sv_f64_t z = sv_fma_n_f64_x (pg, InvLn2_scal, x, Shift); + sv_f64_t n = svsub_f64_x (pg, z, Shift); + + sv_f64_t r = sv_fma_n_f64_x (pg, MinusLn2hi, n, x); + r = sv_fma_n_f64_x (pg, MinusLn2lo, n, r); + + sv_u64_t u = sv_as_u64_f64 (z); + sv_u64_t e = svlsl_n_u64_x (pg, u, 52 - V_EXP_TAIL_TABLE_BITS); + sv_u64_t i = svand_n_u64_x (pg, u, IndexMask); + + sv_f64_t y = sv_fma_f64_x (pg, C3, r, C2); + y = sv_fma_f64_x (pg, y, r, C1); + y = sv_fma_f64_x (pg, y, r, sv_f64 (1.0)); + y = sv_fma_f64_x (pg, y, r, xtail); + + /* s = 2^(n/N). */ + u = sv_lookup_u64_x (pg, Tab, i); + sv_f64_t s = sv_as_f64_u64 (svadd_u64_x (pg, u, e)); + + svbool_t cmp = svcmpgt_n_f64 (pg, svabs_f64_x (pg, x), Thres); + if (unlikely (svptest_any (pg, cmp))) + { + return sv_exp_tail_special_case (pg, s, y, n); + } + return sv_fma_f64_x (pg, y, s, s); +} + +#endif +#endif -- cgit v1.2.3 From f0f80b8a19b2593491847ed87456694d789f6f80 Mon Sep 17 00:00:00 2001 From: Joe Ramsay Date: Fri, 6 Jan 2023 09:10:57 +0000 Subject: pl/math: Update copyright years All files in pl/math updated to 2023. --- pl/math/sv_exp_tail.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pl/math/sv_exp_tail.h') diff --git a/pl/math/sv_exp_tail.h b/pl/math/sv_exp_tail.h index 846fe97..9b739da 100644 --- a/pl/math/sv_exp_tail.h +++ b/pl/math/sv_exp_tail.h @@ -1,7 +1,7 @@ /* * Double-precision SVE e^(x+tail) function. * - * Copyright (c) 2021-2022, Arm Limited. + * Copyright (c) 2021-2023, Arm Limited. * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception */ -- cgit v1.2.3