core/intrinsics/
mod.rs

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