aboutsummaryrefslogtreecommitdiff
path: root/math
AgeCommit message (Collapse)Author
2023-01-24Update copyright yearsSzabolcs Nagy
Scripted copyright year updates based on git committer date.
2023-01-05Rewrite two abs masks as literalsJoe Ramsay
These were technically undefined behaviour - they have been rewritten without the shift so that their type is unsigned int by default.
2022-12-07math: Set fenv exceptions for several Neon routinesJoe Ramsay
In most cases, we mask lanes which should not trigger exceptions with a neutral value, then let the existing special-case handler fix them up later. For exp and exp2 we replace the more complex special-case handler with a simple scalar fallback. All new behaviour is tested in runulp.sh, with a new option to pass -f to the run line. We also extend the fenv testing to Neon log and logf, which already triggered exceptions correctly. New behaviour is mostly hidden behind a new config setting, WANT_SIMD_EXCEPT.
2022-11-17math/test: Fix ulp for non-AArch64 targetsJoe Ramsay
fv and dv are only declared under __aarch64__ - for other targets the new -c option should be disabled.
2022-11-15math/test: Allow user to set control element of input vectorJoe Ramsay
argf and argd have been designed such that non-special input is tested, optionally followed by a vector with one special lane. To be able to test that vector functions have correct behaviour w.r.t. fenv exceptions, we need to be able to choose a different value for the last lane, as using 1 leads to false negatives when testing a function for which 1 is a special value. We add an option, -c, for the user to provide a different control value.
2022-09-02Add more ulp helper macrosJoe Ramsay
All ulp_funcs entries use the same level of macro expansion. Also add some missing routines in mathlib.h and remove funcs which we do not supply from ulp_funcs.
2022-06-15math: Add support for SVE in mathbench.Pierre Blanchard
Provide dummy example to test benchmarks without having to provide an actual implementation.
2022-06-15math: Add support for SVE in ulp assessment.Pierre Blanchard
This patch provides features for assessing accuracy of SVE routines. It also provides dummy entries and wrappers to test ulp assessment without having to provide an actual implementation.
2022-03-25Add build system and infra for the pl directoryPierre Blanchard
- pl/ is built from top-level Makefile by adding pl to SUBS - PLSUBS lists all pl/ subdirectories that can be built, it only contains math for now. Please modify this list in the top-level config.mk. - pl libraries and infrastructure is built in build/pl/ - As a result math/ and pl/math generate separate test and bench binaries. - Use infrastructure provided in math/test to test and profile pl/math routines. The build system ensures the appropriate header files are first copied to build/pl/include/test to define wrappers and entries in ulp and mathbench. - Copyied scalar erff from math/ to pl/math/ to show build system is functional. - pl mathlib libraries are built separately to the main/portable mathlib libraries and installed alongside.
2022-02-10Add README.contributorsSzabolcs Nagy
Document contributor requirements.
2022-02-10Update lincense to MIT OR Apache-2.0 WITH LLVM-exceptionSzabolcs Nagy
The outgoing license was MIT only. The new dual license allows using the code under Apache-2.0 WITH LLVM-exception license too.
2021-12-21math: fix constant in sinf and cosfSzabolcs Nagy
gcc-12 -frounding-math started using runtime rounding mode for converting double constants to float, so abstop12(pio4) is no longer a compile time constant (this is required by iso c). Use float pio4f instead to make the generated code the same as before and avoid regressions on gcc-12.
2021-02-17Update copyright yearsSzabolcs Nagy
Scripted copyright year updates based on git committer date.
2020-11-13math: fix spurious underflow in erff and erfSzabolcs Nagy
The code relied on the final x + c*x to be done via an fma, otherwise the intermediate c*x could underflow for tiny (almost subnormal) x. Use explicit fmaf like elsewhere (this code is not expected to be fast when fma is not inlined, but at least it should be correct).
2020-11-13math: fix erf tests in directed rounding modesSzabolcs Nagy
erf has larger than 1 ULP errors in directed rounding modes, increase the error threshold to 1.4 ULP in the test script.
2020-11-13math: add scalar erfPierre Blanchard
Only tested in round-to-nearest mode. The expected worst case error is 1.01 ULP near x=1.25. Benchmarked over random x in [-6,6] and can increase performance by > 2x (> 3.5x for throughput) on big ooo cores compared to the implementation in glibc 2.28. Includes data for erfc too, but this patch only adds erf.
2020-11-05math: Fix copyright header in erff.tstSzabolcs Nagy
This was incorrect in the previous commit.
2020-10-29math: add scalar erff.Pierre Blanchard
In round-to-nearest mode the maximum error is 1.09 ULP. Compared to glibc-2.28 erff: throughput is about 2.2x better, latency is about 1.5x better on some AArch64 cores (on random input in [-4,4]). There are further optimization and quality improvement opportunities.
2020-02-27math: Improve comments, disable errno handling by defaultWilco Dijkstra
Improve comments in math_config.h. Set WANT_ERRNO to 0 by default.
2020-01-14math: Add more ulp testsSzabolcs Nagy
Some functions were not tested with the statistical ulp error check tool, this commit adds tests for the current math symbols.
2020-01-14math: add vector powSzabolcs Nagy
This implementation is a wrapper around the scalar pow with appropriate call abi. As such it is not expected to be faster than scalar calls, the new double prec vector pow symbols are provided for completeness.
2020-01-09math: fix spurious overflow in pow with clangSzabolcs Nagy
clang does not support c99 fenv_access and may move fp operations out of conditional blocks causing unconditional fenv side-effects. Here if (cond) ix = f (x * 0x1p52); was transformed to ix_ = f (x * 0x1p52); ix = cond ? ix_ : ix; where x can be a huge negative value so the mul overflows. The added barrier should prevent such transformation by significantly increasing the cost of doing the mul unconditionally. Found by enh from google on android arm and aarch64 targets. Fixes github issue #16.
2019-11-22Build system refactoringSzabolcs Nagy
Reorganise the makefiles so subprojects can be more separately used and maintained. Still kept the single toplevel Makefile and config.mk. Subproject Dir.mk is expected to provide all-X, check-X, clean-X and install-X targets where X is the subproject name and it may use generic make variables set in config.mk, like CFLAGS_ALL and CC, or subproject specific variables like X-cflags.
2019-11-06math: add WANT_VMATH feature macroSzabolcs Nagy
When defined as 0 the vector math code is not built and not tested.
2019-11-06math: allow errno setting even if !(math_errhandling&MATH_ERRNO)Szabolcs Nagy
The math_errhandling checks are incorrect in general: it is defined by the libc math.h which is not appropriate for optimized-routines provided functions that we are testing. However even if we want to test a libc implementation, ISO C allows the setting of errno even if !(math_errhandling&MATH_ERRNO), so relax the checks.
2019-11-06math: fix unused function warnings in mathbench.cSzabolcs Nagy
Vector functions are only used on aarch64, so only define them there. math/test/mathbench.c:95:1: warning: '__v_dummyf' defined but not used [-Wunused-function]
2019-11-06math: fix missing attributes warningsSzabolcs Nagy
gcc-9 started warning if alias symbols have different attributes: math/expf.c: At top level: math/expf.c:89:21: warning: '__expf_finite' specifies less restrictive attributes than its target 'expf': 'leaf', 'nothrow', 'pure' [-Wmissing-attributes] so copy the attributes when creating the aliases.
2019-11-06math: fix unused variable warningsSzabolcs Nagy
Compilers (incorrectly) warn about unused volatile variables: math/math_config.h: In function 'force_eval_float': math/math_config.h:188:18: warning: unused variable 'y' [-Wunused-variable] silence them.
2019-11-06math: move definitions in internal headerSzabolcs Nagy
Compiler checks and realated macros need to be done earlier so they are usable for the static inline functions.
2019-11-05Add vector exp2fSzabolcs Nagy
Same design as in expf. Worst-case error of __v_exp2f and __v_exp2f_1u is 1.96 and 0.88 ulp respectively. It is not clear if round/convert instructions are better or +- Shift. For expf the latter, for exp2f the former seems more consistently faster, but both options are kept in the code for now.
2019-11-05math: fix runulp.shSzabolcs Nagy
Use heredoc instead of pipe when iterating over test cases to avoid creating a subshell that would break the PASS/FAIL accounting.
2019-10-17fix the build of s_powf.o on non-aarch64 targetsSzabolcs Nagy
This is a simple fix to the v_powf code, but in general the vector code may not work on arbitrary targets even when compiled with scalar types (s_powf.c), so in the long term may be all s_* should be disabled for non-aarch64 targets (requires test system and header changes too).
2019-10-14Add vector logSzabolcs Nagy
Worst-case error is 1.67 ulp, the polynomial was generated by sollya. Uses a 128 entry (2KB) lookup table. Special cases fall back to scalar log call.
2019-10-14Add vector sin and cosSzabolcs Nagy
Worst-case error is 3.5 ulp, the polynomial was generated by sollya. For large (>2^23) and special inputs the code falls back to scalar sin and cos.
2019-10-14Add vector powfSzabolcs Nagy
Essentially the scalar powf algorithm is used for each element in the vector just inlined for better scheduling and simpler special case handling. The log polynomial is smaller as less accuracy is enough. Worst-case error is 2.6 ulp.
2019-10-14Add vector sinf and cosfSzabolcs Nagy
The polynomials were produced by searching the coefficient space using heuristics and ideas from https://arxiv.org/abs/1508.03211 The worst-case error is 1.886 ulp, large inputs (> 2^20) and other special cases use scalar sinf and cosf.
2019-10-14Add vector logfSzabolcs Nagy
The polynomial was produced by searching the coefficient space using heuristics and ideas from https://arxiv.org/abs/1508.03211 The worst-case error is 3.34 ulp, subnormal range inputs and other special cases use scalar logf.
2019-10-14Add vector exp, expf and related vector math support codeSzabolcs Nagy
Vector math routines are added to the same libmathlib library as scalar ones. The difficulty is that they are not always available, the external abi depends on the compiler version used for the build. Currently only aarch64 AdvSIMD is supported, there are 4 new sets of symbols: __s_foo is a scalar function with identical result to the vector one, __v_foo is a vector function using the base PCS, __vn_foo uses the vector PCS and _ZGV*_foo is the vector ABI symbol alias of vn_foo for a scalar math function foo. The test and benchmark code got extended to handle vector functions. Vector functions aim for < 5 ulp worst case error, only support nearest rounding mode and don't support floating-point exceptions. Vector functions may call scalar functions to handle special cases, but for a single value they should return the same result independently of values in other vector lanes or the position of the value in the vector. The __v_expf and __v_expf_1u polynomials were produced by searching the coefficient space with some heuristics and ideas from https://arxiv.org/abs/1508.03211 Their worst case error is 1.95 and 0.866 ulp respectively. The exp polynomial was produced by sollya, it uses a 128 element (1KB) lookup table and has 2.38 ulp worst case error.
2019-10-14math: more robust mathbench_libcSzabolcs Nagy
Not all symbols referenced by mathbench may be available in libc so link to libmathlib too to resolve the missing symbols.
2019-10-14math: update the plot scriptSzabolcs Nagy
Fix it to be python3 compatible and plot the exact and approximated values too.
2019-10-14Prevent fenv access breaking optimizations of the ulp toolSzabolcs Nagy
The ulp tool compares output of a math function to a larger precision implementation of the same function. But when the input argument is converted to a larger precision number the signaling nan property is lost, so ensure that the conversion happens inside the critical region where fenv exceptions are checked and then the conversion itself will raise the invalid exception, which is the correct behaviour in most cases. The volatile barrier is not perfect and the snan behaviour is not always signaling, but this should give more reliable results in most cases than before.
2019-10-08Support running the math tests without fenv checksSzabolcs Nagy
fenv support is not reliable in clang so provide a mechanism to disable fenv status checks and only check the result values.
2019-10-08Support separate CFLAGS per subprojectSzabolcs Nagy
Users may want different CFLAGS for math and string subprojects, expose a mechanism for this in config.mk.
2019-10-08fix exit status of ulp and runulp.shSzabolcs Nagy
Make ulp and runulp.sh fail on error.
2019-10-08fix mathtest lineno accountingSzabolcs Nagy
Only increment once per fgets.
2019-10-08fix the exit status of mathtest on failureSzabolcs Nagy
Make mathtest fail on error so make check fails too.
2019-08-28math: add long double symbols when long double is same as doubleSzabolcs Nagy
To allow libmathlib.a to be a drop-in replacement for libc functions on 32bit arm, we should provide long double symbols otherwise the libc long double implementation may pull in double symbols that can conflict with libmathlib.a in case of static linking. Using wrappers instead of alias to avoid type declaration conflicts.
2019-08-27math: fix duplicated declaration in mathlib.hSzabolcs Nagy
Removed tanf declaration since the implementation got removed too.
2019-08-08Do not return failure if MPFR is not supportedAdhemerval Zanella
It avoids the 'make check' to abort when building on architectures that has LDBL_MANT_DIG == DBL_MANT_DIG without the mpfr installed (arm cross-compiling for instance).
2019-07-22Add ULP error plot scriptSzabolcs Nagy
Simple script to visualize the output of the ulp test tool, e.g. $ build/bin/ulp -e .0001 log 0.5 2.0 2345678 | math/tools/plot.py