summaryrefslogtreecommitdiffstats
path: root/library/core/src/intrinsics.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /library/core/src/intrinsics.rs
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/core/src/intrinsics.rs')
-rw-r--r--library/core/src/intrinsics.rs56
1 files changed, 38 insertions, 18 deletions
diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs
index 5a9a7013a..676d4f2f3 100644
--- a/library/core/src/intrinsics.rs
+++ b/library/core/src/intrinsics.rs
@@ -9,7 +9,7 @@
//! This includes changes in the stability of the constness.
//!
//! In order to make an intrinsic usable at compile-time, one needs to copy the implementation
-//! from <https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics.rs> to
+//! from <https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics> to
//! <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs> and add a
//! `#[rustc_const_unstable(feature = "const_such_and_such", issue = "01234")]` to the intrinsic declaration.
//!
@@ -1057,23 +1057,6 @@ extern "rust-intrinsic" {
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
#[rustc_safe_intrinsic]
#[rustc_nounwind]
- #[cfg(bootstrap)]
- pub fn type_id<T: ?Sized + 'static>() -> u64;
-
- /// Gets an identifier which is globally unique to the specified type. This
- /// function will return the same value for a type regardless of whichever
- /// crate it is invoked in.
- ///
- /// Note that, unlike most intrinsics, this is safe to call;
- /// it does not require an `unsafe` block.
- /// Therefore, implementations must not require the user to uphold
- /// any safety invariants.
- ///
- /// The stabilized version of this intrinsic is [`core::any::TypeId::of`].
- #[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
- #[rustc_safe_intrinsic]
- #[rustc_nounwind]
- #[cfg(not(bootstrap))]
pub fn type_id<T: ?Sized + 'static>() -> u128;
/// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
@@ -2402,6 +2385,25 @@ extern "rust-intrinsic" {
#[rustc_nounwind]
pub fn raw_eq<T>(a: &T, b: &T) -> bool;
+ /// Lexicographically compare `[left, left + bytes)` and `[right, right + bytes)`
+ /// as unsigned bytes, returning negative if `left` is less, zero if all the
+ /// bytes match, or positive if `right` is greater.
+ ///
+ /// This underlies things like `<[u8]>::cmp`, and will usually lower to `memcmp`.
+ ///
+ /// # Safety
+ ///
+ /// `left` and `right` must each be [valid] for reads of `bytes` bytes.
+ ///
+ /// Note that this applies to the whole range, not just until the first byte
+ /// that differs. That allows optimizations that can read in large chunks.
+ ///
+ /// [valid]: crate::ptr#safety
+ #[cfg(not(bootstrap))]
+ #[rustc_const_unstable(feature = "const_intrinsic_compare_bytes", issue = "none")]
+ #[rustc_nounwind]
+ pub fn compare_bytes(left: *const u8, right: *const u8, bytes: usize) -> i32;
+
/// See documentation of [`std::hint::black_box`] for details.
///
/// [`std::hint::black_box`]: crate::hint::black_box
@@ -2541,12 +2543,14 @@ pub(crate) use assert_unsafe_precondition;
/// Checks whether `ptr` is properly aligned with respect to
/// `align_of::<T>()`.
+#[inline]
pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
!ptr.is_null() && ptr.is_aligned()
}
/// Checks whether an allocation of `len` instances of `T` exceeds
/// the maximum allowed allocation size.
+#[inline]
pub(crate) fn is_valid_allocation_size<T>(len: usize) -> bool {
let max_len = const {
let size = crate::mem::size_of::<T>();
@@ -2557,6 +2561,7 @@ pub(crate) fn is_valid_allocation_size<T>(len: usize) -> bool {
/// Checks whether the regions of memory starting at `src` and `dst` of size
/// `count * size_of::<T>()` do *not* overlap.
+#[inline]
pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
let src_usize = src.addr();
let dst_usize = dst.addr();
@@ -2839,3 +2844,18 @@ pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
write_bytes(dst, val, count)
}
}
+
+/// Backfill for bootstrap
+#[cfg(bootstrap)]
+pub unsafe fn compare_bytes(left: *const u8, right: *const u8, bytes: usize) -> i32 {
+ extern "C" {
+ fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> crate::ffi::c_int;
+ }
+
+ if bytes != 0 {
+ // SAFETY: Since bytes is non-zero, the caller has met `memcmp`'s requirements.
+ unsafe { memcmp(left, right, bytes).into() }
+ } else {
+ 0
+ }
+}