Skip to content

Conversation

@sayantn
Copy link
Contributor

@sayantn sayantn commented Oct 9, 2025

successor to #146568, this PR actually makes the SIMD intrinsics const, and modifies the tests to test the const-eval implementations

r? @tgross35 ig (although feel free to reassign, this is not anything targeted really)

@rustbot
Copy link
Collaborator

rustbot commented Oct 9, 2025

Some changes occurred to the platform-builtins intrinsics. Make sure the
LLVM backend as well as portable-simd gets adapted for the changes.

cc @antoyo, @GuillaumeGomez, @bjorn3, @calebzulawski, @programmerjake

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 9, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 9, 2025

tgross35 is currently at their maximum review capacity.
They may take a while to respond.

@RalfJung
Copy link
Member

RalfJung commented Oct 9, 2025

Cc @Amanieu

let r: f32 = simd_reduce_mul_unordered(x);
assert_eq!(r, -24_f32);
let x = f32x4::from_array([1., -2., 3., 4.]);
let r: f32 = simd_reduce_add_ordered(x, 0.);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this wasn't there originally, but maybe we should add a test that requires being added in the proper order to return the right result? something like 1.0e20f32 + 1.0 - 1.0e20 - 1.0 == -1.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that seems like a nice idea, but I really don't want to add new tests in this PR - this is pretty big by itself anyway

Copy link
Member

@programmerjake programmerjake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other than that idea for a new test, lgtm

View changes since this review

@sayantn sayantn force-pushed the simd-const-intrinsics branch from 8c71ce0 to 48324c2 Compare November 3, 2025 22:06
@rustbot

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Nov 5, 2025

☔ The latest upstream changes (presumably #148507) made this pull request unmergeable. Please resolve the merge conflicts.

@sayantn sayantn force-pushed the simd-const-intrinsics branch from 48324c2 to 76ddb6f Compare November 5, 2025 21:00
@rustbot

This comment has been minimized.

@sayantn sayantn force-pushed the simd-const-intrinsics branch from 76ddb6f to d1b2151 Compare November 10, 2025 11:14
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@sayantn sayantn force-pushed the simd-const-intrinsics branch from d1b2151 to 8715316 Compare November 10, 2025 21:58
@rustbot
Copy link
Collaborator

rustbot commented Nov 10, 2025

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@sayantn
Copy link
Contributor Author

sayantn commented Nov 14, 2025

@rustbot reroll

Rerolling as @tgross35 is a bit busy

@rustbot rustbot assigned madsmtm and unassigned tgross35 Nov 14, 2025
@madsmtm madsmtm added A-SIMD Area: SIMD (Single Instruction Multiple Data) A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) labels Nov 15, 2025
Copy link
Contributor

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't looked through all the tests, will wait until we figure out whether we can just overwrite assert_eq!, from a quick glance they look fine (they were also reviewed previously in #146568 by @tgross35).

View changes since this review

#[rustc_intrinsic]
#[rustc_nounwind]
pub unsafe fn simd_add<T>(x: T, y: T) -> T;
pub const unsafe fn simd_add<T>(x: T, y: T) -> T;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure of the process here: does this need a compiler FCP to confirm that, yes, we do want t-libs to be able to start depending on these intrinsics being const?

#146568 was reviewed by Ralf, so I guess that's close to as good as it gets in terms of "wg-const-eval is fine with this".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, @Amanieu do we need to do some kind of libs fcp??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The team in charge of intrinsics is t-lang. They will have to be involved when stabilizing any of this, i.e., when adding rustc_intrinsic_const_stable_indirect to an intrinsic.

For the unstable part, notifying @rust-lang/wg-const-eval is enough. From my side this is fine: the only part that needs closer scrutiny is the fact that these are float operations, but we made them behave just like their scalar equivalents which seems right to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so we can continue on this 🎉

@rustbot rustbot 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 Nov 15, 2025
@RalfJung
Copy link
Member

Haven't looked through all the tests, will wait until we figure out whether we can just overwrite assert_eq!, from a quick glance they look fine (they were also reviewed previously in #146568 by @tgross35).

Trevor left two comments but didn't indicate whether they even looked at the entire rest of the PR.

@sayantn sayantn force-pushed the simd-const-intrinsics branch from 8715316 to e48c21b Compare November 16, 2025 20:52
@sayantn
Copy link
Contributor Author

sayantn commented Nov 16, 2025

thanks for your suggestion to shadow assert_eq! @madsmtm, it almost halved the diffcount

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 16, 2025
Copy link
Contributor

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed the tests now, generally happy with them.

Trevor left two comments but didn't indicate whether they even looked at the entire rest of the PR.

Yeah, I should've said "skimmed".

View changes since this review

Co-authored-by: Mads Marquart <[email protected]>
@madsmtm
Copy link
Contributor

madsmtm commented Nov 17, 2025

Thanks for the answers, feel free to r=me when you've rebased, and when we've figured out if we've followed the right process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-SIMD Area: SIMD (Single Instruction Multiple Data) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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.

9 participants