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