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