2013-02-20 17:57:15 +01:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-11-25 21:17:11 -05:00
|
|
|
//! rustc compiler intrinsics.
|
|
|
|
//!
|
2018-05-08 16:10:16 +03:00
|
|
|
//! The corresponding definitions are in librustc_codegen_llvm/intrinsic.rs.
|
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
|
|
|
|
2015-06-09 11:18:03 -07:00
|
|
|
#![unstable(feature = "core_intrinsics",
|
|
|
|
reason = "intrinsics are unlikely to ever be stabilized, instead \
|
|
|
|
they should be used through stabilized interfaces \
|
2015-08-12 17:23:48 -07:00
|
|
|
in the rest of the standard library",
|
|
|
|
issue = "0")]
|
2014-10-27 15:37:07 -07:00
|
|
|
#![allow(missing_docs)]
|
2014-02-15 23:49:08 -08:00
|
|
|
|
2017-03-14 01:08:21 +02:00
|
|
|
#[stable(feature = "drop_in_place", since = "1.8.0")]
|
|
|
|
#[rustc_deprecated(reason = "no longer an intrinsic - use `ptr::drop_in_place` directly",
|
|
|
|
since = "1.18.0")]
|
|
|
|
pub use ptr::drop_in_place;
|
2014-02-17 01:37:26 -08:00
|
|
|
|
2017-03-14 01:08:21 +02:00
|
|
|
extern "rust-intrinsic" {
|
2015-06-09 16:49:24 -04:00
|
|
|
// NB: 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.
|
|
|
|
/// 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
|
2016-03-14 11:57:50 +01:00
|
|
|
pub fn atomic_cxchg<T>(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.
|
|
|
|
/// 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
|
2016-03-14 11:57:50 +01:00
|
|
|
pub fn atomic_cxchg_acq<T>(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.
|
|
|
|
/// 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
|
2016-03-14 11:57:50 +01:00
|
|
|
pub fn atomic_cxchg_rel<T>(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.
|
|
|
|
/// 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
|
2016-03-14 11:57:50 +01:00
|
|
|
pub fn atomic_cxchg_acqrel<T>(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.
|
|
|
|
/// 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
|
2016-03-14 11:57:50 +01:00
|
|
|
pub fn atomic_cxchg_relaxed<T>(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.
|
|
|
|
/// 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
|
2016-03-14 11:57:50 +01:00
|
|
|
pub fn atomic_cxchg_failrelaxed<T>(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.
|
|
|
|
/// 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
|
2016-03-14 11:57:50 +01:00
|
|
|
pub fn atomic_cxchg_failacq<T>(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.
|
|
|
|
/// 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
|
2016-03-14 11:57:50 +01:00
|
|
|
pub fn atomic_cxchg_acq_failrelaxed<T>(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.
|
|
|
|
/// 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
|
2016-03-14 11:57:50 +01:00
|
|
|
pub fn atomic_cxchg_acqrel_failrelaxed<T>(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.
|
|
|
|
/// 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
|
2016-01-16 23:40:11 +00:00
|
|
|
pub fn atomic_cxchgweak<T>(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.
|
|
|
|
/// 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
|
2016-01-16 23:40:11 +00:00
|
|
|
pub fn atomic_cxchgweak_acq<T>(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.
|
|
|
|
/// 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
|
2016-01-16 23:40:11 +00:00
|
|
|
pub fn atomic_cxchgweak_rel<T>(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.
|
|
|
|
/// 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
|
2016-01-16 23:40:11 +00:00
|
|
|
pub fn atomic_cxchgweak_acqrel<T>(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.
|
|
|
|
/// 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
|
2016-01-16 23:40:11 +00:00
|
|
|
pub fn atomic_cxchgweak_relaxed<T>(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.
|
|
|
|
/// 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
|
2016-01-16 23:40:11 +00:00
|
|
|
pub fn atomic_cxchgweak_failrelaxed<T>(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.
|
|
|
|
/// 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
|
2016-01-16 23:40:11 +00:00
|
|
|
pub fn atomic_cxchgweak_failacq<T>(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.
|
|
|
|
/// 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
|
2016-01-16 23:40:11 +00:00
|
|
|
pub fn atomic_cxchgweak_acq_failrelaxed<T>(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.
|
|
|
|
/// 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
|
2016-01-16 23:40:11 +00:00
|
|
|
pub fn atomic_cxchgweak_acqrel_failrelaxed<T>(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.
|
|
|
|
/// 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).
|
2014-06-25 12:47:34 -07:00
|
|
|
pub fn atomic_load<T>(src: *const T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Loads the current value of the pointer.
|
|
|
|
/// 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).
|
2014-06-25 12:47:34 -07:00
|
|
|
pub fn atomic_load_acq<T>(src: *const T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Loads the current value of the pointer.
|
|
|
|
/// 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).
|
2014-06-25 12:47:34 -07:00
|
|
|
pub fn atomic_load_relaxed<T>(src: *const T) -> T;
|
2014-12-14 01:44:24 -08:00
|
|
|
pub fn atomic_load_unordered<T>(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.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_store<T>(dst: *mut T, val: T);
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Stores the value at the specified memory location.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_store_rel<T>(dst: *mut T, val: T);
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Stores the value at the specified memory location.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_store_relaxed<T>(dst: *mut T, val: T);
|
2014-12-14 01:44:24 -08:00
|
|
|
pub fn atomic_store_unordered<T>(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.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xchg<T>(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.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xchg_acq<T>(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.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xchg_rel<T>(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.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xchg_acqrel<T>(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.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xchg_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Add to the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xadd<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Add to the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xadd_acq<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Add to the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xadd_rel<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Add to the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xadd_acqrel<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Add to the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xadd_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Subtract from the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xsub<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Subtract from the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xsub_acq<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Subtract from the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xsub_rel<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Subtract from the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xsub_acqrel<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Subtract from the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xsub_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise and with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_and<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise and with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_and_acq<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise and with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_and_rel<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise and with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_and_acqrel<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise and with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_and_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise nand with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_nand<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise nand with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_nand_acq<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise nand with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_nand_rel<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise nand with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_nand_acqrel<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise nand with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_nand_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise or with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_or<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise or with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_or_acq<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise or with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_or_rel<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise or with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_or_acqrel<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise or with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_or_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise xor with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xor<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise xor with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xor_acq<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise xor with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xor_rel<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise xor with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xor_acqrel<T>(dst: *mut T, src: T) -> T;
|
2016-11-05 19:26:57 -04:00
|
|
|
/// Bitwise xor with the current value, returning the previous value.
|
|
|
|
/// 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).
|
2014-02-24 18:20:52 -08:00
|
|
|
pub fn atomic_xor_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
|
|
|
pub fn atomic_max<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_max_acq<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_max_rel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_max_acqrel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_max_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
|
|
|
pub fn atomic_min<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_min_acq<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_min_rel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_min_acqrel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_min_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
|
|
|
pub fn atomic_umin<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_umin_acq<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_umin_rel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_umin_acqrel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_umin_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
|
|
|
pub fn atomic_umax<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_umax_acq<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_umax_rel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_umax_acqrel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_umax_relaxed<T>(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
|
|
|
|
/// if supported; otherwise, it is a noop.
|
|
|
|
/// 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
|
|
|
|
/// ranging from (0) - no locality, to (3) - extremely local keep in cache
|
|
|
|
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
|
|
|
|
/// if supported; otherwise, it is a noop.
|
|
|
|
/// 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
|
|
|
|
/// ranging from (0) - no locality, to (3) - extremely local keep in cache
|
|
|
|
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
|
|
|
|
/// if supported; otherwise, it is a noop.
|
|
|
|
/// 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
|
|
|
|
/// ranging from (0) - no locality, to (3) - extremely local keep in cache
|
|
|
|
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
|
|
|
|
/// if supported; otherwise, it is a noop.
|
|
|
|
/// 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
|
|
|
|
/// ranging from (0) - no locality, to (3) - extremely local keep in cache
|
|
|
|
pub fn prefetch_write_instruction<T>(data: *const T, locality: i32);
|
2014-02-17 01:37:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "rust-intrinsic" {
|
2014-01-15 15:32:44 -08:00
|
|
|
|
|
|
|
pub fn atomic_fence();
|
|
|
|
pub fn atomic_fence_acq();
|
|
|
|
pub fn atomic_fence_rel();
|
|
|
|
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.
|
2015-02-14 23:48:10 -07:00
|
|
|
pub fn atomic_singlethreadfence();
|
|
|
|
pub fn atomic_singlethreadfence_acq();
|
|
|
|
pub fn atomic_singlethreadfence_rel();
|
|
|
|
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.
|
|
|
|
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
|
|
|
///
|
|
|
|
/// The stabilized version of this intrinsic is
|
|
|
|
/// [`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
|
|
|
///
|
2017-08-09 00:47:38 +02:00
|
|
|
/// NB: This is very different from the `unreachable!()` macro: Unlike the
|
|
|
|
/// 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).
|
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.
|
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.
|
|
|
|
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.
|
|
|
|
pub fn unlikely(b: bool) -> bool;
|
|
|
|
|
2015-04-13 10:21:32 -04:00
|
|
|
/// Executes a breakpoint trap, for inspection by a debugger.
|
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.
|
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.
|
|
|
|
pub fn move_val_init<T>(dst: *mut T, src: T);
|
|
|
|
|
2015-02-18 14:43:43 +01:00
|
|
|
pub fn min_align_of<T>() -> usize;
|
|
|
|
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).
|
2015-04-15 11:57:29 +12:00
|
|
|
pub fn size_of_val<T: ?Sized>(_: &T) -> usize;
|
|
|
|
pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize;
|
2015-07-21 14:11:50 -07:00
|
|
|
|
2015-03-15 04:01:57 +02:00
|
|
|
/// Gets a static string slice containing the name of a type.
|
|
|
|
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.
|
2015-01-14 16:08:07 -08:00
|
|
|
pub fn type_id<T: ?Sized + 'static>() -> u64;
|
|
|
|
|
2015-04-13 10:21:32 -04:00
|
|
|
/// Creates a value initialized to zero.
|
2013-05-16 00:04:24 -07:00
|
|
|
///
|
|
|
|
/// `init` is unsafe because it returns a zeroed-out datum,
|
2015-02-10 10:04:39 +01:00
|
|
|
/// which is unsafe unless T is `Copy`. Also, even if T is
|
|
|
|
/// `Copy`, an all-zero value may not correspond to any legitimate
|
|
|
|
/// state for the type in question.
|
2013-08-02 14:30:00 -07:00
|
|
|
pub fn init<T>() -> T;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
2015-04-13 10:21:32 -04:00
|
|
|
/// Creates an uninitialized value.
|
2015-02-10 10:04:39 +01:00
|
|
|
///
|
|
|
|
/// `uninit` is unsafe because there is no guarantee of what its
|
|
|
|
/// contents are. In particular its drop-flag may be set to any
|
|
|
|
/// state, which means it may claim either dropped or
|
|
|
|
/// undropped. In the general case one must use `ptr::write` to
|
|
|
|
/// initialize memory previous set to the result of `uninit`.
|
2013-08-02 14:30:00 -07:00
|
|
|
pub fn uninit<T>() -> T;
|
2013-05-09 22:23:38 +12: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.
|
|
|
|
///
|
|
|
|
/// Getting the bitpattern of a floating point type (or, more generally,
|
2016-07-21 12:57:42 -07:00
|
|
|
/// type punning, when `T` and `U` aren't pointers):
|
2016-07-10 06:13:34 +02:00
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// let bitpattern = unsafe {
|
|
|
|
/// std::mem::transmute::<f32, u32>(1.0)
|
|
|
|
/// };
|
|
|
|
/// assert_eq!(bitpattern, 0x3F800000);
|
|
|
|
/// ```
|
|
|
|
///
|
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
|
|
|
///
|
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];
|
2016-07-05 23:54:34 -07:00
|
|
|
/// let mut v_orig = store.iter().collect::<Vec<&i32>>();
|
2016-09-08 20:04:05 -07:00
|
|
|
///
|
2016-07-05 15:15:33 -07:00
|
|
|
/// // Using transmute: this is Undefined Behavior, and a bad idea.
|
|
|
|
/// // However, it is no-copy.
|
2016-07-05 23:54:34 -07:00
|
|
|
/// let v_transmuted = unsafe {
|
|
|
|
/// std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(
|
|
|
|
/// v_orig.clone())
|
|
|
|
/// };
|
2016-09-08 20:04:05 -07:00
|
|
|
///
|
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.
|
2016-07-05 10:40:59 -07:00
|
|
|
/// let v_collected = v_orig.clone()
|
|
|
|
/// .into_iter()
|
|
|
|
/// .map(|r| Some(r))
|
|
|
|
/// .collect::<Vec<Option<&i32>>>();
|
2016-09-08 20:04:05 -07:00
|
|
|
///
|
2016-07-05 15:15:33 -07:00
|
|
|
/// // The no-copy, unsafe way, still using transmute, but not UB.
|
2016-07-05 10:40:59 -07:00
|
|
|
/// // This is equivalent to the original, but safer, and reuses the
|
|
|
|
/// // same Vec internals. Therefore the new inner type must have the
|
2017-09-13 01:27:41 -07:00
|
|
|
/// // exact same size, and the same alignment, as the old type.
|
|
|
|
/// // 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
|
2016-07-05 15:42:48 -07:00
|
|
|
/// // (`Option<&i32>`), so read the nomicon pages linked above.
|
2016-07-05 23:54:34 -07:00
|
|
|
/// let v_from_raw = unsafe {
|
2017-09-13 01:27:41 -07:00
|
|
|
/// Vec::from_raw_parts(v_orig.as_mut_ptr() as *mut Option<&i32>,
|
2016-07-05 23:54:34 -07:00
|
|
|
/// v_orig.len(),
|
|
|
|
/// v_orig.capacity())
|
|
|
|
/// };
|
|
|
|
/// std::mem::forget(v_orig);
|
2016-07-05 10:40:59 -07:00
|
|
|
/// ```
|
2016-07-02 08:45:01 -07:00
|
|
|
///
|
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
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
/// // There are multiple ways to do this; and there are multiple problems
|
2016-07-05 15:15:33 -07:00
|
|
|
/// // 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);
|
2016-07-05 10:40:59 -07:00
|
|
|
/// // first: transmute is not typesafe; all it checks is that T and
|
|
|
|
/// // 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
|
|
|
///
|
2016-07-05 10:40:59 -07:00
|
|
|
/// // This gets rid of the typesafety 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),
|
|
|
|
/// slice::from_raw_parts_mut(ptr.offset(mid as isize), 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")]
|
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
|
|
|
|
/// `Copy`, then may return `true` or `false`.
|
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).
|
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.
|
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.
|
|
|
|
pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
|
|
|
|
|
2018-05-17 13:19:41 -04:00
|
|
|
/// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
|
|
|
|
/// and destination may *not* overlap.
|
2014-07-09 22:24:23 -07:00
|
|
|
///
|
2018-05-17 13:19:41 -04:00
|
|
|
/// `copy_nonoverlapping` is semantically equivalent to C's `memcpy`.
|
2014-07-09 22:24:23 -07:00
|
|
|
///
|
2014-12-08 20:12:35 -05:00
|
|
|
/// # Safety
|
|
|
|
///
|
2018-05-17 13:19:41 -04:00
|
|
|
/// Beyond requiring that the program must be allowed to access both regions
|
|
|
|
/// of memory, it is Undefined Behavior for source and destination to
|
|
|
|
/// overlap. Care must also be taken with the ownership of `src` and
|
|
|
|
/// `dst`. This method semantically moves the values of `src` into `dst`.
|
|
|
|
/// However it does not drop the contents of `dst`, or prevent the contents
|
|
|
|
/// of `src` from being dropped or used.
|
2014-12-08 20:12:35 -05:00
|
|
|
///
|
|
|
|
/// # Examples
|
2014-07-09 22:24:23 -07:00
|
|
|
///
|
2018-05-17 13:19:41 -04:00
|
|
|
/// A safe swap function:
|
2014-07-09 22:24:23 -07:00
|
|
|
///
|
|
|
|
/// ```
|
2018-05-17 13:19:41 -04:00
|
|
|
/// use std::mem;
|
2014-07-09 22:24:23 -07:00
|
|
|
/// use std::ptr;
|
|
|
|
///
|
2018-05-17 13:19:41 -04:00
|
|
|
/// # #[allow(dead_code)]
|
|
|
|
/// fn swap<T>(x: &mut T, y: &mut T) {
|
2014-07-09 22:24:23 -07:00
|
|
|
/// unsafe {
|
2018-05-17 13:19:41 -04:00
|
|
|
/// // Give ourselves some scratch space to work with
|
|
|
|
/// let mut t: T = mem::uninitialized();
|
2014-07-09 22:24:23 -07:00
|
|
|
///
|
2018-05-17 13:19:41 -04:00
|
|
|
/// // Perform the swap, `&mut` pointers never alias
|
|
|
|
/// ptr::copy_nonoverlapping(x, &mut t, 1);
|
|
|
|
/// ptr::copy_nonoverlapping(y, x, 1);
|
|
|
|
/// ptr::copy_nonoverlapping(&t, y, 1);
|
2014-07-09 22:24:23 -07:00
|
|
|
///
|
2018-05-17 13:19:41 -04:00
|
|
|
/// // y and t now point to the same thing, but we need to completely forget `t`
|
|
|
|
/// // because it's no longer relevant.
|
|
|
|
/// mem::forget(t);
|
2014-07-09 22:24:23 -07:00
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
2015-02-23 11:39:16 -08:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-03-27 11:12:28 -07:00
|
|
|
pub fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
|
|
|
|
|
2018-05-17 13:19:41 -04:00
|
|
|
/// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
|
2014-07-09 22:24:23 -07:00
|
|
|
/// and destination may overlap.
|
|
|
|
///
|
2018-05-17 13:19:41 -04:00
|
|
|
/// `copy` is semantically equivalent to C's `memmove`.
|
2014-07-09 22:24:23 -07:00
|
|
|
///
|
2014-12-08 20:12:35 -05:00
|
|
|
/// # Safety
|
|
|
|
///
|
2018-05-17 13:19:41 -04:00
|
|
|
/// Care must be taken with the ownership of `src` and `dst`.
|
|
|
|
/// This method semantically moves the values of `src` into `dst`.
|
|
|
|
/// However it does not drop the contents of `dst`, or prevent the contents of `src`
|
|
|
|
/// from being dropped or used.
|
2014-12-08 20:12:35 -05:00
|
|
|
///
|
|
|
|
/// # Examples
|
2014-07-09 22:24:23 -07:00
|
|
|
///
|
|
|
|
/// Efficiently create a Rust vector from an unsafe buffer:
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// use std::ptr;
|
|
|
|
///
|
2015-11-03 15:27:03 +00:00
|
|
|
/// # #[allow(dead_code)]
|
2015-03-25 17:06:52 -07:00
|
|
|
/// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
|
2014-07-09 22:24:23 -07:00
|
|
|
/// let mut dst = Vec::with_capacity(elts);
|
|
|
|
/// dst.set_len(elts);
|
2015-03-27 11:12:28 -07:00
|
|
|
/// ptr::copy(ptr, dst.as_mut_ptr(), elts);
|
2014-07-09 22:24:23 -07:00
|
|
|
/// dst
|
|
|
|
/// }
|
|
|
|
/// ```
|
2018-05-17 13:19:41 -04:00
|
|
|
///
|
2015-03-18 19:51:10 -07:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-03-27 11:12:28 -07:00
|
|
|
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
|
|
|
|
|
2018-05-17 13:19:41 -04:00
|
|
|
/// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
|
|
|
|
/// bytes of memory starting at `dst` to `val`.
|
2016-09-26 23:11:47 -04:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// use std::ptr;
|
|
|
|
///
|
|
|
|
/// let mut vec = vec![0; 4];
|
|
|
|
/// unsafe {
|
|
|
|
/// let vec_ptr = vec.as_mut_ptr();
|
|
|
|
/// ptr::write_bytes(vec_ptr, b'a', 2);
|
|
|
|
/// }
|
|
|
|
/// assert_eq!(vec, [b'a', b'a', 0, 0]);
|
|
|
|
/// ```
|
2015-03-18 19:51:10 -07:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
|
|
|
|
|
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.
|
2014-06-25 12:47:34 -07:00
|
|
|
pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T,
|
2015-02-18 14:43:43 +01:00
|
|
|
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
|
|
|
|
/// unless size is equal to zero..
|
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.
|
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
|
|
|
|
|
|
|
/// Perform a volatile load from the `src` pointer.
|
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;
|
2014-04-22 19:51:14 -04:00
|
|
|
/// Perform a volatile store to the `dst` pointer.
|
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);
|
|
|
|
|
2018-07-14 23:28:39 +01:00
|
|
|
/// Perform a volatile load from the `src` pointer
|
|
|
|
/// The pointer is not required to be aligned.
|
|
|
|
pub fn unaligned_volatile_load<T>(src: *const T) -> T;
|
|
|
|
/// Perform a volatile store to the `dst` pointer.
|
|
|
|
/// The pointer is not required to be aligned.
|
|
|
|
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`
|
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`
|
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.
|
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.
|
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`.
|
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`.
|
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`.
|
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`.
|
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.
|
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.
|
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`.
|
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`.
|
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`.
|
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`.
|
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`.
|
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`.
|
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`.
|
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`.
|
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`.
|
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`.
|
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.
|
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.
|
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`.
|
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`.
|
2013-02-20 17:57:15 +01:00
|
|
|
pub fn fabsf64(x: f64) -> f64;
|
2013-02-20 20:41:24 +01:00
|
|
|
|
2014-05-23 07:09:11 +02:00
|
|
|
/// Copies the sign from `y` to `x` for `f32` values.
|
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.
|
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`.
|
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`.
|
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`.
|
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`.
|
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`.
|
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`.
|
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`.
|
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`.
|
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.
|
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.
|
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.
|
|
|
|
pub fn fadd_fast<T>(a: T, b: T) -> T;
|
|
|
|
|
|
|
|
/// Float subtraction that allows optimizations based on algebraic rules.
|
|
|
|
/// May assume inputs are finite.
|
|
|
|
pub fn fsub_fast<T>(a: T, b: T) -> T;
|
|
|
|
|
|
|
|
/// Float multiplication that allows optimizations based on algebraic rules.
|
|
|
|
/// May assume inputs are finite.
|
|
|
|
pub fn fmul_fast<T>(a: T, b: T) -> T;
|
|
|
|
|
|
|
|
/// Float division that allows optimizations based on algebraic rules.
|
|
|
|
/// May assume inputs are finite.
|
|
|
|
pub fn fdiv_fast<T>(a: T, b: T) -> T;
|
|
|
|
|
|
|
|
/// Float remainder that allows optimizations based on algebraic rules.
|
|
|
|
/// May assume inputs are finite.
|
|
|
|
pub fn frem_fast<T>(a: T, b: T) -> T;
|
|
|
|
|
|
|
|
|
2015-10-25 20:51:51 -07:00
|
|
|
/// Returns the number of bits set in an integer type `T`
|
|
|
|
pub fn ctpop<T>(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`.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// #![feature(core_intrinsics)]
|
|
|
|
///
|
|
|
|
/// use std::intrinsics::ctlz;
|
|
|
|
///
|
|
|
|
/// let x = 0b0001_1100_u8;
|
|
|
|
/// let num_leading = unsafe { ctlz(x) };
|
|
|
|
/// 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;
|
|
|
|
/// let num_leading = unsafe { ctlz(x) };
|
|
|
|
/// assert_eq!(num_leading, 16);
|
|
|
|
/// ```
|
2015-10-25 20:51:51 -07:00
|
|
|
pub fn ctlz<T>(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`.
|
|
|
|
///
|
|
|
|
/// # 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);
|
|
|
|
/// ```
|
|
|
|
pub fn ctlz_nonzero<T>(x: T) -> T;
|
|
|
|
|
2016-12-11 13:36:03 -08:00
|
|
|
/// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// #![feature(core_intrinsics)]
|
|
|
|
///
|
|
|
|
/// use std::intrinsics::cttz;
|
|
|
|
///
|
|
|
|
/// let x = 0b0011_1000_u8;
|
|
|
|
/// let num_trailing = unsafe { cttz(x) };
|
|
|
|
/// 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;
|
|
|
|
/// let num_trailing = unsafe { cttz(x) };
|
|
|
|
/// assert_eq!(num_trailing, 16);
|
|
|
|
/// ```
|
2015-10-25 20:51:51 -07:00
|
|
|
pub fn cttz<T>(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`.
|
|
|
|
///
|
|
|
|
/// # 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);
|
|
|
|
/// ```
|
|
|
|
pub fn cttz_nonzero<T>(x: T) -> T;
|
|
|
|
|
2015-10-25 20:51:51 -07:00
|
|
|
/// Reverses the bytes in an integer type `T`.
|
|
|
|
pub fn bswap<T>(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`.
|
|
|
|
pub fn bitreverse<T>(x: T) -> T;
|
|
|
|
|
2015-10-25 20:51:51 -07:00
|
|
|
/// Performs checked integer addition.
|
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)
|
2015-10-25 20:51:51 -07:00
|
|
|
pub fn add_with_overflow<T>(x: T, y: T) -> (T, bool);
|
|
|
|
|
|
|
|
/// Performs checked integer subtraction
|
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)
|
2015-10-25 20:51:51 -07:00
|
|
|
pub fn sub_with_overflow<T>(x: T, y: T) -> (T, bool);
|
|
|
|
|
|
|
|
/// Performs checked integer multiplication
|
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)
|
2015-10-25 20:51:51 -07:00
|
|
|
pub fn mul_with_overflow<T>(x: T, y: T) -> (T, bool);
|
|
|
|
|
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
|
|
|
|
/// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`
|
|
|
|
pub fn exact_div<T>(x: T, y: T) -> T;
|
|
|
|
|
2015-10-25 20:51:51 -07:00
|
|
|
/// Performs an unchecked division, resulting in undefined behavior
|
|
|
|
/// where y = 0 or x = `T::min_value()` and y = -1
|
|
|
|
pub fn unchecked_div<T>(x: T, y: T) -> T;
|
|
|
|
/// Returns the remainder of an unchecked division, resulting in
|
|
|
|
/// undefined behavior where y = 0 or x = `T::min_value()` and y = -1
|
|
|
|
pub fn unchecked_rem<T>(x: T, y: T) -> T;
|
|
|
|
|
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.
|
|
|
|
pub fn unchecked_shl<T>(x: T, y: T) -> T;
|
|
|
|
/// Performs an unchecked right shift, resulting in undefined behavior when
|
|
|
|
/// y < 0 or y >= N, where N is the width of T in bits.
|
|
|
|
pub fn unchecked_shr<T>(x: T, y: T) -> T;
|
|
|
|
|
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.
|
2016-11-08 20:22:09 -05:00
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
/// primitives via the `wrapping_add` method. For example,
|
|
|
|
/// [`std::u32::wrapping_add`](../../std/primitive.u32.html#method.wrapping_add)
|
2015-01-06 00:56:30 -05:00
|
|
|
pub fn overflowing_add<T>(a: T, b: T) -> T;
|
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.
|
2016-11-08 20:22:09 -05:00
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
/// primitives via the `wrapping_sub` method. For example,
|
|
|
|
/// [`std::u32::wrapping_sub`](../../std/primitive.u32.html#method.wrapping_sub)
|
2015-01-06 00:56:30 -05:00
|
|
|
pub fn overflowing_sub<T>(a: T, b: T) -> T;
|
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.
|
2016-11-08 20:22:09 -05:00
|
|
|
/// The stabilized versions of this intrinsic are available on the integer
|
|
|
|
/// primitives via the `wrapping_mul` method. For example,
|
|
|
|
/// [`std::u32::wrapping_mul`](../../std/primitive.u32.html#method.wrapping_mul)
|
2015-01-06 00:56:30 -05:00
|
|
|
pub fn overflowing_mul<T>(a: T, b: T) -> T;
|
2015-01-11 12:58:20 +13: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.
|
|
|
|
pub fn discriminant_value<T>(v: &T) -> u64;
|
2015-07-20 13:27:38 -07:00
|
|
|
|
|
|
|
/// Rust's "try catch" construct which invokes the function pointer `f` with
|
2015-10-23 18:18:44 -07:00
|
|
|
/// the data pointer `data`.
|
|
|
|
///
|
|
|
|
/// The third pointer is a target-specific data pointer which is filled in
|
|
|
|
/// with the specifics of the exception that occurred. For examples on Unix
|
|
|
|
/// platforms this is a `*mut *mut T` which is filled in by the compiler and
|
|
|
|
/// on MSVC it's `*mut [usize; 2]`. For more information see the compiler's
|
|
|
|
/// source as well as std's catch implementation.
|
|
|
|
pub fn try(f: fn(*mut u8), data: *mut u8, local_ptr: *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);
|
2017-08-16 15:41:09 +02:00
|
|
|
}
|