Skip to content

Commit 14eb0da

Browse files
committed
avoid the core_intrinsics feature (for a transition)
1 parent 2a331a2 commit 14eb0da

File tree

5 files changed

+55
-5
lines changed

5 files changed

+55
-5
lines changed

src/int/specialized_div_rem/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn zero_div_fn() -> ! {
7575
// Calling the intrinsic directly, to avoid the `assert_unsafe_precondition` that cannot be used
7676
// here because it involves non-`inline` functions
7777
// (https://github.com/rust-lang/compiler-builtins/issues/491).
78-
unsafe { core::intrinsics::unreachable() }
78+
unsafe { crate::intrinsics::unreachable() }
7979
}
8080

8181
const USE_LZ: bool = {

src/lib.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#![feature(cfg_target_has_atomic)]
66
#![feature(compiler_builtins)]
77
#![feature(core_ffi_c)]
8-
#![feature(core_intrinsics)]
8+
#![feature(intrinsics)]
9+
#![feature(rustc_attrs)]
910
#![feature(inline_const)]
1011
#![feature(lang_items)]
1112
#![feature(linkage)]
@@ -80,3 +81,50 @@ pub mod x86;
8081
pub mod x86_64;
8182

8283
pub mod probestack;
84+
85+
// `core` is changing the feature name for the `intrinsics` module.
86+
// To permit that transition, we avoid using that feature for now.
87+
mod intrinsics {
88+
extern "rust-intrinsic" {
89+
#[rustc_nounwind]
90+
pub fn atomic_load_unordered<T: Copy>(src: *const T) -> T;
91+
92+
#[rustc_nounwind]
93+
pub fn atomic_store_unordered<T: Copy>(dst: *mut T, val: T);
94+
95+
/// Informs the optimizer that this point in the code is not reachable,
96+
/// enabling further optimizations.
97+
///
98+
/// N.B., this is very different from the `unreachable!()` macro: Unlike the
99+
/// macro, which panics when it is executed, it is *undefined behavior* to
100+
/// reach code marked with this function.
101+
///
102+
/// The stabilized version of this intrinsic is [`core::hint::unreachable_unchecked`].
103+
#[rustc_nounwind]
104+
pub fn unreachable() -> !;
105+
106+
/// Performs an exact division, resulting in undefined behavior where
107+
/// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
108+
///
109+
/// This intrinsic does not have a stable counterpart.
110+
#[rustc_nounwind]
111+
pub fn exact_div<T: Copy>(x: T, y: T) -> T;
112+
113+
/// Performs an unchecked division, resulting in undefined behavior
114+
/// where `y == 0` or `x == T::MIN && y == -1`
115+
///
116+
/// Safe wrappers for this intrinsic are available on the integer
117+
/// primitives via the `checked_div` method. For example,
118+
/// [`u32::checked_div`]
119+
#[rustc_nounwind]
120+
pub fn unchecked_div<T: Copy>(x: T, y: T) -> T;
121+
/// Returns the remainder of an unchecked division, resulting in
122+
/// undefined behavior when `y == 0` or `x == T::MIN && y == -1`
123+
///
124+
/// Safe wrappers for this intrinsic are available on the integer
125+
/// primitives via the `checked_rem` method. For example,
126+
/// [`u32::checked_rem`]
127+
#[rustc_nounwind]
128+
pub fn unchecked_rem<T: Copy>(x: T, y: T) -> T;
129+
}
130+
}

src/mem/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ type c_int = i16;
88
#[cfg(not(target_pointer_width = "16"))]
99
type c_int = i32;
1010

11-
use core::intrinsics::{atomic_load_unordered, atomic_store_unordered, exact_div};
1211
use core::mem;
1312
use core::ops::{BitOr, Shl};
1413

14+
use crate::intrinsics::{atomic_load_unordered, atomic_store_unordered, exact_div};
15+
1516
// memcpy/memmove/memset have optimized implementations on some architectures
1617
#[cfg_attr(
1718
all(not(feature = "no-asm"), target_arch = "x86_64"),

src/mem/x86_64.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
// Note that ERMSB does not enhance the backwards (DF=1) "rep movsb".
1818

1919
use core::arch::asm;
20-
use core::intrinsics;
2120
use core::mem;
2221

22+
use crate::intrinsics;
23+
2324
#[inline(always)]
2425
#[cfg(target_feature = "ermsb")]
2526
pub unsafe fn copy_forward(dest: *mut u8, src: *const u8, count: usize) {

src/x86_64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(unused_imports)]
22

3-
use core::intrinsics;
3+
use crate::intrinsics;
44

55
// NOTE These functions are implemented using assembly because they using a custom
66
// calling convention which can't be implemented using a normal Rust function

0 commit comments

Comments
 (0)