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