Module std::intrinsics[][src]

🔬 This is a nightly-only experimental API. (core_intrinsics)

intrinsics are unlikely to ever be stabilized, instead they should be used through stabilized interfaces in the rest of the standard library

Expand description

Compiler intrinsics.

The corresponding definitions are in compiler/rustc_codegen_llvm/src/intrinsic.rs. The corresponding const implementations are in compiler/rustc_mir/src/interpret/intrinsics.rs

Const intrinsics

Note: any changes to the constness of intrinsics should be discussed with the language team. This includes changes in the stability of the constness.

In order to make an intrinsic usable at compile-time, one needs to copy the implementation from https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics.rs to compiler/rustc_mir/src/interpret/intrinsics.rs and add a #[rustc_const_unstable(feature = "foo", issue = "01234")] to the intrinsic.

If an intrinsic is supposed to be used from a const fn with a rustc_const_stable attribute, the intrinsic’s attribute must be rustc_const_stable, too. Such a change should not be done without T-lang consultation, because it bakes a feature into the language that cannot be replicated in user code without compiler support.

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].

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].

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.

Functions

Experimental

Aborts the execution of the process.

Experimental

Performs checked integer addition.

Experimental

Calculates the offset from a pointer, potentially wrapping.

Experimental

A guard for unsafe functions that cannot ever be executed if T is uninhabited: This will statically either panic, or do nothing.

Experimental

A guard for unsafe functions that cannot ever be executed if T has invalid bit patterns: This will statically either panic, or do nothing.

Experimental

A guard for unsafe functions that cannot ever be executed if T does not permit zero-initialization: This will statically either panic, or do nothing.

Experimental

Informs the optimizer that a condition is always true. If the condition is false, the behavior is undefined.

Experimental

Bitwise and with the current value, returning the previous value.

Experimental

Bitwise and with the current value, returning the previous value.

Experimental

Bitwise and with the current value, returning the previous value.

Experimental

Bitwise and with the current value, returning the previous value.

Experimental

Bitwise and with the current value, returning the previous value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

Stores a value if the current value is the same as the old value.

Experimental

An atomic fence.

Experimental

An atomic fence.

Experimental

An atomic fence.

Experimental

An atomic fence.

Experimental

Loads the current value of the pointer.

Experimental

Loads the current value of the pointer.

Experimental

Loads the current value of the pointer.

Experimental
Experimental

Maximum with the current value using a signed comparison.

Experimental

Maximum with the current value using a signed comparison.

Experimental

Maximum with the current value using a signed comparison.

Experimental

Maximum with the current value using a signed comparison.

Experimental

Maximum with the current value.

Experimental

Minimum with the current value using a signed comparison.

Experimental

Minimum with the current value using a signed comparison.

Experimental

Minimum with the current value using a signed comparison.

Experimental

Minimum with the current value using a signed comparison.

Experimental

Minimum with the current value using a signed comparison.

Experimental

Bitwise nand with the current value, returning the previous value.

Experimental

Bitwise nand with the current value, returning the previous value.

Experimental

Bitwise nand with the current value, returning the previous value.

Experimental

Bitwise nand with the current value, returning the previous value.

Experimental

Bitwise nand with the current value, returning the previous value.

Experimental

Bitwise or with the current value, returning the previous value.

Experimental

Bitwise or with the current value, returning the previous value.

Experimental

Bitwise or with the current value, returning the previous value.

Experimental

Bitwise or with the current value, returning the previous value.

Experimental

Bitwise or with the current value, returning the previous value.

Experimental

A compiler-only memory barrier.

Experimental

A compiler-only memory barrier.

Experimental

A compiler-only memory barrier.

Experimental

A compiler-only memory barrier.

Experimental

Stores the value at the specified memory location.

Experimental

Stores the value at the specified memory location.

Experimental

Stores the value at the specified memory location.

Experimental
Experimental

Maximum with the current value using an unsigned comparison.

Experimental

Maximum with the current value using an unsigned comparison.

Experimental

Maximum with the current value using an unsigned comparison.

Experimental

Maximum with the current value using an unsigned comparison.

Experimental

Maximum with the current value using an unsigned comparison.

Experimental

Minimum with the current value using an unsigned comparison.

Experimental

Minimum with the current value using an unsigned comparison.

Experimental

Minimum with the current value using an unsigned comparison.

Experimental

Minimum with the current value using an unsigned comparison.

Experimental

Minimum with the current value using an unsigned comparison.

Experimental

Adds to the current value, returning the previous value.

Experimental

Adds to the current value, returning the previous value.

Experimental

Adds to the current value, returning the previous value.

