core/intrinsics/mod.rs
1//! Compiler intrinsics.
2//!
3//! The functions in this module are implementation details of `core` and should
4//! not be used outside of the standard library. We generally provide access to
5//! intrinsics via stable wrapper functions. Use these instead.
6//!
7//! These are the imports making intrinsics available to Rust code. The actual implementations live in the compiler.
8//! 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>.
9//! 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>
10//! and <https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/intrinsic.rs>,
11//! and for const evaluation in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs>.
12//!
13//! # Const intrinsics
14//!
15//! In order to make an intrinsic unstable usable at compile-time, copy the implementation from
16//! <https://github.com/rust-lang/miri/blob/master/src/intrinsics> to
17//! <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs>
18//! and make the intrinsic declaration below a `const fn`. This should be done in coordination with
19//! wg-const-eval.
20//!
21//! If an intrinsic is supposed to be used from a `const fn` with a `rustc_const_stable` attribute,
22//! `#[rustc_intrinsic_const_stable_indirect]` needs to be added to the intrinsic. Such a change requires
23//! T-lang approval, because it may bake a feature into the language that cannot be replicated in
24//! user code without compiler support.
25//!
26//! # Volatiles
27//!
28//! The volatile intrinsics provide operations intended to act on I/O
29//! memory, which are guaranteed to not be reordered by the compiler
30//! across other volatile intrinsics. See [`read_volatile`][ptr::read_volatile]
31//! and [`write_volatile`][ptr::write_volatile].
32//!
33//! # Atomics
34//!
35//! The atomic intrinsics provide common atomic operations on machine
36//! words, with multiple possible memory orderings. See the
37//! [atomic types][atomic] docs for details.
38//!
39//! # Unwinding
40//!
41//! Rust intrinsics may, in general, unwind. If an intrinsic can never unwind, add the
42//! `#[rustc_nounwind]` attribute so that the compiler can make use of this fact.
43//!
44//! However, even for intrinsics that may unwind, rustc assumes that a Rust intrinsics will never
45//! initiate a foreign (non-Rust) unwind, and thus for panic=abort we can always assume that these
46//! intrinsics cannot unwind.
47
48#![unstable(
49 feature = "core_intrinsics",
50 reason = "intrinsics are unlikely to ever be stabilized, instead \
51 they should be used through stabilized interfaces \
52 in the rest of the standard library",
53 issue = "none"
54)]
55#![allow(missing_docs)]
56
57#[cfg(not(feature = "ferrocene_certified"))]
58use crate::ffi::va_list::{VaArgSafe, VaListImpl};
59#[cfg(not(feature = "ferrocene_certified"))]
60use crate::marker::Destruct;
61use crate::marker::{ConstParamTy, DiscriminantKind, PointeeSized, Tuple};
62use crate::ptr;
63
64mod bounds;
65#[cfg(not(feature = "ferrocene_certified"))]
66pub mod fallback;
67#[cfg(not(feature = "ferrocene_certified"))]
68pub mod mir;
69#[cfg(not(feature = "ferrocene_certified"))]
70pub mod simd;
71
72// These imports are used for simplifying intra-doc links
73#[allow(unused_imports)]
74#[cfg(all(target_has_atomic = "8", target_has_atomic = "32", target_has_atomic = "ptr"))]
75#[cfg(not(feature = "ferrocene_certified"))]
76use crate::sync::atomic::{self, AtomicBool, AtomicI32, AtomicIsize, AtomicU32, Ordering};
77
78/// A type for atomic ordering parameters for intrinsics. This is a separate type from
79/// `atomic::Ordering` so that we can make it `ConstParamTy` and fix the values used here without a
80/// risk of leaking that to stable code.
81#[cfg_attr(not(feature = "ferrocene_certified"), derive(Debug, ConstParamTy, PartialEq, Eq))]
82#[cfg_attr(feature = "ferrocene_certified", derive(ConstParamTy, PartialEq, Eq))]
83pub enum AtomicOrdering {
84 // These values must match the compiler's `AtomicOrdering` defined in
85 // `rustc_middle/src/ty/consts/int.rs`!
86 Relaxed = 0,
87 Release = 1,
88 Acquire = 2,
89 AcqRel = 3,
90 SeqCst = 4,
91}
92
93// N.B., these intrinsics take raw pointers because they mutate aliased
94// memory, which is not valid for either `&` or `&mut`.
95
96/// Stores a value if the current value is the same as the `old` value.
97/// `T` must be an integer or pointer type.
98///
99/// The stabilized version of this intrinsic is available on the
100/// [`atomic`] types via the `compare_exchange` method.
101/// For example, [`AtomicBool::compare_exchange`].
102#[rustc_intrinsic]
103#[rustc_nounwind]
104pub unsafe fn atomic_cxchg<
105 T: Copy,
106 const ORD_SUCC: AtomicOrdering,
107 const ORD_FAIL: AtomicOrdering,
108>(
109 dst: *mut T,
110 old: T,
111 src: T,
112) -> (T, bool);
113
114/// Stores a value if the current value is the same as the `old` value.
115/// `T` must be an integer or pointer type. The comparison may spuriously fail.
116///
117/// The stabilized version of this intrinsic is available on the
118/// [`atomic`] types via the `compare_exchange_weak` method.
119/// For example, [`AtomicBool::compare_exchange_weak`].
120#[rustc_intrinsic]
121#[rustc_nounwind]
122pub unsafe fn atomic_cxchgweak<
123 T: Copy,
124 const ORD_SUCC: AtomicOrdering,
125 const ORD_FAIL: AtomicOrdering,
126>(
127 _dst: *mut T,
128 _old: T,
129 _src: T,
130) -> (T, bool);
131
132/// Loads the current value of the pointer.
133/// `T` must be an integer or pointer type.
134///
135/// The stabilized version of this intrinsic is available on the
136/// [`atomic`] types via the `load` method. For example, [`AtomicBool::load`].
137#[rustc_intrinsic]
138#[rustc_nounwind]
139pub unsafe fn atomic_load<T: Copy, const ORD: AtomicOrdering>(src: *const T) -> T;
140
141/// Stores the value at the specified memory location.
142/// `T` must be an integer or pointer type.
143///
144/// The stabilized version of this intrinsic is available on the
145/// [`atomic`] types via the `store` method. For example, [`AtomicBool::store`].
146#[rustc_intrinsic]
147#[rustc_nounwind]
148pub unsafe fn atomic_store<T: Copy, const ORD: AtomicOrdering>(dst: *mut T, val: T);
149
150/// Stores the value at the specified memory location, returning the old value.
151/// `T` must be an integer or pointer type.
152///
153/// The stabilized version of this intrinsic is available on the
154/// [`atomic`] types via the `swap` method. For example, [`AtomicBool::swap`].
155#[rustc_intrinsic]
156#[rustc_nounwind]
157pub unsafe fn atomic_xchg<T: Copy, const ORD: AtomicOrdering>(dst: *mut T, src: T) -> T;
158
159/// Adds to the current value, returning the previous value.
160/// `T` must be an integer or pointer type.
161/// `U` must be the same as `T` if that is an integer type, or `usize` if `T` is a pointer type.
162///
163/// The stabilized version of this intrinsic is available on the
164/// [`atomic`] types via the `fetch_add` method. For example, [`AtomicIsize::fetch_add`].
165#[rustc_intrinsic]
166#[rustc_nounwind]
167pub unsafe fn atomic_xadd<T: Copy, U: Copy, const ORD: AtomicOrdering>(dst: *mut T, src: U) -> T;
168
169/// Subtract from the current value, returning the previous value.
170/// `T` must be an integer or pointer type.
171/// `U` must be the same as `T` if that is an integer type, or `usize` if `T` is a pointer type.
172///
173/// The stabilized version of this intrinsic is available on the
174/// [`atomic`] types via the `fetch_sub` method. For example, [`AtomicIsize::fetch_sub`].
175#[rustc_intrinsic]
176#[rustc_nounwind]
177pub unsafe fn atomic_xsub<T: Copy, U: Copy, const ORD: AtomicOrdering>(dst: *mut T, src: U) -> T;
178
179/// Bitwise and with the current value, returning the previous value.
180/// `T` must be an integer or pointer type.
181/// `U` must be the same as `T` if that is an integer type, or `usize` if `T` is a pointer type.
182///
183/// The stabilized version of this intrinsic is available on the
184/// [`atomic`] types via the `fetch_and` method. For example, [`AtomicBool::fetch_and`].
185#[rustc_intrinsic]
186#[rustc_nounwind]
187pub unsafe fn atomic_and<T: Copy, U: Copy, const ORD: AtomicOrdering>(dst: *mut T, src: U) -> T;
188
189/// Bitwise nand with the current value, returning the previous value.
190/// `T` must be an integer or pointer type.
191/// `U` must be the same as `T` if that is an integer type, or `usize` if `T` is a pointer type.
192///
193/// The stabilized version of this intrinsic is available on the
194/// [`AtomicBool`] type via the `fetch_nand` method. For example, [`AtomicBool::fetch_nand`].
195#[rustc_intrinsic]
196#[rustc_nounwind]
197pub unsafe fn atomic_nand<T: Copy, U: Copy, const ORD: AtomicOrdering>(dst: *mut T, src: U) -> T;
198
199/// Bitwise or with the current value, returning the previous value.
200/// `T` must be an integer or pointer type.
201/// `U` must be the same as `T` if that is an integer type, or `usize` if `T` is a pointer type.
202///
203/// The stabilized version of this intrinsic is available on the
204/// [`atomic`] types via the `fetch_or` method. For example, [`AtomicBool::fetch_or`].
205#[rustc_intrinsic]
206#[rustc_nounwind]
207pub unsafe fn atomic_or<T: Copy, U: Copy, const ORD: AtomicOrdering>(dst: *mut T, src: U) -> T;
208
209/// Bitwise xor with the current value, returning the previous value.
210/// `T` must be an integer or pointer type.
211/// `U` must be the same as `T` if that is an integer type, or `usize` if `T` is a pointer type.
212///
213/// The stabilized version of this intrinsic is available on the
214/// [`atomic`] types via the `fetch_xor` method. For example, [`AtomicBool::fetch_xor`].
215#[rustc_intrinsic]
216#[rustc_nounwind]
217pub unsafe fn atomic_xor<T: Copy, U: Copy, const ORD: AtomicOrdering>(dst: *mut T, src: U) -> T;
218
219/// Maximum with the current value using a signed comparison.
220/// `T` must be a signed integer type.
221///
222/// The stabilized version of this intrinsic is available on the
223/// [`atomic`] signed integer types via the `fetch_max` method. For example, [`AtomicI32::fetch_max`].
224#[rustc_intrinsic]
225#[rustc_nounwind]
226#[cfg(not(feature = "ferrocene_certified"))]
227pub unsafe fn atomic_max<T: Copy, const ORD: AtomicOrdering>(dst: *mut T, src: T) -> T;
228
229/// Minimum with the current value using a signed comparison.
230/// `T` must be a signed integer type.
231///
232/// The stabilized version of this intrinsic is available on the
233/// [`atomic`] signed integer types via the `fetch_min` method. For example, [`AtomicI32::fetch_min`].
234#[rustc_intrinsic]
235#[rustc_nounwind]
236#[cfg(not(feature = "ferrocene_certified"))]
237pub unsafe fn atomic_min<T: Copy, const ORD: AtomicOrdering>(dst: *mut T, src: T) -> T;
238
239/// Minimum with the current value using an unsigned comparison.
240/// `T` must be an unsigned integer type.
241///
242/// The stabilized version of this intrinsic is available on the
243/// [`atomic`] unsigned integer types via the `fetch_min` method. For example, [`AtomicU32::fetch_min`].
244#[rustc_intrinsic]
245#[rustc_nounwind]
246pub unsafe fn atomic_umin<T: Copy, const ORD: AtomicOrdering>(dst: *mut T, src: T) -> T;
247
248/// Maximum with the current value using an unsigned comparison.
249/// `T` must be an unsigned integer type.
250///
251/// The stabilized version of this intrinsic is available on the
252/// [`atomic`] unsigned integer types via the `fetch_max` method. For example, [`AtomicU32::fetch_max`].
253#[rustc_intrinsic]
254#[rustc_nounwind]
255pub unsafe fn atomic_umax<T: Copy, const ORD: AtomicOrdering>(dst: *mut T, src: T) -> T;
256
257/// An atomic fence.
258///
259/// The stabilized version of this intrinsic is available in
260/// [`atomic::fence`].
261#[rustc_intrinsic]
262#[rustc_nounwind]
263#[cfg(not(feature = "ferrocene_certified"))]
264pub unsafe fn atomic_fence<const ORD: AtomicOrdering>();
265
266/// An atomic fence for synchronization within a single thread.
267///
268/// The stabilized version of this intrinsic is available in
269/// [`atomic::compiler_fence`].
270#[rustc_intrinsic]
271#[rustc_nounwind]
272#[cfg(not(feature = "ferrocene_certified"))]
273pub unsafe fn atomic_singlethreadfence<const ORD: AtomicOrdering>();
274
275/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
276/// for the given address if supported; otherwise, it is a no-op.
277/// Prefetches have no effect on the behavior of the program but can change its performance
278/// characteristics.
279///
280/// The `LOCALITY` argument is a temporal locality specifier ranging from (0) - no locality,
281/// to (3) - extremely local keep in cache.
282///
283/// This intrinsic does not have a stable counterpart.
284#[rustc_intrinsic]
285#[rustc_nounwind]
286#[miri::intrinsic_fallback_is_spec]
287#[cfg(not(feature = "ferrocene_certified"))]
288pub const fn prefetch_read_data<T, const LOCALITY: i32>(data: *const T) {
289 // This operation is a no-op, unless it is overridden by the backend.
290 let _ = data;
291}
292
293/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
294/// for the given address if supported; otherwise, it is a no-op.
295/// Prefetches have no effect on the behavior of the program but can change its performance
296/// characteristics.
297///
298/// The `LOCALITY` argument is a temporal locality specifier ranging from (0) - no locality,
299/// to (3) - extremely local keep in cache.
300///
301/// This intrinsic does not have a stable counterpart.
302#[rustc_intrinsic]
303#[rustc_nounwind]
304#[miri::intrinsic_fallback_is_spec]
305#[cfg(not(feature = "ferrocene_certified"))]
306pub const fn prefetch_write_data<T, const LOCALITY: i32>(data: *const T) {
307 // This operation is a no-op, unless it is overridden by the backend.
308 let _ = data;
309}
310
311/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
312/// for the given address if supported; otherwise, it is a no-op.
313/// Prefetches have no effect on the behavior of the program but can change its performance
314/// characteristics.
315///
316/// The `LOCALITY` argument is a temporal locality specifier ranging from (0) - no locality,
317/// to (3) - extremely local keep in cache.
318///
319/// This intrinsic does not have a stable counterpart.
320#[rustc_intrinsic]
321#[rustc_nounwind]
322#[miri::intrinsic_fallback_is_spec]
323#[cfg(not(feature = "ferrocene_certified"))]
324pub const fn prefetch_read_instruction<T, const LOCALITY: i32>(data: *const T) {
325 // This operation is a no-op, unless it is overridden by the backend.
326 let _ = data;
327}
328
329/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
330/// for the given address if supported; otherwise, it is a no-op.
331/// Prefetches have no effect on the behavior of the program but can change its performance
332/// characteristics.
333///
334/// The `LOCALITY` argument is a temporal locality specifier ranging from (0) - no locality,
335/// to (3) - extremely local keep in cache.
336///
337/// This intrinsic does not have a stable counterpart.
338#[rustc_intrinsic]
339#[rustc_nounwind]
340#[miri::intrinsic_fallback_is_spec]
341#[cfg(not(feature = "ferrocene_certified"))]
342pub const fn prefetch_write_instruction<T, const LOCALITY: i32>(data: *const T) {
343 // This operation is a no-op, unless it is overridden by the backend.
344 let _ = data;
345}
346
347/// Executes a breakpoint trap, for inspection by a debugger.
348///
349/// This intrinsic does not have a stable counterpart.
350#[rustc_intrinsic]
351#[rustc_nounwind]
352#[cfg(not(feature = "ferrocene_certified"))]
353pub fn breakpoint();
354
355/// Magic intrinsic that derives its meaning from attributes
356/// attached to the function.
357///
358/// For example, dataflow uses this to inject static assertions so
359/// that `rustc_peek(potentially_uninitialized)` would actually
360/// double-check that dataflow did indeed compute that it is
361/// uninitialized at that point in the control flow.
362///
363/// This intrinsic should not be used outside of the compiler.
364#[rustc_nounwind]
365#[rustc_intrinsic]
366#[cfg(not(feature = "ferrocene_certified"))]
367pub fn rustc_peek<T>(_: T) -> T;
368
369/// Aborts the execution of the process.
370///
371/// Note that, unlike most intrinsics, this is safe to call;
372/// it does not require an `unsafe` block.
373/// Therefore, implementations must not require the user to uphold
374/// any safety invariants.
375///
376/// [`std::process::abort`](../../std/process/fn.abort.html) is to be preferred if possible,
377/// as its behavior is more user-friendly and more stable.
378///
379/// The current implementation of `intrinsics::abort` is to invoke an invalid instruction,
380/// on most platforms.
381/// On Unix, the
382/// process will probably terminate with a signal like `SIGABRT`, `SIGILL`, `SIGTRAP`, `SIGSEGV` or
383/// `SIGBUS`. The precise behavior is not guaranteed and not stable.
384#[rustc_nounwind]
385#[rustc_intrinsic]
386pub fn abort() -> !;
387
388/// Informs the optimizer that this point in the code is not reachable,
389/// enabling further optimizations.
390///
391/// N.B., this is very different from the `unreachable!()` macro: Unlike the
392/// macro, which panics when it is executed, it is *undefined behavior* to
393/// reach code marked with this function.
394///
395/// The stabilized version of this intrinsic is [`core::hint::unreachable_unchecked`].
396#[rustc_intrinsic_const_stable_indirect]
397#[rustc_nounwind]
398#[rustc_intrinsic]
399pub const unsafe fn unreachable() -> !;
400
401/// Informs the optimizer that a condition is always true.
402/// If the condition is false, the behavior is undefined.
403///
404/// No code is generated for this intrinsic, but the optimizer will try
405/// to preserve it (and its condition) between passes, which may interfere
406/// with optimization of surrounding code and reduce performance. It should
407/// not be used if the invariant can be discovered by the optimizer on its
408/// own, or if it does not enable any significant optimizations.
409///
410/// The stabilized version of this intrinsic is [`core::hint::assert_unchecked`].
411#[rustc_intrinsic_const_stable_indirect]
412#[rustc_nounwind]
413#[unstable(feature = "core_intrinsics", issue = "none")]
414#[rustc_intrinsic]
415pub const unsafe fn assume(b: bool) {
416 if !b {
417 // SAFETY: the caller must guarantee the argument is never `false`
418 unsafe { unreachable() }
419 }
420}
421
422/// Hints to the compiler that current code path is cold.
423///
424/// Note that, unlike most intrinsics, this is safe to call;
425/// it does not require an `unsafe` block.
426/// Therefore, implementations must not require the user to uphold
427/// any safety invariants.
428///
429/// This intrinsic does not have a stable counterpart.
430#[unstable(feature = "core_intrinsics", issue = "none")]
431#[rustc_intrinsic]
432#[rustc_nounwind]
433#[miri::intrinsic_fallback_is_spec]
434#[cold]
435pub const fn cold_path() {}
436
437/// Hints to the compiler that branch condition is likely to be true.
438/// Returns the value passed to it.
439///
440/// Any use other than with `if` statements will probably not have an effect.
441///
442/// Note that, unlike most intrinsics, this is safe to call;
443/// it does not require an `unsafe` block.
444/// Therefore, implementations must not require the user to uphold
445/// any safety invariants.
446///
447/// This intrinsic does not have a stable counterpart.
448#[unstable(feature = "core_intrinsics", issue = "none")]
449#[rustc_nounwind]
450#[inline(always)]
451#[cfg(not(feature = "ferrocene_certified"))]
452pub const fn likely(b: bool) -> bool {
453 if b {
454 true
455 } else {
456 cold_path();
457 false
458 }
459}
460
461/// Hints to the compiler that branch condition is likely to be false.
462/// Returns the value passed to it.
463///
464/// Any use other than with `if` statements will probably not have an effect.
465///
466/// Note that, unlike most intrinsics, this is safe to call;
467/// it does not require an `unsafe` block.
468/// Therefore, implementations must not require the user to uphold
469/// any safety invariants.
470///
471/// This intrinsic does not have a stable counterpart.
472#[unstable(feature = "core_intrinsics", issue = "none")]
473#[rustc_nounwind]
474#[inline(always)]
475pub const fn unlikely(b: bool) -> bool {
476 if b {
477 cold_path();
478 true
479 } else {
480 false
481 }
482}
483
484/// Returns either `true_val` or `false_val` depending on condition `b` with a
485/// hint to the compiler that this condition is unlikely to be correctly
486/// predicted by a CPU's branch predictor (e.g. a binary search).
487///
488/// This is otherwise functionally equivalent to `if b { true_val } else { false_val }`.
489///
490/// Note that, unlike most intrinsics, this is safe to call;
491/// it does not require an `unsafe` block.
492/// Therefore, implementations must not require the user to uphold
493/// any safety invariants.
494///
495/// The public form of this intrinsic is [`core::hint::select_unpredictable`].
496/// However unlike the public form, the intrinsic will not drop the value that
497/// is not selected.
498#[unstable(feature = "core_intrinsics", issue = "none")]
499#[rustc_const_unstable(feature = "const_select_unpredictable", issue = "145938")]
500#[rustc_intrinsic]
501#[rustc_nounwind]
502#[miri::intrinsic_fallback_is_spec]
503#[inline]
504#[cfg(not(feature = "ferrocene_certified"))]
505pub const fn select_unpredictable<T>(b: bool, true_val: T, false_val: T) -> T
506where
507 T: [const] Destruct,
508{
509 if b { true_val } else { false_val }
510}
511
512/// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
513/// This will statically either panic, or do nothing. It does not *guarantee* to ever panic,
514/// and should only be called if an assertion failure will imply language UB in the following code.
515///
516/// This intrinsic does not have a stable counterpart.
517#[rustc_intrinsic_const_stable_indirect]
518#[rustc_nounwind]
519#[rustc_intrinsic]
520pub const fn assert_inhabited<T>();
521
522/// A guard for unsafe functions that cannot ever be executed if `T` does not permit
523/// zero-initialization: This will statically either panic, or do nothing. It does not *guarantee*
524/// to ever panic, and should only be called if an assertion failure will imply language UB in the
525/// following code.
526///
527/// This intrinsic does not have a stable counterpart.
528#[rustc_intrinsic_const_stable_indirect]
529#[rustc_nounwind]
530#[rustc_intrinsic]
531#[cfg(not(feature = "ferrocene_certified"))]
532pub const fn assert_zero_valid<T>();
533
534/// A guard for `std::mem::uninitialized`. This will statically either panic, or do nothing. It does
535/// not *guarantee* to ever panic, and should only be called if an assertion failure will imply
536/// language UB in the following code.
537///
538/// This intrinsic does not have a stable counterpart.
539#[rustc_intrinsic_const_stable_indirect]
540#[rustc_nounwind]
541#[rustc_intrinsic]
542#[cfg(not(feature = "ferrocene_certified"))]
543pub const fn assert_mem_uninitialized_valid<T>();
544
545/// Gets a reference to a static `Location` indicating where it was called.
546///
547/// Note that, unlike most intrinsics, this is safe to call;
548/// it does not require an `unsafe` block.
549/// Therefore, implementations must not require the user to uphold
550/// any safety invariants.
551///
552/// Consider using [`core::panic::Location::caller`] instead.
553#[rustc_intrinsic_const_stable_indirect]
554#[rustc_nounwind]
555#[rustc_intrinsic]
556#[cfg(not(feature = "ferrocene_certified"))]
557pub const fn caller_location() -> &'static crate::panic::Location<'static>;
558
559/// Moves a value out of scope without running drop glue.
560///
561/// This exists solely for [`crate::mem::forget_unsized`]; normal `forget` uses
562/// `ManuallyDrop` instead.
563///
564/// Note that, unlike most intrinsics, this is safe to call;
565/// it does not require an `unsafe` block.
566/// Therefore, implementations must not require the user to uphold
567/// any safety invariants.
568#[rustc_intrinsic_const_stable_indirect]
569#[rustc_nounwind]
570#[rustc_intrinsic]
571#[cfg(not(feature = "ferrocene_certified"))]
572pub const fn forget<T: ?Sized>(_: T);
573
574/// Reinterprets the bits of a value of one type as another type.
575///
576/// Both types must have the same size. Compilation will fail if this is not guaranteed.
577///
578/// `transmute` is semantically equivalent to a bitwise move of one type
579/// into another. It copies the bits from the source value into the
580/// destination value, then forgets the original. Note that source and destination
581/// are passed by-value, which means if `Src` or `Dst` contain padding, that padding
582/// is *not* guaranteed to be preserved by `transmute`.
583///
584/// Both the argument and the result must be [valid](../../nomicon/what-unsafe-does.html) at
585/// their given type. Violating this condition leads to [undefined behavior][ub]. The compiler
586/// will generate code *assuming that you, the programmer, ensure that there will never be
587/// undefined behavior*. It is therefore your responsibility to guarantee that every value
588/// passed to `transmute` is valid at both types `Src` and `Dst`. Failing to uphold this condition
589/// may lead to unexpected and unstable compilation results. This makes `transmute` **incredibly
590/// unsafe**. `transmute` should be the absolute last resort.
591///
592/// Because `transmute` is a by-value operation, alignment of the *transmuted values
593/// themselves* is not a concern. As with any other function, the compiler already ensures
594/// both `Src` and `Dst` are properly aligned. However, when transmuting values that *point
595/// elsewhere* (such as pointers, references, boxes…), the caller has to ensure proper
596/// alignment of the pointed-to values.
597///
598/// The [nomicon](../../nomicon/transmutes.html) has additional documentation.
599///
600/// [ub]: ../../reference/behavior-considered-undefined.html
601///
602/// # Transmutation between pointers and integers
603///
604/// Special care has to be taken when transmuting between pointers and integers, e.g.
605/// transmuting between `*const ()` and `usize`.
606///
607/// Transmuting *pointers to integers* in a `const` context is [undefined behavior][ub], unless
608/// the pointer was originally created *from* an integer. (That includes this function
609/// specifically, integer-to-pointer casts, and helpers like [`dangling`][crate::ptr::dangling],
610/// but also semantically-equivalent conversions such as punning through `repr(C)` union
611/// fields.) Any attempt to use the resulting value for integer operations will abort
612/// const-evaluation. (And even outside `const`, such transmutation is touching on many
613/// unspecified aspects of the Rust memory model and should be avoided. See below for
614/// alternatives.)
615///
616/// Transmuting *integers to pointers* is a largely unspecified operation. It is likely *not*
617/// equivalent to an `as` cast. Doing non-zero-sized memory accesses with a pointer constructed
618/// this way is currently considered undefined behavior.
619///
620/// All this also applies when the integer is nested inside an array, tuple, struct, or enum.
621/// However, `MaybeUninit<usize>` is not considered an integer type for the purpose of this
622/// section. Transmuting `*const ()` to `MaybeUninit<usize>` is fine---but then calling
623/// `assume_init()` on that result is considered as completing the pointer-to-integer transmute
624/// and thus runs into the issues discussed above.
625///
626/// In particular, doing a pointer-to-integer-to-pointer roundtrip via `transmute` is *not* a
627/// lossless process. If you want to round-trip a pointer through an integer in a way that you
628/// can get back the original pointer, you need to use `as` casts, or replace the integer type
629/// by `MaybeUninit<$int>` (and never call `assume_init()`). If you are looking for a way to
630/// store data of arbitrary type, also use `MaybeUninit<T>` (that will also handle uninitialized
631/// memory due to padding). If you specifically need to store something that is "either an
632/// integer or a pointer", use `*mut ()`: integers can be converted to pointers and back without
633/// any loss (via `as` casts or via `transmute`).
634///
635/// # Examples
636///
637/// There are a few things that `transmute` is really useful for.
638///
639/// Turning a pointer into a function pointer. This is *not* portable to
640/// machines where function pointers and data pointers have different sizes.
641///
642/// ```
643/// fn foo() -> i32 {
644/// 0
645/// }
646/// // Crucially, we `as`-cast to a raw pointer before `transmute`ing to a function pointer.
647/// // This avoids an integer-to-pointer `transmute`, which can be problematic.
648/// // Transmuting between raw pointers and function pointers (i.e., two pointer types) is fine.
649/// let pointer = foo as *const ();
650/// let function = unsafe {
651/// std::mem::transmute::<*const (), fn() -> i32>(pointer)
652/// };
653/// assert_eq!(function(), 0);
654/// ```
655///
656/// Extending a lifetime, or shortening an invariant lifetime. This is
657/// advanced, very unsafe Rust!
658///
659/// ```
660/// struct R<'a>(&'a i32);
661/// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
662/// unsafe { std::mem::transmute::<R<'b>, R<'static>>(r) }
663/// }
664///
665/// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
666/// -> &'b mut R<'c> {
667/// unsafe { std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r) }
668/// }
669/// ```
670///
671/// # Alternatives
672///
673/// Don't despair: many uses of `transmute` can be achieved through other means.
674/// Below are common applications of `transmute` which can be replaced with safer
675/// constructs.
676///
677/// Turning raw bytes (`[u8; SZ]`) into `u32`, `f64`, etc.:
678///
679/// ```
680/// # #![allow(unnecessary_transmutes)]
681/// let raw_bytes = [0x78, 0x56, 0x34, 0x12];
682///
683/// let num = unsafe {
684/// std::mem::transmute::<[u8; 4], u32>(raw_bytes)
685/// };
686///
687/// // use `u32::from_ne_bytes` instead
688/// let num = u32::from_ne_bytes(raw_bytes);
689/// // or use `u32::from_le_bytes` or `u32::from_be_bytes` to specify the endianness
690/// let num = u32::from_le_bytes(raw_bytes);
691/// assert_eq!(num, 0x12345678);
692/// let num = u32::from_be_bytes(raw_bytes);
693/// assert_eq!(num, 0x78563412);
694/// ```
695///
696/// Turning a pointer into a `usize`:
697///
698/// ```no_run
699/// let ptr = &0;
700/// let ptr_num_transmute = unsafe {
701/// std::mem::transmute::<&i32, usize>(ptr)
702/// };
703///
704/// // Use an `as` cast instead
705/// let ptr_num_cast = ptr as *const i32 as usize;
706/// ```
707///
708/// Note that using `transmute` to turn a pointer to a `usize` is (as noted above) [undefined
709/// behavior][ub] in `const` contexts. Also outside of consts, this operation might not behave
710/// as expected -- this is touching on many unspecified aspects of the Rust memory model.
711/// Depending on what the code is doing, the following alternatives are preferable to
712/// pointer-to-integer transmutation:
713/// - If the code just wants to store data of arbitrary type in some buffer and needs to pick a
714/// type for that buffer, it can use [`MaybeUninit`][crate::mem::MaybeUninit].
715/// - If the code actually wants to work on the address the pointer points to, it can use `as`
716/// casts or [`ptr.addr()`][pointer::addr].
717///
718/// Turning a `*mut T` into a `&mut T`:
719///
720/// ```
721/// let ptr: *mut i32 = &mut 0;
722/// let ref_transmuted = unsafe {
723/// std::mem::transmute::<*mut i32, &mut i32>(ptr)
724/// };
725///
726/// // Use a reborrow instead
727/// let ref_casted = unsafe { &mut *ptr };
728/// ```
729///
730/// Turning a `&mut T` into a `&mut U`:
731///
732/// ```
733/// let ptr = &mut 0;
734/// let val_transmuted = unsafe {
735/// std::mem::transmute::<&mut i32, &mut u32>(ptr)
736/// };
737///
738/// // Now, put together `as` and reborrowing - note the chaining of `as`
739/// // `as` is not transitive
740/// let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) };
741/// ```
742///
743/// Turning a `&str` into a `&[u8]`:
744///
745/// ```
746/// // this is not a good way to do this.
747/// let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") };
748/// assert_eq!(slice, &[82, 117, 115, 116]);
749///
750/// // You could use `str::as_bytes`
751/// let slice = "Rust".as_bytes();
752/// assert_eq!(slice, &[82, 117, 115, 116]);
753///
754/// // Or, just use a byte string, if you have control over the string
755/// // literal
756/// assert_eq!(b"Rust", &[82, 117, 115, 116]);
757/// ```
758///
759/// Turning a `Vec<&T>` into a `Vec<Option<&T>>`.
760///
761/// To transmute the inner type of the contents of a container, you must make sure to not
762/// violate any of the container's invariants. For `Vec`, this means that both the size
763/// *and alignment* of the inner types have to match. Other containers might rely on the
764/// size of the type, alignment, or even the `TypeId`, in which case transmuting wouldn't
765/// be possible at all without violating the container invariants.
766///
767/// ```
768/// let store = [0, 1, 2, 3];
769/// let v_orig = store.iter().collect::<Vec<&i32>>();
770///
771/// // clone the vector as we will reuse them later
772/// let v_clone = v_orig.clone();
773///
774/// // Using transmute: this relies on the unspecified data layout of `Vec`, which is a
775/// // bad idea and could cause Undefined Behavior.
776/// // However, it is no-copy.
777/// let v_transmuted = unsafe {
778/// std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone)
779/// };
780///
781/// let v_clone = v_orig.clone();
782///
783/// // This is the suggested, safe way.
784/// // It may copy the entire vector into a new one though, but also may not.
785/// let v_collected = v_clone.into_iter()
786/// .map(Some)
787/// .collect::<Vec<Option<&i32>>>();
788///
789/// let v_clone = v_orig.clone();
790///
791/// // This is the proper no-copy, unsafe way of "transmuting" a `Vec`, without relying on the
792/// // data layout. Instead of literally calling `transmute`, we perform a pointer cast, but
793/// // in terms of converting the original inner type (`&i32`) to the new one (`Option<&i32>`),
794/// // this has all the same caveats. Besides the information provided above, also consult the
795/// // [`from_raw_parts`] documentation.
796/// let v_from_raw = unsafe {
797// FIXME Update this when vec_into_raw_parts is stabilized
798/// // Ensure the original vector is not dropped.
799/// let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
800/// Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
801/// v_clone.len(),
802/// v_clone.capacity())
803/// };
804/// ```
805///
806/// [`from_raw_parts`]: ../../std/vec/struct.Vec.html#method.from_raw_parts
807///
808/// Implementing `split_at_mut`:
809///
810/// ```
811/// use std::{slice, mem};
812///
813/// // There are multiple ways to do this, and there are multiple problems
814/// // with the following (transmute) way.
815/// fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize)
816/// -> (&mut [T], &mut [T]) {
817/// let len = slice.len();
818/// assert!(mid <= len);
819/// unsafe {
820/// let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
821/// // first: transmute is not type safe; all it checks is that T and
822/// // U are of the same size. Second, right here, you have two
823/// // mutable references pointing to the same memory.
824/// (&mut slice[0..mid], &mut slice2[mid..len])
825/// }
826/// }
827///
828/// // This gets rid of the type safety problems; `&mut *` will *only* give
829/// // you a `&mut T` from a `&mut T` or `*mut T`.
830/// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
831/// -> (&mut [T], &mut [T]) {
832/// let len = slice.len();
833/// assert!(mid <= len);
834/// unsafe {
835/// let slice2 = &mut *(slice as *mut [T]);
836/// // however, you still have two mutable references pointing to
837/// // the same memory.
838/// (&mut slice[0..mid], &mut slice2[mid..len])
839/// }
840/// }
841///
842/// // This is how the standard library does it. This is the best method, if
843/// // you need to do something like this
844/// fn split_at_stdlib<T>(slice: &mut [T], mid: usize)
845/// -> (&mut [T], &mut [T]) {
846/// let len = slice.len();
847/// assert!(mid <= len);
848/// unsafe {
849/// let ptr = slice.as_mut_ptr();
850/// // This now has three mutable references pointing at the same
851/// // memory. `slice`, the rvalue ret.0, and the rvalue ret.1.
852/// // `slice` is never used after `let ptr = ...`, and so one can
853/// // treat it as "dead", and therefore, you only have two real
854/// // mutable slices.
855/// (slice::from_raw_parts_mut(ptr, mid),
856/// slice::from_raw_parts_mut(ptr.add(mid), len - mid))
857/// }
858/// }
859/// ```
860#[stable(feature = "rust1", since = "1.0.0")]
861#[rustc_allowed_through_unstable_modules = "import this function via `std::mem` instead"]
862#[rustc_const_stable(feature = "const_transmute", since = "1.56.0")]
863#[rustc_diagnostic_item = "transmute"]
864#[rustc_nounwind]
865#[rustc_intrinsic]
866pub const unsafe fn transmute<Src, Dst>(src: Src) -> Dst;
867
868/// Like [`transmute`], but even less checked at compile-time: rather than
869/// giving an error for `size_of::<Src>() != size_of::<Dst>()`, it's
870/// **Undefined Behavior** at runtime.
871///
872/// Prefer normal `transmute` where possible, for the extra checking, since
873/// both do exactly the same thing at runtime, if they both compile.
874///
875/// This is not expected to ever be exposed directly to users, rather it
876/// may eventually be exposed through some more-constrained API.
877#[rustc_intrinsic_const_stable_indirect]
878#[rustc_nounwind]
879#[rustc_intrinsic]
880pub const unsafe fn transmute_unchecked<Src, Dst>(src: Src) -> Dst;
881
882/// Returns `true` if the actual type given as `T` requires drop
883/// glue; returns `false` if the actual type provided for `T`
884/// implements `Copy`.
885///
886/// If the actual type neither requires drop glue nor implements
887/// `Copy`, then the return value of this function is unspecified.
888///
889/// Note that, unlike most intrinsics, this can only be called at compile-time
890/// as backends do not have an implementation for it. The only caller (its
891/// stable counterpart) wraps this intrinsic call in a `const` block so that
892/// backends only see an evaluated constant.
893///
894/// The stabilized version of this intrinsic is [`mem::needs_drop`](crate::mem::needs_drop).
895#[rustc_intrinsic_const_stable_indirect]
896#[rustc_nounwind]
897#[rustc_intrinsic]
898pub const fn needs_drop<T: ?Sized>() -> bool;
899
900/// Calculates the offset from a pointer.
901///
902/// This is implemented as an intrinsic to avoid converting to and from an
903/// integer, since the conversion would throw away aliasing information.
904///
905/// This can only be used with `Ptr` as a raw pointer type (`*mut` or `*const`)
906/// to a `Sized` pointee and with `Delta` as `usize` or `isize`. Any other
907/// instantiations may arbitrarily misbehave, and that's *not* a compiler bug.
908///
909/// # Safety
910///
911/// If the computed offset is non-zero, then both the starting and resulting pointer must be
912/// either in bounds or at the end of an allocation. If either pointer is out
913/// of bounds or arithmetic overflow occurs then this operation is undefined behavior.
914///
915/// The stabilized version of this intrinsic is [`pointer::offset`].
916#[must_use = "returns a new pointer rather than modifying its argument"]
917#[rustc_intrinsic_const_stable_indirect]
918#[rustc_nounwind]
919#[rustc_intrinsic]
920pub const unsafe fn offset<Ptr: bounds::BuiltinDeref, Delta>(dst: Ptr, offset: Delta) -> Ptr;
921
922/// Calculates the offset from a pointer, potentially wrapping.
923///
924/// This is implemented as an intrinsic to avoid converting to and from an
925/// integer, since the conversion inhibits certain optimizations.
926///
927/// # Safety
928///
929/// Unlike the `offset` intrinsic, this intrinsic does not restrict the
930/// resulting pointer to point into or at the end of an allocated
931/// object, and it wraps with two's complement arithmetic. The resulting
932/// value is not necessarily valid to be used to actually access memory.
933///
934/// The stabilized version of this intrinsic is [`pointer::wrapping_offset`].
935#[must_use = "returns a new pointer rather than modifying its argument"]
936#[rustc_intrinsic_const_stable_indirect]
937#[rustc_nounwind]
938#[rustc_intrinsic]
939#[cfg(not(feature = "ferrocene_certified"))]
940pub const unsafe fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
941
942/// Projects to the `index`-th element of `slice_ptr`, as the same kind of pointer
943/// as the slice was provided -- so `&mut [T] → &mut T`, `&[T] → &T`,
944/// `*mut [T] → *mut T`, or `*const [T] → *const T` -- without a bounds check.
945///
946/// This is exposed via `<usize as SliceIndex>::get(_unchecked)(_mut)`,
947/// and isn't intended to be used elsewhere.
948///
949/// Expands in MIR to `{&, &mut, &raw const, &raw mut} (*slice_ptr)[index]`,
950/// depending on the types involved, so no backend support is needed.
951///
952/// # Safety
953///
954/// - `index < PtrMetadata(slice_ptr)`, so the indexing is in-bounds for the slice
955/// - the resulting offsetting is in-bounds of the allocation, which is
956/// always the case for references, but needs to be upheld manually for pointers
957#[rustc_nounwind]
958#[rustc_intrinsic]
959pub const unsafe fn slice_get_unchecked<
960 ItemPtr: bounds::ChangePointee<[T], Pointee = T, Output = SlicePtr>,
961 SlicePtr,
962 T,
963>(
964 slice_ptr: SlicePtr,
965 index: usize,
966) -> ItemPtr;
967
968/// Masks out bits of the pointer according to a mask.
969///
970/// Note that, unlike most intrinsics, this is safe to call;
971/// it does not require an `unsafe` block.
972/// Therefore, implementations must not require the user to uphold
973/// any safety invariants.
974///
975/// Consider using [`pointer::mask`] instead.
976#[rustc_nounwind]
977#[rustc_intrinsic]
978#[cfg(not(feature = "ferrocene_certified"))]
979pub fn ptr_mask<T>(ptr: *const T, mask: usize) -> *const T;
980
981/// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
982/// a size of `count` * `size_of::<T>()` and an alignment of `align_of::<T>()`.
983///
984/// This intrinsic does not have a stable counterpart.
985/// # Safety
986///
987/// The safety requirements are consistent with [`copy_nonoverlapping`]
988/// while the read and write behaviors are volatile,
989/// which means it will not be optimized out unless `_count` or `size_of::<T>()` is equal to zero.
990///
991/// [`copy_nonoverlapping`]: ptr::copy_nonoverlapping
992#[rustc_intrinsic]
993#[rustc_nounwind]
994#[cfg(not(feature = "ferrocene_certified"))]
995pub unsafe fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
996/// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
997/// a size of `count * size_of::<T>()` and an alignment of `align_of::<T>()`.
998///
999/// The volatile parameter is set to `true`, so it will not be optimized out
1000/// unless size is equal to zero.
1001///
1002/// This intrinsic does not have a stable counterpart.
1003#[rustc_intrinsic]
1004#[rustc_nounwind]
1005#[cfg(not(feature = "ferrocene_certified"))]
1006pub unsafe fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
1007/// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
1008/// size of `count * size_of::<T>()` and an alignment of `align_of::<T>()`.
1009///
1010/// This intrinsic does not have a stable counterpart.
1011/// # Safety
1012///
1013/// The safety requirements are consistent with [`write_bytes`] while the write behavior is volatile,
1014/// which means it will not be optimized out unless `_count` or `size_of::<T>()` is equal to zero.
1015///
1016/// [`write_bytes`]: ptr::write_bytes
1017#[rustc_intrinsic]
1018#[rustc_nounwind]
1019#[cfg(not(feature = "ferrocene_certified"))]
1020pub unsafe fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
1021
1022/// Performs a volatile load from the `src` pointer.
1023///
1024/// The stabilized version of this intrinsic is [`core::ptr::read_volatile`].
1025#[rustc_intrinsic]
1026#[rustc_nounwind]
1027pub unsafe fn volatile_load<T>(src: *const T) -> T;
1028/// Performs a volatile store to the `dst` pointer.
1029///
1030/// The stabilized version of this intrinsic is [`core::ptr::write_volatile`].
1031#[rustc_intrinsic]
1032#[rustc_nounwind]
1033pub unsafe fn volatile_store<T>(dst: *mut T, val: T);
1034
1035/// Performs a volatile load from the `src` pointer
1036/// The pointer is not required to be aligned.
1037///
1038/// This intrinsic does not have a stable counterpart.
1039#[rustc_intrinsic]
1040#[rustc_nounwind]
1041#[rustc_diagnostic_item = "intrinsics_unaligned_volatile_load"]
1042#[cfg(not(feature = "ferrocene_certified"))]
1043pub unsafe fn unaligned_volatile_load<T>(src: *const T) -> T;
1044/// Performs a volatile store to the `dst` pointer.
1045/// The pointer is not required to be aligned.
1046///
1047/// This intrinsic does not have a stable counterpart.
1048#[rustc_intrinsic]
1049#[rustc_nounwind]
1050#[rustc_diagnostic_item = "intrinsics_unaligned_volatile_store"]
1051#[cfg(not(feature = "ferrocene_certified"))]
1052pub unsafe fn unaligned_volatile_store<T>(dst: *mut T, val: T);
1053
1054/// Returns the square root of an `f16`
1055///
1056/// The stabilized version of this intrinsic is
1057/// [`f16::sqrt`](../../std/primitive.f16.html#method.sqrt)
1058#[rustc_intrinsic]
1059#[rustc_nounwind]
1060#[cfg(not(feature = "ferrocene_certified"))]
1061pub fn sqrtf16(x: f16) -> f16;
1062/// Returns the square root of an `f32`
1063///
1064/// The stabilized version of this intrinsic is
1065/// [`f32::sqrt`](../../std/primitive.f32.html#method.sqrt)
1066#[rustc_intrinsic]
1067#[rustc_nounwind]
1068#[cfg(not(feature = "ferrocene_certified"))]
1069pub fn sqrtf32(x: f32) -> f32;
1070/// Returns the square root of an `f64`
1071///
1072/// The stabilized version of this intrinsic is
1073/// [`f64::sqrt`](../../std/primitive.f64.html#method.sqrt)
1074#[rustc_intrinsic]
1075#[rustc_nounwind]
1076#[cfg(not(feature = "ferrocene_certified"))]
1077pub fn sqrtf64(x: f64) -> f64;
1078/// Returns the square root of an `f128`
1079///
1080/// The stabilized version of this intrinsic is
1081/// [`f128::sqrt`](../../std/primitive.f128.html#method.sqrt)
1082#[rustc_intrinsic]
1083#[rustc_nounwind]
1084#[cfg(not(feature = "ferrocene_certified"))]
1085pub fn sqrtf128(x: f128) -> f128;
1086
1087/// Raises an `f16` to an integer power.
1088///
1089/// The stabilized version of this intrinsic is
1090/// [`f16::powi`](../../std/primitive.f16.html#method.powi)
1091#[rustc_intrinsic]
1092#[rustc_nounwind]
1093#[cfg(not(feature = "ferrocene_certified"))]
1094pub fn powif16(a: f16, x: i32) -> f16;
1095/// Raises an `f32` to an integer power.
1096///
1097/// The stabilized version of this intrinsic is
1098/// [`f32::powi`](../../std/primitive.f32.html#method.powi)
1099#[rustc_intrinsic]
1100#[rustc_nounwind]
1101#[cfg(not(feature = "ferrocene_certified"))]
1102pub fn powif32(a: f32, x: i32) -> f32;
1103/// Raises an `f64` to an integer power.
1104///
1105/// The stabilized version of this intrinsic is
1106/// [`f64::powi`](../../std/primitive.f64.html#method.powi)
1107#[rustc_intrinsic]
1108#[rustc_nounwind]
1109#[cfg(not(feature = "ferrocene_certified"))]
1110pub fn powif64(a: f64, x: i32) -> f64;
1111/// Raises an `f128` to an integer power.
1112///
1113/// The stabilized version of this intrinsic is
1114/// [`f128::powi`](../../std/primitive.f128.html#method.powi)
1115#[rustc_intrinsic]
1116#[rustc_nounwind]
1117#[cfg(not(feature = "ferrocene_certified"))]
1118pub fn powif128(a: f128, x: i32) -> f128;
1119
1120/// Returns the sine of an `f16`.
1121///
1122/// The stabilized version of this intrinsic is
1123/// [`f16::sin`](../../std/primitive.f16.html#method.sin)
1124#[rustc_intrinsic]
1125#[rustc_nounwind]
1126#[cfg(not(feature = "ferrocene_certified"))]
1127pub fn sinf16(x: f16) -> f16;
1128/// Returns the sine of an `f32`.
1129///
1130/// The stabilized version of this intrinsic is
1131/// [`f32::sin`](../../std/primitive.f32.html#method.sin)
1132#[rustc_intrinsic]
1133#[rustc_nounwind]
1134#[cfg(not(feature = "ferrocene_certified"))]
1135pub fn sinf32(x: f32) -> f32;
1136/// Returns the sine of an `f64`.
1137///
1138/// The stabilized version of this intrinsic is
1139/// [`f64::sin`](../../std/primitive.f64.html#method.sin)
1140#[rustc_intrinsic]
1141#[rustc_nounwind]
1142#[cfg(not(feature = "ferrocene_certified"))]
1143pub fn sinf64(x: f64) -> f64;
1144/// Returns the sine of an `f128`.
1145///
1146/// The stabilized version of this intrinsic is
1147/// [`f128::sin`](../../std/primitive.f128.html#method.sin)
1148#[rustc_intrinsic]
1149#[rustc_nounwind]
1150#[cfg(not(feature = "ferrocene_certified"))]
1151pub fn sinf128(x: f128) -> f128;
1152
1153/// Returns the cosine of an `f16`.
1154///
1155/// The stabilized version of this intrinsic is
1156/// [`f16::cos`](../../std/primitive.f16.html#method.cos)
1157#[rustc_intrinsic]
1158#[rustc_nounwind]
1159#[cfg(not(feature = "ferrocene_certified"))]
1160pub fn cosf16(x: f16) -> f16;
1161/// Returns the cosine of an `f32`.
1162///
1163/// The stabilized version of this intrinsic is
1164/// [`f32::cos`](../../std/primitive.f32.html#method.cos)
1165#[rustc_intrinsic]
1166#[rustc_nounwind]
1167#[cfg(not(feature = "ferrocene_certified"))]
1168pub fn cosf32(x: f32) -> f32;
1169/// Returns the cosine of an `f64`.
1170///
1171/// The stabilized version of this intrinsic is
1172/// [`f64::cos`](../../std/primitive.f64.html#method.cos)
1173#[rustc_intrinsic]
1174#[rustc_nounwind]
1175#[cfg(not(feature = "ferrocene_certified"))]
1176pub fn cosf64(x: f64) -> f64;
1177/// Returns the cosine of an `f128`.
1178///
1179/// The stabilized version of this intrinsic is
1180/// [`f128::cos`](../../std/primitive.f128.html#method.cos)
1181#[rustc_intrinsic]
1182#[rustc_nounwind]
1183#[cfg(not(feature = "ferrocene_certified"))]
1184pub fn cosf128(x: f128) -> f128;
1185
1186/// Raises an `f16` to an `f16` power.
1187///
1188/// The stabilized version of this intrinsic is
1189/// [`f16::powf`](../../std/primitive.f16.html#method.powf)
1190#[rustc_intrinsic]
1191#[rustc_nounwind]
1192#[cfg(not(feature = "ferrocene_certified"))]
1193pub fn powf16(a: f16, x: f16) -> f16;
1194/// Raises an `f32` to an `f32` power.
1195///
1196/// The stabilized version of this intrinsic is
1197/// [`f32::powf`](../../std/primitive.f32.html#method.powf)
1198#[rustc_intrinsic]
1199#[rustc_nounwind]
1200#[cfg(not(feature = "ferrocene_certified"))]
1201pub fn powf32(a: f32, x: f32) -> f32;
1202/// Raises an `f64` to an `f64` power.
1203///
1204/// The stabilized version of this intrinsic is
1205/// [`f64::powf`](../../std/primitive.f64.html#method.powf)
1206#[rustc_intrinsic]
1207#[rustc_nounwind]
1208#[cfg(not(feature = "ferrocene_certified"))]
1209pub fn powf64(a: f64, x: f64) -> f64;
1210/// Raises an `f128` to an `f128` power.
1211///
1212/// The stabilized version of this intrinsic is
1213/// [`f128::powf`](../../std/primitive.f128.html#method.powf)
1214#[rustc_intrinsic]
1215#[rustc_nounwind]
1216#[cfg(not(feature = "ferrocene_certified"))]
1217pub fn powf128(a: f128, x: f128) -> f128;
1218
1219/// Returns the exponential of an `f16`.
1220///
1221/// The stabilized version of this intrinsic is
1222/// [`f16::exp`](../../std/primitive.f16.html#method.exp)
1223#[rustc_intrinsic]
1224#[rustc_nounwind]
1225#[cfg(not(feature = "ferrocene_certified"))]
1226pub fn expf16(x: f16) -> f16;
1227/// Returns the exponential of an `f32`.
1228///
1229/// The stabilized version of this intrinsic is
1230/// [`f32::exp`](../../std/primitive.f32.html#method.exp)
1231#[rustc_intrinsic]
1232#[rustc_nounwind]
1233#[cfg(not(feature = "ferrocene_certified"))]
1234pub fn expf32(x: f32) -> f32;
1235/// Returns the exponential of an `f64`.
1236///
1237/// The stabilized version of this intrinsic is
1238/// [`f64::exp`](../../std/primitive.f64.html#method.exp)
1239#[rustc_intrinsic]
1240#[rustc_nounwind]
1241#[cfg(not(feature = "ferrocene_certified"))]
1242pub fn expf64(x: f64) -> f64;
1243/// Returns the exponential of an `f128`.
1244///
1245/// The stabilized version of this intrinsic is
1246/// [`f128::exp`](../../std/primitive.f128.html#method.exp)
1247#[rustc_intrinsic]
1248#[rustc_nounwind]
1249#[cfg(not(feature = "ferrocene_certified"))]
1250pub fn expf128(x: f128) -> f128;
1251
1252/// Returns 2 raised to the power of an `f16`.
1253///
1254/// The stabilized version of this intrinsic is
1255/// [`f16::exp2`](../../std/primitive.f16.html#method.exp2)
1256#[rustc_intrinsic]
1257#[rustc_nounwind]
1258#[cfg(not(feature = "ferrocene_certified"))]
1259pub fn exp2f16(x: f16) -> f16;
1260/// Returns 2 raised to the power of an `f32`.
1261///
1262/// The stabilized version of this intrinsic is
1263/// [`f32::exp2`](../../std/primitive.f32.html#method.exp2)
1264#[rustc_intrinsic]
1265#[rustc_nounwind]
1266#[cfg(not(feature = "ferrocene_certified"))]
1267pub fn exp2f32(x: f32) -> f32;
1268/// Returns 2 raised to the power of an `f64`.
1269///
1270/// The stabilized version of this intrinsic is
1271/// [`f64::exp2`](../../std/primitive.f64.html#method.exp2)
1272#[rustc_intrinsic]
1273#[rustc_nounwind]
1274#[cfg(not(feature = "ferrocene_certified"))]
1275pub fn exp2f64(x: f64) -> f64;
1276/// Returns 2 raised to the power of an `f128`.
1277///
1278/// The stabilized version of this intrinsic is
1279/// [`f128::exp2`](../../std/primitive.f128.html#method.exp2)
1280#[rustc_intrinsic]
1281#[rustc_nounwind]
1282#[cfg(not(feature = "ferrocene_certified"))]
1283pub fn exp2f128(x: f128) -> f128;
1284
1285/// Returns the natural logarithm of an `f16`.
1286///
1287/// The stabilized version of this intrinsic is
1288/// [`f16::ln`](../../std/primitive.f16.html#method.ln)
1289#[rustc_intrinsic]
1290#[rustc_nounwind]
1291#[cfg(not(feature = "ferrocene_certified"))]
1292pub fn logf16(x: f16) -> f16;
1293/// Returns the natural logarithm of an `f32`.
1294///
1295/// The stabilized version of this intrinsic is
1296/// [`f32::ln`](../../std/primitive.f32.html#method.ln)
1297#[rustc_intrinsic]
1298#[rustc_nounwind]
1299#[cfg(not(feature = "ferrocene_certified"))]
1300pub fn logf32(x: f32) -> f32;
1301/// Returns the natural logarithm of an `f64`.
1302///
1303/// The stabilized version of this intrinsic is
1304/// [`f64::ln`](../../std/primitive.f64.html#method.ln)
1305#[rustc_intrinsic]
1306#[rustc_nounwind]
1307#[cfg(not(feature = "ferrocene_certified"))]
1308pub fn logf64(x: f64) -> f64;
1309/// Returns the natural logarithm of an `f128`.
1310///
1311/// The stabilized version of this intrinsic is
1312/// [`f128::ln`](../../std/primitive.f128.html#method.ln)
1313#[rustc_intrinsic]
1314#[rustc_nounwind]
1315#[cfg(not(feature = "ferrocene_certified"))]
1316pub fn logf128(x: f128) -> f128;
1317
1318/// Returns the base 10 logarithm of an `f16`.
1319///
1320/// The stabilized version of this intrinsic is
1321/// [`f16::log10`](../../std/primitive.f16.html#method.log10)
1322#[rustc_intrinsic]
1323#[rustc_nounwind]
1324#[cfg(not(feature = "ferrocene_certified"))]
1325pub fn log10f16(x: f16) -> f16;
1326/// Returns the base 10 logarithm of an `f32`.
1327///
1328/// The stabilized version of this intrinsic is
1329/// [`f32::log10`](../../std/primitive.f32.html#method.log10)
1330#[rustc_intrinsic]
1331#[rustc_nounwind]
1332#[cfg(not(feature = "ferrocene_certified"))]
1333pub fn log10f32(x: f32) -> f32;
1334/// Returns the base 10 logarithm of an `f64`.
1335///
1336/// The stabilized version of this intrinsic is
1337/// [`f64::log10`](../../std/primitive.f64.html#method.log10)
1338#[rustc_intrinsic]
1339#[rustc_nounwind]
1340#[cfg(not(feature = "ferrocene_certified"))]
1341pub fn log10f64(x: f64) -> f64;
1342/// Returns the base 10 logarithm of an `f128`.
1343///
1344/// The stabilized version of this intrinsic is
1345/// [`f128::log10`](../../std/primitive.f128.html#method.log10)
1346#[rustc_intrinsic]
1347#[rustc_nounwind]
1348#[cfg(not(feature = "ferrocene_certified"))]
1349pub fn log10f128(x: f128) -> f128;
1350
1351/// Returns the base 2 logarithm of an `f16`.
1352///
1353/// The stabilized version of this intrinsic is
1354/// [`f16::log2`](../../std/primitive.f16.html#method.log2)
1355#[rustc_intrinsic]
1356#[rustc_nounwind]
1357#[cfg(not(feature = "ferrocene_certified"))]
1358pub fn log2f16(x: f16) -> f16;
1359/// Returns the base 2 logarithm of an `f32`.
1360///
1361/// The stabilized version of this intrinsic is
1362/// [`f32::log2`](../../std/primitive.f32.html#method.log2)
1363#[rustc_intrinsic]
1364#[rustc_nounwind]
1365#[cfg(not(feature = "ferrocene_certified"))]
1366pub fn log2f32(x: f32) -> f32;
1367/// Returns the base 2 logarithm of an `f64`.
1368///
1369/// The stabilized version of this intrinsic is
1370/// [`f64::log2`](../../std/primitive.f64.html#method.log2)
1371#[rustc_intrinsic]
1372#[rustc_nounwind]
1373#[cfg(not(feature = "ferrocene_certified"))]
1374pub fn log2f64(x: f64) -> f64;
1375/// Returns the base 2 logarithm of an `f128`.
1376///
1377/// The stabilized version of this intrinsic is
1378/// [`f128::log2`](../../std/primitive.f128.html#method.log2)
1379#[rustc_intrinsic]
1380#[rustc_nounwind]
1381#[cfg(not(feature = "ferrocene_certified"))]
1382pub fn log2f128(x: f128) -> f128;
1383
1384/// Returns `a * b + c` for `f16` values.
1385///
1386/// The stabilized version of this intrinsic is
1387/// [`f16::mul_add`](../../std/primitive.f16.html#method.mul_add)
1388#[rustc_intrinsic]
1389#[rustc_nounwind]
1390#[cfg(not(feature = "ferrocene_certified"))]
1391pub const fn fmaf16(a: f16, b: f16, c: f16) -> f16;
1392/// Returns `a * b + c` for `f32` values.
1393///
1394/// The stabilized version of this intrinsic is
1395/// [`f32::mul_add`](../../std/primitive.f32.html#method.mul_add)
1396#[rustc_intrinsic]
1397#[rustc_nounwind]
1398#[cfg(not(feature = "ferrocene_certified"))]
1399pub const fn fmaf32(a: f32, b: f32, c: f32) -> f32;
1400/// Returns `a * b + c` for `f64` values.
1401///
1402/// The stabilized version of this intrinsic is
1403/// [`f64::mul_add`](../../std/primitive.f64.html#method.mul_add)
1404#[rustc_intrinsic]
1405#[rustc_nounwind]
1406#[cfg(not(feature = "ferrocene_certified"))]
1407pub const fn fmaf64(a: f64, b: f64, c: f64) -> f64;
1408/// Returns `a * b + c` for `f128` values.
1409///
1410/// The stabilized version of this intrinsic is
1411/// [`f128::mul_add`](../../std/primitive.f128.html#method.mul_add)
1412#[rustc_intrinsic]
1413#[rustc_nounwind]
1414#[cfg(not(feature = "ferrocene_certified"))]
1415pub const fn fmaf128(a: f128, b: f128, c: f128) -> f128;
1416
1417/// Returns `a * b + c` for `f16` values, non-deterministically executing
1418/// either a fused multiply-add or two operations with rounding of the
1419/// intermediate result.
1420///
1421/// The operation is fused if the code generator determines that target
1422/// instruction set has support for a fused operation, and that the fused
1423/// operation is more efficient than the equivalent, separate pair of mul
1424/// and add instructions. It is unspecified whether or not a fused operation
1425/// is selected, and that may depend on optimization level and context, for
1426/// example.
1427#[rustc_intrinsic]
1428#[rustc_nounwind]
1429#[cfg(not(feature = "ferrocene_certified"))]
1430pub const fn fmuladdf16(a: f16, b: f16, c: f16) -> f16;
1431/// Returns `a * b + c` for `f32` values, non-deterministically executing
1432/// either a fused multiply-add or two operations with rounding of the
1433/// intermediate result.
1434///
1435/// The operation is fused if the code generator determines that target
1436/// instruction set has support for a fused operation, and that the fused
1437/// operation is more efficient than the equivalent, separate pair of mul
1438/// and add instructions. It is unspecified whether or not a fused operation
1439/// is selected, and that may depend on optimization level and context, for
1440/// example.
1441#[rustc_intrinsic]
1442#[rustc_nounwind]
1443#[cfg(not(feature = "ferrocene_certified"))]
1444pub const fn fmuladdf32(a: f32, b: f32, c: f32) -> f32;
1445/// Returns `a * b + c` for `f64` values, non-deterministically executing
1446/// either a fused multiply-add or two operations with rounding of the
1447/// intermediate result.
1448///
1449/// The operation is fused if the code generator determines that target
1450/// instruction set has support for a fused operation, and that the fused
1451/// operation is more efficient than the equivalent, separate pair of mul
1452/// and add instructions. It is unspecified whether or not a fused operation
1453/// is selected, and that may depend on optimization level and context, for
1454/// example.
1455#[rustc_intrinsic]
1456#[rustc_nounwind]
1457#[cfg(not(feature = "ferrocene_certified"))]
1458pub const fn fmuladdf64(a: f64, b: f64, c: f64) -> f64;
1459/// Returns `a * b + c` for `f128` values, non-deterministically executing
1460/// either a fused multiply-add or two operations with rounding of the
1461/// intermediate result.
1462///
1463/// The operation is fused if the code generator determines that target
1464/// instruction set has support for a fused operation, and that the fused
1465/// operation is more efficient than the equivalent, separate pair of mul
1466/// and add instructions. It is unspecified whether or not a fused operation
1467/// is selected, and that may depend on optimization level and context, for
1468/// example.
1469#[rustc_intrinsic]
1470#[rustc_nounwind]
1471#[cfg(not(feature = "ferrocene_certified"))]
1472pub const fn fmuladdf128(a: f128, b: f128, c: f128) -> f128;
1473
1474/// Returns the largest integer less than or equal to an `f16`.
1475///
1476/// The stabilized version of this intrinsic is
1477/// [`f16::floor`](../../std/primitive.f16.html#method.floor)
1478#[rustc_intrinsic_const_stable_indirect]
1479#[rustc_intrinsic]
1480#[rustc_nounwind]
1481#[cfg(not(feature = "ferrocene_certified"))]
1482pub const fn floorf16(x: f16) -> f16;
1483/// Returns the largest integer less than or equal to an `f32`.
1484///
1485/// The stabilized version of this intrinsic is
1486/// [`f32::floor`](../../std/primitive.f32.html#method.floor)
1487#[rustc_intrinsic_const_stable_indirect]
1488#[rustc_intrinsic]
1489#[rustc_nounwind]
1490#[cfg(not(feature = "ferrocene_certified"))]
1491pub const fn floorf32(x: f32) -> f32;
1492/// Returns the largest integer less than or equal to an `f64`.
1493///
1494/// The stabilized version of this intrinsic is
1495/// [`f64::floor`](../../std/primitive.f64.html#method.floor)
1496#[rustc_intrinsic_const_stable_indirect]
1497#[rustc_intrinsic]
1498#[rustc_nounwind]
1499#[cfg(not(feature = "ferrocene_certified"))]
1500pub const fn floorf64(x: f64) -> f64;
1501/// Returns the largest integer less than or equal to an `f128`.
1502///
1503/// The stabilized version of this intrinsic is
1504/// [`f128::floor`](../../std/primitive.f128.html#method.floor)
1505#[rustc_intrinsic_const_stable_indirect]
1506#[rustc_intrinsic]
1507#[rustc_nounwind]
1508#[cfg(not(feature = "ferrocene_certified"))]
1509pub const fn floorf128(x: f128) -> f128;
1510
1511/// Returns the smallest integer greater than or equal to an `f16`.
1512///
1513/// The stabilized version of this intrinsic is
1514/// [`f16::ceil`](../../std/primitive.f16.html#method.ceil)
1515#[rustc_intrinsic_const_stable_indirect]
1516#[rustc_intrinsic]
1517#[rustc_nounwind]
1518#[cfg(not(feature = "ferrocene_certified"))]
1519pub const fn ceilf16(x: f16) -> f16;
1520/// Returns the smallest integer greater than or equal to an `f32`.
1521///
1522/// The stabilized version of this intrinsic is
1523/// [`f32::ceil`](../../std/primitive.f32.html#method.ceil)
1524#[rustc_intrinsic_const_stable_indirect]
1525#[rustc_intrinsic]
1526#[rustc_nounwind]
1527#[cfg(not(feature = "ferrocene_certified"))]
1528pub const fn ceilf32(x: f32) -> f32;
1529/// Returns the smallest integer greater than or equal to an `f64`.
1530///
1531/// The stabilized version of this intrinsic is
1532/// [`f64::ceil`](../../std/primitive.f64.html#method.ceil)
1533#[rustc_intrinsic_const_stable_indirect]
1534#[rustc_intrinsic]
1535#[rustc_nounwind]
1536#[cfg(not(feature = "ferrocene_certified"))]
1537pub const fn ceilf64(x: f64) -> f64;
1538/// Returns the smallest integer greater than or equal to an `f128`.
1539///
1540/// The stabilized version of this intrinsic is
1541/// [`f128::ceil`](../../std/primitive.f128.html#method.ceil)
1542#[rustc_intrinsic_const_stable_indirect]
1543#[rustc_intrinsic]
1544#[rustc_nounwind]
1545#[cfg(not(feature = "ferrocene_certified"))]
1546pub const fn ceilf128(x: f128) -> f128;
1547
1548/// Returns the integer part of an `f16`.
1549///
1550/// The stabilized version of this intrinsic is
1551/// [`f16::trunc`](../../std/primitive.f16.html#method.trunc)
1552#[rustc_intrinsic_const_stable_indirect]
1553#[rustc_intrinsic]
1554#[rustc_nounwind]
1555#[cfg(not(feature = "ferrocene_certified"))]
1556pub const fn truncf16(x: f16) -> f16;
1557/// Returns the integer part of an `f32`.
1558///
1559/// The stabilized version of this intrinsic is
1560/// [`f32::trunc`](../../std/primitive.f32.html#method.trunc)
1561#[rustc_intrinsic_const_stable_indirect]
1562#[rustc_intrinsic]
1563#[rustc_nounwind]
1564#[cfg(not(feature = "ferrocene_certified"))]
1565pub const fn truncf32(x: f32) -> f32;
1566/// Returns the integer part of an `f64`.
1567///
1568/// The stabilized version of this intrinsic is
1569/// [`f64::trunc`](../../std/primitive.f64.html#method.trunc)
1570#[rustc_intrinsic_const_stable_indirect]
1571#[rustc_intrinsic]
1572#[rustc_nounwind]
1573#[cfg(not(feature = "ferrocene_certified"))]
1574pub const fn truncf64(x: f64) -> f64;
1575/// Returns the integer part of an `f128`.
1576///
1577/// The stabilized version of this intrinsic is
1578/// [`f128::trunc`](../../std/primitive.f128.html#method.trunc)
1579#[rustc_intrinsic_const_stable_indirect]
1580#[rustc_intrinsic]
1581#[rustc_nounwind]
1582#[cfg(not(feature = "ferrocene_certified"))]
1583pub const fn truncf128(x: f128) -> f128;
1584
1585/// Returns the nearest integer to an `f16`. Rounds half-way cases to the number with an even
1586/// least significant digit.
1587///
1588/// The stabilized version of this intrinsic is
1589/// [`f16::round_ties_even`](../../std/primitive.f16.html#method.round_ties_even)
1590#[rustc_intrinsic_const_stable_indirect]
1591#[rustc_intrinsic]
1592#[rustc_nounwind]
1593#[cfg(not(feature = "ferrocene_certified"))]
1594pub const fn round_ties_even_f16(x: f16) -> f16;
1595
1596/// Returns the nearest integer to an `f32`. Rounds half-way cases to the number with an even
1597/// least significant digit.
1598///
1599/// The stabilized version of this intrinsic is
1600/// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even)
1601#[rustc_intrinsic_const_stable_indirect]
1602#[rustc_intrinsic]
1603#[rustc_nounwind]
1604#[cfg(not(feature = "ferrocene_certified"))]
1605pub const fn round_ties_even_f32(x: f32) -> f32;
1606
1607/// Returns the nearest integer to an `f64`. Rounds half-way cases to the number with an even
1608/// least significant digit.
1609///
1610/// The stabilized version of this intrinsic is
1611/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)
1612#[rustc_intrinsic_const_stable_indirect]
1613#[rustc_intrinsic]
1614#[rustc_nounwind]
1615#[cfg(not(feature = "ferrocene_certified"))]
1616pub const fn round_ties_even_f64(x: f64) -> f64;
1617
1618/// Returns the nearest integer to an `f128`. Rounds half-way cases to the number with an even
1619/// least significant digit.
1620///
1621/// The stabilized version of this intrinsic is
1622/// [`f128::round_ties_even`](../../std/primitive.f128.html#method.round_ties_even)
1623#[rustc_intrinsic_const_stable_indirect]
1624#[rustc_intrinsic]
1625#[rustc_nounwind]
1626#[cfg(not(feature = "ferrocene_certified"))]
1627pub const fn round_ties_even_f128(x: f128) -> f128;
1628
1629/// Returns the nearest integer to an `f16`. Rounds half-way cases away from zero.
1630///
1631/// The stabilized version of this intrinsic is
1632/// [`f16::round`](../../std/primitive.f16.html#method.round)
1633#[rustc_intrinsic_const_stable_indirect]
1634#[rustc_intrinsic]
1635#[rustc_nounwind]
1636#[cfg(not(feature = "ferrocene_certified"))]
1637pub const fn roundf16(x: f16) -> f16;
1638/// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
1639///
1640/// The stabilized version of this intrinsic is
1641/// [`f32::round`](../../std/primitive.f32.html#method.round)
1642#[rustc_intrinsic_const_stable_indirect]
1643#[rustc_intrinsic]
1644#[rustc_nounwind]
1645#[cfg(not(feature = "ferrocene_certified"))]
1646pub const fn roundf32(x: f32) -> f32;
1647/// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
1648///
1649/// The stabilized version of this intrinsic is
1650/// [`f64::round`](../../std/primitive.f64.html#method.round)
1651#[rustc_intrinsic_const_stable_indirect]
1652#[rustc_intrinsic]
1653#[rustc_nounwind]
1654#[cfg(not(feature = "ferrocene_certified"))]
1655pub const fn roundf64(x: f64) -> f64;
1656/// Returns the nearest integer to an `f128`. Rounds half-way cases away from zero.
1657///
1658/// The stabilized version of this intrinsic is
1659/// [`f128::round`](../../std/primitive.f128.html#method.round)
1660#[rustc_intrinsic_const_stable_indirect]
1661#[rustc_intrinsic]
1662#[rustc_nounwind]
1663#[cfg(not(feature = "ferrocene_certified"))]
1664pub const fn roundf128(x: f128) -> f128;
1665
1666/// Float addition that allows optimizations based on algebraic rules.
1667/// Requires that inputs and output of the operation are finite, causing UB otherwise.
1668///
1669/// This intrinsic does not have a stable counterpart.
1670#[rustc_intrinsic]
1671#[rustc_nounwind]
1672#[cfg(not(feature = "ferrocene_certified"))]
1673pub unsafe fn fadd_fast<T: Copy>(a: T, b: T) -> T;
1674
1675/// Float subtraction that allows optimizations based on algebraic rules.
1676/// Requires that inputs and output of the operation are finite, causing UB otherwise.
1677///
1678/// This intrinsic does not have a stable counterpart.
1679#[rustc_intrinsic]
1680#[rustc_nounwind]
1681#[cfg(not(feature = "ferrocene_certified"))]
1682pub unsafe fn fsub_fast<T: Copy>(a: T, b: T) -> T;
1683
1684/// Float multiplication that allows optimizations based on algebraic rules.
1685/// Requires that inputs and output of the operation are finite, causing UB otherwise.
1686///
1687/// This intrinsic does not have a stable counterpart.
1688#[rustc_intrinsic]
1689#[rustc_nounwind]
1690#[cfg(not(feature = "ferrocene_certified"))]
1691pub unsafe fn fmul_fast<T: Copy>(a: T, b: T) -> T;
1692
1693/// Float division that allows optimizations based on algebraic rules.
1694/// Requires that inputs and output of the operation are finite, causing UB otherwise.
1695///
1696/// This intrinsic does not have a stable counterpart.
1697#[rustc_intrinsic]
1698#[rustc_nounwind]
1699#[cfg(not(feature = "ferrocene_certified"))]
1700pub unsafe fn fdiv_fast<T: Copy>(a: T, b: T) -> T;
1701
1702/// Float remainder that allows optimizations based on algebraic rules.
1703/// Requires that inputs and output of the operation are finite, causing UB otherwise.
1704///
1705/// This intrinsic does not have a stable counterpart.
1706#[rustc_intrinsic]
1707#[rustc_nounwind]
1708#[cfg(not(feature = "ferrocene_certified"))]
1709pub unsafe fn frem_fast<T: Copy>(a: T, b: T) -> T;
1710
1711/// Converts with LLVM’s fptoui/fptosi, which may return undef for values out of range
1712/// (<https://github.com/rust-lang/rust/issues/10184>)
1713///
1714/// Stabilized as [`f32::to_int_unchecked`] and [`f64::to_int_unchecked`].
1715#[rustc_intrinsic]
1716#[rustc_nounwind]
1717#[cfg(not(feature = "ferrocene_certified"))]
1718pub unsafe fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
1719
1720/// Float addition that allows optimizations based on algebraic rules.
1721///
1722/// Stabilized as [`f16::algebraic_add`], [`f32::algebraic_add`], [`f64::algebraic_add`] and [`f128::algebraic_add`].
1723#[rustc_nounwind]
1724#[rustc_intrinsic]
1725#[cfg(not(feature = "ferrocene_certified"))]
1726pub const fn fadd_algebraic<T: Copy>(a: T, b: T) -> T;
1727
1728/// Float subtraction that allows optimizations based on algebraic rules.
1729///
1730/// Stabilized as [`f16::algebraic_sub`], [`f32::algebraic_sub`], [`f64::algebraic_sub`] and [`f128::algebraic_sub`].
1731#[rustc_nounwind]
1732#[rustc_intrinsic]
1733#[cfg(not(feature = "ferrocene_certified"))]
1734pub const fn fsub_algebraic<T: Copy>(a: T, b: T) -> T;
1735
1736/// Float multiplication that allows optimizations based on algebraic rules.
1737///
1738/// Stabilized as [`f16::algebraic_mul`], [`f32::algebraic_mul`], [`f64::algebraic_mul`] and [`f128::algebraic_mul`].
1739#[rustc_nounwind]
1740#[rustc_intrinsic]
1741#[cfg(not(feature = "ferrocene_certified"))]
1742pub const fn fmul_algebraic<T: Copy>(a: T, b: T) -> T;
1743
1744/// Float division that allows optimizations based on algebraic rules.
1745///
1746/// Stabilized as [`f16::algebraic_div`], [`f32::algebraic_div`], [`f64::algebraic_div`] and [`f128::algebraic_div`].
1747#[rustc_nounwind]
1748#[rustc_intrinsic]
1749#[cfg(not(feature = "ferrocene_certified"))]
1750pub const fn fdiv_algebraic<T: Copy>(a: T, b: T) -> T;
1751
1752/// Float remainder that allows optimizations based on algebraic rules.
1753///
1754/// Stabilized as [`f16::algebraic_rem`], [`f32::algebraic_rem`], [`f64::algebraic_rem`] and [`f128::algebraic_rem`].
1755#[rustc_nounwind]
1756#[rustc_intrinsic]
1757#[cfg(not(feature = "ferrocene_certified"))]
1758pub const fn frem_algebraic<T: Copy>(a: T, b: T) -> T;
1759
1760/// Returns the number of bits set in an integer type `T`
1761///
1762/// Note that, unlike most intrinsics, this is safe to call;
1763/// it does not require an `unsafe` block.
1764/// Therefore, implementations must not require the user to uphold
1765/// any safety invariants.
1766///
1767/// The stabilized versions of this intrinsic are available on the integer
1768/// primitives via the `count_ones` method. For example,
1769/// [`u32::count_ones`]
1770#[rustc_intrinsic_const_stable_indirect]
1771#[rustc_nounwind]
1772#[rustc_intrinsic]
1773pub const fn ctpop<T: Copy>(x: T) -> u32;
1774
1775/// Returns the number of leading unset bits (zeroes) in an integer type `T`.
1776///
1777/// Note that, unlike most intrinsics, this is safe to call;
1778/// it does not require an `unsafe` block.
1779/// Therefore, implementations must not require the user to uphold
1780/// any safety invariants.
1781///
1782/// The stabilized versions of this intrinsic are available on the integer
1783/// primitives via the `leading_zeros` method. For example,
1784/// [`u32::leading_zeros`]
1785///
1786/// # Examples
1787///
1788/// ```
1789/// #![feature(core_intrinsics)]
1790/// # #![allow(internal_features)]
1791///
1792/// use std::intrinsics::ctlz;
1793///
1794/// let x = 0b0001_1100_u8;
1795/// let num_leading = ctlz(x);
1796/// assert_eq!(num_leading, 3);
1797/// ```
1798///
1799/// An `x` with value `0` will return the bit width of `T`.
1800///
1801/// ```
1802/// #![feature(core_intrinsics)]
1803/// # #![allow(internal_features)]
1804///
1805/// use std::intrinsics::ctlz;
1806///
1807/// let x = 0u16;
1808/// let num_leading = ctlz(x);
1809/// assert_eq!(num_leading, 16);
1810/// ```
1811#[rustc_intrinsic_const_stable_indirect]
1812#[rustc_nounwind]
1813#[rustc_intrinsic]
1814#[cfg(not(feature = "ferrocene_certified"))]
1815pub const fn ctlz<T: Copy>(x: T) -> u32;
1816
1817/// Like `ctlz`, but extra-unsafe as it returns `undef` when
1818/// given an `x` with value `0`.
1819///
1820/// This intrinsic does not have a stable counterpart.
1821///
1822/// # Examples
1823///
1824/// ```
1825/// #![feature(core_intrinsics)]
1826/// # #![allow(internal_features)]
1827///
1828/// use std::intrinsics::ctlz_nonzero;
1829///
1830/// let x = 0b0001_1100_u8;
1831/// let num_leading = unsafe { ctlz_nonzero(x) };
1832/// assert_eq!(num_leading, 3);
1833/// ```
1834#[rustc_intrinsic_const_stable_indirect]
1835#[rustc_nounwind]
1836#[rustc_intrinsic]
1837#[cfg(not(feature = "ferrocene_certified"))]
1838pub const unsafe fn ctlz_nonzero<T: Copy>(x: T) -> u32;
1839
1840/// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
1841///
1842/// Note that, unlike most intrinsics, this is safe to call;
1843/// it does not require an `unsafe` block.
1844/// Therefore, implementations must not require the user to uphold
1845/// any safety invariants.
1846///
1847/// The stabilized versions of this intrinsic are available on the integer
1848/// primitives via the `trailing_zeros` method. For example,
1849/// [`u32::trailing_zeros`]
1850///
1851/// # Examples
1852///
1853/// ```
1854/// #![feature(core_intrinsics)]
1855/// # #![allow(internal_features)]
1856///
1857/// use std::intrinsics::cttz;
1858///
1859/// let x = 0b0011_1000_u8;
1860/// let num_trailing = cttz(x);
1861/// assert_eq!(num_trailing, 3);
1862/// ```
1863///
1864/// An `x` with value `0` will return the bit width of `T`:
1865///
1866/// ```
1867/// #![feature(core_intrinsics)]
1868/// # #![allow(internal_features)]
1869///
1870/// use std::intrinsics::cttz;
1871///
1872/// let x = 0u16;
1873/// let num_trailing = cttz(x);
1874/// assert_eq!(num_trailing, 16);
1875/// ```
1876#[rustc_intrinsic_const_stable_indirect]
1877#[rustc_nounwind]
1878#[rustc_intrinsic]
1879#[cfg(not(feature = "ferrocene_certified"))]
1880pub const fn cttz<T: Copy>(x: T) -> u32;
1881
1882/// Like `cttz`, but extra-unsafe as it returns `undef` when
1883/// given an `x` with value `0`.
1884///
1885/// This intrinsic does not have a stable counterpart.
1886///
1887/// # Examples
1888///
1889/// ```
1890/// #![feature(core_intrinsics)]
1891/// # #![allow(internal_features)]
1892///
1893/// use std::intrinsics::cttz_nonzero;
1894///
1895/// let x = 0b0011_1000_u8;
1896/// let num_trailing = unsafe { cttz_nonzero(x) };
1897/// assert_eq!(num_trailing, 3);
1898/// ```
1899#[rustc_intrinsic_const_stable_indirect]
1900#[rustc_nounwind]
1901#[rustc_intrinsic]
1902pub const unsafe fn cttz_nonzero<T: Copy>(x: T) -> u32;
1903
1904/// Reverses the bytes in an integer type `T`.
1905///
1906/// Note that, unlike most intrinsics, this is safe to call;
1907/// it does not require an `unsafe` block.
1908/// Therefore, implementations must not require the user to uphold
1909/// any safety invariants.
1910///
1911/// The stabilized versions of this intrinsic are available on the integer
1912/// primitives via the `swap_bytes` method. For example,
1913/// [`u32::swap_bytes`]
1914#[rustc_intrinsic_const_stable_indirect]
1915#[rustc_nounwind]
1916#[rustc_intrinsic]
1917#[cfg(not(feature = "ferrocene_certified"))]
1918pub const fn bswap<T: Copy>(x: T) -> T;
1919
1920/// Reverses the bits in an integer type `T`.
1921///
1922/// Note that, unlike most intrinsics, this is safe to call;
1923/// it does not require an `unsafe` block.
1924/// Therefore, implementations must not require the user to uphold
1925/// any safety invariants.
1926///
1927/// The stabilized versions of this intrinsic are available on the integer
1928/// primitives via the `reverse_bits` method. For example,
1929/// [`u32::reverse_bits`]
1930#[rustc_intrinsic_const_stable_indirect]
1931#[rustc_nounwind]
1932#[rustc_intrinsic]
1933#[cfg(not(feature = "ferrocene_certified"))]
1934pub const fn bitreverse<T: Copy>(x: T) -> T;
1935
1936/// Does a three-way comparison between the two arguments,
1937/// which must be of character or integer (signed or unsigned) type.
1938///
1939/// This was originally added because it greatly simplified the MIR in `cmp`
1940/// implementations, and then LLVM 20 added a backend intrinsic for it too.
1941///
1942/// The stabilized version of this intrinsic is [`Ord::cmp`].
1943#[rustc_intrinsic_const_stable_indirect]
1944#[rustc_nounwind]
1945#[rustc_intrinsic]
1946pub const fn three_way_compare<T: Copy>(lhs: T, rhss: T) -> crate::cmp::Ordering;
1947
1948/// Combine two values which have no bits in common.
1949///
1950/// This allows the backend to implement it as `a + b` *or* `a | b`,
1951/// depending which is easier to implement on a specific target.
1952///
1953/// # Safety
1954///
1955/// Requires that `(a & b) == 0`, or equivalently that `(a | b) == (a + b)`.
1956///
1957/// Otherwise it's immediate UB.
1958#[rustc_const_unstable(feature = "disjoint_bitor", issue = "135758")]
1959#[rustc_nounwind]
1960#[rustc_intrinsic]
1961#[track_caller]
1962#[miri::intrinsic_fallback_is_spec] // the fallbacks all `assume` to tell Miri
1963#[cfg(not(feature = "ferrocene_certified"))]
1964pub const unsafe fn disjoint_bitor<T: [const] fallback::DisjointBitOr>(a: T, b: T) -> T {
1965 // SAFETY: same preconditions as this function.
1966 unsafe { fallback::DisjointBitOr::disjoint_bitor(a, b) }
1967}
1968
1969/// Performs checked integer addition.
1970///
1971/// Note that, unlike most intrinsics, this is safe to call;
1972/// it does not require an `unsafe` block.
1973/// Therefore, implementations must not require the user to uphold
1974/// any safety invariants.
1975///
1976/// The stabilized versions of this intrinsic are available on the integer
1977/// primitives via the `overflowing_add` method. For example,
1978/// [`u32::overflowing_add`]
1979#[rustc_intrinsic_const_stable_indirect]
1980#[rustc_nounwind]
1981#[rustc_intrinsic]
1982pub const fn add_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1983
1984/// Performs checked integer subtraction
1985///
1986/// Note that, unlike most intrinsics, this is safe to call;
1987/// it does not require an `unsafe` block.
1988/// Therefore, implementations must not require the user to uphold
1989/// any safety invariants.
1990///
1991/// The stabilized versions of this intrinsic are available on the integer
1992/// primitives via the `overflowing_sub` method. For example,
1993/// [`u32::overflowing_sub`]
1994#[rustc_intrinsic_const_stable_indirect]
1995#[rustc_nounwind]
1996#[rustc_intrinsic]
1997pub const fn sub_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1998
1999/// Performs checked integer multiplication
2000///
2001/// Note that, unlike most intrinsics, this is safe to call;
2002/// it does not require an `unsafe` block.
2003/// Therefore, implementations must not require the user to uphold
2004/// any safety invariants.
2005///
2006/// The stabilized versions of this intrinsic are available on the integer
2007/// primitives via the `overflowing_mul` method. For example,
2008/// [`u32::overflowing_mul`]
2009#[rustc_intrinsic_const_stable_indirect]
2010#[rustc_nounwind]
2011#[rustc_intrinsic]
2012pub const fn mul_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
2013
2014/// Performs full-width multiplication and addition with a carry:
2015/// `multiplier * multiplicand + addend + carry`.
2016///
2017/// This is possible without any overflow. For `uN`:
2018/// MAX * MAX + MAX + MAX
2019/// => (2ⁿ-1) × (2ⁿ-1) + (2ⁿ-1) + (2ⁿ-1)
2020/// => (2²ⁿ - 2ⁿ⁺¹ + 1) + (2ⁿ⁺¹ - 2)
2021/// => 2²ⁿ - 1
2022///
2023/// For `iN`, the upper bound is MIN * MIN + MAX + MAX => 2²ⁿ⁻² + 2ⁿ - 2,
2024/// and the lower bound is MAX * MIN + MIN + MIN => -2²ⁿ⁻² - 2ⁿ + 2ⁿ⁺¹.
2025///
2026/// This currently supports unsigned integers *only*, no signed ones.
2027/// The stabilized versions of this intrinsic are available on integers.
2028#[unstable(feature = "core_intrinsics", issue = "none")]
2029#[rustc_const_unstable(feature = "const_carrying_mul_add", issue = "85532")]
2030#[rustc_nounwind]
2031#[rustc_intrinsic]
2032#[miri::intrinsic_fallback_is_spec]
2033#[cfg(not(feature = "ferrocene_certified"))]
2034pub const fn carrying_mul_add<T: [const] fallback::CarryingMulAdd<Unsigned = U>, U>(
2035 multiplier: T,
2036 multiplicand: T,
2037 addend: T,
2038 carry: T,
2039) -> (U, T) {
2040 multiplier.carrying_mul_add(multiplicand, addend, carry)
2041}
2042
2043/// Performs an exact division, resulting in undefined behavior where
2044/// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
2045///
2046/// This intrinsic does not have a stable counterpart.
2047#[rustc_intrinsic_const_stable_indirect]
2048#[rustc_nounwind]
2049#[rustc_intrinsic]
2050pub const unsafe fn exact_div<T: Copy>(x: T, y: T) -> T;
2051
2052/// Performs an unchecked division, resulting in undefined behavior
2053/// where `y == 0` or `x == T::MIN && y == -1`
2054///
2055/// Safe wrappers for this intrinsic are available on the integer
2056/// primitives via the `checked_div` method. For example,
2057/// [`u32::checked_div`]
2058#[rustc_intrinsic_const_stable_indirect]
2059#[rustc_nounwind]
2060#[rustc_intrinsic]
2061#[cfg(not(feature = "ferrocene_certified"))]
2062pub const unsafe fn unchecked_div<T: Copy>(x: T, y: T) -> T;
2063/// Returns the remainder of an unchecked division, resulting in
2064/// undefined behavior when `y == 0` or `x == T::MIN && y == -1`
2065///
2066/// Safe wrappers for this intrinsic are available on the integer
2067/// primitives via the `checked_rem` method. For example,
2068/// [`u32::checked_rem`]
2069#[rustc_intrinsic_const_stable_indirect]
2070#[rustc_nounwind]
2071#[rustc_intrinsic]
2072pub const unsafe fn unchecked_rem<T: Copy>(x: T, y: T) -> T;
2073
2074/// Performs an unchecked left shift, resulting in undefined behavior when
2075/// `y < 0` or `y >= N`, where N is the width of T in bits.
2076///
2077/// Safe wrappers for this intrinsic are available on the integer
2078/// primitives via the `checked_shl` method. For example,
2079/// [`u32::checked_shl`]
2080#[rustc_intrinsic_const_stable_indirect]
2081#[rustc_nounwind]
2082#[rustc_intrinsic]
2083pub const unsafe fn unchecked_shl<T: Copy, U: Copy>(x: T, y: U) -> T;
2084/// Performs an unchecked right shift, resulting in undefined behavior when
2085/// `y < 0` or `y >= N`, where N is the width of T in bits.
2086///
2087/// Safe wrappers for this intrinsic are available on the integer
2088/// primitives via the `checked_shr` method. For example,
2089/// [`u32::checked_shr`]
2090#[rustc_intrinsic_const_stable_indirect]
2091#[rustc_nounwind]
2092#[rustc_intrinsic]
2093pub const unsafe fn unchecked_shr<T: Copy, U: Copy>(x: T, y: U) -> T;
2094
2095/// Returns the result of an unchecked addition, resulting in
2096/// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.
2097///
2098/// The stable counterpart of this intrinsic is `unchecked_add` on the various
2099/// integer types, such as [`u16::unchecked_add`] and [`i64::unchecked_add`].
2100#[rustc_intrinsic_const_stable_indirect]
2101#[rustc_nounwind]
2102#[rustc_intrinsic]
2103pub const unsafe fn unchecked_add<T: Copy>(x: T, y: T) -> T;
2104
2105/// Returns the result of an unchecked subtraction, resulting in
2106/// undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`.
2107///
2108/// The stable counterpart of this intrinsic is `unchecked_sub` on the various
2109/// integer types, such as [`u16::unchecked_sub`] and [`i64::unchecked_sub`].
2110#[rustc_intrinsic_const_stable_indirect]
2111#[rustc_nounwind]
2112#[rustc_intrinsic]
2113pub const unsafe fn unchecked_sub<T: Copy>(x: T, y: T) -> T;
2114
2115/// Returns the result of an unchecked multiplication, resulting in
2116/// undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`.
2117///
2118/// The stable counterpart of this intrinsic is `unchecked_mul` on the various
2119/// integer types, such as [`u16::unchecked_mul`] and [`i64::unchecked_mul`].
2120#[rustc_intrinsic_const_stable_indirect]
2121#[rustc_nounwind]
2122#[rustc_intrinsic]
2123#[cfg(not(feature = "ferrocene_certified"))]
2124pub const unsafe fn unchecked_mul<T: Copy>(x: T, y: T) -> T;
2125
2126/// Performs rotate left.
2127///
2128/// Note that, unlike most intrinsics, this is safe to call;
2129/// it does not require an `unsafe` block.
2130/// Therefore, implementations must not require the user to uphold
2131/// any safety invariants.
2132///
2133/// The stabilized versions of this intrinsic are available on the integer
2134/// primitives via the `rotate_left` method. For example,
2135/// [`u32::rotate_left`]
2136#[rustc_intrinsic_const_stable_indirect]
2137#[rustc_nounwind]
2138#[rustc_intrinsic]
2139#[cfg(not(feature = "ferrocene_certified"))]
2140pub const fn rotate_left<T: Copy>(x: T, shift: u32) -> T;
2141
2142/// Performs rotate right.
2143///
2144/// Note that, unlike most intrinsics, this is safe to call;
2145/// it does not require an `unsafe` block.
2146/// Therefore, implementations must not require the user to uphold
2147/// any safety invariants.
2148///
2149/// The stabilized versions of this intrinsic are available on the integer
2150/// primitives via the `rotate_right` method. For example,
2151/// [`u32::rotate_right`]
2152#[rustc_intrinsic_const_stable_indirect]
2153#[rustc_nounwind]
2154#[rustc_intrinsic]
2155#[cfg(not(feature = "ferrocene_certified"))]
2156pub const fn rotate_right<T: Copy>(x: T, shift: u32) -> T;
2157
2158/// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
2159///
2160/// Note that, unlike most intrinsics, this is safe to call;
2161/// it does not require an `unsafe` block.
2162/// Therefore, implementations must not require the user to uphold
2163/// any safety invariants.
2164///
2165/// The stabilized versions of this intrinsic are available on the integer
2166/// primitives via the `wrapping_add` method. For example,
2167/// [`u32::wrapping_add`]
2168#[rustc_intrinsic_const_stable_indirect]
2169#[rustc_nounwind]
2170#[rustc_intrinsic]
2171pub const fn wrapping_add<T: Copy>(a: T, b: T) -> T;
2172/// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
2173///
2174/// Note that, unlike most intrinsics, this is safe to call;
2175/// it does not require an `unsafe` block.
2176/// Therefore, implementations must not require the user to uphold
2177/// any safety invariants.
2178///
2179/// The stabilized versions of this intrinsic are available on the integer
2180/// primitives via the `wrapping_sub` method. For example,
2181/// [`u32::wrapping_sub`]
2182#[rustc_intrinsic_const_stable_indirect]
2183#[rustc_nounwind]
2184#[rustc_intrinsic]
2185pub const fn wrapping_sub<T: Copy>(a: T, b: T) -> T;
2186/// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
2187///
2188/// Note that, unlike most intrinsics, this is safe to call;
2189/// it does not require an `unsafe` block.
2190/// Therefore, implementations must not require the user to uphold
2191/// any safety invariants.
2192///
2193/// The stabilized versions of this intrinsic are available on the integer
2194/// primitives via the `wrapping_mul` method. For example,
2195/// [`u32::wrapping_mul`]
2196#[rustc_intrinsic_const_stable_indirect]
2197#[rustc_nounwind]
2198#[rustc_intrinsic]
2199pub const fn wrapping_mul<T: Copy>(a: T, b: T) -> T;
2200
2201/// Computes `a + b`, saturating at numeric bounds.
2202///
2203/// Note that, unlike most intrinsics, this is safe to call;
2204/// it does not require an `unsafe` block.
2205/// Therefore, implementations must not require the user to uphold
2206/// any safety invariants.
2207///
2208/// The stabilized versions of this intrinsic are available on the integer
2209/// primitives via the `saturating_add` method. For example,
2210/// [`u32::saturating_add`]
2211#[rustc_intrinsic_const_stable_indirect]
2212#[rustc_nounwind]
2213#[rustc_intrinsic]
2214#[cfg(not(feature = "ferrocene_certified"))]
2215pub const fn saturating_add<T: Copy>(a: T, b: T) -> T;
2216/// Computes `a - b`, saturating at numeric bounds.
2217///
2218/// Note that, unlike most intrinsics, this is safe to call;
2219/// it does not require an `unsafe` block.
2220/// Therefore, implementations must not require the user to uphold
2221/// any safety invariants.
2222///
2223/// The stabilized versions of this intrinsic are available on the integer
2224/// primitives via the `saturating_sub` method. For example,
2225/// [`u32::saturating_sub`]
2226#[rustc_intrinsic_const_stable_indirect]
2227#[rustc_nounwind]
2228#[rustc_intrinsic]
2229#[cfg(not(feature = "ferrocene_certified"))]
2230pub const fn saturating_sub<T: Copy>(a: T, b: T) -> T;
2231
2232/// Funnel Shift left.
2233///
2234/// Concatenates `a` and `b` (with `a` in the most significant half),
2235/// creating an integer twice as wide. Then shift this integer left
2236/// by `shift`), and extract the most significant half. If `a` and `b`
2237/// are the same, this is equivalent to a rotate left operation.
2238///
2239/// It is undefined behavior if `shift` is greater than or equal to the
2240/// bit size of `T`.
2241///
2242/// Safe versions of this intrinsic are available on the integer primitives
2243/// via the `funnel_shl` method. For example, [`u32::funnel_shl`].
2244#[rustc_intrinsic]
2245#[rustc_nounwind]
2246#[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")]
2247#[unstable(feature = "funnel_shifts", issue = "145686")]
2248#[track_caller]
2249#[miri::intrinsic_fallback_is_spec]
2250#[cfg(not(feature = "ferrocene_certified"))]
2251pub const unsafe fn unchecked_funnel_shl<T: [const] fallback::FunnelShift>(
2252 a: T,
2253 b: T,
2254 shift: u32,
2255) -> T {
2256 // SAFETY: caller ensures that `shift` is in-range
2257 unsafe { a.unchecked_funnel_shl(b, shift) }
2258}
2259
2260/// Funnel Shift right.
2261///
2262/// Concatenates `a` and `b` (with `a` in the most significant half),
2263/// creating an integer twice as wide. Then shift this integer right
2264/// by `shift` (taken modulo the bit size of `T`), and extract the
2265/// least significant half. If `a` and `b` are the same, this is equivalent
2266/// to a rotate right operation.
2267///
2268/// It is undefined behavior if `shift` is greater than or equal to the
2269/// bit size of `T`.
2270///
2271/// Safer versions of this intrinsic are available on the integer primitives
2272/// via the `funnel_shr` method. For example, [`u32::funnel_shr`]
2273#[rustc_intrinsic]
2274#[rustc_nounwind]
2275#[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")]
2276#[unstable(feature = "funnel_shifts", issue = "145686")]
2277#[track_caller]
2278#[miri::intrinsic_fallback_is_spec]
2279#[cfg(not(feature = "ferrocene_certified"))]
2280pub const unsafe fn unchecked_funnel_shr<T: [const] fallback::FunnelShift>(
2281 a: T,
2282 b: T,
2283 shift: u32,
2284) -> T {
2285 // SAFETY: caller ensures that `shift` is in-range
2286 unsafe { a.unchecked_funnel_shr(b, shift) }
2287}
2288
2289/// This is an implementation detail of [`crate::ptr::read`] and should
2290/// not be used anywhere else. See its comments for why this exists.
2291///
2292/// This intrinsic can *only* be called where the pointer is a local without
2293/// projections (`read_via_copy(ptr)`, not `read_via_copy(*ptr)`) so that it
2294/// trivially obeys runtime-MIR rules about derefs in operands.
2295#[rustc_intrinsic_const_stable_indirect]
2296#[rustc_nounwind]
2297#[rustc_intrinsic]
2298pub const unsafe fn read_via_copy<T>(ptr: *const T) -> T;
2299
2300/// This is an implementation detail of [`crate::ptr::write`] and should
2301/// not be used anywhere else. See its comments for why this exists.
2302///
2303/// This intrinsic can *only* be called where the pointer is a local without
2304/// projections (`write_via_move(ptr, x)`, not `write_via_move(*ptr, x)`) so
2305/// that it trivially obeys runtime-MIR rules about derefs in operands.
2306#[rustc_intrinsic_const_stable_indirect]
2307#[rustc_nounwind]
2308#[rustc_intrinsic]
2309pub const unsafe fn write_via_move<T>(ptr: *mut T, value: T);
2310
2311/// Returns the value of the discriminant for the variant in 'v';
2312/// if `T` has no discriminant, returns `0`.
2313///
2314/// Note that, unlike most intrinsics, this is safe to call;
2315/// it does not require an `unsafe` block.
2316/// Therefore, implementations must not require the user to uphold
2317/// any safety invariants.
2318///
2319/// The stabilized version of this intrinsic is [`core::mem::discriminant`].
2320#[rustc_intrinsic_const_stable_indirect]
2321#[rustc_nounwind]
2322#[rustc_intrinsic]
2323pub const fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
2324
2325/// Rust's "try catch" construct for unwinding. Invokes the function pointer `try_fn` with the
2326/// data pointer `data`, and calls `catch_fn` if unwinding occurs while `try_fn` runs.
2327/// Returns `1` if unwinding occurred and `catch_fn` was called; returns `0` otherwise.
2328///
2329/// `catch_fn` must not unwind.
2330///
2331/// The third argument is a function called if an unwind occurs (both Rust `panic` and foreign
2332/// unwinds). This function takes the data pointer and a pointer to the target- and
2333/// runtime-specific exception object that was caught.
2334///
2335/// Note that in the case of a foreign unwinding operation, the exception object data may not be
2336/// safely usable from Rust, and should not be directly exposed via the standard library. To
2337/// prevent unsafe access, the library implementation may either abort the process or present an
2338/// opaque error type to the user.
2339///
2340/// For more information, see the compiler's source, as well as the documentation for the stable
2341/// version of this intrinsic, `std::panic::catch_unwind`.
2342#[rustc_intrinsic]
2343#[rustc_nounwind]
2344#[cfg(not(feature = "ferrocene_certified"))]
2345pub unsafe fn catch_unwind(
2346 _try_fn: fn(*mut u8),
2347 _data: *mut u8,
2348 _catch_fn: fn(*mut u8, *mut u8),
2349) -> i32;
2350
2351/// Emits a `nontemporal` store, which gives a hint to the CPU that the data should not be held
2352/// in cache. Except for performance, this is fully equivalent to `ptr.write(val)`.
2353///
2354/// Not all architectures provide such an operation. For instance, x86 does not: while `MOVNT`
2355/// exists, that operation is *not* equivalent to `ptr.write(val)` (`MOVNT` writes can be reordered
2356/// in ways that are not allowed for regular writes).
2357#[rustc_intrinsic]
2358#[rustc_nounwind]
2359#[cfg(not(feature = "ferrocene_certified"))]
2360pub unsafe fn nontemporal_store<T>(ptr: *mut T, val: T);
2361
2362/// See documentation of `<*const T>::offset_from` for details.
2363#[rustc_intrinsic_const_stable_indirect]
2364#[rustc_nounwind]
2365#[rustc_intrinsic]
2366#[cfg(not(feature = "ferrocene_certified"))]
2367pub const unsafe fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
2368
2369/// See documentation of `<*const T>::offset_from_unsigned` for details.
2370#[rustc_nounwind]
2371#[rustc_intrinsic]
2372#[rustc_intrinsic_const_stable_indirect]
2373#[cfg(not(feature = "ferrocene_certified"))]
2374pub const unsafe fn ptr_offset_from_unsigned<T>(ptr: *const T, base: *const T) -> usize;
2375
2376/// See documentation of `<*const T>::guaranteed_eq` for details.
2377/// Returns `2` if the result is unknown.
2378/// Returns `1` if the pointers are guaranteed equal.
2379/// Returns `0` if the pointers are guaranteed inequal.
2380#[rustc_intrinsic]
2381#[rustc_nounwind]
2382#[rustc_do_not_const_check]
2383#[inline]
2384#[miri::intrinsic_fallback_is_spec]
2385pub const fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8 {
2386 (ptr == other) as u8
2387}
2388
2389/// Determines whether the raw bytes of the two values are equal.
2390///
2391/// This is particularly handy for arrays, since it allows things like just
2392/// comparing `i96`s instead of forcing `alloca`s for `[6 x i16]`.
2393///
2394/// Above some backend-decided threshold this will emit calls to `memcmp`,
2395/// like slice equality does, instead of causing massive code size.
2396///
2397/// Since this works by comparing the underlying bytes, the actual `T` is
2398/// not particularly important. It will be used for its size and alignment,
2399/// but any validity restrictions will be ignored, not enforced.
2400///
2401/// # Safety
2402///
2403/// It's UB to call this if any of the *bytes* in `*a` or `*b` are uninitialized.
2404/// Note that this is a stricter criterion than just the *values* being
2405/// fully-initialized: if `T` has padding, it's UB to call this intrinsic.
2406///
2407/// At compile-time, it is furthermore UB to call this if any of the bytes
2408/// in `*a` or `*b` have provenance.
2409///
2410/// (The implementation is allowed to branch on the results of comparisons,
2411/// which is UB if any of their inputs are `undef`.)
2412#[rustc_nounwind]
2413#[rustc_intrinsic]
2414#[cfg(not(feature = "ferrocene_certified"))]
2415pub const unsafe fn raw_eq<T>(a: &T, b: &T) -> bool;
2416
2417/// Lexicographically compare `[left, left + bytes)` and `[right, right + bytes)`
2418/// as unsigned bytes, returning negative if `left` is less, zero if all the
2419/// bytes match, or positive if `left` is greater.
2420///
2421/// This underlies things like `<[u8]>::cmp`, and will usually lower to `memcmp`.
2422///
2423/// # Safety
2424///
2425/// `left` and `right` must each be [valid] for reads of `bytes` bytes.
2426///
2427/// Note that this applies to the whole range, not just until the first byte
2428/// that differs. That allows optimizations that can read in large chunks.
2429///
2430/// [valid]: crate::ptr#safety
2431#[rustc_nounwind]
2432#[rustc_intrinsic]
2433#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2434#[cfg(not(feature = "ferrocene_certified"))]
2435pub const unsafe fn compare_bytes(left: *const u8, right: *const u8, bytes: usize) -> i32;
2436
2437/// See documentation of [`std::hint::black_box`] for details.
2438///
2439/// [`std::hint::black_box`]: crate::hint::black_box
2440#[rustc_nounwind]
2441#[rustc_intrinsic]
2442#[rustc_intrinsic_const_stable_indirect]
2443#[cfg(not(feature = "ferrocene_certified"))]
2444pub const fn black_box<T>(dummy: T) -> T;
2445
2446/// Selects which function to call depending on the context.
2447///
2448/// If this function is evaluated at compile-time, then a call to this
2449/// intrinsic will be replaced with a call to `called_in_const`. It gets
2450/// replaced with a call to `called_at_rt` otherwise.
2451///
2452/// This function is safe to call, but note the stability concerns below.
2453///
2454/// # Type Requirements
2455///
2456/// The two functions must be both function items. They cannot be function
2457/// pointers or closures. The first function must be a `const fn`.
2458///
2459/// `arg` will be the tupled arguments that will be passed to either one of
2460/// the two functions, therefore, both functions must accept the same type of
2461/// arguments. Both functions must return RET.
2462///
2463/// # Stability concerns
2464///
2465/// Rust has not yet decided that `const fn` are allowed to tell whether
2466/// they run at compile-time or at runtime. Therefore, when using this
2467/// intrinsic anywhere that can be reached from stable, it is crucial that
2468/// the end-to-end behavior of the stable `const fn` is the same for both
2469/// modes of execution. (Here, Undefined Behavior is considered "the same"
2470/// as any other behavior, so if the function exhibits UB at runtime then
2471/// it may do whatever it wants at compile-time.)
2472///
2473/// Here is an example of how this could cause a problem:
2474/// ```no_run
2475/// #![feature(const_eval_select)]
2476/// #![feature(core_intrinsics)]
2477/// # #![allow(internal_features)]
2478/// use std::intrinsics::const_eval_select;
2479///
2480/// // Standard library
2481/// pub const fn inconsistent() -> i32 {
2482/// fn runtime() -> i32 { 1 }
2483/// const fn compiletime() -> i32 { 2 }
2484///
2485/// // ⚠ This code violates the required equivalence of `compiletime`
2486/// // and `runtime`.
2487/// const_eval_select((), compiletime, runtime)
2488/// }
2489///
2490/// // User Crate
2491/// const X: i32 = inconsistent();
2492/// let x = inconsistent();
2493/// assert_eq!(x, X);
2494/// ```
2495///
2496/// Currently such an assertion would always succeed; until Rust decides
2497/// otherwise, that principle should not be violated.
2498#[rustc_const_unstable(feature = "const_eval_select", issue = "124625")]
2499#[rustc_intrinsic]
2500pub const fn const_eval_select<ARG: Tuple, F, G, RET>(
2501 _arg: ARG,
2502 _called_in_const: F,
2503 _called_at_rt: G,
2504) -> RET
2505where
2506 G: FnOnce<ARG, Output = RET>,
2507 F: const FnOnce<ARG, Output = RET>;
2508
2509/// A macro to make it easier to invoke const_eval_select. Use as follows:
2510/// ```rust,ignore (just a macro example)
2511/// const_eval_select!(
2512/// @capture { arg1: i32 = some_expr, arg2: T = other_expr } -> U:
2513/// if const #[attributes_for_const_arm] {
2514/// // Compile-time code goes here.
2515/// } else #[attributes_for_runtime_arm] {
2516/// // Run-time code goes here.
2517/// }
2518/// )
2519/// ```
2520/// The `@capture` block declares which surrounding variables / expressions can be
2521/// used inside the `if const`.
2522/// Note that the two arms of this `if` really each become their own function, which is why the
2523/// macro supports setting attributes for those functions. The runtime function is always
2524/// marked as `#[inline]`.
2525///
2526/// See [`const_eval_select()`] for the rules and requirements around that intrinsic.
2527pub(crate) macro const_eval_select {
2528 (
2529 @capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty = $val:expr),* $(,)? } $( -> $ret:ty )? :
2530 if const
2531 $(#[$compiletime_attr:meta])* $compiletime:block
2532 else
2533 $(#[$runtime_attr:meta])* $runtime:block
2534 ) => {
2535 // Use the `noinline` arm, after adding explicit `inline` attributes
2536 $crate::intrinsics::const_eval_select!(
2537 @capture$([$($binders)*])? { $($arg : $ty = $val),* } $(-> $ret)? :
2538 #[noinline]
2539 if const
2540 #[inline] // prevent codegen on this function
2541 $(#[$compiletime_attr])*
2542 $compiletime
2543 else
2544 #[inline] // avoid the overhead of an extra fn call
2545 $(#[$runtime_attr])*
2546 $runtime
2547 )
2548 },
2549 // With a leading #[noinline], we don't add inline attributes
2550 (
2551 @capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty = $val:expr),* $(,)? } $( -> $ret:ty )? :
2552 #[noinline]
2553 if const
2554 $(#[$compiletime_attr:meta])* $compiletime:block
2555 else
2556 $(#[$runtime_attr:meta])* $runtime:block
2557 ) => {{
2558 $(#[$runtime_attr])*
2559 fn runtime$(<$($binders)*>)?($($arg: $ty),*) $( -> $ret )? {
2560 $runtime
2561 }
2562
2563 $(#[$compiletime_attr])*
2564 #[ferrocene::annotation("Cannot be covered as this only runs during compilation.")]
2565 const fn compiletime$(<$($binders)*>)?($($arg: $ty),*) $( -> $ret )? {
2566 // Don't warn if one of the arguments is unused.
2567 $(let _ = $arg;)*
2568
2569 $compiletime
2570 }
2571
2572 const_eval_select(($($val,)*), compiletime, runtime)
2573 }},
2574 // We support leaving away the `val` expressions for *all* arguments
2575 // (but not for *some* arguments, that's too tricky).
2576 (
2577 @capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty),* $(,)? } $( -> $ret:ty )? :
2578 if const
2579 $(#[$compiletime_attr:meta])* $compiletime:block
2580 else
2581 $(#[$runtime_attr:meta])* $runtime:block
2582 ) => {
2583 $crate::intrinsics::const_eval_select!(
2584 @capture$([$($binders)*])? { $($arg : $ty = $arg),* } $(-> $ret)? :
2585 if const
2586 $(#[$compiletime_attr])* $compiletime
2587 else
2588 $(#[$runtime_attr])* $runtime
2589 )
2590 },
2591}
2592
2593/// Returns whether the argument's value is statically known at
2594/// compile-time.
2595///
2596/// This is useful when there is a way of writing the code that will
2597/// be *faster* when some variables have known values, but *slower*
2598/// in the general case: an `if is_val_statically_known(var)` can be used
2599/// to select between these two variants. The `if` will be optimized away
2600/// and only the desired branch remains.
2601///
2602/// Formally speaking, this function non-deterministically returns `true`
2603/// or `false`, and the caller has to ensure sound behavior for both cases.
2604/// In other words, the following code has *Undefined Behavior*:
2605///
2606/// ```no_run
2607/// #![feature(core_intrinsics)]
2608/// # #![allow(internal_features)]
2609/// use std::hint::unreachable_unchecked;
2610/// use std::intrinsics::is_val_statically_known;
2611///
2612/// if !is_val_statically_known(0) { unsafe { unreachable_unchecked(); } }
2613/// ```
2614///
2615/// This also means that the following code's behavior is unspecified; it
2616/// may panic, or it may not:
2617///
2618/// ```no_run
2619/// #![feature(core_intrinsics)]
2620/// # #![allow(internal_features)]
2621/// use std::intrinsics::is_val_statically_known;
2622///
2623/// assert_eq!(is_val_statically_known(0), is_val_statically_known(0));
2624/// ```
2625///
2626/// Unsafe code may not rely on `is_val_statically_known` returning any
2627/// particular value, ever. However, the compiler will generally make it
2628/// return `true` only if the value of the argument is actually known.
2629///
2630/// # Stability concerns
2631///
2632/// While it is safe to call, this intrinsic may behave differently in
2633/// a `const` context than otherwise. See the [`const_eval_select()`]
2634/// documentation for an explanation of the issues this can cause. Unlike
2635/// `const_eval_select`, this intrinsic isn't guaranteed to behave
2636/// deterministically even in a `const` context.
2637///
2638/// # Type Requirements
2639///
2640/// `T` must be either a `bool`, a `char`, a primitive numeric type (e.g. `f32`,
2641/// but not `NonZeroISize`), or any thin pointer (e.g. `*mut String`).
2642/// Any other argument types *may* cause a compiler error.
2643///
2644/// ## Pointers
2645///
2646/// When the input is a pointer, only the pointer itself is
2647/// ever considered. The pointee has no effect. Currently, these functions
2648/// behave identically:
2649///
2650/// ```
2651/// #![feature(core_intrinsics)]
2652/// # #![allow(internal_features)]
2653/// use std::intrinsics::is_val_statically_known;
2654///
2655/// fn foo(x: &i32) -> bool {
2656/// is_val_statically_known(x)
2657/// }
2658///
2659/// fn bar(x: &i32) -> bool {
2660/// is_val_statically_known(
2661/// (x as *const i32).addr()
2662/// )
2663/// }
2664/// # _ = foo(&5_i32);
2665/// # _ = bar(&5_i32);
2666/// ```
2667#[rustc_const_stable_indirect]
2668#[rustc_nounwind]
2669#[unstable(feature = "core_intrinsics", issue = "none")]
2670#[rustc_intrinsic]
2671#[cfg(not(feature = "ferrocene_certified"))]
2672pub const fn is_val_statically_known<T: Copy>(_arg: T) -> bool {
2673 false
2674}
2675
2676/// Non-overlapping *typed* swap of a single value.
2677///
2678/// The codegen backends will replace this with a better implementation when
2679/// `T` is a simple type that can be loaded and stored as an immediate.
2680///
2681/// The stabilized form of this intrinsic is [`crate::mem::swap`].
2682///
2683/// # Safety
2684/// Behavior is undefined if any of the following conditions are violated:
2685///
2686/// * Both `x` and `y` must be [valid] for both reads and writes.
2687///
2688/// * Both `x` and `y` must be properly aligned.
2689///
2690/// * The region of memory beginning at `x` must *not* overlap with the region of memory
2691/// beginning at `y`.
2692///
2693/// * The memory pointed by `x` and `y` must both contain values of type `T`.
2694///
2695/// [valid]: crate::ptr#safety
2696#[rustc_nounwind]
2697#[inline]
2698#[rustc_intrinsic]
2699#[rustc_intrinsic_const_stable_indirect]
2700#[cfg(not(feature = "ferrocene_certified"))]
2701pub const unsafe fn typed_swap_nonoverlapping<T>(x: *mut T, y: *mut T) {
2702 // SAFETY: The caller provided single non-overlapping items behind
2703 // pointers, so swapping them with `count: 1` is fine.
2704 unsafe { ptr::swap_nonoverlapping(x, y, 1) };
2705}
2706
2707/// Returns whether we should perform some UB-checking at runtime. This eventually evaluates to
2708/// `cfg!(ub_checks)`, but behaves different from `cfg!` when mixing crates built with different
2709/// flags: if the crate has UB checks enabled or carries the `#[rustc_preserve_ub_checks]`
2710/// attribute, evaluation is delayed until monomorphization (or until the call gets inlined into
2711/// a crate that does not delay evaluation further); otherwise it can happen any time.
2712///
2713/// The common case here is a user program built with ub_checks linked against the distributed
2714/// sysroot which is built without ub_checks but with `#[rustc_preserve_ub_checks]`.
2715/// For code that gets monomorphized in the user crate (i.e., generic functions and functions with
2716/// `#[inline]`), gating assertions on `ub_checks()` rather than `cfg!(ub_checks)` means that
2717/// assertions are enabled whenever the *user crate* has UB checks enabled. However, if the
2718/// user has UB checks disabled, the checks will still get optimized out. This intrinsic is
2719/// primarily used by [`crate::ub_checks::assert_unsafe_precondition`].
2720#[rustc_intrinsic_const_stable_indirect] // just for UB checks
2721#[inline(always)]
2722#[rustc_intrinsic]
2723#[ferrocene::annotation(
2724 "This function is always used in `assert_unsafe_precondition` which produces an unwinding panic, meaning that we cannot cover it."
2725)]
2726pub const fn ub_checks() -> bool {
2727 cfg!(ub_checks)
2728}
2729
2730/// Allocates a block of memory at compile time.
2731/// At runtime, just returns a null pointer.
2732///
2733/// # Safety
2734///
2735/// - The `align` argument must be a power of two.
2736/// - At compile time, a compile error occurs if this constraint is violated.
2737/// - At runtime, it is not checked.
2738#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
2739#[rustc_nounwind]
2740#[rustc_intrinsic]
2741#[miri::intrinsic_fallback_is_spec]
2742#[cfg(not(feature = "ferrocene_certified"))]
2743pub const unsafe fn const_allocate(_size: usize, _align: usize) -> *mut u8 {
2744 // const eval overrides this function, but runtime code for now just returns null pointers.
2745 // See <https://github.com/rust-lang/rust/issues/93935>.
2746 crate::ptr::null_mut()
2747}
2748
2749/// Deallocates a memory which allocated by `intrinsics::const_allocate` at compile time.
2750/// At runtime, does nothing.
2751///
2752/// # Safety
2753///
2754/// - The `align` argument must be a power of two.
2755/// - At compile time, a compile error occurs if this constraint is violated.
2756/// - At runtime, it is not checked.
2757/// - If the `ptr` is created in an another const, this intrinsic doesn't deallocate it.
2758/// - If the `ptr` is pointing to a local variable, this intrinsic doesn't deallocate it.
2759#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
2760#[unstable(feature = "core_intrinsics", issue = "none")]
2761#[rustc_nounwind]
2762#[rustc_intrinsic]
2763#[miri::intrinsic_fallback_is_spec]
2764#[cfg(not(feature = "ferrocene_certified"))]
2765pub const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {
2766 // Runtime NOP
2767}
2768
2769#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
2770#[rustc_nounwind]
2771#[rustc_intrinsic]
2772#[miri::intrinsic_fallback_is_spec]
2773#[ferrocene::annotation("This function is also a noop in runtime so we can't cover it currently.")]
2774pub const unsafe fn const_make_global(ptr: *mut u8) -> *const u8 {
2775 // const eval overrides this function; at runtime, it is a NOP.
2776 ptr
2777}
2778
2779/// Check if the pre-condition `cond` has been met.
2780///
2781/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
2782/// returns false.
2783///
2784/// Note that this function is a no-op during constant evaluation.
2785#[unstable(feature = "contracts_internals", issue = "128044")]
2786// Calls to this function get inserted by an AST expansion pass, which uses the equivalent of
2787// `#[allow_internal_unstable]` to allow using `contracts_internals` functions. Const-checking
2788// doesn't honor `#[allow_internal_unstable]`, so for the const feature gate we use the user-facing
2789// `contracts` feature rather than the perma-unstable `contracts_internals`
2790#[rustc_const_unstable(feature = "contracts", issue = "128044")]
2791#[lang = "contract_check_requires"]
2792#[rustc_intrinsic]
2793#[cfg(not(feature = "ferrocene_certified"))]
2794pub const fn contract_check_requires<C: Fn() -> bool + Copy>(cond: C) {
2795 const_eval_select!(
2796 @capture[C: Fn() -> bool + Copy] { cond: C } :
2797 if const {
2798 // Do nothing
2799 } else {
2800 if !cond() {
2801 // Emit no unwind panic in case this was a safety requirement.
2802 crate::panicking::panic_nounwind("failed requires check");
2803 }
2804 }
2805 )
2806}
2807
2808/// Check if the post-condition `cond` has been met.
2809///
2810/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
2811/// returns false.
2812///
2813/// If `cond` is `None`, then no postcondition checking is performed.
2814///
2815/// Note that this function is a no-op during constant evaluation.
2816#[unstable(feature = "contracts_internals", issue = "128044")]
2817// Similar to `contract_check_requires`, we need to use the user-facing
2818// `contracts` feature rather than the perma-unstable `contracts_internals`.
2819// Const-checking doesn't honor allow_internal_unstable logic used by contract expansion.
2820#[rustc_const_unstable(feature = "contracts", issue = "128044")]
2821#[lang = "contract_check_ensures"]
2822#[rustc_intrinsic]
2823#[cfg(not(feature = "ferrocene_certified"))]
2824pub const fn contract_check_ensures<C: Fn(&Ret) -> bool + Copy, Ret>(
2825 cond: Option<C>,
2826 ret: Ret,
2827) -> Ret {
2828 const_eval_select!(
2829 @capture[C: Fn(&Ret) -> bool + Copy, Ret] { cond: Option<C>, ret: Ret } -> Ret :
2830 if const {
2831 // Do nothing
2832 ret
2833 } else {
2834 match cond {
2835 crate::option::Option::Some(cond) => {
2836 if !cond(&ret) {
2837 // Emit no unwind panic in case this was a safety requirement.
2838 crate::panicking::panic_nounwind("failed ensures check");
2839 }
2840 },
2841 crate::option::Option::None => {},
2842 }
2843 ret
2844 }
2845 )
2846}
2847
2848/// The intrinsic will return the size stored in that vtable.
2849///
2850/// # Safety
2851///
2852/// `ptr` must point to a vtable.
2853#[rustc_nounwind]
2854#[unstable(feature = "core_intrinsics", issue = "none")]
2855#[rustc_intrinsic]
2856#[cfg(not(feature = "ferrocene_certified"))]
2857pub unsafe fn vtable_size(ptr: *const ()) -> usize;
2858
2859/// The intrinsic will return the alignment stored in that vtable.
2860///
2861/// # Safety
2862///
2863/// `ptr` must point to a vtable.
2864#[rustc_nounwind]
2865#[unstable(feature = "core_intrinsics", issue = "none")]
2866#[rustc_intrinsic]
2867#[cfg(not(feature = "ferrocene_certified"))]
2868pub unsafe fn vtable_align(ptr: *const ()) -> usize;
2869
2870/// The size of a type in bytes.
2871///
2872/// Note that, unlike most intrinsics, this is safe to call;
2873/// it does not require an `unsafe` block.
2874/// Therefore, implementations must not require the user to uphold
2875/// any safety invariants.
2876///
2877/// More specifically, this is the offset in bytes between successive
2878/// items of the same type, including alignment padding.
2879///
2880/// Note that, unlike most intrinsics, this can only be called at compile-time
2881/// as backends do not have an implementation for it. The only caller (its
2882/// stable counterpart) wraps this intrinsic call in a `const` block so that
2883/// backends only see an evaluated constant.
2884///
2885/// The stabilized version of this intrinsic is [`core::mem::size_of`].
2886#[rustc_nounwind]
2887#[unstable(feature = "core_intrinsics", issue = "none")]
2888#[rustc_intrinsic_const_stable_indirect]
2889#[rustc_intrinsic]
2890pub const fn size_of<T>() -> usize;
2891
2892/// The minimum alignment of a type.
2893///
2894/// Note that, unlike most intrinsics, this is safe to call;
2895/// it does not require an `unsafe` block.
2896/// Therefore, implementations must not require the user to uphold
2897/// any safety invariants.
2898///
2899/// Note that, unlike most intrinsics, this can only be called at compile-time
2900/// as backends do not have an implementation for it. The only caller (its
2901/// stable counterpart) wraps this intrinsic call in a `const` block so that
2902/// backends only see an evaluated constant.
2903///
2904/// The stabilized version of this intrinsic is [`core::mem::align_of`].
2905#[rustc_nounwind]
2906#[unstable(feature = "core_intrinsics", issue = "none")]
2907#[rustc_intrinsic_const_stable_indirect]
2908#[rustc_intrinsic]
2909pub const fn align_of<T>() -> usize;
2910
2911/// Returns the number of variants of the type `T` cast to a `usize`;
2912/// if `T` has no variants, returns `0`. Uninhabited variants will be counted.
2913///
2914/// Note that, unlike most intrinsics, this can only be called at compile-time
2915/// as backends do not have an implementation for it. The only caller (its
2916/// stable counterpart) wraps this intrinsic call in a `const` block so that
2917/// backends only see an evaluated constant.
2918///
2919/// The to-be-stabilized version of this intrinsic is [`crate::mem::variant_count`].
2920#[rustc_nounwind]
2921#[unstable(feature = "core_intrinsics", issue = "none")]
2922#[rustc_intrinsic]
2923#[cfg(not(feature = "ferrocene_certified"))]
2924pub const fn variant_count<T>() -> usize;
2925
2926/// The size of the referenced value in bytes.
2927///
2928/// The stabilized version of this intrinsic is [`core::mem::size_of_val`].
2929///
2930/// # Safety
2931///
2932/// See [`crate::mem::size_of_val_raw`] for safety conditions.
2933#[rustc_nounwind]
2934#[unstable(feature = "core_intrinsics", issue = "none")]
2935#[rustc_intrinsic]
2936#[rustc_intrinsic_const_stable_indirect]
2937pub const unsafe fn size_of_val<T: ?Sized>(ptr: *const T) -> usize;
2938
2939/// The required alignment of the referenced value.
2940///
2941/// The stabilized version of this intrinsic is [`core::mem::align_of_val`].
2942///
2943/// # Safety
2944///
2945/// See [`crate::mem::align_of_val_raw`] for safety conditions.
2946#[rustc_nounwind]
2947#[unstable(feature = "core_intrinsics", issue = "none")]
2948#[rustc_intrinsic]
2949#[rustc_intrinsic_const_stable_indirect]
2950pub const unsafe fn align_of_val<T: ?Sized>(ptr: *const T) -> usize;
2951
2952/// Gets a static string slice containing the name of a type.
2953///
2954/// Note that, unlike most intrinsics, this can only be called at compile-time
2955/// as backends do not have an implementation for it. The only caller (its
2956/// stable counterpart) wraps this intrinsic call in a `const` block so that
2957/// backends only see an evaluated constant.
2958///
2959/// The stabilized version of this intrinsic is [`core::any::type_name`].
2960#[rustc_nounwind]
2961#[unstable(feature = "core_intrinsics", issue = "none")]
2962#[rustc_intrinsic]
2963pub const fn type_name<T: ?Sized>() -> &'static str;
2964
2965/// Gets an identifier which is globally unique to the specified type. This
2966/// function will return the same value for a type regardless of whichever
2967/// crate it is invoked in.
2968///
2969/// Note that, unlike most intrinsics, this can only be called at compile-time
2970/// as backends do not have an implementation for it. The only caller (its
2971/// stable counterpart) wraps this intrinsic call in a `const` block so that
2972/// backends only see an evaluated constant.
2973///
2974/// The stabilized version of this intrinsic is [`core::any::TypeId::of`].
2975#[rustc_nounwind]
2976#[unstable(feature = "core_intrinsics", issue = "none")]
2977#[rustc_intrinsic]
2978pub const fn type_id<T: ?Sized + 'static>() -> crate::any::TypeId;
2979
2980/// Tests (at compile-time) if two [`crate::any::TypeId`] instances identify the
2981/// same type. This is necessary because at const-eval time the actual discriminating
2982/// data is opaque and cannot be inspected directly.
2983///
2984/// The stabilized version of this intrinsic is the [PartialEq] impl for [`core::any::TypeId`].
2985#[rustc_nounwind]
2986#[unstable(feature = "core_intrinsics", issue = "none")]
2987#[rustc_intrinsic]
2988#[rustc_do_not_const_check]
2989#[ferrocene::annotation("Cannot be covered as this code cannot be reached during runtime.")]
2990pub const fn type_id_eq(a: crate::any::TypeId, b: crate::any::TypeId) -> bool {
2991 a.data == b.data
2992}
2993
2994/// Lowers in MIR to `Rvalue::Aggregate` with `AggregateKind::RawPtr`.
2995///
2996/// This is used to implement functions like `slice::from_raw_parts_mut` and
2997/// `ptr::from_raw_parts` in a way compatible with the compiler being able to
2998/// change the possible layouts of pointers.
2999#[rustc_nounwind]
3000#[unstable(feature = "core_intrinsics", issue = "none")]
3001#[rustc_intrinsic_const_stable_indirect]
3002#[rustc_intrinsic]
3003pub const fn aggregate_raw_ptr<P: bounds::BuiltinDeref, D, M>(data: D, meta: M) -> P
3004where
3005 <P as bounds::BuiltinDeref>::Pointee: ptr::Pointee<Metadata = M>;
3006
3007/// Lowers in MIR to `Rvalue::UnaryOp` with `UnOp::PtrMetadata`.
3008///
3009/// This is used to implement functions like `ptr::metadata`.
3010#[rustc_nounwind]
3011#[unstable(feature = "core_intrinsics", issue = "none")]
3012#[rustc_intrinsic_const_stable_indirect]
3013#[rustc_intrinsic]
3014pub const fn ptr_metadata<P: ptr::Pointee<Metadata = M> + PointeeSized, M>(ptr: *const P) -> M;
3015
3016/// This is an accidentally-stable alias to [`ptr::copy_nonoverlapping`]; use that instead.
3017// Note (intentionally not in the doc comment): `ptr::copy_nonoverlapping` adds some extra
3018// debug assertions; if you are writing compiler tests or code inside the standard library
3019// that wants to avoid those debug assertions, directly call this intrinsic instead.
3020#[stable(feature = "rust1", since = "1.0.0")]
3021#[rustc_allowed_through_unstable_modules = "import this function via `std::ptr` instead"]
3022#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
3023#[rustc_nounwind]
3024#[rustc_intrinsic]
3025pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
3026
3027/// This is an accidentally-stable alias to [`ptr::copy`]; use that instead.
3028// Note (intentionally not in the doc comment): `ptr::copy` adds some extra
3029// debug assertions; if you are writing compiler tests or code inside the standard library
3030// that wants to avoid those debug assertions, directly call this intrinsic instead.
3031#[stable(feature = "rust1", since = "1.0.0")]
3032#[rustc_allowed_through_unstable_modules = "import this function via `std::ptr` instead"]
3033#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
3034#[rustc_nounwind]
3035#[rustc_intrinsic]
3036pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize);
3037
3038/// This is an accidentally-stable alias to [`ptr::write_bytes`]; use that instead.
3039// Note (intentionally not in the doc comment): `ptr::write_bytes` adds some extra
3040// debug assertions; if you are writing compiler tests or code inside the standard library
3041// that wants to avoid those debug assertions, directly call this intrinsic instead.
3042#[stable(feature = "rust1", since = "1.0.0")]
3043#[rustc_allowed_through_unstable_modules = "import this function via `std::ptr` instead"]
3044#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
3045#[rustc_nounwind]
3046#[rustc_intrinsic]
3047pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
3048
3049/// Returns the minimum (IEEE 754-2008 minNum) of two `f16` values.
3050///
3051/// Note that, unlike most intrinsics, this is safe to call;
3052/// it does not require an `unsafe` block.
3053/// Therefore, implementations must not require the user to uphold
3054/// any safety invariants.
3055///
3056/// The stabilized version of this intrinsic is
3057/// [`f16::min`]
3058#[rustc_nounwind]
3059#[rustc_intrinsic]
3060#[cfg(not(feature = "ferrocene_certified"))]
3061pub const fn minnumf16(x: f16, y: f16) -> f16;
3062
3063/// Returns the minimum (IEEE 754-2008 minNum) of two `f32` values.
3064///
3065/// Note that, unlike most intrinsics, this is safe to call;
3066/// it does not require an `unsafe` block.
3067/// Therefore, implementations must not require the user to uphold
3068/// any safety invariants.
3069///
3070/// The stabilized version of this intrinsic is
3071/// [`f32::min`]
3072#[rustc_nounwind]
3073#[rustc_intrinsic_const_stable_indirect]
3074#[rustc_intrinsic]
3075#[cfg(not(feature = "ferrocene_certified"))]
3076pub const fn minnumf32(x: f32, y: f32) -> f32;
3077
3078/// Returns the minimum (IEEE 754-2008 minNum) of two `f64` values.
3079///
3080/// Note that, unlike most intrinsics, this is safe to call;
3081/// it does not require an `unsafe` block.
3082/// Therefore, implementations must not require the user to uphold
3083/// any safety invariants.
3084///
3085/// The stabilized version of this intrinsic is
3086/// [`f64::min`]
3087#[rustc_nounwind]
3088#[rustc_intrinsic_const_stable_indirect]
3089#[rustc_intrinsic]
3090#[cfg(not(feature = "ferrocene_certified"))]
3091pub const fn minnumf64(x: f64, y: f64) -> f64;
3092
3093/// Returns the minimum (IEEE 754-2008 minNum) of two `f128` values.
3094///
3095/// Note that, unlike most intrinsics, this is safe to call;
3096/// it does not require an `unsafe` block.
3097/// Therefore, implementations must not require the user to uphold
3098/// any safety invariants.
3099///
3100/// The stabilized version of this intrinsic is
3101/// [`f128::min`]
3102#[rustc_nounwind]
3103#[rustc_intrinsic]
3104#[cfg(not(feature = "ferrocene_certified"))]
3105pub const fn minnumf128(x: f128, y: f128) -> f128;
3106
3107/// Returns the minimum (IEEE 754-2019 minimum) of two `f16` values.
3108///
3109/// Note that, unlike most intrinsics, this is safe to call;
3110/// it does not require an `unsafe` block.
3111/// Therefore, implementations must not require the user to uphold
3112/// any safety invariants.
3113#[rustc_nounwind]
3114#[rustc_intrinsic]
3115#[cfg(not(feature = "ferrocene_certified"))]
3116pub const fn minimumf16(x: f16, y: f16) -> f16 {
3117 if x < y {
3118 x
3119 } else if y < x {
3120 y
3121 } else if x == y {
3122 if x.is_sign_negative() && y.is_sign_positive() { x } else { y }
3123 } else {
3124 // At least one input is NaN. Use `+` to perform NaN propagation and quieting.
3125 x + y
3126 }
3127}
3128
3129/// Returns the minimum (IEEE 754-2019 minimum) of two `f32` values.
3130///
3131/// Note that, unlike most intrinsics, this is safe to call;
3132/// it does not require an `unsafe` block.
3133/// Therefore, implementations must not require the user to uphold
3134/// any safety invariants.
3135#[rustc_nounwind]
3136#[rustc_intrinsic]
3137#[cfg(not(feature = "ferrocene_certified"))]
3138pub const fn minimumf32(x: f32, y: f32) -> f32 {
3139 if x < y {
3140 x
3141 } else if y < x {
3142 y
3143 } else if x == y {
3144 if x.is_sign_negative() && y.is_sign_positive() { x } else { y }
3145 } else {
3146 // At least one input is NaN. Use `+` to perform NaN propagation and quieting.
3147 x + y
3148 }
3149}
3150
3151/// Returns the minimum (IEEE 754-2019 minimum) of two `f64` values.
3152///
3153/// Note that, unlike most intrinsics, this is safe to call;
3154/// it does not require an `unsafe` block.
3155/// Therefore, implementations must not require the user to uphold
3156/// any safety invariants.
3157#[rustc_nounwind]
3158#[rustc_intrinsic]
3159#[cfg(not(feature = "ferrocene_certified"))]
3160pub const fn minimumf64(x: f64, y: f64) -> f64 {
3161 if x < y {
3162 x
3163 } else if y < x {
3164 y
3165 } else if x == y {
3166 if x.is_sign_negative() && y.is_sign_positive() { x } else { y }
3167 } else {
3168 // At least one input is NaN. Use `+` to perform NaN propagation and quieting.
3169 x + y
3170 }
3171}
3172
3173/// Returns the minimum (IEEE 754-2019 minimum) of two `f128` values.
3174///
3175/// Note that, unlike most intrinsics, this is safe to call;
3176/// it does not require an `unsafe` block.
3177/// Therefore, implementations must not require the user to uphold
3178/// any safety invariants.
3179#[rustc_nounwind]
3180#[rustc_intrinsic]
3181#[cfg(not(feature = "ferrocene_certified"))]
3182pub const fn minimumf128(x: f128, y: f128) -> f128 {
3183 if x < y {
3184 x
3185 } else if y < x {
3186 y
3187 } else if x == y {
3188 if x.is_sign_negative() && y.is_sign_positive() { x } else { y }
3189 } else {
3190 // At least one input is NaN. Use `+` to perform NaN propagation and quieting.
3191 x + y
3192 }
3193}
3194
3195/// Returns the maximum (IEEE 754-2008 maxNum) of two `f16` values.
3196///
3197/// Note that, unlike most intrinsics, this is safe to call;
3198/// it does not require an `unsafe` block.
3199/// Therefore, implementations must not require the user to uphold
3200/// any safety invariants.
3201///
3202/// The stabilized version of this intrinsic is
3203/// [`f16::max`]
3204#[rustc_nounwind]
3205#[rustc_intrinsic]
3206#[cfg(not(feature = "ferrocene_certified"))]
3207pub const fn maxnumf16(x: f16, y: f16) -> f16;
3208
3209/// Returns the maximum (IEEE 754-2008 maxNum) of two `f32` values.
3210///
3211/// Note that, unlike most intrinsics, this is safe to call;
3212/// it does not require an `unsafe` block.
3213/// Therefore, implementations must not require the user to uphold
3214/// any safety invariants.
3215///
3216/// The stabilized version of this intrinsic is
3217/// [`f32::max`]
3218#[rustc_nounwind]
3219#[rustc_intrinsic_const_stable_indirect]
3220#[rustc_intrinsic]
3221#[cfg(not(feature = "ferrocene_certified"))]
3222pub const fn maxnumf32(x: f32, y: f32) -> f32;
3223
3224/// Returns the maximum (IEEE 754-2008 maxNum) of two `f64` values.
3225///
3226/// Note that, unlike most intrinsics, this is safe to call;
3227/// it does not require an `unsafe` block.
3228/// Therefore, implementations must not require the user to uphold
3229/// any safety invariants.
3230///
3231/// The stabilized version of this intrinsic is
3232/// [`f64::max`]
3233#[rustc_nounwind]
3234#[rustc_intrinsic_const_stable_indirect]
3235#[rustc_intrinsic]
3236#[cfg(not(feature = "ferrocene_certified"))]
3237pub const fn maxnumf64(x: f64, y: f64) -> f64;
3238
3239/// Returns the maximum (IEEE 754-2008 maxNum) of two `f128` values.
3240///
3241/// Note that, unlike most intrinsics, this is safe to call;
3242/// it does not require an `unsafe` block.
3243/// Therefore, implementations must not require the user to uphold
3244/// any safety invariants.
3245///
3246/// The stabilized version of this intrinsic is
3247/// [`f128::max`]
3248#[rustc_nounwind]
3249#[rustc_intrinsic]
3250#[cfg(not(feature = "ferrocene_certified"))]
3251pub const fn maxnumf128(x: f128, y: f128) -> f128;
3252
3253/// Returns the maximum (IEEE 754-2019 maximum) of two `f16` values.
3254///
3255/// Note that, unlike most intrinsics, this is safe to call;
3256/// it does not require an `unsafe` block.
3257/// Therefore, implementations must not require the user to uphold
3258/// any safety invariants.
3259#[rustc_nounwind]
3260#[rustc_intrinsic]
3261#[cfg(not(feature = "ferrocene_certified"))]
3262pub const fn maximumf16(x: f16, y: f16) -> f16 {
3263 if x > y {
3264 x
3265 } else if y > x {
3266 y
3267 } else if x == y {
3268 if x.is_sign_positive() && y.is_sign_negative() { x } else { y }
3269 } else {
3270 x + y
3271 }
3272}
3273
3274/// Returns the maximum (IEEE 754-2019 maximum) of two `f32` values.
3275///
3276/// Note that, unlike most intrinsics, this is safe to call;
3277/// it does not require an `unsafe` block.
3278/// Therefore, implementations must not require the user to uphold
3279/// any safety invariants.
3280#[rustc_nounwind]
3281#[rustc_intrinsic]
3282#[cfg(not(feature = "ferrocene_certified"))]
3283pub const fn maximumf32(x: f32, y: f32) -> f32 {
3284 if x > y {
3285 x
3286 } else if y > x {
3287 y
3288 } else if x == y {
3289 if x.is_sign_positive() && y.is_sign_negative() { x } else { y }
3290 } else {
3291 x + y
3292 }
3293}
3294
3295/// Returns the maximum (IEEE 754-2019 maximum) of two `f64` values.
3296///
3297/// Note that, unlike most intrinsics, this is safe to call;
3298/// it does not require an `unsafe` block.
3299/// Therefore, implementations must not require the user to uphold
3300/// any safety invariants.
3301#[rustc_nounwind]
3302#[rustc_intrinsic]
3303#[cfg(not(feature = "ferrocene_certified"))]
3304pub const fn maximumf64(x: f64, y: f64) -> f64 {
3305 if x > y {
3306 x
3307 } else if y > x {
3308 y
3309 } else if x == y {
3310 if x.is_sign_positive() && y.is_sign_negative() { x } else { y }
3311 } else {
3312 x + y
3313 }
3314}
3315
3316/// Returns the maximum (IEEE 754-2019 maximum) of two `f128` values.
3317///
3318/// Note that, unlike most intrinsics, this is safe to call;
3319/// it does not require an `unsafe` block.
3320/// Therefore, implementations must not require the user to uphold
3321/// any safety invariants.
3322#[rustc_nounwind]
3323#[rustc_intrinsic]
3324#[cfg(not(feature = "ferrocene_certified"))]
3325pub const fn maximumf128(x: f128, y: f128) -> f128 {
3326 if x > y {
3327 x
3328 } else if y > x {
3329 y
3330 } else if x == y {
3331 if x.is_sign_positive() && y.is_sign_negative() { x } else { y }
3332 } else {
3333 x + y
3334 }
3335}
3336
3337/// Returns the absolute value of an `f16`.
3338///
3339/// The stabilized version of this intrinsic is
3340/// [`f16::abs`](../../std/primitive.f16.html#method.abs)
3341#[rustc_nounwind]
3342#[rustc_intrinsic]
3343#[cfg(not(feature = "ferrocene_certified"))]
3344pub const fn fabsf16(x: f16) -> f16;
3345
3346/// Returns the absolute value of an `f32`.
3347///
3348/// The stabilized version of this intrinsic is
3349/// [`f32::abs`](../../std/primitive.f32.html#method.abs)
3350#[rustc_nounwind]
3351#[rustc_intrinsic_const_stable_indirect]
3352#[rustc_intrinsic]
3353#[cfg(not(feature = "ferrocene_certified"))]
3354pub const fn fabsf32(x: f32) -> f32;
3355
3356/// Returns the absolute value of an `f64`.
3357///
3358/// The stabilized version of this intrinsic is
3359/// [`f64::abs`](../../std/primitive.f64.html#method.abs)
3360#[rustc_nounwind]
3361#[rustc_intrinsic_const_stable_indirect]
3362#[rustc_intrinsic]
3363#[cfg(not(feature = "ferrocene_certified"))]
3364pub const fn fabsf64(x: f64) -> f64;
3365
3366/// Returns the absolute value of an `f128`.
3367///
3368/// The stabilized version of this intrinsic is
3369/// [`f128::abs`](../../std/primitive.f128.html#method.abs)
3370#[rustc_nounwind]
3371#[rustc_intrinsic]
3372#[cfg(not(feature = "ferrocene_certified"))]
3373pub const fn fabsf128(x: f128) -> f128;
3374
3375/// Copies the sign from `y` to `x` for `f16` values.
3376///
3377/// The stabilized version of this intrinsic is
3378/// [`f16::copysign`](../../std/primitive.f16.html#method.copysign)
3379#[rustc_nounwind]
3380#[rustc_intrinsic]
3381#[cfg(not(feature = "ferrocene_certified"))]
3382pub const fn copysignf16(x: f16, y: f16) -> f16;
3383
3384/// Copies the sign from `y` to `x` for `f32` values.
3385///
3386/// The stabilized version of this intrinsic is
3387/// [`f32::copysign`](../../std/primitive.f32.html#method.copysign)
3388#[rustc_nounwind]
3389#[rustc_intrinsic_const_stable_indirect]
3390#[rustc_intrinsic]
3391#[cfg(not(feature = "ferrocene_certified"))]
3392pub const fn copysignf32(x: f32, y: f32) -> f32;
3393/// Copies the sign from `y` to `x` for `f64` values.
3394///
3395/// The stabilized version of this intrinsic is
3396/// [`f64::copysign`](../../std/primitive.f64.html#method.copysign)
3397#[rustc_nounwind]
3398#[rustc_intrinsic_const_stable_indirect]
3399#[rustc_intrinsic]
3400#[cfg(not(feature = "ferrocene_certified"))]
3401pub const fn copysignf64(x: f64, y: f64) -> f64;
3402
3403/// Copies the sign from `y` to `x` for `f128` values.
3404///
3405/// The stabilized version of this intrinsic is
3406/// [`f128::copysign`](../../std/primitive.f128.html#method.copysign)
3407#[rustc_nounwind]
3408#[rustc_intrinsic]
3409#[cfg(not(feature = "ferrocene_certified"))]
3410pub const fn copysignf128(x: f128, y: f128) -> f128;
3411
3412/// Generates the LLVM body for the automatic differentiation of `f` using Enzyme,
3413/// with `df` as the derivative function and `args` as its arguments.
3414///
3415/// Used internally as the body of `df` when expanding the `#[autodiff_forward]`
3416/// and `#[autodiff_reverse]` attribute macros.
3417///
3418/// Type Parameters:
3419/// - `F`: The original function to differentiate. Must be a function item.
3420/// - `G`: The derivative function. Must be a function item.
3421/// - `T`: A tuple of arguments passed to `df`.
3422/// - `R`: The return type of the derivative function.
3423///
3424/// This shows where the `autodiff` intrinsic is used during macro expansion:
3425///
3426/// ```rust,ignore (macro example)
3427/// #[autodiff_forward(df1, Dual, Const, Dual)]
3428/// pub fn f1(x: &[f64], y: f64) -> f64 {
3429/// unimplemented!()
3430/// }
3431/// ```
3432///
3433/// expands to:
3434///
3435/// ```rust,ignore (macro example)
3436/// #[rustc_autodiff]
3437/// #[inline(never)]
3438/// pub fn f1(x: &[f64], y: f64) -> f64 {
3439/// ::core::panicking::panic("not implemented")
3440/// }
3441/// #[rustc_autodiff(Forward, 1, Dual, Const, Dual)]
3442/// pub fn df1(x: &[f64], bx_0: &[f64], y: f64) -> (f64, f64) {
3443/// ::core::intrinsics::autodiff(f1::<>, df1::<>, (x, bx_0, y))
3444/// }
3445/// ```
3446#[rustc_nounwind]
3447#[rustc_intrinsic]
3448pub const fn autodiff<F, G, T: crate::marker::Tuple, R>(f: F, df: G, args: T) -> R;
3449
3450/// Inform Miri that a given pointer definitely has a certain alignment.
3451#[cfg(miri)]
3452#[rustc_allow_const_fn_unstable(const_eval_select)]
3453#[cfg(not(feature = "ferrocene_certified"))]
3454pub(crate) const fn miri_promise_symbolic_alignment(ptr: *const (), align: usize) {
3455 unsafe extern "Rust" {
3456 /// Miri-provided extern function to promise that a given pointer is properly aligned for
3457 /// "symbolic" alignment checks. Will fail if the pointer is not actually aligned or `align` is
3458 /// not a power of two. Has no effect when alignment checks are concrete (which is the default).
3459 fn miri_promise_symbolic_alignment(ptr: *const (), align: usize);
3460 }
3461
3462 const_eval_select!(
3463 @capture { ptr: *const (), align: usize}:
3464 if const {
3465 // Do nothing.
3466 } else {
3467 // SAFETY: this call is always safe.
3468 unsafe {
3469 miri_promise_symbolic_alignment(ptr, align);
3470 }
3471 }
3472 )
3473}
3474
3475/// Copies the current location of arglist `src` to the arglist `dst`.
3476///
3477/// FIXME: document safety requirements
3478#[rustc_intrinsic]
3479#[rustc_nounwind]
3480#[cfg(not(feature = "ferrocene_certified"))]
3481pub unsafe fn va_copy<'f>(dest: *mut VaListImpl<'f>, src: &VaListImpl<'f>);
3482
3483/// Loads an argument of type `T` from the `va_list` `ap` and increment the
3484/// argument `ap` points to.
3485///
3486/// FIXME: document safety requirements
3487#[rustc_intrinsic]
3488#[rustc_nounwind]
3489#[cfg(not(feature = "ferrocene_certified"))]
3490pub unsafe fn va_arg<T: VaArgSafe>(ap: &mut VaListImpl<'_>) -> T;
3491
3492/// Destroy the arglist `ap` after initialization with `va_start` or `va_copy`.
3493///
3494/// FIXME: document safety requirements
3495#[rustc_intrinsic]
3496#[rustc_nounwind]
3497#[cfg(not(feature = "ferrocene_certified"))]
3498pub unsafe fn va_end(ap: &mut VaListImpl<'_>);