2019-02-09 21:23:30 +00:00
|
|
|
|
//! Compiler intrinsics.
|
2014-11-25 21:17:11 -05:00
|
|
|
|
//!
|
2019-02-09 21:23:30 +00:00
|
|
|
|
//! The corresponding definitions are in `librustc_codegen_llvm/intrinsic.rs`.
|
2019-12-21 00:07:36 +01:00
|
|
|
|
//! The corresponding const implementations are in `librustc_mir/interpret/intrinsics.rs`
|
|
|
|
|
//!
|
|
|
|
|
//! # Const intrinsics
|
|
|
|
|
//!
|
|
|
|
|
//! Note: any changes to the constness of intrinsics should be discussed with the language team.
|
|
|
|
|
//! 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
|
|
|
|
|
//! `librustc_mir/interpret/intrinsics.rs` and add a
|
2020-06-20 14:14:30 +02:00
|
|
|
|
//! `#[rustc_const_unstable(feature = "foo", issue = "01234")]` to the intrinsic.
|
2019-12-21 00:07:36 +01:00
|
|
|
|
//!
|
|
|
|
|
//! If an intrinsic is supposed to be used from a `const fn` with a `rustc_const_stable` attribute,
|
|
|
|
|
//! the intrinsic's attribute must be `rustc_const_stable`, too. Such a change should not be done
|
2020-07-07 20:48:15 -04:00
|
|
|
|
//! without T-lang consultation, because it bakes a feature into the language that cannot be
|
2019-12-21 00:07:36 +01:00
|
|
|
|
//! replicated in user code without compiler support.
|
2014-11-25 21:17:11 -05:00
|
|
|
|
//!
|
|
|
|
|
//! # Volatiles
|
|
|
|
|
//!
|
|
|
|
|
//! The volatile intrinsics provide operations intended to act on I/O
|
|
|
|
|
//! memory, which are guaranteed to not be reordered by the compiler
|
|
|
|
|
//! across other volatile intrinsics. See the LLVM documentation on
|
|
|
|
|
//! [[volatile]].
|
|
|
|
|
//!
|
|
|
|
|
//! [volatile]: http://llvm.org/docs/LangRef.html#volatile-memory-accesses
|
|
|
|
|
//!
|
|
|
|
|
//! # Atomics
|
|
|
|
|
//!
|
|
|
|
|
//! The atomic intrinsics provide common atomic operations on machine
|
|
|
|
|
//! words, with multiple possible memory orderings. They obey the same
|
|
|
|
|
//! semantics as C++11. See the LLVM documentation on [[atomics]].
|
|
|
|
|
//!
|
|
|
|
|
//! [atomics]: http://llvm.org/docs/Atomics.html
|
|
|
|
|
//!
|
|
|
|
|
//! A quick refresher on memory ordering:
|
|
|
|
|
//!
|
|
|
|
|
//! * Acquire - a barrier for acquiring a lock. Subsequent reads and writes
|
|
|
|
|
//! take place after the barrier.
|
|
|
|
|
//! * Release - a barrier for releasing a lock. Preceding reads and writes
|
|
|
|
|
//! take place before the barrier.
|
|
|
|
|
//! * Sequentially consistent - sequentially consistent operations are
|
|
|
|
|
//! guaranteed to happen in order. This is the standard mode for working
|
|
|
|
|
//! with atomic types and is equivalent to Java's `volatile`.
|
2013-05-24 18:05:27 -04:00
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
|
#![unstable(
|
|
|
|
|
feature = "core_intrinsics",
|
|
|
|
|
reason = "intrinsics are unlikely to ever be stabilized, instead \
|
2015-06-09 11:18:03 -07:00
|
|
|
|
they should be used through stabilized interfaces \
|
2015-08-12 17:23:48 -07:00
|
|
|
|
in the rest of the standard library",
|
2019-12-22 17:42:04 -05:00
|
|
|
|
issue = "none"
|
|
|
|
|
)]
|
2014-10-27 15:37:07 -07:00
|
|
|
|
#![allow(missing_docs)]
|
2014-02-15 23:49:08 -08:00
|
|
|
|
|
2020-04-05 19:30:03 +02:00
|
|
|
|
use crate::marker::DiscriminantKind;
|
2019-02-27 17:10:59 +01:00
|
|
|
|
use crate::mem;
|
|
|
|
|
|
2017-03-14 01:08:21 +02:00
|
|
|
|
#[stable(feature = "drop_in_place", since = "1.8.0")]
|
2019-12-22 17:42:04 -05:00
|
|
|
|
#[rustc_deprecated(
|
|
|
|
|
reason = "no longer an intrinsic - use `ptr::drop_in_place` directly",
|
|
|
|
|
since = "1.18.0"
|
|
|
|
|
)]
|
2019-04-15 11:23:21 +09:00
|
|
|
|
pub use crate::ptr::drop_in_place;
|
2014-02-17 01:37:26 -08:00
|
|
|
|
|
2017-03-14 01:08:21 +02:00
|
|
|
|
extern "rust-intrinsic" {
|
2018-11-27 02:59:49 +00:00
|
|
|
|
// N.B., these intrinsics take raw pointers because they mutate aliased
|
2014-02-24 18:20:52 -08:00
|
|
|
|
// memory, which is not valid for either `&` or `&mut`.
|
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as both the `success` and `failure` parameters. For example,
|
2017-04-04 15:39:44 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange`][compare_exchange].
|
|
|
|
|
///
|
|
|
|
|
/// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchg<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as both the `success` and `failure` parameters. For example,
|
2017-04-04 15:39:44 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange`][compare_exchange].
|
|
|
|
|
///
|
|
|
|
|
/// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchg_acq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange` method by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `success` and
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `failure` parameters. For example,
|
2017-04-04 15:39:44 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange`][compare_exchange].
|
|
|
|
|
///
|
|
|
|
|
/// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchg_rel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `success` and
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `failure` parameters. For example,
|
2017-04-04 15:39:44 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange`][compare_exchange].
|
|
|
|
|
///
|
|
|
|
|
/// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchg_acqrel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as both the `success` and `failure` parameters. For example,
|
2017-04-04 15:39:44 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange`][compare_exchange].
|
|
|
|
|
///
|
|
|
|
|
/// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchg_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `success` and
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `failure` parameters. For example,
|
2017-04-04 15:39:44 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange`][compare_exchange].
|
|
|
|
|
///
|
|
|
|
|
/// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchg_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `success` and
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `failure` parameters. For example,
|
2017-04-04 15:39:44 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange`][compare_exchange].
|
|
|
|
|
///
|
|
|
|
|
/// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchg_failacq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `success` and
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `failure` parameters. For example,
|
2017-04-04 15:39:44 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange`][compare_exchange].
|
|
|
|
|
///
|
|
|
|
|
/// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchg_acq_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `success` and
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `failure` parameters. For example,
|
2017-04-04 15:39:44 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange`][compare_exchange].
|
|
|
|
|
///
|
|
|
|
|
/// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchg_acqrel_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-01-16 23:40:11 +00:00
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as both the `success` and `failure` parameters. For example,
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange_weak`][cew].
|
2017-04-04 15:39:44 -04:00
|
|
|
|
///
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchgweak<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as both the `success` and `failure` parameters. For example,
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange_weak`][cew].
|
2017-04-04 15:39:44 -04:00
|
|
|
|
///
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchgweak_acq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `success` and
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `failure` parameters. For example,
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange_weak`][cew].
|
2017-04-04 15:39:44 -04:00
|
|
|
|
///
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchgweak_rel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `success` and
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `failure` parameters. For example,
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange_weak`][cew].
|
2017-04-04 15:39:44 -04:00
|
|
|
|
///
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchgweak_acqrel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as both the `success` and `failure` parameters. For example,
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange_weak`][cew].
|
2017-04-04 15:39:44 -04:00
|
|
|
|
///
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchgweak_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `success` and
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `failure` parameters. For example,
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange_weak`][cew].
|
2017-04-04 15:39:44 -04:00
|
|
|
|
///
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchgweak_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `success` and
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `failure` parameters. For example,
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange_weak`][cew].
|
2017-04-04 15:39:44 -04:00
|
|
|
|
///
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchgweak_failacq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `success` and
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `failure` parameters. For example,
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange_weak`][cew].
|
2017-04-04 15:39:44 -04:00
|
|
|
|
///
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchgweak_acq_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores a value if the current value is the same as the `old` value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `success` and
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `failure` parameters. For example,
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [`AtomicBool::compare_exchange_weak`][cew].
|
2017-04-04 15:39:44 -04:00
|
|
|
|
///
|
2017-04-05 11:58:53 -04:00
|
|
|
|
/// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_cxchgweak_acqrel_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
|
2014-02-24 18:20:52 -08:00
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Loads the current value of the pointer.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `load` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_load<T: Copy>(src: *const T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Loads the current value of the pointer.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `load` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_load_acq<T: Copy>(src: *const T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Loads the current value of the pointer.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `load` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_load_relaxed<T: Copy>(src: *const T) -> T;
|
|
|
|
|
pub fn atomic_load_unordered<T: Copy>(src: *const T) -> T;
|
2014-02-24 18:20:52 -08:00
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores the value at the specified memory location.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `store` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_store<T: Copy>(dst: *mut T, val: T);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores the value at the specified memory location.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `store` method by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_store_rel<T: Copy>(dst: *mut T, val: T);
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores the value at the specified memory location.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `store` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_store_relaxed<T: Copy>(dst: *mut T, val: T);
|
|
|
|
|
pub fn atomic_store_unordered<T: Copy>(dst: *mut T, val: T);
|
2014-02-24 18:20:52 -08:00
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores the value at the specified memory location, returning the old value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `swap` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xchg<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores the value at the specified memory location, returning the old value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `swap` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xchg_acq<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores the value at the specified memory location, returning the old value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `swap` method by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xchg_rel<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores the value at the specified memory location, returning the old value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `swap` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xchg_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Stores the value at the specified memory location, returning the old value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `swap` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xchg_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
|
2014-02-24 18:20:52 -08:00
|
|
|
|
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// Adds to the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_add` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xadd<T: Copy>(dst: *mut T, src: T) -> T;
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// Adds to the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_add` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xadd_acq<T: Copy>(dst: *mut T, src: T) -> T;
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// Adds to the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_add` method by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xadd_rel<T: Copy>(dst: *mut T, src: T) -> T;
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// Adds to the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_add` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xadd_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// Adds to the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_add` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xadd_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
|
2014-02-24 18:20:52 -08:00
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Subtract from the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_sub` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xsub<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Subtract from the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_sub` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xsub_acq<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Subtract from the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_sub` method by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xsub_rel<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Subtract from the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_sub` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xsub_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Subtract from the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_sub` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xsub_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
|
2014-02-24 18:20:52 -08:00
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise and with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_and` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_and<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise and with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_and` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_and_acq<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise and with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_and` method by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_and_rel<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise and with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_and` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_and_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise and with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_and` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_and_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
|
2014-02-24 18:20:52 -08:00
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise nand with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_nand<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise nand with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_nand_acq<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise nand with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_nand_rel<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise nand with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_nand_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise nand with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_nand_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
|
2014-02-24 18:20:52 -08:00
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise or with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_or` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_or<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise or with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_or` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_or_acq<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise or with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_or` method by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_or_rel<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise or with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_or` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_or_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise or with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_or` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_or_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
|
2014-02-24 18:20:52 -08:00
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise xor with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_xor` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xor<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise xor with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_xor` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xor_acq<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise xor with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_xor` method by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xor_rel<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise xor with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_xor` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xor_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// Bitwise xor with the current value, returning the previous value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:26:57 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` types via the `fetch_xor` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_xor_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
|
2014-02-24 18:20:52 -08:00
|
|
|
|
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Maximum with the current value using a signed comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_max<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Maximum with the current value using a signed comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_max_acq<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Maximum with the current value using a signed comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_max_rel<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Maximum with the current value using a signed comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_max_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// Maximum with the current value.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_max_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
|
2014-02-24 18:20:52 -08:00
|
|
|
|
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Minimum with the current value using a signed comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_min<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Minimum with the current value using a signed comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_min_acq<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Minimum with the current value using a signed comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_min_rel<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Minimum with the current value using a signed comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_min_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Minimum with the current value using a signed comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_min_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
|
2014-02-24 18:20:52 -08:00
|
|
|
|
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Minimum with the current value using an unsigned comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_umin<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Minimum with the current value using an unsigned comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_umin_acq<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Minimum with the current value using an unsigned comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_umin_rel<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Minimum with the current value using an unsigned comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_umin_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Minimum with the current value using an unsigned comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_umin_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
|
2014-02-24 18:20:52 -08:00
|
|
|
|
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Maximum with the current value using an unsigned comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_umax<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Maximum with the current value using an unsigned comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_umax_acq<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Maximum with the current value using an unsigned comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_umax_rel<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Maximum with the current value using an unsigned comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_umax_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
|
2020-01-31 21:49:00 +01:00
|
|
|
|
/// Maximum with the current value using an unsigned comparison.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available on the
|
|
|
|
|
/// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
|
|
|
|
|
/// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
|
|
|
|
|
/// as the `order`. For example,
|
|
|
|
|
/// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn atomic_umax_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
|
2017-04-21 09:00:34 +02:00
|
|
|
|
|
|
|
|
|
/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// if supported; otherwise, it is a no-op.
|
2017-04-21 09:00:34 +02:00
|
|
|
|
/// Prefetches have no effect on the behavior of the program but can change its performance
|
|
|
|
|
/// characteristics.
|
|
|
|
|
///
|
|
|
|
|
/// The `locality` argument must be a constant integer and is a temporal locality specifier
|
2020-04-29 15:49:48 +02:00
|
|
|
|
/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
|
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2017-04-21 09:00:34 +02:00
|
|
|
|
pub fn prefetch_read_data<T>(data: *const T, locality: i32);
|
|
|
|
|
/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// if supported; otherwise, it is a no-op.
|
2017-04-21 09:00:34 +02:00
|
|
|
|
/// Prefetches have no effect on the behavior of the program but can change its performance
|
|
|
|
|
/// characteristics.
|
|
|
|
|
///
|
|
|
|
|
/// The `locality` argument must be a constant integer and is a temporal locality specifier
|
2020-04-29 15:49:48 +02:00
|
|
|
|
/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
|
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2017-04-21 09:00:34 +02:00
|
|
|
|
pub fn prefetch_write_data<T>(data: *const T, locality: i32);
|
|
|
|
|
/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// if supported; otherwise, it is a no-op.
|
2017-04-21 09:00:34 +02:00
|
|
|
|
/// Prefetches have no effect on the behavior of the program but can change its performance
|
|
|
|
|
/// characteristics.
|
|
|
|
|
///
|
|
|
|
|
/// The `locality` argument must be a constant integer and is a temporal locality specifier
|
2020-04-29 15:49:48 +02:00
|
|
|
|
/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
|
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2017-04-21 09:00:34 +02:00
|
|
|
|
pub fn prefetch_read_instruction<T>(data: *const T, locality: i32);
|
|
|
|
|
/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// if supported; otherwise, it is a no-op.
|
2017-04-21 09:00:34 +02:00
|
|
|
|
/// Prefetches have no effect on the behavior of the program but can change its performance
|
|
|
|
|
/// characteristics.
|
|
|
|
|
///
|
|
|
|
|
/// The `locality` argument must be a constant integer and is a temporal locality specifier
|
2020-04-29 15:49:48 +02:00
|
|
|
|
/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
|
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2017-04-21 09:00:34 +02:00
|
|
|
|
pub fn prefetch_write_instruction<T>(data: *const T, locality: i32);
|
2014-02-17 01:37:26 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "rust-intrinsic" {
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// An atomic fence.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available in
|
|
|
|
|
/// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
|
|
|
|
|
/// by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
|
|
|
|
|
/// as the `order`.
|
2014-01-15 15:32:44 -08:00
|
|
|
|
pub fn atomic_fence();
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// An atomic fence.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available in
|
|
|
|
|
/// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
|
|
|
|
|
/// by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
|
|
|
|
|
/// as the `order`.
|
2014-01-15 15:32:44 -08:00
|
|
|
|
pub fn atomic_fence_acq();
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// An atomic fence.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available in
|
|
|
|
|
/// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
|
|
|
|
|
/// by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
|
|
|
|
|
/// as the `order`.
|
2014-01-15 15:32:44 -08:00
|
|
|
|
pub fn atomic_fence_rel();
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// An atomic fence.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is available in
|
|
|
|
|
/// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
|
|
|
|
|
/// by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
|
|
|
|
|
/// as the `order`.
|
2014-01-15 15:32:44 -08:00
|
|
|
|
pub fn atomic_fence_acqrel();
|
|
|
|
|
|
2015-02-14 23:48:10 -07:00
|
|
|
|
/// A compiler-only memory barrier.
|
|
|
|
|
///
|
2015-06-09 11:18:03 -07:00
|
|
|
|
/// Memory accesses will never be reordered across this barrier by the
|
|
|
|
|
/// compiler, but no instructions will be emitted for it. This is
|
|
|
|
|
/// appropriate for operations on the same thread that may be preempted,
|
|
|
|
|
/// such as when interacting with signal handlers.
|
2020-01-31 22:03:59 +01:00
|
|
|
|
///
|
|
|
|
|
/// The stabilized version of this intrinsic is available in
|
|
|
|
|
/// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
|
|
|
|
|
/// by passing
|
|
|
|
|
/// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
|
|
|
|
|
/// as the `order`.
|
2015-02-14 23:48:10 -07:00
|
|
|
|
pub fn atomic_singlethreadfence();
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// A compiler-only memory barrier.
|
|
|
|
|
///
|
|
|
|
|
/// Memory accesses will never be reordered across this barrier by the
|
|
|
|
|
/// compiler, but no instructions will be emitted for it. This is
|
|
|
|
|
/// appropriate for operations on the same thread that may be preempted,
|
|
|
|
|
/// such as when interacting with signal handlers.
|
2020-01-31 22:03:59 +01:00
|
|
|
|
///
|
|
|
|
|
/// The stabilized version of this intrinsic is available in
|
|
|
|
|
/// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
|
|
|
|
|
/// by passing
|
|
|
|
|
/// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
|
|
|
|
|
/// as the `order`.
|
2015-02-14 23:48:10 -07:00
|
|
|
|
pub fn atomic_singlethreadfence_acq();
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// A compiler-only memory barrier.
|
|
|
|
|
///
|
|
|
|
|
/// Memory accesses will never be reordered across this barrier by the
|
|
|
|
|
/// compiler, but no instructions will be emitted for it. This is
|
|
|
|
|
/// appropriate for operations on the same thread that may be preempted,
|
|
|
|
|
/// such as when interacting with signal handlers.
|
2020-01-31 22:03:59 +01:00
|
|
|
|
///
|
|
|
|
|
/// The stabilized version of this intrinsic is available in
|
|
|
|
|
/// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
|
|
|
|
|
/// by passing
|
|
|
|
|
/// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
|
|
|
|
|
/// as the `order`.
|
2015-02-14 23:48:10 -07:00
|
|
|
|
pub fn atomic_singlethreadfence_rel();
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// A compiler-only memory barrier.
|
|
|
|
|
///
|
|
|
|
|
/// Memory accesses will never be reordered across this barrier by the
|
|
|
|
|
/// compiler, but no instructions will be emitted for it. This is
|
|
|
|
|
/// appropriate for operations on the same thread that may be preempted,
|
|
|
|
|
/// such as when interacting with signal handlers.
|
2020-01-31 22:03:59 +01:00
|
|
|
|
///
|
|
|
|
|
/// The stabilized version of this intrinsic is available in
|
|
|
|
|
/// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
|
|
|
|
|
/// by passing
|
|
|
|
|
/// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
|
|
|
|
|
/// as the `order`.
|
2015-02-14 23:48:10 -07:00
|
|
|
|
pub fn atomic_singlethreadfence_acqrel();
|
|
|
|
|
|
2016-05-11 21:54:12 +02:00
|
|
|
|
/// Magic intrinsic that derives its meaning from attributes
|
|
|
|
|
/// attached to the function.
|
|
|
|
|
///
|
|
|
|
|
/// For example, dataflow uses this to inject static assertions so
|
2016-05-16 17:10:44 +02:00
|
|
|
|
/// that `rustc_peek(potentially_uninitialized)` would actually
|
2016-05-11 21:54:12 +02:00
|
|
|
|
/// double-check that dataflow did indeed compute that it is
|
|
|
|
|
/// uninitialized at that point in the control flow.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic should not be used outside of the compiler.
|
2016-05-11 21:54:12 +02:00
|
|
|
|
pub fn rustc_peek<T>(_: T) -> T;
|
|
|
|
|
|
2015-04-13 10:21:32 -04:00
|
|
|
|
/// Aborts the execution of the process.
|
2017-10-29 22:53:07 -04:00
|
|
|
|
///
|
2020-05-17 11:06:59 +02:00
|
|
|
|
/// A more user-friendly and stable version of this operation is
|
2020-04-29 15:49:48 +02:00
|
|
|
|
/// [`std::process::abort`](../../std/process/fn.abort.html).
|
2014-01-15 15:32:44 -08:00
|
|
|
|
pub fn abort() -> !;
|
|
|
|
|
|
2017-08-09 00:47:38 +02:00
|
|
|
|
/// Tells LLVM that this point in the code is not reachable, enabling
|
|
|
|
|
/// further optimizations.
|
2014-09-03 12:00:08 -07:00
|
|
|
|
///
|
2018-11-27 02:59:49 +00:00
|
|
|
|
/// N.B., this is very different from the `unreachable!()` macro: Unlike the
|
2017-08-09 00:47:38 +02:00
|
|
|
|
/// macro, which panics when it is executed, it is *undefined behavior* to
|
|
|
|
|
/// reach code marked with this function.
|
2018-04-12 21:47:38 +08:00
|
|
|
|
///
|
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html).
|
2020-07-17 21:57:13 +02:00
|
|
|
|
#[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")]
|
2014-09-03 12:00:08 -07:00
|
|
|
|
pub fn unreachable() -> !;
|
|
|
|
|
|
2015-04-13 10:21:32 -04:00
|
|
|
|
/// Informs the optimizer that a condition is always true.
|
2014-10-16 01:44:44 +02:00
|
|
|
|
/// If the condition is false, the behavior is undefined.
|
|
|
|
|
///
|
2014-10-16 14:20:54 +02:00
|
|
|
|
/// No code is generated for this intrinsic, but the optimizer will try
|
|
|
|
|
/// to preserve it (and its condition) between passes, which may interfere
|
|
|
|
|
/// with optimization of surrounding code and reduce performance. It should
|
|
|
|
|
/// not be used if the invariant can be discovered by the optimizer on its
|
|
|
|
|
/// own, or if it does not enable any significant optimizations.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2014-10-16 01:44:44 +02:00
|
|
|
|
pub fn assume(b: bool);
|
|
|
|
|
|
2016-08-31 16:02:55 -07:00
|
|
|
|
/// Hints to the compiler that branch condition is likely to be true.
|
|
|
|
|
/// Returns the value passed to it.
|
|
|
|
|
///
|
|
|
|
|
/// Any use other than with `if` statements will probably not have an effect.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2020-06-26 13:19:50 +01:00
|
|
|
|
#[rustc_const_unstable(feature = "const_likely", issue = "none")]
|
2016-08-31 16:02:55 -07:00
|
|
|
|
pub fn likely(b: bool) -> bool;
|
|
|
|
|
|
|
|
|
|
/// Hints to the compiler that branch condition is likely to be false.
|
|
|
|
|
/// Returns the value passed to it.
|
|
|
|
|
///
|
|
|
|
|
/// Any use other than with `if` statements will probably not have an effect.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2020-06-26 13:19:50 +01:00
|
|
|
|
#[rustc_const_unstable(feature = "const_likely", issue = "none")]
|
2016-08-31 16:02:55 -07:00
|
|
|
|
pub fn unlikely(b: bool) -> bool;
|
|
|
|
|
|
2015-04-13 10:21:32 -04:00
|
|
|
|
/// Executes a breakpoint trap, for inspection by a debugger.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2014-01-15 15:32:44 -08:00
|
|
|
|
pub fn breakpoint();
|
|
|
|
|
|
2013-05-16 00:04:24 -07:00
|
|
|
|
/// The size of a type in bytes.
|
|
|
|
|
///
|
2016-05-01 23:30:12 -07:00
|
|
|
|
/// More specifically, this is the offset in bytes between successive
|
|
|
|
|
/// items of the same type, including alignment padding.
|
2018-10-30 16:13:42 +01:00
|
|
|
|
///
|
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::mem::size_of`](../../std/mem/fn.size_of.html).
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
|
2015-02-18 14:43:43 +01:00
|
|
|
|
pub fn size_of<T>() -> usize;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2015-06-05 14:17:49 +02:00
|
|
|
|
/// Moves a value to an uninitialized memory location.
|
|
|
|
|
///
|
|
|
|
|
/// Drop glue is not run on the destination.
|
2020-01-30 21:37:34 +01:00
|
|
|
|
///
|
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::ptr::write`](../../std/ptr/fn.write.html).
|
2015-06-05 14:17:49 +02:00
|
|
|
|
pub fn move_val_init<T>(dst: *mut T, src: T);
|
|
|
|
|
|
2020-01-30 21:37:34 +01:00
|
|
|
|
/// The minimum alignment of a type.
|
|
|
|
|
///
|
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::mem::align_of`](../../std/mem/fn.align_of.html).
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
|
2015-02-18 14:43:43 +01:00
|
|
|
|
pub fn min_align_of<T>() -> usize;
|
2020-07-07 20:48:15 -04:00
|
|
|
|
/// The preferred alignment of a type.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2019-12-25 11:54:55 +01:00
|
|
|
|
#[rustc_const_unstable(feature = "const_pref_align_of", issue = "none")]
|
2015-02-18 14:43:43 +01:00
|
|
|
|
pub fn pref_align_of<T>() -> usize;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2017-10-22 11:53:29 -04:00
|
|
|
|
/// The size of the referenced value in bytes.
|
|
|
|
|
///
|
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::mem::size_of_val`](../../std/mem/fn.size_of_val.html).
|
2020-07-29 14:56:58 -07:00
|
|
|
|
#[rustc_const_unstable(feature = "const_size_of_val", issue = "46571")]
|
2020-02-11 14:10:49 -05:00
|
|
|
|
pub fn size_of_val<T: ?Sized>(_: *const T) -> usize;
|
2020-04-29 15:49:48 +02:00
|
|
|
|
/// The required alignment of the referenced value.
|
|
|
|
|
///
|
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::mem::align_of_val`](../../std/mem/fn.align_of_val.html).
|
2020-07-29 14:56:58 -07:00
|
|
|
|
#[rustc_const_unstable(feature = "const_align_of_val", issue = "46571")]
|
2020-02-11 14:10:49 -05:00
|
|
|
|
pub fn min_align_of_val<T: ?Sized>(_: *const T) -> usize;
|
|
|
|
|
|
2015-03-15 04:01:57 +02:00
|
|
|
|
/// Gets a static string slice containing the name of a type.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 14:34:29 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::any::type_name`](../../std/any/fn.type_name.html)
|
2020-06-18 10:06:57 +02:00
|
|
|
|
#[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
|
2015-03-15 04:01:57 +02:00
|
|
|
|
pub fn type_name<T: ?Sized>() -> &'static str;
|
|
|
|
|
|
2013-10-30 16:32:33 -07:00
|
|
|
|
/// 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.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 14:34:29 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::any::TypeId::of`](../../std/any/struct.TypeId.html#method.of)
|
2020-06-30 10:21:22 +10:00
|
|
|
|
#[rustc_const_stable(feature = "const_type_id", since = "1.46.0")]
|
2015-01-14 16:08:07 -08:00
|
|
|
|
pub fn type_id<T: ?Sized + 'static>() -> u64;
|
|
|
|
|
|
2018-12-27 09:40:33 +01:00
|
|
|
|
/// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
|
|
|
|
|
/// This will statically either panic, or do nothing.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2020-03-12 19:38:09 +01:00
|
|
|
|
pub fn assert_inhabited<T>();
|
|
|
|
|
|
2019-11-03 17:21:37 +01:00
|
|
|
|
/// A guard for unsafe functions that cannot ever be executed if `T` does not permit
|
|
|
|
|
/// zero-initialization: This will statically either panic, or do nothing.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2020-03-12 19:38:09 +01:00
|
|
|
|
pub fn assert_zero_valid<T>();
|
2019-11-03 17:21:37 +01:00
|
|
|
|
|
|
|
|
|
/// A guard for unsafe functions that cannot ever be executed if `T` has invalid
|
|
|
|
|
/// bit patterns: This will statically either panic, or do nothing.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2020-03-12 19:38:09 +01:00
|
|
|
|
pub fn assert_uninit_valid<T>();
|
2019-11-03 17:21:37 +01:00
|
|
|
|
|
2019-10-09 08:25:41 -07:00
|
|
|
|
/// Gets a reference to a static `Location` indicating where it was called.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// Consider using [`std::panic::Location::caller`](../../std/panic/struct.Location.html#method.caller)
|
|
|
|
|
/// instead.
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_unstable(feature = "const_caller_location", issue = "47809")]
|
2019-10-09 08:25:41 -07:00
|
|
|
|
pub fn caller_location() -> &'static crate::panic::Location<'static>;
|
|
|
|
|
|
2018-11-08 15:28:06 +01:00
|
|
|
|
/// Moves a value out of scope without running drop glue.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This exists solely for [`mem::forget_unsized`](../../std/mem/fn.forget_unsized.html);
|
|
|
|
|
/// normal `forget` uses `ManuallyDrop` instead.
|
2018-11-08 17:58:12 +01:00
|
|
|
|
pub fn forget<T: ?Sized>(_: T);
|
2018-11-08 15:28:06 +01:00
|
|
|
|
|
2016-09-08 20:04:05 -07:00
|
|
|
|
/// Reinterprets the bits of a value of one type as another type.
|
|
|
|
|
///
|
|
|
|
|
/// Both types must have the same size. Neither the original, nor the result,
|
2018-05-25 11:47:48 -07:00
|
|
|
|
/// may be an [invalid value](../../nomicon/what-unsafe-does.html).
|
2014-06-12 14:08:44 -07:00
|
|
|
|
///
|
2016-07-05 16:04:58 -07:00
|
|
|
|
/// `transmute` is semantically equivalent to a bitwise move of one type
|
2016-09-08 20:04:05 -07:00
|
|
|
|
/// into another. It copies the bits from the source value into the
|
|
|
|
|
/// destination value, then forgets the original. It's equivalent to C's
|
|
|
|
|
/// `memcpy` under the hood, just like `transmute_copy`.
|
2016-07-01 23:33:44 -07:00
|
|
|
|
///
|
2016-09-08 20:04:05 -07:00
|
|
|
|
/// `transmute` is **incredibly** unsafe. There are a vast number of ways to
|
|
|
|
|
/// cause [undefined behavior][ub] with this function. `transmute` should be
|
2016-07-01 23:33:44 -07:00
|
|
|
|
/// the absolute last resort.
|
|
|
|
|
///
|
2016-07-05 16:04:58 -07:00
|
|
|
|
/// The [nomicon](../../nomicon/transmutes.html) has additional
|
|
|
|
|
/// documentation.
|
2014-06-12 14:08:44 -07:00
|
|
|
|
///
|
2017-02-21 01:15:29 -05:00
|
|
|
|
/// [ub]: ../../reference/behavior-considered-undefined.html
|
2016-09-08 20:04:05 -07:00
|
|
|
|
///
|
2014-12-08 20:12:35 -05:00
|
|
|
|
/// # Examples
|
2014-06-12 14:08:44 -07:00
|
|
|
|
///
|
2016-07-10 06:13:34 +02:00
|
|
|
|
/// There are a few things that `transmute` is really useful for.
|
|
|
|
|
///
|
2016-09-08 20:04:05 -07:00
|
|
|
|
/// Turning a pointer into a function pointer. This is *not* portable to
|
|
|
|
|
/// machines where function pointers and data pointers have different sizes.
|
2016-07-10 06:13:34 +02:00
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// fn foo() -> i32 {
|
|
|
|
|
/// 0
|
|
|
|
|
/// }
|
|
|
|
|
/// let pointer = foo as *const ();
|
|
|
|
|
/// let function = unsafe {
|
|
|
|
|
/// std::mem::transmute::<*const (), fn() -> i32>(pointer)
|
|
|
|
|
/// };
|
|
|
|
|
/// assert_eq!(function(), 0);
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
2016-09-08 20:04:05 -07:00
|
|
|
|
/// Extending a lifetime, or shortening an invariant lifetime. This is
|
|
|
|
|
/// advanced, very unsafe Rust!
|
2016-07-10 06:13:34 +02:00
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// struct R<'a>(&'a i32);
|
|
|
|
|
/// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
|
|
|
|
|
/// std::mem::transmute::<R<'b>, R<'static>>(r)
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
|
|
|
|
|
/// -> &'b mut R<'c> {
|
|
|
|
|
/// std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
2016-07-01 23:57:10 -07:00
|
|
|
|
/// # Alternatives
|
|
|
|
|
///
|
2016-09-08 20:04:05 -07:00
|
|
|
|
/// Don't despair: many uses of `transmute` can be achieved through other means.
|
|
|
|
|
/// Below are common applications of `transmute` which can be replaced with safer
|
|
|
|
|
/// constructs.
|
2014-06-12 14:08:44 -07:00
|
|
|
|
///
|
2020-04-18 14:58:38 +08:00
|
|
|
|
/// Turning raw bytes(`&[u8]`) to `u32`, `f64`, etc.:
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// let raw_bytes = [0x78, 0x56, 0x34, 0x12];
|
|
|
|
|
///
|
|
|
|
|
/// let num = unsafe {
|
|
|
|
|
/// std::mem::transmute::<[u8; 4], u32>(raw_bytes);
|
|
|
|
|
/// };
|
|
|
|
|
///
|
|
|
|
|
/// // use `u32::from_ne_bytes` instead
|
|
|
|
|
/// let num = u32::from_ne_bytes(raw_bytes);
|
2020-07-16 11:04:01 +02:00
|
|
|
|
/// // or use `u32::from_le_bytes` or `u32::from_be_bytes` to specify the endianness
|
2020-04-18 14:58:38 +08:00
|
|
|
|
/// let num = u32::from_le_bytes(raw_bytes);
|
|
|
|
|
/// assert_eq!(num, 0x12345678);
|
|
|
|
|
/// let num = u32::from_be_bytes(raw_bytes);
|
|
|
|
|
/// assert_eq!(num, 0x78563412);
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// Turning a pointer into a `usize`:
|
2016-07-05 15:15:33 -07:00
|
|
|
|
///
|
2015-02-09 21:51:30 -05:00
|
|
|
|
/// ```
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// let ptr = &0;
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// let ptr_num_transmute = unsafe {
|
|
|
|
|
/// std::mem::transmute::<&i32, usize>(ptr)
|
|
|
|
|
/// };
|
2016-09-08 20:04:05 -07:00
|
|
|
|
///
|
2016-07-05 15:15:33 -07:00
|
|
|
|
/// // Use an `as` cast instead
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// let ptr_num_cast = ptr as *const i32 as usize;
|
2015-02-09 21:51:30 -05:00
|
|
|
|
/// ```
|
2016-07-01 23:57:10 -07:00
|
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// Turning a `*mut T` into an `&mut T`:
|
2016-07-05 15:15:33 -07:00
|
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// ```
|
|
|
|
|
/// let ptr: *mut i32 = &mut 0;
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// let ref_transmuted = unsafe {
|
|
|
|
|
/// std::mem::transmute::<*mut i32, &mut i32>(ptr)
|
|
|
|
|
/// };
|
2016-09-08 20:04:05 -07:00
|
|
|
|
///
|
2016-07-05 15:15:33 -07:00
|
|
|
|
/// // Use a reborrow instead
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// let ref_casted = unsafe { &mut *ptr };
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// ```
|
2016-07-01 23:57:10 -07:00
|
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// Turning an `&mut T` into an `&mut U`:
|
2016-07-05 15:15:33 -07:00
|
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// ```
|
|
|
|
|
/// let ptr = &mut 0;
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// let val_transmuted = unsafe {
|
|
|
|
|
/// std::mem::transmute::<&mut i32, &mut u32>(ptr)
|
|
|
|
|
/// };
|
2016-09-08 20:04:05 -07:00
|
|
|
|
///
|
2016-07-10 23:17:02 +02:00
|
|
|
|
/// // Now, put together `as` and reborrowing - note the chaining of `as`
|
|
|
|
|
/// // `as` is not transitive
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) };
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// ```
|
2016-07-01 23:33:44 -07:00
|
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// Turning an `&str` into an `&[u8]`:
|
2014-06-12 14:08:44 -07:00
|
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// ```
|
|
|
|
|
/// // this is not a good way to do this.
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") };
|
2016-07-05 15:42:48 -07:00
|
|
|
|
/// assert_eq!(slice, &[82, 117, 115, 116]);
|
2016-09-08 20:04:05 -07:00
|
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// // You could use `str::as_bytes`
|
|
|
|
|
/// let slice = "Rust".as_bytes();
|
2016-07-05 15:42:48 -07:00
|
|
|
|
/// assert_eq!(slice, &[82, 117, 115, 116]);
|
2016-09-08 20:04:05 -07:00
|
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// // Or, just use a byte string, if you have control over the string
|
|
|
|
|
/// // literal
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// assert_eq!(b"Rust", &[82, 117, 115, 116]);
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// ```
|
2016-07-02 08:45:01 -07:00
|
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// Turning a `Vec<&T>` into a `Vec<Option<&T>>`:
|
2016-07-05 15:15:33 -07:00
|
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// ```
|
|
|
|
|
/// let store = [0, 1, 2, 3];
|
2019-09-13 18:42:09 +02:00
|
|
|
|
/// let v_orig = store.iter().collect::<Vec<&i32>>();
|
|
|
|
|
///
|
|
|
|
|
/// // clone the vector as we will reuse them later
|
|
|
|
|
/// let v_clone = v_orig.clone();
|
2016-09-08 20:04:05 -07:00
|
|
|
|
///
|
2020-02-29 14:03:25 +01:00
|
|
|
|
/// // Using transmute: this relies on the unspecified data layout of `Vec`, which is a
|
2020-02-29 16:20:17 +01:00
|
|
|
|
/// // bad idea and could cause Undefined Behavior.
|
2016-07-05 15:15:33 -07:00
|
|
|
|
/// // However, it is no-copy.
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// let v_transmuted = unsafe {
|
2019-09-13 18:42:09 +02:00
|
|
|
|
/// std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone)
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// };
|
2016-09-08 20:04:05 -07:00
|
|
|
|
///
|
2019-09-13 18:42:09 +02:00
|
|
|
|
/// let v_clone = v_orig.clone();
|
|
|
|
|
///
|
2016-07-05 15:15:33 -07:00
|
|
|
|
/// // This is the suggested, safe way.
|
2016-09-08 20:04:05 -07:00
|
|
|
|
/// // It does copy the entire vector, though, into a new array.
|
2019-09-13 18:42:09 +02:00
|
|
|
|
/// let v_collected = v_clone.into_iter()
|
|
|
|
|
/// .map(Some)
|
|
|
|
|
/// .collect::<Vec<Option<&i32>>>();
|
|
|
|
|
///
|
|
|
|
|
/// let v_clone = v_orig.clone();
|
2016-09-08 20:04:05 -07:00
|
|
|
|
///
|
2020-02-29 14:03:25 +01:00
|
|
|
|
/// // The no-copy, unsafe way, still using transmute, but not relying on the data layout.
|
|
|
|
|
/// // Like the first approach, this reuses the `Vec` internals.
|
|
|
|
|
/// // Therefore, the new inner type must have the
|
|
|
|
|
/// // exact same size, *and the same alignment*, as the old type.
|
2017-09-13 01:27:41 -07:00
|
|
|
|
/// // The same caveats exist for this method as transmute, for
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// // the original inner type (`&i32`) to the converted inner type
|
2020-02-29 14:03:25 +01:00
|
|
|
|
/// // (`Option<&i32>`), so read the nomicon pages linked above and also
|
|
|
|
|
/// // consult the [`from_raw_parts`] documentation.
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// let v_from_raw = unsafe {
|
2019-10-22 12:48:52 -04:00
|
|
|
|
// FIXME Update this when vec_into_raw_parts is stabilized
|
2019-09-13 18:42:09 +02:00
|
|
|
|
/// // Ensure the original vector is not dropped.
|
|
|
|
|
/// let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
|
|
|
|
|
/// Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
|
|
|
|
|
/// v_clone.len(),
|
|
|
|
|
/// v_clone.capacity())
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// };
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// ```
|
2016-07-02 08:45:01 -07:00
|
|
|
|
///
|
2020-02-29 14:03:25 +01:00
|
|
|
|
/// [`from_raw_parts`]: ../../std/vec/struct.Vec.html#method.from_raw_parts
|
|
|
|
|
///
|
2016-07-05 15:15:33 -07:00
|
|
|
|
/// Implementing `split_at_mut`:
|
|
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// ```
|
|
|
|
|
/// use std::{slice, mem};
|
2016-09-08 20:04:05 -07:00
|
|
|
|
///
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// // There are multiple ways to do this, and there are multiple problems
|
|
|
|
|
/// // with the following (transmute) way.
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize)
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// -> (&mut [T], &mut [T]) {
|
|
|
|
|
/// let len = slice.len();
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// assert!(mid <= len);
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// unsafe {
|
2016-07-02 22:55:30 -07:00
|
|
|
|
/// let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
|
2020-07-07 20:48:15 -04:00
|
|
|
|
/// // first: transmute is not type safe; all it checks is that T and
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// // U are of the same size. Second, right here, you have two
|
2016-07-05 15:15:33 -07:00
|
|
|
|
/// // mutable references pointing to the same memory.
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// (&mut slice[0..mid], &mut slice2[mid..len])
|
2016-07-02 22:55:30 -07:00
|
|
|
|
/// }
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// }
|
2016-09-08 20:04:05 -07:00
|
|
|
|
///
|
2020-07-07 20:48:15 -04:00
|
|
|
|
/// // This gets rid of the type safety problems; `&mut *` will *only* give
|
2016-07-05 15:15:33 -07:00
|
|
|
|
/// // you an `&mut T` from an `&mut T` or `*mut T`.
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// -> (&mut [T], &mut [T]) {
|
|
|
|
|
/// let len = slice.len();
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// assert!(mid <= len);
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// unsafe {
|
|
|
|
|
/// let slice2 = &mut *(slice as *mut [T]);
|
|
|
|
|
/// // however, you still have two mutable references pointing to
|
2016-07-05 15:15:33 -07:00
|
|
|
|
/// // the same memory.
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// (&mut slice[0..mid], &mut slice2[mid..len])
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// }
|
|
|
|
|
/// }
|
2016-09-08 20:04:05 -07:00
|
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// // This is how the standard library does it. This is the best method, if
|
|
|
|
|
/// // you need to do something like this
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// fn split_at_stdlib<T>(slice: &mut [T], mid: usize)
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// -> (&mut [T], &mut [T]) {
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// let len = slice.len();
|
|
|
|
|
/// assert!(mid <= len);
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// unsafe {
|
2016-07-05 23:54:34 -07:00
|
|
|
|
/// let ptr = slice.as_mut_ptr();
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// // This now has three mutable references pointing at the same
|
|
|
|
|
/// // memory. `slice`, the rvalue ret.0, and the rvalue ret.1.
|
2016-07-05 15:15:33 -07:00
|
|
|
|
/// // `slice` is never used after `let ptr = ...`, and so one can
|
|
|
|
|
/// // treat it as "dead", and therefore, you only have two real
|
|
|
|
|
/// // mutable slices.
|
2016-07-05 10:40:59 -07:00
|
|
|
|
/// (slice::from_raw_parts_mut(ptr, mid),
|
2018-08-19 22:16:22 -04:00
|
|
|
|
/// slice::from_raw_parts_mut(ptr.add(mid), len - mid))
|
2016-07-02 22:55:30 -07:00
|
|
|
|
/// }
|
2016-07-01 23:33:44 -07:00
|
|
|
|
/// }
|
2014-06-12 14:08:44 -07:00
|
|
|
|
/// ```
|
2015-01-23 21:48:20 -08:00
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2019-08-30 02:01:04 +02:00
|
|
|
|
// NOTE: While this makes the intrinsic const stable, we have some custom code in const fn
|
|
|
|
|
// checks that prevent its use within `const fn`.
|
|
|
|
|
#[rustc_const_stable(feature = "const_transmute", since = "1.46.0")]
|
2015-08-19 19:45:31 +02:00
|
|
|
|
pub fn transmute<T, U>(e: T) -> U;
|
2013-02-20 17:57:15 +01:00
|
|
|
|
|
2015-02-26 14:35:08 +01:00
|
|
|
|
/// Returns `true` if the actual type given as `T` requires drop
|
|
|
|
|
/// glue; returns `false` if the actual type provided for `T`
|
|
|
|
|
/// implements `Copy`.
|
|
|
|
|
///
|
|
|
|
|
/// If the actual type neither requires drop glue nor implements
|
2020-06-22 14:42:26 +02:00
|
|
|
|
/// `Copy`, then the return value of this function is unspecified.
|
2017-10-22 20:15:56 -04:00
|
|
|
|
///
|
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::mem::needs_drop`](../../std/mem/fn.needs_drop.html).
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_needs_drop", since = "1.40.0")]
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn needs_drop<T>() -> bool;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2015-04-19 20:17:47 +03:00
|
|
|
|
/// Calculates the offset from a pointer.
|
2013-08-06 17:44:40 -04:00
|
|
|
|
///
|
2013-08-08 22:22:52 -07:00
|
|
|
|
/// This is implemented as an intrinsic to avoid converting to and from an
|
|
|
|
|
/// integer, since the conversion would throw away aliasing information.
|
2015-04-19 20:17:47 +03:00
|
|
|
|
///
|
|
|
|
|
/// # Safety
|
|
|
|
|
///
|
|
|
|
|
/// Both the starting and resulting pointer must be either in bounds or one
|
|
|
|
|
/// byte past the end of an allocated object. If either pointer is out of
|
|
|
|
|
/// bounds or arithmetic overflow occurs then any further use of the
|
|
|
|
|
/// returned value will result in undefined behavior.
|
2020-01-30 21:37:34 +01:00
|
|
|
|
///
|
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::pointer::offset`](../../std/primitive.pointer.html#method.offset).
|
2020-05-12 11:41:41 -05:00
|
|
|
|
#[must_use = "returns a new pointer rather than modifying its argument"]
|
2020-04-24 00:19:11 -07:00
|
|
|
|
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
|
2015-02-18 14:43:43 +01:00
|
|
|
|
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
|
2013-08-06 17:44:40 -04:00
|
|
|
|
|
2015-05-15 15:20:42 +02:00
|
|
|
|
/// Calculates the offset from a pointer, potentially wrapping.
|
|
|
|
|
///
|
|
|
|
|
/// This is implemented as an intrinsic to avoid converting to and from an
|
|
|
|
|
/// integer, since the conversion inhibits certain optimizations.
|
|
|
|
|
///
|
|
|
|
|
/// # Safety
|
|
|
|
|
///
|
|
|
|
|
/// Unlike the `offset` intrinsic, this intrinsic does not restrict the
|
|
|
|
|
/// resulting pointer to point into or one byte past the end of an allocated
|
|
|
|
|
/// object, and it wraps with two's complement arithmetic. The resulting
|
|
|
|
|
/// value is not necessarily valid to be used to actually access memory.
|
2020-01-30 21:37:34 +01:00
|
|
|
|
///
|
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::pointer::wrapping_offset`](../../std/primitive.pointer.html#method.wrapping_offset).
|
2020-05-12 11:41:41 -05:00
|
|
|
|
#[must_use = "returns a new pointer rather than modifying its argument"]
|
2020-04-24 00:19:11 -07:00
|
|
|
|
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
|
2015-05-15 15:20:42 +02:00
|
|
|
|
pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
|
|
|
|
|
|
2014-04-22 19:51:14 -04:00
|
|
|
|
/// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
|
|
|
|
|
/// a size of `count` * `size_of::<T>()` and an alignment of
|
|
|
|
|
/// `min_align_of::<T>()`
|
|
|
|
|
///
|
2017-08-12 18:43:59 +10:00
|
|
|
|
/// The volatile parameter is set to `true`, so it will not be optimized out
|
|
|
|
|
/// unless size is equal to zero.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2019-12-22 17:42:04 -05:00
|
|
|
|
pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
|
2014-04-22 19:51:14 -04:00
|
|
|
|
/// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
|
|
|
|
|
/// a size of `count` * `size_of::<T>()` and an alignment of
|
|
|
|
|
/// `min_align_of::<T>()`
|
|
|
|
|
///
|
2017-08-12 18:43:59 +10:00
|
|
|
|
/// The volatile parameter is set to `true`, so it will not be optimized out
|
2018-08-29 14:34:59 +02:00
|
|
|
|
/// unless size is equal to zero.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2015-02-18 14:43:43 +01:00
|
|
|
|
pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
|
2014-04-22 19:51:14 -04:00
|
|
|
|
/// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
|
|
|
|
|
/// size of `count` * `size_of::<T>()` and an alignment of
|
|
|
|
|
/// `min_align_of::<T>()`.
|
|
|
|
|
///
|
2017-08-12 18:43:59 +10:00
|
|
|
|
/// The volatile parameter is set to `true`, so it will not be optimized out
|
|
|
|
|
/// unless size is equal to zero.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2015-02-18 14:43:43 +01:00
|
|
|
|
pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
|
2014-04-22 19:51:14 -04:00
|
|
|
|
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// Performs a volatile load from the `src` pointer.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:30:56 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::ptr::read_volatile`](../../std/ptr/fn.read_volatile.html).
|
2014-06-25 12:47:34 -07:00
|
|
|
|
pub fn volatile_load<T>(src: *const T) -> T;
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// Performs a volatile store to the `dst` pointer.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-05 19:30:56 -04:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::ptr::write_volatile`](../../std/ptr/fn.write_volatile.html).
|
2014-04-22 19:51:14 -04:00
|
|
|
|
pub fn volatile_store<T>(dst: *mut T, val: T);
|
|
|
|
|
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// Performs a volatile load from the `src` pointer
|
2018-07-14 23:28:39 +01:00
|
|
|
|
/// The pointer is not required to be aligned.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2018-07-14 23:28:39 +01:00
|
|
|
|
pub fn unaligned_volatile_load<T>(src: *const T) -> T;
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// Performs a volatile store to the `dst` pointer.
|
2018-07-14 23:28:39 +01:00
|
|
|
|
/// The pointer is not required to be aligned.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2018-07-14 23:28:39 +01:00
|
|
|
|
pub fn unaligned_volatile_store<T>(dst: *mut T, val: T);
|
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the square root of an `f32`
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::sqrt`](../../std/primitive.f32.html#method.sqrt)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn sqrtf32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the square root of an `f64`
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::sqrt`](../../std/primitive.f64.html#method.sqrt)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn sqrtf64(x: f64) -> f64;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Raises an `f32` to an integer power.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::powi`](../../std/primitive.f32.html#method.powi)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn powif32(a: f32, x: i32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Raises an `f64` to an integer power.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::powi`](../../std/primitive.f64.html#method.powi)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn powif64(a: f64, x: i32) -> f64;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the sine of an `f32`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::sin`](../../std/primitive.f32.html#method.sin)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn sinf32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the sine of an `f64`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::sin`](../../std/primitive.f64.html#method.sin)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn sinf64(x: f64) -> f64;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the cosine of an `f32`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::cos`](../../std/primitive.f32.html#method.cos)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn cosf32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the cosine of an `f64`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::cos`](../../std/primitive.f64.html#method.cos)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn cosf64(x: f64) -> f64;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Raises an `f32` to an `f32` power.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::powf`](../../std/primitive.f32.html#method.powf)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn powf32(a: f32, x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Raises an `f64` to an `f64` power.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::powf`](../../std/primitive.f64.html#method.powf)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn powf64(a: f64, x: f64) -> f64;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the exponential of an `f32`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::exp`](../../std/primitive.f32.html#method.exp)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn expf32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the exponential of an `f64`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::exp`](../../std/primitive.f64.html#method.exp)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn expf64(x: f64) -> f64;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns 2 raised to the power of an `f32`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::exp2`](../../std/primitive.f32.html#method.exp2)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn exp2f32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns 2 raised to the power of an `f64`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::exp2`](../../std/primitive.f64.html#method.exp2)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn exp2f64(x: f64) -> f64;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the natural logarithm of an `f32`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::ln`](../../std/primitive.f32.html#method.ln)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn logf32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the natural logarithm of an `f64`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::ln`](../../std/primitive.f64.html#method.ln)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn logf64(x: f64) -> f64;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the base 10 logarithm of an `f32`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::log10`](../../std/primitive.f32.html#method.log10)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn log10f32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the base 10 logarithm of an `f64`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::log10`](../../std/primitive.f64.html#method.log10)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn log10f64(x: f64) -> f64;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the base 2 logarithm of an `f32`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::log2`](../../std/primitive.f32.html#method.log2)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn log2f32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the base 2 logarithm of an `f64`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::log2`](../../std/primitive.f64.html#method.log2)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn log2f64(x: f64) -> f64;
|
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns `a * b + c` for `f32` values.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::mul_add`](../../std/primitive.f32.html#method.mul_add)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns `a * b + c` for `f64` values.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::mul_add`](../../std/primitive.f64.html#method.mul_add)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the absolute value of an `f32`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::abs`](../../std/primitive.f32.html#method.abs)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn fabsf32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the absolute value of an `f64`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::abs`](../../std/primitive.f64.html#method.abs)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn fabsf64(x: f64) -> f64;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2019-06-06 21:27:23 +01:00
|
|
|
|
/// Returns the minimum of two `f32` values.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::min`](../../std/primitive.f32.html#method.min)
|
2019-06-06 21:27:23 +01:00
|
|
|
|
pub fn minnumf32(x: f32, y: f32) -> f32;
|
|
|
|
|
/// Returns the minimum of two `f64` values.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::min`](../../std/primitive.f64.html#method.min)
|
2019-06-06 21:27:23 +01:00
|
|
|
|
pub fn minnumf64(x: f64, y: f64) -> f64;
|
|
|
|
|
/// Returns the maximum of two `f32` values.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::max`](../../std/primitive.f32.html#method.max)
|
2019-06-06 21:27:23 +01:00
|
|
|
|
pub fn maxnumf32(x: f32, y: f32) -> f32;
|
|
|
|
|
/// Returns the maximum of two `f64` values.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::max`](../../std/primitive.f64.html#method.max)
|
2019-06-06 21:27:23 +01:00
|
|
|
|
pub fn maxnumf64(x: f64, y: f64) -> f64;
|
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Copies the sign from `y` to `x` for `f32` values.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::copysign`](../../std/primitive.f32.html#method.copysign)
|
2013-10-21 14:09:42 -04:00
|
|
|
|
pub fn copysignf32(x: f32, y: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Copies the sign from `y` to `x` for `f64` values.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::copysign`](../../std/primitive.f64.html#method.copysign)
|
2013-10-21 14:09:42 -04:00
|
|
|
|
pub fn copysignf64(x: f64, y: f64) -> f64;
|
2013-10-21 02:21:39 -04:00
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the largest integer less than or equal to an `f32`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::floor`](../../std/primitive.f32.html#method.floor)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn floorf32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the largest integer less than or equal to an `f64`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::floor`](../../std/primitive.f64.html#method.floor)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn floorf64(x: f64) -> f64;
|
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the smallest integer greater than or equal to an `f32`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::ceil`](../../std/primitive.f32.html#method.ceil)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn ceilf32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the smallest integer greater than or equal to an `f64`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::ceil`](../../std/primitive.f64.html#method.ceil)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn ceilf64(x: f64) -> f64;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the integer part of an `f32`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::trunc`](../../std/primitive.f32.html#method.trunc)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn truncf32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the integer part of an `f64`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::trunc`](../../std/primitive.f64.html#method.trunc)
|
2013-02-20 17:57:15 +01:00
|
|
|
|
pub fn truncf64(x: f64) -> f64;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
|
|
|
|
|
/// if the argument is not an integer.
|
2013-10-21 02:21:39 -04:00
|
|
|
|
pub fn rintf32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
|
|
|
|
|
/// if the argument is not an integer.
|
2013-10-21 02:21:39 -04:00
|
|
|
|
pub fn rintf64(x: f64) -> f64;
|
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the nearest integer to an `f32`.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2013-10-21 02:21:39 -04:00
|
|
|
|
pub fn nearbyintf32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the nearest integer to an `f64`.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2013-10-21 02:21:39 -04:00
|
|
|
|
pub fn nearbyintf64(x: f64) -> f64;
|
|
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f32::round`](../../std/primitive.f32.html#method.round)
|
2013-10-21 02:21:39 -04:00
|
|
|
|
pub fn roundf32(x: f32) -> f32;
|
2014-05-23 07:09:11 +02:00
|
|
|
|
/// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 22:45:00 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::f64::round`](../../std/primitive.f64.html#method.round)
|
2013-10-21 02:21:39 -04:00
|
|
|
|
pub fn roundf64(x: f64) -> f64;
|
2014-04-16 08:06:44 -07:00
|
|
|
|
|
2016-03-15 00:01:12 +01:00
|
|
|
|
/// Float addition that allows optimizations based on algebraic rules.
|
|
|
|
|
/// May assume inputs are finite.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn fadd_fast<T: Copy>(a: T, b: T) -> T;
|
2016-03-15 00:01:12 +01:00
|
|
|
|
|
|
|
|
|
/// Float subtraction that allows optimizations based on algebraic rules.
|
|
|
|
|
/// May assume inputs are finite.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn fsub_fast<T: Copy>(a: T, b: T) -> T;
|
2016-03-15 00:01:12 +01:00
|
|
|
|
|
|
|
|
|
/// Float multiplication that allows optimizations based on algebraic rules.
|
|
|
|
|
/// May assume inputs are finite.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn fmul_fast<T: Copy>(a: T, b: T) -> T;
|
2016-03-15 00:01:12 +01:00
|
|
|
|
|
|
|
|
|
/// Float division that allows optimizations based on algebraic rules.
|
|
|
|
|
/// May assume inputs are finite.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn fdiv_fast<T: Copy>(a: T, b: T) -> T;
|
2016-03-15 00:01:12 +01:00
|
|
|
|
|
|
|
|
|
/// Float remainder that allows optimizations based on algebraic rules.
|
|
|
|
|
/// May assume inputs are finite.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn frem_fast<T: Copy>(a: T, b: T) -> T;
|
2016-03-15 00:01:12 +01:00
|
|
|
|
|
2020-03-27 19:18:52 -04:00
|
|
|
|
/// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range
|
|
|
|
|
/// (<https://github.com/rust-lang/rust/issues/10184>)
|
|
|
|
|
///
|
2020-04-29 15:49:48 +02:00
|
|
|
|
/// Stabilized as [`f32::to_int_unchecked`](../../std/primitive.f32.html#method.to_int_unchecked)
|
|
|
|
|
/// and [`f64::to_int_unchecked`](../../std/primitive.f64.html#method.to_int_unchecked).
|
2020-03-27 19:18:52 -04:00
|
|
|
|
pub fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
|
|
|
|
|
|
2015-10-25 20:51:51 -07:00
|
|
|
|
/// Returns the number of bits set in an integer type `T`
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 21:38:37 +01:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
|
/// primitives via the `count_ones` method. For example,
|
|
|
|
|
/// [`std::u32::count_ones`](../../std/primitive.u32.html#method.count_ones)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_ctpop", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn ctpop<T: Copy>(x: T) -> T;
|
2014-04-14 20:04:14 +10:00
|
|
|
|
|
2016-12-11 13:36:03 -08:00
|
|
|
|
/// Returns the number of leading unset bits (zeroes) in an integer type `T`.
|
|
|
|
|
///
|
2020-01-30 21:38:37 +01:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
|
/// primitives via the `leading_zeros` method. For example,
|
|
|
|
|
/// [`std::u32::leading_zeros`](../../std/primitive.u32.html#method.leading_zeros)
|
2016-12-11 13:36:03 -08:00
|
|
|
|
///
|
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// #![feature(core_intrinsics)]
|
|
|
|
|
///
|
|
|
|
|
/// use std::intrinsics::ctlz;
|
|
|
|
|
///
|
|
|
|
|
/// let x = 0b0001_1100_u8;
|
2018-12-31 16:11:03 +01:00
|
|
|
|
/// let num_leading = ctlz(x);
|
2016-12-11 13:36:03 -08:00
|
|
|
|
/// assert_eq!(num_leading, 3);
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// An `x` with value `0` will return the bit width of `T`.
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// #![feature(core_intrinsics)]
|
|
|
|
|
///
|
|
|
|
|
/// use std::intrinsics::ctlz;
|
|
|
|
|
///
|
|
|
|
|
/// let x = 0u16;
|
2018-12-31 16:11:03 +01:00
|
|
|
|
/// let num_leading = ctlz(x);
|
2016-12-11 13:36:03 -08:00
|
|
|
|
/// assert_eq!(num_leading, 16);
|
|
|
|
|
/// ```
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_ctlz", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn ctlz<T: Copy>(x: T) -> T;
|
2014-04-14 20:04:14 +10:00
|
|
|
|
|
2017-05-27 20:56:25 -07:00
|
|
|
|
/// Like `ctlz`, but extra-unsafe as it returns `undef` when
|
|
|
|
|
/// given an `x` with value `0`.
|
|
|
|
|
///
|
2020-04-29 15:49:48 +02:00
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
|
|
|
|
///
|
2017-05-27 20:56:25 -07:00
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// #![feature(core_intrinsics)]
|
|
|
|
|
///
|
|
|
|
|
/// use std::intrinsics::ctlz_nonzero;
|
|
|
|
|
///
|
|
|
|
|
/// let x = 0b0001_1100_u8;
|
|
|
|
|
/// let num_leading = unsafe { ctlz_nonzero(x) };
|
|
|
|
|
/// assert_eq!(num_leading, 3);
|
|
|
|
|
/// ```
|
2019-12-25 11:54:55 +01:00
|
|
|
|
#[rustc_const_unstable(feature = "constctlz", issue = "none")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn ctlz_nonzero<T: Copy>(x: T) -> T;
|
2017-05-27 20:56:25 -07:00
|
|
|
|
|
2016-12-11 13:36:03 -08:00
|
|
|
|
/// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
|
|
|
|
|
///
|
2020-01-30 21:38:37 +01:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
|
/// primitives via the `trailing_zeros` method. For example,
|
|
|
|
|
/// [`std::u32::trailing_zeros`](../../std/primitive.u32.html#method.trailing_zeros)
|
2016-12-11 13:36:03 -08:00
|
|
|
|
///
|
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// #![feature(core_intrinsics)]
|
|
|
|
|
///
|
|
|
|
|
/// use std::intrinsics::cttz;
|
|
|
|
|
///
|
|
|
|
|
/// let x = 0b0011_1000_u8;
|
2018-12-31 16:11:03 +01:00
|
|
|
|
/// let num_trailing = cttz(x);
|
2016-12-11 13:36:03 -08:00
|
|
|
|
/// assert_eq!(num_trailing, 3);
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// An `x` with value `0` will return the bit width of `T`:
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// #![feature(core_intrinsics)]
|
|
|
|
|
///
|
|
|
|
|
/// use std::intrinsics::cttz;
|
|
|
|
|
///
|
|
|
|
|
/// let x = 0u16;
|
2018-12-31 16:11:03 +01:00
|
|
|
|
/// let num_trailing = cttz(x);
|
2016-12-11 13:36:03 -08:00
|
|
|
|
/// assert_eq!(num_trailing, 16);
|
|
|
|
|
/// ```
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_cttz", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn cttz<T: Copy>(x: T) -> T;
|
2014-04-14 20:04:14 +10:00
|
|
|
|
|
2017-05-27 20:56:25 -07:00
|
|
|
|
/// Like `cttz`, but extra-unsafe as it returns `undef` when
|
|
|
|
|
/// given an `x` with value `0`.
|
|
|
|
|
///
|
2020-04-29 15:49:48 +02:00
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
|
|
|
|
///
|
2017-05-27 20:56:25 -07:00
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// #![feature(core_intrinsics)]
|
|
|
|
|
///
|
|
|
|
|
/// use std::intrinsics::cttz_nonzero;
|
|
|
|
|
///
|
|
|
|
|
/// let x = 0b0011_1000_u8;
|
|
|
|
|
/// let num_trailing = unsafe { cttz_nonzero(x) };
|
|
|
|
|
/// assert_eq!(num_trailing, 3);
|
|
|
|
|
/// ```
|
2019-12-25 11:54:55 +01:00
|
|
|
|
#[rustc_const_unstable(feature = "const_cttz", issue = "none")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn cttz_nonzero<T: Copy>(x: T) -> T;
|
2017-05-27 20:56:25 -07:00
|
|
|
|
|
2015-10-25 20:51:51 -07:00
|
|
|
|
/// Reverses the bytes in an integer type `T`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 21:38:37 +01:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
|
/// primitives via the `swap_bytes` method. For example,
|
|
|
|
|
/// [`std::u32::swap_bytes`](../../std/primitive.u32.html#method.swap_bytes)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_bswap", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn bswap<T: Copy>(x: T) -> T;
|
2013-10-21 02:21:39 -04:00
|
|
|
|
|
2016-04-07 18:16:40 +01:00
|
|
|
|
/// Reverses the bits in an integer type `T`.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 21:38:37 +01:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
|
/// primitives via the `reverse_bits` method. For example,
|
|
|
|
|
/// [`std::u32::reverse_bits`](../../std/primitive.u32.html#method.reverse_bits)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_bitreverse", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn bitreverse<T: Copy>(x: T) -> T;
|
2016-04-07 18:16:40 +01:00
|
|
|
|
|
2015-10-25 20:51:51 -07:00
|
|
|
|
/// Performs checked integer addition.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-08 20:22:09 -05:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
|
/// primitives via the `overflowing_add` method. For example,
|
|
|
|
|
/// [`std::u32::overflowing_add`](../../std/primitive.u32.html#method.overflowing_add)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn add_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
|
2015-10-25 20:51:51 -07:00
|
|
|
|
|
|
|
|
|
/// Performs checked integer subtraction
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-08 20:22:09 -05:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
|
/// primitives via the `overflowing_sub` method. For example,
|
|
|
|
|
/// [`std::u32::overflowing_sub`](../../std/primitive.u32.html#method.overflowing_sub)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn sub_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
|
2015-10-25 20:51:51 -07:00
|
|
|
|
|
|
|
|
|
/// Performs checked integer multiplication
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-08 20:22:09 -05:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
|
/// primitives via the `overflowing_mul` method. For example,
|
|
|
|
|
/// [`std::u32::overflowing_mul`](../../std/primitive.u32.html#method.overflowing_mul)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn mul_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
|
2015-10-25 20:51:51 -07:00
|
|
|
|
|
Introduce unsafe offset_from on pointers
Adds intrinsics::exact_div to take advantage of the unsafe, which reduces the implementation from
```asm
sub rcx, rdx
mov rax, rcx
sar rax, 63
shr rax, 62
lea rax, [rax + rcx]
sar rax, 2
ret
```
down to
```asm
sub rcx, rdx
sar rcx, 2
mov rax, rcx
ret
```
(for `*const i32`)
2018-03-23 01:30:23 -07:00
|
|
|
|
/// Performs an exact division, resulting in undefined behavior where
|
2020-03-27 22:15:02 +01:00
|
|
|
|
/// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn exact_div<T: Copy>(x: T, y: T) -> T;
|
Introduce unsafe offset_from on pointers
Adds intrinsics::exact_div to take advantage of the unsafe, which reduces the implementation from
```asm
sub rcx, rdx
mov rax, rcx
sar rax, 63
shr rax, 62
lea rax, [rax + rcx]
sar rax, 2
ret
```
down to
```asm
sub rcx, rdx
sar rcx, 2
mov rax, rcx
ret
```
(for `*const i32`)
2018-03-23 01:30:23 -07:00
|
|
|
|
|
2015-10-25 20:51:51 -07:00
|
|
|
|
/// Performs an unchecked division, resulting in undefined behavior
|
2020-03-27 22:15:02 +01:00
|
|
|
|
/// where y = 0 or x = `T::MIN` and y = -1
|
2020-01-30 21:38:37 +01:00
|
|
|
|
///
|
2020-04-29 15:49:48 +02:00
|
|
|
|
/// Safe wrappers for this intrinsic are available on the integer
|
2020-01-30 21:38:37 +01:00
|
|
|
|
/// primitives via the `checked_div` method. For example,
|
|
|
|
|
/// [`std::u32::checked_div`](../../std/primitive.u32.html#method.checked_div)
|
2020-02-03 12:49:31 -08:00
|
|
|
|
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn unchecked_div<T: Copy>(x: T, y: T) -> T;
|
2015-10-25 20:51:51 -07:00
|
|
|
|
/// Returns the remainder of an unchecked division, resulting in
|
2020-03-27 22:15:02 +01:00
|
|
|
|
/// undefined behavior where y = 0 or x = `T::MIN` and y = -1
|
2020-01-30 21:38:37 +01:00
|
|
|
|
///
|
2020-04-29 15:49:48 +02:00
|
|
|
|
/// Safe wrappers for this intrinsic are available on the integer
|
2020-01-30 21:38:37 +01:00
|
|
|
|
/// primitives via the `checked_rem` method. For example,
|
|
|
|
|
/// [`std::u32::checked_rem`](../../std/primitive.u32.html#method.checked_rem)
|
2020-02-03 12:49:31 -08:00
|
|
|
|
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn unchecked_rem<T: Copy>(x: T, y: T) -> T;
|
2015-10-25 20:51:51 -07:00
|
|
|
|
|
2017-03-14 16:35:11 +01:00
|
|
|
|
/// Performs an unchecked left shift, resulting in undefined behavior when
|
|
|
|
|
/// y < 0 or y >= N, where N is the width of T in bits.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-04-29 15:49:48 +02:00
|
|
|
|
/// Safe wrappers for this intrinsic are available on the integer
|
2020-01-31 21:53:30 +01:00
|
|
|
|
/// primitives via the `checked_shl` method. For example,
|
|
|
|
|
/// [`std::u32::checked_shl`](../../std/primitive.u32.html#method.checked_shl)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn unchecked_shl<T: Copy>(x: T, y: T) -> T;
|
2017-03-14 16:35:11 +01:00
|
|
|
|
/// Performs an unchecked right shift, resulting in undefined behavior when
|
|
|
|
|
/// y < 0 or y >= N, where N is the width of T in bits.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-04-29 15:49:48 +02:00
|
|
|
|
/// Safe wrappers for this intrinsic are available on the integer
|
2020-01-31 21:53:30 +01:00
|
|
|
|
/// primitives via the `checked_shr` method. For example,
|
|
|
|
|
/// [`std::u32::checked_shr`](../../std/primitive.u32.html#method.checked_shr)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn unchecked_shr<T: Copy>(x: T, y: T) -> T;
|
2017-03-14 16:35:11 +01:00
|
|
|
|
|
2019-06-03 12:59:48 +02:00
|
|
|
|
/// Returns the result of an unchecked addition, resulting in
|
2020-03-27 22:15:02 +01:00
|
|
|
|
/// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2020-02-03 12:49:31 -08:00
|
|
|
|
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn unchecked_add<T: Copy>(x: T, y: T) -> T;
|
2019-06-03 12:59:48 +02:00
|
|
|
|
|
2019-11-26 22:19:54 -05:00
|
|
|
|
/// Returns the result of an unchecked subtraction, resulting in
|
2020-03-27 22:15:02 +01:00
|
|
|
|
/// undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2020-02-03 12:49:31 -08:00
|
|
|
|
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn unchecked_sub<T: Copy>(x: T, y: T) -> T;
|
2019-06-03 12:59:48 +02:00
|
|
|
|
|
|
|
|
|
/// Returns the result of an unchecked multiplication, resulting in
|
2020-03-27 22:15:02 +01:00
|
|
|
|
/// undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`.
|
2020-04-29 15:49:48 +02:00
|
|
|
|
///
|
|
|
|
|
/// This intrinsic does not have a stable counterpart.
|
2020-02-03 12:49:31 -08:00
|
|
|
|
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn unchecked_mul<T: Copy>(x: T, y: T) -> T;
|
2019-06-03 12:59:48 +02:00
|
|
|
|
|
2018-11-03 15:48:29 +01:00
|
|
|
|
/// Performs rotate left.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2018-11-03 15:48:29 +01:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
|
/// primitives via the `rotate_left` method. For example,
|
|
|
|
|
/// [`std::u32::rotate_left`](../../std/primitive.u32.html#method.rotate_left)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn rotate_left<T: Copy>(x: T, y: T) -> T;
|
2018-11-03 15:48:29 +01:00
|
|
|
|
|
|
|
|
|
/// Performs rotate right.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2018-11-03 15:48:29 +01:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
|
/// primitives via the `rotate_right` method. For example,
|
|
|
|
|
/// [`std::u32::rotate_right`](../../std/primitive.u32.html#method.rotate_right)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn rotate_right<T: Copy>(x: T, y: T) -> T;
|
2018-11-03 15:48:29 +01:00
|
|
|
|
|
2017-04-03 21:17:47 +02:00
|
|
|
|
/// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2016-11-08 20:22:09 -05:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
2020-01-31 21:53:30 +01:00
|
|
|
|
/// primitives via the `checked_add` method. For example,
|
|
|
|
|
/// [`std::u32::checked_add`](../../std/primitive.u32.html#method.checked_add)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn wrapping_add<T: Copy>(a: T, b: T) -> T;
|
2019-08-16 20:02:31 +03:00
|
|
|
|
/// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2019-08-16 20:02:31 +03:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
2020-01-31 21:53:30 +01:00
|
|
|
|
/// primitives via the `checked_sub` method. For example,
|
|
|
|
|
/// [`std::u32::checked_sub`](../../std/primitive.u32.html#method.checked_sub)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn wrapping_sub<T: Copy>(a: T, b: T) -> T;
|
2019-08-16 20:02:31 +03:00
|
|
|
|
/// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2019-08-16 20:02:31 +03:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
2020-01-31 21:53:30 +01:00
|
|
|
|
/// primitives via the `checked_mul` method. For example,
|
|
|
|
|
/// [`std::u32::checked_mul`](../../std/primitive.u32.html#method.checked_mul)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn wrapping_mul<T: Copy>(a: T, b: T) -> T;
|
2019-08-16 20:02:31 +03:00
|
|
|
|
|
2019-01-29 22:16:43 +01:00
|
|
|
|
/// Computes `a + b`, while saturating at numeric bounds.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2019-01-29 22:16:43 +01:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
|
/// primitives via the `saturating_add` method. For example,
|
|
|
|
|
/// [`std::u32::saturating_add`](../../std/primitive.u32.html#method.saturating_add)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn saturating_add<T: Copy>(a: T, b: T) -> T;
|
2019-01-29 22:16:43 +01:00
|
|
|
|
/// Computes `a - b`, while saturating at numeric bounds.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2019-01-29 22:16:43 +01:00
|
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
|
/// primitives via the `saturating_sub` method. For example,
|
|
|
|
|
/// [`std::u32::saturating_sub`](../../std/primitive.u32.html#method.saturating_sub)
|
2019-12-20 23:15:50 +01:00
|
|
|
|
#[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
|
2020-03-18 00:00:00 +00:00
|
|
|
|
pub fn saturating_sub<T: Copy>(a: T, b: T) -> T;
|
2019-01-29 22:16:43 +01:00
|
|
|
|
|
2015-05-25 20:21:29 +03:00
|
|
|
|
/// Returns the value of the discriminant for the variant in 'v',
|
|
|
|
|
/// cast to a `u64`; if `T` has no discriminant, returns 0.
|
2020-01-31 19:28:15 +01:00
|
|
|
|
///
|
2020-01-30 21:37:34 +01:00
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::mem::discriminant`](../../std/mem/fn.discriminant.html)
|
2020-03-08 14:24:32 +01:00
|
|
|
|
#[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
|
2020-04-05 19:30:03 +02:00
|
|
|
|
pub fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
|
2015-07-20 13:27:38 -07:00
|
|
|
|
|
2020-06-23 16:46:24 +01:00
|
|
|
|
/// Returns the number of variants of the type `T` cast to a `usize`;
|
|
|
|
|
/// if `T` has no variants, returns 0. Uninhabited variants will be counted.
|
|
|
|
|
///
|
|
|
|
|
/// The to-be-stabilized version of this intrinsic is
|
|
|
|
|
/// [`std::mem::variant_count`](../../std/mem/fn.variant_count.html)
|
|
|
|
|
#[rustc_const_unstable(feature = "variant_count", issue = "73662")]
|
|
|
|
|
pub fn variant_count<T>() -> usize;
|
|
|
|
|
|
2020-03-02 13:59:20 +00:00
|
|
|
|
/// Rust's "try catch" construct which invokes the function pointer `try_fn`
|
|
|
|
|
/// with the data pointer `data`.
|
2015-10-23 18:18:44 -07:00
|
|
|
|
///
|
2020-03-02 13:59:20 +00:00
|
|
|
|
/// The third argument is a function called if a panic occurs. This function
|
|
|
|
|
/// takes the data pointer and a pointer to the target-specific exception
|
|
|
|
|
/// object that was caught. For more information see the compiler's
|
2015-10-23 18:18:44 -07:00
|
|
|
|
/// source as well as std's catch implementation.
|
2020-03-02 13:59:20 +00:00
|
|
|
|
pub fn r#try(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32;
|
2017-08-16 15:41:09 +02:00
|
|
|
|
|
2017-10-18 10:30:29 -07:00
|
|
|
|
/// Emits a `!nontemporal` store according to LLVM (see their docs).
|
|
|
|
|
/// Probably will never become stable.
|
|
|
|
|
pub fn nontemporal_store<T>(ptr: *mut T, val: T);
|
2019-08-20 17:51:54 +02:00
|
|
|
|
|
|
|
|
|
/// See documentation of `<*const T>::offset_from` for details.
|
2020-06-18 10:06:57 +02:00
|
|
|
|
#[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "41079")]
|
2019-08-20 17:51:54 +02:00
|
|
|
|
pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
|
2019-10-28 22:44:30 -04:00
|
|
|
|
|
2020-06-05 09:14:45 -07:00
|
|
|
|
/// Internal placeholder for injecting code coverage counters when the "instrument-coverage"
|
2020-08-01 20:03:59 -07:00
|
|
|
|
/// option is enabled. The source code region information is extracted prior to code generation,
|
|
|
|
|
/// and added to the "coverage map", which is injected into the generated code as additional
|
|
|
|
|
/// data. This intrinsic then triggers the generation of LLVM intrinsic call
|
|
|
|
|
/// `instrprof.increment`, using the remaining args (`function_source_hash` and `index`).
|
2020-07-02 11:27:15 -07:00
|
|
|
|
#[cfg(not(bootstrap))]
|
2020-06-05 09:49:31 -07:00
|
|
|
|
#[lang = "count_code_region"]
|
2020-07-02 11:27:15 -07:00
|
|
|
|
pub fn count_code_region(
|
|
|
|
|
function_source_hash: u64,
|
|
|
|
|
index: u32,
|
2020-08-01 20:03:59 -07:00
|
|
|
|
file_name: &'static str,
|
|
|
|
|
start_line: u32,
|
|
|
|
|
start_col: u32,
|
|
|
|
|
end_line: u32,
|
|
|
|
|
end_col: u32,
|
2020-07-02 11:27:15 -07:00
|
|
|
|
);
|
2020-06-21 23:29:08 -07:00
|
|
|
|
|
|
|
|
|
/// Internal marker for code coverage expressions, injected into the MIR when the
|
|
|
|
|
/// "instrument-coverage" option is enabled. This intrinsic is not converted into a
|
|
|
|
|
/// backend intrinsic call, but its arguments are extracted during the production of a
|
|
|
|
|
/// "coverage map", which is injected into the generated code, as additional data.
|
|
|
|
|
/// This marker identifies a code region and two other counters or counter expressions
|
|
|
|
|
/// whose sum is the number of times the code region was executed.
|
2020-07-02 11:27:15 -07:00
|
|
|
|
#[cfg(not(bootstrap))]
|
|
|
|
|
#[lang = "coverage_counter_add"]
|
2020-06-21 23:29:08 -07:00
|
|
|
|
pub fn coverage_counter_add(
|
|
|
|
|
index: u32,
|
|
|
|
|
left_index: u32,
|
|
|
|
|
right_index: u32,
|
2020-08-01 20:03:59 -07:00
|
|
|
|
file_name: &'static str,
|
|
|
|
|
start_line: u32,
|
|
|
|
|
start_col: u32,
|
|
|
|
|
end_line: u32,
|
|
|
|
|
end_col: u32,
|
2020-06-21 23:29:08 -07:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/// This marker identifies a code region and two other counters or counter expressions
|
|
|
|
|
/// whose difference is the number of times the code region was executed.
|
|
|
|
|
/// (See `coverage_counter_add` for more information.)
|
2020-07-02 11:27:15 -07:00
|
|
|
|
#[cfg(not(bootstrap))]
|
|
|
|
|
#[lang = "coverage_counter_subtract"]
|
2020-06-21 23:29:08 -07:00
|
|
|
|
pub fn coverage_counter_subtract(
|
|
|
|
|
index: u32,
|
|
|
|
|
left_index: u32,
|
|
|
|
|
right_index: u32,
|
2020-08-01 20:03:59 -07:00
|
|
|
|
file_name: &'static str,
|
|
|
|
|
start_line: u32,
|
|
|
|
|
start_col: u32,
|
|
|
|
|
end_line: u32,
|
|
|
|
|
end_col: u32,
|
2020-06-21 23:29:08 -07:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/// This marker identifies a code region to be added to the "coverage map" to indicate source
|
|
|
|
|
/// code that can never be reached.
|
|
|
|
|
/// (See `coverage_counter_add` for more information.)
|
2020-08-01 20:03:59 -07:00
|
|
|
|
#[cfg(not(bootstrap))]
|
|
|
|
|
pub fn coverage_unreachable(
|
|
|
|
|
file_name: &'static str,
|
|
|
|
|
start_line: u32,
|
|
|
|
|
start_col: u32,
|
|
|
|
|
end_line: u32,
|
|
|
|
|
end_col: u32,
|
|
|
|
|
);
|
2020-06-16 10:37:34 +02:00
|
|
|
|
|
|
|
|
|
/// See documentation of `<*const T>::guaranteed_eq` for details.
|
|
|
|
|
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
|
|
|
|
|
pub fn ptr_guaranteed_eq<T>(ptr: *const T, other: *const T) -> bool;
|
|
|
|
|
|
|
|
|
|
/// See documentation of `<*const T>::guaranteed_ne` for details.
|
|
|
|
|
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
|
|
|
|
|
pub fn ptr_guaranteed_ne<T>(ptr: *const T, other: *const T) -> bool;
|
2020-06-03 21:19:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-03 21:16:31 +02:00
|
|
|
|
// Some functions are defined here because they accidentally got made
|
|
|
|
|
// available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
|
|
|
|
|
// (`transmute` also falls into this category, but it cannot be wrapped due to the
|
|
|
|
|
// check that `T` and `U` have the same size.)
|
2019-02-08 14:14:15 +01:00
|
|
|
|
|
2019-02-27 17:10:59 +01:00
|
|
|
|
/// Checks whether `ptr` is properly aligned with respect to
|
|
|
|
|
/// `align_of::<T>()`.
|
|
|
|
|
pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
|
|
|
|
|
!ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Checks whether the regions of memory starting at `src` and `dst` of size
|
2020-02-16 14:44:16 +01:00
|
|
|
|
/// `count * size_of::<T>()` do *not* overlap.
|
|
|
|
|
pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
|
2019-02-27 17:10:59 +01:00
|
|
|
|
let src_usize = src as usize;
|
|
|
|
|
let dst_usize = dst as usize;
|
|
|
|
|
let size = mem::size_of::<T>().checked_mul(count).unwrap();
|
2019-12-22 17:42:04 -05:00
|
|
|
|
let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
|
2020-02-27 09:45:32 +01:00
|
|
|
|
// If the absolute distance between the ptrs is at least as big as the size of the buffer,
|
|
|
|
|
// they do not overlap.
|
|
|
|
|
diff >= size
|
2019-02-27 17:10:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 14:14:15 +01:00
|
|
|
|
/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
|
|
|
|
|
/// and destination must *not* overlap.
|
|
|
|
|
///
|
|
|
|
|
/// For regions of memory which might overlap, use [`copy`] instead.
|
|
|
|
|
///
|
|
|
|
|
/// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
|
|
|
|
|
/// with the argument order swapped.
|
|
|
|
|
///
|
|
|
|
|
/// [`copy`]: ./fn.copy.html
|
|
|
|
|
/// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy
|
|
|
|
|
///
|
|
|
|
|
/// # Safety
|
|
|
|
|
///
|
|
|
|
|
/// Behavior is undefined if any of the following conditions are violated:
|
|
|
|
|
///
|
|
|
|
|
/// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
|
|
|
|
|
///
|
|
|
|
|
/// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
|
|
|
|
|
///
|
|
|
|
|
/// * Both `src` and `dst` must be properly aligned.
|
|
|
|
|
///
|
|
|
|
|
/// * The region of memory beginning at `src` with a size of `count *
|
|
|
|
|
/// size_of::<T>()` bytes must *not* overlap with the region of memory
|
|
|
|
|
/// beginning at `dst` with the same size.
|
|
|
|
|
///
|
|
|
|
|
/// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of
|
|
|
|
|
/// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values
|
|
|
|
|
/// in the region beginning at `*src` and the region beginning at `*dst` can
|
|
|
|
|
/// [violate memory safety][read-ownership].
|
|
|
|
|
///
|
|
|
|
|
/// Note that even if the effectively copied size (`count * size_of::<T>()`) is
|
|
|
|
|
/// `0`, the pointers must be non-NULL and properly aligned.
|
|
|
|
|
///
|
|
|
|
|
/// [`Copy`]: ../marker/trait.Copy.html
|
|
|
|
|
/// [`read`]: ../ptr/fn.read.html
|
|
|
|
|
/// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
|
|
|
|
|
/// [valid]: ../ptr/index.html#safety
|
|
|
|
|
///
|
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
|
|
|
|
/// Manually implement [`Vec::append`]:
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use std::ptr;
|
|
|
|
|
///
|
|
|
|
|
/// /// Moves all the elements of `src` into `dst`, leaving `src` empty.
|
|
|
|
|
/// fn append<T>(dst: &mut Vec<T>, src: &mut Vec<T>) {
|
|
|
|
|
/// let src_len = src.len();
|
|
|
|
|
/// let dst_len = dst.len();
|
|
|
|
|
///
|
|
|
|
|
/// // Ensure that `dst` has enough capacity to hold all of `src`.
|
|
|
|
|
/// dst.reserve(src_len);
|
|
|
|
|
///
|
|
|
|
|
/// unsafe {
|
|
|
|
|
/// // The call to offset is always safe because `Vec` will never
|
|
|
|
|
/// // allocate more than `isize::MAX` bytes.
|
|
|
|
|
/// let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize);
|
|
|
|
|
/// let src_ptr = src.as_ptr();
|
|
|
|
|
///
|
|
|
|
|
/// // Truncate `src` without dropping its contents. We do this first,
|
|
|
|
|
/// // to avoid problems in case something further down panics.
|
|
|
|
|
/// src.set_len(0);
|
|
|
|
|
///
|
|
|
|
|
/// // The two regions cannot overlap because mutable references do
|
|
|
|
|
/// // not alias, and two different vectors cannot own the same
|
|
|
|
|
/// // memory.
|
|
|
|
|
/// ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
|
|
|
|
|
///
|
|
|
|
|
/// // Notify `dst` that it now holds the contents of `src`.
|
|
|
|
|
/// dst.set_len(dst_len + src_len);
|
|
|
|
|
/// }
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// let mut a = vec!['r'];
|
|
|
|
|
/// let mut b = vec!['u', 's', 't'];
|
|
|
|
|
///
|
|
|
|
|
/// append(&mut a, &mut b);
|
|
|
|
|
///
|
|
|
|
|
/// assert_eq!(a, &['r', 'u', 's', 't']);
|
|
|
|
|
/// assert!(b.is_empty());
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append
|
2020-02-22 22:25:47 -05:00
|
|
|
|
#[doc(alias = "memcpy")]
|
2019-02-08 14:14:15 +01:00
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
|
#[inline]
|
|
|
|
|
pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
|
2019-06-03 21:16:31 +02:00
|
|
|
|
extern "rust-intrinsic" {
|
|
|
|
|
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
|
|
|
|
|
}
|
2019-02-27 17:10:59 +01:00
|
|
|
|
|
2020-06-06 11:56:58 +02:00
|
|
|
|
if cfg!(debug_assertions)
|
|
|
|
|
&& !(is_aligned_and_not_null(src)
|
|
|
|
|
&& is_aligned_and_not_null(dst)
|
|
|
|
|
&& is_nonoverlapping(src, dst, count))
|
|
|
|
|
{
|
|
|
|
|
// Not panicking to keep codegen impact smaller.
|
|
|
|
|
abort();
|
|
|
|
|
}
|
2020-06-22 00:54:46 +02:00
|
|
|
|
|
|
|
|
|
// SAFETY: the safety contract for `copy_nonoverlapping` must be
|
|
|
|
|
// upheld by the caller.
|
|
|
|
|
unsafe { copy_nonoverlapping(src, dst, count) }
|
2019-02-08 14:14:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
|
|
|
|
|
/// and destination may overlap.
|
|
|
|
|
///
|
|
|
|
|
/// If the source and destination will *never* overlap,
|
|
|
|
|
/// [`copy_nonoverlapping`] can be used instead.
|
|
|
|
|
///
|
|
|
|
|
/// `copy` is semantically equivalent to C's [`memmove`], but with the argument
|
|
|
|
|
/// order swapped. Copying takes place as if the bytes were copied from `src`
|
|
|
|
|
/// to a temporary array and then copied from the array to `dst`.
|
|
|
|
|
///
|
|
|
|
|
/// [`copy_nonoverlapping`]: ./fn.copy_nonoverlapping.html
|
|
|
|
|
/// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove
|
|
|
|
|
///
|
|
|
|
|
/// # Safety
|
|
|
|
|
///
|
|
|
|
|
/// Behavior is undefined if any of the following conditions are violated:
|
|
|
|
|
///
|
|
|
|
|
/// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
|
|
|
|
|
///
|
|
|
|
|
/// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
|
|
|
|
|
///
|
|
|
|
|
/// * Both `src` and `dst` must be properly aligned.
|
|
|
|
|
///
|
|
|
|
|
/// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of
|
|
|
|
|
/// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the values
|
|
|
|
|
/// in the region beginning at `*src` and the region beginning at `*dst` can
|
|
|
|
|
/// [violate memory safety][read-ownership].
|
|
|
|
|
///
|
|
|
|
|
/// Note that even if the effectively copied size (`count * size_of::<T>()`) is
|
|
|
|
|
/// `0`, the pointers must be non-NULL and properly aligned.
|
|
|
|
|
///
|
|
|
|
|
/// [`Copy`]: ../marker/trait.Copy.html
|
|
|
|
|
/// [`read`]: ../ptr/fn.read.html
|
|
|
|
|
/// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
|
|
|
|
|
/// [valid]: ../ptr/index.html#safety
|
|
|
|
|
///
|
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
|
|
|
|
/// Efficiently create a Rust vector from an unsafe buffer:
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use std::ptr;
|
|
|
|
|
///
|
|
|
|
|
/// # #[allow(dead_code)]
|
|
|
|
|
/// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
|
|
|
|
|
/// let mut dst = Vec::with_capacity(elts);
|
|
|
|
|
/// dst.set_len(elts);
|
|
|
|
|
/// ptr::copy(ptr, dst.as_mut_ptr(), elts);
|
|
|
|
|
/// dst
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2020-02-22 22:25:47 -05:00
|
|
|
|
#[doc(alias = "memmove")]
|
2019-02-08 14:14:15 +01:00
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
|
#[inline]
|
|
|
|
|
pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
|
2019-06-03 21:16:31 +02:00
|
|
|
|
extern "rust-intrinsic" {
|
|
|
|
|
fn copy<T>(src: *const T, dst: *mut T, count: usize);
|
|
|
|
|
}
|
2019-02-27 17:10:59 +01:00
|
|
|
|
|
2020-06-06 11:56:58 +02:00
|
|
|
|
if cfg!(debug_assertions) && !(is_aligned_and_not_null(src) && is_aligned_and_not_null(dst)) {
|
|
|
|
|
// Not panicking to keep codegen impact smaller.
|
|
|
|
|
abort();
|
|
|
|
|
}
|
2020-06-22 00:54:46 +02:00
|
|
|
|
|
|
|
|
|
// SAFETY: the safety contract for `copy` must be upheld by the caller.
|
|
|
|
|
unsafe { copy(src, dst, count) }
|
2019-02-08 14:14:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
|
|
|
|
|
/// `val`.
|
|
|
|
|
///
|
|
|
|
|
/// `write_bytes` is similar to C's [`memset`], but sets `count *
|
|
|
|
|
/// size_of::<T>()` bytes to `val`.
|
|
|
|
|
///
|
|
|
|
|
/// [`memset`]: https://en.cppreference.com/w/c/string/byte/memset
|
|
|
|
|
///
|
|
|
|
|
/// # Safety
|
|
|
|
|
///
|
|
|
|
|
/// Behavior is undefined if any of the following conditions are violated:
|
|
|
|
|
///
|
|
|
|
|
/// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
|
|
|
|
|
///
|
|
|
|
|
/// * `dst` must be properly aligned.
|
|
|
|
|
///
|
|
|
|
|
/// Additionally, the caller must ensure that writing `count *
|
|
|
|
|
/// size_of::<T>()` bytes to the given region of memory results in a valid
|
|
|
|
|
/// value of `T`. Using a region of memory typed as a `T` that contains an
|
|
|
|
|
/// invalid value of `T` is undefined behavior.
|
|
|
|
|
///
|
|
|
|
|
/// Note that even if the effectively copied size (`count * size_of::<T>()`) is
|
|
|
|
|
/// `0`, the pointer must be non-NULL and properly aligned.
|
|
|
|
|
///
|
|
|
|
|
/// [valid]: ../ptr/index.html#safety
|
|
|
|
|
///
|
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
|
|
|
|
/// Basic usage:
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use std::ptr;
|
|
|
|
|
///
|
|
|
|
|
/// let mut vec = vec![0u32; 4];
|
|
|
|
|
/// unsafe {
|
|
|
|
|
/// let vec_ptr = vec.as_mut_ptr();
|
|
|
|
|
/// ptr::write_bytes(vec_ptr, 0xfe, 2);
|
|
|
|
|
/// }
|
|
|
|
|
/// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// Creating an invalid value:
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use std::ptr;
|
|
|
|
|
///
|
|
|
|
|
/// let mut v = Box::new(0i32);
|
|
|
|
|
///
|
|
|
|
|
/// unsafe {
|
|
|
|
|
/// // Leaks the previously held value by overwriting the `Box<T>` with
|
|
|
|
|
/// // a null pointer.
|
|
|
|
|
/// ptr::write_bytes(&mut v as *mut Box<i32>, 0, 1);
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// // At this point, using or dropping `v` results in undefined behavior.
|
|
|
|
|
/// // drop(v); // ERROR
|
|
|
|
|
///
|
|
|
|
|
/// // Even leaking `v` "uses" it, and hence is undefined behavior.
|
|
|
|
|
/// // mem::forget(v); // ERROR
|
|
|
|
|
///
|
|
|
|
|
/// // In fact, `v` is invalid according to basic type layout invariants, so *any*
|
|
|
|
|
/// // operation touching it is undefined behavior.
|
|
|
|
|
/// // let v2 = v; // ERROR
|
|
|
|
|
///
|
|
|
|
|
/// unsafe {
|
|
|
|
|
/// // Let us instead put in a valid value
|
|
|
|
|
/// ptr::write(&mut v as *mut Box<i32>, Box::new(42i32));
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// // Now the box is fine
|
|
|
|
|
/// assert_eq!(*v, 42);
|
|
|
|
|
/// ```
|
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
|
#[inline]
|
|
|
|
|
pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
|
2019-06-03 21:16:31 +02:00
|
|
|
|
extern "rust-intrinsic" {
|
|
|
|
|
fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
|
|
|
|
|
}
|
2019-02-27 17:10:59 +01:00
|
|
|
|
|
|
|
|
|
debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer");
|
2020-06-22 00:54:46 +02:00
|
|
|
|
|
|
|
|
|
// SAFETY: the safety contract for `write_bytes` must be upheld by the caller.
|
|
|
|
|
unsafe { write_bytes(dst, val, count) }
|
2019-02-08 14:14:15 +01:00
|
|
|
|
}
|