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§
- Atomic
Ordering Experimental - A type for atomic ordering parameters for intrinsics. This is a separate type from
atomic::Ordering
so that we can make itConstParamTy
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.
- abort
Experimental - Aborts the execution of the process.
- aggregate_
raw_ ptr Experimental - Lowers in MIR to
Rvalue::Aggregate
withAggregateKind::RawPtr
. - align_
of Experimental - 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 asT
if that is an integer type, orusize
ifT
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 asT
if that is an integer type, orusize
ifT
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 asT
if that is an integer type, orusize
ifT
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 asT
if that is an integer type, orusize
ifT
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 asT
if that is an integer type, orusize
ifT
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 asT
if that is an integer type, orusize
ifT
is a pointer type. - autodiff
Experimental - Generates the LLVM body for the automatic differentiation of
f
using Enzyme, withdf
as the derivative function andargs
as its arguments. - const_
eval_ select Experimental - Selects which function to call depending on the context.
- const_
make_ âšglobal Experimental - ctpop
Experimental - Returns the number of bits set in an integer type
T
- discriminant_
value Experimental - Returns the value of the discriminant for the variant in ‘v’;
if
T
has no discriminant, returns0
. - ptr_
guaranteed_ cmp Experimental - See documentation of
<*const T>::guaranteed_eq
for details. Returns2
if the result is unknown. Returns1
if the pointers are guaranteed equal. Returns0
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_of
Experimental - The size of a type in bytes.
- three_
way_ compare Experimental - Does a three-way comparison between the two arguments, which must be of character or integer (signed or unsigned) type.
- ub_
checks Experimental - Returns whether we should perform some UB-checking at runtime. This eventually evaluates to
cfg!(ub_checks)
, but behaves different fromcfg!
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
orx - 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.