Experimental

Adds to the current value, returning the previous value.

Experimental

Adds to the current value, returning the previous value.

Experimental

Stores the value at the specified memory location, returning the old value.

Experimental

Stores the value at the specified memory location, returning the old value.

Experimental

Stores the value at the specified memory location, returning the old value.

Experimental

Stores the value at the specified memory location, returning the old value.

Experimental

Stores the value at the specified memory location, returning the old value.

Experimental

Bitwise xor with the current value, returning the previous value.

Experimental

Bitwise xor with the current value, returning the previous value.

Experimental

Bitwise xor with the current value, returning the previous value.

Experimental

Bitwise xor with the current value, returning the previous value.

Experimental

Bitwise xor with the current value, returning the previous value.

Experimental

Subtract from the current value, returning the previous value.

Experimental

Subtract from the current value, returning the previous value.

Experimental

Subtract from the current value, returning the previous value.

Experimental

Subtract from the current value, returning the previous value.

Experimental

Subtract from the current value, returning the previous value.

Experimental

Reverses the bits in an integer type T.

Experimental

Executes a breakpoint trap, for inspection by a debugger.

Experimental

Reverses the bytes in an integer type T.

Experimental

Gets a reference to a static Location indicating where it was called.

Experimental

Returns the smallest integer greater than or equal to an f32.

Experimental

Returns the smallest integer greater than or equal to an f64.

Experimental

Allocate at compile time. Should not be called at runtime.

Experimental

Copies the sign from y to x for f32 values.

Experimental

Copies the sign from y to x for f64 values.

Experimental

Returns the cosine of an f32.

Experimental

Returns the cosine of an f64.

Experimental

Returns the number of leading unset bits (zeroes) in an integer type T.

Experimental

Like ctlz, but extra-unsafe as it returns undef when given an x with value 0.

Experimental

Returns the number of bits set in an integer type T

Experimental

Returns the number of trailing unset bits (zeroes) in an integer type T.

Experimental

Like cttz, but extra-unsafe as it returns undef when given an x with value 0.

Experimental

Returns the value of the discriminant for the variant in ‘v’; if T has no discriminant, returns 0.

Experimental

Performs an exact division, resulting in undefined behavior where x % y != 0 or y == 0 or x == T::MIN && y == -1

Experimental

Returns 2 raised to the power of an f32.

Experimental

Returns 2 raised to the power of an f64.

Experimental

Returns the exponential of an f32.

Experimental

Returns the exponential of an f64.

Experimental

Returns the absolute value of an f32.

Experimental

Returns the absolute value of an f64.

Experimental

Float addition that allows optimizations based on algebraic rules. May assume inputs are finite.

Experimental

Float division that allows optimizations based on algebraic rules. May assume inputs are finite.

