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