-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add const-eval support for SIMD types, insert, and extract #64738
Conversation
@oli-obk this does the bare minimum for getting |
This is pretty cool. I think it would be best if the experimentation happened in the |
I tried that but I'm really confused for when some intrinsics should be implemented in the const-evaluator vs in the miri repository. |
Also notice that these intrinsics are all unstable anyways so they can't be used from stable Rust. |
Sometimes miri changes need smaller miri-engine changes. In this case the removal of the ABI check
anything experimental should go into miri, anything that will never get stabilized should go into miri. Anything that has an RFC and generally a sound plan for stabilization should go into the const evaluator. We can trivially move things from miri to the const evaluator when we need to in the future.
I'm not worried about that. I just think it would allow you to iterate much faster if you did this in miri, and you could test it much more easily since you can run miri on regular crates instead of having to cook up artificial examples |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
So I think I've made all changes. Tests pass on my side. |
Add const-eval support for SIMD types, insert, and extract This adds initial support for constant-evaluation of Abi::Vector types. r? @oli-obk
Rollup of 6 pull requests Successful merges: - #62975 (Almost fully deprecate hir::map::Map.hir_to_node_id) - #64386 (use `sign` variable in abs and wrapping_abs methods) - #64508 (or-patterns: Push `PatKind/PatternKind::Or` at top level to HIR & HAIR) - #64738 (Add const-eval support for SIMD types, insert, and extract) - #64759 (Refactor mbe a tiny bit) - #64764 (Master is now 1.40 ) Failed merges: r? @ghost
&self, op: OpTy<'tcx, M::PointerTag> | ||
) -> (u64, &rustc::ty::TyS<'tcx>) { | ||
if let layout::Abi::Vector { .. } = op.layout.abi { | ||
(op.layout.ty.simd_size(*self.tcx) as _, op.layout.ty.simd_type(*self.tcx)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why this is not using the element count from Abi::Vector
?
These two methods are removed in the SIMD array support PR. I have to
change them there anyways, and that PR added a method that does this IIRC.
|
@@ -239,7 +239,52 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |||
"transmute" => { | |||
self.copy_op_transmute(args[0], dest)?; | |||
} | |||
"simd_insert" => { | |||
let index = self.read_scalar(args[1])?.to_u32()? as u64; | |||
let scalar = args[2]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite confusing to call something of type OpTy
a "scalar". Those should have type Scalar
, or this should be called somewhere else, or there should at least be a comment.
@@ -335,6 +335,17 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |||
} | |||
} | |||
|
|||
/// Read vector length and element type | |||
pub fn read_vector_ty( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't even look at the actual "operand", right? It is just a layout function?
Then it (a) should be mixed up with all the other read_*
methods as it is very different, and (b) shouldn't even be called "read" as it doesn't read from memory.
I am not sure what the best place is for such a method, but it is not operand.rs
. Sounds more like a TyLayout
method to me?
if caller_abi != Abi::RustIntrinsic { | ||
throw_unsup!(FunctionAbiMismatch(caller_abi, Abi::RustIntrinsic)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, why this? Instead of throwing out this check entirely, you could have just added platform intrinsics to the whitelist.
Was this reverted recently anywhere? Seems to consider them non-const in the latest nightly 0a58f58 |
We now need rustc_const_unstable on the intrinsics. Not sure if stdsimd added that, but it should. Maybe rustc should alsohave regression tests |
Is that something I can add to these intrinsics now? extern "platform-intrinsic" {
crate fn simd_insert<T, U>(x: T, idx: u32, val: U) -> T;
crate fn simd_extract<T, U>(x: T, idx: u32) -> U;
} |
Yes, there are instructions in the rustc guide |
The two paragraphs for |
The last paragraph in https://rust-lang.github.io/rustc-guide/stability.html?highlight=rustc_const#rustc_const_unstable mentions this. Adding the attribute will make the intrinsic const |
Can you update the guide so it explains it in a way that would have been clearer? |
I'm not a rustc dev, this is within an application. I should have opened an issue but I figured it was a simple mistake or an intentional revert so I asked here first. It seems I will need to open an issue now. |
Huh? You should not need to use intrinsics outside stdsimd. Can't you use the intrinsics from libcore instead of declaring them yourself? |
Did this work on stable or nightly without feature gates? If so, we seem to have exposed a stability hole, and that definitely deserves an issue |
I don't believe these are exposed anywhere in libcore, none of the "platform-intrinsics" are. Specifically, I have a fork of |
Some things are in |
If you just want your code to work again in a hacky way, you can see in https://github.com/rust-lang/rust/blob/9ae6cedb8d1e37469be1434642a3e403fce50a03/src/test/ui/consts/const-eval/simd/insert_extract.rs how this is done and what feature gates are needed. I don't know much about intrinsics, @gnzlbg is there any plan for exposing enough API surface so |
It does seem as though adding: #![feature(staged_api)] // and many more, but this was the additional feature
#![stable(feature = "const_simd_intrinsics_raygon", since = "1.33.7")]
extern "platform-intrinsic" {
#[rustc_const_stable(
feature = "const_simd_intrinsics_raygon",
since = "1.3.37"
)]
crate fn simd_extract<T, U>(x: T, idx: u32) -> U;
} works for making it |
The plan is to move |
OK. @novacrazy I'm sorry, for now we can't support your use case without you needing to add all the stability flags |
@novacrazy I’ll try to update packed simd with the new flags so that you can rebase your fork, but feel free to submit a PR doing that since I won’t have time till Monday or so. |
You don't have to make it a priority. I was able to revert most of my |
This adds initial support for constant-evaluation of Abi::Vector types.
r? @oli-obk