Experimental

Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range (https://github.com/rust-lang/rust/issues/10184)

Experimental

Returns the largest integer less than or equal to an f32.

Experimental

Returns the largest integer less than or equal to an f64.

Experimental

Returns a * b + c for f32 values.

Experimental

Returns a * b + c for f64 values.

Experimental

Float multiplication that allows optimizations based on algebraic rules. May assume inputs are finite.

Experimental

Moves a value out of scope without running drop glue.

Experimental

Float remainder that allows optimizations based on algebraic rules. May assume inputs are finite.

Experimental

Float subtraction that allows optimizations based on algebraic rules. May assume inputs are finite.

Experimental

Hints to the compiler that branch condition is likely to be true. Returns the value passed to it.

Experimental

Returns the base 2 logarithm of an f32.

Experimental

Returns the base 2 logarithm of an f64.

Experimental

Returns the base 10 logarithm of an f32.

Experimental

Returns the base 10 logarithm of an f64.

Experimental

Returns the natural logarithm of an f32.

Experimental

Returns the natural logarithm of an f64.

Experimental

Returns the maximum of two f32 values.

Experimental

Returns the maximum of two f64 values.

Experimental

The minimum alignment of a type.

Experimental

The required alignment of the referenced value.

Experimental

Returns the minimum of two f32 values.

Experimental

Returns the minimum of two f64 values.

Experimental

Performs checked integer multiplication

Experimental

Returns the nearest integer to an f32.

Experimental

Returns the nearest integer to an f64.

Experimental

Returns true if the actual type given as T requires drop glue; returns false if the actual type provided for T implements Copy.

Experimental

Emits a !nontemporal store according to LLVM (see their docs). Probably will never become stable.

Experimental

Calculates the offset from a pointer.

Experimental

Raises an f32 to an f32 power.

Experimental

Raises an f64 to an f64 power.

Experimental

Raises an f32 to an integer power.

Experimental

Raises an f64 to an integer power.

Experimental

The preferred alignment of a type.

Experimental

The prefetch intrinsic is a hint to the code generator to insert a prefetch instruction if supported; otherwise, it is a no-op. Prefetches have no effect on the behavior of the program but can change its performance characteristics.

Experimental

The prefetch intrinsic is a hint to the code generator to insert a prefetch instruction if supported; otherwise, it is a no-op. Prefetches have no effect on the behavior of the program but can change its performance characteristics.

Experimental

The prefetch intrinsic is a hint to the code generator to insert a prefetch instruction if supported; otherwise, it is a no-op. Prefetches have no effect on the behavior of the program but can change its performance characteristics.

Experimental

The prefetch intrinsic is a hint to the code generator to insert a prefetch instruction if supported; otherwise, it is a no-op. Prefetches have no effect on the behavior of the program but can change its performance characteristics.

Experimental

See documentation of <*const T>::guaranteed_eq for details.

Experimental

See documentation of <*const T>::guaranteed_ne for details.

Experimental

See documentation of <*const T>::offset_from for details.

Experimental

Returns the nearest integer to an f32. May raise an inexact floating-point exception if the argument is not an integer.

Experimental

Returns the nearest integer to an f64. May raise an inexact floating-point exception if the argument is not an integer.

Experimental

Performs rotate left.

Experimental

Performs rotate right.

Experimental

Returns the nearest integer to an f32. Rounds half-way cases away from zero.

Experimental

Returns the nearest integer to an f64. Rounds half-way cases away from zero.

Experimental

Magic intrinsic that derives its meaning from attributes attached to the function.

Experimental

Computes a + b, saturating at numeric bounds.

Experimental

Computes a - b, saturating at numeric bounds.

Experimental

Returns the sine of an f32.

Experimental

Returns the sine of an f64.

Experimental

The size of a type in bytes.

Experimental

The size of the referenced value in bytes.

Experimental

Returns the square root of an f32

Experimental

Returns the square root of an f64

Experimental

Performs checked integer subtraction

Experimental

Returns the integer part of an f32.

Experimental

Returns the integer part of an f64.

Experimental

Rust’s “try catch” construct which invokes the function pointer try_fn with the data pointer data.

Experimental

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.

Experimental

Gets a static string slice containing the name of a type.

Experimental

Performs a volatile load from the src pointer The pointer is not required to be aligned.

Experimental

Performs a volatile store to the dst pointer. The pointer is not required to be aligned.

Experimental

Returns the result of an unchecked addition, resulting in undefined behavior when x + y > T::MAX or x + y < T::MIN.

Experimental

Performs an unchecked division, resulting in undefined behavior where y == 0 or x == T::MIN && y == -1

Experimental

Returns the result of an unchecked multiplication, resulting in undefined behavior when x * y > T::MAX or x * y < T::MIN.

Experimental

Returns the remainder of an unchecked division, resulting in undefined behavior when y == 0 or x == T::MIN && y == -1

Experimental

Performs an unchecked left shift, resulting in undefined behavior when y < 0 or y >= N, where N is the width of T in bits.

Experimental

Performs an unchecked right shift, resulting in undefined behavior when y < 0 or y >= N, where N is the width of T in bits.

Experimental

Returns the result of an unchecked subtraction, resulting in undefined behavior when x - y > T::MAX or x - y < T::MIN.

Experimental

Hints to the compiler that branch condition is likely to be false. Returns the value passed to it.

Experimental

Informs the optimizer that this point in the code is not reachable, enabling further optimizations.

Experimental

Returns the number of variants of the type T cast to a usize; if T has no variants, returns 0. Uninhabited variants will be counted.

Experimental

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>()

Experimental

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>()

Experimental

Performs a volatile load from the src pointer.

Experimental

Equivalent to the appropriate llvm.memset.p0i8.* intrinsic, with a size of count * size_of::<T>() and an alignment of min_align_of::<T>().

Experimental

Performs a volatile store to the dst pointer.

Experimental

Returns (a + b) mod 2N, where N is the width of T in bits.

Experimental

Returns (a * b) mod 2N, where N is the width of T in bits.

Experimental

Returns (a - b) mod 2N, where N is the width of T in bits.

Copies count * size_of::<T>() bytes from src to dst. The source and destination may overlap.

Copies count * size_of::<T>() bytes from src to dst. The source and destination must not overlap.

Deprecated

Reinterprets the bits of a value of one type as another type.

Sets count * size_of::<T>() bytes of memory starting at dst to val.