core\intrinsics/
mod.rs

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