2013-02-20 10:57:15 -06: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 20:17:11 -06:00
|
|
|
//! rustc compiler intrinsics.
|
|
|
|
//!
|
2014-12-02 13:43:47 -06:00
|
|
|
//! The corresponding definitions are in librustc_trans/trans/intrinsic.rs.
|
2014-11-25 20:17:11 -06: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 17:05:27 -05:00
|
|
|
|
2015-01-22 20:22:03 -06:00
|
|
|
#![unstable(feature = "core")]
|
2014-10-27 17:37:07 -05:00
|
|
|
#![allow(missing_docs)]
|
2014-02-16 01:49:08 -06:00
|
|
|
|
2015-01-06 15:59:07 -06:00
|
|
|
use marker::Sized;
|
|
|
|
|
2015-03-18 21:51:10 -05:00
|
|
|
#[cfg(stage0)] pub use self::copy_memory as copy;
|
|
|
|
#[cfg(stage0)] pub use self::set_memory as write_bytes;
|
|
|
|
#[cfg(stage0)] pub use self::copy_nonoverlapping_memory as copy_nonoverlapping;
|
|
|
|
|
2014-02-17 03:37:26 -06:00
|
|
|
extern "rust-intrinsic" {
|
|
|
|
|
2014-02-24 20:20:52 -06:00
|
|
|
// NB: These intrinsics take unsafe pointers because they mutate aliased
|
|
|
|
// memory, which is not valid for either `&` or `&mut`.
|
|
|
|
|
|
|
|
pub fn atomic_cxchg<T>(dst: *mut T, old: T, src: T) -> T;
|
|
|
|
pub fn atomic_cxchg_acq<T>(dst: *mut T, old: T, src: T) -> T;
|
|
|
|
pub fn atomic_cxchg_rel<T>(dst: *mut T, old: T, src: T) -> T;
|
|
|
|
pub fn atomic_cxchg_acqrel<T>(dst: *mut T, old: T, src: T) -> T;
|
|
|
|
pub fn atomic_cxchg_relaxed<T>(dst: *mut T, old: T, src: T) -> T;
|
|
|
|
|
2014-06-25 14:47:34 -05:00
|
|
|
pub fn atomic_load<T>(src: *const T) -> T;
|
|
|
|
pub fn atomic_load_acq<T>(src: *const T) -> T;
|
|
|
|
pub fn atomic_load_relaxed<T>(src: *const T) -> T;
|
2014-12-14 03:44:24 -06:00
|
|
|
pub fn atomic_load_unordered<T>(src: *const T) -> T;
|
2014-02-24 20:20:52 -06:00
|
|
|
|
|
|
|
pub fn atomic_store<T>(dst: *mut T, val: T);
|
|
|
|
pub fn atomic_store_rel<T>(dst: *mut T, val: T);
|
|
|
|
pub fn atomic_store_relaxed<T>(dst: *mut T, val: T);
|
2014-12-14 03:44:24 -06:00
|
|
|
pub fn atomic_store_unordered<T>(dst: *mut T, val: T);
|
2014-02-24 20:20:52 -06:00
|
|
|
|
|
|
|
pub fn atomic_xchg<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xchg_acq<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xchg_rel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xchg_acqrel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xchg_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
|
|
|
pub fn atomic_xadd<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xadd_acq<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xadd_rel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xadd_acqrel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xadd_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
|
|
|
pub fn atomic_xsub<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xsub_acq<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xsub_rel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xsub_acqrel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xsub_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
|
|
|
pub fn atomic_and<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_and_acq<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_and_rel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_and_acqrel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_and_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
|
|
|
pub fn atomic_nand<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_nand_acq<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_nand_rel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_nand_acqrel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_nand_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
|
|
|
pub fn atomic_or<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_or_acq<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_or_rel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_or_acqrel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_or_relaxed<T>(dst: *mut T, src: T) -> T;
|
|
|
|
|
|
|
|
pub fn atomic_xor<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xor_acq<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xor_rel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
pub fn atomic_xor_acqrel<T>(dst: *mut T, src: T) -> T;
|
|
|
|
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;
|
2014-02-17 03:37:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "rust-intrinsic" {
|
2014-01-15 17:32:44 -06:00
|
|
|
|
|
|
|
pub fn atomic_fence();
|
|
|
|
pub fn atomic_fence_acq();
|
|
|
|
pub fn atomic_fence_rel();
|
|
|
|
pub fn atomic_fence_acqrel();
|
|
|
|
|
|
|
|
/// Abort the execution of the process.
|
|
|
|
pub fn abort() -> !;
|
|
|
|
|
2014-09-03 14:00:08 -05:00
|
|
|
/// Tell LLVM that this point in the code is not reachable,
|
|
|
|
/// enabling further optimizations.
|
|
|
|
///
|
|
|
|
/// NB: This is very different from the `unreachable!()` macro!
|
|
|
|
pub fn unreachable() -> !;
|
|
|
|
|
2014-10-15 18:44:44 -05:00
|
|
|
/// Inform the optimizer that a condition is always true.
|
|
|
|
/// If the condition is false, the behavior is undefined.
|
|
|
|
///
|
2014-10-16 07:20:54 -05: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-15 18:44:44 -05:00
|
|
|
pub fn assume(b: bool);
|
|
|
|
|
2014-01-15 17:32:44 -06:00
|
|
|
/// Execute a breakpoint trap, for inspection by a debugger.
|
|
|
|
pub fn breakpoint();
|
|
|
|
|
2013-05-16 02:04:24 -05:00
|
|
|
/// The size of a type in bytes.
|
|
|
|
///
|
|
|
|
/// This is the exact number of bytes in memory taken up by a
|
|
|
|
/// value of the given type. In other words, a memset of this size
|
|
|
|
/// would *exactly* overwrite a value. When laid out in vectors
|
|
|
|
/// and structures there may be additional padding between
|
|
|
|
/// elements.
|
2015-02-18 07:43:43 -06:00
|
|
|
pub fn size_of<T>() -> usize;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2013-05-16 02:04:24 -05:00
|
|
|
/// Move a value to an uninitialized memory location.
|
|
|
|
///
|
|
|
|
/// Drop glue is not run on the destination.
|
2013-05-07 16:20:56 -05:00
|
|
|
pub fn move_val_init<T>(dst: &mut T, src: T);
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2015-02-18 07:43:43 -06:00
|
|
|
pub fn min_align_of<T>() -> usize;
|
|
|
|
pub fn pref_align_of<T>() -> usize;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2015-03-14 21:01:57 -05:00
|
|
|
/// Gets a static string slice containing the name of a type.
|
2015-03-18 11:36:18 -05:00
|
|
|
#[cfg(not(stage0))]
|
2015-03-14 21:01:57 -05:00
|
|
|
pub fn type_name<T: ?Sized>() -> &'static str;
|
|
|
|
|
2013-10-30 18:32:33 -05: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 18:08:07 -06:00
|
|
|
pub fn type_id<T: ?Sized + 'static>() -> u64;
|
|
|
|
|
2013-05-16 02:04:24 -05:00
|
|
|
/// Create a value initialized to zero.
|
|
|
|
///
|
|
|
|
/// `init` is unsafe because it returns a zeroed-out datum,
|
2014-03-26 18:01:11 -05:00
|
|
|
/// which is unsafe unless T is Copy.
|
2013-08-02 16:30:00 -05:00
|
|
|
pub fn init<T>() -> T;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2013-05-16 02:04:24 -05:00
|
|
|
/// Create an uninitialized value.
|
2013-08-02 16:30:00 -05:00
|
|
|
pub fn uninit<T>() -> T;
|
2013-05-09 05:23:38 -05:00
|
|
|
|
2013-05-16 02:04:24 -05:00
|
|
|
/// Move a value out of scope without running drop glue.
|
|
|
|
///
|
|
|
|
/// `forget` is unsafe because the caller is responsible for
|
|
|
|
/// ensuring the argument is deallocated already.
|
2015-01-23 23:48:20 -06:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2013-08-02 16:30:00 -05:00
|
|
|
pub fn forget<T>(_: T) -> ();
|
2014-06-12 16:08:44 -05:00
|
|
|
|
|
|
|
/// Unsafely transforms a value of one type into a value of another type.
|
|
|
|
///
|
2015-02-09 20:51:30 -06:00
|
|
|
/// Both types must have the same size.
|
2014-06-12 16:08:44 -05:00
|
|
|
///
|
2014-12-08 19:12:35 -06:00
|
|
|
/// # Examples
|
2014-06-12 16:08:44 -05:00
|
|
|
///
|
2015-02-09 20:51:30 -06:00
|
|
|
/// ```
|
2014-06-12 16:08:44 -05:00
|
|
|
/// use std::mem;
|
|
|
|
///
|
|
|
|
/// let v: &[u8] = unsafe { mem::transmute("L") };
|
2015-03-03 02:42:26 -06:00
|
|
|
/// assert!(v == [76]);
|
2014-06-12 16:08:44 -05:00
|
|
|
/// ```
|
2015-01-23 23:48:20 -06:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2013-05-09 14:49:14 -05:00
|
|
|
pub fn transmute<T,U>(e: T) -> U;
|
2013-02-20 10:57:15 -06:00
|
|
|
|
2014-08-05 16:38:14 -05:00
|
|
|
/// Gives the address for the return value of the enclosing function.
|
|
|
|
///
|
2014-09-02 00:35:58 -05:00
|
|
|
/// Using this intrinsic in a function that does not use an out pointer
|
2014-08-05 16:38:14 -05:00
|
|
|
/// will trigger a compiler error.
|
|
|
|
pub fn return_address() -> *const u8;
|
|
|
|
|
2015-02-26 07:35:08 -06: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`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn needs_drop<T>() -> bool;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2013-06-29 21:36:27 -05:00
|
|
|
/// Returns `true` if a type is managed (will be allocated on the local heap)
|
2013-11-05 13:50:33 -06:00
|
|
|
pub fn owns_managed<T>() -> bool;
|
|
|
|
|
2013-08-06 16:44:40 -05:00
|
|
|
/// Calculates the offset from a pointer. The offset *must* be in-bounds of
|
|
|
|
/// the object, or one-byte-past-the-end. An arithmetic overflow is also
|
|
|
|
/// undefined behaviour.
|
|
|
|
///
|
2013-08-09 00:22:52 -05:00
|
|
|
/// This is implemented as an intrinsic to avoid converting to and from an
|
|
|
|
/// integer, since the conversion would throw away aliasing information.
|
2015-02-18 07:43:43 -06:00
|
|
|
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
|
2013-08-06 16:44:40 -05:00
|
|
|
|
2014-12-08 19:12:35 -06:00
|
|
|
/// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
|
2014-07-10 00:24:23 -05:00
|
|
|
/// and destination may *not* overlap.
|
|
|
|
///
|
2015-03-18 21:51:10 -05:00
|
|
|
/// `copy_nonoverlapping` is semantically equivalent to C's `memcpy`.
|
2014-07-10 00:24:23 -05:00
|
|
|
///
|
2014-12-08 19:12:35 -06:00
|
|
|
/// # Safety
|
|
|
|
///
|
2015-02-10 20:58:11 -06:00
|
|
|
/// Beyond requiring that the program must be allowed to access both regions
|
|
|
|
/// of memory, it is Undefined Behaviour 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 19:12:35 -06:00
|
|
|
///
|
|
|
|
/// # Examples
|
2014-07-10 00:24:23 -05:00
|
|
|
///
|
|
|
|
/// A safe swap function:
|
|
|
|
///
|
|
|
|
/// ```
|
2015-03-13 17:28:35 -05:00
|
|
|
/// # #![feature(core)]
|
2014-07-10 00:24:23 -05:00
|
|
|
/// use std::mem;
|
|
|
|
/// use std::ptr;
|
|
|
|
///
|
|
|
|
/// fn swap<T>(x: &mut T, y: &mut T) {
|
|
|
|
/// unsafe {
|
|
|
|
/// // Give ourselves some scratch space to work with
|
|
|
|
/// let mut t: T = mem::uninitialized();
|
|
|
|
///
|
|
|
|
/// // Perform the swap, `&mut` pointers never alias
|
2015-03-18 21:51:10 -05:00
|
|
|
/// ptr::copy_nonoverlapping(&mut t, &*x, 1);
|
|
|
|
/// ptr::copy_nonoverlapping(x, &*y, 1);
|
|
|
|
/// ptr::copy_nonoverlapping(y, &t, 1);
|
2014-07-10 00:24:23 -05:00
|
|
|
///
|
|
|
|
/// // y and t now point to the same thing, but we need to completely forget `tmp`
|
|
|
|
/// // because it's no longer relevant.
|
|
|
|
/// mem::forget(t);
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
2015-02-23 13:39:16 -06:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-03-18 21:51:10 -05:00
|
|
|
#[cfg(not(stage0))]
|
|
|
|
pub fn copy_nonoverlapping<T>(dst: *mut T, src: *const T, count: usize);
|
|
|
|
|
|
|
|
/// dox
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
#[cfg(stage0)]
|
2015-02-18 07:43:43 -06:00
|
|
|
pub fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
|
2013-11-03 15:54:58 -06:00
|
|
|
|
2014-12-08 19:12:35 -06:00
|
|
|
/// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
|
2014-07-10 00:24:23 -05:00
|
|
|
/// and destination may overlap.
|
|
|
|
///
|
2015-03-18 21:51:10 -05:00
|
|
|
/// `copy` is semantically equivalent to C's `memmove`.
|
2014-07-10 00:24:23 -05:00
|
|
|
///
|
2014-12-08 19:12:35 -06:00
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// 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.
|
|
|
|
///
|
|
|
|
/// # Examples
|
2014-07-10 00:24:23 -05:00
|
|
|
///
|
|
|
|
/// Efficiently create a Rust vector from an unsafe buffer:
|
|
|
|
///
|
|
|
|
/// ```
|
2015-03-13 17:28:35 -05:00
|
|
|
/// # #![feature(core)]
|
2014-07-10 00:24:23 -05:00
|
|
|
/// use std::ptr;
|
|
|
|
///
|
|
|
|
/// unsafe fn from_buf_raw<T>(ptr: *const T, elts: uint) -> Vec<T> {
|
|
|
|
/// let mut dst = Vec::with_capacity(elts);
|
|
|
|
/// dst.set_len(elts);
|
2015-03-18 21:51:10 -05:00
|
|
|
/// ptr::copy(dst.as_mut_ptr(), ptr, elts);
|
2014-07-10 00:24:23 -05:00
|
|
|
/// dst
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
2015-03-18 21:51:10 -05:00
|
|
|
#[cfg(not(stage0))]
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
pub fn copy<T>(dst: *mut T, src: *const T, count: usize);
|
|
|
|
|
|
|
|
/// dox
|
|
|
|
#[cfg(stage0)]
|
2015-02-23 13:39:16 -06:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-02-18 07:43:43 -06:00
|
|
|
pub fn copy_memory<T>(dst: *mut T, src: *const T, count: usize);
|
2013-11-03 15:54:58 -06:00
|
|
|
|
2014-07-10 00:24:23 -05:00
|
|
|
/// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
|
|
|
|
/// bytes of memory starting at `dst` to `c`.
|
2015-03-18 21:51:10 -05:00
|
|
|
#[cfg(not(stage0))]
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
|
|
|
|
|
|
|
|
/// dox
|
|
|
|
#[cfg(stage0)]
|
2015-02-23 13:39:16 -06:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2015-02-18 07:43:43 -06:00
|
|
|
pub fn set_memory<T>(dst: *mut T, val: u8, count: usize);
|
2013-11-03 15:54:58 -06:00
|
|
|
|
2014-04-22 18:51:14 -05: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>()`
|
|
|
|
///
|
|
|
|
/// The volatile parameter parameter is set to `true`, so it will not be optimized out.
|
2014-06-25 14:47:34 -05:00
|
|
|
pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T,
|
2015-02-18 07:43:43 -06:00
|
|
|
count: usize);
|
2014-04-22 18:51:14 -05: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>()`
|
|
|
|
///
|
|
|
|
/// The volatile parameter parameter is set to `true`, so it will not be optimized out.
|
2015-02-18 07:43:43 -06:00
|
|
|
pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
|
2014-04-22 18:51:14 -05: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>()`.
|
|
|
|
///
|
|
|
|
/// The volatile parameter parameter is set to `true`, so it will not be optimized out.
|
2015-02-18 07:43:43 -06:00
|
|
|
pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
|
2014-04-22 18:51:14 -05:00
|
|
|
|
|
|
|
/// Perform a volatile load from the `src` pointer.
|
2014-06-25 14:47:34 -05:00
|
|
|
pub fn volatile_load<T>(src: *const T) -> T;
|
2014-04-22 18:51:14 -05:00
|
|
|
/// Perform a volatile store to the `dst` pointer.
|
|
|
|
pub fn volatile_store<T>(dst: *mut T, val: T);
|
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the square root of an `f32`
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn sqrtf32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the square root of an `f64`
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn sqrtf64(x: f64) -> f64;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Raises an `f32` to an integer power.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn powif32(a: f32, x: i32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Raises an `f64` to an integer power.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn powif64(a: f64, x: i32) -> f64;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the sine of an `f32`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn sinf32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the sine of an `f64`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn sinf64(x: f64) -> f64;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the cosine of an `f32`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn cosf32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the cosine of an `f64`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn cosf64(x: f64) -> f64;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Raises an `f32` to an `f32` power.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn powf32(a: f32, x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Raises an `f64` to an `f64` power.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn powf64(a: f64, x: f64) -> f64;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the exponential of an `f32`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn expf32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the exponential of an `f64`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn expf64(x: f64) -> f64;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns 2 raised to the power of an `f32`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn exp2f32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns 2 raised to the power of an `f64`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn exp2f64(x: f64) -> f64;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the natural logarithm of an `f32`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn logf32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the natural logarithm of an `f64`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn logf64(x: f64) -> f64;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the base 10 logarithm of an `f32`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn log10f32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the base 10 logarithm of an `f64`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn log10f64(x: f64) -> f64;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the base 2 logarithm of an `f32`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn log2f32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the base 2 logarithm of an `f64`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn log2f64(x: f64) -> f64;
|
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns `a * b + c` for `f32` values.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns `a * b + c` for `f64` values.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the absolute value of an `f32`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn fabsf32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the absolute value of an `f64`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn fabsf64(x: f64) -> f64;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Copies the sign from `y` to `x` for `f32` values.
|
2013-10-21 13:09:42 -05:00
|
|
|
pub fn copysignf32(x: f32, y: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Copies the sign from `y` to `x` for `f64` values.
|
2013-10-21 13:09:42 -05:00
|
|
|
pub fn copysignf64(x: f64, y: f64) -> f64;
|
2013-10-21 01:21:39 -05:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the largest integer less than or equal to an `f32`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn floorf32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the largest integer less than or equal to an `f64`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn floorf64(x: f64) -> f64;
|
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the smallest integer greater than or equal to an `f32`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn ceilf32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the smallest integer greater than or equal to an `f64`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn ceilf64(x: f64) -> f64;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the integer part of an `f32`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn truncf32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the integer part of an `f64`.
|
2013-02-20 10:57:15 -06:00
|
|
|
pub fn truncf64(x: f64) -> f64;
|
2013-02-20 13:41:24 -06:00
|
|
|
|
2014-05-23 00:09:11 -05: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 01:21:39 -05:00
|
|
|
pub fn rintf32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05: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 01:21:39 -05:00
|
|
|
pub fn rintf64(x: f64) -> f64;
|
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the nearest integer to an `f32`.
|
2013-10-21 01:21:39 -05:00
|
|
|
pub fn nearbyintf32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the nearest integer to an `f64`.
|
2013-10-21 01:21:39 -05:00
|
|
|
pub fn nearbyintf64(x: f64) -> f64;
|
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
|
2013-10-21 01:21:39 -05:00
|
|
|
pub fn roundf32(x: f32) -> f32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
|
2013-10-21 01:21:39 -05:00
|
|
|
pub fn roundf64(x: f64) -> f64;
|
2014-04-16 10:06:44 -05:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the number of bits set in a `u8`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn ctpop8(x: u8) -> u8;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the number of bits set in a `u16`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn ctpop16(x: u16) -> u16;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the number of bits set in a `u32`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn ctpop32(x: u32) -> u32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the number of bits set in a `u64`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn ctpop64(x: u64) -> u64;
|
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the number of leading bits unset in a `u8`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn ctlz8(x: u8) -> u8;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the number of leading bits unset in a `u16`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn ctlz16(x: u16) -> u16;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the number of leading bits unset in a `u32`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn ctlz32(x: u32) -> u32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the number of leading bits unset in a `u64`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn ctlz64(x: u64) -> u64;
|
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the number of trailing bits unset in a `u8`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn cttz8(x: u8) -> u8;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the number of trailing bits unset in a `u16`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn cttz16(x: u16) -> u16;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the number of trailing bits unset in a `u32`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn cttz32(x: u32) -> u32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Returns the number of trailing bits unset in a `u64`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn cttz64(x: u64) -> u64;
|
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Reverses the bytes in a `u16`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn bswap16(x: u16) -> u16;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Reverses the bytes in a `u32`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn bswap32(x: u32) -> u32;
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Reverses the bytes in a `u64`.
|
2014-04-14 05:04:14 -05:00
|
|
|
pub fn bswap64(x: u64) -> u64;
|
2013-10-21 01:21:39 -05:00
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `i8` addition.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn i8_add_with_overflow(x: i8, y: i8) -> (i8, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `i16` addition.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn i16_add_with_overflow(x: i16, y: i16) -> (i16, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `i32` addition.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn i32_add_with_overflow(x: i32, y: i32) -> (i32, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `i64` addition.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn i64_add_with_overflow(x: i64, y: i64) -> (i64, bool);
|
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `u8` addition.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn u8_add_with_overflow(x: u8, y: u8) -> (u8, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `u16` addition.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn u16_add_with_overflow(x: u16, y: u16) -> (u16, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `u32` addition.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn u32_add_with_overflow(x: u32, y: u32) -> (u32, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `u64` addition.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn u64_add_with_overflow(x: u64, y: u64) -> (u64, bool);
|
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `i8` subtraction.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn i8_sub_with_overflow(x: i8, y: i8) -> (i8, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `i16` subtraction.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn i16_sub_with_overflow(x: i16, y: i16) -> (i16, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `i32` subtraction.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn i32_sub_with_overflow(x: i32, y: i32) -> (i32, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `i64` subtraction.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn i64_sub_with_overflow(x: i64, y: i64) -> (i64, bool);
|
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `u8` subtraction.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn u8_sub_with_overflow(x: u8, y: u8) -> (u8, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `u16` subtraction.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn u16_sub_with_overflow(x: u16, y: u16) -> (u16, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `u32` subtraction.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn u32_sub_with_overflow(x: u32, y: u32) -> (u32, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `u64` subtraction.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn u64_sub_with_overflow(x: u64, y: u64) -> (u64, bool);
|
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `i8` multiplication.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn i8_mul_with_overflow(x: i8, y: i8) -> (i8, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `i16` multiplication.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn i16_mul_with_overflow(x: i16, y: i16) -> (i16, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `i32` multiplication.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn i32_mul_with_overflow(x: i32, y: i32) -> (i32, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `i64` multiplication.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn i64_mul_with_overflow(x: i64, y: i64) -> (i64, bool);
|
|
|
|
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `u8` multiplication.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn u8_mul_with_overflow(x: u8, y: u8) -> (u8, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `u16` multiplication.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn u16_mul_with_overflow(x: u16, y: u16) -> (u16, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `u32` multiplication.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn u32_mul_with_overflow(x: u32, y: u32) -> (u32, bool);
|
2014-05-23 00:09:11 -05:00
|
|
|
/// Performs checked `u64` multiplication.
|
2013-08-07 14:40:09 -05:00
|
|
|
pub fn u64_mul_with_overflow(x: u64, y: u64) -> (u64, bool);
|
2015-01-05 23:56:30 -06:00
|
|
|
|
|
|
|
/// Returns (a + b) mod 2^N, where N is the width of N in bits.
|
|
|
|
pub fn overflowing_add<T>(a: T, b: T) -> T;
|
|
|
|
/// Returns (a - b) mod 2^N, where N is the width of N in bits.
|
|
|
|
pub fn overflowing_sub<T>(a: T, b: T) -> T;
|
|
|
|
/// Returns (a * b) mod 2^N, where N is the width of N in bits.
|
|
|
|
pub fn overflowing_mul<T>(a: T, b: T) -> T;
|
|
|
|
}
|