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