core/intrinsics/
mod.rs

1//! Compiler intrinsics.
2//!
3//! The corresponding definitions are in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/intrinsic.rs>.
4//! The corresponding const implementations are in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs>.
5//!
6//! # Const intrinsics
7//!
8//! Note: any changes to the constness of intrinsics should be discussed with the language team.
9//! This includes changes in the stability of the constness.
10//!
11//! In order to make an intrinsic usable at compile-time, it needs to be declared in the "new"
12//! style, i.e. as a `#[rustc_intrinsic]` function, not inside an `extern` block. Then copy the
13//! implementation from <https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics> to
14//! <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs>
15//! and make the intrinsic declaration a `const fn`.
16//!
17//! If an intrinsic is supposed to be used from a `const fn` with a `rustc_const_stable` attribute,
18//! `#[rustc_intrinsic_const_stable_indirect]` needs to be added to the intrinsic. Such a change requires
19//! T-lang approval, because it may bake a feature into the language that cannot be replicated in
20//! user code without compiler support.
21//!
22//! # Volatiles
23//!
24//! The volatile intrinsics provide operations intended to act on I/O
25//! memory, which are guaranteed to not be reordered by the compiler
26//! across other volatile intrinsics. See the LLVM documentation on
27//! [[volatile]].
28//!
29//! [volatile]: https://llvm.org/docs/LangRef.html#volatile-memory-accesses
30//!
31//! # Atomics
32//!
33//! The atomic intrinsics provide common atomic operations on machine
34//! words, with multiple possible memory orderings. They obey the same
35//! semantics as C++11. See the LLVM documentation on [[atomics]].
36//!
37//! [atomics]: https://llvm.org/docs/Atomics.html
38//!
39//! A quick refresher on memory ordering:
40//!
41//! * Acquire - a barrier for acquiring a lock. Subsequent reads and writes
42//!   take place after the barrier.
43//! * Release - a barrier for releasing a lock. Preceding reads and writes
44//!   take place before the barrier.
45//! * Sequentially consistent - sequentially consistent operations are
46//!   guaranteed to happen in order. This is the standard mode for working
47//!   with atomic types and is equivalent to Java's `volatile`.
48//!
49//! # Unwinding
50//!
51//! Rust intrinsics may, in general, unwind. If an intrinsic can never unwind, add the
52//! `#[rustc_nounwind]` attribute so that the compiler can make use of this fact.
53//!
54//! However, even for intrinsics that may unwind, rustc assumes that a Rust intrinsics will never
55//! initiate a foreign (non-Rust) unwind, and thus for panic=abort we can always assume that these
56//! intrinsics cannot unwind.
57
58#![unstable(
59    feature = "core_intrinsics",
60    reason = "intrinsics are unlikely to ever be stabilized, instead \
61                      they should be used through stabilized interfaces \
62                      in the rest of the standard library",
63    issue = "none"
64)]
65#![allow(missing_docs)]
66
67use crate::marker::{DiscriminantKind, Tuple};
68use crate::mem::SizedTypeProperties;
69use crate::{ptr, ub_checks};
70
71pub mod fallback;
72pub mod mir;
73pub mod simd;
74
75// These imports are used for simplifying intra-doc links
76#[allow(unused_imports)]
77#[cfg(all(target_has_atomic = "8", target_has_atomic = "32", target_has_atomic = "ptr"))]
78use crate::sync::atomic::{self, AtomicBool, AtomicI32, AtomicIsize, AtomicU32, Ordering};
79
80#[stable(feature = "drop_in_place", since = "1.8.0")]
81#[cfg_attr(bootstrap, rustc_allowed_through_unstable_modules)]
82#[cfg_attr(
83    not(bootstrap),
84    rustc_allowed_through_unstable_modules = "import this function via `std::ptr` instead"
85)]
86#[deprecated(note = "no longer an intrinsic - use `ptr::drop_in_place` directly", since = "1.52.0")]
87#[inline]
88pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
89    // SAFETY: see `ptr::drop_in_place`
90    unsafe { crate::ptr::drop_in_place(to_drop) }
91}
92
93// N.B., these intrinsics take raw pointers because they mutate aliased
94// memory, which is not valid for either `&` or `&mut`.
95
96/// Stores a value if the current value is the same as the `old` value.
97///
98/// The stabilized version of this intrinsic is available on the
99/// [`atomic`] types via the `compare_exchange` method by passing
100/// [`Ordering::Relaxed`] as both the success and failure parameters.
101/// For example, [`AtomicBool::compare_exchange`].
102#[rustc_intrinsic]
103#[rustc_intrinsic_must_be_overridden]
104#[rustc_nounwind]
105pub unsafe fn atomic_cxchg_relaxed_relaxed<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
106    unreachable!()
107}
108/// Stores a value if the current value is the same as the `old` value.
109///
110/// The stabilized version of this intrinsic is available on the
111/// [`atomic`] types via the `compare_exchange` method by passing
112/// [`Ordering::Relaxed`] and [`Ordering::Acquire`] as the success and failure parameters.
113/// For example, [`AtomicBool::compare_exchange`].
114#[rustc_intrinsic]
115#[rustc_intrinsic_must_be_overridden]
116#[rustc_nounwind]
117pub unsafe fn atomic_cxchg_relaxed_acquire<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
118    unreachable!()
119}
120/// Stores a value if the current value is the same as the `old` value.
121///
122/// The stabilized version of this intrinsic is available on the
123/// [`atomic`] types via the `compare_exchange` method by passing
124/// [`Ordering::Relaxed`] and [`Ordering::SeqCst`] as the success and failure parameters.
125/// For example, [`AtomicBool::compare_exchange`].
126#[rustc_intrinsic]
127#[rustc_intrinsic_must_be_overridden]
128#[rustc_nounwind]
129pub unsafe fn atomic_cxchg_relaxed_seqcst<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
130    unreachable!()
131}
132/// Stores a value if the current value is the same as the `old` value.
133///
134/// The stabilized version of this intrinsic is available on the
135/// [`atomic`] types via the `compare_exchange` method by passing
136/// [`Ordering::Acquire`] and [`Ordering::Relaxed`] as the success and failure parameters.
137/// For example, [`AtomicBool::compare_exchange`].
138#[rustc_intrinsic]
139#[rustc_intrinsic_must_be_overridden]
140#[rustc_nounwind]
141pub unsafe fn atomic_cxchg_acquire_relaxed<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
142    unreachable!()
143}
144/// Stores a value if the current value is the same as the `old` value.
145///
146/// The stabilized version of this intrinsic is available on the
147/// [`atomic`] types via the `compare_exchange` method by passing
148/// [`Ordering::Acquire`] as both the success and failure parameters.
149/// For example, [`AtomicBool::compare_exchange`].
150#[rustc_intrinsic]
151#[rustc_intrinsic_must_be_overridden]
152#[rustc_nounwind]
153pub unsafe fn atomic_cxchg_acquire_acquire<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
154    unreachable!()
155}
156/// Stores a value if the current value is the same as the `old` value.
157///
158/// The stabilized version of this intrinsic is available on the
159/// [`atomic`] types via the `compare_exchange` method by passing
160/// [`Ordering::Acquire`] and [`Ordering::SeqCst`] as the success and failure parameters.
161/// For example, [`AtomicBool::compare_exchange`].
162#[rustc_intrinsic]
163#[rustc_intrinsic_must_be_overridden]
164#[rustc_nounwind]
165pub unsafe fn atomic_cxchg_acquire_seqcst<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
166    unreachable!()
167}
168/// Stores a value if the current value is the same as the `old` value.
169///
170/// The stabilized version of this intrinsic is available on the
171/// [`atomic`] types via the `compare_exchange` method by passing
172/// [`Ordering::Release`] and [`Ordering::Relaxed`] as the success and failure parameters.
173/// For example, [`AtomicBool::compare_exchange`].
174#[rustc_intrinsic]
175#[rustc_intrinsic_must_be_overridden]
176#[rustc_nounwind]
177pub unsafe fn atomic_cxchg_release_relaxed<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
178    unreachable!()
179}
180/// Stores a value if the current value is the same as the `old` value.
181///
182/// The stabilized version of this intrinsic is available on the
183/// [`atomic`] types via the `compare_exchange` method by passing
184/// [`Ordering::Release`] and [`Ordering::Acquire`] as the success and failure parameters.
185/// For example, [`AtomicBool::compare_exchange`].
186#[rustc_intrinsic]
187#[rustc_intrinsic_must_be_overridden]
188#[rustc_nounwind]
189pub unsafe fn atomic_cxchg_release_acquire<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
190    unreachable!()
191}
192/// Stores a value if the current value is the same as the `old` value.
193///
194/// The stabilized version of this intrinsic is available on the
195/// [`atomic`] types via the `compare_exchange` method by passing
196/// [`Ordering::Release`] and [`Ordering::SeqCst`] as the success and failure parameters.
197/// For example, [`AtomicBool::compare_exchange`].
198#[rustc_intrinsic]
199#[rustc_intrinsic_must_be_overridden]
200#[rustc_nounwind]
201pub unsafe fn atomic_cxchg_release_seqcst<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
202    unreachable!()
203}
204/// Stores a value if the current value is the same as the `old` value.
205///
206/// The stabilized version of this intrinsic is available on the
207/// [`atomic`] types via the `compare_exchange` method by passing
208/// [`Ordering::AcqRel`] and [`Ordering::Relaxed`] as the success and failure parameters.
209/// For example, [`AtomicBool::compare_exchange`].
210#[rustc_intrinsic]
211#[rustc_intrinsic_must_be_overridden]
212#[rustc_nounwind]
213pub unsafe fn atomic_cxchg_acqrel_relaxed<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
214    unreachable!()
215}
216/// Stores a value if the current value is the same as the `old` value.
217///
218/// The stabilized version of this intrinsic is available on the
219/// [`atomic`] types via the `compare_exchange` method by passing
220/// [`Ordering::AcqRel`] and [`Ordering::Acquire`] as the success and failure parameters.
221/// For example, [`AtomicBool::compare_exchange`].
222#[rustc_intrinsic]
223#[rustc_intrinsic_must_be_overridden]
224#[rustc_nounwind]
225pub unsafe fn atomic_cxchg_acqrel_acquire<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
226    unreachable!()
227}
228/// Stores a value if the current value is the same as the `old` value.
229///
230/// The stabilized version of this intrinsic is available on the
231/// [`atomic`] types via the `compare_exchange` method by passing
232/// [`Ordering::AcqRel`] and [`Ordering::SeqCst`] as the success and failure parameters.
233/// For example, [`AtomicBool::compare_exchange`].
234#[rustc_intrinsic]
235#[rustc_intrinsic_must_be_overridden]
236#[rustc_nounwind]
237pub unsafe fn atomic_cxchg_acqrel_seqcst<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
238    unreachable!()
239}
240/// Stores a value if the current value is the same as the `old` value.
241///
242/// The stabilized version of this intrinsic is available on the
243/// [`atomic`] types via the `compare_exchange` method by passing
244/// [`Ordering::SeqCst`] and [`Ordering::Relaxed`] as the success and failure parameters.
245/// For example, [`AtomicBool::compare_exchange`].
246#[rustc_intrinsic]
247#[rustc_intrinsic_must_be_overridden]
248#[rustc_nounwind]
249pub unsafe fn atomic_cxchg_seqcst_relaxed<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
250    unreachable!()
251}
252/// Stores a value if the current value is the same as the `old` value.
253///
254/// The stabilized version of this intrinsic is available on the
255/// [`atomic`] types via the `compare_exchange` method by passing
256/// [`Ordering::SeqCst`] and [`Ordering::Acquire`] as the success and failure parameters.
257/// For example, [`AtomicBool::compare_exchange`].
258#[rustc_intrinsic]
259#[rustc_intrinsic_must_be_overridden]
260#[rustc_nounwind]
261pub unsafe fn atomic_cxchg_seqcst_acquire<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
262    unreachable!()
263}
264/// Stores a value if the current value is the same as the `old` value.
265///
266/// The stabilized version of this intrinsic is available on the
267/// [`atomic`] types via the `compare_exchange` method by passing
268/// [`Ordering::SeqCst`] as both the success and failure parameters.
269/// For example, [`AtomicBool::compare_exchange`].
270#[rustc_intrinsic]
271#[rustc_intrinsic_must_be_overridden]
272#[rustc_nounwind]
273pub unsafe fn atomic_cxchg_seqcst_seqcst<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
274    unreachable!()
275}
276
277/// Stores a value if the current value is the same as the `old` value.
278///
279/// The stabilized version of this intrinsic is available on the
280/// [`atomic`] types via the `compare_exchange_weak` method by passing
281/// [`Ordering::Relaxed`] as both the success and failure parameters.
282/// For example, [`AtomicBool::compare_exchange_weak`].
283#[rustc_intrinsic]
284#[rustc_intrinsic_must_be_overridden]
285#[rustc_nounwind]
286pub unsafe fn atomic_cxchgweak_relaxed_relaxed<T: Copy>(
287    _dst: *mut T,
288    _old: T,
289    _src: T,
290) -> (T, bool) {
291    unreachable!()
292}
293/// Stores a value if the current value is the same as the `old` value.
294///
295/// The stabilized version of this intrinsic is available on the
296/// [`atomic`] types via the `compare_exchange_weak` method by passing
297/// [`Ordering::Relaxed`] and [`Ordering::Acquire`] as the success and failure parameters.
298/// For example, [`AtomicBool::compare_exchange_weak`].
299#[rustc_intrinsic]
300#[rustc_intrinsic_must_be_overridden]
301#[rustc_nounwind]
302pub unsafe fn atomic_cxchgweak_relaxed_acquire<T: Copy>(
303    _dst: *mut T,
304    _old: T,
305    _src: T,
306) -> (T, bool) {
307    unreachable!()
308}
309/// Stores a value if the current value is the same as the `old` value.
310///
311/// The stabilized version of this intrinsic is available on the
312/// [`atomic`] types via the `compare_exchange_weak` method by passing
313/// [`Ordering::Relaxed`] and [`Ordering::SeqCst`] as the success and failure parameters.
314/// For example, [`AtomicBool::compare_exchange_weak`].
315#[rustc_intrinsic]
316#[rustc_intrinsic_must_be_overridden]
317#[rustc_nounwind]
318pub unsafe fn atomic_cxchgweak_relaxed_seqcst<T: Copy>(
319    _dst: *mut T,
320    _old: T,
321    _src: T,
322) -> (T, bool) {
323    unreachable!()
324}
325/// Stores a value if the current value is the same as the `old` value.
326///
327/// The stabilized version of this intrinsic is available on the
328/// [`atomic`] types via the `compare_exchange_weak` method by passing
329/// [`Ordering::Acquire`] and [`Ordering::Relaxed`] as the success and failure parameters.
330/// For example, [`AtomicBool::compare_exchange_weak`].
331#[rustc_intrinsic]
332#[rustc_intrinsic_must_be_overridden]
333#[rustc_nounwind]
334pub unsafe fn atomic_cxchgweak_acquire_relaxed<T: Copy>(
335    _dst: *mut T,
336    _old: T,
337    _src: T,
338) -> (T, bool) {
339    unreachable!()
340}
341/// Stores a value if the current value is the same as the `old` value.
342///
343/// The stabilized version of this intrinsic is available on the
344/// [`atomic`] types via the `compare_exchange_weak` method by passing
345/// [`Ordering::Acquire`] as both the success and failure parameters.
346/// For example, [`AtomicBool::compare_exchange_weak`].
347#[rustc_intrinsic]
348#[rustc_intrinsic_must_be_overridden]
349#[rustc_nounwind]
350pub unsafe fn atomic_cxchgweak_acquire_acquire<T: Copy>(
351    _dst: *mut T,
352    _old: T,
353    _src: T,
354) -> (T, bool) {
355    unreachable!()
356}
357/// Stores a value if the current value is the same as the `old` value.
358///
359/// The stabilized version of this intrinsic is available on the
360/// [`atomic`] types via the `compare_exchange_weak` method by passing
361/// [`Ordering::Acquire`] and [`Ordering::SeqCst`] as the success and failure parameters.
362/// For example, [`AtomicBool::compare_exchange_weak`].
363#[rustc_intrinsic]
364#[rustc_intrinsic_must_be_overridden]
365#[rustc_nounwind]
366pub unsafe fn atomic_cxchgweak_acquire_seqcst<T: Copy>(
367    _dst: *mut T,
368    _old: T,
369    _src: T,
370) -> (T, bool) {
371    unreachable!()
372}
373/// Stores a value if the current value is the same as the `old` value.
374///
375/// The stabilized version of this intrinsic is available on the
376/// [`atomic`] types via the `compare_exchange_weak` method by passing
377/// [`Ordering::Release`] and [`Ordering::Relaxed`] as the success and failure parameters.
378/// For example, [`AtomicBool::compare_exchange_weak`].
379#[rustc_intrinsic]
380#[rustc_intrinsic_must_be_overridden]
381#[rustc_nounwind]
382pub unsafe fn atomic_cxchgweak_release_relaxed<T: Copy>(
383    _dst: *mut T,
384    _old: T,
385    _src: T,
386) -> (T, bool) {
387    unreachable!()
388}
389/// Stores a value if the current value is the same as the `old` value.
390///
391/// The stabilized version of this intrinsic is available on the
392/// [`atomic`] types via the `compare_exchange_weak` method by passing
393/// [`Ordering::Release`] and [`Ordering::Acquire`] as the success and failure parameters.
394/// For example, [`AtomicBool::compare_exchange_weak`].
395#[rustc_intrinsic]
396#[rustc_intrinsic_must_be_overridden]
397#[rustc_nounwind]
398pub unsafe fn atomic_cxchgweak_release_acquire<T: Copy>(
399    _dst: *mut T,
400    _old: T,
401    _src: T,
402) -> (T, bool) {
403    unreachable!()
404}
405/// Stores a value if the current value is the same as the `old` value.
406///
407/// The stabilized version of this intrinsic is available on the
408/// [`atomic`] types via the `compare_exchange_weak` method by passing
409/// [`Ordering::Release`] and [`Ordering::SeqCst`] as the success and failure parameters.
410/// For example, [`AtomicBool::compare_exchange_weak`].
411#[rustc_intrinsic]
412#[rustc_intrinsic_must_be_overridden]
413#[rustc_nounwind]
414pub unsafe fn atomic_cxchgweak_release_seqcst<T: Copy>(
415    _dst: *mut T,
416    _old: T,
417    _src: T,
418) -> (T, bool) {
419    unreachable!()
420}
421/// Stores a value if the current value is the same as the `old` value.
422///
423/// The stabilized version of this intrinsic is available on the
424/// [`atomic`] types via the `compare_exchange_weak` method by passing
425/// [`Ordering::AcqRel`] and [`Ordering::Relaxed`] as the success and failure parameters.
426/// For example, [`AtomicBool::compare_exchange_weak`].
427#[rustc_intrinsic]
428#[rustc_intrinsic_must_be_overridden]
429#[rustc_nounwind]
430pub unsafe fn atomic_cxchgweak_acqrel_relaxed<T: Copy>(
431    _dst: *mut T,
432    _old: T,
433    _src: T,
434) -> (T, bool) {
435    unreachable!()
436}
437/// Stores a value if the current value is the same as the `old` value.
438///
439/// The stabilized version of this intrinsic is available on the
440/// [`atomic`] types via the `compare_exchange_weak` method by passing
441/// [`Ordering::AcqRel`] and [`Ordering::Acquire`] as the success and failure parameters.
442/// For example, [`AtomicBool::compare_exchange_weak`].
443#[rustc_intrinsic]
444#[rustc_intrinsic_must_be_overridden]
445#[rustc_nounwind]
446pub unsafe fn atomic_cxchgweak_acqrel_acquire<T: Copy>(
447    _dst: *mut T,
448    _old: T,
449    _src: T,
450) -> (T, bool) {
451    unreachable!()
452}
453/// Stores a value if the current value is the same as the `old` value.
454///
455/// The stabilized version of this intrinsic is available on the
456/// [`atomic`] types via the `compare_exchange_weak` method by passing
457/// [`Ordering::AcqRel`] and [`Ordering::SeqCst`] as the success and failure parameters.
458/// For example, [`AtomicBool::compare_exchange_weak`].
459#[rustc_intrinsic]
460#[rustc_intrinsic_must_be_overridden]
461#[rustc_nounwind]
462pub unsafe fn atomic_cxchgweak_acqrel_seqcst<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
463    unreachable!()
464}
465/// Stores a value if the current value is the same as the `old` value.
466///
467/// The stabilized version of this intrinsic is available on the
468/// [`atomic`] types via the `compare_exchange_weak` method by passing
469/// [`Ordering::SeqCst`] and [`Ordering::Relaxed`] as the success and failure parameters.
470/// For example, [`AtomicBool::compare_exchange_weak`].
471#[rustc_intrinsic]
472#[rustc_intrinsic_must_be_overridden]
473#[rustc_nounwind]
474pub unsafe fn atomic_cxchgweak_seqcst_relaxed<T: Copy>(
475    _dst: *mut T,
476    _old: T,
477    _src: T,
478) -> (T, bool) {
479    unreachable!()
480}
481/// Stores a value if the current value is the same as the `old` value.
482///
483/// The stabilized version of this intrinsic is available on the
484/// [`atomic`] types via the `compare_exchange_weak` method by passing
485/// [`Ordering::SeqCst`] and [`Ordering::Acquire`] as the success and failure parameters.
486/// For example, [`AtomicBool::compare_exchange_weak`].
487#[rustc_intrinsic]
488#[rustc_intrinsic_must_be_overridden]
489#[rustc_nounwind]
490pub unsafe fn atomic_cxchgweak_seqcst_acquire<T: Copy>(
491    _dst: *mut T,
492    _old: T,
493    _src: T,
494) -> (T, bool) {
495    unreachable!()
496}
497/// Stores a value if the current value is the same as the `old` value.
498///
499/// The stabilized version of this intrinsic is available on the
500/// [`atomic`] types via the `compare_exchange_weak` method by passing
501/// [`Ordering::SeqCst`] as both the success and failure parameters.
502/// For example, [`AtomicBool::compare_exchange_weak`].
503#[rustc_intrinsic]
504#[rustc_intrinsic_must_be_overridden]
505#[rustc_nounwind]
506pub unsafe fn atomic_cxchgweak_seqcst_seqcst<T: Copy>(_dst: *mut T, _old: T, _src: T) -> (T, bool) {
507    unreachable!()
508}
509
510/// Loads the current value of the pointer.
511///
512/// The stabilized version of this intrinsic is available on the
513/// [`atomic`] types via the `load` method by passing
514/// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::load`].
515#[rustc_intrinsic]
516#[rustc_intrinsic_must_be_overridden]
517#[rustc_nounwind]
518pub unsafe fn atomic_load_seqcst<T: Copy>(_src: *const T) -> T {
519    unreachable!()
520}
521/// Loads the current value of the pointer.
522///
523/// The stabilized version of this intrinsic is available on the
524/// [`atomic`] types via the `load` method by passing
525/// [`Ordering::Acquire`] as the `order`. For example, [`AtomicBool::load`].
526#[rustc_intrinsic]
527#[rustc_intrinsic_must_be_overridden]
528#[rustc_nounwind]
529pub unsafe fn atomic_load_acquire<T: Copy>(_src: *const T) -> T {
530    unreachable!()
531}
532/// Loads the current value of the pointer.
533///
534/// The stabilized version of this intrinsic is available on the
535/// [`atomic`] types via the `load` method by passing
536/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::load`].
537#[rustc_intrinsic]
538#[rustc_intrinsic_must_be_overridden]
539#[rustc_nounwind]
540pub unsafe fn atomic_load_relaxed<T: Copy>(_src: *const T) -> T {
541    unreachable!()
542}
543/// Do NOT use this intrinsic; "unordered" operations do not exist in our memory model!
544/// In terms of the Rust Abstract Machine, this operation is equivalent to `src.read()`,
545/// i.e., it performs a non-atomic read.
546#[rustc_intrinsic]
547#[rustc_intrinsic_must_be_overridden]
548#[rustc_nounwind]
549pub unsafe fn atomic_load_unordered<T: Copy>(_src: *const T) -> T {
550    unreachable!()
551}
552
553/// Stores the value at the specified memory location.
554///
555/// The stabilized version of this intrinsic is available on the
556/// [`atomic`] types via the `store` method by passing
557/// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::store`].
558#[rustc_intrinsic]
559#[rustc_intrinsic_must_be_overridden]
560#[rustc_nounwind]
561pub unsafe fn atomic_store_seqcst<T: Copy>(_dst: *mut T, _val: T) {
562    unreachable!()
563}
564/// Stores the value at the specified memory location.
565///
566/// The stabilized version of this intrinsic is available on the
567/// [`atomic`] types via the `store` method by passing
568/// [`Ordering::Release`] as the `order`. For example, [`AtomicBool::store`].
569#[rustc_intrinsic]
570#[rustc_intrinsic_must_be_overridden]
571#[rustc_nounwind]
572pub unsafe fn atomic_store_release<T: Copy>(_dst: *mut T, _val: T) {
573    unreachable!()
574}
575/// Stores the value at the specified memory location.
576///
577/// The stabilized version of this intrinsic is available on the
578/// [`atomic`] types via the `store` method by passing
579/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::store`].
580#[rustc_intrinsic]
581#[rustc_intrinsic_must_be_overridden]
582#[rustc_nounwind]
583pub unsafe fn atomic_store_relaxed<T: Copy>(_dst: *mut T, _val: T) {
584    unreachable!()
585}
586/// Do NOT use this intrinsic; "unordered" operations do not exist in our memory model!
587/// In terms of the Rust Abstract Machine, this operation is equivalent to `dst.write(val)`,
588/// i.e., it performs a non-atomic write.
589#[rustc_intrinsic]
590#[rustc_intrinsic_must_be_overridden]
591#[rustc_nounwind]
592pub unsafe fn atomic_store_unordered<T: Copy>(_dst: *mut T, _val: T) {
593    unreachable!()
594}
595
596/// Stores the value at the specified memory location, returning the old value.
597///
598/// The stabilized version of this intrinsic is available on the
599/// [`atomic`] types via the `swap` method by passing
600/// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::swap`].
601#[rustc_intrinsic]
602#[rustc_intrinsic_must_be_overridden]
603#[rustc_nounwind]
604pub unsafe fn atomic_xchg_seqcst<T: Copy>(_dst: *mut T, _src: T) -> T {
605    unreachable!()
606}
607/// Stores the value at the specified memory location, returning the old value.
608///
609/// The stabilized version of this intrinsic is available on the
610/// [`atomic`] types via the `swap` method by passing
611/// [`Ordering::Acquire`] as the `order`. For example, [`AtomicBool::swap`].
612#[rustc_intrinsic]
613#[rustc_intrinsic_must_be_overridden]
614#[rustc_nounwind]
615pub unsafe fn atomic_xchg_acquire<T: Copy>(_dst: *mut T, _src: T) -> T {
616    unreachable!()
617}
618/// Stores the value at the specified memory location, returning the old value.
619///
620/// The stabilized version of this intrinsic is available on the
621/// [`atomic`] types via the `swap` method by passing
622/// [`Ordering::Release`] as the `order`. For example, [`AtomicBool::swap`].
623#[rustc_intrinsic]
624#[rustc_intrinsic_must_be_overridden]
625#[rustc_nounwind]
626pub unsafe fn atomic_xchg_release<T: Copy>(_dst: *mut T, _src: T) -> T {
627    unreachable!()
628}
629/// Stores the value at the specified memory location, returning the old value.
630///
631/// The stabilized version of this intrinsic is available on the
632/// [`atomic`] types via the `swap` method by passing
633/// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicBool::swap`].
634#[rustc_intrinsic]
635#[rustc_intrinsic_must_be_overridden]
636#[rustc_nounwind]
637pub unsafe fn atomic_xchg_acqrel<T: Copy>(_dst: *mut T, _src: T) -> T {
638    unreachable!()
639}
640/// Stores the value at the specified memory location, returning the old value.
641///
642/// The stabilized version of this intrinsic is available on the
643/// [`atomic`] types via the `swap` method by passing
644/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::swap`].
645#[rustc_intrinsic]
646#[rustc_intrinsic_must_be_overridden]
647#[rustc_nounwind]
648pub unsafe fn atomic_xchg_relaxed<T: Copy>(_dst: *mut T, _src: T) -> T {
649    unreachable!()
650}
651
652/// Adds to the current value, returning the previous value.
653///
654/// The stabilized version of this intrinsic is available on the
655/// [`atomic`] types via the `fetch_add` method by passing
656/// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicIsize::fetch_add`].
657#[rustc_intrinsic]
658#[rustc_intrinsic_must_be_overridden]
659#[rustc_nounwind]
660pub unsafe fn atomic_xadd_seqcst<T: Copy>(_dst: *mut T, _src: T) -> T {
661    unreachable!()
662}
663/// Adds to the current value, returning the previous value.
664///
665/// The stabilized version of this intrinsic is available on the
666/// [`atomic`] types via the `fetch_add` method by passing
667/// [`Ordering::Acquire`] as the `order`. For example, [`AtomicIsize::fetch_add`].
668#[rustc_intrinsic]
669#[rustc_intrinsic_must_be_overridden]
670#[rustc_nounwind]
671pub unsafe fn atomic_xadd_acquire<T: Copy>(_dst: *mut T, _src: T) -> T {
672    unreachable!()
673}
674/// Adds to the current value, returning the previous value.
675///
676/// The stabilized version of this intrinsic is available on the
677/// [`atomic`] types via the `fetch_add` method by passing
678/// [`Ordering::Release`] as the `order`. For example, [`AtomicIsize::fetch_add`].
679#[rustc_intrinsic]
680#[rustc_intrinsic_must_be_overridden]
681#[rustc_nounwind]
682pub unsafe fn atomic_xadd_release<T: Copy>(_dst: *mut T, _src: T) -> T {
683    unreachable!()
684}
685/// Adds to the current value, returning the previous value.
686///
687/// The stabilized version of this intrinsic is available on the
688/// [`atomic`] types via the `fetch_add` method by passing
689/// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicIsize::fetch_add`].
690#[rustc_intrinsic]
691#[rustc_intrinsic_must_be_overridden]
692#[rustc_nounwind]
693pub unsafe fn atomic_xadd_acqrel<T: Copy>(_dst: *mut T, _src: T) -> T {
694    unreachable!()
695}
696/// Adds to the current value, returning the previous value.
697///
698/// The stabilized version of this intrinsic is available on the
699/// [`atomic`] types via the `fetch_add` method by passing
700/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicIsize::fetch_add`].
701#[rustc_intrinsic]
702#[rustc_intrinsic_must_be_overridden]
703#[rustc_nounwind]
704pub unsafe fn atomic_xadd_relaxed<T: Copy>(_dst: *mut T, _src: T) -> T {
705    unreachable!()
706}
707
708/// Subtract from the current value, returning the previous value.
709///
710/// The stabilized version of this intrinsic is available on the
711/// [`atomic`] types via the `fetch_sub` method by passing
712/// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicIsize::fetch_sub`].
713#[rustc_intrinsic]
714#[rustc_intrinsic_must_be_overridden]
715#[rustc_nounwind]
716pub unsafe fn atomic_xsub_seqcst<T: Copy>(_dst: *mut T, _src: T) -> T {
717    unreachable!()
718}
719/// Subtract from the current value, returning the previous value.
720///
721/// The stabilized version of this intrinsic is available on the
722/// [`atomic`] types via the `fetch_sub` method by passing
723/// [`Ordering::Acquire`] as the `order`. For example, [`AtomicIsize::fetch_sub`].
724#[rustc_intrinsic]
725#[rustc_intrinsic_must_be_overridden]
726#[rustc_nounwind]
727pub unsafe fn atomic_xsub_acquire<T: Copy>(_dst: *mut T, _src: T) -> T {
728    unreachable!()
729}
730/// Subtract from the current value, returning the previous value.
731///
732/// The stabilized version of this intrinsic is available on the
733/// [`atomic`] types via the `fetch_sub` method by passing
734/// [`Ordering::Release`] as the `order`. For example, [`AtomicIsize::fetch_sub`].
735#[rustc_intrinsic]
736#[rustc_intrinsic_must_be_overridden]
737#[rustc_nounwind]
738pub unsafe fn atomic_xsub_release<T: Copy>(_dst: *mut T, _src: T) -> T {
739    unreachable!()
740}
741/// Subtract from the current value, returning the previous value.
742///
743/// The stabilized version of this intrinsic is available on the
744/// [`atomic`] types via the `fetch_sub` method by passing
745/// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicIsize::fetch_sub`].
746#[rustc_intrinsic]
747#[rustc_intrinsic_must_be_overridden]
748#[rustc_nounwind]
749pub unsafe fn atomic_xsub_acqrel<T: Copy>(_dst: *mut T, _src: T) -> T {
750    unreachable!()
751}
752/// Subtract from the current value, returning the previous value.
753///
754/// The stabilized version of this intrinsic is available on the
755/// [`atomic`] types via the `fetch_sub` method by passing
756/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicIsize::fetch_sub`].
757#[rustc_intrinsic]
758#[rustc_intrinsic_must_be_overridden]
759#[rustc_nounwind]
760pub unsafe fn atomic_xsub_relaxed<T: Copy>(_dst: *mut T, _src: T) -> T {
761    unreachable!()
762}
763
764/// Bitwise and with the current value, returning the previous value.
765///
766/// The stabilized version of this intrinsic is available on the
767/// [`atomic`] types via the `fetch_and` method by passing
768/// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::fetch_and`].
769#[rustc_intrinsic]
770#[rustc_intrinsic_must_be_overridden]
771#[rustc_nounwind]
772pub unsafe fn atomic_and_seqcst<T: Copy>(_dst: *mut T, _src: T) -> T {
773    unreachable!()
774}
775/// Bitwise and with the current value, returning the previous value.
776///
777/// The stabilized version of this intrinsic is available on the
778/// [`atomic`] types via the `fetch_and` method by passing
779/// [`Ordering::Acquire`] as the `order`. For example, [`AtomicBool::fetch_and`].
780#[rustc_intrinsic]
781#[rustc_intrinsic_must_be_overridden]
782#[rustc_nounwind]
783pub unsafe fn atomic_and_acquire<T: Copy>(_dst: *mut T, _src: T) -> T {
784    unreachable!()
785}
786/// Bitwise and with the current value, returning the previous value.
787///
788/// The stabilized version of this intrinsic is available on the
789/// [`atomic`] types via the `fetch_and` method by passing
790/// [`Ordering::Release`] as the `order`. For example, [`AtomicBool::fetch_and`].
791#[rustc_intrinsic]
792#[rustc_intrinsic_must_be_overridden]
793#[rustc_nounwind]
794pub unsafe fn atomic_and_release<T: Copy>(_dst: *mut T, _src: T) -> T {
795    unreachable!()
796}
797/// Bitwise and with the current value, returning the previous value.
798///
799/// The stabilized version of this intrinsic is available on the
800/// [`atomic`] types via the `fetch_and` method by passing
801/// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicBool::fetch_and`].
802#[rustc_intrinsic]
803#[rustc_intrinsic_must_be_overridden]
804#[rustc_nounwind]
805pub unsafe fn atomic_and_acqrel<T: Copy>(_dst: *mut T, _src: T) -> T {
806    unreachable!()
807}
808/// Bitwise and with the current value, returning the previous value.
809///
810/// The stabilized version of this intrinsic is available on the
811/// [`atomic`] types via the `fetch_and` method by passing
812/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::fetch_and`].
813#[rustc_intrinsic]
814#[rustc_intrinsic_must_be_overridden]
815#[rustc_nounwind]
816pub unsafe fn atomic_and_relaxed<T: Copy>(_dst: *mut T, _src: T) -> T {
817    unreachable!()
818}
819
820/// Bitwise nand with the current value, returning the previous value.
821///
822/// The stabilized version of this intrinsic is available on the
823/// [`AtomicBool`] type via the `fetch_nand` method by passing
824/// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::fetch_nand`].
825#[rustc_intrinsic]
826#[rustc_intrinsic_must_be_overridden]
827#[rustc_nounwind]
828pub unsafe fn atomic_nand_seqcst<T: Copy>(_dst: *mut T, _src: T) -> T {
829    unreachable!()
830}
831/// Bitwise nand with the current value, returning the previous value.
832///
833/// The stabilized version of this intrinsic is available on the
834/// [`AtomicBool`] type via the `fetch_nand` method by passing
835/// [`Ordering::Acquire`] as the `order`. For example, [`AtomicBool::fetch_nand`].
836#[rustc_intrinsic]
837#[rustc_intrinsic_must_be_overridden]
838#[rustc_nounwind]
839pub unsafe fn atomic_nand_acquire<T: Copy>(_dst: *mut T, _src: T) -> T {
840    unreachable!()
841}
842/// Bitwise nand with the current value, returning the previous value.
843///
844/// The stabilized version of this intrinsic is available on the
845/// [`AtomicBool`] type via the `fetch_nand` method by passing
846/// [`Ordering::Release`] as the `order`. For example, [`AtomicBool::fetch_nand`].
847#[rustc_intrinsic]
848#[rustc_intrinsic_must_be_overridden]
849#[rustc_nounwind]
850pub unsafe fn atomic_nand_release<T: Copy>(_dst: *mut T, _src: T) -> T {
851    unreachable!()
852}
853/// Bitwise nand with the current value, returning the previous value.
854///
855/// The stabilized version of this intrinsic is available on the
856/// [`AtomicBool`] type via the `fetch_nand` method by passing
857/// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicBool::fetch_nand`].
858#[rustc_intrinsic]
859#[rustc_intrinsic_must_be_overridden]
860#[rustc_nounwind]
861pub unsafe fn atomic_nand_acqrel<T: Copy>(_dst: *mut T, _src: T) -> T {
862    unreachable!()
863}
864/// Bitwise nand with the current value, returning the previous value.
865///
866/// The stabilized version of this intrinsic is available on the
867/// [`AtomicBool`] type via the `fetch_nand` method by passing
868/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::fetch_nand`].
869#[rustc_intrinsic]
870#[rustc_intrinsic_must_be_overridden]
871#[rustc_nounwind]
872pub unsafe fn atomic_nand_relaxed<T: Copy>(_dst: *mut T, _src: T) -> T {
873    unreachable!()
874}
875
876/// Bitwise or with the current value, returning the previous value.
877///
878/// The stabilized version of this intrinsic is available on the
879/// [`atomic`] types via the `fetch_or` method by passing
880/// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::fetch_or`].
881#[rustc_intrinsic]
882#[rustc_intrinsic_must_be_overridden]
883#[rustc_nounwind]
884pub unsafe fn atomic_or_seqcst<T: Copy>(_dst: *mut T, _src: T) -> T {
885    unreachable!()
886}
887/// Bitwise or with the current value, returning the previous value.
888///
889/// The stabilized version of this intrinsic is available on the
890/// [`atomic`] types via the `fetch_or` method by passing
891/// [`Ordering::Acquire`] as the `order`. For example, [`AtomicBool::fetch_or`].
892#[rustc_intrinsic]
893#[rustc_intrinsic_must_be_overridden]
894#[rustc_nounwind]
895pub unsafe fn atomic_or_acquire<T: Copy>(_dst: *mut T, _src: T) -> T {
896    unreachable!()
897}
898/// Bitwise or with the current value, returning the previous value.
899///
900/// The stabilized version of this intrinsic is available on the
901/// [`atomic`] types via the `fetch_or` method by passing
902/// [`Ordering::Release`] as the `order`. For example, [`AtomicBool::fetch_or`].
903#[rustc_intrinsic]
904#[rustc_intrinsic_must_be_overridden]
905#[rustc_nounwind]
906pub unsafe fn atomic_or_release<T: Copy>(_dst: *mut T, _src: T) -> T {
907    unreachable!()
908}
909/// Bitwise or with the current value, returning the previous value.
910///
911/// The stabilized version of this intrinsic is available on the
912/// [`atomic`] types via the `fetch_or` method by passing
913/// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicBool::fetch_or`].
914#[rustc_intrinsic]
915#[rustc_intrinsic_must_be_overridden]
916#[rustc_nounwind]
917pub unsafe fn atomic_or_acqrel<T: Copy>(_dst: *mut T, _src: T) -> T {
918    unreachable!()
919}
920/// Bitwise or with the current value, returning the previous value.
921///
922/// The stabilized version of this intrinsic is available on the
923/// [`atomic`] types via the `fetch_or` method by passing
924/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::fetch_or`].
925#[rustc_intrinsic]
926#[rustc_intrinsic_must_be_overridden]
927#[rustc_nounwind]
928pub unsafe fn atomic_or_relaxed<T: Copy>(_dst: *mut T, _src: T) -> T {
929    unreachable!()
930}
931
932/// Bitwise xor with the current value, returning the previous value.
933///
934/// The stabilized version of this intrinsic is available on the
935/// [`atomic`] types via the `fetch_xor` method by passing
936/// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::fetch_xor`].
937#[rustc_intrinsic]
938#[rustc_intrinsic_must_be_overridden]
939#[rustc_nounwind]
940pub unsafe fn atomic_xor_seqcst<T: Copy>(_dst: *mut T, _src: T) -> T {
941    unreachable!()
942}
943/// Bitwise xor with the current value, returning the previous value.
944///
945/// The stabilized version of this intrinsic is available on the
946/// [`atomic`] types via the `fetch_xor` method by passing
947/// [`Ordering::Acquire`] as the `order`. For example, [`AtomicBool::fetch_xor`].
948#[rustc_intrinsic]
949#[rustc_intrinsic_must_be_overridden]
950#[rustc_nounwind]
951pub unsafe fn atomic_xor_acquire<T: Copy>(_dst: *mut T, _src: T) -> T {
952    unreachable!()
953}
954/// Bitwise xor with the current value, returning the previous value.
955///
956/// The stabilized version of this intrinsic is available on the
957/// [`atomic`] types via the `fetch_xor` method by passing
958/// [`Ordering::Release`] as the `order`. For example, [`AtomicBool::fetch_xor`].
959#[rustc_intrinsic]
960#[rustc_intrinsic_must_be_overridden]
961#[rustc_nounwind]
962pub unsafe fn atomic_xor_release<T: Copy>(_dst: *mut T, _src: T) -> T {
963    unreachable!()
964}
965/// Bitwise xor with the current value, returning the previous value.
966///
967/// The stabilized version of this intrinsic is available on the
968/// [`atomic`] types via the `fetch_xor` method by passing
969/// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicBool::fetch_xor`].
970#[rustc_intrinsic]
971#[rustc_intrinsic_must_be_overridden]
972#[rustc_nounwind]
973pub unsafe fn atomic_xor_acqrel<T: Copy>(_dst: *mut T, _src: T) -> T {
974    unreachable!()
975}
976/// Bitwise xor with the current value, returning the previous value.
977///
978/// The stabilized version of this intrinsic is available on the
979/// [`atomic`] types via the `fetch_xor` method by passing
980/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::fetch_xor`].
981#[rustc_intrinsic]
982#[rustc_intrinsic_must_be_overridden]
983#[rustc_nounwind]
984pub unsafe fn atomic_xor_relaxed<T: Copy>(_dst: *mut T, _src: T) -> T {
985    unreachable!()
986}
987
988/// Maximum with the current value using a signed comparison.
989///
990/// The stabilized version of this intrinsic is available on the
991/// [`atomic`] signed integer types via the `fetch_max` method by passing
992/// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicI32::fetch_max`].
993#[rustc_intrinsic]
994#[rustc_intrinsic_must_be_overridden]
995#[rustc_nounwind]
996pub unsafe fn atomic_max_seqcst<T: Copy>(_dst: *mut T, _src: T) -> T {
997    unreachable!()
998}
999/// Maximum with the current value using a signed comparison.
1000///
1001/// The stabilized version of this intrinsic is available on the
1002/// [`atomic`] signed integer types via the `fetch_max` method by passing
1003/// [`Ordering::Acquire`] as the `order`. For example, [`AtomicI32::fetch_max`].
1004#[rustc_intrinsic]
1005#[rustc_intrinsic_must_be_overridden]
1006#[rustc_nounwind]
1007pub unsafe fn atomic_max_acquire<T: Copy>(_dst: *mut T, _src: T) -> T {
1008    unreachable!()
1009}
1010/// Maximum with the current value using a signed comparison.
1011///
1012/// The stabilized version of this intrinsic is available on the
1013/// [`atomic`] signed integer types via the `fetch_max` method by passing
1014/// [`Ordering::Release`] as the `order`. For example, [`AtomicI32::fetch_max`].
1015#[rustc_intrinsic]
1016#[rustc_intrinsic_must_be_overridden]
1017#[rustc_nounwind]
1018pub unsafe fn atomic_max_release<T: Copy>(_dst: *mut T, _src: T) -> T {
1019    unreachable!()
1020}
1021/// Maximum with the current value using a signed comparison.
1022///
1023/// The stabilized version of this intrinsic is available on the
1024/// [`atomic`] signed integer types via the `fetch_max` method by passing
1025/// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicI32::fetch_max`].
1026#[rustc_intrinsic]
1027#[rustc_intrinsic_must_be_overridden]
1028#[rustc_nounwind]
1029pub unsafe fn atomic_max_acqrel<T: Copy>(_dst: *mut T, _src: T) -> T {
1030    unreachable!()
1031}
1032/// Maximum with the current value.
1033///
1034/// The stabilized version of this intrinsic is available on the
1035/// [`atomic`] signed integer types via the `fetch_max` method by passing
1036/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicI32::fetch_max`].
1037#[rustc_intrinsic]
1038#[rustc_intrinsic_must_be_overridden]
1039#[rustc_nounwind]
1040pub unsafe fn atomic_max_relaxed<T: Copy>(_dst: *mut T, _src: T) -> T {
1041    unreachable!()
1042}
1043
1044/// Minimum with the current value using a signed comparison.
1045///
1046/// The stabilized version of this intrinsic is available on the
1047/// [`atomic`] signed integer types via the `fetch_min` method by passing
1048/// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicI32::fetch_min`].
1049#[rustc_intrinsic]
1050#[rustc_intrinsic_must_be_overridden]
1051#[rustc_nounwind]
1052pub unsafe fn atomic_min_seqcst<T: Copy>(_dst: *mut T, _src: T) -> T {
1053    unreachable!()
1054}
1055/// Minimum with the current value using a signed comparison.
1056///
1057/// The stabilized version of this intrinsic is available on the
1058/// [`atomic`] signed integer types via the `fetch_min` method by passing
1059/// [`Ordering::Acquire`] as the `order`. For example, [`AtomicI32::fetch_min`].
1060#[rustc_intrinsic]
1061#[rustc_intrinsic_must_be_overridden]
1062#[rustc_nounwind]
1063pub unsafe fn atomic_min_acquire<T: Copy>(_dst: *mut T, _src: T) -> T {
1064    unreachable!()
1065}
1066/// Minimum with the current value using a signed comparison.
1067///
1068/// The stabilized version of this intrinsic is available on the
1069/// [`atomic`] signed integer types via the `fetch_min` method by passing
1070/// [`Ordering::Release`] as the `order`. For example, [`AtomicI32::fetch_min`].
1071#[rustc_intrinsic]
1072#[rustc_intrinsic_must_be_overridden]
1073#[rustc_nounwind]
1074pub unsafe fn atomic_min_release<T: Copy>(_dst: *mut T, _src: T) -> T {
1075    unreachable!()
1076}
1077/// Minimum with the current value using a signed comparison.
1078///
1079/// The stabilized version of this intrinsic is available on the
1080/// [`atomic`] signed integer types via the `fetch_min` method by passing
1081/// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicI32::fetch_min`].
1082#[rustc_intrinsic]
1083#[rustc_intrinsic_must_be_overridden]
1084#[rustc_nounwind]
1085pub unsafe fn atomic_min_acqrel<T: Copy>(_dst: *mut T, _src: T) -> T {
1086    unreachable!()
1087}
1088/// Minimum with the current value using a signed comparison.
1089///
1090/// The stabilized version of this intrinsic is available on the
1091/// [`atomic`] signed integer types via the `fetch_min` method by passing
1092/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicI32::fetch_min`].
1093#[rustc_intrinsic]
1094#[rustc_intrinsic_must_be_overridden]
1095#[rustc_nounwind]
1096pub unsafe fn atomic_min_relaxed<T: Copy>(_dst: *mut T, _src: T) -> T {
1097    unreachable!()
1098}
1099
1100/// Minimum with the current value using an unsigned comparison.
1101///
1102/// The stabilized version of this intrinsic is available on the
1103/// [`atomic`] unsigned integer types via the `fetch_min` method by passing
1104/// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicU32::fetch_min`].
1105#[rustc_intrinsic]
1106#[rustc_intrinsic_must_be_overridden]
1107#[rustc_nounwind]
1108pub unsafe fn atomic_umin_seqcst<T: Copy>(_dst: *mut T, _src: T) -> T {
1109    unreachable!()
1110}
1111/// Minimum with the current value using an unsigned comparison.
1112///
1113/// The stabilized version of this intrinsic is available on the
1114/// [`atomic`] unsigned integer types via the `fetch_min` method by passing
1115/// [`Ordering::Acquire`] as the `order`. For example, [`AtomicU32::fetch_min`].
1116#[rustc_intrinsic]
1117#[rustc_intrinsic_must_be_overridden]
1118#[rustc_nounwind]
1119pub unsafe fn atomic_umin_acquire<T: Copy>(_dst: *mut T, _src: T) -> T {
1120    unreachable!()
1121}
1122/// Minimum with the current value using an unsigned comparison.
1123///
1124/// The stabilized version of this intrinsic is available on the
1125/// [`atomic`] unsigned integer types via the `fetch_min` method by passing
1126/// [`Ordering::Release`] as the `order`. For example, [`AtomicU32::fetch_min`].
1127#[rustc_intrinsic]
1128#[rustc_intrinsic_must_be_overridden]
1129#[rustc_nounwind]
1130pub unsafe fn atomic_umin_release<T: Copy>(_dst: *mut T, _src: T) -> T {
1131    unreachable!()
1132}
1133/// Minimum with the current value using an unsigned comparison.
1134///
1135/// The stabilized version of this intrinsic is available on the
1136/// [`atomic`] unsigned integer types via the `fetch_min` method by passing
1137/// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicU32::fetch_min`].
1138#[rustc_intrinsic]
1139#[rustc_intrinsic_must_be_overridden]
1140#[rustc_nounwind]
1141pub unsafe fn atomic_umin_acqrel<T: Copy>(_dst: *mut T, _src: T) -> T {
1142    unreachable!()
1143}
1144/// Minimum with the current value using an unsigned comparison.
1145///
1146/// The stabilized version of this intrinsic is available on the
1147/// [`atomic`] unsigned integer types via the `fetch_min` method by passing
1148/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicU32::fetch_min`].
1149#[rustc_intrinsic]
1150#[rustc_intrinsic_must_be_overridden]
1151#[rustc_nounwind]
1152pub unsafe fn atomic_umin_relaxed<T: Copy>(_dst: *mut T, _src: T) -> T {
1153    unreachable!()
1154}
1155
1156/// Maximum with the current value using an unsigned comparison.
1157///
1158/// The stabilized version of this intrinsic is available on the
1159/// [`atomic`] unsigned integer types via the `fetch_max` method by passing
1160/// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicU32::fetch_max`].
1161#[rustc_intrinsic]
1162#[rustc_intrinsic_must_be_overridden]
1163#[rustc_nounwind]
1164pub unsafe fn atomic_umax_seqcst<T: Copy>(_dst: *mut T, _src: T) -> T {
1165    unreachable!()
1166}
1167/// Maximum with the current value using an unsigned comparison.
1168///
1169/// The stabilized version of this intrinsic is available on the
1170/// [`atomic`] unsigned integer types via the `fetch_max` method by passing
1171/// [`Ordering::Acquire`] as the `order`. For example, [`AtomicU32::fetch_max`].
1172#[rustc_intrinsic]
1173#[rustc_intrinsic_must_be_overridden]
1174#[rustc_nounwind]
1175pub unsafe fn atomic_umax_acquire<T: Copy>(_dst: *mut T, _src: T) -> T {
1176    unreachable!()
1177}
1178/// Maximum with the current value using an unsigned comparison.
1179///
1180/// The stabilized version of this intrinsic is available on the
1181/// [`atomic`] unsigned integer types via the `fetch_max` method by passing
1182/// [`Ordering::Release`] as the `order`. For example, [`AtomicU32::fetch_max`].
1183#[rustc_intrinsic]
1184#[rustc_intrinsic_must_be_overridden]
1185#[rustc_nounwind]
1186pub unsafe fn atomic_umax_release<T: Copy>(_dst: *mut T, _src: T) -> T {
1187    unreachable!()
1188}
1189/// Maximum with the current value using an unsigned comparison.
1190///
1191/// The stabilized version of this intrinsic is available on the
1192/// [`atomic`] unsigned integer types via the `fetch_max` method by passing
1193/// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicU32::fetch_max`].
1194#[rustc_intrinsic]
1195#[rustc_intrinsic_must_be_overridden]
1196#[rustc_nounwind]
1197pub unsafe fn atomic_umax_acqrel<T: Copy>(_dst: *mut T, _src: T) -> T {
1198    unreachable!()
1199}
1200/// Maximum with the current value using an unsigned comparison.
1201///
1202/// The stabilized version of this intrinsic is available on the
1203/// [`atomic`] unsigned integer types via the `fetch_max` method by passing
1204/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicU32::fetch_max`].
1205#[rustc_intrinsic]
1206#[rustc_intrinsic_must_be_overridden]
1207#[rustc_nounwind]
1208pub unsafe fn atomic_umax_relaxed<T: Copy>(_dst: *mut T, _src: T) -> T {
1209    unreachable!()
1210}
1211
1212/// An atomic fence.
1213///
1214/// The stabilized version of this intrinsic is available in
1215/// [`atomic::fence`] by passing [`Ordering::SeqCst`]
1216/// as the `order`.
1217#[rustc_intrinsic]
1218#[rustc_intrinsic_must_be_overridden]
1219#[rustc_nounwind]
1220pub unsafe fn atomic_fence_seqcst() {
1221    unreachable!()
1222}
1223/// An atomic fence.
1224///
1225/// The stabilized version of this intrinsic is available in
1226/// [`atomic::fence`] by passing [`Ordering::Acquire`]
1227/// as the `order`.
1228#[rustc_intrinsic]
1229#[rustc_intrinsic_must_be_overridden]
1230#[rustc_nounwind]
1231pub unsafe fn atomic_fence_acquire() {
1232    unreachable!()
1233}
1234/// An atomic fence.
1235///
1236/// The stabilized version of this intrinsic is available in
1237/// [`atomic::fence`] by passing [`Ordering::Release`]
1238/// as the `order`.
1239#[rustc_intrinsic]
1240#[rustc_intrinsic_must_be_overridden]
1241#[rustc_nounwind]
1242pub unsafe fn atomic_fence_release() {
1243    unreachable!()
1244}
1245/// An atomic fence.
1246///
1247/// The stabilized version of this intrinsic is available in
1248/// [`atomic::fence`] by passing [`Ordering::AcqRel`]
1249/// as the `order`.
1250#[rustc_intrinsic]
1251#[rustc_intrinsic_must_be_overridden]
1252#[rustc_nounwind]
1253pub unsafe fn atomic_fence_acqrel() {
1254    unreachable!()
1255}
1256
1257/// A compiler-only memory barrier.
1258///
1259/// Memory accesses will never be reordered across this barrier by the
1260/// compiler, but no instructions will be emitted for it. This is
1261/// appropriate for operations on the same thread that may be preempted,
1262/// such as when interacting with signal handlers.
1263///
1264/// The stabilized version of this intrinsic is available in
1265/// [`atomic::compiler_fence`] by passing [`Ordering::SeqCst`]
1266/// as the `order`.
1267#[rustc_intrinsic]
1268#[rustc_intrinsic_must_be_overridden]
1269#[rustc_nounwind]
1270pub unsafe fn atomic_singlethreadfence_seqcst() {
1271    unreachable!()
1272}
1273/// A compiler-only memory barrier.
1274///
1275/// Memory accesses will never be reordered across this barrier by the
1276/// compiler, but no instructions will be emitted for it. This is
1277/// appropriate for operations on the same thread that may be preempted,
1278/// such as when interacting with signal handlers.
1279///
1280/// The stabilized version of this intrinsic is available in
1281/// [`atomic::compiler_fence`] by passing [`Ordering::Acquire`]
1282/// as the `order`.
1283#[rustc_intrinsic]
1284#[rustc_intrinsic_must_be_overridden]
1285#[rustc_nounwind]
1286pub unsafe fn atomic_singlethreadfence_acquire() {
1287    unreachable!()
1288}
1289/// A compiler-only memory barrier.
1290///
1291/// Memory accesses will never be reordered across this barrier by the
1292/// compiler, but no instructions will be emitted for it. This is
1293/// appropriate for operations on the same thread that may be preempted,
1294/// such as when interacting with signal handlers.
1295///
1296/// The stabilized version of this intrinsic is available in
1297/// [`atomic::compiler_fence`] by passing [`Ordering::Release`]
1298/// as the `order`.
1299#[rustc_intrinsic]
1300#[rustc_intrinsic_must_be_overridden]
1301#[rustc_nounwind]
1302pub unsafe fn atomic_singlethreadfence_release() {
1303    unreachable!()
1304}
1305/// A compiler-only memory barrier.
1306///
1307/// Memory accesses will never be reordered across this barrier by the
1308/// compiler, but no instructions will be emitted for it. This is
1309/// appropriate for operations on the same thread that may be preempted,
1310/// such as when interacting with signal handlers.
1311///
1312/// The stabilized version of this intrinsic is available in
1313/// [`atomic::compiler_fence`] by passing [`Ordering::AcqRel`]
1314/// as the `order`.
1315#[rustc_intrinsic]
1316#[rustc_intrinsic_must_be_overridden]
1317#[rustc_nounwind]
1318pub unsafe fn atomic_singlethreadfence_acqrel() {
1319    unreachable!()
1320}
1321
1322/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
1323/// if supported; otherwise, it is a no-op.
1324/// Prefetches have no effect on the behavior of the program but can change its performance
1325/// characteristics.
1326///
1327/// The `locality` argument must be a constant integer and is a temporal locality specifier
1328/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
1329///
1330/// This intrinsic does not have a stable counterpart.
1331#[rustc_intrinsic]
1332#[rustc_intrinsic_must_be_overridden]
1333#[rustc_nounwind]
1334pub unsafe fn prefetch_read_data<T>(_data: *const T, _locality: i32) {
1335    unreachable!()
1336}
1337/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
1338/// if supported; otherwise, it is a no-op.
1339/// Prefetches have no effect on the behavior of the program but can change its performance
1340/// characteristics.
1341///
1342/// The `locality` argument must be a constant integer and is a temporal locality specifier
1343/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
1344///
1345/// This intrinsic does not have a stable counterpart.
1346#[rustc_intrinsic]
1347#[rustc_intrinsic_must_be_overridden]
1348#[rustc_nounwind]
1349pub unsafe fn prefetch_write_data<T>(_data: *const T, _locality: i32) {
1350    unreachable!()
1351}
1352/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
1353/// if supported; otherwise, it is a no-op.
1354/// Prefetches have no effect on the behavior of the program but can change its performance
1355/// characteristics.
1356///
1357/// The `locality` argument must be a constant integer and is a temporal locality specifier
1358/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
1359///
1360/// This intrinsic does not have a stable counterpart.
1361#[rustc_intrinsic]
1362#[rustc_intrinsic_must_be_overridden]
1363#[rustc_nounwind]
1364pub unsafe fn prefetch_read_instruction<T>(_data: *const T, _locality: i32) {
1365    unreachable!()
1366}
1367/// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
1368/// if supported; otherwise, it is a no-op.
1369/// Prefetches have no effect on the behavior of the program but can change its performance
1370/// characteristics.
1371///
1372/// The `locality` argument must be a constant integer and is a temporal locality specifier
1373/// ranging from (0) - no locality, to (3) - extremely local keep in cache.
1374///
1375/// This intrinsic does not have a stable counterpart.
1376#[rustc_intrinsic]
1377#[rustc_intrinsic_must_be_overridden]
1378#[rustc_nounwind]
1379pub unsafe fn prefetch_write_instruction<T>(_data: *const T, _locality: i32) {
1380    unreachable!()
1381}
1382
1383/// Executes a breakpoint trap, for inspection by a debugger.
1384///
1385/// This intrinsic does not have a stable counterpart.
1386#[rustc_intrinsic]
1387#[rustc_intrinsic_must_be_overridden]
1388#[rustc_nounwind]
1389pub fn breakpoint() {
1390    unreachable!()
1391}
1392
1393/// Magic intrinsic that derives its meaning from attributes
1394/// attached to the function.
1395///
1396/// For example, dataflow uses this to inject static assertions so
1397/// that `rustc_peek(potentially_uninitialized)` would actually
1398/// double-check that dataflow did indeed compute that it is
1399/// uninitialized at that point in the control flow.
1400///
1401/// This intrinsic should not be used outside of the compiler.
1402#[rustc_nounwind]
1403#[rustc_intrinsic]
1404#[rustc_intrinsic_must_be_overridden]
1405pub fn rustc_peek<T>(_: T) -> T {
1406    unreachable!()
1407}
1408
1409/// Aborts the execution of the process.
1410///
1411/// Note that, unlike most intrinsics, this is safe to call;
1412/// it does not require an `unsafe` block.
1413/// Therefore, implementations must not require the user to uphold
1414/// any safety invariants.
1415///
1416/// [`std::process::abort`](../../std/process/fn.abort.html) is to be preferred if possible,
1417/// as its behavior is more user-friendly and more stable.
1418///
1419/// The current implementation of `intrinsics::abort` is to invoke an invalid instruction,
1420/// on most platforms.
1421/// On Unix, the
1422/// process will probably terminate with a signal like `SIGABRT`, `SIGILL`, `SIGTRAP`, `SIGSEGV` or
1423/// `SIGBUS`.  The precise behavior is not guaranteed and not stable.
1424#[rustc_nounwind]
1425#[rustc_intrinsic]
1426#[rustc_intrinsic_must_be_overridden]
1427pub fn abort() -> ! {
1428    unreachable!()
1429}
1430
1431/// Informs the optimizer that this point in the code is not reachable,
1432/// enabling further optimizations.
1433///
1434/// N.B., this is very different from the `unreachable!()` macro: Unlike the
1435/// macro, which panics when it is executed, it is *undefined behavior* to
1436/// reach code marked with this function.
1437///
1438/// The stabilized version of this intrinsic is [`core::hint::unreachable_unchecked`].
1439#[rustc_intrinsic_const_stable_indirect]
1440#[rustc_nounwind]
1441#[rustc_intrinsic]
1442#[rustc_intrinsic_must_be_overridden]
1443pub const unsafe fn unreachable() -> ! {
1444    unreachable!()
1445}
1446
1447/// Informs the optimizer that a condition is always true.
1448/// If the condition is false, the behavior is undefined.
1449///
1450/// No code is generated for this intrinsic, but the optimizer will try
1451/// to preserve it (and its condition) between passes, which may interfere
1452/// with optimization of surrounding code and reduce performance. It should
1453/// not be used if the invariant can be discovered by the optimizer on its
1454/// own, or if it does not enable any significant optimizations.
1455///
1456/// The stabilized version of this intrinsic is [`core::hint::assert_unchecked`].
1457#[rustc_intrinsic_const_stable_indirect]
1458#[rustc_nounwind]
1459#[unstable(feature = "core_intrinsics", issue = "none")]
1460#[rustc_intrinsic]
1461pub const unsafe fn assume(b: bool) {
1462    if !b {
1463        // SAFETY: the caller must guarantee the argument is never `false`
1464        unsafe { unreachable() }
1465    }
1466}
1467
1468/// Hints to the compiler that current code path is cold.
1469///
1470/// Note that, unlike most intrinsics, this is safe to call;
1471/// it does not require an `unsafe` block.
1472/// Therefore, implementations must not require the user to uphold
1473/// any safety invariants.
1474///
1475/// This intrinsic does not have a stable counterpart.
1476#[unstable(feature = "core_intrinsics", issue = "none")]
1477#[rustc_intrinsic]
1478#[rustc_nounwind]
1479#[miri::intrinsic_fallback_is_spec]
1480#[cold]
1481pub const fn cold_path() {}
1482
1483/// Hints to the compiler that branch condition is likely to be true.
1484/// Returns the value passed to it.
1485///
1486/// Any use other than with `if` statements will probably not have an effect.
1487///
1488/// Note that, unlike most intrinsics, this is safe to call;
1489/// it does not require an `unsafe` block.
1490/// Therefore, implementations must not require the user to uphold
1491/// any safety invariants.
1492///
1493/// This intrinsic does not have a stable counterpart.
1494#[unstable(feature = "core_intrinsics", issue = "none")]
1495#[rustc_nounwind]
1496#[inline(always)]
1497pub const fn likely(b: bool) -> bool {
1498    if b {
1499        true
1500    } else {
1501        cold_path();
1502        false
1503    }
1504}
1505
1506/// Hints to the compiler that branch condition is likely to be false.
1507/// Returns the value passed to it.
1508///
1509/// Any use other than with `if` statements will probably not have an effect.
1510///
1511/// Note that, unlike most intrinsics, this is safe to call;
1512/// it does not require an `unsafe` block.
1513/// Therefore, implementations must not require the user to uphold
1514/// any safety invariants.
1515///
1516/// This intrinsic does not have a stable counterpart.
1517#[unstable(feature = "core_intrinsics", issue = "none")]
1518#[rustc_nounwind]
1519#[inline(always)]
1520pub const fn unlikely(b: bool) -> bool {
1521    if b {
1522        cold_path();
1523        true
1524    } else {
1525        false
1526    }
1527}
1528
1529/// Returns either `true_val` or `false_val` depending on condition `b` with a
1530/// hint to the compiler that this condition is unlikely to be correctly
1531/// predicted by a CPU's branch predictor (e.g. a binary search).
1532///
1533/// This is otherwise functionally equivalent to `if b { true_val } else { false_val }`.
1534///
1535/// Note that, unlike most intrinsics, this is safe to call;
1536/// it does not require an `unsafe` block.
1537/// Therefore, implementations must not require the user to uphold
1538/// any safety invariants.
1539///
1540/// The public form of this instrinsic is [`bool::select_unpredictable`].
1541#[unstable(feature = "core_intrinsics", issue = "none")]
1542#[rustc_intrinsic]
1543#[rustc_nounwind]
1544#[miri::intrinsic_fallback_is_spec]
1545#[inline]
1546pub fn select_unpredictable<T>(b: bool, true_val: T, false_val: T) -> T {
1547    if b { true_val } else { false_val }
1548}
1549
1550/// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
1551/// This will statically either panic, or do nothing.
1552///
1553/// This intrinsic does not have a stable counterpart.
1554#[rustc_intrinsic_const_stable_indirect]
1555#[rustc_nounwind]
1556#[rustc_intrinsic]
1557#[rustc_intrinsic_must_be_overridden]
1558pub const fn assert_inhabited<T>() {
1559    unreachable!()
1560}
1561
1562/// A guard for unsafe functions that cannot ever be executed if `T` does not permit
1563/// zero-initialization: This will statically either panic, or do nothing.
1564///
1565/// This intrinsic does not have a stable counterpart.
1566#[rustc_intrinsic_const_stable_indirect]
1567#[rustc_nounwind]
1568#[rustc_intrinsic]
1569#[rustc_intrinsic_must_be_overridden]
1570pub const fn assert_zero_valid<T>() {
1571    unreachable!()
1572}
1573
1574/// A guard for `std::mem::uninitialized`. This will statically either panic, or do nothing.
1575///
1576/// This intrinsic does not have a stable counterpart.
1577#[rustc_intrinsic_const_stable_indirect]
1578#[rustc_nounwind]
1579#[rustc_intrinsic]
1580#[rustc_intrinsic_must_be_overridden]
1581pub const fn assert_mem_uninitialized_valid<T>() {
1582    unreachable!()
1583}
1584
1585/// Gets a reference to a static `Location` indicating where it was called.
1586///
1587/// Note that, unlike most intrinsics, this is safe to call;
1588/// it does not require an `unsafe` block.
1589/// Therefore, implementations must not require the user to uphold
1590/// any safety invariants.
1591///
1592/// Consider using [`core::panic::Location::caller`] instead.
1593#[rustc_intrinsic_const_stable_indirect]
1594#[rustc_nounwind]
1595#[rustc_intrinsic]
1596#[rustc_intrinsic_must_be_overridden]
1597pub const fn caller_location() -> &'static crate::panic::Location<'static> {
1598    unreachable!()
1599}
1600
1601/// Moves a value out of scope without running drop glue.
1602///
1603/// This exists solely for [`crate::mem::forget_unsized`]; normal `forget` uses
1604/// `ManuallyDrop` instead.
1605///
1606/// Note that, unlike most intrinsics, this is safe to call;
1607/// it does not require an `unsafe` block.
1608/// Therefore, implementations must not require the user to uphold
1609/// any safety invariants.
1610#[rustc_intrinsic_const_stable_indirect]
1611#[rustc_nounwind]
1612#[rustc_intrinsic]
1613#[rustc_intrinsic_must_be_overridden]
1614pub const fn forget<T: ?Sized>(_: T) {
1615    unreachable!()
1616}
1617
1618/// Reinterprets the bits of a value of one type as another type.
1619///
1620/// Both types must have the same size. Compilation will fail if this is not guaranteed.
1621///
1622/// `transmute` is semantically equivalent to a bitwise move of one type
1623/// into another. It copies the bits from the source value into the
1624/// destination value, then forgets the original. Note that source and destination
1625/// are passed by-value, which means if `Src` or `Dst` contain padding, that padding
1626/// is *not* guaranteed to be preserved by `transmute`.
1627///
1628/// Both the argument and the result must be [valid](../../nomicon/what-unsafe-does.html) at
1629/// their given type. Violating this condition leads to [undefined behavior][ub]. The compiler
1630/// will generate code *assuming that you, the programmer, ensure that there will never be
1631/// undefined behavior*. It is therefore your responsibility to guarantee that every value
1632/// passed to `transmute` is valid at both types `Src` and `Dst`. Failing to uphold this condition
1633/// may lead to unexpected and unstable compilation results. This makes `transmute` **incredibly
1634/// unsafe**. `transmute` should be the absolute last resort.
1635///
1636/// Because `transmute` is a by-value operation, alignment of the *transmuted values
1637/// themselves* is not a concern. As with any other function, the compiler already ensures
1638/// both `Src` and `Dst` are properly aligned. However, when transmuting values that *point
1639/// elsewhere* (such as pointers, references, boxes…), the caller has to ensure proper
1640/// alignment of the pointed-to values.
1641///
1642/// The [nomicon](../../nomicon/transmutes.html) has additional documentation.
1643///
1644/// [ub]: ../../reference/behavior-considered-undefined.html
1645///
1646/// # Transmutation between pointers and integers
1647///
1648/// Special care has to be taken when transmuting between pointers and integers, e.g.
1649/// transmuting between `*const ()` and `usize`.
1650///
1651/// Transmuting *pointers to integers* in a `const` context is [undefined behavior][ub], unless
1652/// the pointer was originally created *from* an integer. (That includes this function
1653/// specifically, integer-to-pointer casts, and helpers like [`dangling`][crate::ptr::dangling],
1654/// but also semantically-equivalent conversions such as punning through `repr(C)` union
1655/// fields.) Any attempt to use the resulting value for integer operations will abort
1656/// const-evaluation. (And even outside `const`, such transmutation is touching on many
1657/// unspecified aspects of the Rust memory model and should be avoided. See below for
1658/// alternatives.)
1659///
1660/// Transmuting *integers to pointers* is a largely unspecified operation. It is likely *not*
1661/// equivalent to an `as` cast. Doing non-zero-sized memory accesses with a pointer constructed
1662/// this way is currently considered undefined behavior.
1663///
1664/// All this also applies when the integer is nested inside an array, tuple, struct, or enum.
1665/// However, `MaybeUninit<usize>` is not considered an integer type for the purpose of this
1666/// section. Transmuting `*const ()` to `MaybeUninit<usize>` is fine---but then calling
1667/// `assume_init()` on that result is considered as completing the pointer-to-integer transmute
1668/// and thus runs into the issues discussed above.
1669///
1670/// In particular, doing a pointer-to-integer-to-pointer roundtrip via `transmute` is *not* a
1671/// lossless process. If you want to round-trip a pointer through an integer in a way that you
1672/// can get back the original pointer, you need to use `as` casts, or replace the integer type
1673/// by `MaybeUninit<$int>` (and never call `assume_init()`). If you are looking for a way to
1674/// store data of arbitrary type, also use `MaybeUninit<T>` (that will also handle uninitialized
1675/// memory due to padding). If you specifically need to store something that is "either an
1676/// integer or a pointer", use `*mut ()`: integers can be converted to pointers and back without
1677/// any loss (via `as` casts or via `transmute`).
1678///
1679/// # Examples
1680///
1681/// There are a few things that `transmute` is really useful for.
1682///
1683/// Turning a pointer into a function pointer. This is *not* portable to
1684/// machines where function pointers and data pointers have different sizes.
1685///
1686/// ```
1687/// fn foo() -> i32 {
1688///     0
1689/// }
1690/// // Crucially, we `as`-cast to a raw pointer before `transmute`ing to a function pointer.
1691/// // This avoids an integer-to-pointer `transmute`, which can be problematic.
1692/// // Transmuting between raw pointers and function pointers (i.e., two pointer types) is fine.
1693/// let pointer = foo as *const ();
1694/// let function = unsafe {
1695///     std::mem::transmute::<*const (), fn() -> i32>(pointer)
1696/// };
1697/// assert_eq!(function(), 0);
1698/// ```
1699///
1700/// Extending a lifetime, or shortening an invariant lifetime. This is
1701/// advanced, very unsafe Rust!
1702///
1703/// ```
1704/// struct R<'a>(&'a i32);
1705/// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
1706///     std::mem::transmute::<R<'b>, R<'static>>(r)
1707/// }
1708///
1709/// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
1710///                                              -> &'b mut R<'c> {
1711///     std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
1712/// }
1713/// ```
1714///
1715/// # Alternatives
1716///
1717/// Don't despair: many uses of `transmute` can be achieved through other means.
1718/// Below are common applications of `transmute` which can be replaced with safer
1719/// constructs.
1720///
1721/// Turning raw bytes (`[u8; SZ]`) into `u32`, `f64`, etc.:
1722///
1723/// ```
1724/// let raw_bytes = [0x78, 0x56, 0x34, 0x12];
1725///
1726/// let num = unsafe {
1727///     std::mem::transmute::<[u8; 4], u32>(raw_bytes)
1728/// };
1729///
1730/// // use `u32::from_ne_bytes` instead
1731/// let num = u32::from_ne_bytes(raw_bytes);
1732/// // or use `u32::from_le_bytes` or `u32::from_be_bytes` to specify the endianness
1733/// let num = u32::from_le_bytes(raw_bytes);
1734/// assert_eq!(num, 0x12345678);
1735/// let num = u32::from_be_bytes(raw_bytes);
1736/// assert_eq!(num, 0x78563412);
1737/// ```
1738///
1739/// Turning a pointer into a `usize`:
1740///
1741/// ```no_run
1742/// let ptr = &0;
1743/// let ptr_num_transmute = unsafe {
1744///     std::mem::transmute::<&i32, usize>(ptr)
1745/// };
1746///
1747/// // Use an `as` cast instead
1748/// let ptr_num_cast = ptr as *const i32 as usize;
1749/// ```
1750///
1751/// Note that using `transmute` to turn a pointer to a `usize` is (as noted above) [undefined
1752/// behavior][ub] in `const` contexts. Also outside of consts, this operation might not behave
1753/// as expected -- this is touching on many unspecified aspects of the Rust memory model.
1754/// Depending on what the code is doing, the following alternatives are preferable to
1755/// pointer-to-integer transmutation:
1756/// - If the code just wants to store data of arbitrary type in some buffer and needs to pick a
1757///   type for that buffer, it can use [`MaybeUninit`][crate::mem::MaybeUninit].
1758/// - If the code actually wants to work on the address the pointer points to, it can use `as`
1759///   casts or [`ptr.addr()`][pointer::addr].
1760///
1761/// Turning a `*mut T` into a `&mut T`:
1762///
1763/// ```
1764/// let ptr: *mut i32 = &mut 0;
1765/// let ref_transmuted = unsafe {
1766///     std::mem::transmute::<*mut i32, &mut i32>(ptr)
1767/// };
1768///
1769/// // Use a reborrow instead
1770/// let ref_casted = unsafe { &mut *ptr };
1771/// ```
1772///
1773/// Turning a `&mut T` into a `&mut U`:
1774///
1775/// ```
1776/// let ptr = &mut 0;
1777/// let val_transmuted = unsafe {
1778///     std::mem::transmute::<&mut i32, &mut u32>(ptr)
1779/// };
1780///
1781/// // Now, put together `as` and reborrowing - note the chaining of `as`
1782/// // `as` is not transitive
1783/// let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) };
1784/// ```
1785///
1786/// Turning a `&str` into a `&[u8]`:
1787///
1788/// ```
1789/// // this is not a good way to do this.
1790/// let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") };
1791/// assert_eq!(slice, &[82, 117, 115, 116]);
1792///
1793/// // You could use `str::as_bytes`
1794/// let slice = "Rust".as_bytes();
1795/// assert_eq!(slice, &[82, 117, 115, 116]);
1796///
1797/// // Or, just use a byte string, if you have control over the string
1798/// // literal
1799/// assert_eq!(b"Rust", &[82, 117, 115, 116]);
1800/// ```
1801///
1802/// Turning a `Vec<&T>` into a `Vec<Option<&T>>`.
1803///
1804/// To transmute the inner type of the contents of a container, you must make sure to not
1805/// violate any of the container's invariants. For `Vec`, this means that both the size
1806/// *and alignment* of the inner types have to match. Other containers might rely on the
1807/// size of the type, alignment, or even the `TypeId`, in which case transmuting wouldn't
1808/// be possible at all without violating the container invariants.
1809///
1810/// ```
1811/// let store = [0, 1, 2, 3];
1812/// let v_orig = store.iter().collect::<Vec<&i32>>();
1813///
1814/// // clone the vector as we will reuse them later
1815/// let v_clone = v_orig.clone();
1816///
1817/// // Using transmute: this relies on the unspecified data layout of `Vec`, which is a
1818/// // bad idea and could cause Undefined Behavior.
1819/// // However, it is no-copy.
1820/// let v_transmuted = unsafe {
1821///     std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone)
1822/// };
1823///
1824/// let v_clone = v_orig.clone();
1825///
1826/// // This is the suggested, safe way.
1827/// // It may copy the entire vector into a new one though, but also may not.
1828/// let v_collected = v_clone.into_iter()
1829///                          .map(Some)
1830///                          .collect::<Vec<Option<&i32>>>();
1831///
1832/// let v_clone = v_orig.clone();
1833///
1834/// // This is the proper no-copy, unsafe way of "transmuting" a `Vec`, without relying on the
1835/// // data layout. Instead of literally calling `transmute`, we perform a pointer cast, but
1836/// // in terms of converting the original inner type (`&i32`) to the new one (`Option<&i32>`),
1837/// // this has all the same caveats. Besides the information provided above, also consult the
1838/// // [`from_raw_parts`] documentation.
1839/// let v_from_raw = unsafe {
1840// FIXME Update this when vec_into_raw_parts is stabilized
1841///     // Ensure the original vector is not dropped.
1842///     let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
1843///     Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
1844///                         v_clone.len(),
1845///                         v_clone.capacity())
1846/// };
1847/// ```
1848///
1849/// [`from_raw_parts`]: ../../std/vec/struct.Vec.html#method.from_raw_parts
1850///
1851/// Implementing `split_at_mut`:
1852///
1853/// ```
1854/// use std::{slice, mem};
1855///
1856/// // There are multiple ways to do this, and there are multiple problems
1857/// // with the following (transmute) way.
1858/// fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize)
1859///                              -> (&mut [T], &mut [T]) {
1860///     let len = slice.len();
1861///     assert!(mid <= len);
1862///     unsafe {
1863///         let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
1864///         // first: transmute is not type safe; all it checks is that T and
1865///         // U are of the same size. Second, right here, you have two
1866///         // mutable references pointing to the same memory.
1867///         (&mut slice[0..mid], &mut slice2[mid..len])
1868///     }
1869/// }
1870///
1871/// // This gets rid of the type safety problems; `&mut *` will *only* give
1872/// // you a `&mut T` from a `&mut T` or `*mut T`.
1873/// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
1874///                          -> (&mut [T], &mut [T]) {
1875///     let len = slice.len();
1876///     assert!(mid <= len);
1877///     unsafe {
1878///         let slice2 = &mut *(slice as *mut [T]);
1879///         // however, you still have two mutable references pointing to
1880///         // the same memory.
1881///         (&mut slice[0..mid], &mut slice2[mid..len])
1882///     }
1883/// }
1884///
1885/// // This is how the standard library does it. This is the best method, if
1886/// // you need to do something like this
1887/// fn split_at_stdlib<T>(slice: &mut [T], mid: usize)
1888///                       -> (&mut [T], &mut [T]) {
1889///     let len = slice.len();
1890///     assert!(mid <= len);
1891///     unsafe {
1892///         let ptr = slice.as_mut_ptr();
1893///         // This now has three mutable references pointing at the same
1894///         // memory. `slice`, the rvalue ret.0, and the rvalue ret.1.
1895///         // `slice` is never used after `let ptr = ...`, and so one can
1896///         // treat it as "dead", and therefore, you only have two real
1897///         // mutable slices.
1898///         (slice::from_raw_parts_mut(ptr, mid),
1899///          slice::from_raw_parts_mut(ptr.add(mid), len - mid))
1900///     }
1901/// }
1902/// ```
1903#[stable(feature = "rust1", since = "1.0.0")]
1904#[cfg_attr(bootstrap, rustc_allowed_through_unstable_modules)]
1905#[cfg_attr(
1906    not(bootstrap),
1907    rustc_allowed_through_unstable_modules = "import this function via `std::mem` instead"
1908)]
1909#[rustc_const_stable(feature = "const_transmute", since = "1.56.0")]
1910#[rustc_diagnostic_item = "transmute"]
1911#[rustc_nounwind]
1912#[rustc_intrinsic]
1913#[rustc_intrinsic_must_be_overridden]
1914pub const unsafe fn transmute<Src, Dst>(_src: Src) -> Dst {
1915    unreachable!()
1916}
1917
1918/// Like [`transmute`], but even less checked at compile-time: rather than
1919/// giving an error for `size_of::<Src>() != size_of::<Dst>()`, it's
1920/// **Undefined Behavior** at runtime.
1921///
1922/// Prefer normal `transmute` where possible, for the extra checking, since
1923/// both do exactly the same thing at runtime, if they both compile.
1924///
1925/// This is not expected to ever be exposed directly to users, rather it
1926/// may eventually be exposed through some more-constrained API.
1927#[rustc_intrinsic_const_stable_indirect]
1928#[rustc_nounwind]
1929#[rustc_intrinsic]
1930#[rustc_intrinsic_must_be_overridden]
1931pub const unsafe fn transmute_unchecked<Src, Dst>(_src: Src) -> Dst {
1932    unreachable!()
1933}
1934
1935/// Returns `true` if the actual type given as `T` requires drop
1936/// glue; returns `false` if the actual type provided for `T`
1937/// implements `Copy`.
1938///
1939/// If the actual type neither requires drop glue nor implements
1940/// `Copy`, then the return value of this function is unspecified.
1941///
1942/// Note that, unlike most intrinsics, this is safe to call;
1943/// it does not require an `unsafe` block.
1944/// Therefore, implementations must not require the user to uphold
1945/// any safety invariants.
1946///
1947/// The stabilized version of this intrinsic is [`mem::needs_drop`](crate::mem::needs_drop).
1948#[rustc_intrinsic_const_stable_indirect]
1949#[rustc_nounwind]
1950#[rustc_intrinsic]
1951#[rustc_intrinsic_must_be_overridden]
1952pub const fn needs_drop<T: ?Sized>() -> bool {
1953    unreachable!()
1954}
1955
1956/// Calculates the offset from a pointer.
1957///
1958/// This is implemented as an intrinsic to avoid converting to and from an
1959/// integer, since the conversion would throw away aliasing information.
1960///
1961/// This can only be used with `Ptr` as a raw pointer type (`*mut` or `*const`)
1962/// to a `Sized` pointee and with `Delta` as `usize` or `isize`.  Any other
1963/// instantiations may arbitrarily misbehave, and that's *not* a compiler bug.
1964///
1965/// # Safety
1966///
1967/// If the computed offset is non-zero, then both the starting and resulting pointer must be
1968/// either in bounds or at the end of an allocated object. If either pointer is out
1969/// of bounds or arithmetic overflow occurs then this operation is undefined behavior.
1970///
1971/// The stabilized version of this intrinsic is [`pointer::offset`].
1972#[must_use = "returns a new pointer rather than modifying its argument"]
1973#[rustc_intrinsic_const_stable_indirect]
1974#[rustc_nounwind]
1975#[rustc_intrinsic]
1976#[rustc_intrinsic_must_be_overridden]
1977pub const unsafe fn offset<Ptr, Delta>(_dst: Ptr, _offset: Delta) -> Ptr {
1978    unreachable!()
1979}
1980
1981/// Calculates the offset from a pointer, potentially wrapping.
1982///
1983/// This is implemented as an intrinsic to avoid converting to and from an
1984/// integer, since the conversion inhibits certain optimizations.
1985///
1986/// # Safety
1987///
1988/// Unlike the `offset` intrinsic, this intrinsic does not restrict the
1989/// resulting pointer to point into or at the end of an allocated
1990/// object, and it wraps with two's complement arithmetic. The resulting
1991/// value is not necessarily valid to be used to actually access memory.
1992///
1993/// The stabilized version of this intrinsic is [`pointer::wrapping_offset`].
1994#[must_use = "returns a new pointer rather than modifying its argument"]
1995#[rustc_intrinsic_const_stable_indirect]
1996#[rustc_nounwind]
1997#[rustc_intrinsic]
1998#[rustc_intrinsic_must_be_overridden]
1999pub const unsafe fn arith_offset<T>(_dst: *const T, _offset: isize) -> *const T {
2000    unreachable!()
2001}
2002
2003/// Masks out bits of the pointer according to a mask.
2004///
2005/// Note that, unlike most intrinsics, this is safe to call;
2006/// it does not require an `unsafe` block.
2007/// Therefore, implementations must not require the user to uphold
2008/// any safety invariants.
2009///
2010/// Consider using [`pointer::mask`] instead.
2011#[rustc_nounwind]
2012#[rustc_intrinsic]
2013#[rustc_intrinsic_must_be_overridden]
2014pub fn ptr_mask<T>(_ptr: *const T, _mask: usize) -> *const T {
2015    unreachable!()
2016}
2017
2018/// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
2019/// a size of `count` * `size_of::<T>()` and an alignment of
2020/// `min_align_of::<T>()`
2021///
2022/// The volatile parameter is set to `true`, so it will not be optimized out
2023/// unless size is equal to zero.
2024///
2025/// This intrinsic does not have a stable counterpart.
2026#[rustc_intrinsic]
2027#[rustc_intrinsic_must_be_overridden]
2028#[rustc_nounwind]
2029pub unsafe fn volatile_copy_nonoverlapping_memory<T>(_dst: *mut T, _src: *const T, _count: usize) {
2030    unreachable!()
2031}
2032/// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
2033/// a size of `count * size_of::<T>()` and an alignment of
2034/// `min_align_of::<T>()`
2035///
2036/// The volatile parameter is set to `true`, so it will not be optimized out
2037/// unless size is equal to zero.
2038///
2039/// This intrinsic does not have a stable counterpart.
2040#[rustc_intrinsic]
2041#[rustc_intrinsic_must_be_overridden]
2042#[rustc_nounwind]
2043pub unsafe fn volatile_copy_memory<T>(_dst: *mut T, _src: *const T, _count: usize) {
2044    unreachable!()
2045}
2046/// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
2047/// size of `count * size_of::<T>()` and an alignment of
2048/// `min_align_of::<T>()`.
2049///
2050/// The volatile parameter is set to `true`, so it will not be optimized out
2051/// unless size is equal to zero.
2052///
2053/// This intrinsic does not have a stable counterpart.
2054#[rustc_intrinsic]
2055#[rustc_intrinsic_must_be_overridden]
2056#[rustc_nounwind]
2057pub unsafe fn volatile_set_memory<T>(_dst: *mut T, _val: u8, _count: usize) {
2058    unreachable!()
2059}
2060
2061/// Performs a volatile load from the `src` pointer.
2062///
2063/// The stabilized version of this intrinsic is [`core::ptr::read_volatile`].
2064#[rustc_intrinsic]
2065#[rustc_intrinsic_must_be_overridden]
2066#[rustc_nounwind]
2067pub unsafe fn volatile_load<T>(_src: *const T) -> T {
2068    unreachable!()
2069}
2070/// Performs a volatile store to the `dst` pointer.
2071///
2072/// The stabilized version of this intrinsic is [`core::ptr::write_volatile`].
2073#[rustc_intrinsic]
2074#[rustc_intrinsic_must_be_overridden]
2075#[rustc_nounwind]
2076pub unsafe fn volatile_store<T>(_dst: *mut T, _val: T) {
2077    unreachable!()
2078}
2079
2080/// Performs a volatile load from the `src` pointer
2081/// The pointer is not required to be aligned.
2082///
2083/// This intrinsic does not have a stable counterpart.
2084#[rustc_intrinsic]
2085#[rustc_intrinsic_must_be_overridden]
2086#[rustc_nounwind]
2087#[rustc_diagnostic_item = "intrinsics_unaligned_volatile_load"]
2088pub unsafe fn unaligned_volatile_load<T>(_src: *const T) -> T {
2089    unreachable!()
2090}
2091/// Performs a volatile store to the `dst` pointer.
2092/// The pointer is not required to be aligned.
2093///
2094/// This intrinsic does not have a stable counterpart.
2095#[rustc_intrinsic]
2096#[rustc_intrinsic_must_be_overridden]
2097#[rustc_nounwind]
2098#[rustc_diagnostic_item = "intrinsics_unaligned_volatile_store"]
2099pub unsafe fn unaligned_volatile_store<T>(_dst: *mut T, _val: T) {
2100    unreachable!()
2101}
2102
2103/// Returns the square root of an `f16`
2104///
2105/// The stabilized version of this intrinsic is
2106/// [`f16::sqrt`](../../std/primitive.f16.html#method.sqrt)
2107#[rustc_intrinsic]
2108#[rustc_intrinsic_must_be_overridden]
2109#[rustc_nounwind]
2110pub unsafe fn sqrtf16(_x: f16) -> f16 {
2111    unreachable!()
2112}
2113/// Returns the square root of an `f32`
2114///
2115/// The stabilized version of this intrinsic is
2116/// [`f32::sqrt`](../../std/primitive.f32.html#method.sqrt)
2117#[rustc_intrinsic]
2118#[rustc_intrinsic_must_be_overridden]
2119#[rustc_nounwind]
2120pub unsafe fn sqrtf32(_x: f32) -> f32 {
2121    unreachable!()
2122}
2123/// Returns the square root of an `f64`
2124///
2125/// The stabilized version of this intrinsic is
2126/// [`f64::sqrt`](../../std/primitive.f64.html#method.sqrt)
2127#[rustc_intrinsic]
2128#[rustc_intrinsic_must_be_overridden]
2129#[rustc_nounwind]
2130pub unsafe fn sqrtf64(_x: f64) -> f64 {
2131    unreachable!()
2132}
2133/// Returns the square root of an `f128`
2134///
2135/// The stabilized version of this intrinsic is
2136/// [`f128::sqrt`](../../std/primitive.f128.html#method.sqrt)
2137#[rustc_intrinsic]
2138#[rustc_intrinsic_must_be_overridden]
2139#[rustc_nounwind]
2140pub unsafe fn sqrtf128(_x: f128) -> f128 {
2141    unreachable!()
2142}
2143
2144/// Raises an `f16` to an integer power.
2145///
2146/// The stabilized version of this intrinsic is
2147/// [`f16::powi`](../../std/primitive.f16.html#method.powi)
2148#[rustc_intrinsic]
2149#[rustc_intrinsic_must_be_overridden]
2150#[rustc_nounwind]
2151pub unsafe fn powif16(_a: f16, _x: i32) -> f16 {
2152    unreachable!()
2153}
2154/// Raises an `f32` to an integer power.
2155///
2156/// The stabilized version of this intrinsic is
2157/// [`f32::powi`](../../std/primitive.f32.html#method.powi)
2158#[rustc_intrinsic]
2159#[rustc_intrinsic_must_be_overridden]
2160#[rustc_nounwind]
2161pub unsafe fn powif32(_a: f32, _x: i32) -> f32 {
2162    unreachable!()
2163}
2164/// Raises an `f64` to an integer power.
2165///
2166/// The stabilized version of this intrinsic is
2167/// [`f64::powi`](../../std/primitive.f64.html#method.powi)
2168#[rustc_intrinsic]
2169#[rustc_intrinsic_must_be_overridden]
2170#[rustc_nounwind]
2171pub unsafe fn powif64(_a: f64, _x: i32) -> f64 {
2172    unreachable!()
2173}
2174/// Raises an `f128` to an integer power.
2175///
2176/// The stabilized version of this intrinsic is
2177/// [`f128::powi`](../../std/primitive.f128.html#method.powi)
2178#[rustc_intrinsic]
2179#[rustc_intrinsic_must_be_overridden]
2180#[rustc_nounwind]
2181pub unsafe fn powif128(_a: f128, _x: i32) -> f128 {
2182    unreachable!()
2183}
2184
2185/// Returns the sine of an `f16`.
2186///
2187/// The stabilized version of this intrinsic is
2188/// [`f16::sin`](../../std/primitive.f16.html#method.sin)
2189#[rustc_intrinsic]
2190#[rustc_intrinsic_must_be_overridden]
2191#[rustc_nounwind]
2192pub unsafe fn sinf16(_x: f16) -> f16 {
2193    unreachable!()
2194}
2195/// Returns the sine of an `f32`.
2196///
2197/// The stabilized version of this intrinsic is
2198/// [`f32::sin`](../../std/primitive.f32.html#method.sin)
2199#[rustc_intrinsic]
2200#[rustc_intrinsic_must_be_overridden]
2201#[rustc_nounwind]
2202pub unsafe fn sinf32(_x: f32) -> f32 {
2203    unreachable!()
2204}
2205/// Returns the sine of an `f64`.
2206///
2207/// The stabilized version of this intrinsic is
2208/// [`f64::sin`](../../std/primitive.f64.html#method.sin)
2209#[rustc_intrinsic]
2210#[rustc_intrinsic_must_be_overridden]
2211#[rustc_nounwind]
2212pub unsafe fn sinf64(_x: f64) -> f64 {
2213    unreachable!()
2214}
2215/// Returns the sine of an `f128`.
2216///
2217/// The stabilized version of this intrinsic is
2218/// [`f128::sin`](../../std/primitive.f128.html#method.sin)
2219#[rustc_intrinsic]
2220#[rustc_intrinsic_must_be_overridden]
2221#[rustc_nounwind]
2222pub unsafe fn sinf128(_x: f128) -> f128 {
2223    unreachable!()
2224}
2225
2226/// Returns the cosine of an `f16`.
2227///
2228/// The stabilized version of this intrinsic is
2229/// [`f16::cos`](../../std/primitive.f16.html#method.cos)
2230#[rustc_intrinsic]
2231#[rustc_intrinsic_must_be_overridden]
2232#[rustc_nounwind]
2233pub unsafe fn cosf16(_x: f16) -> f16 {
2234    unreachable!()
2235}
2236/// Returns the cosine of an `f32`.
2237///
2238/// The stabilized version of this intrinsic is
2239/// [`f32::cos`](../../std/primitive.f32.html#method.cos)
2240#[rustc_intrinsic]
2241#[rustc_intrinsic_must_be_overridden]
2242#[rustc_nounwind]
2243pub unsafe fn cosf32(_x: f32) -> f32 {
2244    unreachable!()
2245}
2246/// Returns the cosine of an `f64`.
2247///
2248/// The stabilized version of this intrinsic is
2249/// [`f64::cos`](../../std/primitive.f64.html#method.cos)
2250#[rustc_intrinsic]
2251#[rustc_intrinsic_must_be_overridden]
2252#[rustc_nounwind]
2253pub unsafe fn cosf64(_x: f64) -> f64 {
2254    unreachable!()
2255}
2256/// Returns the cosine of an `f128`.
2257///
2258/// The stabilized version of this intrinsic is
2259/// [`f128::cos`](../../std/primitive.f128.html#method.cos)
2260#[rustc_intrinsic]
2261#[rustc_intrinsic_must_be_overridden]
2262#[rustc_nounwind]
2263pub unsafe fn cosf128(_x: f128) -> f128 {
2264    unreachable!()
2265}
2266
2267/// Raises an `f16` to an `f16` power.
2268///
2269/// The stabilized version of this intrinsic is
2270/// [`f16::powf`](../../std/primitive.f16.html#method.powf)
2271#[rustc_intrinsic]
2272#[rustc_intrinsic_must_be_overridden]
2273#[rustc_nounwind]
2274pub unsafe fn powf16(_a: f16, _x: f16) -> f16 {
2275    unreachable!()
2276}
2277/// Raises an `f32` to an `f32` power.
2278///
2279/// The stabilized version of this intrinsic is
2280/// [`f32::powf`](../../std/primitive.f32.html#method.powf)
2281#[rustc_intrinsic]
2282#[rustc_intrinsic_must_be_overridden]
2283#[rustc_nounwind]
2284pub unsafe fn powf32(_a: f32, _x: f32) -> f32 {
2285    unreachable!()
2286}
2287/// Raises an `f64` to an `f64` power.
2288///
2289/// The stabilized version of this intrinsic is
2290/// [`f64::powf`](../../std/primitive.f64.html#method.powf)
2291#[rustc_intrinsic]
2292#[rustc_intrinsic_must_be_overridden]
2293#[rustc_nounwind]
2294pub unsafe fn powf64(_a: f64, _x: f64) -> f64 {
2295    unreachable!()
2296}
2297/// Raises an `f128` to an `f128` power.
2298///
2299/// The stabilized version of this intrinsic is
2300/// [`f128::powf`](../../std/primitive.f128.html#method.powf)
2301#[rustc_intrinsic]
2302#[rustc_intrinsic_must_be_overridden]
2303#[rustc_nounwind]
2304pub unsafe fn powf128(_a: f128, _x: f128) -> f128 {
2305    unreachable!()
2306}
2307
2308/// Returns the exponential of an `f16`.
2309///
2310/// The stabilized version of this intrinsic is
2311/// [`f16::exp`](../../std/primitive.f16.html#method.exp)
2312#[rustc_intrinsic]
2313#[rustc_intrinsic_must_be_overridden]
2314#[rustc_nounwind]
2315pub unsafe fn expf16(_x: f16) -> f16 {
2316    unreachable!()
2317}
2318/// Returns the exponential of an `f32`.
2319///
2320/// The stabilized version of this intrinsic is
2321/// [`f32::exp`](../../std/primitive.f32.html#method.exp)
2322#[rustc_intrinsic]
2323#[rustc_intrinsic_must_be_overridden]
2324#[rustc_nounwind]
2325pub unsafe fn expf32(_x: f32) -> f32 {
2326    unreachable!()
2327}
2328/// Returns the exponential of an `f64`.
2329///
2330/// The stabilized version of this intrinsic is
2331/// [`f64::exp`](../../std/primitive.f64.html#method.exp)
2332#[rustc_intrinsic]
2333#[rustc_intrinsic_must_be_overridden]
2334#[rustc_nounwind]
2335pub unsafe fn expf64(_x: f64) -> f64 {
2336    unreachable!()
2337}
2338/// Returns the exponential of an `f128`.
2339///
2340/// The stabilized version of this intrinsic is
2341/// [`f128::exp`](../../std/primitive.f128.html#method.exp)
2342#[rustc_intrinsic]
2343#[rustc_intrinsic_must_be_overridden]
2344#[rustc_nounwind]
2345pub unsafe fn expf128(_x: f128) -> f128 {
2346    unreachable!()
2347}
2348
2349/// Returns 2 raised to the power of an `f16`.
2350///
2351/// The stabilized version of this intrinsic is
2352/// [`f16::exp2`](../../std/primitive.f16.html#method.exp2)
2353#[rustc_intrinsic]
2354#[rustc_intrinsic_must_be_overridden]
2355#[rustc_nounwind]
2356pub unsafe fn exp2f16(_x: f16) -> f16 {
2357    unreachable!()
2358}
2359/// Returns 2 raised to the power of an `f32`.
2360///
2361/// The stabilized version of this intrinsic is
2362/// [`f32::exp2`](../../std/primitive.f32.html#method.exp2)
2363#[rustc_intrinsic]
2364#[rustc_intrinsic_must_be_overridden]
2365#[rustc_nounwind]
2366pub unsafe fn exp2f32(_x: f32) -> f32 {
2367    unreachable!()
2368}
2369/// Returns 2 raised to the power of an `f64`.
2370///
2371/// The stabilized version of this intrinsic is
2372/// [`f64::exp2`](../../std/primitive.f64.html#method.exp2)
2373#[rustc_intrinsic]
2374#[rustc_intrinsic_must_be_overridden]
2375#[rustc_nounwind]
2376pub unsafe fn exp2f64(_x: f64) -> f64 {
2377    unreachable!()
2378}
2379/// Returns 2 raised to the power of an `f128`.
2380///
2381/// The stabilized version of this intrinsic is
2382/// [`f128::exp2`](../../std/primitive.f128.html#method.exp2)
2383#[rustc_intrinsic]
2384#[rustc_intrinsic_must_be_overridden]
2385#[rustc_nounwind]
2386pub unsafe fn exp2f128(_x: f128) -> f128 {
2387    unreachable!()
2388}
2389
2390/// Returns the natural logarithm of an `f16`.
2391///
2392/// The stabilized version of this intrinsic is
2393/// [`f16::ln`](../../std/primitive.f16.html#method.ln)
2394#[rustc_intrinsic]
2395#[rustc_intrinsic_must_be_overridden]
2396#[rustc_nounwind]
2397pub unsafe fn logf16(_x: f16) -> f16 {
2398    unreachable!()
2399}
2400/// Returns the natural logarithm of an `f32`.
2401///
2402/// The stabilized version of this intrinsic is
2403/// [`f32::ln`](../../std/primitive.f32.html#method.ln)
2404#[rustc_intrinsic]
2405#[rustc_intrinsic_must_be_overridden]
2406#[rustc_nounwind]
2407pub unsafe fn logf32(_x: f32) -> f32 {
2408    unreachable!()
2409}
2410/// Returns the natural logarithm of an `f64`.
2411///
2412/// The stabilized version of this intrinsic is
2413/// [`f64::ln`](../../std/primitive.f64.html#method.ln)
2414#[rustc_intrinsic]
2415#[rustc_intrinsic_must_be_overridden]
2416#[rustc_nounwind]
2417pub unsafe fn logf64(_x: f64) -> f64 {
2418    unreachable!()
2419}
2420/// Returns the natural logarithm of an `f128`.
2421///
2422/// The stabilized version of this intrinsic is
2423/// [`f128::ln`](../../std/primitive.f128.html#method.ln)
2424#[rustc_intrinsic]
2425#[rustc_intrinsic_must_be_overridden]
2426#[rustc_nounwind]
2427pub unsafe fn logf128(_x: f128) -> f128 {
2428    unreachable!()
2429}
2430
2431/// Returns the base 10 logarithm of an `f16`.
2432///
2433/// The stabilized version of this intrinsic is
2434/// [`f16::log10`](../../std/primitive.f16.html#method.log10)
2435#[rustc_intrinsic]
2436#[rustc_intrinsic_must_be_overridden]
2437#[rustc_nounwind]
2438pub unsafe fn log10f16(_x: f16) -> f16 {
2439    unreachable!()
2440}
2441/// Returns the base 10 logarithm of an `f32`.
2442///
2443/// The stabilized version of this intrinsic is
2444/// [`f32::log10`](../../std/primitive.f32.html#method.log10)
2445#[rustc_intrinsic]
2446#[rustc_intrinsic_must_be_overridden]
2447#[rustc_nounwind]
2448pub unsafe fn log10f32(_x: f32) -> f32 {
2449    unreachable!()
2450}
2451/// Returns the base 10 logarithm of an `f64`.
2452///
2453/// The stabilized version of this intrinsic is
2454/// [`f64::log10`](../../std/primitive.f64.html#method.log10)
2455#[rustc_intrinsic]
2456#[rustc_intrinsic_must_be_overridden]
2457#[rustc_nounwind]
2458pub unsafe fn log10f64(_x: f64) -> f64 {
2459    unreachable!()
2460}
2461/// Returns the base 10 logarithm of an `f128`.
2462///
2463/// The stabilized version of this intrinsic is
2464/// [`f128::log10`](../../std/primitive.f128.html#method.log10)
2465#[rustc_intrinsic]
2466#[rustc_intrinsic_must_be_overridden]
2467#[rustc_nounwind]
2468pub unsafe fn log10f128(_x: f128) -> f128 {
2469    unreachable!()
2470}
2471
2472/// Returns the base 2 logarithm of an `f16`.
2473///
2474/// The stabilized version of this intrinsic is
2475/// [`f16::log2`](../../std/primitive.f16.html#method.log2)
2476#[rustc_intrinsic]
2477#[rustc_intrinsic_must_be_overridden]
2478#[rustc_nounwind]
2479pub unsafe fn log2f16(_x: f16) -> f16 {
2480    unreachable!()
2481}
2482/// Returns the base 2 logarithm of an `f32`.
2483///
2484/// The stabilized version of this intrinsic is
2485/// [`f32::log2`](../../std/primitive.f32.html#method.log2)
2486#[rustc_intrinsic]
2487#[rustc_intrinsic_must_be_overridden]
2488#[rustc_nounwind]
2489pub unsafe fn log2f32(_x: f32) -> f32 {
2490    unreachable!()
2491}
2492/// Returns the base 2 logarithm of an `f64`.
2493///
2494/// The stabilized version of this intrinsic is
2495/// [`f64::log2`](../../std/primitive.f64.html#method.log2)
2496#[rustc_intrinsic]
2497#[rustc_intrinsic_must_be_overridden]
2498#[rustc_nounwind]
2499pub unsafe fn log2f64(_x: f64) -> f64 {
2500    unreachable!()
2501}
2502/// Returns the base 2 logarithm of an `f128`.
2503///
2504/// The stabilized version of this intrinsic is
2505/// [`f128::log2`](../../std/primitive.f128.html#method.log2)
2506#[rustc_intrinsic]
2507#[rustc_intrinsic_must_be_overridden]
2508#[rustc_nounwind]
2509pub unsafe fn log2f128(_x: f128) -> f128 {
2510    unreachable!()
2511}
2512
2513/// Returns `a * b + c` for `f16` values.
2514///
2515/// The stabilized version of this intrinsic is
2516/// [`f16::mul_add`](../../std/primitive.f16.html#method.mul_add)
2517#[rustc_intrinsic]
2518#[rustc_intrinsic_must_be_overridden]
2519#[rustc_nounwind]
2520pub unsafe fn fmaf16(_a: f16, _b: f16, _c: f16) -> f16 {
2521    unreachable!()
2522}
2523/// Returns `a * b + c` for `f32` values.
2524///
2525/// The stabilized version of this intrinsic is
2526/// [`f32::mul_add`](../../std/primitive.f32.html#method.mul_add)
2527#[rustc_intrinsic]
2528#[rustc_intrinsic_must_be_overridden]
2529#[rustc_nounwind]
2530pub unsafe fn fmaf32(_a: f32, _b: f32, _c: f32) -> f32 {
2531    unreachable!()
2532}
2533/// Returns `a * b + c` for `f64` values.
2534///
2535/// The stabilized version of this intrinsic is
2536/// [`f64::mul_add`](../../std/primitive.f64.html#method.mul_add)
2537#[rustc_intrinsic]
2538#[rustc_intrinsic_must_be_overridden]
2539#[rustc_nounwind]
2540pub unsafe fn fmaf64(_a: f64, _b: f64, _c: f64) -> f64 {
2541    unreachable!()
2542}
2543/// Returns `a * b + c` for `f128` values.
2544///
2545/// The stabilized version of this intrinsic is
2546/// [`f128::mul_add`](../../std/primitive.f128.html#method.mul_add)
2547#[rustc_intrinsic]
2548#[rustc_intrinsic_must_be_overridden]
2549#[rustc_nounwind]
2550pub unsafe fn fmaf128(_a: f128, _b: f128, _c: f128) -> f128 {
2551    unreachable!()
2552}
2553
2554/// Returns `a * b + c` for `f16` values, non-deterministically executing
2555/// either a fused multiply-add or two operations with rounding of the
2556/// intermediate result.
2557///
2558/// The operation is fused if the code generator determines that target
2559/// instruction set has support for a fused operation, and that the fused
2560/// operation is more efficient than the equivalent, separate pair of mul
2561/// and add instructions. It is unspecified whether or not a fused operation
2562/// is selected, and that may depend on optimization level and context, for
2563/// example.
2564#[rustc_intrinsic]
2565#[rustc_intrinsic_must_be_overridden]
2566#[rustc_nounwind]
2567pub unsafe fn fmuladdf16(_a: f16, _b: f16, _c: f16) -> f16 {
2568    unreachable!()
2569}
2570/// Returns `a * b + c` for `f32` values, non-deterministically executing
2571/// either a fused multiply-add or two operations with rounding of the
2572/// intermediate result.
2573///
2574/// The operation is fused if the code generator determines that target
2575/// instruction set has support for a fused operation, and that the fused
2576/// operation is more efficient than the equivalent, separate pair of mul
2577/// and add instructions. It is unspecified whether or not a fused operation
2578/// is selected, and that may depend on optimization level and context, for
2579/// example.
2580#[rustc_intrinsic]
2581#[rustc_intrinsic_must_be_overridden]
2582#[rustc_nounwind]
2583pub unsafe fn fmuladdf32(_a: f32, _b: f32, _c: f32) -> f32 {
2584    unreachable!()
2585}
2586/// Returns `a * b + c` for `f64` values, non-deterministically executing
2587/// either a fused multiply-add or two operations with rounding of the
2588/// intermediate result.
2589///
2590/// The operation is fused if the code generator determines that target
2591/// instruction set has support for a fused operation, and that the fused
2592/// operation is more efficient than the equivalent, separate pair of mul
2593/// and add instructions. It is unspecified whether or not a fused operation
2594/// is selected, and that may depend on optimization level and context, for
2595/// example.
2596#[rustc_intrinsic]
2597#[rustc_intrinsic_must_be_overridden]
2598#[rustc_nounwind]
2599pub unsafe fn fmuladdf64(_a: f64, _b: f64, _c: f64) -> f64 {
2600    unreachable!()
2601}
2602/// Returns `a * b + c` for `f128` values, non-deterministically executing
2603/// either a fused multiply-add or two operations with rounding of the
2604/// intermediate result.
2605///
2606/// The operation is fused if the code generator determines that target
2607/// instruction set has support for a fused operation, and that the fused
2608/// operation is more efficient than the equivalent, separate pair of mul
2609/// and add instructions. It is unspecified whether or not a fused operation
2610/// is selected, and that may depend on optimization level and context, for
2611/// example.
2612#[rustc_intrinsic]
2613#[rustc_intrinsic_must_be_overridden]
2614#[rustc_nounwind]
2615pub unsafe fn fmuladdf128(_a: f128, _b: f128, _c: f128) -> f128 {
2616    unreachable!()
2617}
2618
2619/// Returns the largest integer less than or equal to an `f16`.
2620///
2621/// The stabilized version of this intrinsic is
2622/// [`f16::floor`](../../std/primitive.f16.html#method.floor)
2623#[rustc_intrinsic]
2624#[rustc_intrinsic_must_be_overridden]
2625#[rustc_nounwind]
2626pub unsafe fn floorf16(_x: f16) -> f16 {
2627    unreachable!()
2628}
2629/// Returns the largest integer less than or equal to an `f32`.
2630///
2631/// The stabilized version of this intrinsic is
2632/// [`f32::floor`](../../std/primitive.f32.html#method.floor)
2633#[rustc_intrinsic]
2634#[rustc_intrinsic_must_be_overridden]
2635#[rustc_nounwind]
2636pub unsafe fn floorf32(_x: f32) -> f32 {
2637    unreachable!()
2638}
2639/// Returns the largest integer less than or equal to an `f64`.
2640///
2641/// The stabilized version of this intrinsic is
2642/// [`f64::floor`](../../std/primitive.f64.html#method.floor)
2643#[rustc_intrinsic]
2644#[rustc_intrinsic_must_be_overridden]
2645#[rustc_nounwind]
2646pub unsafe fn floorf64(_x: f64) -> f64 {
2647    unreachable!()
2648}
2649/// Returns the largest integer less than or equal to an `f128`.
2650///
2651/// The stabilized version of this intrinsic is
2652/// [`f128::floor`](../../std/primitive.f128.html#method.floor)
2653#[rustc_intrinsic]
2654#[rustc_intrinsic_must_be_overridden]
2655#[rustc_nounwind]
2656pub unsafe fn floorf128(_x: f128) -> f128 {
2657    unreachable!()
2658}
2659
2660/// Returns the smallest integer greater than or equal to an `f16`.
2661///
2662/// The stabilized version of this intrinsic is
2663/// [`f16::ceil`](../../std/primitive.f16.html#method.ceil)
2664#[rustc_intrinsic]
2665#[rustc_intrinsic_must_be_overridden]
2666#[rustc_nounwind]
2667pub unsafe fn ceilf16(_x: f16) -> f16 {
2668    unreachable!()
2669}
2670/// Returns the smallest integer greater than or equal to an `f32`.
2671///
2672/// The stabilized version of this intrinsic is
2673/// [`f32::ceil`](../../std/primitive.f32.html#method.ceil)
2674#[rustc_intrinsic]
2675#[rustc_intrinsic_must_be_overridden]
2676#[rustc_nounwind]
2677pub unsafe fn ceilf32(_x: f32) -> f32 {
2678    unreachable!()
2679}
2680/// Returns the smallest integer greater than or equal to an `f64`.
2681///
2682/// The stabilized version of this intrinsic is
2683/// [`f64::ceil`](../../std/primitive.f64.html#method.ceil)
2684#[rustc_intrinsic]
2685#[rustc_intrinsic_must_be_overridden]
2686#[rustc_nounwind]
2687pub unsafe fn ceilf64(_x: f64) -> f64 {
2688    unreachable!()
2689}
2690/// Returns the smallest integer greater than or equal to an `f128`.
2691///
2692/// The stabilized version of this intrinsic is
2693/// [`f128::ceil`](../../std/primitive.f128.html#method.ceil)
2694#[rustc_intrinsic]
2695#[rustc_intrinsic_must_be_overridden]
2696#[rustc_nounwind]
2697pub unsafe fn ceilf128(_x: f128) -> f128 {
2698    unreachable!()
2699}
2700
2701/// Returns the integer part of an `f16`.
2702///
2703/// The stabilized version of this intrinsic is
2704/// [`f16::trunc`](../../std/primitive.f16.html#method.trunc)
2705#[rustc_intrinsic]
2706#[rustc_intrinsic_must_be_overridden]
2707#[rustc_nounwind]
2708pub unsafe fn truncf16(_x: f16) -> f16 {
2709    unreachable!()
2710}
2711/// Returns the integer part of an `f32`.
2712///
2713/// The stabilized version of this intrinsic is
2714/// [`f32::trunc`](../../std/primitive.f32.html#method.trunc)
2715#[rustc_intrinsic]
2716#[rustc_intrinsic_must_be_overridden]
2717#[rustc_nounwind]
2718pub unsafe fn truncf32(_x: f32) -> f32 {
2719    unreachable!()
2720}
2721/// Returns the integer part of an `f64`.
2722///
2723/// The stabilized version of this intrinsic is
2724/// [`f64::trunc`](../../std/primitive.f64.html#method.trunc)
2725#[rustc_intrinsic]
2726#[rustc_intrinsic_must_be_overridden]
2727#[rustc_nounwind]
2728pub unsafe fn truncf64(_x: f64) -> f64 {
2729    unreachable!()
2730}
2731/// Returns the integer part of an `f128`.
2732///
2733/// The stabilized version of this intrinsic is
2734/// [`f128::trunc`](../../std/primitive.f128.html#method.trunc)
2735#[rustc_intrinsic]
2736#[rustc_intrinsic_must_be_overridden]
2737#[rustc_nounwind]
2738pub unsafe fn truncf128(_x: f128) -> f128 {
2739    unreachable!()
2740}
2741
2742/// Returns the nearest integer to an `f16`. Changing the rounding mode is not possible in Rust,
2743/// so this rounds half-way cases to the number with an even least significant digit.
2744///
2745/// May raise an inexact floating-point exception if the argument is not an integer.
2746/// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions
2747/// cannot actually be utilized from Rust code.
2748/// In other words, this intrinsic is equivalent in behavior to `nearbyintf16` and `roundevenf16`.
2749///
2750/// The stabilized version of this intrinsic is
2751/// [`f16::round_ties_even`](../../std/primitive.f16.html#method.round_ties_even)
2752#[rustc_intrinsic]
2753#[rustc_intrinsic_must_be_overridden]
2754#[rustc_nounwind]
2755pub unsafe fn rintf16(_x: f16) -> f16 {
2756    unreachable!()
2757}
2758/// Returns the nearest integer to an `f32`. Changing the rounding mode is not possible in Rust,
2759/// so this rounds half-way cases to the number with an even least significant digit.
2760///
2761/// May raise an inexact floating-point exception if the argument is not an integer.
2762/// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions
2763/// cannot actually be utilized from Rust code.
2764/// In other words, this intrinsic is equivalent in behavior to `nearbyintf32` and `roundevenf32`.
2765///
2766/// The stabilized version of this intrinsic is
2767/// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even)
2768#[rustc_intrinsic]
2769#[rustc_intrinsic_must_be_overridden]
2770#[rustc_nounwind]
2771pub unsafe fn rintf32(_x: f32) -> f32 {
2772    unreachable!()
2773}
2774/// Returns the nearest integer to an `f64`. Changing the rounding mode is not possible in Rust,
2775/// so this rounds half-way cases to the number with an even least significant digit.
2776///
2777/// May raise an inexact floating-point exception if the argument is not an integer.
2778/// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions
2779/// cannot actually be utilized from Rust code.
2780/// In other words, this intrinsic is equivalent in behavior to `nearbyintf64` and `roundevenf64`.
2781///
2782/// The stabilized version of this intrinsic is
2783/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)
2784#[rustc_intrinsic]
2785#[rustc_intrinsic_must_be_overridden]
2786#[rustc_nounwind]
2787pub unsafe fn rintf64(_x: f64) -> f64 {
2788    unreachable!()
2789}
2790/// Returns the nearest integer to an `f128`. Changing the rounding mode is not possible in Rust,
2791/// so this rounds half-way cases to the number with an even least significant digit.
2792///
2793/// May raise an inexact floating-point exception if the argument is not an integer.
2794/// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions
2795/// cannot actually be utilized from Rust code.
2796/// In other words, this intrinsic is equivalent in behavior to `nearbyintf128` and `roundevenf128`.
2797///
2798/// The stabilized version of this intrinsic is
2799/// [`f128::round_ties_even`](../../std/primitive.f128.html#method.round_ties_even)
2800#[rustc_intrinsic]
2801#[rustc_intrinsic_must_be_overridden]
2802#[rustc_nounwind]
2803pub unsafe fn rintf128(_x: f128) -> f128 {
2804    unreachable!()
2805}
2806
2807/// Returns the nearest integer to an `f16`. Changing the rounding mode is not possible in Rust,
2808/// so this rounds half-way cases to the number with an even least significant digit.
2809///
2810/// This intrinsic does not have a stable counterpart.
2811#[rustc_intrinsic]
2812#[rustc_intrinsic_must_be_overridden]
2813#[rustc_nounwind]
2814pub unsafe fn nearbyintf16(_x: f16) -> f16 {
2815    unreachable!()
2816}
2817/// Returns the nearest integer to an `f32`. Changing the rounding mode is not possible in Rust,
2818/// so this rounds half-way cases to the number with an even least significant digit.
2819///
2820/// This intrinsic does not have a stable counterpart.
2821#[rustc_intrinsic]
2822#[rustc_intrinsic_must_be_overridden]
2823#[rustc_nounwind]
2824pub unsafe fn nearbyintf32(_x: f32) -> f32 {
2825    unreachable!()
2826}
2827/// Returns the nearest integer to an `f64`. Changing the rounding mode is not possible in Rust,
2828/// so this rounds half-way cases to the number with an even least significant digit.
2829///
2830/// This intrinsic does not have a stable counterpart.
2831#[rustc_intrinsic]
2832#[rustc_intrinsic_must_be_overridden]
2833#[rustc_nounwind]
2834pub unsafe fn nearbyintf64(_x: f64) -> f64 {
2835    unreachable!()
2836}
2837/// Returns the nearest integer to an `f128`. Changing the rounding mode is not possible in Rust,
2838/// so this rounds half-way cases to the number with an even least significant digit.
2839///
2840/// This intrinsic does not have a stable counterpart.
2841#[rustc_intrinsic]
2842#[rustc_intrinsic_must_be_overridden]
2843#[rustc_nounwind]
2844pub unsafe fn nearbyintf128(_x: f128) -> f128 {
2845    unreachable!()
2846}
2847
2848/// Returns the nearest integer to an `f16`. Rounds half-way cases away from zero.
2849///
2850/// The stabilized version of this intrinsic is
2851/// [`f16::round`](../../std/primitive.f16.html#method.round)
2852#[rustc_intrinsic]
2853#[rustc_intrinsic_must_be_overridden]
2854#[rustc_nounwind]
2855pub unsafe fn roundf16(_x: f16) -> f16 {
2856    unreachable!()
2857}
2858/// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
2859///
2860/// The stabilized version of this intrinsic is
2861/// [`f32::round`](../../std/primitive.f32.html#method.round)
2862#[rustc_intrinsic]
2863#[rustc_intrinsic_must_be_overridden]
2864#[rustc_nounwind]
2865pub unsafe fn roundf32(_x: f32) -> f32 {
2866    unreachable!()
2867}
2868/// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
2869///
2870/// The stabilized version of this intrinsic is
2871/// [`f64::round`](../../std/primitive.f64.html#method.round)
2872#[rustc_intrinsic]
2873#[rustc_intrinsic_must_be_overridden]
2874#[rustc_nounwind]
2875pub unsafe fn roundf64(_x: f64) -> f64 {
2876    unreachable!()
2877}
2878/// Returns the nearest integer to an `f128`. Rounds half-way cases away from zero.
2879///
2880/// The stabilized version of this intrinsic is
2881/// [`f128::round`](../../std/primitive.f128.html#method.round)
2882#[rustc_intrinsic]
2883#[rustc_intrinsic_must_be_overridden]
2884#[rustc_nounwind]
2885pub unsafe fn roundf128(_x: f128) -> f128 {
2886    unreachable!()
2887}
2888
2889/// Returns the nearest integer to an `f16`. Rounds half-way cases to the number
2890/// with an even least significant digit.
2891///
2892/// This intrinsic does not have a stable counterpart.
2893#[rustc_intrinsic]
2894#[rustc_intrinsic_must_be_overridden]
2895#[rustc_nounwind]
2896pub unsafe fn roundevenf16(_x: f16) -> f16 {
2897    unreachable!()
2898}
2899/// Returns the nearest integer to an `f32`. Rounds half-way cases to the number
2900/// with an even least significant digit.
2901///
2902/// This intrinsic does not have a stable counterpart.
2903#[rustc_intrinsic]
2904#[rustc_intrinsic_must_be_overridden]
2905#[rustc_nounwind]
2906pub unsafe fn roundevenf32(_x: f32) -> f32 {
2907    unreachable!()
2908}
2909/// Returns the nearest integer to an `f64`. Rounds half-way cases to the number
2910/// with an even least significant digit.
2911///
2912/// This intrinsic does not have a stable counterpart.
2913#[rustc_intrinsic]
2914#[rustc_intrinsic_must_be_overridden]
2915#[rustc_nounwind]
2916pub unsafe fn roundevenf64(_x: f64) -> f64 {
2917    unreachable!()
2918}
2919/// Returns the nearest integer to an `f128`. Rounds half-way cases to the number
2920/// with an even least significant digit.
2921///
2922/// This intrinsic does not have a stable counterpart.
2923#[rustc_intrinsic]
2924#[rustc_intrinsic_must_be_overridden]
2925#[rustc_nounwind]
2926pub unsafe fn roundevenf128(_x: f128) -> f128 {
2927    unreachable!()
2928}
2929
2930/// Float addition that allows optimizations based on algebraic rules.
2931/// May assume inputs are finite.
2932///
2933/// This intrinsic does not have a stable counterpart.
2934#[rustc_intrinsic]
2935#[rustc_intrinsic_must_be_overridden]
2936#[rustc_nounwind]
2937pub unsafe fn fadd_fast<T: Copy>(_a: T, _b: T) -> T {
2938    unreachable!()
2939}
2940
2941/// Float subtraction that allows optimizations based on algebraic rules.
2942/// May assume inputs are finite.
2943///
2944/// This intrinsic does not have a stable counterpart.
2945#[rustc_intrinsic]
2946#[rustc_intrinsic_must_be_overridden]
2947#[rustc_nounwind]
2948pub unsafe fn fsub_fast<T: Copy>(_a: T, _b: T) -> T {
2949    unreachable!()
2950}
2951
2952/// Float multiplication that allows optimizations based on algebraic rules.
2953/// May assume inputs are finite.
2954///
2955/// This intrinsic does not have a stable counterpart.
2956#[rustc_intrinsic]
2957#[rustc_intrinsic_must_be_overridden]
2958#[rustc_nounwind]
2959pub unsafe fn fmul_fast<T: Copy>(_a: T, _b: T) -> T {
2960    unreachable!()
2961}
2962
2963/// Float division that allows optimizations based on algebraic rules.
2964/// May assume inputs are finite.
2965///
2966/// This intrinsic does not have a stable counterpart.
2967#[rustc_intrinsic]
2968#[rustc_intrinsic_must_be_overridden]
2969#[rustc_nounwind]
2970pub unsafe fn fdiv_fast<T: Copy>(_a: T, _b: T) -> T {
2971    unreachable!()
2972}
2973
2974/// Float remainder that allows optimizations based on algebraic rules.
2975/// May assume inputs are finite.
2976///
2977/// This intrinsic does not have a stable counterpart.
2978#[rustc_intrinsic]
2979#[rustc_intrinsic_must_be_overridden]
2980#[rustc_nounwind]
2981pub unsafe fn frem_fast<T: Copy>(_a: T, _b: T) -> T {
2982    unreachable!()
2983}
2984
2985/// Converts with LLVM’s fptoui/fptosi, which may return undef for values out of range
2986/// (<https://github.com/rust-lang/rust/issues/10184>)
2987///
2988/// Stabilized as [`f32::to_int_unchecked`] and [`f64::to_int_unchecked`].
2989#[rustc_intrinsic]
2990#[rustc_intrinsic_must_be_overridden]
2991#[rustc_nounwind]
2992pub unsafe fn float_to_int_unchecked<Float: Copy, Int: Copy>(_value: Float) -> Int {
2993    unreachable!()
2994}
2995
2996/// Float addition that allows optimizations based on algebraic rules.
2997///
2998/// This intrinsic does not have a stable counterpart.
2999#[rustc_nounwind]
3000#[rustc_intrinsic]
3001#[rustc_intrinsic_must_be_overridden]
3002pub fn fadd_algebraic<T: Copy>(_a: T, _b: T) -> T {
3003    unimplemented!()
3004}
3005
3006/// Float subtraction that allows optimizations based on algebraic rules.
3007///
3008/// This intrinsic does not have a stable counterpart.
3009#[rustc_nounwind]
3010#[rustc_intrinsic]
3011#[rustc_intrinsic_must_be_overridden]
3012pub fn fsub_algebraic<T: Copy>(_a: T, _b: T) -> T {
3013    unimplemented!()
3014}
3015
3016/// Float multiplication that allows optimizations based on algebraic rules.
3017///
3018/// This intrinsic does not have a stable counterpart.
3019#[rustc_nounwind]
3020#[rustc_intrinsic]
3021#[rustc_intrinsic_must_be_overridden]
3022pub fn fmul_algebraic<T: Copy>(_a: T, _b: T) -> T {
3023    unimplemented!()
3024}
3025
3026/// Float division that allows optimizations based on algebraic rules.
3027///
3028/// This intrinsic does not have a stable counterpart.
3029#[rustc_nounwind]
3030#[rustc_intrinsic]
3031#[rustc_intrinsic_must_be_overridden]
3032pub fn fdiv_algebraic<T: Copy>(_a: T, _b: T) -> T {
3033    unimplemented!()
3034}
3035
3036/// Float remainder that allows optimizations based on algebraic rules.
3037///
3038/// This intrinsic does not have a stable counterpart.
3039#[rustc_nounwind]
3040#[rustc_intrinsic]
3041#[rustc_intrinsic_must_be_overridden]
3042pub fn frem_algebraic<T: Copy>(_a: T, _b: T) -> T {
3043    unimplemented!()
3044}
3045
3046/// Returns the number of bits set in an integer type `T`
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/// The stabilized versions of this intrinsic are available on the integer
3054/// primitives via the `count_ones` method. For example,
3055/// [`u32::count_ones`]
3056#[rustc_intrinsic_const_stable_indirect]
3057#[rustc_nounwind]
3058#[rustc_intrinsic]
3059#[rustc_intrinsic_must_be_overridden]
3060pub const fn ctpop<T: Copy>(_x: T) -> u32 {
3061    unimplemented!()
3062}
3063
3064/// Returns the number of leading unset bits (zeroes) in an integer type `T`.
3065///
3066/// Note that, unlike most intrinsics, this is safe to call;
3067/// it does not require an `unsafe` block.
3068/// Therefore, implementations must not require the user to uphold
3069/// any safety invariants.
3070///
3071/// The stabilized versions of this intrinsic are available on the integer
3072/// primitives via the `leading_zeros` method. For example,
3073/// [`u32::leading_zeros`]
3074///
3075/// # Examples
3076///
3077/// ```
3078/// #![feature(core_intrinsics)]
3079/// # #![allow(internal_features)]
3080///
3081/// use std::intrinsics::ctlz;
3082///
3083/// let x = 0b0001_1100_u8;
3084/// let num_leading = ctlz(x);
3085/// assert_eq!(num_leading, 3);
3086/// ```
3087///
3088/// An `x` with value `0` will return the bit width of `T`.
3089///
3090/// ```
3091/// #![feature(core_intrinsics)]
3092/// # #![allow(internal_features)]
3093///
3094/// use std::intrinsics::ctlz;
3095///
3096/// let x = 0u16;
3097/// let num_leading = ctlz(x);
3098/// assert_eq!(num_leading, 16);
3099/// ```
3100#[rustc_intrinsic_const_stable_indirect]
3101#[rustc_nounwind]
3102#[rustc_intrinsic]
3103#[rustc_intrinsic_must_be_overridden]
3104pub const fn ctlz<T: Copy>(_x: T) -> u32 {
3105    unimplemented!()
3106}
3107
3108/// Like `ctlz`, but extra-unsafe as it returns `undef` when
3109/// given an `x` with value `0`.
3110///
3111/// This intrinsic does not have a stable counterpart.
3112///
3113/// # Examples
3114///
3115/// ```
3116/// #![feature(core_intrinsics)]
3117/// # #![allow(internal_features)]
3118///
3119/// use std::intrinsics::ctlz_nonzero;
3120///
3121/// let x = 0b0001_1100_u8;
3122/// let num_leading = unsafe { ctlz_nonzero(x) };
3123/// assert_eq!(num_leading, 3);
3124/// ```
3125#[rustc_intrinsic_const_stable_indirect]
3126#[rustc_nounwind]
3127#[rustc_intrinsic]
3128#[rustc_intrinsic_must_be_overridden]
3129pub const unsafe fn ctlz_nonzero<T: Copy>(_x: T) -> u32 {
3130    unimplemented!()
3131}
3132
3133/// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
3134///
3135/// Note that, unlike most intrinsics, this is safe to call;
3136/// it does not require an `unsafe` block.
3137/// Therefore, implementations must not require the user to uphold
3138/// any safety invariants.
3139///
3140/// The stabilized versions of this intrinsic are available on the integer
3141/// primitives via the `trailing_zeros` method. For example,
3142/// [`u32::trailing_zeros`]
3143///
3144/// # Examples
3145///
3146/// ```
3147/// #![feature(core_intrinsics)]
3148/// # #![allow(internal_features)]
3149///
3150/// use std::intrinsics::cttz;
3151///
3152/// let x = 0b0011_1000_u8;
3153/// let num_trailing = cttz(x);
3154/// assert_eq!(num_trailing, 3);
3155/// ```
3156///
3157/// An `x` with value `0` will return the bit width of `T`:
3158///
3159/// ```
3160/// #![feature(core_intrinsics)]
3161/// # #![allow(internal_features)]
3162///
3163/// use std::intrinsics::cttz;
3164///
3165/// let x = 0u16;
3166/// let num_trailing = cttz(x);
3167/// assert_eq!(num_trailing, 16);
3168/// ```
3169#[rustc_intrinsic_const_stable_indirect]
3170#[rustc_nounwind]
3171#[rustc_intrinsic]
3172#[rustc_intrinsic_must_be_overridden]
3173pub const fn cttz<T: Copy>(_x: T) -> u32 {
3174    unimplemented!()
3175}
3176
3177/// Like `cttz`, but extra-unsafe as it returns `undef` when
3178/// given an `x` with value `0`.
3179///
3180/// This intrinsic does not have a stable counterpart.
3181///
3182/// # Examples
3183///
3184/// ```
3185/// #![feature(core_intrinsics)]
3186/// # #![allow(internal_features)]
3187///
3188/// use std::intrinsics::cttz_nonzero;
3189///
3190/// let x = 0b0011_1000_u8;
3191/// let num_trailing = unsafe { cttz_nonzero(x) };
3192/// assert_eq!(num_trailing, 3);
3193/// ```
3194#[rustc_intrinsic_const_stable_indirect]
3195#[rustc_nounwind]
3196#[rustc_intrinsic]
3197#[rustc_intrinsic_must_be_overridden]
3198pub const unsafe fn cttz_nonzero<T: Copy>(_x: T) -> u32 {
3199    unimplemented!()
3200}
3201
3202/// Reverses the bytes in an integer type `T`.
3203///
3204/// Note that, unlike most intrinsics, this is safe to call;
3205/// it does not require an `unsafe` block.
3206/// Therefore, implementations must not require the user to uphold
3207/// any safety invariants.
3208///
3209/// The stabilized versions of this intrinsic are available on the integer
3210/// primitives via the `swap_bytes` method. For example,
3211/// [`u32::swap_bytes`]
3212#[rustc_intrinsic_const_stable_indirect]
3213#[rustc_nounwind]
3214#[rustc_intrinsic]
3215#[rustc_intrinsic_must_be_overridden]
3216pub const fn bswap<T: Copy>(_x: T) -> T {
3217    unimplemented!()
3218}
3219
3220/// Reverses the bits in an integer type `T`.
3221///
3222/// Note that, unlike most intrinsics, this is safe to call;
3223/// it does not require an `unsafe` block.
3224/// Therefore, implementations must not require the user to uphold
3225/// any safety invariants.
3226///
3227/// The stabilized versions of this intrinsic are available on the integer
3228/// primitives via the `reverse_bits` method. For example,
3229/// [`u32::reverse_bits`]
3230#[rustc_intrinsic_const_stable_indirect]
3231#[rustc_nounwind]
3232#[rustc_intrinsic]
3233#[rustc_intrinsic_must_be_overridden]
3234pub const fn bitreverse<T: Copy>(_x: T) -> T {
3235    unimplemented!()
3236}
3237
3238/// Does a three-way comparison between the two integer arguments.
3239///
3240/// This is included as an intrinsic as it's useful to let it be one thing
3241/// in MIR, rather than the multiple checks and switches that make its IR
3242/// large and difficult to optimize.
3243///
3244/// The stabilized version of this intrinsic is [`Ord::cmp`].
3245#[rustc_intrinsic]
3246#[rustc_intrinsic_must_be_overridden]
3247pub const fn three_way_compare<T: Copy>(_lhs: T, _rhss: T) -> crate::cmp::Ordering {
3248    unimplemented!()
3249}
3250
3251/// Combine two values which have no bits in common.
3252///
3253/// This allows the backend to implement it as `a + b` *or* `a | b`,
3254/// depending which is easier to implement on a specific target.
3255///
3256/// # Safety
3257///
3258/// Requires that `(a & b) == 0`, or equivalently that `(a | b) == (a + b)`.
3259///
3260/// Otherwise it's immediate UB.
3261#[rustc_const_unstable(feature = "disjoint_bitor", issue = "135758")]
3262#[rustc_nounwind]
3263#[cfg_attr(not(bootstrap), rustc_intrinsic)]
3264#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
3265#[miri::intrinsic_fallback_is_spec] // the fallbacks all `assume` to tell Miri
3266pub const unsafe fn disjoint_bitor<T: ~const fallback::DisjointBitOr>(a: T, b: T) -> T {
3267    // SAFETY: same preconditions as this function.
3268    unsafe { fallback::DisjointBitOr::disjoint_bitor(a, b) }
3269}
3270
3271/// Performs checked integer addition.
3272///
3273/// Note that, unlike most intrinsics, this is safe to call;
3274/// it does not require an `unsafe` block.
3275/// Therefore, implementations must not require the user to uphold
3276/// any safety invariants.
3277///
3278/// The stabilized versions of this intrinsic are available on the integer
3279/// primitives via the `overflowing_add` method. For example,
3280/// [`u32::overflowing_add`]
3281#[rustc_intrinsic_const_stable_indirect]
3282#[rustc_nounwind]
3283#[rustc_intrinsic]
3284#[rustc_intrinsic_must_be_overridden]
3285pub const fn add_with_overflow<T: Copy>(_x: T, _y: T) -> (T, bool) {
3286    unimplemented!()
3287}
3288
3289/// Performs checked integer subtraction
3290///
3291/// Note that, unlike most intrinsics, this is safe to call;
3292/// it does not require an `unsafe` block.
3293/// Therefore, implementations must not require the user to uphold
3294/// any safety invariants.
3295///
3296/// The stabilized versions of this intrinsic are available on the integer
3297/// primitives via the `overflowing_sub` method. For example,
3298/// [`u32::overflowing_sub`]
3299#[rustc_intrinsic_const_stable_indirect]
3300#[rustc_nounwind]
3301#[rustc_intrinsic]
3302#[rustc_intrinsic_must_be_overridden]
3303pub const fn sub_with_overflow<T: Copy>(_x: T, _y: T) -> (T, bool) {
3304    unimplemented!()
3305}
3306
3307/// Performs checked integer multiplication
3308///
3309/// Note that, unlike most intrinsics, this is safe to call;
3310/// it does not require an `unsafe` block.
3311/// Therefore, implementations must not require the user to uphold
3312/// any safety invariants.
3313///
3314/// The stabilized versions of this intrinsic are available on the integer
3315/// primitives via the `overflowing_mul` method. For example,
3316/// [`u32::overflowing_mul`]
3317#[rustc_intrinsic_const_stable_indirect]
3318#[rustc_nounwind]
3319#[rustc_intrinsic]
3320#[rustc_intrinsic_must_be_overridden]
3321pub const fn mul_with_overflow<T: Copy>(_x: T, _y: T) -> (T, bool) {
3322    unimplemented!()
3323}
3324
3325/// Performs full-width multiplication and addition with a carry:
3326/// `multiplier * multiplicand + addend + carry`.
3327///
3328/// This is possible without any overflow.  For `uN`:
3329///    MAX * MAX + MAX + MAX
3330/// => (2ⁿ-1) × (2ⁿ-1) + (2ⁿ-1) + (2ⁿ-1)
3331/// => (2²ⁿ - 2ⁿ⁺¹ + 1) + (2ⁿ⁺¹ - 2)
3332/// => 2²ⁿ - 1
3333///
3334/// For `iN`, the upper bound is MIN * MIN + MAX + MAX => 2²ⁿ⁻² + 2ⁿ - 2,
3335/// and the lower bound is MAX * MIN + MIN + MIN => -2²ⁿ⁻² - 2ⁿ + 2ⁿ⁺¹.
3336///
3337/// This currently supports unsigned integers *only*, no signed ones.
3338/// The stabilized versions of this intrinsic are available on integers.
3339#[unstable(feature = "core_intrinsics", issue = "none")]
3340#[rustc_const_unstable(feature = "const_carrying_mul_add", issue = "85532")]
3341#[rustc_nounwind]
3342#[rustc_intrinsic]
3343#[miri::intrinsic_fallback_is_spec]
3344pub const fn carrying_mul_add<T: ~const fallback::CarryingMulAdd<Unsigned = U>, U>(
3345    multiplier: T,
3346    multiplicand: T,
3347    addend: T,
3348    carry: T,
3349) -> (U, T) {
3350    multiplier.carrying_mul_add(multiplicand, addend, carry)
3351}
3352
3353/// Performs an exact division, resulting in undefined behavior where
3354/// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
3355///
3356/// This intrinsic does not have a stable counterpart.
3357#[rustc_nounwind]
3358#[rustc_intrinsic]
3359#[rustc_intrinsic_must_be_overridden]
3360pub const unsafe fn exact_div<T: Copy>(_x: T, _y: T) -> T {
3361    unimplemented!()
3362}
3363
3364/// Performs an unchecked division, resulting in undefined behavior
3365/// where `y == 0` or `x == T::MIN && y == -1`
3366///
3367/// Safe wrappers for this intrinsic are available on the integer
3368/// primitives via the `checked_div` method. For example,
3369/// [`u32::checked_div`]
3370#[rustc_intrinsic_const_stable_indirect]
3371#[rustc_nounwind]
3372#[rustc_intrinsic]
3373#[rustc_intrinsic_must_be_overridden]
3374pub const unsafe fn unchecked_div<T: Copy>(_x: T, _y: T) -> T {
3375    unimplemented!()
3376}
3377/// Returns the remainder of an unchecked division, resulting in
3378/// undefined behavior when `y == 0` or `x == T::MIN && y == -1`
3379///
3380/// Safe wrappers for this intrinsic are available on the integer
3381/// primitives via the `checked_rem` method. For example,
3382/// [`u32::checked_rem`]
3383#[rustc_intrinsic_const_stable_indirect]
3384#[rustc_nounwind]
3385#[rustc_intrinsic]
3386#[rustc_intrinsic_must_be_overridden]
3387pub const unsafe fn unchecked_rem<T: Copy>(_x: T, _y: T) -> T {
3388    unimplemented!()
3389}
3390
3391/// Performs an unchecked left shift, resulting in undefined behavior when
3392/// `y < 0` or `y >= N`, where N is the width of T in bits.
3393///
3394/// Safe wrappers for this intrinsic are available on the integer
3395/// primitives via the `checked_shl` method. For example,
3396/// [`u32::checked_shl`]
3397#[rustc_intrinsic_const_stable_indirect]
3398#[rustc_nounwind]
3399#[rustc_intrinsic]
3400#[rustc_intrinsic_must_be_overridden]
3401pub const unsafe fn unchecked_shl<T: Copy, U: Copy>(_x: T, _y: U) -> T {
3402    unimplemented!()
3403}
3404/// Performs an unchecked right shift, resulting in undefined behavior when
3405/// `y < 0` or `y >= N`, where N is the width of T in bits.
3406///
3407/// Safe wrappers for this intrinsic are available on the integer
3408/// primitives via the `checked_shr` method. For example,
3409/// [`u32::checked_shr`]
3410#[rustc_intrinsic_const_stable_indirect]
3411#[rustc_nounwind]
3412#[rustc_intrinsic]
3413#[rustc_intrinsic_must_be_overridden]
3414pub const unsafe fn unchecked_shr<T: Copy, U: Copy>(_x: T, _y: U) -> T {
3415    unimplemented!()
3416}
3417
3418/// Returns the result of an unchecked addition, resulting in
3419/// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.
3420///
3421/// The stable counterpart of this intrinsic is `unchecked_add` on the various
3422/// integer types, such as [`u16::unchecked_add`] and [`i64::unchecked_add`].
3423#[rustc_intrinsic_const_stable_indirect]
3424#[rustc_nounwind]
3425#[rustc_intrinsic]
3426#[rustc_intrinsic_must_be_overridden]
3427pub const unsafe fn unchecked_add<T: Copy>(_x: T, _y: T) -> T {
3428    unimplemented!()
3429}
3430
3431/// Returns the result of an unchecked subtraction, resulting in
3432/// undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`.
3433///
3434/// The stable counterpart of this intrinsic is `unchecked_sub` on the various
3435/// integer types, such as [`u16::unchecked_sub`] and [`i64::unchecked_sub`].
3436#[rustc_intrinsic_const_stable_indirect]
3437#[rustc_nounwind]
3438#[rustc_intrinsic]
3439#[rustc_intrinsic_must_be_overridden]
3440pub const unsafe fn unchecked_sub<T: Copy>(_x: T, _y: T) -> T {
3441    unimplemented!()
3442}
3443
3444/// Returns the result of an unchecked multiplication, resulting in
3445/// undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`.
3446///
3447/// The stable counterpart of this intrinsic is `unchecked_mul` on the various
3448/// integer types, such as [`u16::unchecked_mul`] and [`i64::unchecked_mul`].
3449#[rustc_intrinsic_const_stable_indirect]
3450#[rustc_nounwind]
3451#[rustc_intrinsic]
3452#[rustc_intrinsic_must_be_overridden]
3453pub const unsafe fn unchecked_mul<T: Copy>(_x: T, _y: T) -> T {
3454    unimplemented!()
3455}
3456
3457/// Performs rotate left.
3458///
3459/// Note that, unlike most intrinsics, this is safe to call;
3460/// it does not require an `unsafe` block.
3461/// Therefore, implementations must not require the user to uphold
3462/// any safety invariants.
3463///
3464/// The stabilized versions of this intrinsic are available on the integer
3465/// primitives via the `rotate_left` method. For example,
3466/// [`u32::rotate_left`]
3467#[rustc_intrinsic_const_stable_indirect]
3468#[rustc_nounwind]
3469#[rustc_intrinsic]
3470#[rustc_intrinsic_must_be_overridden]
3471pub const fn rotate_left<T: Copy>(_x: T, _shift: u32) -> T {
3472    unimplemented!()
3473}
3474
3475/// Performs rotate right.
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///
3482/// The stabilized versions of this intrinsic are available on the integer
3483/// primitives via the `rotate_right` method. For example,
3484/// [`u32::rotate_right`]
3485#[rustc_intrinsic_const_stable_indirect]
3486#[rustc_nounwind]
3487#[rustc_intrinsic]
3488#[rustc_intrinsic_must_be_overridden]
3489pub const fn rotate_right<T: Copy>(_x: T, _shift: u32) -> T {
3490    unimplemented!()
3491}
3492
3493/// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
3494///
3495/// Note that, unlike most intrinsics, this is safe to call;
3496/// it does not require an `unsafe` block.
3497/// Therefore, implementations must not require the user to uphold
3498/// any safety invariants.
3499///
3500/// The stabilized versions of this intrinsic are available on the integer
3501/// primitives via the `wrapping_add` method. For example,
3502/// [`u32::wrapping_add`]
3503#[rustc_intrinsic_const_stable_indirect]
3504#[rustc_nounwind]
3505#[rustc_intrinsic]
3506#[rustc_intrinsic_must_be_overridden]
3507pub const fn wrapping_add<T: Copy>(_a: T, _b: T) -> T {
3508    unimplemented!()
3509}
3510/// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
3511///
3512/// Note that, unlike most intrinsics, this is safe to call;
3513/// it does not require an `unsafe` block.
3514/// Therefore, implementations must not require the user to uphold
3515/// any safety invariants.
3516///
3517/// The stabilized versions of this intrinsic are available on the integer
3518/// primitives via the `wrapping_sub` method. For example,
3519/// [`u32::wrapping_sub`]
3520#[rustc_intrinsic_const_stable_indirect]
3521#[rustc_nounwind]
3522#[rustc_intrinsic]
3523#[rustc_intrinsic_must_be_overridden]
3524pub const fn wrapping_sub<T: Copy>(_a: T, _b: T) -> T {
3525    unimplemented!()
3526}
3527/// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
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 versions of this intrinsic are available on the integer
3535/// primitives via the `wrapping_mul` method. For example,
3536/// [`u32::wrapping_mul`]
3537#[rustc_intrinsic_const_stable_indirect]
3538#[rustc_nounwind]
3539#[rustc_intrinsic]
3540#[rustc_intrinsic_must_be_overridden]
3541pub const fn wrapping_mul<T: Copy>(_a: T, _b: T) -> T {
3542    unimplemented!()
3543}
3544
3545/// Computes `a + b`, saturating at numeric bounds.
3546///
3547/// Note that, unlike most intrinsics, this is safe to call;
3548/// it does not require an `unsafe` block.
3549/// Therefore, implementations must not require the user to uphold
3550/// any safety invariants.
3551///
3552/// The stabilized versions of this intrinsic are available on the integer
3553/// primitives via the `saturating_add` method. For example,
3554/// [`u32::saturating_add`]
3555#[rustc_intrinsic_const_stable_indirect]
3556#[rustc_nounwind]
3557#[rustc_intrinsic]
3558#[rustc_intrinsic_must_be_overridden]
3559pub const fn saturating_add<T: Copy>(_a: T, _b: T) -> T {
3560    unimplemented!()
3561}
3562/// Computes `a - b`, saturating at numeric bounds.
3563///
3564/// Note that, unlike most intrinsics, this is safe to call;
3565/// it does not require an `unsafe` block.
3566/// Therefore, implementations must not require the user to uphold
3567/// any safety invariants.
3568///
3569/// The stabilized versions of this intrinsic are available on the integer
3570/// primitives via the `saturating_sub` method. For example,
3571/// [`u32::saturating_sub`]
3572#[rustc_intrinsic_const_stable_indirect]
3573#[rustc_nounwind]
3574#[rustc_intrinsic]
3575#[rustc_intrinsic_must_be_overridden]
3576pub const fn saturating_sub<T: Copy>(_a: T, _b: T) -> T {
3577    unimplemented!()
3578}
3579
3580/// This is an implementation detail of [`crate::ptr::read`] and should
3581/// not be used anywhere else.  See its comments for why this exists.
3582///
3583/// This intrinsic can *only* be called where the pointer is a local without
3584/// projections (`read_via_copy(ptr)`, not `read_via_copy(*ptr)`) so that it
3585/// trivially obeys runtime-MIR rules about derefs in operands.
3586#[rustc_intrinsic_const_stable_indirect]
3587#[rustc_nounwind]
3588#[rustc_intrinsic]
3589#[rustc_intrinsic_must_be_overridden]
3590pub const unsafe fn read_via_copy<T>(_ptr: *const T) -> T {
3591    unimplemented!()
3592}
3593
3594/// This is an implementation detail of [`crate::ptr::write`] and should
3595/// not be used anywhere else.  See its comments for why this exists.
3596///
3597/// This intrinsic can *only* be called where the pointer is a local without
3598/// projections (`write_via_move(ptr, x)`, not `write_via_move(*ptr, x)`) so
3599/// that it trivially obeys runtime-MIR rules about derefs in operands.
3600#[rustc_intrinsic_const_stable_indirect]
3601#[rustc_nounwind]
3602#[rustc_intrinsic]
3603#[rustc_intrinsic_must_be_overridden]
3604pub const unsafe fn write_via_move<T>(_ptr: *mut T, _value: T) {
3605    unimplemented!()
3606}
3607
3608/// Returns the value of the discriminant for the variant in 'v';
3609/// if `T` has no discriminant, returns `0`.
3610///
3611/// Note that, unlike most intrinsics, this is safe to call;
3612/// it does not require an `unsafe` block.
3613/// Therefore, implementations must not require the user to uphold
3614/// any safety invariants.
3615///
3616/// The stabilized version of this intrinsic is [`core::mem::discriminant`].
3617#[rustc_intrinsic_const_stable_indirect]
3618#[rustc_nounwind]
3619#[rustc_intrinsic]
3620#[rustc_intrinsic_must_be_overridden]
3621pub const fn discriminant_value<T>(_v: &T) -> <T as DiscriminantKind>::Discriminant {
3622    unimplemented!()
3623}
3624
3625/// Rust's "try catch" construct for unwinding. Invokes the function pointer `try_fn` with the
3626/// data pointer `data`, and calls `catch_fn` if unwinding occurs while `try_fn` runs.
3627///
3628/// `catch_fn` must not unwind.
3629///
3630/// The third argument is a function called if an unwind occurs (both Rust `panic` and foreign
3631/// unwinds). This function takes the data pointer and a pointer to the target- and
3632/// runtime-specific exception object that was caught.
3633///
3634/// Note that in the case of a foreign unwinding operation, the exception object data may not be
3635/// safely usable from Rust, and should not be directly exposed via the standard library. To
3636/// prevent unsafe access, the library implementation may either abort the process or present an
3637/// opaque error type to the user.
3638///
3639/// For more information, see the compiler's source, as well as the documentation for the stable
3640/// version of this intrinsic, `std::panic::catch_unwind`.
3641#[rustc_intrinsic]
3642#[rustc_intrinsic_must_be_overridden]
3643#[rustc_nounwind]
3644pub unsafe fn catch_unwind(
3645    _try_fn: fn(*mut u8),
3646    _data: *mut u8,
3647    _catch_fn: fn(*mut u8, *mut u8),
3648) -> i32 {
3649    unreachable!()
3650}
3651
3652/// Emits a `nontemporal` store, which gives a hint to the CPU that the data should not be held
3653/// in cache. Except for performance, this is fully equivalent to `ptr.write(val)`.
3654///
3655/// Not all architectures provide such an operation. For instance, x86 does not: while `MOVNT`
3656/// exists, that operation is *not* equivalent to `ptr.write(val)` (`MOVNT` writes can be reordered
3657/// in ways that are not allowed for regular writes).
3658#[rustc_intrinsic]
3659#[rustc_intrinsic_must_be_overridden]
3660#[rustc_nounwind]
3661pub unsafe fn nontemporal_store<T>(_ptr: *mut T, _val: T) {
3662    unreachable!()
3663}
3664
3665/// See documentation of `<*const T>::offset_from` for details.
3666#[rustc_intrinsic_const_stable_indirect]
3667#[rustc_nounwind]
3668#[rustc_intrinsic]
3669#[rustc_intrinsic_must_be_overridden]
3670pub const unsafe fn ptr_offset_from<T>(_ptr: *const T, _base: *const T) -> isize {
3671    unimplemented!()
3672}
3673
3674/// See documentation of `<*const T>::sub_ptr` for details.
3675#[rustc_nounwind]
3676#[rustc_intrinsic]
3677#[rustc_intrinsic_must_be_overridden]
3678pub const unsafe fn ptr_offset_from_unsigned<T>(_ptr: *const T, _base: *const T) -> usize {
3679    unimplemented!()
3680}
3681
3682/// See documentation of `<*const T>::guaranteed_eq` for details.
3683/// Returns `2` if the result is unknown.
3684/// Returns `1` if the pointers are guaranteed equal.
3685/// Returns `0` if the pointers are guaranteed inequal.
3686#[rustc_intrinsic]
3687#[rustc_nounwind]
3688#[rustc_do_not_const_check]
3689#[inline]
3690#[miri::intrinsic_fallback_is_spec]
3691pub const fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8 {
3692    (ptr == other) as u8
3693}
3694
3695/// Determines whether the raw bytes of the two values are equal.
3696///
3697/// This is particularly handy for arrays, since it allows things like just
3698/// comparing `i96`s instead of forcing `alloca`s for `[6 x i16]`.
3699///
3700/// Above some backend-decided threshold this will emit calls to `memcmp`,
3701/// like slice equality does, instead of causing massive code size.
3702///
3703/// Since this works by comparing the underlying bytes, the actual `T` is
3704/// not particularly important.  It will be used for its size and alignment,
3705/// but any validity restrictions will be ignored, not enforced.
3706///
3707/// # Safety
3708///
3709/// It's UB to call this if any of the *bytes* in `*a` or `*b` are uninitialized.
3710/// Note that this is a stricter criterion than just the *values* being
3711/// fully-initialized: if `T` has padding, it's UB to call this intrinsic.
3712///
3713/// At compile-time, it is furthermore UB to call this if any of the bytes
3714/// in `*a` or `*b` have provenance.
3715///
3716/// (The implementation is allowed to branch on the results of comparisons,
3717/// which is UB if any of their inputs are `undef`.)
3718#[rustc_nounwind]
3719#[rustc_intrinsic]
3720#[rustc_intrinsic_must_be_overridden]
3721pub const unsafe fn raw_eq<T>(_a: &T, _b: &T) -> bool {
3722    unimplemented!()
3723}
3724
3725/// Lexicographically compare `[left, left + bytes)` and `[right, right + bytes)`
3726/// as unsigned bytes, returning negative if `left` is less, zero if all the
3727/// bytes match, or positive if `left` is greater.
3728///
3729/// This underlies things like `<[u8]>::cmp`, and will usually lower to `memcmp`.
3730///
3731/// # Safety
3732///
3733/// `left` and `right` must each be [valid] for reads of `bytes` bytes.
3734///
3735/// Note that this applies to the whole range, not just until the first byte
3736/// that differs.  That allows optimizations that can read in large chunks.
3737///
3738/// [valid]: crate::ptr#safety
3739#[rustc_nounwind]
3740#[rustc_intrinsic]
3741#[rustc_intrinsic_must_be_overridden]
3742pub const unsafe fn compare_bytes(_left: *const u8, _right: *const u8, _bytes: usize) -> i32 {
3743    unimplemented!()
3744}
3745
3746/// See documentation of [`std::hint::black_box`] for details.
3747///
3748/// [`std::hint::black_box`]: crate::hint::black_box
3749#[rustc_nounwind]
3750#[rustc_intrinsic]
3751#[rustc_intrinsic_must_be_overridden]
3752#[rustc_intrinsic_const_stable_indirect]
3753pub const fn black_box<T>(_dummy: T) -> T {
3754    unimplemented!()
3755}
3756
3757/// Selects which function to call depending on the context.
3758///
3759/// If this function is evaluated at compile-time, then a call to this
3760/// intrinsic will be replaced with a call to `called_in_const`. It gets
3761/// replaced with a call to `called_at_rt` otherwise.
3762///
3763/// This function is safe to call, but note the stability concerns below.
3764///
3765/// # Type Requirements
3766///
3767/// The two functions must be both function items. They cannot be function
3768/// pointers or closures. The first function must be a `const fn`.
3769///
3770/// `arg` will be the tupled arguments that will be passed to either one of
3771/// the two functions, therefore, both functions must accept the same type of
3772/// arguments. Both functions must return RET.
3773///
3774/// # Stability concerns
3775///
3776/// Rust has not yet decided that `const fn` are allowed to tell whether
3777/// they run at compile-time or at runtime. Therefore, when using this
3778/// intrinsic anywhere that can be reached from stable, it is crucial that
3779/// the end-to-end behavior of the stable `const fn` is the same for both
3780/// modes of execution. (Here, Undefined Behavior is considered "the same"
3781/// as any other behavior, so if the function exhibits UB at runtime then
3782/// it may do whatever it wants at compile-time.)
3783///
3784/// Here is an example of how this could cause a problem:
3785/// ```no_run
3786/// #![feature(const_eval_select)]
3787/// #![feature(core_intrinsics)]
3788/// # #![allow(internal_features)]
3789/// use std::intrinsics::const_eval_select;
3790///
3791/// // Standard library
3792/// pub const fn inconsistent() -> i32 {
3793///     fn runtime() -> i32 { 1 }
3794///     const fn compiletime() -> i32 { 2 }
3795///
3796///     // ⚠ This code violates the required equivalence of `compiletime`
3797///     // and `runtime`.
3798///     const_eval_select((), compiletime, runtime)
3799/// }
3800///
3801/// // User Crate
3802/// const X: i32 = inconsistent();
3803/// let x = inconsistent();
3804/// assert_eq!(x, X);
3805/// ```
3806///
3807/// Currently such an assertion would always succeed; until Rust decides
3808/// otherwise, that principle should not be violated.
3809#[rustc_const_unstable(feature = "const_eval_select", issue = "124625")]
3810#[rustc_intrinsic]
3811#[rustc_intrinsic_must_be_overridden]
3812pub const fn const_eval_select<ARG: Tuple, F, G, RET>(
3813    _arg: ARG,
3814    _called_in_const: F,
3815    _called_at_rt: G,
3816) -> RET
3817where
3818    G: FnOnce<ARG, Output = RET>,
3819    F: FnOnce<ARG, Output = RET>,
3820{
3821    unreachable!()
3822}
3823
3824/// A macro to make it easier to invoke const_eval_select. Use as follows:
3825/// ```rust,ignore (just a macro example)
3826/// const_eval_select!(
3827///     @capture { arg1: i32 = some_expr, arg2: T = other_expr } -> U:
3828///     if const #[attributes_for_const_arm] {
3829///         // Compile-time code goes here.
3830///     } else #[attributes_for_runtime_arm] {
3831///         // Run-time code goes here.
3832///     }
3833/// )
3834/// ```
3835/// The `@capture` block declares which surrounding variables / expressions can be
3836/// used inside the `if const`.
3837/// Note that the two arms of this `if` really each become their own function, which is why the
3838/// macro supports setting attributes for those functions. The runtime function is always
3839/// markes as `#[inline]`.
3840///
3841/// See [`const_eval_select()`] for the rules and requirements around that intrinsic.
3842pub(crate) macro const_eval_select {
3843    (
3844        @capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty = $val:expr),* $(,)? } $( -> $ret:ty )? :
3845        if const
3846            $(#[$compiletime_attr:meta])* $compiletime:block
3847        else
3848            $(#[$runtime_attr:meta])* $runtime:block
3849    ) => {
3850        // Use the `noinline` arm, after adding explicit `inline` attributes
3851        $crate::intrinsics::const_eval_select!(
3852            @capture$([$($binders)*])? { $($arg : $ty = $val),* } $(-> $ret)? :
3853            #[noinline]
3854            if const
3855                #[inline] // prevent codegen on this function
3856                $(#[$compiletime_attr])*
3857                $compiletime
3858            else
3859                #[inline] // avoid the overhead of an extra fn call
3860                $(#[$runtime_attr])*
3861                $runtime
3862        )
3863    },
3864    // With a leading #[noinline], we don't add inline attributes
3865    (
3866        @capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty = $val:expr),* $(,)? } $( -> $ret:ty )? :
3867        #[noinline]
3868        if const
3869            $(#[$compiletime_attr:meta])* $compiletime:block
3870        else
3871            $(#[$runtime_attr:meta])* $runtime:block
3872    ) => {{
3873        $(#[$runtime_attr])*
3874        fn runtime$(<$($binders)*>)?($($arg: $ty),*) $( -> $ret )? {
3875            $runtime
3876        }
3877
3878        $(#[$compiletime_attr])*
3879        const fn compiletime$(<$($binders)*>)?($($arg: $ty),*) $( -> $ret )? {
3880            // Don't warn if one of the arguments is unused.
3881            $(let _ = $arg;)*
3882
3883            $compiletime
3884        }
3885
3886        const_eval_select(($($val,)*), compiletime, runtime)
3887    }},
3888    // We support leaving away the `val` expressions for *all* arguments
3889    // (but not for *some* arguments, that's too tricky).
3890    (
3891        @capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty),* $(,)? } $( -> $ret:ty )? :
3892        if const
3893            $(#[$compiletime_attr:meta])* $compiletime:block
3894        else
3895            $(#[$runtime_attr:meta])* $runtime:block
3896    ) => {
3897        $crate::intrinsics::const_eval_select!(
3898            @capture$([$($binders)*])? { $($arg : $ty = $arg),* } $(-> $ret)? :
3899            if const
3900                $(#[$compiletime_attr])* $compiletime
3901            else
3902                $(#[$runtime_attr])* $runtime
3903        )
3904    },
3905}
3906
3907/// Returns whether the argument's value is statically known at
3908/// compile-time.
3909///
3910/// This is useful when there is a way of writing the code that will
3911/// be *faster* when some variables have known values, but *slower*
3912/// in the general case: an `if is_val_statically_known(var)` can be used
3913/// to select between these two variants. The `if` will be optimized away
3914/// and only the desired branch remains.
3915///
3916/// Formally speaking, this function non-deterministically returns `true`
3917/// or `false`, and the caller has to ensure sound behavior for both cases.
3918/// In other words, the following code has *Undefined Behavior*:
3919///
3920/// ```no_run
3921/// #![feature(core_intrinsics)]
3922/// # #![allow(internal_features)]
3923/// use std::hint::unreachable_unchecked;
3924/// use std::intrinsics::is_val_statically_known;
3925///
3926/// if !is_val_statically_known(0) { unsafe { unreachable_unchecked(); } }
3927/// ```
3928///
3929/// This also means that the following code's behavior is unspecified; it
3930/// may panic, or it may not:
3931///
3932/// ```no_run
3933/// #![feature(core_intrinsics)]
3934/// # #![allow(internal_features)]
3935/// use std::intrinsics::is_val_statically_known;
3936///
3937/// assert_eq!(is_val_statically_known(0), is_val_statically_known(0));
3938/// ```
3939///
3940/// Unsafe code may not rely on `is_val_statically_known` returning any
3941/// particular value, ever. However, the compiler will generally make it
3942/// return `true` only if the value of the argument is actually known.
3943///
3944/// # Stability concerns
3945///
3946/// While it is safe to call, this intrinsic may behave differently in
3947/// a `const` context than otherwise. See the [`const_eval_select()`]
3948/// documentation for an explanation of the issues this can cause. Unlike
3949/// `const_eval_select`, this intrinsic isn't guaranteed to behave
3950/// deterministically even in a `const` context.
3951///
3952/// # Type Requirements
3953///
3954/// `T` must be either a `bool`, a `char`, a primitive numeric type (e.g. `f32`,
3955/// but not `NonZeroISize`), or any thin pointer (e.g. `*mut String`).
3956/// Any other argument types *may* cause a compiler error.
3957///
3958/// ## Pointers
3959///
3960/// When the input is a pointer, only the pointer itself is
3961/// ever considered. The pointee has no effect. Currently, these functions
3962/// behave identically:
3963///
3964/// ```
3965/// #![feature(core_intrinsics)]
3966/// # #![allow(internal_features)]
3967/// use std::intrinsics::is_val_statically_known;
3968///
3969/// fn foo(x: &i32) -> bool {
3970///     is_val_statically_known(x)
3971/// }
3972///
3973/// fn bar(x: &i32) -> bool {
3974///     is_val_statically_known(
3975///         (x as *const i32).addr()
3976///     )
3977/// }
3978/// # _ = foo(&5_i32);
3979/// # _ = bar(&5_i32);
3980/// ```
3981#[rustc_const_stable_indirect]
3982#[rustc_nounwind]
3983#[unstable(feature = "core_intrinsics", issue = "none")]
3984#[rustc_intrinsic]
3985pub const fn is_val_statically_known<T: Copy>(_arg: T) -> bool {
3986    false
3987}
3988
3989/// Non-overlapping *typed* swap of a single value.
3990///
3991/// The codegen backends will replace this with a better implementation when
3992/// `T` is a simple type that can be loaded and stored as an immediate.
3993///
3994/// The stabilized form of this intrinsic is [`crate::mem::swap`].
3995///
3996/// # Safety
3997///
3998/// `x` and `y` are readable and writable as `T`, and non-overlapping.
3999#[rustc_nounwind]
4000#[inline]
4001#[rustc_intrinsic]
4002#[rustc_intrinsic_const_stable_indirect]
4003#[rustc_allow_const_fn_unstable(const_swap_nonoverlapping)] // this is anyway not called since CTFE implements the intrinsic
4004pub const unsafe fn typed_swap_nonoverlapping<T>(x: *mut T, y: *mut T) {
4005    // SAFETY: The caller provided single non-overlapping items behind
4006    // pointers, so swapping them with `count: 1` is fine.
4007    unsafe { ptr::swap_nonoverlapping(x, y, 1) };
4008}
4009
4010/// Returns whether we should perform some UB-checking at runtime. This eventually evaluates to
4011/// `cfg!(ub_checks)`, but behaves different from `cfg!` when mixing crates built with different
4012/// flags: if the crate has UB checks enabled or carries the `#[rustc_preserve_ub_checks]`
4013/// attribute, evaluation is delayed until monomorphization (or until the call gets inlined into
4014/// a crate that does not delay evaluation further); otherwise it can happen any time.
4015///
4016/// The common case here is a user program built with ub_checks linked against the distributed
4017/// sysroot which is built without ub_checks but with `#[rustc_preserve_ub_checks]`.
4018/// For code that gets monomorphized in the user crate (i.e., generic functions and functions with
4019/// `#[inline]`), gating assertions on `ub_checks()` rather than `cfg!(ub_checks)` means that
4020/// assertions are enabled whenever the *user crate* has UB checks enabled. However, if the
4021/// user has UB checks disabled, the checks will still get optimized out. This intrinsic is
4022/// primarily used by [`ub_checks::assert_unsafe_precondition`].
4023#[rustc_intrinsic_const_stable_indirect] // just for UB checks
4024#[inline(always)]
4025#[rustc_intrinsic]
4026pub const fn ub_checks() -> bool {
4027    cfg!(ub_checks)
4028}
4029
4030/// Allocates a block of memory at compile time.
4031/// At runtime, just returns a null pointer.
4032///
4033/// # Safety
4034///
4035/// - The `align` argument must be a power of two.
4036///    - At compile time, a compile error occurs if this constraint is violated.
4037///    - At runtime, it is not checked.
4038#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
4039#[rustc_nounwind]
4040#[rustc_intrinsic]
4041#[miri::intrinsic_fallback_is_spec]
4042pub const unsafe fn const_allocate(_size: usize, _align: usize) -> *mut u8 {
4043    // const eval overrides this function, but runtime code for now just returns null pointers.
4044    // See <https://github.com/rust-lang/rust/issues/93935>.
4045    crate::ptr::null_mut()
4046}
4047
4048/// Deallocates a memory which allocated by `intrinsics::const_allocate` at compile time.
4049/// At runtime, does nothing.
4050///
4051/// # Safety
4052///
4053/// - The `align` argument must be a power of two.
4054///    - At compile time, a compile error occurs if this constraint is violated.
4055///    - At runtime, it is not checked.
4056/// - If the `ptr` is created in an another const, this intrinsic doesn't deallocate it.
4057/// - If the `ptr` is pointing to a local variable, this intrinsic doesn't deallocate it.
4058#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
4059#[unstable(feature = "core_intrinsics", issue = "none")]
4060#[rustc_nounwind]
4061#[rustc_intrinsic]
4062#[miri::intrinsic_fallback_is_spec]
4063pub const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {
4064    // Runtime NOP
4065}
4066
4067/// Returns whether we should perform contract-checking at runtime.
4068///
4069/// This is meant to be similar to the ub_checks intrinsic, in terms
4070/// of not prematurely commiting at compile-time to whether contract
4071/// checking is turned on, so that we can specify contracts in libstd
4072/// and let an end user opt into turning them on.
4073#[cfg(not(bootstrap))]
4074#[rustc_const_unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
4075#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
4076#[inline(always)]
4077#[rustc_intrinsic]
4078pub const fn contract_checks() -> bool {
4079    // FIXME: should this be `false` or `cfg!(contract_checks)`?
4080
4081    // cfg!(contract_checks)
4082    false
4083}
4084
4085/// Check if the pre-condition `cond` has been met.
4086///
4087/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
4088/// returns false.
4089#[cfg(not(bootstrap))]
4090#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
4091#[lang = "contract_check_requires"]
4092#[rustc_intrinsic]
4093pub fn contract_check_requires<C: Fn() -> bool>(cond: C) {
4094    if contract_checks() && !cond() {
4095        // Emit no unwind panic in case this was a safety requirement.
4096        crate::panicking::panic_nounwind("failed requires check");
4097    }
4098}
4099
4100/// Check if the post-condition `cond` has been met.
4101///
4102/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
4103/// returns false.
4104#[cfg(not(bootstrap))]
4105#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
4106#[rustc_intrinsic]
4107pub fn contract_check_ensures<'a, Ret, C: Fn(&'a Ret) -> bool>(ret: &'a Ret, cond: C) {
4108    if contract_checks() && !cond(ret) {
4109        crate::panicking::panic_nounwind("failed ensures check");
4110    }
4111}
4112
4113/// The intrinsic will return the size stored in that vtable.
4114///
4115/// # Safety
4116///
4117/// `ptr` must point to a vtable.
4118#[rustc_nounwind]
4119#[unstable(feature = "core_intrinsics", issue = "none")]
4120#[rustc_intrinsic]
4121#[rustc_intrinsic_must_be_overridden]
4122pub unsafe fn vtable_size(_ptr: *const ()) -> usize {
4123    unreachable!()
4124}
4125
4126/// The intrinsic will return the alignment stored in that vtable.
4127///
4128/// # Safety
4129///
4130/// `ptr` must point to a vtable.
4131#[rustc_nounwind]
4132#[unstable(feature = "core_intrinsics", issue = "none")]
4133#[rustc_intrinsic]
4134#[rustc_intrinsic_must_be_overridden]
4135pub unsafe fn vtable_align(_ptr: *const ()) -> usize {
4136    unreachable!()
4137}
4138
4139/// The size of a type in bytes.
4140///
4141/// Note that, unlike most intrinsics, this is safe to call;
4142/// it does not require an `unsafe` block.
4143/// Therefore, implementations must not require the user to uphold
4144/// any safety invariants.
4145///
4146/// More specifically, this is the offset in bytes between successive
4147/// items of the same type, including alignment padding.
4148///
4149/// The stabilized version of this intrinsic is [`core::mem::size_of`].
4150#[rustc_nounwind]
4151#[unstable(feature = "core_intrinsics", issue = "none")]
4152#[rustc_intrinsic_const_stable_indirect]
4153#[rustc_intrinsic]
4154#[rustc_intrinsic_must_be_overridden]
4155pub const fn size_of<T>() -> usize {
4156    unreachable!()
4157}
4158
4159/// The minimum alignment of a type.
4160///
4161/// Note that, unlike most intrinsics, this is safe to call;
4162/// it does not require an `unsafe` block.
4163/// Therefore, implementations must not require the user to uphold
4164/// any safety invariants.
4165///
4166/// The stabilized version of this intrinsic is [`core::mem::align_of`].
4167#[rustc_nounwind]
4168#[unstable(feature = "core_intrinsics", issue = "none")]
4169#[rustc_intrinsic_const_stable_indirect]
4170#[rustc_intrinsic]
4171#[rustc_intrinsic_must_be_overridden]
4172pub const fn min_align_of<T>() -> usize {
4173    unreachable!()
4174}
4175
4176/// The preferred alignment of a type.
4177///
4178/// This intrinsic does not have a stable counterpart.
4179/// It's "tracking issue" is [#91971](https://github.com/rust-lang/rust/issues/91971).
4180#[rustc_nounwind]
4181#[unstable(feature = "core_intrinsics", issue = "none")]
4182#[rustc_intrinsic]
4183#[rustc_intrinsic_must_be_overridden]
4184pub const unsafe fn pref_align_of<T>() -> usize {
4185    unreachable!()
4186}
4187
4188/// Returns the number of variants of the type `T` cast to a `usize`;
4189/// if `T` has no variants, returns `0`. Uninhabited variants will be counted.
4190///
4191/// Note that, unlike most intrinsics, this is safe to call;
4192/// it does not require an `unsafe` block.
4193/// Therefore, implementations must not require the user to uphold
4194/// any safety invariants.
4195///
4196/// The to-be-stabilized version of this intrinsic is [`crate::mem::variant_count`].
4197#[rustc_nounwind]
4198#[unstable(feature = "core_intrinsics", issue = "none")]
4199#[rustc_intrinsic]
4200#[rustc_intrinsic_must_be_overridden]
4201pub const fn variant_count<T>() -> usize {
4202    unreachable!()
4203}
4204
4205/// The size of the referenced value in bytes.
4206///
4207/// The stabilized version of this intrinsic is [`crate::mem::size_of_val`].
4208///
4209/// # Safety
4210///
4211/// See [`crate::mem::size_of_val_raw`] for safety conditions.
4212#[rustc_nounwind]
4213#[unstable(feature = "core_intrinsics", issue = "none")]
4214#[rustc_intrinsic]
4215#[rustc_intrinsic_must_be_overridden]
4216#[rustc_intrinsic_const_stable_indirect]
4217pub const unsafe fn size_of_val<T: ?Sized>(_ptr: *const T) -> usize {
4218    unreachable!()
4219}
4220
4221/// The required alignment of the referenced value.
4222///
4223/// The stabilized version of this intrinsic is [`core::mem::align_of_val`].
4224///
4225/// # Safety
4226///
4227/// See [`crate::mem::align_of_val_raw`] for safety conditions.
4228#[rustc_nounwind]
4229#[unstable(feature = "core_intrinsics", issue = "none")]
4230#[rustc_intrinsic]
4231#[rustc_intrinsic_must_be_overridden]
4232#[rustc_intrinsic_const_stable_indirect]
4233pub const unsafe fn min_align_of_val<T: ?Sized>(_ptr: *const T) -> usize {
4234    unreachable!()
4235}
4236
4237/// Gets a static string slice containing the name of a type.
4238///
4239/// Note that, unlike most intrinsics, this is safe to call;
4240/// it does not require an `unsafe` block.
4241/// Therefore, implementations must not require the user to uphold
4242/// any safety invariants.
4243///
4244/// The stabilized version of this intrinsic is [`core::any::type_name`].
4245#[rustc_nounwind]
4246#[unstable(feature = "core_intrinsics", issue = "none")]
4247#[rustc_intrinsic]
4248#[rustc_intrinsic_must_be_overridden]
4249pub const fn type_name<T: ?Sized>() -> &'static str {
4250    unreachable!()
4251}
4252
4253/// Gets an identifier which is globally unique to the specified type. This
4254/// function will return the same value for a type regardless of whichever
4255/// crate it is invoked in.
4256///
4257/// Note that, unlike most intrinsics, this is safe to call;
4258/// it does not require an `unsafe` block.
4259/// Therefore, implementations must not require the user to uphold
4260/// any safety invariants.
4261///
4262/// The stabilized version of this intrinsic is [`core::any::TypeId::of`].
4263#[rustc_nounwind]
4264#[unstable(feature = "core_intrinsics", issue = "none")]
4265#[rustc_intrinsic]
4266#[rustc_intrinsic_must_be_overridden]
4267pub const fn type_id<T: ?Sized + 'static>() -> u128 {
4268    unreachable!()
4269}
4270
4271/// Lowers in MIR to `Rvalue::Aggregate` with `AggregateKind::RawPtr`.
4272///
4273/// This is used to implement functions like `slice::from_raw_parts_mut` and
4274/// `ptr::from_raw_parts` in a way compatible with the compiler being able to
4275/// change the possible layouts of pointers.
4276#[rustc_nounwind]
4277#[unstable(feature = "core_intrinsics", issue = "none")]
4278#[rustc_intrinsic_const_stable_indirect]
4279#[rustc_intrinsic]
4280#[rustc_intrinsic_must_be_overridden]
4281pub const fn aggregate_raw_ptr<P: AggregateRawPtr<D, Metadata = M>, D, M>(_data: D, _meta: M) -> P {
4282    // To implement a fallback we'd have to assume the layout of the pointer,
4283    // but the whole point of this intrinsic is that we shouldn't do that.
4284    unreachable!()
4285}
4286
4287#[unstable(feature = "core_intrinsics", issue = "none")]
4288pub trait AggregateRawPtr<D> {
4289    type Metadata: Copy;
4290}
4291impl<P: ?Sized, T: ptr::Thin> AggregateRawPtr<*const T> for *const P {
4292    type Metadata = <P as ptr::Pointee>::Metadata;
4293}
4294impl<P: ?Sized, T: ptr::Thin> AggregateRawPtr<*mut T> for *mut P {
4295    type Metadata = <P as ptr::Pointee>::Metadata;
4296}
4297
4298/// Lowers in MIR to `Rvalue::UnaryOp` with `UnOp::PtrMetadata`.
4299///
4300/// This is used to implement functions like `ptr::metadata`.
4301#[rustc_nounwind]
4302#[unstable(feature = "core_intrinsics", issue = "none")]
4303#[rustc_intrinsic_const_stable_indirect]
4304#[rustc_intrinsic]
4305#[rustc_intrinsic_must_be_overridden]
4306pub const fn ptr_metadata<P: ptr::Pointee<Metadata = M> + ?Sized, M>(_ptr: *const P) -> M {
4307    // To implement a fallback we'd have to assume the layout of the pointer,
4308    // but the whole point of this intrinsic is that we shouldn't do that.
4309    unreachable!()
4310}
4311
4312// Some functions are defined here because they accidentally got made
4313// available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
4314// (`transmute` also falls into this category, but it cannot be wrapped due to the
4315// check that `T` and `U` have the same size.)
4316
4317/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
4318/// and destination must *not* overlap.
4319///
4320/// For regions of memory which might overlap, use [`copy`] instead.
4321///
4322/// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
4323/// with the argument order swapped.
4324///
4325/// The copy is "untyped" in the sense that data may be uninitialized or otherwise violate the
4326/// requirements of `T`. The initialization state is preserved exactly.
4327///
4328/// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy
4329///
4330/// # Safety
4331///
4332/// Behavior is undefined if any of the following conditions are violated:
4333///
4334/// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
4335///
4336/// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
4337///
4338/// * Both `src` and `dst` must be properly aligned.
4339///
4340/// * The region of memory beginning at `src` with a size of `count *
4341///   size_of::<T>()` bytes must *not* overlap with the region of memory
4342///   beginning at `dst` with the same size.
4343///
4344/// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of
4345/// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values
4346/// in the region beginning at `*src` and the region beginning at `*dst` can
4347/// [violate memory safety][read-ownership].
4348///
4349/// Note that even if the effectively copied size (`count * size_of::<T>()`) is
4350/// `0`, the pointers must be properly aligned.
4351///
4352/// [`read`]: crate::ptr::read
4353/// [read-ownership]: crate::ptr::read#ownership-of-the-returned-value
4354/// [valid]: crate::ptr#safety
4355///
4356/// # Examples
4357///
4358/// Manually implement [`Vec::append`]:
4359///
4360/// ```
4361/// use std::ptr;
4362///
4363/// /// Moves all the elements of `src` into `dst`, leaving `src` empty.
4364/// fn append<T>(dst: &mut Vec<T>, src: &mut Vec<T>) {
4365///     let src_len = src.len();
4366///     let dst_len = dst.len();
4367///
4368///     // Ensure that `dst` has enough capacity to hold all of `src`.
4369///     dst.reserve(src_len);
4370///
4371///     unsafe {
4372///         // The call to add is always safe because `Vec` will never
4373///         // allocate more than `isize::MAX` bytes.
4374///         let dst_ptr = dst.as_mut_ptr().add(dst_len);
4375///         let src_ptr = src.as_ptr();
4376///
4377///         // Truncate `src` without dropping its contents. We do this first,
4378///         // to avoid problems in case something further down panics.
4379///         src.set_len(0);
4380///
4381///         // The two regions cannot overlap because mutable references do
4382///         // not alias, and two different vectors cannot own the same
4383///         // memory.
4384///         ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
4385///
4386///         // Notify `dst` that it now holds the contents of `src`.
4387///         dst.set_len(dst_len + src_len);
4388///     }
4389/// }
4390///
4391/// let mut a = vec!['r'];
4392/// let mut b = vec!['u', 's', 't'];
4393///
4394/// append(&mut a, &mut b);
4395///
4396/// assert_eq!(a, &['r', 'u', 's', 't']);
4397/// assert!(b.is_empty());
4398/// ```
4399///
4400/// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append
4401#[doc(alias = "memcpy")]
4402#[stable(feature = "rust1", since = "1.0.0")]
4403#[cfg_attr(bootstrap, rustc_allowed_through_unstable_modules)]
4404#[cfg_attr(
4405    not(bootstrap),
4406    rustc_allowed_through_unstable_modules = "import this function via `std::mem` instead"
4407)]
4408#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
4409#[inline(always)]
4410#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
4411#[rustc_diagnostic_item = "ptr_copy_nonoverlapping"]
4412pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
4413    #[rustc_intrinsic_const_stable_indirect]
4414    #[rustc_nounwind]
4415    #[rustc_intrinsic]
4416    #[rustc_intrinsic_must_be_overridden]
4417    const unsafe fn copy_nonoverlapping<T>(_src: *const T, _dst: *mut T, _count: usize) {
4418        unreachable!()
4419    }
4420
4421    ub_checks::assert_unsafe_precondition!(
4422        check_language_ub,
4423        "ptr::copy_nonoverlapping requires that both pointer arguments are aligned and non-null \
4424        and the specified memory ranges do not overlap",
4425        (
4426            src: *const () = src as *const (),
4427            dst: *mut () = dst as *mut (),
4428            size: usize = size_of::<T>(),
4429            align: usize = align_of::<T>(),
4430            count: usize = count,
4431        ) => {
4432            let zero_size = count == 0 || size == 0;
4433            ub_checks::maybe_is_aligned_and_not_null(src, align, zero_size)
4434                && ub_checks::maybe_is_aligned_and_not_null(dst, align, zero_size)
4435                && ub_checks::maybe_is_nonoverlapping(src, dst, size, count)
4436        }
4437    );
4438
4439    // SAFETY: the safety contract for `copy_nonoverlapping` must be
4440    // upheld by the caller.
4441    unsafe { copy_nonoverlapping(src, dst, count) }
4442}
4443
4444/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
4445/// and destination may overlap.
4446///
4447/// If the source and destination will *never* overlap,
4448/// [`copy_nonoverlapping`] can be used instead.
4449///
4450/// `copy` is semantically equivalent to C's [`memmove`], but with the argument
4451/// order swapped. Copying takes place as if the bytes were copied from `src`
4452/// to a temporary array and then copied from the array to `dst`.
4453///
4454/// The copy is "untyped" in the sense that data may be uninitialized or otherwise violate the
4455/// requirements of `T`. The initialization state is preserved exactly.
4456///
4457/// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove
4458///
4459/// # Safety
4460///
4461/// Behavior is undefined if any of the following conditions are violated:
4462///
4463/// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
4464///
4465/// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes, and must remain valid even
4466///   when `src` is read for `count * size_of::<T>()` bytes. (This means if the memory ranges
4467///   overlap, the `dst` pointer must not be invalidated by `src` reads.)
4468///
4469/// * Both `src` and `dst` must be properly aligned.
4470///
4471/// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of
4472/// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the values
4473/// in the region beginning at `*src` and the region beginning at `*dst` can
4474/// [violate memory safety][read-ownership].
4475///
4476/// Note that even if the effectively copied size (`count * size_of::<T>()`) is
4477/// `0`, the pointers must be properly aligned.
4478///
4479/// [`read`]: crate::ptr::read
4480/// [read-ownership]: crate::ptr::read#ownership-of-the-returned-value
4481/// [valid]: crate::ptr#safety
4482///
4483/// # Examples
4484///
4485/// Efficiently create a Rust vector from an unsafe buffer:
4486///
4487/// ```
4488/// use std::ptr;
4489///
4490/// /// # Safety
4491/// ///
4492/// /// * `ptr` must be correctly aligned for its type and non-zero.
4493/// /// * `ptr` must be valid for reads of `elts` contiguous elements of type `T`.
4494/// /// * Those elements must not be used after calling this function unless `T: Copy`.
4495/// # #[allow(dead_code)]
4496/// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
4497///     let mut dst = Vec::with_capacity(elts);
4498///
4499///     // SAFETY: Our precondition ensures the source is aligned and valid,
4500///     // and `Vec::with_capacity` ensures that we have usable space to write them.
4501///     ptr::copy(ptr, dst.as_mut_ptr(), elts);
4502///
4503///     // SAFETY: We created it with this much capacity earlier,
4504///     // and the previous `copy` has initialized these elements.
4505///     dst.set_len(elts);
4506///     dst
4507/// }
4508/// ```
4509#[doc(alias = "memmove")]
4510#[stable(feature = "rust1", since = "1.0.0")]
4511#[cfg_attr(bootstrap, rustc_allowed_through_unstable_modules)]
4512#[cfg_attr(
4513    not(bootstrap),
4514    rustc_allowed_through_unstable_modules = "import this function via `std::mem` instead"
4515)]
4516#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
4517#[inline(always)]
4518#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
4519#[rustc_diagnostic_item = "ptr_copy"]
4520pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
4521    #[rustc_intrinsic_const_stable_indirect]
4522    #[rustc_nounwind]
4523    #[rustc_intrinsic]
4524    #[rustc_intrinsic_must_be_overridden]
4525    const unsafe fn copy<T>(_src: *const T, _dst: *mut T, _count: usize) {
4526        unreachable!()
4527    }
4528
4529    // SAFETY: the safety contract for `copy` must be upheld by the caller.
4530    unsafe {
4531        ub_checks::assert_unsafe_precondition!(
4532            check_language_ub,
4533            "ptr::copy requires that both pointer arguments are aligned and non-null",
4534            (
4535                src: *const () = src as *const (),
4536                dst: *mut () = dst as *mut (),
4537                align: usize = align_of::<T>(),
4538                zero_size: bool = T::IS_ZST || count == 0,
4539            ) =>
4540            ub_checks::maybe_is_aligned_and_not_null(src, align, zero_size)
4541                && ub_checks::maybe_is_aligned_and_not_null(dst, align, zero_size)
4542        );
4543        copy(src, dst, count)
4544    }
4545}
4546
4547/// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
4548/// `val`.
4549///
4550/// `write_bytes` is similar to C's [`memset`], but sets `count *
4551/// size_of::<T>()` bytes to `val`.
4552///
4553/// [`memset`]: https://en.cppreference.com/w/c/string/byte/memset
4554///
4555/// # Safety
4556///
4557/// Behavior is undefined if any of the following conditions are violated:
4558///
4559/// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
4560///
4561/// * `dst` must be properly aligned.
4562///
4563/// Note that even if the effectively copied size (`count * size_of::<T>()`) is
4564/// `0`, the pointer must be properly aligned.
4565///
4566/// Additionally, note that changing `*dst` in this way can easily lead to undefined behavior (UB)
4567/// later if the written bytes are not a valid representation of some `T`. For instance, the
4568/// following is an **incorrect** use of this function:
4569///
4570/// ```rust,no_run
4571/// unsafe {
4572///     let mut value: u8 = 0;
4573///     let ptr: *mut bool = &mut value as *mut u8 as *mut bool;
4574///     let _bool = ptr.read(); // This is fine, `ptr` points to a valid `bool`.
4575///     ptr.write_bytes(42u8, 1); // This function itself does not cause UB...
4576///     let _bool = ptr.read(); // ...but it makes this operation UB! ⚠️
4577/// }
4578/// ```
4579///
4580/// [valid]: crate::ptr#safety
4581///
4582/// # Examples
4583///
4584/// Basic usage:
4585///
4586/// ```
4587/// use std::ptr;
4588///
4589/// let mut vec = vec![0u32; 4];
4590/// unsafe {
4591///     let vec_ptr = vec.as_mut_ptr();
4592///     ptr::write_bytes(vec_ptr, 0xfe, 2);
4593/// }
4594/// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
4595/// ```
4596#[doc(alias = "memset")]
4597#[stable(feature = "rust1", since = "1.0.0")]
4598#[cfg_attr(bootstrap, rustc_allowed_through_unstable_modules)]
4599#[cfg_attr(
4600    not(bootstrap),
4601    rustc_allowed_through_unstable_modules = "import this function via `std::mem` instead"
4602)]
4603#[rustc_const_stable(feature = "const_ptr_write", since = "1.83.0")]
4604#[inline(always)]
4605#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
4606#[rustc_diagnostic_item = "ptr_write_bytes"]
4607pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
4608    #[rustc_intrinsic_const_stable_indirect]
4609    #[rustc_nounwind]
4610    #[rustc_intrinsic]
4611    #[rustc_intrinsic_must_be_overridden]
4612    const unsafe fn write_bytes<T>(_dst: *mut T, _val: u8, _count: usize) {
4613        unreachable!()
4614    }
4615
4616    // SAFETY: the safety contract for `write_bytes` must be upheld by the caller.
4617    unsafe {
4618        ub_checks::assert_unsafe_precondition!(
4619            check_language_ub,
4620            "ptr::write_bytes requires that the destination pointer is aligned and non-null",
4621            (
4622                addr: *const () = dst as *const (),
4623                align: usize = align_of::<T>(),
4624                zero_size: bool = T::IS_ZST || count == 0,
4625            ) => ub_checks::maybe_is_aligned_and_not_null(addr, align, zero_size)
4626        );
4627        write_bytes(dst, val, count)
4628    }
4629}
4630
4631/// Returns the minimum of two `f16` values.
4632///
4633/// Note that, unlike most intrinsics, this is safe to call;
4634/// it does not require an `unsafe` block.
4635/// Therefore, implementations must not require the user to uphold
4636/// any safety invariants.
4637///
4638/// The stabilized version of this intrinsic is
4639/// [`f16::min`]
4640#[rustc_nounwind]
4641#[rustc_intrinsic]
4642#[rustc_intrinsic_must_be_overridden]
4643pub const fn minnumf16(_x: f16, _y: f16) -> f16 {
4644    unimplemented!();
4645}
4646
4647/// Returns the minimum of two `f32` values.
4648///
4649/// Note that, unlike most intrinsics, this is safe to call;
4650/// it does not require an `unsafe` block.
4651/// Therefore, implementations must not require the user to uphold
4652/// any safety invariants.
4653///
4654/// The stabilized version of this intrinsic is
4655/// [`f32::min`]
4656#[rustc_nounwind]
4657#[rustc_intrinsic_const_stable_indirect]
4658#[rustc_intrinsic]
4659#[rustc_intrinsic_must_be_overridden]
4660pub const fn minnumf32(_x: f32, _y: f32) -> f32 {
4661    unimplemented!();
4662}
4663
4664/// Returns the minimum of two `f64` values.
4665///
4666/// Note that, unlike most intrinsics, this is safe to call;
4667/// it does not require an `unsafe` block.
4668/// Therefore, implementations must not require the user to uphold
4669/// any safety invariants.
4670///
4671/// The stabilized version of this intrinsic is
4672/// [`f64::min`]
4673#[rustc_nounwind]
4674#[rustc_intrinsic_const_stable_indirect]
4675#[rustc_intrinsic]
4676#[rustc_intrinsic_must_be_overridden]
4677pub const fn minnumf64(_x: f64, _y: f64) -> f64 {
4678    unimplemented!();
4679}
4680
4681/// Returns the minimum of two `f128` values.
4682///
4683/// Note that, unlike most intrinsics, this is safe to call;
4684/// it does not require an `unsafe` block.
4685/// Therefore, implementations must not require the user to uphold
4686/// any safety invariants.
4687///
4688/// The stabilized version of this intrinsic is
4689/// [`f128::min`]
4690#[rustc_nounwind]
4691#[rustc_intrinsic]
4692#[rustc_intrinsic_must_be_overridden]
4693pub const fn minnumf128(_x: f128, _y: f128) -> f128 {
4694    unimplemented!();
4695}
4696
4697/// Returns the maximum of two `f16` values.
4698///
4699/// Note that, unlike most intrinsics, this is safe to call;
4700/// it does not require an `unsafe` block.
4701/// Therefore, implementations must not require the user to uphold
4702/// any safety invariants.
4703///
4704/// The stabilized version of this intrinsic is
4705/// [`f16::max`]
4706#[rustc_nounwind]
4707#[rustc_intrinsic]
4708#[rustc_intrinsic_must_be_overridden]
4709pub const fn maxnumf16(_x: f16, _y: f16) -> f16 {
4710    unimplemented!();
4711}
4712
4713/// Returns the maximum of two `f32` values.
4714///
4715/// Note that, unlike most intrinsics, this is safe to call;
4716/// it does not require an `unsafe` block.
4717/// Therefore, implementations must not require the user to uphold
4718/// any safety invariants.
4719///
4720/// The stabilized version of this intrinsic is
4721/// [`f32::max`]
4722#[rustc_nounwind]
4723#[rustc_intrinsic_const_stable_indirect]
4724#[rustc_intrinsic]
4725#[rustc_intrinsic_must_be_overridden]
4726pub const fn maxnumf32(_x: f32, _y: f32) -> f32 {
4727    unimplemented!();
4728}
4729
4730/// Returns the maximum of two `f64` values.
4731///
4732/// Note that, unlike most intrinsics, this is safe to call;
4733/// it does not require an `unsafe` block.
4734/// Therefore, implementations must not require the user to uphold
4735/// any safety invariants.
4736///
4737/// The stabilized version of this intrinsic is
4738/// [`f64::max`]
4739#[rustc_nounwind]
4740#[rustc_intrinsic_const_stable_indirect]
4741#[rustc_intrinsic]
4742#[rustc_intrinsic_must_be_overridden]
4743pub const fn maxnumf64(_x: f64, _y: f64) -> f64 {
4744    unimplemented!();
4745}
4746
4747/// Returns the maximum of two `f128` values.
4748///
4749/// Note that, unlike most intrinsics, this is safe to call;
4750/// it does not require an `unsafe` block.
4751/// Therefore, implementations must not require the user to uphold
4752/// any safety invariants.
4753///
4754/// The stabilized version of this intrinsic is
4755/// [`f128::max`]
4756#[rustc_nounwind]
4757#[rustc_intrinsic]
4758#[rustc_intrinsic_must_be_overridden]
4759pub const fn maxnumf128(_x: f128, _y: f128) -> f128 {
4760    unimplemented!();
4761}
4762
4763/// Returns the absolute value of an `f16`.
4764///
4765/// The stabilized version of this intrinsic is
4766/// [`f16::abs`](../../std/primitive.f16.html#method.abs)
4767#[rustc_nounwind]
4768#[rustc_intrinsic]
4769#[rustc_intrinsic_must_be_overridden]
4770pub const unsafe fn fabsf16(_x: f16) -> f16 {
4771    unimplemented!();
4772}
4773
4774/// Returns the absolute value of an `f32`.
4775///
4776/// The stabilized version of this intrinsic is
4777/// [`f32::abs`](../../std/primitive.f32.html#method.abs)
4778#[rustc_nounwind]
4779#[rustc_intrinsic_const_stable_indirect]
4780#[rustc_intrinsic]
4781#[rustc_intrinsic_must_be_overridden]
4782pub const unsafe fn fabsf32(_x: f32) -> f32 {
4783    unimplemented!();
4784}
4785
4786/// Returns the absolute value of an `f64`.
4787///
4788/// The stabilized version of this intrinsic is
4789/// [`f64::abs`](../../std/primitive.f64.html#method.abs)
4790#[rustc_nounwind]
4791#[rustc_intrinsic_const_stable_indirect]
4792#[rustc_intrinsic]
4793#[rustc_intrinsic_must_be_overridden]
4794pub const unsafe fn fabsf64(_x: f64) -> f64 {
4795    unimplemented!();
4796}
4797
4798/// Returns the absolute value of an `f128`.
4799///
4800/// The stabilized version of this intrinsic is
4801/// [`f128::abs`](../../std/primitive.f128.html#method.abs)
4802#[rustc_nounwind]
4803#[rustc_intrinsic]
4804#[rustc_intrinsic_must_be_overridden]
4805pub const unsafe fn fabsf128(_x: f128) -> f128 {
4806    unimplemented!();
4807}
4808
4809/// Copies the sign from `y` to `x` for `f16` values.
4810///
4811/// The stabilized version of this intrinsic is
4812/// [`f16::copysign`](../../std/primitive.f16.html#method.copysign)
4813#[rustc_nounwind]
4814#[rustc_intrinsic]
4815#[rustc_intrinsic_must_be_overridden]
4816pub const unsafe fn copysignf16(_x: f16, _y: f16) -> f16 {
4817    unimplemented!();
4818}
4819
4820/// Copies the sign from `y` to `x` for `f32` values.
4821///
4822/// The stabilized version of this intrinsic is
4823/// [`f32::copysign`](../../std/primitive.f32.html#method.copysign)
4824#[rustc_nounwind]
4825#[rustc_intrinsic_const_stable_indirect]
4826#[rustc_intrinsic]
4827#[rustc_intrinsic_must_be_overridden]
4828pub const unsafe fn copysignf32(_x: f32, _y: f32) -> f32 {
4829    unimplemented!();
4830}
4831/// Copies the sign from `y` to `x` for `f64` values.
4832///
4833/// The stabilized version of this intrinsic is
4834/// [`f64::copysign`](../../std/primitive.f64.html#method.copysign)
4835#[rustc_nounwind]
4836#[rustc_intrinsic_const_stable_indirect]
4837#[rustc_intrinsic]
4838#[rustc_intrinsic_must_be_overridden]
4839pub const unsafe fn copysignf64(_x: f64, _y: f64) -> f64 {
4840    unimplemented!();
4841}
4842
4843/// Copies the sign from `y` to `x` for `f128` values.
4844///
4845/// The stabilized version of this intrinsic is
4846/// [`f128::copysign`](../../std/primitive.f128.html#method.copysign)
4847#[rustc_nounwind]
4848#[rustc_intrinsic]
4849#[rustc_intrinsic_must_be_overridden]
4850pub const unsafe fn copysignf128(_x: f128, _y: f128) -> f128 {
4851    unimplemented!();
4852}
4853
4854/// Inform Miri that a given pointer definitely has a certain alignment.
4855#[cfg(miri)]
4856#[rustc_allow_const_fn_unstable(const_eval_select)]
4857pub(crate) const fn miri_promise_symbolic_alignment(ptr: *const (), align: usize) {
4858    unsafe extern "Rust" {
4859        /// Miri-provided extern function to promise that a given pointer is properly aligned for
4860        /// "symbolic" alignment checks. Will fail if the pointer is not actually aligned or `align` is
4861        /// not a power of two. Has no effect when alignment checks are concrete (which is the default).
4862        fn miri_promise_symbolic_alignment(ptr: *const (), align: usize);
4863    }
4864
4865    const_eval_select!(
4866        @capture { ptr: *const (), align: usize}:
4867        if const {
4868            // Do nothing.
4869        } else {
4870            // SAFETY: this call is always safe.
4871            unsafe {
4872                miri_promise_symbolic_alignment(ptr, align);
4873            }
4874        }
4875    )
4876}