Skip to content

Commit cf13767

Browse files
authored
Rollup merge of #145626 - folkertdev:prefetch-fallback, r=Amanieu
add a fallback implementation for the `prefetch_*` intrinsics related ACP: rust-lang/libs-team#638 The fallback is to just ignore the arguments. That is a valid implementation because this intrinsic is just a hint. I also added the `miri::intrinsic_fallback_is_spec` annotation, so that miri now supports these operations. A prefetch intrinsic call is valid on any pointer. (specifically LLVM guarantees this https://llvm.org/docs/LangRef.html#llvm-prefetch-intrinsic) Next, I made the `LOCALITY` argument a const generic. That argument must be const (otherwise LLVM crashes), but that was not reflected in the type. Finally, with these changes, the intrinsic can be safe and `const` (a prefetch at const evaluation time is just a no-op). cc `@Amanieu` r? `@RalfJung`
2 parents 67b4d91 + 544eb34 commit cf13767

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/pass/prefetch.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![feature(core_intrinsics)]
2+
3+
// Test that these intrinsics work. Their behavior should be a no-op.
4+
5+
fn main() {
6+
static X: [u8; 8] = [0; 8];
7+
8+
::std::intrinsics::prefetch_read_data::<_, 1>(::std::ptr::null::<u8>());
9+
::std::intrinsics::prefetch_read_data::<_, 2>(::std::ptr::dangling::<u8>());
10+
::std::intrinsics::prefetch_read_data::<_, 3>(X.as_ptr());
11+
12+
::std::intrinsics::prefetch_write_data::<_, 1>(::std::ptr::null::<u8>());
13+
::std::intrinsics::prefetch_write_data::<_, 2>(::std::ptr::dangling::<u8>());
14+
::std::intrinsics::prefetch_write_data::<_, 3>(X.as_ptr());
15+
16+
::std::intrinsics::prefetch_read_instruction::<_, 1>(::std::ptr::null::<u8>());
17+
::std::intrinsics::prefetch_read_instruction::<_, 2>(::std::ptr::dangling::<u8>());
18+
::std::intrinsics::prefetch_read_instruction::<_, 3>(X.as_ptr());
19+
20+
::std::intrinsics::prefetch_write_instruction::<_, 1>(::std::ptr::null::<u8>());
21+
::std::intrinsics::prefetch_write_instruction::<_, 2>(::std::ptr::dangling::<u8>());
22+
::std::intrinsics::prefetch_write_instruction::<_, 3>(X.as_ptr());
23+
}

0 commit comments

Comments
 (0)