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