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