[libc-commits] [PATCH] D129215: [libc][math] Universal exp function for cosh/sinh calculation.
Tue Ly via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Jul 19 20:50:00 PDT 2022
lntue added inline comments.
================
Comment at: libc/src/math/generic/expxf.h:32
+// EXP_num_p Precise value of the constant is not needed.
+static constexpr double LN2_INV = 1.44269504088896340735 * EXP_num_p;
+
----------------
Use hexadecimal float constant.
================
Comment at: libc/src/math/generic/expxf.h:48
+// negative range.
+static exe_eval_result_t exp_eval(double x) {
+ int64_t ps = fputil::multiply_add(LN2_INV, x, double(ADD_TO_POS) + 0.5);
----------------
`static inline` since this is in a header file.
================
Comment at: libc/src/math/generic/expxf.h:49-53
+ int64_t ps = fputil::multiply_add(LN2_INV, x, double(ADD_TO_POS) + 0.5);
+ // Negative sign due to multiply_add optimization
+ double mult_e1, ml;
+ {
+ uint64_t ps_shifted = ps + (1 << (EXP_bits_p - 1));
----------------
You might want to try to see if using `fputil::nearest_integer` can improve the throughput or not:
```
double ps = fputil::nearest_integer(fputil::multiply_add(LN2_INV, x, static_cast<double>(ADD_TO_POS)));
int64_t ps_shifted = static_cast<int64_t>(ps) + (1 << (EXP_bits_p - 1));
...
```
================
Comment at: libc/src/math/generic/expxf.h:66-67
+ // Taylor series coefficients
+ double pe = dx * fputil::polyeval(dx, 1.0, 1.0 / 2.0, 1.0 / 6.0, 1.0 / 24.0,
+ 1.0 / 120.0, 1.0 / 720.0);
+
----------------
You might want to use a fix representation of `1.0/6.0, ... 1.0/720.0` with hexadecimal floating point literals to reduce an uncertainty due to compiler constant evaluation methods and rounding modes.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D129215/new/
https://reviews.llvm.org/D129215
More information about the libc-commits
mailing list