Skip to content

Initial implementation of core_float_math #138087

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Mar 6, 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 inherent 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.

The following are included to start:

  • floor
  • ceil
  • round
  • round_ties_even
  • trunc
  • fract
  • mul_add
  • div_euclid
  • rem_euclid
  • powi
  • sqrt
  • abs_sub
  • cbrt

These mirror the set of functions that we have in compiler-builtins
since 1, with the exception of powi that has been there longer.

Details for each of the changes is in the commit messages.

Tracking issue: #137578

try-job: aarch64-gnu
tru-job: armhf-gnu
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 6, 2025
@rust-log-analyzer

This comment has been minimized.

@tgross35

This comment was marked as outdated.

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 6, 2025
Initial implementation of `core_float_math`

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 inherent 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.

The following are included to start:

* floor
* ceil
* round
* round_ties_even
* trunc
* fract
* mul_add
* div_euclid
* rem_euclid
* powi
* sqrt
* abs_sub
* cbrt

These mirror the set of functions that we have in `compiler-builtins`
since [1].

Tracking issue: rust-lang#137578

[1]: rust-lang/compiler-builtins#763

r? `@ghost`

try-job: aarch64-gnu
try-job: arm-android
tru-job: armhf-gnu
try-job: test-various
try-job: x86_64-apple-1
try-job: aarch64-apple
try-job: i686-msvc-1
try-job: x86_64-msvc-ext2
@bors

This comment was marked as outdated.

@tgross35

This comment was marked as outdated.

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 6, 2025
Initial implementation of `core_float_math`

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 inherent 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.

The following are included to start:

* floor
* ceil
* round
* round_ties_even
* trunc
* fract
* mul_add
* div_euclid
* rem_euclid
* powi
* sqrt
* abs_sub
* cbrt

These mirror the set of functions that we have in `compiler-builtins`
since [1].

Tracking issue: rust-lang#137578

[1]: rust-lang/compiler-builtins#763

r? `@ghost`

try-job: aarch64-apple
try-job: aarch64-gnu
try-job: arm-android
tru-job: armhf-gnu
try-job: dist-various-1
try-job: dist-various-2
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-apple-1
try-job: x86_64-msvc-ext2
@bors

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@tgross35

This comment was marked as outdated.

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 6, 2025
Initial implementation of `core_float_math`

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 inherent 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.

The following are included to start:

* floor
* ceil
* round
* round_ties_even
* trunc
* fract
* mul_add
* div_euclid
* rem_euclid
* powi
* sqrt
* abs_sub
* cbrt

These mirror the set of functions that we have in `compiler-builtins`
since [1], with the exception of `powi` that has been there longer.

Tracking issue: rust-lang#137578

[1]: rust-lang/compiler-builtins#763

r? `@ghost`

try-job: aarch64-apple
try-job: aarch64-gnu
try-job: arm-android
tru-job: armhf-gnu
try-job: dist-various-1
try-job: dist-various-2
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-apple-1
try-job: x86_64-msvc-ext2
@bors

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

@bors

This comment was marked as outdated.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 6, 2025
@tgross35 tgross35 force-pushed the core-float-math branch 2 times, most recently from 4375018 to 77794c6 Compare March 6, 2025 21:15
@tgross35

This comment was marked as outdated.

@bors

This comment was marked as outdated.

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 6, 2025
Initial implementation of `core_float_math`

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 inherent 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.

The following are included to start:

* floor
* ceil
* round
* round_ties_even
* trunc
* fract
* mul_add
* div_euclid
* rem_euclid
* powi
* sqrt
* abs_sub
* cbrt

These mirror the set of functions that we have in `compiler-builtins`
since [1], with the exception of `powi` that has been there longer.

Tracking issue: rust-lang#137578

[1]: rust-lang/compiler-builtins#763

r? `@ghost`

try-job: aarch64-apple
try-job: aarch64-gnu
try-job: arm-android
tru-job: armhf-gnu
try-job: dist-various-1
try-job: dist-various-2
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-apple-1
try-job: x86_64-msvc-ext2
@tgross35 tgross35 marked this pull request as ready for review March 6, 2025 21:35
@tgross35
Copy link
Contributor Author

tgross35 commented Mar 6, 2025

test-various passed, the others likely only need tweaks for f128 config.

r? @Amanieu

@tgross35
Copy link
Contributor Author

Added a skip for the fma tests on mingw for now, the try job is running for that. It sounds like we have a fix for #140515 planned so we should be able to unignore them soon.

At this point there have been a handful of changes from the original review (though nothing fundamental), so I re-requested.

@rust-log-analyzer

This comment has been minimized.

@tgross35 tgross35 force-pushed the core-float-math branch from 9489ace to 15af070 Compare May 1, 2025 00:04
@tgross35
Copy link
Contributor Author

