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