-
Notifications
You must be signed in to change notification settings - Fork 218
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
Make a subset of libm
symbols weakly available on all platforms
#763
Merged
Conversation
This file contains 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
Yes, this sounds perfectly reasonable. |
4832ff0
to
cbc5f3a
Compare
018616e ("Always have math functions but with `weak` linking attribute if we can") made all math symbols available on platforms that support weak linkage. This caused some unexpected regressions, however, because our less accurate and sometimes slow routines were being selected over the system `libm`, which also tends to be weak [1]. Thus, 0fab77e ("Don't include `math` for `unix` and `wasi` targets") was applied to undo these changes on many platforms. Now that some improvements have been made to `libm`, add back a subset of these functions: * cbrt * ceil * copysign * fabs * fdim * floor * fma * fmax * fmaximum * fmin * fminimum * fmod * rint * round * roundeven * sqrt * trunc This list includes only functions that produce exact results (verified with exhaustive / extensive tests, and also required by IEEE in most cases), and for which benchmarks indicate performance similar to or better than Musl's soft float math routines [^1]. All except `cbrt` also have `f16` and `f128` implementations. Once more routines meet these criteria, we can move them from platform-specific availability to always available. Once this change makes it to rust-lang/rust, we will also be able to move the relevant functions from `std` to `core`. [^1]: We still rely on the backend to provide optimized assmebly routines when available. [1]: rust-lang/rust#128386
cbc5f3a
to
31f7b60
Compare
tgross35
added a commit
to tgross35/rust
that referenced
this pull request
Feb 25, 2025
Since [1], `compiler-builtins` makes a certain set of math symbols weakly available on all platforms. This means we can begin exposing some of the related functions in `core`, so begin this process here. It is not possible to provide inerent methods in both `core` and `std` while giving them different stability gates, so standalone functions are added instead. This provides a way to experiment with the functionality while unstable; once it is time to stabilize, they can be converted to inherent. For `f16` and `f128`, everything is unstable so we can move the inherent methods. [1]: rust-lang/compiler-builtins#763
tgross35
added a commit
to tgross35/rust
that referenced
this pull request
Feb 25, 2025
Includes a change to make a subset of math symbols available on all platforms [1]. [1]: rust-lang/compiler-builtins#763
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Feb 25, 2025
Update `compiler-builtins` to 0.1.149 Includes a change to make a subset of math symbols available on all platforms [1]. [1]: rust-lang/compiler-builtins#763 try-job: aarch64-gnu try-job: armhf-gnu try-job: i686-gnu-1 try-job: i686-mingw-1 try-job: i686-mingw-2 try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Feb 28, 2025
Update `compiler-builtins` to 0.1.149 Includes a change to make a subset of math symbols available on all platforms [1]. [1]: rust-lang/compiler-builtins#763 try-job: aarch64-gnu try-job: armhf-gnu try-job: i686-gnu-1 try-job: i686-mingw-1 try-job: i686-mingw-2 try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2
tgross35
added a commit
to tgross35/rust
that referenced
this pull request
Mar 1, 2025
Includes a change to make a subset of math symbols available on all platforms [1]. [1]: rust-lang/compiler-builtins#763
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Mar 1, 2025
Update `compiler-builtins` to 0.1.149 Includes a change to make a subset of math symbols available on all platforms [1]. [1]: rust-lang/compiler-builtins#763 try-job: dist-various-1 try-job: dist-various-2 try-job: dist-aarch64-linux try-job: dist-x86_64-linux
tgross35
added a commit
to tgross35/rust
that referenced
this pull request
Mar 1, 2025
Includes a change to make a subset of math symbols available on all platforms [1], and disables `f16` on aarch64 without neon [2]. [1]: rust-lang/compiler-builtins#763 [2]: rust-lang/compiler-builtins#775
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Mar 1, 2025
Update `compiler-builtins` to 0.1.149 Includes a change to make a subset of math symbols available on all platforms [1], and disables `f16` on aarch64 without neon [2]. [1]: rust-lang/compiler-builtins#763 [2]: rust-lang/compiler-builtins#775 try-job: aarch64-gnu try-job: aarch64-gnu-debug try-job: armhf-gnu try-job: dist-various-1 try-job: dist-various-2 try-job: dist-aarch64-linux try-job: dist-arm-linux try-job: dist-armv7-linux try-job: dist-x86_64-linux try-job: test-various
jieyouxu
added a commit
to jieyouxu/rust
that referenced
this pull request
Mar 4, 2025
Update `compiler-builtins` to 0.1.149 Includes a change to make a subset of math symbols available on all platforms [1], and disables `f16` on aarch64 without neon [2]. [1]: rust-lang/compiler-builtins#763 [2]: rust-lang/compiler-builtins#775 try-job: aarch64-gnu try-job: aarch64-gnu-debug try-job: armhf-gnu try-job: dist-various-1 try-job: dist-various-2 try-job: dist-aarch64-linux try-job: dist-arm-linux try-job: dist-armv7-linux try-job: dist-x86_64-linux try-job: test-various
workingjubilee
added a commit
to workingjubilee/rustc
that referenced
this pull request
Mar 4, 2025
Update `compiler-builtins` to 0.1.149 Includes a change to make a subset of math symbols available on all platforms [1], and disables `f16` on aarch64 without neon [2]. [1]: rust-lang/compiler-builtins#763 [2]: rust-lang/compiler-builtins#775 try-job: aarch64-gnu try-job: aarch64-gnu-debug try-job: armhf-gnu try-job: dist-various-1 try-job: dist-various-2 try-job: dist-aarch64-linux try-job: dist-arm-linux try-job: dist-armv7-linux try-job: dist-x86_64-linux try-job: test-various
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
018616e ("Always have math functions but with
weak
linking attribute if we can") made all math symbols available on platforms that support weak linkage. This caused some unexpected regressions, however, because our less accurate and sometimes slow routines were being selected over the systemlibm
, which also tends to be weak 1. Thus, 0fab77e ("Don't includemath
forunix
andwasi
targets") was applied to undo these changes on many platforms.Now that some improvements have been made to
libm
, add back a subset of these functions:This list includes only functions that produce exact results (verified with exhaustive / extensive tests, and also required by IEEE in most cases), and for which benchmarks indicate performance similar to or better than Musl's soft float math routines 1. All except
cbrt
also havef16
andf128
implementations. Once more routines meet these criteria, we can move them from platform-specific availability to always available.Once this change makes it to rust-lang/rust, we will also be able to move the relevant functions from
std
tocore
.Footnotes
We still rely on the backend to provide optimized assmebly
routines when available. ↩