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/// Returns the nearest integer to an `f64`. Rounds half-way cases to the number with an even
2289/// least significant digit.
2290///
2291/// The stabilized version of this intrinsic is
2292/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)
2293#[rustc_intrinsic]
2294#[rustc_nounwind]
2295pub fn round_ties_even_f64(x: f64) -> f64;
2296
2297/// Returns the nearest integer to an `f128`. Rounds half-way cases to the number with an even
2298/// least significant digit.
2299///
2300/// The stabilized version of this intrinsic is
2301/// [`f128::round_ties_even`](../../std/primitive.f128.html#method.round_ties_even)
2302#[rustc_intrinsic]
2303#[rustc_nounwind]
2304pub fn round_ties_even_f128(x: f128) -> f128;
2305
2306/// Returns the nearest integer to an `f16`. Rounds half-way cases away from zero.
2307///
2308/// The stabilized version of this intrinsic is
2309/// [`f16::round`](../../std/primitive.f16.html#method.round)
2310#[rustc_intrinsic]
2311#[rustc_nounwind]
2312pub unsafe fn roundf16(x: f16) -> f16;
2313/// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
2314///
2315/// The stabilized version of this intrinsic is
2316/// [`f32::round`](../../std/primitive.f32.html#method.round)
2317#[rustc_intrinsic]
2318#[rustc_nounwind]
2319pub unsafe fn roundf32(x: f32) -> f32;
2320/// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
2321///
2322/// The stabilized version of this intrinsic is
2323/// [`f64::round`](../../std/primitive.f64.html#method.round)
2324#[rustc_intrinsic]
2325#[rustc_nounwind]
2326pub unsafe fn roundf64(x: f64) -> f64;
2327/// Returns the nearest integer to an `f128`. Rounds half-way cases away from zero.
2328///
2329/// The stabilized version of this intrinsic is
2330/// [`f128::round`](../../std/primitive.f128.html#method.round)
2331#[rustc_intrinsic]
2332#[rustc_nounwind]
2333pub unsafe fn roundf128(x: f128) -> f128;
2334
2335/// Float addition that allows optimizations based on algebraic rules.
2336/// May assume inputs are finite.
2337///
2338/// This intrinsic does not have a stable counterpart.
2339#[rustc_intrinsic]
2340#[rustc_nounwind]
2341pub unsafe fn fadd_fast<T: Copy>(a: T, b: T) -> T;
2342
2343/// Float subtraction that allows optimizations based on algebraic rules.
2344/// May assume inputs are finite.
2345///
2346/// This intrinsic does not have a stable counterpart.
2347#[rustc_intrinsic]
2348#[rustc_nounwind]
2349pub unsafe fn fsub_fast<T: Copy>(a: T, b: T) -> T;
2350
2351/// Float multiplication that allows optimizations based on algebraic rules.
2352/// May assume inputs are finite.
2353///
2354/// This intrinsic does not have a stable counterpart.
2355#[rustc_intrinsic]
2356#[rustc_nounwind]
2357pub unsafe fn fmul_fast<T: Copy>(a: T, b: T) -> T;
2358
2359/// Float division that allows optimizations based on algebraic rules.
2360/// May assume inputs are finite.
2361///
2362/// This intrinsic does not have a stable counterpart.
2363#[rustc_intrinsic]
2364#[rustc_nounwind]
2365pub unsafe fn fdiv_fast<T: Copy>(a: T, b: T) -> T;
2366
2367/// Float remainder that allows optimizations based on algebraic rules.
2368/// May assume inputs are finite.
2369///
2370/// This intrinsic does not have a stable counterpart.
2371#[rustc_intrinsic]
2372#[rustc_nounwind]
2373pub unsafe fn frem_fast<T: Copy>(a: T, b: T) -> T;
2374
2375/// Converts with LLVM’s fptoui/fptosi, which may return undef for values out of range
2376/// (<https://github.com/rust-lang/rust/issues/10184>)
2377///
2378/// Stabilized as [`f32::to_int_unchecked`] and [`f64::to_int_unchecked`].
2379#[rustc_intrinsic]
2380#[rustc_nounwind]
2381pub unsafe fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
2382
2383/// Float addition that allows optimizations based on algebraic rules.
2384///
2385/// Stabilized as [`f16::algebraic_add`], [`f32::algebraic_add`], [`f64::algebraic_add`] and [`f128::algebraic_add`].
2386#[rustc_nounwind]
2387#[rustc_intrinsic]
2388pub const fn fadd_algebraic<T: Copy>(a: T, b: T) -> T;
2389
2390/// Float subtraction that allows optimizations based on algebraic rules.
2391///
2392/// Stabilized as [`f16::algebraic_sub`], [`f32::algebraic_sub`], [`f64::algebraic_sub`] and [`f128::algebraic_sub`].
2393#[rustc_nounwind]
2394#[rustc_intrinsic]
2395pub const fn fsub_algebraic<T: Copy>(a: T, b: T) -> T;
2396
2397/// Float multiplication that allows optimizations based on algebraic rules.
2398///
2399/// Stabilized as [`f16::algebraic_mul`], [`f32::algebraic_mul`], [`f64::algebraic_mul`] and [`f128::algebraic_mul`].
2400#[rustc_nounwind]
2401#[rustc_intrinsic]
2402pub const fn fmul_algebraic<T: Copy>(a: T, b: T) -> T;
2403
2404/// Float division that allows optimizations based on algebraic rules.
2405///
2406/// Stabilized as [`f16::algebraic_div`], [`f32::algebraic_div`], [`f64::algebraic_div`] and [`f128::algebraic_div`].
2407#[rustc_nounwind]
2408#[rustc_intrinsic]
2409pub const fn fdiv_algebraic<T: Copy>(a: T, b: T) -> T;
2410
2411/// Float remainder that allows optimizations based on algebraic rules.
2412///
2413/// Stabilized as [`f16::algebraic_rem`], [`f32::algebraic_rem`], [`f64::algebraic_rem`] and [`f128::algebraic_rem`].
2414#[rustc_nounwind]
2415#[rustc_intrinsic]
2416pub const fn frem_algebraic<T: Copy>(a: T, b: T) -> T;
2417
2418/// Returns the number of bits set in an integer type `T`
2419///
2420/// Note that, unlike most intrinsics, this is safe to call;
2421/// it does not require an `unsafe` block.
2422/// Therefore, implementations must not require the user to uphold
2423/// any safety invariants.
2424///
2425/// The stabilized versions of this intrinsic are available on the integer
2426/// primitives via the `count_ones` method. For example,
2427/// [`u32::count_ones`]
2428#[rustc_intrinsic_const_stable_indirect]
2429#[rustc_nounwind]
2430#[rustc_intrinsic]
2431pub const fn ctpop<T: Copy>(x: T) -> u32;
2432
2433/// Returns the number of leading unset bits (zeroes) in an integer type `T`.
2434///
2435/// Note that, unlike most intrinsics, this is safe to call;
2436/// it does not require an `unsafe` block.
2437/// Therefore, implementations must not require the user to uphold
2438/// any safety invariants.
2439///
2440/// The stabilized versions of this intrinsic are available on the integer
2441/// primitives via the `leading_zeros` method. For example,
2442/// [`u32::leading_zeros`]
2443///
2444/// # Examples
2445///
2446/// ```
2447/// #![feature(core_intrinsics)]
2448/// # #![allow(internal_features)]
2449///
2450/// use std::intrinsics::ctlz;
2451///
2452/// let x = 0b0001_1100_u8;
2453/// let num_leading = ctlz(x);
2454/// assert_eq!(num_leading, 3);
2455/// ```
2456///
2457/// An `x` with value `0` will return the bit width of `T`.
2458///
2459/// ```
2460/// #![feature(core_intrinsics)]
2461/// # #![allow(internal_features)]
2462///
2463/// use std::intrinsics::ctlz;
2464///
2465/// let x = 0u16;
2466/// let num_leading = ctlz(x);
2467/// assert_eq!(num_leading, 16);
2468/// ```
2469#[rustc_intrinsic_const_stable_indirect]
2470#[rustc_nounwind]
2471#[rustc_intrinsic]
2472pub const fn ctlz<T: Copy>(x: T) -> u32;
2473
2474/// Like `ctlz`, but extra-unsafe as it returns `undef` when
2475/// given an `x` with value `0`.
2476///
2477/// This intrinsic does not have a stable counterpart.
2478///
2479/// # Examples
2480///
2481/// ```
2482/// #![feature(core_intrinsics)]
2483/// # #![allow(internal_features)]
2484///
2485/// use std::intrinsics::ctlz_nonzero;
2486///
2487/// let x = 0b0001_1100_u8;
2488/// let num_leading = unsafe { ctlz_nonzero(x) };
2489/// assert_eq!(num_leading, 3);
2490/// ```
2491#[rustc_intrinsic_const_stable_indirect]
2492#[rustc_nounwind]
2493#[rustc_intrinsic]
2494pub const unsafe fn ctlz_nonzero<T: Copy>(x: T) -> u32;
2495
2496/// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
2497///
2498/// Note that, unlike most intrinsics, this is safe to call;
2499/// it does not require an `unsafe` block.
2500/// Therefore, implementations must not require the user to uphold
2501/// any safety invariants.
2502///
2503/// The stabilized versions of this intrinsic are available on the integer
2504/// primitives via the `trailing_zeros` method. For example,
2505/// [`u32::trailing_zeros`]
2506///
2507/// # Examples
2508///
2509/// ```
2510/// #![feature(core_intrinsics)]
2511/// # #![allow(internal_features)]
2512///
2513/// use std::intrinsics::cttz;
2514///
2515/// let x = 0b0011_1000_u8;
2516/// let num_trailing = cttz(x);
2517/// assert_eq!(num_trailing, 3);
2518/// ```
2519///
2520/// An `x` with value `0` will return the bit width of `T`:
2521///
2522/// ```
2523/// #![feature(core_intrinsics)]
2524/// # #![allow(internal_features)]
2525///
2526/// use std::intrinsics::cttz;
2527///
2528/// let x = 0u16;
2529/// let num_trailing = cttz(x);
2530/// assert_eq!(num_trailing, 16);
2531/// ```
2532#[rustc_intrinsic_const_stable_indirect]
2533#[rustc_nounwind]
2534#[rustc_intrinsic]
2535pub const fn cttz<T: Copy>(x: T) -> u32;
2536
2537/// Like `cttz`, but extra-unsafe as it returns `undef` when
2538/// given an `x` with value `0`.
2539///
2540/// This intrinsic does not have a stable counterpart.
2541///
2542/// # Examples
2543///
2544/// ```
2545/// #![feature(core_intrinsics)]
2546/// # #![allow(internal_features)]
2547///
2548/// use std::intrinsics::cttz_nonzero;
2549///
2550/// let x = 0b0011_1000_u8;
2551/// let num_trailing = unsafe { cttz_nonzero(x) };
2552/// assert_eq!(num_trailing, 3);
2553/// ```
2554#[rustc_intrinsic_const_stable_indirect]
2555#[rustc_nounwind]
2556#[rustc_intrinsic]
2557pub const unsafe fn cttz_nonzero<T: Copy>(x: T) -> u32;
2558
2559/// Reverses the bytes in an integer type `T`.
2560///
2561/// Note that, unlike most intrinsics, this is safe to call;
2562/// it does not require an `unsafe` block.
2563/// Therefore, implementations must not require the user to uphold
2564/// any safety invariants.
2565///
2566/// The stabilized versions of this intrinsic are available on the integer
2567/// primitives via the `swap_bytes` method. For example,
2568/// [`u32::swap_bytes`]
2569#[rustc_intrinsic_const_stable_indirect]
2570#[rustc_nounwind]
2571#[rustc_intrinsic]
2572pub const fn bswap<T: Copy>(x: T) -> T;
2573
2574/// Reverses the bits in an integer type `T`.
2575///
2576/// Note that, unlike most intrinsics, this is safe to call;
2577/// it does not require an `unsafe` block.
2578/// Therefore, implementations must not require the user to uphold
2579/// any safety invariants.
2580///
2581/// The stabilized versions of this intrinsic are available on the integer
2582/// primitives via the `reverse_bits` method. For example,
2583/// [`u32::reverse_bits`]
2584#[rustc_intrinsic_const_stable_indirect]
2585#[rustc_nounwind]
2586#[rustc_intrinsic]
2587pub const fn bitreverse<T: Copy>(x: T) -> T;
2588
2589/// Does a three-way comparison between the two arguments,
2590/// which must be of character or integer (signed or unsigned) type.
2591///
2592/// This was originally added because it greatly simplified the MIR in `cmp`
2593/// implementations, and then LLVM 20 added a backend intrinsic for it too.
2594///
2595/// The stabilized version of this intrinsic is [`Ord::cmp`].
2596#[rustc_intrinsic_const_stable_indirect]
2597#[rustc_nounwind]
2598#[rustc_intrinsic]
2599pub const fn three_way_compare<T: Copy>(lhs: T, rhss: T) -> crate::cmp::Ordering;
2600
2601/// Combine two values which have no bits in common.
2602///
2603/// This allows the backend to implement it as `a + b` *or* `a | b`,
2604/// depending which is easier to implement on a specific target.
2605///
2606/// # Safety
2607///
2608/// Requires that `(a & b) == 0`, or equivalently that `(a | b) == (a + b)`.
2609///
2610/// Otherwise it's immediate UB.
2611#[rustc_const_unstable(feature = "disjoint_bitor", issue = "135758")]
2612#[rustc_nounwind]
2613#[rustc_intrinsic]
2614#[track_caller]
2615#[miri::intrinsic_fallback_is_spec] // the fallbacks all `assume` to tell Miri
2616pub const unsafe fn disjoint_bitor<T: ~const fallback::DisjointBitOr>(a: T, b: T) -> T {
2617    // SAFETY: same preconditions as this function.
2618    unsafe { fallback::DisjointBitOr::disjoint_bitor(a, b) }
2619}
2620
2621/// Performs checked integer addition.
2622///
2623/// Note that, unlike most intrinsics, this is safe to call;
2624/// it does not require an `unsafe` block.
2625/// Therefore, implementations must not require the user to uphold
2626/// any safety invariants.
2627///
2628/// The stabilized versions of this intrinsic are available on the integer
2629/// primitives via the `overflowing_add` method. For example,
2630/// [`u32::overflowing_add`]
2631#[rustc_intrinsic_const_stable_indirect]
2632#[rustc_nounwind]
2633#[rustc_intrinsic]
2634pub const fn add_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
2635
2636/// Performs checked integer subtraction
2637///
2638/// Note that, unlike most intrinsics, this is safe to call;
2639/// it does not require an `unsafe` block.
2640/// Therefore, implementations must not require the user to uphold
2641/// any safety invariants.
2642///
2643/// The stabilized versions of this intrinsic are available on the integer
2644/// primitives via the `overflowing_sub` method. For example,
2645/// [`u32::overflowing_sub`]
2646#[rustc_intrinsic_const_stable_indirect]
2647#[rustc_nounwind]
2648#[rustc_intrinsic]
2649pub const fn sub_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
2650
2651/// Performs checked integer multiplication
2652///
2653/// Note that, unlike most intrinsics, this is safe to call;
2654/// it does not require an `unsafe` block.
2655/// Therefore, implementations must not require the user to uphold
2656/// any safety invariants.
2657///
2658/// The stabilized versions of this intrinsic are available on the integer
2659/// primitives via the `overflowing_mul` method. For example,
2660/// [`u32::overflowing_mul`]
2661#[rustc_intrinsic_const_stable_indirect]
2662#[rustc_nounwind]
2663#[rustc_intrinsic]
2664pub const fn mul_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
2665
2666/// Performs full-width multiplication and addition with a carry:
2667/// `multiplier * multiplicand + addend + carry`.
2668///
2669/// This is possible without any overflow.  For `uN`:
2670///    MAX * MAX + MAX + MAX
2671/// => (2ⁿ-1) × (2ⁿ-1) + (2ⁿ-1) + (2ⁿ-1)
2672/// => (2²ⁿ - 2ⁿ⁺¹ + 1) + (2ⁿ⁺¹ - 2)
2673/// => 2²ⁿ - 1
2674///
2675/// For `iN`, the upper bound is MIN * MIN + MAX + MAX => 2²ⁿ⁻² + 2ⁿ - 2,
2676/// and the lower bound is MAX * MIN + MIN + MIN => -2²ⁿ⁻² - 2ⁿ + 2ⁿ⁺¹.
2677///
2678/// This currently supports unsigned integers *only*, no signed ones.
2679/// The stabilized versions of this intrinsic are available on integers.
2680#[unstable(feature = "core_intrinsics", issue = "none")]
2681#[rustc_const_unstable(feature = "const_carrying_mul_add", issue = "85532")]
2682#[rustc_nounwind]
2683#[rustc_intrinsic]
2684#[miri::intrinsic_fallback_is_spec]
2685pub const fn carrying_mul_add<T: ~const fallback::CarryingMulAdd<Unsigned = U>, U>(
2686    multiplier: T,
2687    multiplicand: T,
2688    addend: T,
2689    carry: T,
2690) -> (U, T) {
2691    multiplier.carrying_mul_add(multiplicand, addend, carry)
2692}
2693
2694/// Performs an exact division, resulting in undefined behavior where
2695/// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
2696///
2697/// This intrinsic does not have a stable counterpart.
2698#[rustc_intrinsic_const_stable_indirect]
2699#[rustc_nounwind]
2700#[rustc_intrinsic]
2701pub const unsafe fn exact_div<T: Copy>(x: T, y: T) -> T;
2702
2703/// Performs an unchecked division, resulting in undefined behavior
2704/// where `y == 0` or `x == T::MIN && y == -1`
2705///
2706/// Safe wrappers for this intrinsic are available on the integer
2707/// primitives via the `checked_div` method. For example,
2708/// [`u32::checked_div`]
2709#[rustc_intrinsic_const_stable_indirect]
2710#[rustc_nounwind]
2711#[rustc_intrinsic]
2712pub const unsafe fn unchecked_div<T: Copy>(x: T, y: T) -> T;
2713/// Returns the remainder of an unchecked division, resulting in
2714/// undefined behavior when `y == 0` or `x == T::MIN && y == -1`
2715///
2716/// Safe wrappers for this intrinsic are available on the integer
2717/// primitives via the `checked_rem` method. For example,
2718/// [`u32::checked_rem`]
2719#[rustc_intrinsic_const_stable_indirect]
2720#[rustc_nounwind]
2721#[rustc_intrinsic]
2722pub const unsafe fn unchecked_rem<T: Copy>(x: T, y: T) -> T;
2723
2724/// Performs an unchecked left shift, resulting in undefined behavior when
2725/// `y < 0` or `y >= N`, where N is the width of T in bits.
2726///
2727/// Safe wrappers for this intrinsic are available on the integer
2728/// primitives via the `checked_shl` method. For example,
2729/// [`u32::checked_shl`]
2730#[rustc_intrinsic_const_stable_indirect]
2731#[rustc_nounwind]
2732#[rustc_intrinsic]
2733pub const unsafe fn unchecked_shl<T: Copy, U: Copy>(x: T, y: U) -> T;
2734/// Performs an unchecked right shift, resulting in undefined behavior when
2735/// `y < 0` or `y >= N`, where N is the width of T in bits.
2736///
2737/// Safe wrappers for this intrinsic are available on the integer
2738/// primitives via the `checked_shr` method. For example,
2739/// [`u32::checked_shr`]
2740#[rustc_intrinsic_const_stable_indirect]
2741#[rustc_nounwind]
2742#[rustc_intrinsic]
2743pub const unsafe fn unchecked_shr<T: Copy, U: Copy>(x: T, y: U) -> T;
2744
2745/// Returns the result of an unchecked addition, resulting in
2746/// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.
2747///
2748/// The stable counterpart of this intrinsic is `unchecked_add` on the various
2749/// integer types, such as [`u16::unchecked_add`] and [`i64::unchecked_add`].
2750#[rustc_intrinsic_const_stable_indirect]
2751#[rustc_nounwind]
2752#[rustc_intrinsic]
2753pub const unsafe fn unchecked_add<T: Copy>(x: T, y: T) -> T;
2754
2755/// Returns the result of an unchecked subtraction, resulting in
2756/// undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`.
2757///
2758/// The stable counterpart of this intrinsic is `unchecked_sub` on the various
2759/// integer types, such as [`u16::unchecked_sub`] and [`i64::unchecked_sub`].
2760#[rustc_intrinsic_const_stable_indirect]
2761#[rustc_nounwind]
2762#[rustc_intrinsic]
2763pub const unsafe fn unchecked_sub<T: Copy>(x: T, y: T) -> T;
2764
2765/// Returns the result of an unchecked multiplication, resulting in
2766/// undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`.
2767///
2768/// The stable counterpart of this intrinsic is `unchecked_mul` on the various
2769/// integer types, such as [`u16::unchecked_mul`] and [`i64::unchecked_mul`].
2770#[rustc_intrinsic_const_stable_indirect]
2771#[rustc_nounwind]
2772#[rustc_intrinsic]
2773pub const unsafe fn unchecked_mul<T: Copy>(x: T, y: T) -> T;
2774
2775/// Performs rotate left.
2776///
2777/// Note that, unlike most intrinsics, this is safe to call;
2778/// it does not require an `unsafe` block.
2779/// Therefore, implementations must not require the user to uphold
2780/// any safety invariants.
2781///
2782/// The stabilized versions of this intrinsic are available on the integer
2783/// primitives via the `rotate_left` method. For example,
2784/// [`u32::rotate_left`]
2785#[rustc_intrinsic_const_stable_indirect]
2786#[rustc_nounwind]
2787#[rustc_intrinsic]
2788pub const fn rotate_left<T: Copy>(x: T, shift: u32) -> T;
2789
2790/// Performs rotate right.
2791///
2792/// Note that, unlike most intrinsics, this is safe to call;
2793/// it does not require an `unsafe` block.
2794/// Therefore, implementations must not require the user to uphold
2795/// any safety invariants.
2796///
2797/// The stabilized versions of this intrinsic are available on the integer
2798/// primitives via the `rotate_right` method. For example,
2799/// [`u32::rotate_right`]
2800#[rustc_intrinsic_const_stable_indirect]
2801#[rustc_nounwind]
2802#[rustc_intrinsic]
2803pub const fn rotate_right<T: Copy>(x: T, shift: u32) -> T;
2804
2805/// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
2806///
2807/// Note that, unlike most intrinsics, this is safe to call;
2808/// it does not require an `unsafe` block.
2809/// Therefore, implementations must not require the user to uphold
2810/// any safety invariants.
2811///
2812/// The stabilized versions of this intrinsic are available on the integer
2813/// primitives via the `wrapping_add` method. For example,
2814/// [`u32::wrapping_add`]
2815#[rustc_intrinsic_const_stable_indirect]
2816#[rustc_nounwind]
2817#[rustc_intrinsic]
2818pub const fn wrapping_add<T: Copy>(a: T, b: T) -> T;
2819/// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
2820///
2821/// Note that, unlike most intrinsics, this is safe to call;
2822/// it does not require an `unsafe` block.
2823/// Therefore, implementations must not require the user to uphold
2824/// any safety invariants.
2825///
2826/// The stabilized versions of this intrinsic are available on the integer
2827/// primitives via the `wrapping_sub` method. For example,
2828/// [`u32::wrapping_sub`]
2829#[rustc_intrinsic_const_stable_indirect]
2830#[rustc_nounwind]
2831#[rustc_intrinsic]
2832pub const fn wrapping_sub<T: Copy>(a: T, b: T) -> T;
2833/// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
2834///
2835/// Note that, unlike most intrinsics, this is safe to call;
2836/// it does not require an `unsafe` block.
2837/// Therefore, implementations must not require the user to uphold
2838/// any safety invariants.
2839///
2840/// The stabilized versions of this intrinsic are available on the integer
2841/// primitives via the `wrapping_mul` method. For example,
2842/// [`u32::wrapping_mul`]
2843#[rustc_intrinsic_const_stable_indirect]
2844#[rustc_nounwind]
2845#[rustc_intrinsic]
2846pub const fn wrapping_mul<T: Copy>(a: T, b: T) -> T;
2847
2848/// Computes `a + b`, saturating at numeric bounds.
2849///
2850/// Note that, unlike most intrinsics, this is safe to call;
2851/// it does not require an `unsafe` block.
2852/// Therefore, implementations must not require the user to uphold
2853/// any safety invariants.
2854///
2855/// The stabilized versions of this intrinsic are available on the integer
2856/// primitives via the `saturating_add` method. For example,
2857/// [`u32::saturating_add`]
2858#[rustc_intrinsic_const_stable_indirect]
2859#[rustc_nounwind]
2860#[rustc_intrinsic]
2861pub const fn saturating_add<T: Copy>(a: T, b: T) -> T;
2862/// Computes `a - b`, saturating at numeric bounds.
2863///
2864/// Note that, unlike most intrinsics, this is safe to call;
2865/// it does not require an `unsafe` block.
2866/// Therefore, implementations must not require the user to uphold
2867/// any safety invariants.
2868///
2869/// The stabilized versions of this intrinsic are available on the integer
2870/// primitives via the `saturating_sub` method. For example,
2871/// [`u32::saturating_sub`]
2872#[rustc_intrinsic_const_stable_indirect]
2873#[rustc_nounwind]
2874#[rustc_intrinsic]
2875pub const fn saturating_sub<T: Copy>(a: T, b: T) -> T;
2876
2877/// This is an implementation detail of [`crate::ptr::read`] and should
2878/// not be used anywhere else.  See its comments for why this exists.
2879///
2880/// This intrinsic can *only* be called where the pointer is a local without
2881/// projections (`read_via_copy(ptr)`, not `read_via_copy(*ptr)`) so that it
2882/// trivially obeys runtime-MIR rules about derefs in operands.
2883#[rustc_intrinsic_const_stable_indirect]
2884#[rustc_nounwind]
2885#[rustc_intrinsic]
2886pub const unsafe fn read_via_copy<T>(ptr: *const T) -> T;
2887
2888/// This is an implementation detail of [`crate::ptr::write`] and should
2889/// not be used anywhere else.  See its comments for why this exists.
2890///
2891/// This intrinsic can *only* be called where the pointer is a local without
2892/// projections (`write_via_move(ptr, x)`, not `write_via_move(*ptr, x)`) so
2893/// that it trivially obeys runtime-MIR rules about derefs in operands.
2894#[rustc_intrinsic_const_stable_indirect]
2895#[rustc_nounwind]
2896#[rustc_intrinsic]
2897pub const unsafe fn write_via_move<T>(ptr: *mut T, value: T);
2898
2899/// Returns the value of the discriminant for the variant in 'v';
2900/// if `T` has no discriminant, returns `0`.
2901///
2902/// Note that, unlike most intrinsics, this is safe to call;
2903/// it does not require an `unsafe` block.
2904/// Therefore, implementations must not require the user to uphold
2905/// any safety invariants.
2906///
2907/// The stabilized version of this intrinsic is [`core::mem::discriminant`].
2908#[rustc_intrinsic_const_stable_indirect]
2909#[rustc_nounwind]
2910#[rustc_intrinsic]
2911pub const fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
2912
2913/// Rust's "try catch" construct for unwinding. Invokes the function pointer `try_fn` with the
2914/// data pointer `data`, and calls `catch_fn` if unwinding occurs while `try_fn` runs.
2915/// Returns `1` if unwinding occurred and `catch_fn` was called; returns `0` otherwise.
2916///
2917/// `catch_fn` must not unwind.
2918///
2919/// The third argument is a function called if an unwind occurs (both Rust `panic` and foreign
2920/// unwinds). This function takes the data pointer and a pointer to the target- and
2921/// runtime-specific exception object that was caught.
2922///
2923/// Note that in the case of a foreign unwinding operation, the exception object data may not be
2924/// safely usable from Rust, and should not be directly exposed via the standard library. To
2925/// prevent unsafe access, the library implementation may either abort the process or present an
2926/// opaque error type to the user.
2927///
2928/// For more information, see the compiler's source, as well as the documentation for the stable
2929/// version of this intrinsic, `std::panic::catch_unwind`.
2930#[rustc_intrinsic]
2931#[rustc_nounwind]
2932pub unsafe fn catch_unwind(
2933    _try_fn: fn(*mut u8),
2934    _data: *mut u8,
2935    _catch_fn: fn(*mut u8, *mut u8),
2936) -> i32;
2937
2938/// Emits a `nontemporal` store, which gives a hint to the CPU that the data should not be held
2939/// in cache. Except for performance, this is fully equivalent to `ptr.write(val)`.
2940///
2941/// Not all architectures provide such an operation. For instance, x86 does not: while `MOVNT`
2942/// exists, that operation is *not* equivalent to `ptr.write(val)` (`MOVNT` writes can be reordered
2943/// in ways that are not allowed for regular writes).
2944#[rustc_intrinsic]
2945#[rustc_nounwind]
2946pub unsafe fn nontemporal_store<T>(ptr: *mut T, val: T);
2947
2948/// See documentation of `<*const T>::offset_from` for details.
2949#[rustc_intrinsic_const_stable_indirect]
2950#[rustc_nounwind]
2951#[rustc_intrinsic]
2952pub const unsafe fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
2953
2954/// See documentation of `<*const T>::offset_from_unsigned` for details.
2955#[rustc_nounwind]
2956#[rustc_intrinsic]
2957#[rustc_intrinsic_const_stable_indirect]
2958pub const unsafe fn ptr_offset_from_unsigned<T>(ptr: *const T, base: *const T) -> usize;
2959
2960/// See documentation of `<*const T>::guaranteed_eq` for details.
2961/// Returns `2` if the result is unknown.
2962/// Returns `1` if the pointers are guaranteed equal.
2963/// Returns `0` if the pointers are guaranteed inequal.
2964#[rustc_intrinsic]
2965#[rustc_nounwind]
2966#[rustc_do_not_const_check]
2967#[inline]
2968#[miri::intrinsic_fallback_is_spec]
2969pub const fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8 {
2970    (ptr == other) as u8
2971}
2972
2973/// Determines whether the raw bytes of the two values are equal.
2974///
2975/// This is particularly handy for arrays, since it allows things like just
2976/// comparing `i96`s instead of forcing `alloca`s for `[6 x i16]`.
2977///
2978/// Above some backend-decided threshold this will emit calls to `memcmp`,
2979/// like slice equality does, instead of causing massive code size.
2980///
2981/// Since this works by comparing the underlying bytes, the actual `T` is
2982/// not particularly important.  It will be used for its size and alignment,
2983/// but any validity restrictions will be ignored, not enforced.
2984///
2985/// # Safety
2986///
2987/// It's UB to call this if any of the *bytes* in `*a` or `*b` are uninitialized.
2988/// Note that this is a stricter criterion than just the *values* being
2989/// fully-initialized: if `T` has padding, it's UB to call this intrinsic.
2990///
2991/// At compile-time, it is furthermore UB to call this if any of the bytes
2992/// in `*a` or `*b` have provenance.
2993///
2994/// (The implementation is allowed to branch on the results of comparisons,
2995/// which is UB if any of their inputs are `undef`.)
2996#[rustc_nounwind]
2997#[rustc_intrinsic]
2998pub const unsafe fn raw_eq<T>(a: &T, b: &T) -> bool;
2999
3000/// Lexicographically compare `[left, left + bytes)` and `[right, right + bytes)`
3001/// as unsigned bytes, returning negative if `left` is less, zero if all the
3002/// bytes match, or positive if `left` is greater.
3003///
3004/// This underlies things like `<[u8]>::cmp`, and will usually lower to `memcmp`.
3005///
3006/// # Safety
3007///
3008/// `left` and `right` must each be [valid] for reads of `bytes` bytes.
3009///
3010/// Note that this applies to the whole range, not just until the first byte
3011/// that differs.  That allows optimizations that can read in large chunks.
3012///
3013/// [valid]: crate::ptr#safety
3014#[rustc_nounwind]
3015#[rustc_intrinsic]
3016pub const unsafe fn compare_bytes(left: *const u8, right: *const u8, bytes: usize) -> i32;
3017
3018/// See documentation of [`std::hint::black_box`] for details.
3019///
3020/// [`std::hint::black_box`]: crate::hint::black_box
3021#[rustc_nounwind]
3022#[rustc_intrinsic]
3023#[rustc_intrinsic_const_stable_indirect]
3024pub const fn black_box<T>(dummy: T) -> T;
3025
3026/// Selects which function to call depending on the context.
3027///
3028/// If this function is evaluated at compile-time, then a call to this
3029/// intrinsic will be replaced with a call to `called_in_const`. It gets
3030/// replaced with a call to `called_at_rt` otherwise.
3031///
3032/// This function is safe to call, but note the stability concerns below.
3033///
3034/// # Type Requirements
3035///
3036/// The two functions must be both function items. They cannot be function
3037/// pointers or closures. The first function must be a `const fn`.
3038///
3039/// `arg` will be the tupled arguments that will be passed to either one of
3040/// the two functions, therefore, both functions must accept the same type of
3041/// arguments. Both functions must return RET.
3042///
3043/// # Stability concerns
3044///
3045/// Rust has not yet decided that `const fn` are allowed to tell whether
3046/// they run at compile-time or at runtime. Therefore, when using this
3047/// intrinsic anywhere that can be reached from stable, it is crucial that
3048/// the end-to-end behavior of the stable `const fn` is the same for both
3049/// modes of execution. (Here, Undefined Behavior is considered "the same"
3050/// as any other behavior, so if the function exhibits UB at runtime then
3051/// it may do whatever it wants at compile-time.)
3052///
3053/// Here is an example of how this could cause a problem:
3054/// ```no_run
3055/// #![feature(const_eval_select)]
3056/// #![feature(core_intrinsics)]
3057/// # #![allow(internal_features)]
3058/// use std::intrinsics::const_eval_select;
3059///
3060/// // Standard library
3061/// pub const fn inconsistent() -> i32 {
3062///     fn runtime() -> i32 { 1 }
3063///     const fn compiletime() -> i32 { 2 }
3064///
3065///     // ⚠ This code violates the required equivalence of `compiletime`
3066///     // and `runtime`.
3067///     const_eval_select((), compiletime, runtime)
3068/// }
3069///
3070/// // User Crate
3071/// const X: i32 = inconsistent();
3072/// let x = inconsistent();
3073/// assert_eq!(x, X);
3074/// ```
3075///
3076/// Currently such an assertion would always succeed; until Rust decides
3077/// otherwise, that principle should not be violated.
3078#[rustc_const_unstable(feature = "const_eval_select", issue = "124625")]
3079#[rustc_intrinsic]
3080pub const fn const_eval_select<ARG: Tuple, F, G, RET>(
3081    _arg: ARG,
3082    _called_in_const: F,
3083    _called_at_rt: G,
3084) -> RET
3085where
3086    G: FnOnce<ARG, Output = RET>,
3087    F: FnOnce<ARG, Output = RET>;
3088
3089/// A macro to make it easier to invoke const_eval_select. Use as follows:
3090/// ```rust,ignore (just a macro example)
3091/// const_eval_select!(
3092///     @capture { arg1: i32 = some_expr, arg2: T = other_expr } -> U:
3093///     if const #[attributes_for_const_arm] {
3094///         // Compile-time code goes here.
3095///     } else #[attributes_for_runtime_arm] {
3096///         // Run-time code goes here.
3097///     }
3098/// )
3099/// ```
3100/// The `@capture` block declares which surrounding variables / expressions can be
3101/// used inside the `if const`.
3102/// Note that the two arms of this `if` really each become their own function, which is why the
3103/// macro supports setting attributes for those functions. The runtime function is always
3104/// markes as `#[inline]`.
3105///
3106/// See [`const_eval_select()`] for the rules and requirements around that intrinsic.
3107pub(crate) macro const_eval_select {
3108    (
3109        @capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty = $val:expr),* $(,)? } $( -> $ret:ty )? :
3110        if const
3111            $(#[$compiletime_attr:meta])* $compiletime:block
3112        else
3113            $(#[$runtime_attr:meta])* $runtime:block
3114    ) => {
3115        // Use the `noinline` arm, after adding explicit `inline` attributes
3116        $crate::intrinsics::const_eval_select!(
3117            @capture$([$($binders)*])? { $($arg : $ty = $val),* } $(-> $ret)? :
3118            #[noinline]
3119            if const
3120                #[inline] // prevent codegen on this function
3121                $(#[$compiletime_attr])*
3122                $compiletime
3123            else
3124                #[inline] // avoid the overhead of an extra fn call
3125                $(#[$runtime_attr])*
3126                $runtime
3127        )
3128    },
3129    // With a leading #[noinline], we don't add inline attributes
3130    (
3131        @capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty = $val:expr),* $(,)? } $( -> $ret:ty )? :
3132        #[noinline]
3133        if const
3134            $(#[$compiletime_attr:meta])* $compiletime:block
3135        else
3136            $(#[$runtime_attr:meta])* $runtime:block
3137    ) => {{
3138        $(#[$runtime_attr])*
3139        fn runtime$(<$($binders)*>)?($($arg: $ty),*) $( -> $ret )? {
3140            $runtime
3141        }
3142
3143        $(#[$compiletime_attr])*
3144        const fn compiletime$(<$($binders)*>)?($($arg: $ty),*) $( -> $ret )? {
3145            // Don't warn if one of the arguments is unused.
3146            $(let _ = $arg;)*
3147
3148            $compiletime
3149        }
3150
3151        const_eval_select(($($val,)*), compiletime, runtime)
3152    }},
3153    // We support leaving away the `val` expressions for *all* arguments
3154    // (but not for *some* arguments, that's too tricky).
3155    (
3156        @capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty),* $(,)? } $( -> $ret:ty )? :
3157        if const
3158            $(#[$compiletime_attr:meta])* $compiletime:block
3159        else
3160            $(#[$runtime_attr:meta])* $runtime:block
3161    ) => {
3162        $crate::intrinsics::const_eval_select!(
3163            @capture$([$($binders)*])? { $($arg : $ty = $arg),* } $(-> $ret)? :
3164            if const
3165                $(#[$compiletime_attr])* $compiletime
3166            else
3167                $(#[$runtime_attr])* $runtime
3168        )
3169    },
3170}
3171
3172/// Returns whether the argument's value is statically known at
3173/// compile-time.
3174///
3175/// This is useful when there is a way of writing the code that will
3176/// be *faster* when some variables have known values, but *slower*
3177/// in the general case: an `if is_val_statically_known(var)` can be used
3178/// to select between these two variants. The `if` will be optimized away
3179/// and only the desired branch remains.
3180///
3181/// Formally speaking, this function non-deterministically returns `true`
3182/// or `false`, and the caller has to ensure sound behavior for both cases.
3183/// In other words, the following code has *Undefined Behavior*:
3184///
3185/// ```no_run
3186/// #![feature(core_intrinsics)]
3187/// # #![allow(internal_features)]
3188/// use std::hint::unreachable_unchecked;
3189/// use std::intrinsics::is_val_statically_known;
3190///
3191/// if !is_val_statically_known(0) { unsafe { unreachable_unchecked(); } }
3192/// ```
3193///
3194/// This also means that the following code's behavior is unspecified; it
3195/// may panic, or it may not:
3196///
3197/// ```no_run
3198/// #![feature(core_intrinsics)]
3199/// # #![allow(internal_features)]
3200/// use std::intrinsics::is_val_statically_known;
3201///
3202/// assert_eq!(is_val_statically_known(0), is_val_statically_known(0));
3203/// ```
3204///
3205/// Unsafe code may not rely on `is_val_statically_known` returning any
3206/// particular value, ever. However, the compiler will generally make it
3207/// return `true` only if the value of the argument is actually known.
3208///
3209/// # Stability concerns
3210///
3211/// While it is safe to call, this intrinsic may behave differently in
3212/// a `const` context than otherwise. See the [`const_eval_select()`]
3213/// documentation for an explanation of the issues this can cause. Unlike
3214/// `const_eval_select`, this intrinsic isn't guaranteed to behave
3215/// deterministically even in a `const` context.
3216///
3217/// # Type Requirements
3218///
3219/// `T` must be either a `bool`, a `char`, a primitive numeric type (e.g. `f32`,
3220/// but not `NonZeroISize`), or any thin pointer (e.g. `*mut String`).
3221/// Any other argument types *may* cause a compiler error.
3222///
3223/// ## Pointers
3224///
3225/// When the input is a pointer, only the pointer itself is
3226/// ever considered. The pointee has no effect. Currently, these functions
3227/// behave identically:
3228///
3229/// ```
3230/// #![feature(core_intrinsics)]
3231/// # #![allow(internal_features)]
3232/// use std::intrinsics::is_val_statically_known;
3233///
3234/// fn foo(x: &i32) -> bool {
3235///     is_val_statically_known(x)
3236/// }
3237///
3238/// fn bar(x: &i32) -> bool {
3239///     is_val_statically_known(
3240///         (x as *const i32).addr()
3241///     )
3242/// }
3243/// # _ = foo(&5_i32);
3244/// # _ = bar(&5_i32);
3245/// ```
3246#[rustc_const_stable_indirect]
3247#[rustc_nounwind]
3248#[unstable(feature = "core_intrinsics", issue = "none")]
3249#[rustc_intrinsic]
3250pub const fn is_val_statically_known<T: Copy>(_arg: T) -> bool {
3251    false
3252}
3253
3254/// Non-overlapping *typed* swap of a single value.
3255///
3256/// The codegen backends will replace this with a better implementation when
3257/// `T` is a simple type that can be loaded and stored as an immediate.
3258///
3259/// The stabilized form of this intrinsic is [`crate::mem::swap`].
3260///
3261/// # Safety
3262/// Behavior is undefined if any of the following conditions are violated:
3263///
3264/// * Both `x` and `y` must be [valid] for both reads and writes.
3265///
3266/// * Both `x` and `y` must be properly aligned.
3267///
3268/// * The region of memory beginning at `x` must *not* overlap with the region of memory
3269///   beginning at `y`.
3270///
3271/// * The memory pointed by `x` and `y` must both contain values of type `T`.
3272///
3273/// [valid]: crate::ptr#safety
3274#[rustc_nounwind]
3275#[inline]
3276#[rustc_intrinsic]
3277#[rustc_intrinsic_const_stable_indirect]
3278pub const unsafe fn typed_swap_nonoverlapping<T>(x: *mut T, y: *mut T) {
3279    // SAFETY: The caller provided single non-overlapping items behind
3280    // pointers, so swapping them with `count: 1` is fine.
3281    unsafe { ptr::swap_nonoverlapping(x, y, 1) };
3282}
3283
3284/// Returns whether we should perform some UB-checking at runtime. This eventually evaluates to
3285/// `cfg!(ub_checks)`, but behaves different from `cfg!` when mixing crates built with different
3286/// flags: if the crate has UB checks enabled or carries the `#[rustc_preserve_ub_checks]`
3287/// attribute, evaluation is delayed until monomorphization (or until the call gets inlined into
3288/// a crate that does not delay evaluation further); otherwise it can happen any time.
3289///
3290/// The common case here is a user program built with ub_checks linked against the distributed
3291/// sysroot which is built without ub_checks but with `#[rustc_preserve_ub_checks]`.
3292/// For code that gets monomorphized in the user crate (i.e., generic functions and functions with
3293/// `#[inline]`), gating assertions on `ub_checks()` rather than `cfg!(ub_checks)` means that
3294/// assertions are enabled whenever the *user crate* has UB checks enabled. However, if the
3295/// user has UB checks disabled, the checks will still get optimized out. This intrinsic is
3296/// primarily used by [`crate::ub_checks::assert_unsafe_precondition`].
3297#[rustc_intrinsic_const_stable_indirect] // just for UB checks
3298#[inline(always)]
3299#[rustc_intrinsic]
3300pub const fn ub_checks() -> bool {
3301    cfg!(ub_checks)
3302}
3303
3304/// Allocates a block of memory at compile time.
3305/// At runtime, just returns a null pointer.
3306///
3307/// # Safety
3308///
3309/// - The `align` argument must be a power of two.
3310///    - At compile time, a compile error occurs if this constraint is violated.
3311///    - At runtime, it is not checked.
3312#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
3313#[rustc_nounwind]
3314#[rustc_intrinsic]
3315#[miri::intrinsic_fallback_is_spec]
3316pub const unsafe fn const_allocate(_size: usize, _align: usize) -> *mut u8 {
3317    // const eval overrides this function, but runtime code for now just returns null pointers.
3318    // See <https://github.com/rust-lang/rust/issues/93935>.
3319    crate::ptr::null_mut()
3320}
3321
3322/// Deallocates a memory which allocated by `intrinsics::const_allocate` at compile time.
3323/// At runtime, does nothing.
3324///
3325/// # Safety
3326///
3327/// - The `align` argument must be a power of two.
3328///    - At compile time, a compile error occurs if this constraint is violated.
3329///    - At runtime, it is not checked.
3330/// - If the `ptr` is created in an another const, this intrinsic doesn't deallocate it.
3331/// - If the `ptr` is pointing to a local variable, this intrinsic doesn't deallocate it.
3332#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
3333#[unstable(feature = "core_intrinsics", issue = "none")]
3334#[rustc_nounwind]
3335#[rustc_intrinsic]
3336#[miri::intrinsic_fallback_is_spec]
3337pub const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {
3338    // Runtime NOP
3339}
3340
3341/// Returns whether we should perform contract-checking at runtime.
3342///
3343/// This is meant to be similar to the ub_checks intrinsic, in terms
3344/// of not prematurely commiting at compile-time to whether contract
3345/// checking is turned on, so that we can specify contracts in libstd
3346/// and let an end user opt into turning them on.
3347#[rustc_const_unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
3348#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
3349#[inline(always)]
3350#[rustc_intrinsic]
3351pub const fn contract_checks() -> bool {
3352    // FIXME: should this be `false` or `cfg!(contract_checks)`?
3353
3354    // cfg!(contract_checks)
3355    false
3356}
3357
3358/// Check if the pre-condition `cond` has been met.
3359///
3360/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
3361/// returns false.
3362///
3363/// Note that this function is a no-op during constant evaluation.
3364#[unstable(feature = "contracts_internals", issue = "128044")]
3365// Calls to this function get inserted by an AST expansion pass, which uses the equivalent of
3366// `#[allow_internal_unstable]` to allow using `contracts_internals` functions. Const-checking
3367// doesn't honor `#[allow_internal_unstable]`, so for the const feature gate we use the user-facing
3368// `contracts` feature rather than the perma-unstable `contracts_internals`
3369#[rustc_const_unstable(feature = "contracts", issue = "128044")]
3370#[lang = "contract_check_requires"]
3371#[rustc_intrinsic]
3372pub const fn contract_check_requires<C: Fn() -> bool + Copy>(cond: C) {
3373    const_eval_select!(
3374        @capture[C: Fn() -> bool + Copy] { cond: C } :
3375        if const {
3376                // Do nothing
3377        } else {
3378            if contract_checks() && !cond() {
3379                // Emit no unwind panic in case this was a safety requirement.
3380                crate::panicking::panic_nounwind("failed requires check");
3381            }
3382        }
3383    )
3384}
3385
3386/// Check if the post-condition `cond` has been met.
3387///
3388/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
3389/// returns false.
3390///
3391/// Note that this function is a no-op during constant evaluation.
3392#[unstable(feature = "contracts_internals", issue = "128044")]
3393// Similar to `contract_check_requires`, we need to use the user-facing
3394// `contracts` feature rather than the perma-unstable `contracts_internals`.
3395// Const-checking doesn't honor allow_internal_unstable logic used by contract expansion.
3396#[rustc_const_unstable(feature = "contracts", issue = "128044")]
3397#[lang = "contract_check_ensures"]
3398#[rustc_intrinsic]
3399pub const fn contract_check_ensures<C: Fn(&Ret) -> bool + Copy, Ret>(cond: C, ret: Ret) -> Ret {
3400    const_eval_select!(
3401        @capture[C: Fn(&Ret) -> bool + Copy, Ret] { cond: C, ret: Ret } -> Ret :
3402        if const {
3403            // Do nothing
3404            ret
3405        } else {
3406            if contract_checks() && !cond(&ret) {
3407                // Emit no unwind panic in case this was a safety requirement.
3408                crate::panicking::panic_nounwind("failed ensures check");
3409            }
3410            ret
3411        }
3412    )
3413}
3414
3415/// The intrinsic will return the size stored in that vtable.
3416///
3417/// # Safety
3418///
3419/// `ptr` must point to a vtable.
3420#[rustc_nounwind]
3421#[unstable(feature = "core_intrinsics", issue = "none")]
3422#[rustc_intrinsic]
3423pub unsafe fn vtable_size(ptr: *const ()) -> usize;
3424
3425/// The intrinsic will return the alignment stored in that vtable.
3426///
3427/// # Safety
3428///
3429/// `ptr` must point to a vtable.
3430#[rustc_nounwind]
3431#[unstable(feature = "core_intrinsics", issue = "none")]
3432#[rustc_intrinsic]
3433pub unsafe fn vtable_align(ptr: *const ()) -> usize;
3434
3435/// The size of a type in bytes.
3436///
3437/// Note that, unlike most intrinsics, this is safe to call;
3438/// it does not require an `unsafe` block.
3439/// Therefore, implementations must not require the user to uphold
3440/// any safety invariants.
3441///
3442/// More specifically, this is the offset in bytes between successive
3443/// items of the same type, including alignment padding.
3444///
3445/// The stabilized version of this intrinsic is [`size_of`].
3446#[rustc_nounwind]
3447#[unstable(feature = "core_intrinsics", issue = "none")]
3448#[rustc_intrinsic_const_stable_indirect]
3449#[rustc_intrinsic]
3450pub const fn size_of<T>() -> usize;
3451
3452/// The minimum alignment of a type.
3453///
3454/// Note that, unlike most intrinsics, this is safe to call;
3455/// it does not require an `unsafe` block.
3456/// Therefore, implementations must not require the user to uphold
3457/// any safety invariants.
3458///
3459/// The stabilized version of this intrinsic is [`align_of`].
3460#[rustc_nounwind]
3461#[unstable(feature = "core_intrinsics", issue = "none")]
3462#[rustc_intrinsic_const_stable_indirect]
3463#[rustc_intrinsic]
3464pub const fn min_align_of<T>() -> usize;
3465
3466/// The preferred alignment of a type.
3467///
3468/// This intrinsic does not have a stable counterpart.
3469/// It's "tracking issue" is [#91971](https://github.com/rust-lang/rust/issues/91971).
3470#[rustc_nounwind]
3471#[unstable(feature = "core_intrinsics", issue = "none")]
3472#[rustc_intrinsic]
3473pub const unsafe fn pref_align_of<T>() -> usize;
3474
3475/// Returns the number of variants of the type `T` cast to a `usize`;
3476/// if `T` has no variants, returns `0`. Uninhabited variants will be counted.
3477///
3478/// Note that, unlike most intrinsics, this is safe to call;
3479/// it does not require an `unsafe` block.
3480/// Therefore, implementations must not require the user to uphold
3481/// any safety invariants.
3482///
3483/// The to-be-stabilized version of this intrinsic is [`crate::mem::variant_count`].
3484#[rustc_nounwind]
3485#[unstable(feature = "core_intrinsics", issue = "none")]
3486#[rustc_intrinsic]
3487pub const fn variant_count<T>() -> usize;
3488
3489/// The size of the referenced value in bytes.
3490///
3491/// The stabilized version of this intrinsic is [`size_of_val`].
3492///
3493/// # Safety
3494///
3495/// See [`crate::mem::size_of_val_raw`] for safety conditions.
3496#[rustc_nounwind]
3497#[unstable(feature = "core_intrinsics", issue = "none")]
3498#[rustc_intrinsic]
3499#[rustc_intrinsic_const_stable_indirect]
3500pub const unsafe fn size_of_val<T: ?Sized>(ptr: *const T) -> usize;
3501
3502/// The required alignment of the referenced value.
3503///
3504/// The stabilized version of this intrinsic is [`align_of_val`].
3505///
3506/// # Safety
3507///
3508/// See [`crate::mem::align_of_val_raw`] for safety conditions.
3509#[rustc_nounwind]
3510#[unstable(feature = "core_intrinsics", issue = "none")]
3511#[rustc_intrinsic]
3512#[rustc_intrinsic_const_stable_indirect]
3513pub const unsafe fn min_align_of_val<T: ?Sized>(ptr: *const T) -> usize;
3514
3515/// Gets a static string slice containing the name of a type.
3516///
3517/// Note that, unlike most intrinsics, this is safe to call;
3518/// it does not require an `unsafe` block.
3519/// Therefore, implementations must not require the user to uphold
3520/// any safety invariants.
3521///
3522/// The stabilized version of this intrinsic is [`core::any::type_name`].
3523#[rustc_nounwind]
3524#[unstable(feature = "core_intrinsics", issue = "none")]
3525#[rustc_intrinsic]
3526pub const fn type_name<T: ?Sized>() -> &'static str;
3527
3528/// Gets an identifier which is globally unique to the specified type. This
3529/// function will return the same value for a type regardless of whichever
3530/// crate it is invoked in.
3531///
3532/// Note that, unlike most intrinsics, this is safe to call;
3533/// it does not require an `unsafe` block.
3534/// Therefore, implementations must not require the user to uphold
3535/// any safety invariants.
3536///
3537/// The stabilized version of this intrinsic is [`core::any::TypeId::of`].
3538#[rustc_nounwind]
3539#[unstable(feature = "core_intrinsics", issue = "none")]
3540#[rustc_intrinsic]
3541pub const fn type_id<T: ?Sized + 'static>() -> u128;
3542
3543/// Lowers in MIR to `Rvalue::Aggregate` with `AggregateKind::RawPtr`.
3544///
3545/// This is used to implement functions like `slice::from_raw_parts_mut` and
3546/// `ptr::from_raw_parts` in a way compatible with the compiler being able to
3547/// change the possible layouts of pointers.
3548#[rustc_nounwind]
3549#[unstable(feature = "core_intrinsics", issue = "none")]
3550#[rustc_intrinsic_const_stable_indirect]
3551#[rustc_intrinsic]
3552pub const fn aggregate_raw_ptr<P: AggregateRawPtr<D, Metadata = M>, D, M>(data: D, meta: M) -> P;
3553
3554#[unstable(feature = "core_intrinsics", issue = "none")]
3555pub trait AggregateRawPtr<D> {
3556    type Metadata: Copy;
3557}
3558impl<P: ?Sized, T: ptr::Thin> AggregateRawPtr<*const T> for *const P {
3559    type Metadata = <P as ptr::Pointee>::Metadata;
3560}
3561impl<P: ?Sized, T: ptr::Thin> AggregateRawPtr<*mut T> for *mut P {
3562    type Metadata = <P as ptr::Pointee>::Metadata;
3563}
3564
3565/// Lowers in MIR to `Rvalue::UnaryOp` with `UnOp::PtrMetadata`.
3566///
3567/// This is used to implement functions like `ptr::metadata`.
3568#[rustc_nounwind]
3569#[unstable(feature = "core_intrinsics", issue = "none")]
3570#[rustc_intrinsic_const_stable_indirect]
3571#[rustc_intrinsic]
3572pub const fn ptr_metadata<P: ptr::Pointee<Metadata = M> + ?Sized, M>(ptr: *const P) -> M;
3573
3574/// This is an accidentally-stable alias to [`ptr::copy_nonoverlapping`]; use that instead.
3575// Note (intentionally not in the doc comment): `ptr::copy_nonoverlapping` adds some extra
3576// debug assertions; if you are writing compiler tests or code inside the standard library
3577// that wants to avoid those debug assertions, directly call this intrinsic instead.
3578#[stable(feature = "rust1", since = "1.0.0")]
3579#[rustc_allowed_through_unstable_modules = "import this function via `std::ptr` instead"]
3580#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
3581#[rustc_nounwind]
3582#[rustc_intrinsic]
3583pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
3584
3585/// This is an accidentally-stable alias to [`ptr::copy`]; use that instead.
3586// Note (intentionally not in the doc comment): `ptr::copy` adds some extra
3587// debug assertions; if you are writing compiler tests or code inside the standard library
3588// that wants to avoid those debug assertions, directly call this intrinsic instead.
3589#[stable(feature = "rust1", since = "1.0.0")]
3590#[rustc_allowed_through_unstable_modules = "import this function via `std::ptr` instead"]
3591#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
3592#[rustc_nounwind]
3593#[rustc_intrinsic]
3594pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize);
3595
3596/// This is an accidentally-stable alias to [`ptr::write_bytes`]; use that instead.
3597// Note (intentionally not in the doc comment): `ptr::write_bytes` adds some extra
3598// debug assertions; if you are writing compiler tests or code inside the standard library
3599// that wants to avoid those debug assertions, directly call this intrinsic instead.
3600#[stable(feature = "rust1", since = "1.0.0")]
3601#[rustc_allowed_through_unstable_modules = "import this function via `std::ptr` instead"]
3602#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.83.0")]
3603#[rustc_nounwind]
3604#[rustc_intrinsic]
3605pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
3606
3607/// Returns the minimum (IEEE 754-2008 minNum) of two `f16` values.
3608///
3609/// Note that, unlike most intrinsics, this is safe to call;
3610/// it does not require an `unsafe` block.
3611/// Therefore, implementations must not require the user to uphold
3612/// any safety invariants.
3613///
3614/// The stabilized version of this intrinsic is
3615/// [`f16::min`]
3616#[rustc_nounwind]
3617#[rustc_intrinsic]
3618pub const fn minnumf16(x: f16, y: f16) -> f16;
3619
3620/// Returns the minimum (IEEE 754-2008 minNum) of two `f32` values.
3621///
3622/// Note that, unlike most intrinsics, this is safe to call;
3623/// it does not require an `unsafe` block.
3624/// Therefore, implementations must not require the user to uphold
3625/// any safety invariants.
3626///
3627/// The stabilized version of this intrinsic is
3628/// [`f32::min`]
3629#[rustc_nounwind]
3630#[rustc_intrinsic_const_stable_indirect]
3631#[rustc_intrinsic]
3632pub const fn minnumf32(x: f32, y: f32) -> f32;
3633
3634/// Returns the minimum (IEEE 754-2008 minNum) of two `f64` values.
3635///
3636/// Note that, unlike most intrinsics, this is safe to call;
3637/// it does not require an `unsafe` block.
3638/// Therefore, implementations must not require the user to uphold
3639/// any safety invariants.
3640///
3641/// The stabilized version of this intrinsic is
3642/// [`f64::min`]
3643#[rustc_nounwind]
3644#[rustc_intrinsic_const_stable_indirect]
3645#[rustc_intrinsic]
3646pub const fn minnumf64(x: f64, y: f64) -> f64;
3647
3648/// Returns the minimum (IEEE 754-2008 minNum) of two `f128` values.
3649///
3650/// Note that, unlike most intrinsics, this is safe to call;
3651/// it does not require an `unsafe` block.
3652/// Therefore, implementations must not require the user to uphold
3653/// any safety invariants.
3654///
3655/// The stabilized version of this intrinsic is
3656/// [`f128::min`]
3657#[rustc_nounwind]
3658#[rustc_intrinsic]
3659pub const fn minnumf128(x: f128, y: f128) -> f128;
3660
3661/// Returns the minimum (IEEE 754-2019 minimum) of two `f16` values.
3662///
3663/// Note that, unlike most intrinsics, this is safe to call;
3664/// it does not require an `unsafe` block.
3665/// Therefore, implementations must not require the user to uphold
3666/// any safety invariants.
3667#[rustc_nounwind]
3668#[cfg_attr(not(bootstrap), rustc_intrinsic)]
3669pub const fn minimumf16(x: f16, y: f16) -> f16 {
3670    if x < y {
3671        x
3672    } else if y < x {
3673        y
3674    } else if x == y {
3675        if x.is_sign_negative() && y.is_sign_positive() { x } else { y }
3676    } else {
3677        // At least one input is NaN. Use `+` to perform NaN propagation and quieting.
3678        x + y
3679    }
3680}
3681
3682/// Returns the minimum (IEEE 754-2019 minimum) of two `f32` values.
3683///
3684/// Note that, unlike most intrinsics, this is safe to call;
3685/// it does not require an `unsafe` block.
3686/// Therefore, implementations must not require the user to uphold
3687/// any safety invariants.
3688#[rustc_nounwind]
3689#[cfg_attr(not(bootstrap), rustc_intrinsic)]
3690pub const fn minimumf32(x: f32, y: f32) -> f32 {
3691    if x < y {
3692        x
3693    } else if y < x {
3694        y
3695    } else if x == y {
3696        if x.is_sign_negative() && y.is_sign_positive() { x } else { y }
3697    } else {
3698        // At least one input is NaN. Use `+` to perform NaN propagation and quieting.
3699        x + y
3700    }
3701}
3702
3703/// Returns the minimum (IEEE 754-2019 minimum) of two `f64` values.
3704///
3705/// Note that, unlike most intrinsics, this is safe to call;
3706/// it does not require an `unsafe` block.
3707/// Therefore, implementations must not require the user to uphold
3708/// any safety invariants.
3709#[rustc_nounwind]
3710#[cfg_attr(not(bootstrap), rustc_intrinsic)]
3711pub const fn minimumf64(x: f64, y: f64) -> f64 {
3712    if x < y {
3713        x
3714    } else if y < x {
3715        y
3716    } else if x == y {
3717        if x.is_sign_negative() && y.is_sign_positive() { x } else { y }
3718    } else {
3719        // At least one input is NaN. Use `+` to perform NaN propagation and quieting.
3720        x + y
3721    }
3722}
3723
3724/// Returns the minimum (IEEE 754-2019 minimum) of two `f128` values.
3725///
3726/// Note that, unlike most intrinsics, this is safe to call;
3727/// it does not require an `unsafe` block.
3728/// Therefore, implementations must not require the user to uphold
3729/// any safety invariants.
3730#[rustc_nounwind]
3731#[cfg_attr(not(bootstrap), rustc_intrinsic)]
3732pub const fn minimumf128(x: f128, y: f128) -> f128 {
3733    if x < y {
3734        x
3735    } else if y < x {
3736        y
3737    } else if x == y {
3738        if x.is_sign_negative() && y.is_sign_positive() { x } else { y }
3739    } else {
3740        // At least one input is NaN. Use `+` to perform NaN propagation and quieting.
3741        x + y
3742    }
3743}
3744
3745/// Returns the maximum (IEEE 754-2008 maxNum) of two `f16` values.
3746///
3747/// Note that, unlike most intrinsics, this is safe to call;
3748/// it does not require an `unsafe` block.
3749/// Therefore, implementations must not require the user to uphold
3750/// any safety invariants.
3751///
3752/// The stabilized version of this intrinsic is
3753/// [`f16::max`]
3754#[rustc_nounwind]
3755#[rustc_intrinsic]
3756pub const fn maxnumf16(x: f16, y: f16) -> f16;
3757
3758/// Returns the maximum (IEEE 754-2008 maxNum) of two `f32` values.
3759///
3760/// Note that, unlike most intrinsics, this is safe to call;
3761/// it does not require an `unsafe` block.
3762/// Therefore, implementations must not require the user to uphold
3763/// any safety invariants.
3764///
3765/// The stabilized version of this intrinsic is
3766/// [`f32::max`]
3767#[rustc_nounwind]
3768#[rustc_intrinsic_const_stable_indirect]
3769#[rustc_intrinsic]
3770pub const fn maxnumf32(x: f32, y: f32) -> f32;
3771
3772/// Returns the maximum (IEEE 754-2008 maxNum) of two `f64` values.
3773///
3774/// Note that, unlike most intrinsics, this is safe to call;
3775/// it does not require an `unsafe` block.
3776/// Therefore, implementations must not require the user to uphold
3777/// any safety invariants.
3778///
3779/// The stabilized version of this intrinsic is
3780/// [`f64::max`]
3781#[rustc_nounwind]
3782#[rustc_intrinsic_const_stable_indirect]
3783#[rustc_intrinsic]
3784pub const fn maxnumf64(x: f64, y: f64) -> f64;
3785
3786/// Returns the maximum (IEEE 754-2008 maxNum) of two `f128` values.
3787///
3788/// Note that, unlike most intrinsics, this is safe to call;
3789/// it does not require an `unsafe` block.
3790/// Therefore, implementations must not require the user to uphold
3791/// any safety invariants.
3792///
3793/// The stabilized version of this intrinsic is
3794/// [`f128::max`]
3795#[rustc_nounwind]
3796#[rustc_intrinsic]
3797pub const fn maxnumf128(x: f128, y: f128) -> f128;
3798
3799/// Returns the maximum (IEEE 754-2019 maximum) of two `f16` values.
3800///
3801/// Note that, unlike most intrinsics, this is safe to call;
3802/// it does not require an `unsafe` block.
3803/// Therefore, implementations must not require the user to uphold
3804/// any safety invariants.
3805#[rustc_nounwind]
3806#[cfg_attr(not(bootstrap), rustc_intrinsic)]
3807pub const fn maximumf16(x: f16, y: f16) -> f16 {
3808    if x > y {
3809        x
3810    } else if y > x {
3811        y
3812    } else if x == y {
3813        if x.is_sign_positive() && y.is_sign_negative() { x } else { y }
3814    } else {
3815        x + y
3816    }
3817}
3818
3819/// Returns the maximum (IEEE 754-2019 maximum) of two `f32` values.
3820///
3821/// Note that, unlike most intrinsics, this is safe to call;
3822/// it does not require an `unsafe` block.
3823/// Therefore, implementations must not require the user to uphold
3824/// any safety invariants.
3825#[rustc_nounwind]
3826#[cfg_attr(not(bootstrap), rustc_intrinsic)]
3827pub const fn maximumf32(x: f32, y: f32) -> f32 {
3828    if x > y {
3829        x
3830    } else if y > x {
3831        y
3832    } else if x == y {
3833        if x.is_sign_positive() && y.is_sign_negative() { x } else { y }
3834    } else {
3835        x + y
3836    }
3837}
3838
3839/// Returns the maximum (IEEE 754-2019 maximum) of two `f64` values.
3840///
3841/// Note that, unlike most intrinsics, this is safe to call;
3842/// it does not require an `unsafe` block.
3843/// Therefore, implementations must not require the user to uphold
3844/// any safety invariants.
3845#[rustc_nounwind]
3846#[cfg_attr(not(bootstrap), rustc_intrinsic)]
3847pub const fn maximumf64(x: f64, y: f64) -> f64 {
3848    if x > y {
3849        x
3850    } else if y > x {
3851        y
3852    } else if x == y {
3853        if x.is_sign_positive() && y.is_sign_negative() { x } else { y }
3854    } else {
3855        x + y
3856    }
3857}
3858
3859/// Returns the maximum (IEEE 754-2019 maximum) of two `f128` values.
3860///
3861/// Note that, unlike most intrinsics, this is safe to call;
3862/// it does not require an `unsafe` block.
3863/// Therefore, implementations must not require the user to uphold
3864/// any safety invariants.
3865#[rustc_nounwind]
3866#[cfg_attr(not(bootstrap), rustc_intrinsic)]
3867pub const fn maximumf128(x: f128, y: f128) -> f128 {
3868    if x > y {
3869        x
3870    } else if y > x {
3871        y
3872    } else if x == y {
3873        if x.is_sign_positive() && y.is_sign_negative() { x } else { y }
3874    } else {
3875        x + y
3876    }
3877}
3878
3879/// Returns the absolute value of an `f16`.
3880///
3881/// The stabilized version of this intrinsic is
3882/// [`f16::abs`](../../std/primitive.f16.html#method.abs)
3883#[rustc_nounwind]
3884#[rustc_intrinsic]
3885pub const unsafe fn fabsf16(x: f16) -> f16;
3886
3887/// Returns the absolute value of an `f32`.
3888///
3889/// The stabilized version of this intrinsic is
3890/// [`f32::abs`](../../std/primitive.f32.html#method.abs)
3891#[rustc_nounwind]
3892#[rustc_intrinsic_const_stable_indirect]
3893#[rustc_intrinsic]
3894pub const unsafe fn fabsf32(x: f32) -> f32;
3895
3896/// Returns the absolute value of an `f64`.
3897///
3898/// The stabilized version of this intrinsic is
3899/// [`f64::abs`](../../std/primitive.f64.html#method.abs)
3900#[rustc_nounwind]
3901#[rustc_intrinsic_const_stable_indirect]
3902#[rustc_intrinsic]
3903pub const unsafe fn fabsf64(x: f64) -> f64;
3904
3905/// Returns the absolute value of an `f128`.
3906///
3907/// The stabilized version of this intrinsic is
3908/// [`f128::abs`](../../std/primitive.f128.html#method.abs)
3909#[rustc_nounwind]
3910#[rustc_intrinsic]
3911pub const unsafe fn fabsf128(x: f128) -> f128;
3912
3913/// Copies the sign from `y` to `x` for `f16` values.
3914///
3915/// The stabilized version of this intrinsic is
3916/// [`f16::copysign`](../../std/primitive.f16.html#method.copysign)
3917#[rustc_nounwind]
3918#[rustc_intrinsic]
3919pub const unsafe fn copysignf16(x: f16, y: f16) -> f16;
3920
3921/// Copies the sign from `y` to `x` for `f32` values.
3922///
3923/// The stabilized version of this intrinsic is
3924/// [`f32::copysign`](../../std/primitive.f32.html#method.copysign)
3925#[rustc_nounwind]
3926#[rustc_intrinsic_const_stable_indirect]
3927#[rustc_intrinsic]
3928pub const unsafe fn copysignf32(x: f32, y: f32) -> f32;
3929/// Copies the sign from `y` to `x` for `f64` values.
3930///
3931/// The stabilized version of this intrinsic is
3932/// [`f64::copysign`](../../std/primitive.f64.html#method.copysign)
3933#[rustc_nounwind]
3934#[rustc_intrinsic_const_stable_indirect]
3935#[rustc_intrinsic]
3936pub const unsafe fn copysignf64(x: f64, y: f64) -> f64;
3937
3938/// Copies the sign from `y` to `x` for `f128` values.
3939///
3940/// The stabilized version of this intrinsic is
3941/// [`f128::copysign`](../../std/primitive.f128.html#method.copysign)
3942#[rustc_nounwind]
3943#[rustc_intrinsic]
3944pub const unsafe fn copysignf128(x: f128, y: f128) -> f128;
3945
3946/// Inform Miri that a given pointer definitely has a certain alignment.
3947#[cfg(miri)]
3948#[rustc_allow_const_fn_unstable(const_eval_select)]
3949pub(crate) const fn miri_promise_symbolic_alignment(ptr: *const (), align: usize) {
3950    unsafe extern "Rust" {
3951        /// Miri-provided extern function to promise that a given pointer is properly aligned for
3952        /// "symbolic" alignment checks. Will fail if the pointer is not actually aligned or `align` is
3953        /// not a power of two. Has no effect when alignment checks are concrete (which is the default).
3954        fn miri_promise_symbolic_alignment(ptr: *const (), align: usize);
3955    }
3956
3957    const_eval_select!(
3958        @capture { ptr: *const (), align: usize}:
3959        if const {
3960            // Do nothing.
3961        } else {
3962            // SAFETY: this call is always safe.
3963            unsafe {
3964                miri_promise_symbolic_alignment(ptr, align);
3965            }
3966        }
3967    )
3968}