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