Skip to main content

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