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