Module std::intrinsics
source · core_intrinsics
)Expand description
Compiler intrinsics.
The corresponding definitions are in https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/intrinsic.rs. The corresponding const implementations are in https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/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
https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs and add a
#[rustc_const_unstable(feature = "const_such_and_such", issue = "01234")]
to the intrinsic declaration.
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
.
Modules
- mirExperimentalRustc internal tooling for hand-writing MIR.
Functions
- abortExperimentalAborts the execution of the process.
- add_with_overflowExperimentalPerforms checked integer addition.
- arith_offset⚠ExperimentalCalculates the offset from a pointer, potentially wrapping.
- assert_inhabitedExperimentalA guard for unsafe functions that cannot ever be executed if
T
is uninhabited: This will statically either panic, or do nothing. - assert_mem_uninitialized_validExperimentalA guard for
std::mem::uninitialized
. This will statically either panic, or do nothing. - assert_zero_validExperimentalA guard for unsafe functions that cannot ever be executed if
T
does not permit zero-initialization: This will statically either panic, or do nothing. - assume⚠ExperimentalInforms the optimizer that a condition is always true. If the condition is false, the behavior is undefined.
- atomic_and_acqrel⚠ExperimentalBitwise and with the current value, returning the previous value.
- atomic_and_acquire⚠ExperimentalBitwise and with the current value, returning the previous value.
- atomic_and_relaxed⚠ExperimentalBitwise and with the current value, returning the previous value.
- atomic_and_release⚠ExperimentalBitwise and with the current value, returning the previous value.
- atomic_and_seqcst⚠ExperimentalBitwise and with the current value, returning the previous value.
- atomic_cxchg_acqrel_acquire⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchg_acqrel_relaxed⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchg_acqrel_seqcst⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchg_acquire_acquire⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchg_acquire_relaxed⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchg_acquire_seqcst⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchg_relaxed_acquire⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchg_relaxed_relaxed⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchg_relaxed_seqcst⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchg_release_acquire⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchg_release_relaxed⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchg_release_seqcst⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchg_seqcst_acquire⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchg_seqcst_relaxed⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchg_seqcst_seqcst⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_acqrel_acquire⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_acqrel_relaxed⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_acqrel_seqcst⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_acquire_acquire⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_acquire_relaxed⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_acquire_seqcst⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_relaxed_acquire⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_relaxed_relaxed⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_relaxed_seqcst⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_release_acquire⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_release_relaxed⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_release_seqcst⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_seqcst_acquire⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_seqcst_relaxed⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_cxchgweak_seqcst_seqcst⚠ExperimentalStores a value if the current value is the same as the
old
value. - atomic_fence_acqrel⚠ExperimentalAn atomic fence.
- atomic_fence_acquire⚠ExperimentalAn atomic fence.
- atomic_fence_release⚠ExperimentalAn atomic fence.
- atomic_fence_seqcst⚠ExperimentalAn atomic fence.
- atomic_load_acquire⚠ExperimentalLoads the current value of the pointer.
- atomic_load_relaxed⚠ExperimentalLoads the current value of the pointer.
- atomic_load_seqcst⚠ExperimentalLoads the current value of the pointer.
- atomic_load_unordered⚠Experimental
- atomic_max_acqrel⚠ExperimentalMaximum with the current value using a signed comparison.
- atomic_max_acquire⚠ExperimentalMaximum with the current value using a signed comparison.
- atomic_max_relaxed⚠ExperimentalMaximum with the current value.
- atomic_max_release⚠ExperimentalMaximum with the current value using a signed comparison.
- atomic_max_seqcst⚠ExperimentalMaximum with the current value using a signed comparison.
- atomic_min_acqrel⚠ExperimentalMinimum with the current value using a signed comparison.
- atomic_min_acquire⚠ExperimentalMinimum with the current value using a signed comparison.
- atomic_min_relaxed⚠ExperimentalMinimum with the current value using a signed comparison.
- atomic_min_release⚠ExperimentalMinimum with the current value using a signed comparison.
- atomic_min_seqcst⚠ExperimentalMinimum with the current value using a signed comparison.
- atomic_nand_acqrel⚠ExperimentalBitwise nand with the current value, returning the previous value.
- atomic_nand_acquire⚠ExperimentalBitwise nand with the current value, returning the previous value.
- atomic_nand_relaxed⚠ExperimentalBitwise nand with the current value, returning the previous value.
- atomic_nand_release⚠ExperimentalBitwise nand with the current value, returning the previous value.
- atomic_nand_seqcst⚠ExperimentalBitwise nand with the current value, returning the previous value.
- atomic_or_acqrel⚠ExperimentalBitwise or with the current value, returning the previous value.
- atomic_or_acquire⚠ExperimentalBitwise or with the current value, returning the previous value.
- atomic_or_relaxed⚠ExperimentalBitwise or with the current value, returning the previous value.
- atomic_or_release⚠ExperimentalBitwise or with the current value, returning the previous value.
- atomic_or_seqcst⚠ExperimentalBitwise or with the current value, returning the previous value.
- atomic_singlethreadfence_acqrel⚠ExperimentalA compiler-only memory barrier.
- atomic_singlethreadfence_acquire⚠ExperimentalA compiler-only memory barrier.
- atomic_singlethreadfence_release⚠ExperimentalA compiler-only memory barrier.
- atomic_singlethreadfence_seqcst⚠ExperimentalA compiler-only memory barrier.
- atomic_store_relaxed⚠ExperimentalStores the value at the specified memory location.
- atomic_store_release⚠ExperimentalStores the value at the specified memory location.
- atomic_store_seqcst⚠ExperimentalStores the value at the specified memory location.
- atomic_store_unordered⚠Experimental
- atomic_umax_acqrel⚠ExperimentalMaximum with the current value using an unsigned comparison.
- atomic_umax_acquire⚠ExperimentalMaximum with the current value using an unsigned comparison.
- atomic_umax_relaxed⚠ExperimentalMaximum with the current value using an unsigned comparison.
- atomic_umax_release⚠ExperimentalMaximum with the current value using an unsigned comparison.
- atomic_umax_seqcst⚠ExperimentalMaximum with the current value using an unsigned comparison.
- atomic_umin_acqrel⚠ExperimentalMinimum with the current value using an unsigned comparison.
- atomic_umin_acquire⚠ExperimentalMinimum with the current value using an unsigned comparison.
- atomic_umin_relaxed⚠ExperimentalMinimum with the current value using an unsigned comparison.
- atomic_umin_release⚠ExperimentalMinimum with the current value using an unsigned comparison.
- atomic_umin_seqcst⚠ExperimentalMinimum with the current value using an unsigned comparison.
- atomic_xadd_acqrel⚠ExperimentalAdds to the current value, returning the previous value.
- atomic_xadd_acquire⚠ExperimentalAdds to the current value, returning the previous value.
- atomic_xadd_relaxed⚠ExperimentalAdds to the current value, returning the previous value.
- atomic_xadd_release⚠ExperimentalAdds to the current value, returning the previous value.
- atomic_xadd_seqcst⚠ExperimentalAdds to the current value, returning the previous value.
- atomic_xchg_acqrel⚠ExperimentalStores the value at the specified memory location, returning the old value.
- atomic_xchg_acquire⚠ExperimentalStores the value at the specified memory location, returning the old value.
- atomic_xchg_relaxed⚠ExperimentalStores the value at the specified memory location, returning the old value.
- atomic_xchg_release⚠ExperimentalStores the value at the specified memory location, returning the old value.
- atomic_xchg_seqcst⚠ExperimentalStores the value at the specified memory location, returning the old value.
- atomic_xor_acqrel⚠ExperimentalBitwise xor with the current value, returning the previous value.
- atomic_xor_acquire⚠ExperimentalBitwise xor with the current value, returning the previous value.
- atomic_xor_relaxed⚠ExperimentalBitwise xor with the current value, returning the previous value.
- atomic_xor_release⚠ExperimentalBitwise xor with the current value, returning the previous value.
- atomic_xor_seqcst⚠ExperimentalBitwise xor with the current value, returning the previous value.
- atomic_xsub_acqrel⚠ExperimentalSubtract from the current value, returning the previous value.
- atomic_xsub_acquire⚠ExperimentalSubtract from the current value, returning the previous value.
- atomic_xsub_relaxed⚠ExperimentalSubtract from the current value, returning the previous value.
- atomic_xsub_release⚠ExperimentalSubtract from the current value, returning the previous value.
- atomic_xsub_seqcst⚠ExperimentalSubtract from the current value, returning the previous value.
- bitreverseExperimentalReverses the bits in an integer type
T
. - black_boxExperimentalSee documentation of
std::hint::black_box
for details. - breakpoint⚠ExperimentalExecutes a breakpoint trap, for inspection by a debugger.
- bswapExperimentalReverses the bytes in an integer type
T
. - caller_locationExperimentalGets a reference to a static
Location
indicating where it was called. - ceilf32⚠ExperimentalReturns the smallest integer greater than or equal to an
f32
. - ceilf64⚠ExperimentalReturns the smallest integer greater than or equal to an
f64
. - const_allocate⚠ExperimentalAllocates a block of memory at compile time. At runtime, just returns a null pointer.
- const_deallocate⚠ExperimentalDeallocates a memory which allocated by
intrinsics::const_allocate
at compile time. At runtime, does nothing. - const_eval_select⚠ExperimentalSelects which function to call depending on the context.
- copysignf32⚠ExperimentalCopies the sign from
y
tox
forf32
values. - copysignf64⚠ExperimentalCopies the sign from
y
tox
forf64
values. - cosf32⚠ExperimentalReturns the cosine of an
f32
. - cosf64⚠ExperimentalReturns the cosine of an
f64
. - ctlzExperimentalReturns the number of leading unset bits (zeroes) in an integer type
T
. - ctlz_nonzero⚠ExperimentalLike
ctlz
, but extra-unsafe as it returnsundef
when given anx
with value0
. - ctpopExperimentalReturns the number of bits set in an integer type
T
- cttzExperimentalReturns the number of trailing unset bits (zeroes) in an integer type
T
. - cttz_nonzero⚠ExperimentalLike
cttz
, but extra-unsafe as it returnsundef
when given anx
with value0
. - discriminant_valueExperimentalReturns the value of the discriminant for the variant in ‘v’; if
T
has no discriminant, returns0
. - exact_div⚠ExperimentalPerforms an exact division, resulting in undefined behavior where
x % y != 0
ory == 0
orx == T::MIN && y == -1
- exp2f32⚠ExperimentalReturns 2 raised to the power of an
f32
. - exp2f64⚠ExperimentalReturns 2 raised to the power of an
f64
. - expf32⚠ExperimentalReturns the exponential of an
f32
. - expf64⚠ExperimentalReturns the exponential of an
f64
. - fabsf32⚠ExperimentalReturns the absolute value of an
f32
. - fabsf64⚠ExperimentalReturns the absolute value of an
f64
. - fadd_fast⚠ExperimentalFloat addition that allows optimizations based on algebraic rules. May assume inputs are finite.
- fdiv_fast⚠ExperimentalFloat division that allows optimizations based on algebraic rules. May assume inputs are finite.
- float_to_int_unchecked⚠ExperimentalConvert with LLVM’s fptoui/fptosi, which may return undef for values out of range (https://github.com/rust-lang/rust/issues/10184)
- floorf32⚠ExperimentalReturns the largest integer less than or equal to an
f32
. - floorf64⚠ExperimentalReturns the largest integer less than or equal to an
f64
. - fmaf32⚠ExperimentalReturns
a * b + c
forf32
values. - fmaf64⚠ExperimentalReturns
a * b + c
forf64
values. - fmul_fast⚠ExperimentalFloat multiplication that allows optimizations based on algebraic rules. May assume inputs are finite.
- forgetExperimentalMoves a value out of scope without running drop glue.
- frem_fast⚠ExperimentalFloat remainder that allows optimizations based on algebraic rules. May assume inputs are finite.
- fsub_fast⚠ExperimentalFloat subtraction that allows optimizations based on algebraic rules. May assume inputs are finite.
- likelyExperimentalHints to the compiler that branch condition is likely to be true. Returns the value passed to it.
- log2f32⚠ExperimentalReturns the base 2 logarithm of an
f32
. - log2f64⚠ExperimentalReturns the base 2 logarithm of an
f64
. - log10f32⚠ExperimentalReturns the base 10 logarithm of an
f32
. - log10f64⚠ExperimentalReturns the base 10 logarithm of an
f64
. - logf32⚠ExperimentalReturns the natural logarithm of an
f32
. - logf64⚠ExperimentalReturns the natural logarithm of an
f64
. - maxnumf32ExperimentalReturns the maximum of two
f32
values. - maxnumf64ExperimentalReturns the maximum of two
f64
values. - min_align_ofExperimentalThe minimum alignment of a type.
- min_align_of_val⚠ExperimentalThe required alignment of the referenced value.
- minnumf32ExperimentalReturns the minimum of two
f32
values. - minnumf64ExperimentalReturns the minimum of two
f64
values. - mul_with_overflowExperimentalPerforms checked integer multiplication
- nearbyintf32⚠ExperimentalReturns the nearest integer to an
f32
. - nearbyintf64⚠ExperimentalReturns the nearest integer to an
f64
. - needs_dropExperimentalReturns
true
if the actual type given asT
requires drop glue; returnsfalse
if the actual type provided forT
implementsCopy
. - nontemporal_store⚠ExperimentalEmits a
!nontemporal
store according to LLVM (see their docs). Probably will never become stable. - offset⚠ExperimentalCalculates the offset from a pointer.
- powf32⚠ExperimentalRaises an
f32
to anf32
power. - powf64⚠ExperimentalRaises an
f64
to anf64
power. - powif32⚠ExperimentalRaises an
f32
to an integer power. - powif64⚠ExperimentalRaises an
f64
to an integer power. - pref_align_of⚠ExperimentalThe preferred alignment of a type.
- prefetch_read_data⚠ExperimentalThe
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. - prefetch_read_instruction⚠ExperimentalThe
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. - prefetch_write_data⚠ExperimentalThe
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. - prefetch_write_instruction⚠ExperimentalThe
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. - ptr_guaranteed_cmpExperimentalSee 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 - ptr_maskExperimentalMasks out bits of the pointer according to a mask.
- ptr_offset_from⚠ExperimentalSee documentation of
<*const T>::offset_from
for details. - ptr_offset_from_unsigned⚠ExperimentalSee documentation of
<*const T>::sub_ptr
for details. - raw_eq⚠ExperimentalDetermines whether the raw bytes of the two values are equal.
- rintf32⚠ExperimentalReturns the nearest integer to an
f32
. May raise an inexact floating-point exception if the argument is not an integer. - rintf64⚠ExperimentalReturns the nearest integer to an
f64
. May raise an inexact floating-point exception if the argument is not an integer. - rotate_leftExperimentalPerforms rotate left.
- rotate_rightExperimentalPerforms rotate right.
- roundevenf32⚠ExperimentalReturns the nearest integer to an
f32
. Rounds half-way cases to the number with an even least significant digit. - roundevenf64⚠ExperimentalReturns the nearest integer to an
f64
. Rounds half-way cases to the number with an even least significant digit. - roundf32⚠ExperimentalReturns the nearest integer to an
f32
. Rounds half-way cases away from zero. - roundf64⚠ExperimentalReturns the nearest integer to an
f64
. Rounds half-way cases away from zero. - rustc_peekExperimentalMagic intrinsic that derives its meaning from attributes attached to the function.
- saturating_addExperimentalComputes
a + b
, saturating at numeric bounds. - saturating_subExperimentalComputes
a - b
, saturating at numeric bounds. - sinf32⚠ExperimentalReturns the sine of an
f32
. - sinf64⚠ExperimentalReturns the sine of an
f64
. - size_ofExperimentalThe size of a type in bytes.
- size_of_val⚠ExperimentalThe size of the referenced value in bytes.
- sqrtf32⚠ExperimentalReturns the square root of an
f32
- sqrtf64⚠ExperimentalReturns the square root of an
f64
- sub_with_overflowExperimentalPerforms checked integer subtraction
- truncf32⚠ExperimentalReturns the integer part of an
f32
. - truncf64⚠ExperimentalReturns the integer part of an
f64
. - try⚠ExperimentalRust’s “try catch” construct which invokes the function pointer
try_fn
with the data pointerdata
. - type_idExperimentalGets 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.
- type_nameExperimentalGets a static string slice containing the name of a type.
- unaligned_volatile_load⚠ExperimentalPerforms a volatile load from the
src
pointer The pointer is not required to be aligned. - unaligned_volatile_store⚠ExperimentalPerforms a volatile store to the
dst
pointer. The pointer is not required to be aligned. - unchecked_add⚠ExperimentalReturns the result of an unchecked addition, resulting in undefined behavior when
x + y > T::MAX
orx + y < T::MIN
. - unchecked_div⚠ExperimentalPerforms an unchecked division, resulting in undefined behavior where
y == 0
orx == T::MIN && y == -1
- unchecked_mul⚠ExperimentalReturns the result of an unchecked multiplication, resulting in undefined behavior when
x * y > T::MAX
orx * y < T::MIN
. - unchecked_rem⚠ExperimentalReturns the remainder of an unchecked division, resulting in undefined behavior when
y == 0
orx == T::MIN && y == -1
- unchecked_shl⚠ExperimentalPerforms an unchecked left shift, resulting in undefined behavior when
y < 0
ory >= N
, where N is the width of T in bits. - unchecked_shr⚠ExperimentalPerforms an unchecked right shift, resulting in undefined behavior when
y < 0
ory >= N
, where N is the width of T in bits. - unchecked_sub⚠ExperimentalReturns the result of an unchecked subtraction, resulting in undefined behavior when
x - y > T::MAX
orx - y < T::MIN
. - unlikelyExperimentalHints to the compiler that branch condition is likely to be false. Returns the value passed to it.
- unreachable⚠ExperimentalInforms the optimizer that this point in the code is not reachable, enabling further optimizations.
- variant_countExperimentalReturns the number of variants of the type
T
cast to ausize
; ifT
has no variants, returns0
. Uninhabited variants will be counted. - volatile_copy_memory⚠ExperimentalEquivalent to the appropriate
llvm.memmove.p0i8.0i8.*
intrinsic, with a size ofcount * size_of::<T>()
and an alignment ofmin_align_of::<T>()
- volatile_copy_nonoverlapping_memory⚠ExperimentalEquivalent to the appropriate
llvm.memcpy.p0i8.0i8.*
intrinsic, with a size ofcount
*size_of::<T>()
and an alignment ofmin_align_of::<T>()
- volatile_load⚠ExperimentalPerforms a volatile load from the
src
pointer. - volatile_set_memory⚠ExperimentalEquivalent to the appropriate
llvm.memset.p0i8.*
intrinsic, with a size ofcount * size_of::<T>()
and an alignment ofmin_align_of::<T>()
. - volatile_store⚠ExperimentalPerforms a volatile store to the
dst
pointer. - vtable_align⚠Experimental
ptr
must point to a vtable. The intrinsic will return the alignment stored in that vtable. - vtable_size⚠Experimental
ptr
must point to a vtable. The intrinsic will return the size stored in that vtable. - wrapping_addExperimentalReturns (a + b) mod 2N, where N is the width of T in bits.
- wrapping_mulExperimentalReturns (a * b) mod 2N, where N is the width of T in bits.
- wrapping_subExperimentalReturns (a - b) mod 2N, where N is the width of T in bits.
- copy⚠Copies
count * size_of::<T>()
bytes fromsrc
todst
. The source and destination may overlap. - Copies
count * size_of::<T>()
bytes fromsrc
todst
. The source and destination must not overlap. - drop_in_place⚠Deprecated
- Reinterprets the bits of a value of one type as another type.
- Sets
count * size_of::<T>()
bytes of memory starting atdst
toval
.