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