tgross35 commented May 1, 2025

Seems like fmaf is also affected.

@bors try

@bors
Copy link
Collaborator

bors commented May 1, 2025

⌛ Trying commit 15af070 with merge 9838adf...

bors added a commit to rust-lang-ci/rust that referenced this pull request May 1, 2025
Initial implementation of `core_float_math`

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 inherent 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.

The following are included to start:

* floor
* ceil
* round
* round_ties_even
* trunc
* fract
* mul_add
* div_euclid
* rem_euclid
* powi
* sqrt
* abs_sub
* cbrt

These mirror the set of functions that we have in `compiler-builtins`
since [1], with the exception of `powi` that has been there longer.

Details for each of the changes is in the commit messages.

Tracking issue: rust-lang#137578

[1]: rust-lang/compiler-builtins#763

try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
@bors
Copy link
Collaborator

bors commented May 1, 2025

☀️ Try build successful - checks-actions
Build commit: 9838adf (9838adf28c46b1a0309a0ddb48276aedcb179cde)

tgross35 added 2 commits May 13, 2025 22:08
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 inherent 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.

The following are included to start:

* floor
* ceil
* round
* round_ties_even
* trunc
* fract
* mul_add
* div_euclid
* rem_euclid
* powi
* sqrt
* abs_sub
* cbrt

These mirror the set of functions that we have in `compiler-builtins`
since [1].

Tracking issue: rust-lang#137578

[1]: rust-lang/compiler-builtins#763
Many float-related tests in `std` only depend on `core`, so move the
tests there. This also allows us to verify functions from
`core_float_math`.

Since the majority of test files need to be moved to `coretests`, move
the files here without any cleanup; this is done in a followup commit.
This makes git history slightly cleaner, but coretests will not build
immediately after this commit.
@tgross35
Copy link
Contributor Author

tgross35 commented May 13, 2025

Most recent diff of diffs git range-diff 456d8a0b5901fd87dcb17282bcdabc514eb16b8a~1..15af070f604b715ffce195619191f3b08255af10 36790d28810ac188a8bca7fc9e95fe0869ae9a11~1..a2f1d6400e168eda6e17da59d3da288d125155fe

@tgross35
Copy link
Contributor Author

@bors try

@bors
Copy link
Collaborator

bors commented May 14, 2025

⌛ Trying commit a2f1d64 with merge 1ce122e...

bors added a commit to rust-lang-ci/rust that referenced this pull request May 14, 2025
Initial implementation of `core_float_math`

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 inherent 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.

The following are included to start:

* floor
* ceil
* round
* round_ties_even
* trunc
* fract
* mul_add
* div_euclid
* rem_euclid
* powi
* sqrt
* abs_sub
* cbrt

These mirror the set of functions that we have in `compiler-builtins`
since [1], with the exception of `powi` that has been there longer.

Details for each of the changes is in the commit messages.

Tracking issue: rust-lang#137578

[1]: rust-lang/compiler-builtins#763

try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented May 14, 2025

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 14, 2025
tgross35 added 2 commits May 14, 2025 14:29
The previous commit moved all test files from `std` to `core` so git
understands the move. Not all functionality is actually testable in
`core`, however, so perform move the relevant portions back. Changes
from inherent to module methods is also done since this is the form of
math operations available in `core` (as `core_float_math`).
Per [1], MinGW has an incorrect fma implementation. This showed up in
tests run with cranelift after adding float math operations to `core`.
Presumably we hadn't noticed this when running tests with LLVM because
LLVM was constant folding the result away.

Rust issue: rust-lang#140515

[1]: https://sourceforge.net/p/mingw-w64/bugs/848/
@tgross35
Copy link
Contributor Author

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request May 14, 2025
Initial implementation of `core_float_math`

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 inherent 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.

The following are included to start:

* floor
* ceil
* round
* round_ties_even
* trunc
* fract
* mul_add
* div_euclid
* rem_euclid
* powi
* sqrt
* abs_sub
* cbrt

These mirror the set of functions that we have in `compiler-builtins`
since [1], with the exception of `powi` that has been there longer.

Details for each of the changes is in the commit messages.

Tracking issue: rust-lang#137578

[1]: rust-lang/compiler-builtins#763

try-job: aarch64-gnu
tru-job: armhf-gnu
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
@bors
Copy link
Collaborator

bors commented May 14, 2025

⌛ Trying commit 65117ee with merge 9577b71...

@bors
Copy link
Collaborator

bors commented May 14, 2025

☀️ Try build successful - checks-actions
Build commit: 9577b71 (9577b719e027050906395fd518d4df98fa17ced3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rla-silenced Silences rust-log-analyzer postings to the PR it's added on. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants