summaryrefslogtreecommitdiff
path: root/libc/test/src/math/tanf_test.cpp
AgeCommit message (Collapse)Author
2025-10-21[libc][math] Add tolerance to math tests so that they still work when ↵lntue
accurate path is skipped. (#164522)
2025-09-10[libc] Clean up errno header usage in math tests. (#157898)Alexey Samsonov
This is one more follow-up to PR https://github.com/llvm/llvm-project/pull/157517 that cleans up the usage of libc_errno in math unit-tests (non-smoke). It follows the same rule: * if you use libc_errno in code literally, include src/__support/libc_errno.h * if you only rely on errno constants, include hdr/errno_macros.h Several tests for exp/log still retain the direct libc_errno usage, since in some cases they skip doing any validation if the error was raised. But the direct usage of libc_errno is removed from all other cases.
2025-07-23[libc][NFC] Add stdint.h proxy header to fix dependency issue with ↵lntue
<stdint.h> includes. (#150303) https://github.com/llvm/llvm-project/issues/149993
2025-06-11[libc] Move libc_errno.h to libc/src/__support and make ↵lntue
LIBC_ERRNO_MODE_SYSTEM to be header-only. (#143187) This is the first step in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2024-10-05[libc] remove errno.h includes (#110934)Job Henandez Lara
2024-07-28[libc] Create a separate proxy header for math-function-macros.h (#98430)Nhat Nguyen
Fix #98393
2024-04-05[libc] Add proxy header math_macros.h. (#87598)lntue
Context: https://github.com/llvm/llvm-project/pull/87017 - Add proxy header `libc/hdr/math_macros.h` that will: - include `<math.h>` in overlay mode, - include `"include/llvm-libc-macros/math-macros.h"` in full build mode. - Its corresponding CMake target `libc.hdr.math_macros` will only depend on `libc.include.math` and `libc.include.llvm-libc-macros.math_macros` in full build mode. - Replace all `#include "include/llvm-libc-macros/math-macros.h"` with `#include "hdr/math_macros.h"`. - Add dependency to `libc.hdr.math_macros` CMake target when using `add_fp_unittest`. - Update the remaining dependency. - Update bazel overlay: add `libc:hdr_math_macros` target, and replacing all dependency on `libc:llvm_libc_macros_math_macros` with `libc:hdr_math_macros`.
2024-03-18[libc] Remove direct math.h includes (#85324)Michael Jones
Reland of #84991 A downstream overlay mode user ran into issues with the isnan macro not working in our sources with a specific libc configuration. This patch replaces the last direct includes of math.h with our internal math_macros.h, along with the necessary build system changes.
2024-02-06[libc] Move libc_errno inside of LIBC_NAMESPACE (#80774)michaelrj-google
Having libc_errno outside of the namespace causes versioning issues when trying to link the tests against LLVM-libc. Most of this patch is just moving libc_errno inside the namespace in tests. This isn't necessary in the function implementations since those are already inside the namespace.
2024-01-23[libc][NFC] Remove `FPBits` cast operator (#79142)Guillaume Chatelet
The semantics for casting can range from "bitcast" (same representation) to "different representation", to "type promotion". Here we remove the cast operator and force usage of `get_val` as the only function to get the floating point value, making the intent clearer and more consistent.
2023-10-19[libc][math][NFC] Remove global scope constants declaration in math tests ↵lntue
(#69558) Clean up usage of `DECLARE_SPECIAL_CONSTANTS` in global scope.
2023-09-26[libc] Mass replace enclosing namespace (#67032)Guillaume Chatelet
This is step 4 of https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079
2023-06-01[libc] Reduce math tests runtimeGuillaume Chatelet
Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D151798
2023-03-07[libc][math] Switch math functions to use libc_errno and fix some errno and ↵Tue Ly
floating point exceptions. Switch math functions to use libc_errno and fix some errno and floating point exceptions Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D145349
2023-02-07[libc][NFC] Move UnitTest and IntegrationTest to the 'test' directory.Siva Chandra Reddy
This part of the effort to make all test related pieces into the `test` directory. This helps is excluding test related pieces in a straight forward manner if LLVM_INCLUDE_TESTS is OFF. Future patches will also move the MPFR wrapper and testutils into the 'test' directory.
2022-09-26[libc][math] Simplify tanf implementation and improve its performance.Tue Ly
Simplify `tanf` implementation and improve its performance. Completely reuse the implementation of `sinf`, `cosf`, `sincosf` and use the definition `tan(x) = sin(x)/cos(x)`. Performance benchmark using perf tool from the CORE-MATH project on Ryzen 1700: ``` $ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh tanf GNU libc version: 2.35 GNU libc release: stable CORE-MATH reciprocal throughput : 18.558 System LIBC reciprocal throughput : 49.919 BEFORE: LIBC reciprocal throughput : 36.480 LIBC reciprocal throughput : 27.217 (with `-msse4.2` flag) LIBC reciprocal throughput : 20.205 (with `-mfma` flag) AFTER: LIBC reciprocal throughput : 30.337 LIBC reciprocal throughput : 21.072 (with `-msse4.2` flag) LIBC reciprocal throughput : 15.804 (with `-mfma` flag) $ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh tanf --latency GNU libc version: 2.35 GNU libc release: stable CORE-MATH latency : 56.702 System LIBC latency : 107.206 BEFORE LIBC latency : 97.598 LIBC latency : 91.119 (with `-msse4.2` flag) LIBC latency : 82.655 (with `-mfma` flag) AFTER LIBC latency : 74.560 LIBC latency : 66.575 (with `-msse4.2` flag) LIBC latency : 61.636 (with `-mfma` flag) ``` Reviewed By: zimmermann6 Differential Revision: https://reviews.llvm.org/D134575
2022-08-12[libc] Implement tanf function correctly rounded for all rounding modes.Tue Ly
Implement tanf function correctly rounded for all rounding modes. We use the range reduction that is shared with `sinf`, `cosf`, and `sincosf`: ``` k = round(x * 32/pi) and y = x * (32/pi) - k. ``` Then we use the tangent of sum formula: ``` tan(x) = tan((k + y)* pi/32) = tan((k mod 32) * pi / 32 + y * pi/32) = (tan((k mod 32) * pi/32) + tan(y * pi/32)) / (1 - tan((k mod 32) * pi/32) * tan(y * pi/32)) ``` We need to make a further reduction when `k mod 32 >= 16` due to the pole at `pi/2` of `tan(x)` function: ``` if (k mod 32 >= 16): k = k - 31, y = y - 1.0 ``` And to compute the final result, we store `tan(k * pi/32)` for `k = -15..15` in a table of 32 double values, and evaluate `tan(y * pi/32)` with a degree-11 minimax odd polynomial generated by Sollya with: ``` > P = fpminimax(tan(y * pi/32)/y, [|0, 2, 4, 6, 8, 10|], [|D...|], [0, 1.5]); ``` Performance benchmark using `perf` tool from the CORE-MATH project on Ryzen 1700: ``` $ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh tanf CORE-MATH reciprocal throughput : 18.586 System LIBC reciprocal throughput : 50.068 LIBC reciprocal throughput : 33.823 LIBC reciprocal throughput : 25.161 (with `-msse4.2` flag) LIBC reciprocal throughput : 19.157 (with `-mfma` flag) $ CORE_MATH_PERF_MODE="rdtsc" ./perf.sh tanf --latency GNU libc version: 2.31 GNU libc release: stable CORE-MATH latency : 55.630 System LIBC latency : 106.264 LIBC latency : 96.060 LIBC latency : 90.727 (with `-msse4.2` flag) LIBC latency : 82.361 (with `-mfma` flag) ``` Reviewed By: orex Differential Revision: https://reviews.llvm.org/D131715