-
Notifications
You must be signed in to change notification settings - Fork 16.8k
[libc][math] Refractor sinhf to Header only #177336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3ceb174
Use constexpr for sinhf #147386
an1k3sh 1f18110
correct bug in __support/math/CMakeLists
an1k3sh ec6084f
use header implementation for sinhf
an1k3sh c923684
use header implementation for sinhf
an1k3sh 9ad0531
update dependency list and file structures
an1k3sh 9c6eaa6
update bazel build file
an1k3sh 8f3b1fb
update bazel build file
an1k3sh d277ba5
merge main
an1k3sh ed84993
update header files
an1k3sh 0581c98
add inline directive
an1k3sh 37e9d86
Resolve merge conflicts from main
an1k3sh 46449bf
Update libc/src/__support/math/CMakeLists.txt
an1k3sh b2721c9
Update libc/shared/math/sinhf.h - remove extra dashes from comment
an1k3sh 6298805
merge main
an1k3sh 30fc90d
Update libc/shared/math/sinhf.h
bassiounix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //===-- Shared sinhf function -----------------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_LIBC_SHARED_MATH_SINHF_H | ||
| #define LLVM_LIBC_SHARED_MATH_SINHF_H | ||
|
|
||
| #include "shared/libc_common.h" | ||
| #include "src/__support/math/sinhf.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
| namespace shared { | ||
|
|
||
| using math::sinhf; | ||
|
|
||
| } // namespace shared | ||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SHARED_MATH_SINHF_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| //===-- Single-precision sinh function ------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SINHF_H | ||
| #define LLVM_LIBC_SRC___SUPPORT_MATH_SINHF_H | ||
|
|
||
| #include "sinhfcoshf_utils.h" | ||
| #include "src/__support/FPUtil/FEnvImpl.h" | ||
| #include "src/__support/FPUtil/FPBits.h" | ||
| #include "src/__support/FPUtil/rounding_mode.h" | ||
| #include "src/__support/macros/config.h" | ||
| #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| namespace math { | ||
|
|
||
| LIBC_INLINE static constexpr float sinhf(float x) { | ||
| using FPBits = typename fputil::FPBits<float>; | ||
| FPBits xbits(x); | ||
| uint32_t x_abs = xbits.abs().uintval(); | ||
|
|
||
| // When |x| >= 90, or x is inf or nan | ||
| if (LIBC_UNLIKELY(x_abs >= 0x42b4'0000U || x_abs <= 0x3da0'0000U)) { | ||
| // |x| <= 0.078125 | ||
| if (x_abs <= 0x3da0'0000U) { | ||
| #ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS | ||
| // |x| = 0.0005589424981735646724700927734375 | ||
| if (LIBC_UNLIKELY(x_abs == 0x3a12'85ffU)) { | ||
| if (fputil::fenv_is_round_to_nearest()) | ||
| return x; | ||
| } | ||
| #endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS | ||
|
|
||
| // |x| <= 2^-26 | ||
| if (LIBC_UNLIKELY(x_abs <= 0x3280'0000U)) { | ||
| return static_cast<float>( | ||
| LIBC_UNLIKELY(x_abs == 0) ? x : (x + 0.25 * x * x * x)); | ||
| } | ||
|
|
||
| double xdbl = x; | ||
| double x2 = xdbl * xdbl; | ||
| // Sollya: fpminimax(sinh(x),[|3,5,7|],[|D...|],[-1/16-1/64;1/16+1/64],x); | ||
| // Sollya output: x * (0x1p0 + x^0x1p1 * (0x1.5555555556583p-3 + x^0x1p1 | ||
| // * (0x1.111110d239f1fp-7 | ||
| // + x^0x1p1 * 0x1.a02b5a284013cp-13))) | ||
| // Therefore, output of Sollya = x * pe; | ||
| double pe = fputil::polyeval(x2, 0.0, 0x1.5555555556583p-3, | ||
| 0x1.111110d239f1fp-7, 0x1.a02b5a284013cp-13); | ||
| return static_cast<float>(fputil::multiply_add(xdbl, pe, xdbl)); | ||
| } | ||
|
|
||
| if (xbits.is_nan()) | ||
| return x + 1.0f; // sNaN to qNaN + signal | ||
|
|
||
| if (xbits.is_inf()) | ||
| return x; | ||
|
|
||
| int rounding = fputil::quick_get_round(); | ||
| if (xbits.is_neg()) { | ||
| if (LIBC_UNLIKELY(rounding == FE_UPWARD || rounding == FE_TOWARDZERO)) | ||
| return -FPBits::max_normal().get_val(); | ||
| } else { | ||
| if (LIBC_UNLIKELY(rounding == FE_DOWNWARD || rounding == FE_TOWARDZERO)) | ||
| return FPBits::max_normal().get_val(); | ||
| } | ||
|
|
||
| fputil::set_errno_if_required(ERANGE); | ||
| fputil::raise_except_if_required(FE_OVERFLOW); | ||
|
|
||
| return x + FPBits::inf(xbits.sign()).get_val(); | ||
| } | ||
|
|
||
| // sinh(x) = (e^x - e^(-x)) / 2. | ||
| return static_cast<float>( | ||
| math::sinhfcoshf_internal::exp_pm_eval</*is_sinh*/ true>(x)); | ||
| } | ||
|
|
||
| } // namespace math | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SRC___SUPPORT_MATH_SINHF_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.