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