You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
std::simd is in the awkward situation of being an attempt to have reasonable codegen for target-independent code, yet wanting to exploit highly target-specific and even compiler-invocation-specific codegen details that our precompiled std is a fairly poor fit for.
We have three problems that cannot be addressed by std's existing dynamic feature detection code or cfg!(target_feature = "..."):
Target features are abstractions. LLVM cannot relate them to the complicated code used to inspect the architectural registers which encode correlating bits, so it cannot see a feature is statically available and remove dynamic feature detection code.
#[cfg] and cfg! resolve their predicates at the time of AST expansion, so when we precompile std, we have the answer to those questions and cannot delay the answer to "after inlining".
Even the lightest dynamic feature detection code is enormously costly in performance, defeating the purpose of using it inside std::simd.
While we can pursue other extensions of LLVM's capabilities, a decent amount of std::simd's needs can be implemented in library code with one extension to Rust's list of directly-known intrinsics: target_feature_available_at_call_site. This has been implemented in rust-lang/rust#158713.
This intrinsic asks the question in its name and then returns a bool, allowing introducing a branch on whether this feature is known to be available in a "static" (known-at-compile-time) fashion. It relies on some integration with the codegen backend so that it can correctly answer the question after inlining. We plan to upstream the custom LLVM pass its experimental form depends on as soon as feasible. Dead code removal takes care of the rest, allowing the optimized implementation to remain despite being part of std.
It is acceptable for this intrinsic to be implemented as "always return false", as it is a quality-of-implementation detail that is the responsibility of the codegen backend. For soundness, the answer of true must be correct, as it will gate the use of intrinsics based on that target feature.
The current plan is to only use this internally and to pursue an RFC or other appropriate process when this has more stable exposure. For now, we ask if this is a reasonable addition to the compiler and explicitly invite opsem to be part of this decision: cc @rust-lang/opsem
Mentors or Reviewers
@nikic and everyone accursed to be involved in codegen
someone on T-opsem, probably
@workingjubilee can probably glance at it and nod sagaciously about parts that aren't directly in backends
Proposal
std::simdis in the awkward situation of being an attempt to have reasonable codegen for target-independent code, yet wanting to exploit highly target-specific and even compiler-invocation-specific codegen details that our precompiledstdis a fairly poor fit for.We have three problems that cannot be addressed by
std's existing dynamic feature detection code orcfg!(target_feature = "..."):#[cfg]andcfg!resolve their predicates at the time of AST expansion, so when we precompile std, we have the answer to those questions and cannot delay the answer to "after inlining".std::simd.While we can pursue other extensions of LLVM's capabilities, a decent amount of
std::simd's needs can be implemented in library code with one extension to Rust's list of directly-known intrinsics:target_feature_available_at_call_site. This has been implemented in rust-lang/rust#158713.This intrinsic asks the question in its name and then returns a
bool, allowing introducing a branch on whether this feature is known to be available in a "static" (known-at-compile-time) fashion. It relies on some integration with the codegen backend so that it can correctly answer the question after inlining. We plan to upstream the custom LLVM pass its experimental form depends on as soon as feasible. Dead code removal takes care of the rest, allowing the optimized implementation to remain despite being part ofstd.It is acceptable for this intrinsic to be implemented as "always return
false", as it is a quality-of-implementation detail that is the responsibility of the codegen backend. For soundness, the answer oftruemust be correct, as it will gate the use of intrinsics based on that target feature.The current plan is to only use this internally and to pursue an RFC or other appropriate process when this has more stable exposure. For now, we ask if this is a reasonable addition to the compiler and explicitly invite opsem to be part of this decision: cc @rust-lang/opsem
Mentors or Reviewers
Process
The main points of the Major Change Process are as follows:
@rustbot secondor kickoff a team FCP with@rfcbot fcp $RESOLUTION.You can read more about Major Change Proposals on forge.
Caution
Concerns (1 active)
Managed by
@rustbot—see help for details.