Skip to content

Commit 0a6b3f6

Browse files
committed
make prefetch intrinsics safe
1 parent 6dde419 commit 0a6b3f6

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

core/src/intrinsics/mod.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -265,71 +265,67 @@ pub unsafe fn atomic_singlethreadfence<const ORD: AtomicOrdering>();
265265
/// Prefetches have no effect on the behavior of the program but can change its performance
266266
/// characteristics.
267267
///
268-
/// The `locality` argument must be a constant integer and is a temporal locality specifier
269-
/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
268+
/// The `LOCALITY` argument is a temporal locality specifier ranging from (0) - no locality,
269+
/// to (3) - extremely local keep in cache.
270270
///
271271
/// This intrinsic does not have a stable counterpart.
272272
#[rustc_intrinsic]
273273
#[rustc_nounwind]
274274
#[miri::intrinsic_fallback_is_spec]
275-
pub unsafe fn prefetch_read_data<T>(data: *const T, locality: i32) {
275+
pub const fn prefetch_read_data<T, const LOCALITY: i32>(data: *const T) {
276276
// This operation is a no-op, unless it is overridden by the backend.
277277
let _ = data;
278-
let _ = locality;
279278
}
280279

281280
/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
282281
/// for the given address if supported; otherwise, it is a no-op.
283282
/// Prefetches have no effect on the behavior of the program but can change its performance
284283
/// characteristics.
285284
///
286-
/// The `locality` argument must be a constant integer and is a temporal locality specifier
287-
/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
285+
/// The `LOCALITY` argument is a temporal locality specifier ranging from (0) - no locality,
286+
/// to (3) - extremely local keep in cache.
288287
///
289288
/// This intrinsic does not have a stable counterpart.
290289
#[rustc_intrinsic]
291290
#[rustc_nounwind]
292291
#[miri::intrinsic_fallback_is_spec]
293-
pub unsafe fn prefetch_write_data<T>(data: *const T, locality: i32) {
292+
pub const fn prefetch_write_data<T, const LOCALITY: i32>(data: *const T) {
294293
// This operation is a no-op, unless it is overridden by the backend.
295294
let _ = data;
296-
let _ = locality;
297295
}
298296

299297
/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
300298
/// for the given address if supported; otherwise, it is a no-op.
301299
/// Prefetches have no effect on the behavior of the program but can change its performance
302300
/// characteristics.
303301
///
304-
/// The `locality` argument must be a constant integer and is a temporal locality specifier
305-
/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
302+
/// The `LOCALITY` argument is a temporal locality specifier ranging from (0) - no locality,
303+
/// to (3) - extremely local keep in cache.
306304
///
307305
/// This intrinsic does not have a stable counterpart.
308306
#[rustc_intrinsic]
309307
#[rustc_nounwind]
310308
#[miri::intrinsic_fallback_is_spec]
311-
pub unsafe fn prefetch_read_instruction<T>(data: *const T, locality: i32) {
309+
pub const fn prefetch_read_instruction<T, const LOCALITY: i32>(data: *const T) {
312310
// This operation is a no-op, unless it is overridden by the backend.
313311
let _ = data;
314-
let _ = locality;
315312
}
316313

317314
/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
318315
/// for the given address if supported; otherwise, it is a no-op.
319316
/// Prefetches have no effect on the behavior of the program but can change its performance
320317
/// characteristics.
321318
///
322-
/// The `locality` argument must be a constant integer and is a temporal locality specifier
323-
/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
319+
/// The `LOCALITY` argument is a temporal locality specifier ranging from (0) - no locality,
320+
/// to (3) - extremely local keep in cache.
324321
///
325322
/// This intrinsic does not have a stable counterpart.
326323
#[rustc_intrinsic]
327324
#[rustc_nounwind]
328325
#[miri::intrinsic_fallback_is_spec]
329-
pub unsafe fn prefetch_write_instruction<T>(data: *const T, locality: i32) {
326+
pub const fn prefetch_write_instruction<T, const LOCALITY: i32>(data: *const T) {
330327
// This operation is a no-op, unless it is overridden by the backend.
331328
let _ = data;
332-
let _ = locality;
333329
}
334330

335331
/// Executes a breakpoint trap, for inspection by a debugger.

0 commit comments

Comments
 (0)