Module intrinsics

Module intrinsics 

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

Compiler intrinsics.

The functions in this module are implementation details of core and should not be used outside of the standard library. We generally provide access to intrinsics via stable wrapper functions. Use these instead.

These are the imports making intrinsics available to Rust code. The actual implementations live in the compiler. Some of these intrinsics are lowered to MIR in https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_transform/src/lower_intrinsics.rs. The remaining intrinsics are implemented for the LLVM backend in https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs and https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/intrinsic.rs, and for const evaluation in https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs.

§Const intrinsics

In order to make an intrinsic unstable usable at compile-time, copy the implementation from https://github.com/rust-lang/miri/blob/master/src/intrinsics to https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs and make the intrinsic declaration below a const fn. This should be done in coordination with wg-const-eval.

If an intrinsic is supposed to be used from a const fn with a rustc_const_stable attribute, #[rustc_intrinsic_const_stable_indirect] needs to be added to the intrinsic. Such a change requires T-lang approval, because it may bake 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 [read_volatile][ptr::read_volatile] and [write_volatile][ptr::write_volatile].

§Atomics

The atomic intrinsics provide common atomic operations on machine words, with multiple possible memory orderings. See the [atomic types][atomic] docs for details.

§Unwinding

Rust intrinsics may, in general, unwind. If an intrinsic can never unwind, add the #[rustc_nounwind] attribute so that the compiler can make use of this fact.

However, even for intrinsics that may unwind, rustc assumes that a Rust intrinsics will never initiate a foreign (non-Rust) unwind, and thus for panic=abort we can always assume that these intrinsics cannot unwind.

Enums§

AtomicOrderingExperimental
A type for atomic ordering parameters for intrinsics. This is a separate type from atomic::Ordering so that we can make it ConstParamTy and fix the values used here without a risk of leaking that to stable code.

Functions§

transmuteâš Deprecated
Reinterprets the bits of a value of one type as another type.
abortExperimental
Aborts the execution of the process.
aggregate_raw_ptrExperimental
Lowers in MIR to Rvalue::Aggregate with AggregateKind::RawPtr.
align_ofExperimental
The minimum alignment of a type.
atomic_andâš Experimental
Bitwise and with the current value, returning the previous value. T must be an integer or pointer type. U must be the same as T if that is an integer type, or usize if T is a pointer type.
atomic_cxchgâš Experimental
Stores a value if the current value is the same as the old value. T must be an integer or pointer type.
atomic_cxchgweakâš Experimental
Stores a value if the current value is the same as the old value. T must be an integer or pointer type. The comparison may spuriously fail.
atomic_loadâš Experimental
Loads the current value of the pointer. T must be an integer or pointer type.
atomic_nandâš Experimental
Bitwise nand with the current value, returning the previous value. T must be an integer or pointer type. U must be the same as T if that is an integer type, or usize if T is a pointer type.
atomic_orâš Experimental
Bitwise or with the current value, returning the previous value. T must be an integer or pointer type. U must be the same as T if that is an integer type, or usize if T is a pointer type.
atomic_storeâš Experimental
Stores the value at the specified memory location. T must be an integer or pointer type.
atomic_umaxâš Experimental
Maximum with the current value using an unsigned comparison. T must be an unsigned integer type.
atomic_uminâš Experimental
Minimum with the current value using an unsigned comparison. T must be an unsigned integer type.
atomic_xaddâš Experimental
Adds to the current value, returning the previous value. T must be an integer or pointer type. U must be the same as T if that is an integer type, or usize if T is a pointer type.
atomic_xchgâš Experimental
Stores the value at the specified memory location, returning the old value. T must be an integer or pointer type.
atomic_xorâš Experimental
Bitwise xor with the current value, returning the previous value. T must be an integer or pointer type. U must be the same as T if that is an integer type, or usize if T is a pointer type.
atomic_xsubâš Experimental
Subtract from the current value, returning the previous value. T must be an integer or pointer type. U must be the same as T if that is an integer type, or usize if T is a pointer type.
autodiffExperimental
Generates the LLVM body for the automatic differentiation of f using Enzyme, with df as the derivative function and args as its arguments.
const_eval_selectExperimental
Selects which function to call depending on the context.
const_make_globalâš Experimental
ctpopExperimental
Returns the number of bits set in an integer type T
discriminant_valueExperimental
Returns the value of the discriminant for the variant in ‘v’; if T has no discriminant, returns 0.
ptr_guaranteed_cmpExperimental
See documentation of <*const T>::guaranteed_eq for details. Returns 2 if the result is unknown. Returns 1 if the pointers are guaranteed equal. Returns 0 if the pointers are guaranteed inequal.
read_via_copyâš Experimental
This is an implementation detail of crate::ptr::read and should not be used anywhere else. See its comments for why this exists.
size_ofExperimental
The size of a type in bytes.
three_way_compareExperimental
Does a three-way comparison between the two arguments, which must be of character or integer (signed or unsigned) type.
ub_checksExperimental
Returns whether we should perform some UB-checking at runtime. This eventually evaluates to cfg!(ub_checks), but behaves different from cfg! when mixing crates built with different flags: if the crate has UB checks enabled or carries the #[rustc_preserve_ub_checks] attribute, evaluation is delayed until monomorphization (or until the call gets inlined into a crate that does not delay evaluation further); otherwise it can happen any time.
unchecked_subâš Experimental
Returns the result of an unchecked subtraction, resulting in undefined behavior when x - y > T::MAX or x - y < T::MIN.
unreachableâš Experimental
Informs the optimizer that this point in the code is not reachable, enabling further optimizations.
write_via_moveâš Experimental
This is an implementation detail of crate::ptr::write and should not be used anywhere else. See its comments for why this exists.