Skip to content

Commit 2f1d999

Browse files
committed
c-b: Replace core::intrinsics::{cold_path, likely}
Replace the use of intrinsics with `core::hint::cold_path` which has been unstably available for a while, and is on track to become stable in the next release.
1 parent 94f9cda commit 2f1d999

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

compiler-builtins/src/mem/impls.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
// crate doing wrapping pointer arithmetic with a method that must not wrap won't be the problem if
1717
// something does go wrong at runtime.
1818
use core::ffi::c_int;
19-
use core::intrinsics::likely;
19+
20+
use crate::support::cold_path;
2021

2122
const WORD_SIZE: usize = core::mem::size_of::<usize>();
2223
const WORD_MASK: usize = WORD_SIZE - 1;
@@ -209,9 +210,10 @@ pub unsafe fn copy_forward(mut dest: *mut u8, mut src: *const u8, mut n: usize)
209210

210211
let n_words = n & !WORD_MASK;
211212
let src_misalignment = src as usize & WORD_MASK;
212-
if likely(src_misalignment == 0) {
213+
if src_misalignment == 0 {
213214
copy_forward_aligned_words(dest, src, n_words);
214215
} else {
216+
cold_path();
215217
copy_forward_misaligned_words(dest, src, n_words);
216218
}
217219
dest = dest.wrapping_add(n_words);
@@ -327,9 +329,10 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, mut n: usize) {
327329

328330
let n_words = n & !WORD_MASK;
329331
let src_misalignment = src as usize & WORD_MASK;
330-
if likely(src_misalignment == 0) {
332+
if src_misalignment == 0 {
331333
copy_backward_aligned_words(dest, src, n_words);
332334
} else {
335+
cold_path();
333336
copy_backward_misaligned_words(dest, src, n_words);
334337
}
335338
dest = dest.wrapping_sub(n_words);
@@ -368,7 +371,7 @@ pub unsafe fn set_bytes(mut s: *mut u8, c: u8, mut n: usize) {
368371
}
369372
}
370373

371-
if likely(n >= WORD_COPY_THRESHOLD) {
374+
if n >= WORD_COPY_THRESHOLD {
372375
// Align s
373376
// Because of n >= 2 * WORD_SIZE, dst_misalignment < n
374377
let misalignment = (s as usize).wrapping_neg() & WORD_MASK;
@@ -380,6 +383,8 @@ pub unsafe fn set_bytes(mut s: *mut u8, c: u8, mut n: usize) {
380383
set_bytes_words(s, c, n_words);
381384
s = s.wrapping_add(n_words);
382385
n -= n_words;
386+
} else {
387+
cold_path();
383388
}
384389
set_bytes_bytes(s, c, n);
385390
}

libm/src/math/support/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ pub use modular::linear_mul_reduction;
3535
/// Hint to the compiler that the current path is cold.
3636
pub fn cold_path() {
3737
#[cfg(intrinsics_enabled)]
38-
core::intrinsics::cold_path();
38+
core::hint::cold_path();
3939
}

0 commit comments

Comments
 (0)