Skip to content

Conversation

@sayantn
Copy link
Contributor

@sayantn sayantn commented Dec 4, 2025

recently most SIMD intrinsics were made available in const contexts in #147521. This PR makes the indirectly stable to use in const contexts.

cc @RalfJung @rust-lang/lang @rust-lang/wg-const-eval

@rustbot
Copy link
Collaborator

rustbot commented Dec 4, 2025

⚠️ #[rustc_intrinsic_const_stable_indirect] controls whether intrinsics can be exposed to stable const
code; adding it needs t-lang approval.

cc @rust-lang/wg-const-eval

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

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

@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 Dec 4, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 4, 2025

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@RalfJung
Copy link
Member

RalfJung commented Dec 4, 2025

So you plan to soon const-stabilize functions using these intrinsics?

@sayantn
Copy link
Contributor Author

sayantn commented Dec 4, 2025

I won't say soon (it would require t-libs-api approval), but yes the plan is eventually to stabilize them

@traviscross traviscross added the I-lang-radar Items that are on lang's radar and will need eventual work or consideration. label Dec 5, 2025
@RalfJung
Copy link
Member

RalfJung commented Dec 5, 2025

Usually we do the t-lang FCP for const intrinsics as part of that stabilization, not preemptively.

Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

For some of these I am not sure they are ready for stabilization.

Also, please give an overview of the test coverage we have for these being invoked from const-eval.

View changes since this review

#[rustc_intrinsic]
#[rustc_nounwind]
#[rustc_intrinsic_const_stable_indirect]
pub const unsafe fn simd_fma<T>(x: T, y: T, z: T) -> T;
Copy link
Member

Choose a reason for hiding this comment

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

For this, not even the scalar version is const-stable yet. It seems odd to stabilize the SIMD version before the scalar version.

Copy link
Member

Choose a reason for hiding this comment

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

More specifically, const-stabilization is in progress at #148052.

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 ok, then I think it would be better to wait until that lands first

#[rustc_intrinsic]
#[rustc_nounwind]
#[rustc_intrinsic_const_stable_indirect]
pub const unsafe fn simd_relaxed_fma<T>(x: T, y: T, z: T) -> T;
Copy link
Member

Choose a reason for hiding this comment

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

This one is tricky since it is non-deterministic. Also, not even the scalar version is const-stable yet.

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 am ok with not doing it now, we don't use it in stdarch anyway

#[rustc_intrinsic]
#[rustc_nounwind]
#[rustc_intrinsic_const_stable_indirect]
pub const unsafe fn simd_reduce_max<T, U>(x: T) -> U;
Copy link
Member

@RalfJung RalfJung Dec 5, 2025

Choose a reason for hiding this comment

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

We should check the intended and actual semantics of this carefully, given all the recent discussion around the semantics of min and max (see #149537 and also LLVM discussions). In particular, IEEE-754 maxNum is not what we do for $float::max -- do we really want a different semantics here, and do we really have a different semantics here?

Copy link
Member

@RalfJung RalfJung Dec 5, 2025

Choose a reason for hiding this comment

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

In fact what we currently implement in the interpreter is NOT IEEE-754 maxNum. It is the same as $float::max, which is a mix of IEEE 754-2008 maxNum and IEEE 754-2019 maximumNumber. I don't know if that's what the users of this operation want, and I don't know what the codegen backends are doing.

Copy link
Member

Choose a reason for hiding this comment

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

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 see, LLVM is also very weird in this scenario. It ways llvm.vector.reduce.fmax behaves like an ordered reduction, with the operation being llvm.maxnum -- but this doesn't align exactly with IEEE maxNum. But in x86 stdarch, we only use it for integers (we explicitly avoid using any of the reduce intrinsics in x86 stdarch because the semantics and ordering of the operations don't match exactly with x86)

Copy link
Member

Choose a reason for hiding this comment

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

I think ideally we'd just not mark it as indirectly stable at all.

Otherwise we'll have to devise some clever ad-hoc plan for how to allow it only for integers.

#[rustc_intrinsic]
#[rustc_nounwind]
#[rustc_intrinsic_const_stable_indirect]
pub const unsafe fn simd_reduce_min<T, U>(x: T) -> U;
Copy link
Member

Choose a reason for hiding this comment

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

This has the same concern as max.

@joboet
Copy link
Member

joboet commented Dec 5, 2025

r? @RalfJung
I'm really not sure who normally handles these PRs, feel free to reassign as necessary.

@rustbot rustbot assigned RalfJung and unassigned joboet Dec 5, 2025
@traviscross traviscross added T-lang Relevant to the language team needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. labels Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I-lang-radar Items that are on lang's radar and will need eventual work or consideration. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-lang Relevant to the language team 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.

5 participants