]> git.lizzy.rs Git - rust.git/blob - src/libcore/intrinsics.rs
Deny unsafe ops in unsafe fns, part 6
[rust.git] / src / libcore / intrinsics.rs
1 //! Compiler intrinsics.
2 //!
3 //! The corresponding definitions are in `librustc_codegen_llvm/intrinsic.rs`.
4 //! The corresponding const implementations are in `librustc_mir/interpret/intrinsics.rs`
5 //!
6 //! # Const intrinsics
7 //!
8 //! Note: any changes to the constness of intrinsics should be discussed with the language team.
9 //! This includes changes in the stability of the constness.
10 //!
11 //! In order to make an intrinsic usable at compile-time, one needs to copy the implementation
12 //! from https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics.rs to
13 //! `librustc_mir/interpret/intrinsics.rs` and add a
14 //! `#[rustc_const_unstable(feature = "foo", issue = "01234")]` to the intrinsic.
15 //!
16 //! If an intrinsic is supposed to be used from a `const fn` with a `rustc_const_stable` attribute,
17 //! the intrinsic's attribute must be `rustc_const_stable`, too. Such a change should not be done
18 //! without T-lang consulation, because it bakes a feature into the language that cannot be
19 //! replicated in user code without compiler support.
20 //!
21 //! # Volatiles
22 //!
23 //! The volatile intrinsics provide operations intended to act on I/O
24 //! memory, which are guaranteed to not be reordered by the compiler
25 //! across other volatile intrinsics. See the LLVM documentation on
26 //! [[volatile]].
27 //!
28 //! [volatile]: http://llvm.org/docs/LangRef.html#volatile-memory-accesses
29 //!
30 //! # Atomics
31 //!
32 //! The atomic intrinsics provide common atomic operations on machine
33 //! words, with multiple possible memory orderings. They obey the same
34 //! semantics as C++11. See the LLVM documentation on [[atomics]].
35 //!
36 //! [atomics]: http://llvm.org/docs/Atomics.html
37 //!
38 //! A quick refresher on memory ordering:
39 //!
40 //! * Acquire - a barrier for acquiring a lock. Subsequent reads and writes
41 //!   take place after the barrier.
42 //! * Release - a barrier for releasing a lock. Preceding reads and writes
43 //!   take place before the barrier.
44 //! * Sequentially consistent - sequentially consistent operations are
45 //!   guaranteed to happen in order. This is the standard mode for working
46 //!   with atomic types and is equivalent to Java's `volatile`.
47
48 #![unstable(
49     feature = "core_intrinsics",
50     reason = "intrinsics are unlikely to ever be stabilized, instead \
51                       they should be used through stabilized interfaces \
52                       in the rest of the standard library",
53     issue = "none"
54 )]
55 #![allow(missing_docs)]
56
57 use crate::marker::DiscriminantKind;
58 use crate::mem;
59
60 #[stable(feature = "drop_in_place", since = "1.8.0")]
61 #[rustc_deprecated(
62     reason = "no longer an intrinsic - use `ptr::drop_in_place` directly",
63     since = "1.18.0"
64 )]
65 pub use crate::ptr::drop_in_place;
66
67 extern "rust-intrinsic" {
68     // N.B., these intrinsics take raw pointers because they mutate aliased
69     // memory, which is not valid for either `&` or `&mut`.
70
71     /// Stores a value if the current value is the same as the `old` value.
72     ///
73     /// The stabilized version of this intrinsic is available on the
74     /// `std::sync::atomic` types via the `compare_exchange` method by passing
75     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
76     /// as both the `success` and `failure` parameters. For example,
77     /// [`AtomicBool::compare_exchange`][compare_exchange].
78     ///
79     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
80     pub fn atomic_cxchg<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
81     /// Stores a value if the current value is the same as the `old` value.
82     ///
83     /// The stabilized version of this intrinsic is available on the
84     /// `std::sync::atomic` types via the `compare_exchange` method by passing
85     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
86     /// as both the `success` and `failure` parameters. For example,
87     /// [`AtomicBool::compare_exchange`][compare_exchange].
88     ///
89     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
90     pub fn atomic_cxchg_acq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
91     /// Stores a value if the current value is the same as the `old` value.
92     ///
93     /// The stabilized version of this intrinsic is available on the
94     /// `std::sync::atomic` types via the `compare_exchange` method by passing
95     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
96     /// as the `success` and
97     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
98     /// as the `failure` parameters. For example,
99     /// [`AtomicBool::compare_exchange`][compare_exchange].
100     ///
101     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
102     pub fn atomic_cxchg_rel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
103     /// Stores a value if the current value is the same as the `old` value.
104     ///
105     /// The stabilized version of this intrinsic is available on the
106     /// `std::sync::atomic` types via the `compare_exchange` method by passing
107     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
108     /// as the `success` and
109     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
110     /// as the `failure` parameters. For example,
111     /// [`AtomicBool::compare_exchange`][compare_exchange].
112     ///
113     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
114     pub fn atomic_cxchg_acqrel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
115     /// Stores a value if the current value is the same as the `old` value.
116     ///
117     /// The stabilized version of this intrinsic is available on the
118     /// `std::sync::atomic` types via the `compare_exchange` method by passing
119     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
120     /// as both the `success` and `failure` parameters. For example,
121     /// [`AtomicBool::compare_exchange`][compare_exchange].
122     ///
123     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
124     pub fn atomic_cxchg_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
125     /// Stores a value if the current value is the same as the `old` value.
126     ///
127     /// The stabilized version of this intrinsic is available on the
128     /// `std::sync::atomic` types via the `compare_exchange` method by passing
129     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
130     /// as the `success` and
131     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
132     /// as the `failure` parameters. For example,
133     /// [`AtomicBool::compare_exchange`][compare_exchange].
134     ///
135     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
136     pub fn atomic_cxchg_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
137     /// Stores a value if the current value is the same as the `old` value.
138     ///
139     /// The stabilized version of this intrinsic is available on the
140     /// `std::sync::atomic` types via the `compare_exchange` method by passing
141     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
142     /// as the `success` and
143     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
144     /// as the `failure` parameters. For example,
145     /// [`AtomicBool::compare_exchange`][compare_exchange].
146     ///
147     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
148     pub fn atomic_cxchg_failacq<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     ///
151     /// The stabilized version of this intrinsic is available on the
152     /// `std::sync::atomic` types via the `compare_exchange` method by passing
153     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
154     /// as the `success` and
155     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
156     /// as the `failure` parameters. For example,
157     /// [`AtomicBool::compare_exchange`][compare_exchange].
158     ///
159     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
160     pub fn atomic_cxchg_acq_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
161     /// Stores a value if the current value is the same as the `old` value.
162     ///
163     /// The stabilized version of this intrinsic is available on the
164     /// `std::sync::atomic` types via the `compare_exchange` method by passing
165     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
166     /// as the `success` and
167     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
168     /// as the `failure` parameters. For example,
169     /// [`AtomicBool::compare_exchange`][compare_exchange].
170     ///
171     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
172     pub fn atomic_cxchg_acqrel_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
173
174     /// Stores a value if the current value is the same as the `old` value.
175     ///
176     /// The stabilized version of this intrinsic is available on the
177     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
178     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
179     /// as both the `success` and `failure` parameters. For example,
180     /// [`AtomicBool::compare_exchange_weak`][cew].
181     ///
182     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
183     pub fn atomic_cxchgweak<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
184     /// Stores a value if the current value is the same as the `old` value.
185     ///
186     /// The stabilized version of this intrinsic is available on the
187     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
188     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
189     /// as both the `success` and `failure` parameters. For example,
190     /// [`AtomicBool::compare_exchange_weak`][cew].
191     ///
192     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
193     pub fn atomic_cxchgweak_acq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
194     /// Stores a value if the current value is the same as the `old` value.
195     ///
196     /// The stabilized version of this intrinsic is available on the
197     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
198     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
199     /// as the `success` and
200     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
201     /// as the `failure` parameters. For example,
202     /// [`AtomicBool::compare_exchange_weak`][cew].
203     ///
204     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
205     pub fn atomic_cxchgweak_rel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
206     /// Stores a value if the current value is the same as the `old` value.
207     ///
208     /// The stabilized version of this intrinsic is available on the
209     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
210     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
211     /// as the `success` and
212     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
213     /// as the `failure` parameters. For example,
214     /// [`AtomicBool::compare_exchange_weak`][cew].
215     ///
216     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
217     pub fn atomic_cxchgweak_acqrel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
218     /// Stores a value if the current value is the same as the `old` value.
219     ///
220     /// The stabilized version of this intrinsic is available on the
221     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
222     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
223     /// as both the `success` and `failure` parameters. For example,
224     /// [`AtomicBool::compare_exchange_weak`][cew].
225     ///
226     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
227     pub fn atomic_cxchgweak_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
228     /// Stores a value if the current value is the same as the `old` value.
229     ///
230     /// The stabilized version of this intrinsic is available on the
231     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
232     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
233     /// as the `success` and
234     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
235     /// as the `failure` parameters. For example,
236     /// [`AtomicBool::compare_exchange_weak`][cew].
237     ///
238     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
239     pub fn atomic_cxchgweak_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
240     /// Stores a value if the current value is the same as the `old` value.
241     ///
242     /// The stabilized version of this intrinsic is available on the
243     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
244     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
245     /// as the `success` and
246     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
247     /// as the `failure` parameters. For example,
248     /// [`AtomicBool::compare_exchange_weak`][cew].
249     ///
250     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
251     pub fn atomic_cxchgweak_failacq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
252     /// Stores a value if the current value is the same as the `old` value.
253     ///
254     /// The stabilized version of this intrinsic is available on the
255     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
256     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
257     /// as the `success` and
258     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
259     /// as the `failure` parameters. For example,
260     /// [`AtomicBool::compare_exchange_weak`][cew].
261     ///
262     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
263     pub fn atomic_cxchgweak_acq_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
264     /// Stores a value if the current value is the same as the `old` value.
265     ///
266     /// The stabilized version of this intrinsic is available on the
267     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
268     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
269     /// as the `success` and
270     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
271     /// as the `failure` parameters. For example,
272     /// [`AtomicBool::compare_exchange_weak`][cew].
273     ///
274     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
275     pub fn atomic_cxchgweak_acqrel_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
276
277     /// Loads the current value of the pointer.
278     ///
279     /// The stabilized version of this intrinsic is available on the
280     /// `std::sync::atomic` types via the `load` method by passing
281     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
282     /// as the `order`. For example,
283     /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
284     pub fn atomic_load<T: Copy>(src: *const T) -> T;
285     /// Loads the current value of the pointer.
286     ///
287     /// The stabilized version of this intrinsic is available on the
288     /// `std::sync::atomic` types via the `load` method by passing
289     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
290     /// as the `order`. For example,
291     /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
292     pub fn atomic_load_acq<T: Copy>(src: *const T) -> T;
293     /// Loads the current value of the pointer.
294     ///
295     /// The stabilized version of this intrinsic is available on the
296     /// `std::sync::atomic` types via the `load` method by passing
297     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
298     /// as the `order`. For example,
299     /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
300     pub fn atomic_load_relaxed<T: Copy>(src: *const T) -> T;
301     pub fn atomic_load_unordered<T: Copy>(src: *const T) -> T;
302
303     /// Stores the value at the specified memory location.
304     ///
305     /// The stabilized version of this intrinsic is available on the
306     /// `std::sync::atomic` types via the `store` method by passing
307     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
308     /// as the `order`. For example,
309     /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
310     pub fn atomic_store<T: Copy>(dst: *mut T, val: T);
311     /// Stores the value at the specified memory location.
312     ///
313     /// The stabilized version of this intrinsic is available on the
314     /// `std::sync::atomic` types via the `store` method by passing
315     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
316     /// as the `order`. For example,
317     /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
318     pub fn atomic_store_rel<T: Copy>(dst: *mut T, val: T);
319     /// Stores the value at the specified memory location.
320     ///
321     /// The stabilized version of this intrinsic is available on the
322     /// `std::sync::atomic` types via the `store` method by passing
323     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
324     /// as the `order`. For example,
325     /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
326     pub fn atomic_store_relaxed<T: Copy>(dst: *mut T, val: T);
327     pub fn atomic_store_unordered<T: Copy>(dst: *mut T, val: T);
328
329     /// Stores the value at the specified memory location, returning the old value.
330     ///
331     /// The stabilized version of this intrinsic is available on the
332     /// `std::sync::atomic` types via the `swap` method by passing
333     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
334     /// as the `order`. For example,
335     /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
336     pub fn atomic_xchg<T: Copy>(dst: *mut T, src: T) -> T;
337     /// Stores the value at the specified memory location, returning the old value.
338     ///
339     /// The stabilized version of this intrinsic is available on the
340     /// `std::sync::atomic` types via the `swap` method by passing
341     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
342     /// as the `order`. For example,
343     /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
344     pub fn atomic_xchg_acq<T: Copy>(dst: *mut T, src: T) -> T;
345     /// Stores the value at the specified memory location, returning the old value.
346     ///
347     /// The stabilized version of this intrinsic is available on the
348     /// `std::sync::atomic` types via the `swap` method by passing
349     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
350     /// as the `order`. For example,
351     /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
352     pub fn atomic_xchg_rel<T: Copy>(dst: *mut T, src: T) -> T;
353     /// Stores the value at the specified memory location, returning the old value.
354     ///
355     /// The stabilized version of this intrinsic is available on the
356     /// `std::sync::atomic` types via the `swap` method by passing
357     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
358     /// as the `order`. For example,
359     /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
360     pub fn atomic_xchg_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
361     /// Stores the value at the specified memory location, returning the old value.
362     ///
363     /// The stabilized version of this intrinsic is available on the
364     /// `std::sync::atomic` types via the `swap` method by passing
365     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
366     /// as the `order`. For example,
367     /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
368     pub fn atomic_xchg_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
369
370     /// Adds to the current value, returning the previous value.
371     ///
372     /// The stabilized version of this intrinsic is available on the
373     /// `std::sync::atomic` types via the `fetch_add` method by passing
374     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
375     /// as the `order`. For example,
376     /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
377     pub fn atomic_xadd<T: Copy>(dst: *mut T, src: T) -> T;
378     /// Adds to the current value, returning the previous value.
379     ///
380     /// The stabilized version of this intrinsic is available on the
381     /// `std::sync::atomic` types via the `fetch_add` method by passing
382     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
383     /// as the `order`. For example,
384     /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
385     pub fn atomic_xadd_acq<T: Copy>(dst: *mut T, src: T) -> T;
386     /// Adds to the current value, returning the previous value.
387     ///
388     /// The stabilized version of this intrinsic is available on the
389     /// `std::sync::atomic` types via the `fetch_add` method by passing
390     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
391     /// as the `order`. For example,
392     /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
393     pub fn atomic_xadd_rel<T: Copy>(dst: *mut T, src: T) -> T;
394     /// Adds to the current value, returning the previous value.
395     ///
396     /// The stabilized version of this intrinsic is available on the
397     /// `std::sync::atomic` types via the `fetch_add` method by passing
398     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
399     /// as the `order`. For example,
400     /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
401     pub fn atomic_xadd_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
402     /// Adds to the current value, returning the previous value.
403     ///
404     /// The stabilized version of this intrinsic is available on the
405     /// `std::sync::atomic` types via the `fetch_add` method by passing
406     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
407     /// as the `order`. For example,
408     /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
409     pub fn atomic_xadd_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
410
411     /// Subtract from the current value, returning the previous value.
412     ///
413     /// The stabilized version of this intrinsic is available on the
414     /// `std::sync::atomic` types via the `fetch_sub` method by passing
415     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
416     /// as the `order`. For example,
417     /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
418     pub fn atomic_xsub<T: Copy>(dst: *mut T, src: T) -> T;
419     /// Subtract from the current value, returning the previous value.
420     ///
421     /// The stabilized version of this intrinsic is available on the
422     /// `std::sync::atomic` types via the `fetch_sub` method by passing
423     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
424     /// as the `order`. For example,
425     /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
426     pub fn atomic_xsub_acq<T: Copy>(dst: *mut T, src: T) -> T;
427     /// Subtract from the current value, returning the previous value.
428     ///
429     /// The stabilized version of this intrinsic is available on the
430     /// `std::sync::atomic` types via the `fetch_sub` method by passing
431     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
432     /// as the `order`. For example,
433     /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
434     pub fn atomic_xsub_rel<T: Copy>(dst: *mut T, src: T) -> T;
435     /// Subtract from the current value, returning the previous value.
436     ///
437     /// The stabilized version of this intrinsic is available on the
438     /// `std::sync::atomic` types via the `fetch_sub` method by passing
439     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
440     /// as the `order`. For example,
441     /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
442     pub fn atomic_xsub_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
443     /// Subtract from the current value, returning the previous value.
444     ///
445     /// The stabilized version of this intrinsic is available on the
446     /// `std::sync::atomic` types via the `fetch_sub` method by passing
447     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
448     /// as the `order`. For example,
449     /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
450     pub fn atomic_xsub_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
451
452     /// Bitwise and with the current value, returning the previous value.
453     ///
454     /// The stabilized version of this intrinsic is available on the
455     /// `std::sync::atomic` types via the `fetch_and` method by passing
456     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
457     /// as the `order`. For example,
458     /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
459     pub fn atomic_and<T: Copy>(dst: *mut T, src: T) -> T;
460     /// Bitwise and with the current value, returning the previous value.
461     ///
462     /// The stabilized version of this intrinsic is available on the
463     /// `std::sync::atomic` types via the `fetch_and` method by passing
464     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
465     /// as the `order`. For example,
466     /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
467     pub fn atomic_and_acq<T: Copy>(dst: *mut T, src: T) -> T;
468     /// Bitwise and with the current value, returning the previous value.
469     ///
470     /// The stabilized version of this intrinsic is available on the
471     /// `std::sync::atomic` types via the `fetch_and` method by passing
472     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
473     /// as the `order`. For example,
474     /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
475     pub fn atomic_and_rel<T: Copy>(dst: *mut T, src: T) -> T;
476     /// Bitwise and with the current value, returning the previous value.
477     ///
478     /// The stabilized version of this intrinsic is available on the
479     /// `std::sync::atomic` types via the `fetch_and` method by passing
480     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
481     /// as the `order`. For example,
482     /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
483     pub fn atomic_and_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
484     /// Bitwise and with the current value, returning the previous value.
485     ///
486     /// The stabilized version of this intrinsic is available on the
487     /// `std::sync::atomic` types via the `fetch_and` method by passing
488     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
489     /// as the `order`. For example,
490     /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
491     pub fn atomic_and_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
492
493     /// Bitwise nand with the current value, returning the previous value.
494     ///
495     /// The stabilized version of this intrinsic is available on the
496     /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
497     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
498     /// as the `order`. For example,
499     /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
500     pub fn atomic_nand<T: Copy>(dst: *mut T, src: T) -> T;
501     /// Bitwise nand with the current value, returning the previous value.
502     ///
503     /// The stabilized version of this intrinsic is available on the
504     /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
505     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
506     /// as the `order`. For example,
507     /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
508     pub fn atomic_nand_acq<T: Copy>(dst: *mut T, src: T) -> T;
509     /// Bitwise nand with the current value, returning the previous value.
510     ///
511     /// The stabilized version of this intrinsic is available on the
512     /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
513     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
514     /// as the `order`. For example,
515     /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
516     pub fn atomic_nand_rel<T: Copy>(dst: *mut T, src: T) -> T;
517     /// Bitwise nand with the current value, returning the previous value.
518     ///
519     /// The stabilized version of this intrinsic is available on the
520     /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
521     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
522     /// as the `order`. For example,
523     /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
524     pub fn atomic_nand_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
525     /// Bitwise nand with the current value, returning the previous value.
526     ///
527     /// The stabilized version of this intrinsic is available on the
528     /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
529     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
530     /// as the `order`. For example,
531     /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
532     pub fn atomic_nand_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
533
534     /// Bitwise or with the current value, returning the previous value.
535     ///
536     /// The stabilized version of this intrinsic is available on the
537     /// `std::sync::atomic` types via the `fetch_or` method by passing
538     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
539     /// as the `order`. For example,
540     /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
541     pub fn atomic_or<T: Copy>(dst: *mut T, src: T) -> T;
542     /// Bitwise or with the current value, returning the previous value.
543     ///
544     /// The stabilized version of this intrinsic is available on the
545     /// `std::sync::atomic` types via the `fetch_or` method by passing
546     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
547     /// as the `order`. For example,
548     /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
549     pub fn atomic_or_acq<T: Copy>(dst: *mut T, src: T) -> T;
550     /// Bitwise or with the current value, returning the previous value.
551     ///
552     /// The stabilized version of this intrinsic is available on the
553     /// `std::sync::atomic` types via the `fetch_or` method by passing
554     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
555     /// as the `order`. For example,
556     /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
557     pub fn atomic_or_rel<T: Copy>(dst: *mut T, src: T) -> T;
558     /// Bitwise or with the current value, returning the previous value.
559     ///
560     /// The stabilized version of this intrinsic is available on the
561     /// `std::sync::atomic` types via the `fetch_or` method by passing
562     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
563     /// as the `order`. For example,
564     /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
565     pub fn atomic_or_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
566     /// Bitwise or with the current value, returning the previous value.
567     ///
568     /// The stabilized version of this intrinsic is available on the
569     /// `std::sync::atomic` types via the `fetch_or` method by passing
570     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
571     /// as the `order`. For example,
572     /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
573     pub fn atomic_or_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
574
575     /// Bitwise xor with the current value, returning the previous value.
576     ///
577     /// The stabilized version of this intrinsic is available on the
578     /// `std::sync::atomic` types via the `fetch_xor` method by passing
579     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
580     /// as the `order`. For example,
581     /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
582     pub fn atomic_xor<T: Copy>(dst: *mut T, src: T) -> T;
583     /// Bitwise xor with the current value, returning the previous value.
584     ///
585     /// The stabilized version of this intrinsic is available on the
586     /// `std::sync::atomic` types via the `fetch_xor` method by passing
587     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
588     /// as the `order`. For example,
589     /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
590     pub fn atomic_xor_acq<T: Copy>(dst: *mut T, src: T) -> T;
591     /// Bitwise xor with the current value, returning the previous value.
592     ///
593     /// The stabilized version of this intrinsic is available on the
594     /// `std::sync::atomic` types via the `fetch_xor` method by passing
595     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
596     /// as the `order`. For example,
597     /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
598     pub fn atomic_xor_rel<T: Copy>(dst: *mut T, src: T) -> T;
599     /// Bitwise xor with the current value, returning the previous value.
600     ///
601     /// The stabilized version of this intrinsic is available on the
602     /// `std::sync::atomic` types via the `fetch_xor` method by passing
603     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
604     /// as the `order`. For example,
605     /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
606     pub fn atomic_xor_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
607     /// Bitwise xor with the current value, returning the previous value.
608     ///
609     /// The stabilized version of this intrinsic is available on the
610     /// `std::sync::atomic` types via the `fetch_xor` method by passing
611     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
612     /// as the `order`. For example,
613     /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
614     pub fn atomic_xor_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
615
616     /// Maximum with the current value using a signed comparison.
617     ///
618     /// The stabilized version of this intrinsic is available on the
619     /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
620     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
621     /// as the `order`. For example,
622     /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
623     pub fn atomic_max<T: Copy>(dst: *mut T, src: T) -> T;
624     /// Maximum with the current value using a signed comparison.
625     ///
626     /// The stabilized version of this intrinsic is available on the
627     /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
628     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
629     /// as the `order`. For example,
630     /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
631     pub fn atomic_max_acq<T: Copy>(dst: *mut T, src: T) -> T;
632     /// Maximum with the current value using a signed comparison.
633     ///
634     /// The stabilized version of this intrinsic is available on the
635     /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
636     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
637     /// as the `order`. For example,
638     /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
639     pub fn atomic_max_rel<T: Copy>(dst: *mut T, src: T) -> T;
640     /// Maximum with the current value using a signed comparison.
641     ///
642     /// The stabilized version of this intrinsic is available on the
643     /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
644     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
645     /// as the `order`. For example,
646     /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
647     pub fn atomic_max_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
648     /// Maximum with the current value.
649     ///
650     /// The stabilized version of this intrinsic is available on the
651     /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
652     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
653     /// as the `order`. For example,
654     /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
655     pub fn atomic_max_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
656
657     /// Minimum with the current value using a signed comparison.
658     ///
659     /// The stabilized version of this intrinsic is available on the
660     /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
661     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
662     /// as the `order`. For example,
663     /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
664     pub fn atomic_min<T: Copy>(dst: *mut T, src: T) -> T;
665     /// Minimum with the current value using a signed comparison.
666     ///
667     /// The stabilized version of this intrinsic is available on the
668     /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
669     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
670     /// as the `order`. For example,
671     /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
672     pub fn atomic_min_acq<T: Copy>(dst: *mut T, src: T) -> T;
673     /// Minimum with the current value using a signed comparison.
674     ///
675     /// The stabilized version of this intrinsic is available on the
676     /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
677     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
678     /// as the `order`. For example,
679     /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
680     pub fn atomic_min_rel<T: Copy>(dst: *mut T, src: T) -> T;
681     /// Minimum with the current value using a signed comparison.
682     ///
683     /// The stabilized version of this intrinsic is available on the
684     /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
685     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
686     /// as the `order`. For example,
687     /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
688     pub fn atomic_min_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
689     /// Minimum with the current value using a signed comparison.
690     ///
691     /// The stabilized version of this intrinsic is available on the
692     /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
693     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
694     /// as the `order`. For example,
695     /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
696     pub fn atomic_min_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
697
698     /// Minimum with the current value using an unsigned comparison.
699     ///
700     /// The stabilized version of this intrinsic is available on the
701     /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
702     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
703     /// as the `order`. For example,
704     /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
705     pub fn atomic_umin<T: Copy>(dst: *mut T, src: T) -> T;
706     /// Minimum with the current value using an unsigned comparison.
707     ///
708     /// The stabilized version of this intrinsic is available on the
709     /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
710     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
711     /// as the `order`. For example,
712     /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
713     pub fn atomic_umin_acq<T: Copy>(dst: *mut T, src: T) -> T;
714     /// Minimum with the current value using an unsigned comparison.
715     ///
716     /// The stabilized version of this intrinsic is available on the
717     /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
718     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
719     /// as the `order`. For example,
720     /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
721     pub fn atomic_umin_rel<T: Copy>(dst: *mut T, src: T) -> T;
722     /// Minimum with the current value using an unsigned comparison.
723     ///
724     /// The stabilized version of this intrinsic is available on the
725     /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
726     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
727     /// as the `order`. For example,
728     /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
729     pub fn atomic_umin_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
730     /// Minimum with the current value using an unsigned comparison.
731     ///
732     /// The stabilized version of this intrinsic is available on the
733     /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
734     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
735     /// as the `order`. For example,
736     /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
737     pub fn atomic_umin_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
738
739     /// Maximum with the current value using an unsigned comparison.
740     ///
741     /// The stabilized version of this intrinsic is available on the
742     /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
743     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
744     /// as the `order`. For example,
745     /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
746     pub fn atomic_umax<T: Copy>(dst: *mut T, src: T) -> T;
747     /// Maximum with the current value using an unsigned comparison.
748     ///
749     /// The stabilized version of this intrinsic is available on the
750     /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
751     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
752     /// as the `order`. For example,
753     /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
754     pub fn atomic_umax_acq<T: Copy>(dst: *mut T, src: T) -> T;
755     /// Maximum with the current value using an unsigned comparison.
756     ///
757     /// The stabilized version of this intrinsic is available on the
758     /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
759     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
760     /// as the `order`. For example,
761     /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
762     pub fn atomic_umax_rel<T: Copy>(dst: *mut T, src: T) -> T;
763     /// Maximum with the current value using an unsigned comparison.
764     ///
765     /// The stabilized version of this intrinsic is available on the
766     /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
767     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
768     /// as the `order`. For example,
769     /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
770     pub fn atomic_umax_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
771     /// Maximum with the current value using an unsigned comparison.
772     ///
773     /// The stabilized version of this intrinsic is available on the
774     /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
775     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
776     /// as the `order`. For example,
777     /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
778     pub fn atomic_umax_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
779
780     /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
781     /// if supported; otherwise, it is a no-op.
782     /// Prefetches have no effect on the behavior of the program but can change its performance
783     /// characteristics.
784     ///
785     /// The `locality` argument must be a constant integer and is a temporal locality specifier
786     /// ranging from (0) - no locality, to (3) - extremely local keep in cache.
787     ///
788     /// This intrinsic does not have a stable counterpart.
789     pub fn prefetch_read_data<T>(data: *const T, locality: i32);
790     /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
791     /// if supported; otherwise, it is a no-op.
792     /// Prefetches have no effect on the behavior of the program but can change its performance
793     /// characteristics.
794     ///
795     /// The `locality` argument must be a constant integer and is a temporal locality specifier
796     /// ranging from (0) - no locality, to (3) - extremely local keep in cache.
797     ///
798     /// This intrinsic does not have a stable counterpart.
799     pub fn prefetch_write_data<T>(data: *const T, locality: i32);
800     /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
801     /// if supported; otherwise, it is a no-op.
802     /// Prefetches have no effect on the behavior of the program but can change its performance
803     /// characteristics.
804     ///
805     /// The `locality` argument must be a constant integer and is a temporal locality specifier
806     /// ranging from (0) - no locality, to (3) - extremely local keep in cache.
807     ///
808     /// This intrinsic does not have a stable counterpart.
809     pub fn prefetch_read_instruction<T>(data: *const T, locality: i32);
810     /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
811     /// if supported; otherwise, it is a no-op.
812     /// Prefetches have no effect on the behavior of the program but can change its performance
813     /// characteristics.
814     ///
815     /// The `locality` argument must be a constant integer and is a temporal locality specifier
816     /// ranging from (0) - no locality, to (3) - extremely local keep in cache.
817     ///
818     /// This intrinsic does not have a stable counterpart.
819     pub fn prefetch_write_instruction<T>(data: *const T, locality: i32);
820 }
821
822 extern "rust-intrinsic" {
823     /// An atomic fence.
824     ///
825     /// The stabilized version of this intrinsic is available in
826     /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
827     /// by passing
828     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
829     /// as the `order`.
830     pub fn atomic_fence();
831     /// An atomic fence.
832     ///
833     /// The stabilized version of this intrinsic is available in
834     /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
835     /// by passing
836     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
837     /// as the `order`.
838     pub fn atomic_fence_acq();
839     /// An atomic fence.
840     ///
841     /// The stabilized version of this intrinsic is available in
842     /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
843     /// by passing
844     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
845     /// as the `order`.
846     pub fn atomic_fence_rel();
847     /// An atomic fence.
848     ///
849     /// The stabilized version of this intrinsic is available in
850     /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
851     /// by passing
852     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
853     /// as the `order`.
854     pub fn atomic_fence_acqrel();
855
856     /// A compiler-only memory barrier.
857     ///
858     /// Memory accesses will never be reordered across this barrier by the
859     /// compiler, but no instructions will be emitted for it. This is
860     /// appropriate for operations on the same thread that may be preempted,
861     /// such as when interacting with signal handlers.
862     ///
863     /// The stabilized version of this intrinsic is available in
864     /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
865     /// by passing
866     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
867     /// as the `order`.
868     pub fn atomic_singlethreadfence();
869     /// A compiler-only memory barrier.
870     ///
871     /// Memory accesses will never be reordered across this barrier by the
872     /// compiler, but no instructions will be emitted for it. This is
873     /// appropriate for operations on the same thread that may be preempted,
874     /// such as when interacting with signal handlers.
875     ///
876     /// The stabilized version of this intrinsic is available in
877     /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
878     /// by passing
879     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
880     /// as the `order`.
881     pub fn atomic_singlethreadfence_acq();
882     /// A compiler-only memory barrier.
883     ///
884     /// Memory accesses will never be reordered across this barrier by the
885     /// compiler, but no instructions will be emitted for it. This is
886     /// appropriate for operations on the same thread that may be preempted,
887     /// such as when interacting with signal handlers.
888     ///
889     /// The stabilized version of this intrinsic is available in
890     /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
891     /// by passing
892     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
893     /// as the `order`.
894     pub fn atomic_singlethreadfence_rel();
895     /// A compiler-only memory barrier.
896     ///
897     /// Memory accesses will never be reordered across this barrier by the
898     /// compiler, but no instructions will be emitted for it. This is
899     /// appropriate for operations on the same thread that may be preempted,
900     /// such as when interacting with signal handlers.
901     ///
902     /// The stabilized version of this intrinsic is available in
903     /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
904     /// by passing
905     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
906     /// as the `order`.
907     pub fn atomic_singlethreadfence_acqrel();
908
909     /// Magic intrinsic that derives its meaning from attributes
910     /// attached to the function.
911     ///
912     /// For example, dataflow uses this to inject static assertions so
913     /// that `rustc_peek(potentially_uninitialized)` would actually
914     /// double-check that dataflow did indeed compute that it is
915     /// uninitialized at that point in the control flow.
916     ///
917     /// This intrinsic should not be used outside of the compiler.
918     pub fn rustc_peek<T>(_: T) -> T;
919
920     /// Aborts the execution of the process.
921     ///
922     /// A more user-friendly and stable version of this operation is
923     /// [`std::process::abort`](../../std/process/fn.abort.html).
924     pub fn abort() -> !;
925
926     /// Tells LLVM that this point in the code is not reachable, enabling
927     /// further optimizations.
928     ///
929     /// N.B., this is very different from the `unreachable!()` macro: Unlike the
930     /// macro, which panics when it is executed, it is *undefined behavior* to
931     /// reach code marked with this function.
932     ///
933     /// The stabilized version of this intrinsic is
934     /// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html).
935     pub fn unreachable() -> !;
936
937     /// Informs the optimizer that a condition is always true.
938     /// If the condition is false, the behavior is undefined.
939     ///
940     /// No code is generated for this intrinsic, but the optimizer will try
941     /// to preserve it (and its condition) between passes, which may interfere
942     /// with optimization of surrounding code and reduce performance. It should
943     /// not be used if the invariant can be discovered by the optimizer on its
944     /// own, or if it does not enable any significant optimizations.
945     ///
946     /// This intrinsic does not have a stable counterpart.
947     pub fn assume(b: bool);
948
949     /// Hints to the compiler that branch condition is likely to be true.
950     /// Returns the value passed to it.
951     ///
952     /// Any use other than with `if` statements will probably not have an effect.
953     ///
954     /// This intrinsic does not have a stable counterpart.
955     pub fn likely(b: bool) -> bool;
956
957     /// Hints to the compiler that branch condition is likely to be false.
958     /// Returns the value passed to it.
959     ///
960     /// Any use other than with `if` statements will probably not have an effect.
961     ///
962     /// This intrinsic does not have a stable counterpart.
963     pub fn unlikely(b: bool) -> bool;
964
965     /// Executes a breakpoint trap, for inspection by a debugger.
966     ///
967     /// This intrinsic does not have a stable counterpart.
968     pub fn breakpoint();
969
970     /// The size of a type in bytes.
971     ///
972     /// More specifically, this is the offset in bytes between successive
973     /// items of the same type, including alignment padding.
974     ///
975     /// The stabilized version of this intrinsic is
976     /// [`std::mem::size_of`](../../std/mem/fn.size_of.html).
977     #[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
978     pub fn size_of<T>() -> usize;
979
980     /// Moves a value to an uninitialized memory location.
981     ///
982     /// Drop glue is not run on the destination.
983     ///
984     /// The stabilized version of this intrinsic is
985     /// [`std::ptr::write`](../../std/ptr/fn.write.html).
986     pub fn move_val_init<T>(dst: *mut T, src: T);
987
988     /// The minimum alignment of a type.
989     ///
990     /// The stabilized version of this intrinsic is
991     /// [`std::mem::align_of`](../../std/mem/fn.align_of.html).
992     #[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
993     pub fn min_align_of<T>() -> usize;
994     /// The prefered alignment of a type.
995     ///
996     /// This intrinsic does not have a stable counterpart.
997     #[rustc_const_unstable(feature = "const_pref_align_of", issue = "none")]
998     pub fn pref_align_of<T>() -> usize;
999
1000     /// The size of the referenced value in bytes.
1001     ///
1002     /// The stabilized version of this intrinsic is
1003     /// [`std::mem::size_of_val`](../../std/mem/fn.size_of_val.html).
1004     pub fn size_of_val<T: ?Sized>(_: *const T) -> usize;
1005     /// The required alignment of the referenced value.
1006     ///
1007     /// The stabilized version of this intrinsic is
1008     /// [`std::mem::align_of_val`](../../std/mem/fn.align_of_val.html).
1009     pub fn min_align_of_val<T: ?Sized>(_: *const T) -> usize;
1010
1011     /// Gets a static string slice containing the name of a type.
1012     ///
1013     /// The stabilized version of this intrinsic is
1014     /// [`std::any::type_name`](../../std/any/fn.type_name.html)
1015     #[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
1016     pub fn type_name<T: ?Sized>() -> &'static str;
1017
1018     /// Gets an identifier which is globally unique to the specified type. This
1019     /// function will return the same value for a type regardless of whichever
1020     /// crate it is invoked in.
1021     ///
1022     /// The stabilized version of this intrinsic is
1023     /// [`std::any::TypeId::of`](../../std/any/struct.TypeId.html#method.of)
1024     #[rustc_const_unstable(feature = "const_type_id", issue = "41875")]
1025     pub fn type_id<T: ?Sized + 'static>() -> u64;
1026
1027     /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
1028     /// This will statically either panic, or do nothing.
1029     ///
1030     /// This intrinsic does not have a stable counterpart.
1031     pub fn assert_inhabited<T>();
1032
1033     /// A guard for unsafe functions that cannot ever be executed if `T` does not permit
1034     /// zero-initialization: This will statically either panic, or do nothing.
1035     ///
1036     /// This intrinsic does not have a stable counterpart.
1037     pub fn assert_zero_valid<T>();
1038
1039     /// A guard for unsafe functions that cannot ever be executed if `T` has invalid
1040     /// bit patterns: This will statically either panic, or do nothing.
1041     ///
1042     /// This intrinsic does not have a stable counterpart.
1043     pub fn assert_uninit_valid<T>();
1044
1045     /// Gets a reference to a static `Location` indicating where it was called.
1046     ///
1047     /// Consider using [`std::panic::Location::caller`](../../std/panic/struct.Location.html#method.caller)
1048     /// instead.
1049     #[rustc_const_unstable(feature = "const_caller_location", issue = "47809")]
1050     pub fn caller_location() -> &'static crate::panic::Location<'static>;
1051
1052     /// Moves a value out of scope without running drop glue.
1053     ///
1054     /// This exists solely for [`mem::forget_unsized`](../../std/mem/fn.forget_unsized.html);
1055     /// normal `forget` uses `ManuallyDrop` instead.
1056     pub fn forget<T: ?Sized>(_: T);
1057
1058     /// Reinterprets the bits of a value of one type as another type.
1059     ///
1060     /// Both types must have the same size. Neither the original, nor the result,
1061     /// may be an [invalid value](../../nomicon/what-unsafe-does.html).
1062     ///
1063     /// `transmute` is semantically equivalent to a bitwise move of one type
1064     /// into another. It copies the bits from the source value into the
1065     /// destination value, then forgets the original. It's equivalent to C's
1066     /// `memcpy` under the hood, just like `transmute_copy`.
1067     ///
1068     /// `transmute` is **incredibly** unsafe. There are a vast number of ways to
1069     /// cause [undefined behavior][ub] with this function. `transmute` should be
1070     /// the absolute last resort.
1071     ///
1072     /// The [nomicon](../../nomicon/transmutes.html) has additional
1073     /// documentation.
1074     ///
1075     /// [ub]: ../../reference/behavior-considered-undefined.html
1076     ///
1077     /// # Examples
1078     ///
1079     /// There are a few things that `transmute` is really useful for.
1080     ///
1081     /// Turning a pointer into a function pointer. This is *not* portable to
1082     /// machines where function pointers and data pointers have different sizes.
1083     ///
1084     /// ```
1085     /// fn foo() -> i32 {
1086     ///     0
1087     /// }
1088     /// let pointer = foo as *const ();
1089     /// let function = unsafe {
1090     ///     std::mem::transmute::<*const (), fn() -> i32>(pointer)
1091     /// };
1092     /// assert_eq!(function(), 0);
1093     /// ```
1094     ///
1095     /// Extending a lifetime, or shortening an invariant lifetime. This is
1096     /// advanced, very unsafe Rust!
1097     ///
1098     /// ```
1099     /// struct R<'a>(&'a i32);
1100     /// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
1101     ///     std::mem::transmute::<R<'b>, R<'static>>(r)
1102     /// }
1103     ///
1104     /// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
1105     ///                                              -> &'b mut R<'c> {
1106     ///     std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
1107     /// }
1108     /// ```
1109     ///
1110     /// # Alternatives
1111     ///
1112     /// Don't despair: many uses of `transmute` can be achieved through other means.
1113     /// Below are common applications of `transmute` which can be replaced with safer
1114     /// constructs.
1115     ///
1116     /// Turning raw bytes(`&[u8]`) to `u32`, `f64`, etc.:
1117     ///
1118     /// ```
1119     /// let raw_bytes = [0x78, 0x56, 0x34, 0x12];
1120     ///
1121     /// let num = unsafe {
1122     ///     std::mem::transmute::<[u8; 4], u32>(raw_bytes);
1123     /// };
1124     ///
1125     /// // use `u32::from_ne_bytes` instead
1126     /// let num = u32::from_ne_bytes(raw_bytes);
1127     /// // or use `u32::from_le_bytes` or `u32::from_ge_bytes` to specify the endianness
1128     /// let num = u32::from_le_bytes(raw_bytes);
1129     /// assert_eq!(num, 0x12345678);
1130     /// let num = u32::from_be_bytes(raw_bytes);
1131     /// assert_eq!(num, 0x78563412);
1132     /// ```
1133     ///
1134     /// Turning a pointer into a `usize`:
1135     ///
1136     /// ```
1137     /// let ptr = &0;
1138     /// let ptr_num_transmute = unsafe {
1139     ///     std::mem::transmute::<&i32, usize>(ptr)
1140     /// };
1141     ///
1142     /// // Use an `as` cast instead
1143     /// let ptr_num_cast = ptr as *const i32 as usize;
1144     /// ```
1145     ///
1146     /// Turning a `*mut T` into an `&mut T`:
1147     ///
1148     /// ```
1149     /// let ptr: *mut i32 = &mut 0;
1150     /// let ref_transmuted = unsafe {
1151     ///     std::mem::transmute::<*mut i32, &mut i32>(ptr)
1152     /// };
1153     ///
1154     /// // Use a reborrow instead
1155     /// let ref_casted = unsafe { &mut *ptr };
1156     /// ```
1157     ///
1158     /// Turning an `&mut T` into an `&mut U`:
1159     ///
1160     /// ```
1161     /// let ptr = &mut 0;
1162     /// let val_transmuted = unsafe {
1163     ///     std::mem::transmute::<&mut i32, &mut u32>(ptr)
1164     /// };
1165     ///
1166     /// // Now, put together `as` and reborrowing - note the chaining of `as`
1167     /// // `as` is not transitive
1168     /// let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) };
1169     /// ```
1170     ///
1171     /// Turning an `&str` into an `&[u8]`:
1172     ///
1173     /// ```
1174     /// // this is not a good way to do this.
1175     /// let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") };
1176     /// assert_eq!(slice, &[82, 117, 115, 116]);
1177     ///
1178     /// // You could use `str::as_bytes`
1179     /// let slice = "Rust".as_bytes();
1180     /// assert_eq!(slice, &[82, 117, 115, 116]);
1181     ///
1182     /// // Or, just use a byte string, if you have control over the string
1183     /// // literal
1184     /// assert_eq!(b"Rust", &[82, 117, 115, 116]);
1185     /// ```
1186     ///
1187     /// Turning a `Vec<&T>` into a `Vec<Option<&T>>`:
1188     ///
1189     /// ```
1190     /// let store = [0, 1, 2, 3];
1191     /// let v_orig = store.iter().collect::<Vec<&i32>>();
1192     ///
1193     /// // clone the vector as we will reuse them later
1194     /// let v_clone = v_orig.clone();
1195     ///
1196     /// // Using transmute: this relies on the unspecified data layout of `Vec`, which is a
1197     /// // bad idea and could cause Undefined Behavior.
1198     /// // However, it is no-copy.
1199     /// let v_transmuted = unsafe {
1200     ///     std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone)
1201     /// };
1202     ///
1203     /// let v_clone = v_orig.clone();
1204     ///
1205     /// // This is the suggested, safe way.
1206     /// // It does copy the entire vector, though, into a new array.
1207     /// let v_collected = v_clone.into_iter()
1208     ///                          .map(Some)
1209     ///                          .collect::<Vec<Option<&i32>>>();
1210     ///
1211     /// let v_clone = v_orig.clone();
1212     ///
1213     /// // The no-copy, unsafe way, still using transmute, but not relying on the data layout.
1214     /// // Like the first approach, this reuses the `Vec` internals.
1215     /// // Therefore, the new inner type must have the
1216     /// // exact same size, *and the same alignment*, as the old type.
1217     /// // The same caveats exist for this method as transmute, for
1218     /// // the original inner type (`&i32`) to the converted inner type
1219     /// // (`Option<&i32>`), so read the nomicon pages linked above and also
1220     /// // consult the [`from_raw_parts`] documentation.
1221     /// let v_from_raw = unsafe {
1222     // FIXME Update this when vec_into_raw_parts is stabilized
1223     ///     // Ensure the original vector is not dropped.
1224     ///     let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
1225     ///     Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
1226     ///                         v_clone.len(),
1227     ///                         v_clone.capacity())
1228     /// };
1229     /// ```
1230     ///
1231     /// [`from_raw_parts`]: ../../std/vec/struct.Vec.html#method.from_raw_parts
1232     ///
1233     /// Implementing `split_at_mut`:
1234     ///
1235     /// ```
1236     /// use std::{slice, mem};
1237     ///
1238     /// // There are multiple ways to do this, and there are multiple problems
1239     /// // with the following (transmute) way.
1240     /// fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize)
1241     ///                              -> (&mut [T], &mut [T]) {
1242     ///     let len = slice.len();
1243     ///     assert!(mid <= len);
1244     ///     unsafe {
1245     ///         let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
1246     ///         // first: transmute is not typesafe; all it checks is that T and
1247     ///         // U are of the same size. Second, right here, you have two
1248     ///         // mutable references pointing to the same memory.
1249     ///         (&mut slice[0..mid], &mut slice2[mid..len])
1250     ///     }
1251     /// }
1252     ///
1253     /// // This gets rid of the typesafety problems; `&mut *` will *only* give
1254     /// // you an `&mut T` from an `&mut T` or `*mut T`.
1255     /// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
1256     ///                          -> (&mut [T], &mut [T]) {
1257     ///     let len = slice.len();
1258     ///     assert!(mid <= len);
1259     ///     unsafe {
1260     ///         let slice2 = &mut *(slice as *mut [T]);
1261     ///         // however, you still have two mutable references pointing to
1262     ///         // the same memory.
1263     ///         (&mut slice[0..mid], &mut slice2[mid..len])
1264     ///     }
1265     /// }
1266     ///
1267     /// // This is how the standard library does it. This is the best method, if
1268     /// // you need to do something like this
1269     /// fn split_at_stdlib<T>(slice: &mut [T], mid: usize)
1270     ///                       -> (&mut [T], &mut [T]) {
1271     ///     let len = slice.len();
1272     ///     assert!(mid <= len);
1273     ///     unsafe {
1274     ///         let ptr = slice.as_mut_ptr();
1275     ///         // This now has three mutable references pointing at the same
1276     ///         // memory. `slice`, the rvalue ret.0, and the rvalue ret.1.
1277     ///         // `slice` is never used after `let ptr = ...`, and so one can
1278     ///         // treat it as "dead", and therefore, you only have two real
1279     ///         // mutable slices.
1280     ///         (slice::from_raw_parts_mut(ptr, mid),
1281     ///          slice::from_raw_parts_mut(ptr.add(mid), len - mid))
1282     ///     }
1283     /// }
1284     /// ```
1285     #[stable(feature = "rust1", since = "1.0.0")]
1286     #[rustc_const_unstable(feature = "const_transmute", issue = "53605")]
1287     pub fn transmute<T, U>(e: T) -> U;
1288
1289     /// Returns `true` if the actual type given as `T` requires drop
1290     /// glue; returns `false` if the actual type provided for `T`
1291     /// implements `Copy`.
1292     ///
1293     /// If the actual type neither requires drop glue nor implements
1294     /// `Copy`, then the return value of this function is unspecified.
1295     ///
1296     /// The stabilized version of this intrinsic is
1297     /// [`std::mem::needs_drop`](../../std/mem/fn.needs_drop.html).
1298     #[rustc_const_stable(feature = "const_needs_drop", since = "1.40.0")]
1299     pub fn needs_drop<T>() -> bool;
1300
1301     /// Calculates the offset from a pointer.
1302     ///
1303     /// This is implemented as an intrinsic to avoid converting to and from an
1304     /// integer, since the conversion would throw away aliasing information.
1305     ///
1306     /// # Safety
1307     ///
1308     /// Both the starting and resulting pointer must be either in bounds or one
1309     /// byte past the end of an allocated object. If either pointer is out of
1310     /// bounds or arithmetic overflow occurs then any further use of the
1311     /// returned value will result in undefined behavior.
1312     ///
1313     /// The stabilized version of this intrinsic is
1314     /// [`std::pointer::offset`](../../std/primitive.pointer.html#method.offset).
1315     #[must_use = "returns a new pointer rather than modifying its argument"]
1316     #[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
1317     pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
1318
1319     /// Calculates the offset from a pointer, potentially wrapping.
1320     ///
1321     /// This is implemented as an intrinsic to avoid converting to and from an
1322     /// integer, since the conversion inhibits certain optimizations.
1323     ///
1324     /// # Safety
1325     ///
1326     /// Unlike the `offset` intrinsic, this intrinsic does not restrict the
1327     /// resulting pointer to point into or one byte past the end of an allocated
1328     /// object, and it wraps with two's complement arithmetic. The resulting
1329     /// value is not necessarily valid to be used to actually access memory.
1330     ///
1331     /// The stabilized version of this intrinsic is
1332     /// [`std::pointer::wrapping_offset`](../../std/primitive.pointer.html#method.wrapping_offset).
1333     #[must_use = "returns a new pointer rather than modifying its argument"]
1334     #[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
1335     pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
1336
1337     /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
1338     /// a size of `count` * `size_of::<T>()` and an alignment of
1339     /// `min_align_of::<T>()`
1340     ///
1341     /// The volatile parameter is set to `true`, so it will not be optimized out
1342     /// unless size is equal to zero.
1343     ///
1344     /// This intrinsic does not have a stable counterpart.
1345     pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
1346     /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
1347     /// a size of `count` * `size_of::<T>()` and an alignment of
1348     /// `min_align_of::<T>()`
1349     ///
1350     /// The volatile parameter is set to `true`, so it will not be optimized out
1351     /// unless size is equal to zero.
1352     ///
1353     /// This intrinsic does not have a stable counterpart.
1354     pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
1355     /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
1356     /// size of `count` * `size_of::<T>()` and an alignment of
1357     /// `min_align_of::<T>()`.
1358     ///
1359     /// The volatile parameter is set to `true`, so it will not be optimized out
1360     /// unless size is equal to zero.
1361     ///
1362     /// This intrinsic does not have a stable counterpart.
1363     pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
1364
1365     /// Performs a volatile load from the `src` pointer.
1366     ///
1367     /// The stabilized version of this intrinsic is
1368     /// [`std::ptr::read_volatile`](../../std/ptr/fn.read_volatile.html).
1369     pub fn volatile_load<T>(src: *const T) -> T;
1370     /// Performs a volatile store to the `dst` pointer.
1371     ///
1372     /// The stabilized version of this intrinsic is
1373     /// [`std::ptr::write_volatile`](../../std/ptr/fn.write_volatile.html).
1374     pub fn volatile_store<T>(dst: *mut T, val: T);
1375
1376     /// Performs a volatile load from the `src` pointer
1377     /// The pointer is not required to be aligned.
1378     ///
1379     /// This intrinsic does not have a stable counterpart.
1380     pub fn unaligned_volatile_load<T>(src: *const T) -> T;
1381     /// Performs a volatile store to the `dst` pointer.
1382     /// The pointer is not required to be aligned.
1383     ///
1384     /// This intrinsic does not have a stable counterpart.
1385     pub fn unaligned_volatile_store<T>(dst: *mut T, val: T);
1386
1387     /// Returns the square root of an `f32`
1388     ///
1389     /// The stabilized version of this intrinsic is
1390     /// [`std::f32::sqrt`](../../std/primitive.f32.html#method.sqrt)
1391     pub fn sqrtf32(x: f32) -> f32;
1392     /// Returns the square root of an `f64`
1393     ///
1394     /// The stabilized version of this intrinsic is
1395     /// [`std::f64::sqrt`](../../std/primitive.f64.html#method.sqrt)
1396     pub fn sqrtf64(x: f64) -> f64;
1397
1398     /// Raises an `f32` to an integer power.
1399     ///
1400     /// The stabilized version of this intrinsic is
1401     /// [`std::f32::powi`](../../std/primitive.f32.html#method.powi)
1402     pub fn powif32(a: f32, x: i32) -> f32;
1403     /// Raises an `f64` to an integer power.
1404     ///
1405     /// The stabilized version of this intrinsic is
1406     /// [`std::f64::powi`](../../std/primitive.f64.html#method.powi)
1407     pub fn powif64(a: f64, x: i32) -> f64;
1408
1409     /// Returns the sine of an `f32`.
1410     ///
1411     /// The stabilized version of this intrinsic is
1412     /// [`std::f32::sin`](../../std/primitive.f32.html#method.sin)
1413     pub fn sinf32(x: f32) -> f32;
1414     /// Returns the sine of an `f64`.
1415     ///
1416     /// The stabilized version of this intrinsic is
1417     /// [`std::f64::sin`](../../std/primitive.f64.html#method.sin)
1418     pub fn sinf64(x: f64) -> f64;
1419
1420     /// Returns the cosine of an `f32`.
1421     ///
1422     /// The stabilized version of this intrinsic is
1423     /// [`std::f32::cos`](../../std/primitive.f32.html#method.cos)
1424     pub fn cosf32(x: f32) -> f32;
1425     /// Returns the cosine of an `f64`.
1426     ///
1427     /// The stabilized version of this intrinsic is
1428     /// [`std::f64::cos`](../../std/primitive.f64.html#method.cos)
1429     pub fn cosf64(x: f64) -> f64;
1430
1431     /// Raises an `f32` to an `f32` power.
1432     ///
1433     /// The stabilized version of this intrinsic is
1434     /// [`std::f32::powf`](../../std/primitive.f32.html#method.powf)
1435     pub fn powf32(a: f32, x: f32) -> f32;
1436     /// Raises an `f64` to an `f64` power.
1437     ///
1438     /// The stabilized version of this intrinsic is
1439     /// [`std::f64::powf`](../../std/primitive.f64.html#method.powf)
1440     pub fn powf64(a: f64, x: f64) -> f64;
1441
1442     /// Returns the exponential of an `f32`.
1443     ///
1444     /// The stabilized version of this intrinsic is
1445     /// [`std::f32::exp`](../../std/primitive.f32.html#method.exp)
1446     pub fn expf32(x: f32) -> f32;
1447     /// Returns the exponential of an `f64`.
1448     ///
1449     /// The stabilized version of this intrinsic is
1450     /// [`std::f64::exp`](../../std/primitive.f64.html#method.exp)
1451     pub fn expf64(x: f64) -> f64;
1452
1453     /// Returns 2 raised to the power of an `f32`.
1454     ///
1455     /// The stabilized version of this intrinsic is
1456     /// [`std::f32::exp2`](../../std/primitive.f32.html#method.exp2)
1457     pub fn exp2f32(x: f32) -> f32;
1458     /// Returns 2 raised to the power of an `f64`.
1459     ///
1460     /// The stabilized version of this intrinsic is
1461     /// [`std::f64::exp2`](../../std/primitive.f64.html#method.exp2)
1462     pub fn exp2f64(x: f64) -> f64;
1463
1464     /// Returns the natural logarithm of an `f32`.
1465     ///
1466     /// The stabilized version of this intrinsic is
1467     /// [`std::f32::ln`](../../std/primitive.f32.html#method.ln)
1468     pub fn logf32(x: f32) -> f32;
1469     /// Returns the natural logarithm of an `f64`.
1470     ///
1471     /// The stabilized version of this intrinsic is
1472     /// [`std::f64::ln`](../../std/primitive.f64.html#method.ln)
1473     pub fn logf64(x: f64) -> f64;
1474
1475     /// Returns the base 10 logarithm of an `f32`.
1476     ///
1477     /// The stabilized version of this intrinsic is
1478     /// [`std::f32::log10`](../../std/primitive.f32.html#method.log10)
1479     pub fn log10f32(x: f32) -> f32;
1480     /// Returns the base 10 logarithm of an `f64`.
1481     ///
1482     /// The stabilized version of this intrinsic is
1483     /// [`std::f64::log10`](../../std/primitive.f64.html#method.log10)
1484     pub fn log10f64(x: f64) -> f64;
1485
1486     /// Returns the base 2 logarithm of an `f32`.
1487     ///
1488     /// The stabilized version of this intrinsic is
1489     /// [`std::f32::log2`](../../std/primitive.f32.html#method.log2)
1490     pub fn log2f32(x: f32) -> f32;
1491     /// Returns the base 2 logarithm of an `f64`.
1492     ///
1493     /// The stabilized version of this intrinsic is
1494     /// [`std::f64::log2`](../../std/primitive.f64.html#method.log2)
1495     pub fn log2f64(x: f64) -> f64;
1496
1497     /// Returns `a * b + c` for `f32` values.
1498     ///
1499     /// The stabilized version of this intrinsic is
1500     /// [`std::f32::mul_add`](../../std/primitive.f32.html#method.mul_add)
1501     pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
1502     /// Returns `a * b + c` for `f64` values.
1503     ///
1504     /// The stabilized version of this intrinsic is
1505     /// [`std::f64::mul_add`](../../std/primitive.f64.html#method.mul_add)
1506     pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
1507
1508     /// Returns the absolute value of an `f32`.
1509     ///
1510     /// The stabilized version of this intrinsic is
1511     /// [`std::f32::abs`](../../std/primitive.f32.html#method.abs)
1512     pub fn fabsf32(x: f32) -> f32;
1513     /// Returns the absolute value of an `f64`.
1514     ///
1515     /// The stabilized version of this intrinsic is
1516     /// [`std::f64::abs`](../../std/primitive.f64.html#method.abs)
1517     pub fn fabsf64(x: f64) -> f64;
1518
1519     /// Returns the minimum of two `f32` values.
1520     ///
1521     /// The stabilized version of this intrinsic is
1522     /// [`std::f32::min`](../../std/primitive.f32.html#method.min)
1523     pub fn minnumf32(x: f32, y: f32) -> f32;
1524     /// Returns the minimum of two `f64` values.
1525     ///
1526     /// The stabilized version of this intrinsic is
1527     /// [`std::f64::min`](../../std/primitive.f64.html#method.min)
1528     pub fn minnumf64(x: f64, y: f64) -> f64;
1529     /// Returns the maximum of two `f32` values.
1530     ///
1531     /// The stabilized version of this intrinsic is
1532     /// [`std::f32::max`](../../std/primitive.f32.html#method.max)
1533     pub fn maxnumf32(x: f32, y: f32) -> f32;
1534     /// Returns the maximum of two `f64` values.
1535     ///
1536     /// The stabilized version of this intrinsic is
1537     /// [`std::f64::max`](../../std/primitive.f64.html#method.max)
1538     pub fn maxnumf64(x: f64, y: f64) -> f64;
1539
1540     /// Copies the sign from `y` to `x` for `f32` values.
1541     ///
1542     /// The stabilized version of this intrinsic is
1543     /// [`std::f32::copysign`](../../std/primitive.f32.html#method.copysign)
1544     pub fn copysignf32(x: f32, y: f32) -> f32;
1545     /// Copies the sign from `y` to `x` for `f64` values.
1546     ///
1547     /// The stabilized version of this intrinsic is
1548     /// [`std::f64::copysign`](../../std/primitive.f64.html#method.copysign)
1549     pub fn copysignf64(x: f64, y: f64) -> f64;
1550
1551     /// Returns the largest integer less than or equal to an `f32`.
1552     ///
1553     /// The stabilized version of this intrinsic is
1554     /// [`std::f32::floor`](../../std/primitive.f32.html#method.floor)
1555     pub fn floorf32(x: f32) -> f32;
1556     /// Returns the largest integer less than or equal to an `f64`.
1557     ///
1558     /// The stabilized version of this intrinsic is
1559     /// [`std::f64::floor`](../../std/primitive.f64.html#method.floor)
1560     pub fn floorf64(x: f64) -> f64;
1561
1562     /// Returns the smallest integer greater than or equal to an `f32`.
1563     ///
1564     /// The stabilized version of this intrinsic is
1565     /// [`std::f32::ceil`](../../std/primitive.f32.html#method.ceil)
1566     pub fn ceilf32(x: f32) -> f32;
1567     /// Returns the smallest integer greater than or equal to an `f64`.
1568     ///
1569     /// The stabilized version of this intrinsic is
1570     /// [`std::f64::ceil`](../../std/primitive.f64.html#method.ceil)
1571     pub fn ceilf64(x: f64) -> f64;
1572
1573     /// Returns the integer part of an `f32`.
1574     ///
1575     /// The stabilized version of this intrinsic is
1576     /// [`std::f32::trunc`](../../std/primitive.f32.html#method.trunc)
1577     pub fn truncf32(x: f32) -> f32;
1578     /// Returns the integer part of an `f64`.
1579     ///
1580     /// The stabilized version of this intrinsic is
1581     /// [`std::f64::trunc`](../../std/primitive.f64.html#method.trunc)
1582     pub fn truncf64(x: f64) -> f64;
1583
1584     /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
1585     /// if the argument is not an integer.
1586     pub fn rintf32(x: f32) -> f32;
1587     /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
1588     /// if the argument is not an integer.
1589     pub fn rintf64(x: f64) -> f64;
1590
1591     /// Returns the nearest integer to an `f32`.
1592     ///
1593     /// This intrinsic does not have a stable counterpart.
1594     pub fn nearbyintf32(x: f32) -> f32;
1595     /// Returns the nearest integer to an `f64`.
1596     ///
1597     /// This intrinsic does not have a stable counterpart.
1598     pub fn nearbyintf64(x: f64) -> f64;
1599
1600     /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
1601     ///
1602     /// The stabilized version of this intrinsic is
1603     /// [`std::f32::round`](../../std/primitive.f32.html#method.round)
1604     pub fn roundf32(x: f32) -> f32;
1605     /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
1606     ///
1607     /// The stabilized version of this intrinsic is
1608     /// [`std::f64::round`](../../std/primitive.f64.html#method.round)
1609     pub fn roundf64(x: f64) -> f64;
1610
1611     /// Float addition that allows optimizations based on algebraic rules.
1612     /// May assume inputs are finite.
1613     ///
1614     /// This intrinsic does not have a stable counterpart.
1615     pub fn fadd_fast<T: Copy>(a: T, b: T) -> T;
1616
1617     /// Float subtraction that allows optimizations based on algebraic rules.
1618     /// May assume inputs are finite.
1619     ///
1620     /// This intrinsic does not have a stable counterpart.
1621     pub fn fsub_fast<T: Copy>(a: T, b: T) -> T;
1622
1623     /// Float multiplication that allows optimizations based on algebraic rules.
1624     /// May assume inputs are finite.
1625     ///
1626     /// This intrinsic does not have a stable counterpart.
1627     pub fn fmul_fast<T: Copy>(a: T, b: T) -> T;
1628
1629     /// Float division that allows optimizations based on algebraic rules.
1630     /// May assume inputs are finite.
1631     ///
1632     /// This intrinsic does not have a stable counterpart.
1633     pub fn fdiv_fast<T: Copy>(a: T, b: T) -> T;
1634
1635     /// Float remainder that allows optimizations based on algebraic rules.
1636     /// May assume inputs are finite.
1637     ///
1638     /// This intrinsic does not have a stable counterpart.
1639     pub fn frem_fast<T: Copy>(a: T, b: T) -> T;
1640
1641     /// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range
1642     /// (<https://github.com/rust-lang/rust/issues/10184>)
1643     ///
1644     /// Stabilized as [`f32::to_int_unchecked`](../../std/primitive.f32.html#method.to_int_unchecked)
1645     /// and [`f64::to_int_unchecked`](../../std/primitive.f64.html#method.to_int_unchecked).
1646     pub fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
1647
1648     /// Returns the number of bits set in an integer type `T`
1649     ///
1650     /// The stabilized versions of this intrinsic are available on the integer
1651     /// primitives via the `count_ones` method. For example,
1652     /// [`std::u32::count_ones`](../../std/primitive.u32.html#method.count_ones)
1653     #[rustc_const_stable(feature = "const_ctpop", since = "1.40.0")]
1654     pub fn ctpop<T: Copy>(x: T) -> T;
1655
1656     /// Returns the number of leading unset bits (zeroes) in an integer type `T`.
1657     ///
1658     /// The stabilized versions of this intrinsic are available on the integer
1659     /// primitives via the `leading_zeros` method. For example,
1660     /// [`std::u32::leading_zeros`](../../std/primitive.u32.html#method.leading_zeros)
1661     ///
1662     /// # Examples
1663     ///
1664     /// ```
1665     /// #![feature(core_intrinsics)]
1666     ///
1667     /// use std::intrinsics::ctlz;
1668     ///
1669     /// let x = 0b0001_1100_u8;
1670     /// let num_leading = ctlz(x);
1671     /// assert_eq!(num_leading, 3);
1672     /// ```
1673     ///
1674     /// An `x` with value `0` will return the bit width of `T`.
1675     ///
1676     /// ```
1677     /// #![feature(core_intrinsics)]
1678     ///
1679     /// use std::intrinsics::ctlz;
1680     ///
1681     /// let x = 0u16;
1682     /// let num_leading = ctlz(x);
1683     /// assert_eq!(num_leading, 16);
1684     /// ```
1685     #[rustc_const_stable(feature = "const_ctlz", since = "1.40.0")]
1686     pub fn ctlz<T: Copy>(x: T) -> T;
1687
1688     /// Like `ctlz`, but extra-unsafe as it returns `undef` when
1689     /// given an `x` with value `0`.
1690     ///
1691     /// This intrinsic does not have a stable counterpart.
1692     ///
1693     /// # Examples
1694     ///
1695     /// ```
1696     /// #![feature(core_intrinsics)]
1697     ///
1698     /// use std::intrinsics::ctlz_nonzero;
1699     ///
1700     /// let x = 0b0001_1100_u8;
1701     /// let num_leading = unsafe { ctlz_nonzero(x) };
1702     /// assert_eq!(num_leading, 3);
1703     /// ```
1704     #[rustc_const_unstable(feature = "constctlz", issue = "none")]
1705     pub fn ctlz_nonzero<T: Copy>(x: T) -> T;
1706
1707     /// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
1708     ///
1709     /// The stabilized versions of this intrinsic are available on the integer
1710     /// primitives via the `trailing_zeros` method. For example,
1711     /// [`std::u32::trailing_zeros`](../../std/primitive.u32.html#method.trailing_zeros)
1712     ///
1713     /// # Examples
1714     ///
1715     /// ```
1716     /// #![feature(core_intrinsics)]
1717     ///
1718     /// use std::intrinsics::cttz;
1719     ///
1720     /// let x = 0b0011_1000_u8;
1721     /// let num_trailing = cttz(x);
1722     /// assert_eq!(num_trailing, 3);
1723     /// ```
1724     ///
1725     /// An `x` with value `0` will return the bit width of `T`:
1726     ///
1727     /// ```
1728     /// #![feature(core_intrinsics)]
1729     ///
1730     /// use std::intrinsics::cttz;
1731     ///
1732     /// let x = 0u16;
1733     /// let num_trailing = cttz(x);
1734     /// assert_eq!(num_trailing, 16);
1735     /// ```
1736     #[rustc_const_stable(feature = "const_cttz", since = "1.40.0")]
1737     pub fn cttz<T: Copy>(x: T) -> T;
1738
1739     /// Like `cttz`, but extra-unsafe as it returns `undef` when
1740     /// given an `x` with value `0`.
1741     ///
1742     /// This intrinsic does not have a stable counterpart.
1743     ///
1744     /// # Examples
1745     ///
1746     /// ```
1747     /// #![feature(core_intrinsics)]
1748     ///
1749     /// use std::intrinsics::cttz_nonzero;
1750     ///
1751     /// let x = 0b0011_1000_u8;
1752     /// let num_trailing = unsafe { cttz_nonzero(x) };
1753     /// assert_eq!(num_trailing, 3);
1754     /// ```
1755     #[rustc_const_unstable(feature = "const_cttz", issue = "none")]
1756     pub fn cttz_nonzero<T: Copy>(x: T) -> T;
1757
1758     /// Reverses the bytes in an integer type `T`.
1759     ///
1760     /// The stabilized versions of this intrinsic are available on the integer
1761     /// primitives via the `swap_bytes` method. For example,
1762     /// [`std::u32::swap_bytes`](../../std/primitive.u32.html#method.swap_bytes)
1763     #[rustc_const_stable(feature = "const_bswap", since = "1.40.0")]
1764     pub fn bswap<T: Copy>(x: T) -> T;
1765
1766     /// Reverses the bits in an integer type `T`.
1767     ///
1768     /// The stabilized versions of this intrinsic are available on the integer
1769     /// primitives via the `reverse_bits` method. For example,
1770     /// [`std::u32::reverse_bits`](../../std/primitive.u32.html#method.reverse_bits)
1771     #[rustc_const_stable(feature = "const_bitreverse", since = "1.40.0")]
1772     pub fn bitreverse<T: Copy>(x: T) -> T;
1773
1774     /// Performs checked integer addition.
1775     ///
1776     /// The stabilized versions of this intrinsic are available on the integer
1777     /// primitives via the `overflowing_add` method. For example,
1778     /// [`std::u32::overflowing_add`](../../std/primitive.u32.html#method.overflowing_add)
1779     #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1780     pub fn add_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1781
1782     /// Performs checked integer subtraction
1783     ///
1784     /// The stabilized versions of this intrinsic are available on the integer
1785     /// primitives via the `overflowing_sub` method. For example,
1786     /// [`std::u32::overflowing_sub`](../../std/primitive.u32.html#method.overflowing_sub)
1787     #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1788     pub fn sub_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1789
1790     /// Performs checked integer multiplication
1791     ///
1792     /// The stabilized versions of this intrinsic are available on the integer
1793     /// primitives via the `overflowing_mul` method. For example,
1794     /// [`std::u32::overflowing_mul`](../../std/primitive.u32.html#method.overflowing_mul)
1795     #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1796     pub fn mul_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1797
1798     /// Performs an exact division, resulting in undefined behavior where
1799     /// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
1800     ///
1801     /// This intrinsic does not have a stable counterpart.
1802     pub fn exact_div<T: Copy>(x: T, y: T) -> T;
1803
1804     /// Performs an unchecked division, resulting in undefined behavior
1805     /// where y = 0 or x = `T::MIN` and y = -1
1806     ///
1807     /// Safe wrappers for this intrinsic are available on the integer
1808     /// primitives via the `checked_div` method. For example,
1809     /// [`std::u32::checked_div`](../../std/primitive.u32.html#method.checked_div)
1810     #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1811     pub fn unchecked_div<T: Copy>(x: T, y: T) -> T;
1812     /// Returns the remainder of an unchecked division, resulting in
1813     /// undefined behavior where y = 0 or x = `T::MIN` and y = -1
1814     ///
1815     /// Safe wrappers for this intrinsic are available on the integer
1816     /// primitives via the `checked_rem` method. For example,
1817     /// [`std::u32::checked_rem`](../../std/primitive.u32.html#method.checked_rem)
1818     #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1819     pub fn unchecked_rem<T: Copy>(x: T, y: T) -> T;
1820
1821     /// Performs an unchecked left shift, resulting in undefined behavior when
1822     /// y < 0 or y >= N, where N is the width of T in bits.
1823     ///
1824     /// Safe wrappers for this intrinsic are available on the integer
1825     /// primitives via the `checked_shl` method. For example,
1826     /// [`std::u32::checked_shl`](../../std/primitive.u32.html#method.checked_shl)
1827     #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1828     pub fn unchecked_shl<T: Copy>(x: T, y: T) -> T;
1829     /// Performs an unchecked right shift, resulting in undefined behavior when
1830     /// y < 0 or y >= N, where N is the width of T in bits.
1831     ///
1832     /// Safe wrappers for this intrinsic are available on the integer
1833     /// primitives via the `checked_shr` method. For example,
1834     /// [`std::u32::checked_shr`](../../std/primitive.u32.html#method.checked_shr)
1835     #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1836     pub fn unchecked_shr<T: Copy>(x: T, y: T) -> T;
1837
1838     /// Returns the result of an unchecked addition, resulting in
1839     /// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.
1840     ///
1841     /// This intrinsic does not have a stable counterpart.
1842     #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1843     pub fn unchecked_add<T: Copy>(x: T, y: T) -> T;
1844
1845     /// Returns the result of an unchecked subtraction, resulting in
1846     /// undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`.
1847     ///
1848     /// This intrinsic does not have a stable counterpart.
1849     #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1850     pub fn unchecked_sub<T: Copy>(x: T, y: T) -> T;
1851
1852     /// Returns the result of an unchecked multiplication, resulting in
1853     /// undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`.
1854     ///
1855     /// This intrinsic does not have a stable counterpart.
1856     #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1857     pub fn unchecked_mul<T: Copy>(x: T, y: T) -> T;
1858
1859     /// Performs rotate left.
1860     ///
1861     /// The stabilized versions of this intrinsic are available on the integer
1862     /// primitives via the `rotate_left` method. For example,
1863     /// [`std::u32::rotate_left`](../../std/primitive.u32.html#method.rotate_left)
1864     #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1865     pub fn rotate_left<T: Copy>(x: T, y: T) -> T;
1866
1867     /// Performs rotate right.
1868     ///
1869     /// The stabilized versions of this intrinsic are available on the integer
1870     /// primitives via the `rotate_right` method. For example,
1871     /// [`std::u32::rotate_right`](../../std/primitive.u32.html#method.rotate_right)
1872     #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1873     pub fn rotate_right<T: Copy>(x: T, y: T) -> T;
1874
1875     /// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
1876     ///
1877     /// The stabilized versions of this intrinsic are available on the integer
1878     /// primitives via the `checked_add` method. For example,
1879     /// [`std::u32::checked_add`](../../std/primitive.u32.html#method.checked_add)
1880     #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1881     pub fn wrapping_add<T: Copy>(a: T, b: T) -> T;
1882     /// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
1883     ///
1884     /// The stabilized versions of this intrinsic are available on the integer
1885     /// primitives via the `checked_sub` method. For example,
1886     /// [`std::u32::checked_sub`](../../std/primitive.u32.html#method.checked_sub)
1887     #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1888     pub fn wrapping_sub<T: Copy>(a: T, b: T) -> T;
1889     /// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
1890     ///
1891     /// The stabilized versions of this intrinsic are available on the integer
1892     /// primitives via the `checked_mul` method. For example,
1893     /// [`std::u32::checked_mul`](../../std/primitive.u32.html#method.checked_mul)
1894     #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1895     pub fn wrapping_mul<T: Copy>(a: T, b: T) -> T;
1896
1897     /// Computes `a + b`, while saturating at numeric bounds.
1898     ///
1899     /// The stabilized versions of this intrinsic are available on the integer
1900     /// primitives via the `saturating_add` method. For example,
1901     /// [`std::u32::saturating_add`](../../std/primitive.u32.html#method.saturating_add)
1902     #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1903     pub fn saturating_add<T: Copy>(a: T, b: T) -> T;
1904     /// Computes `a - b`, while saturating at numeric bounds.
1905     ///
1906     /// The stabilized versions of this intrinsic are available on the integer
1907     /// primitives via the `saturating_sub` method. For example,
1908     /// [`std::u32::saturating_sub`](../../std/primitive.u32.html#method.saturating_sub)
1909     #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1910     pub fn saturating_sub<T: Copy>(a: T, b: T) -> T;
1911
1912     /// Returns the value of the discriminant for the variant in 'v',
1913     /// cast to a `u64`; if `T` has no discriminant, returns 0.
1914     ///
1915     /// The stabilized version of this intrinsic is
1916     /// [`std::mem::discriminant`](../../std/mem/fn.discriminant.html)
1917     #[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
1918     pub fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
1919
1920     /// Returns the number of variants of the type `T` cast to a `usize`;
1921     /// if `T` has no variants, returns 0. Uninhabited variants will be counted.
1922     ///
1923     /// The to-be-stabilized version of this intrinsic is
1924     /// [`std::mem::variant_count`](../../std/mem/fn.variant_count.html)
1925     #[rustc_const_unstable(feature = "variant_count", issue = "73662")]
1926     #[cfg(not(bootstrap))]
1927     pub fn variant_count<T>() -> usize;
1928
1929     /// Rust's "try catch" construct which invokes the function pointer `try_fn`
1930     /// with the data pointer `data`.
1931     ///
1932     /// The third argument is a function called if a panic occurs. This function
1933     /// takes the data pointer and a pointer to the target-specific exception
1934     /// object that was caught. For more information see the compiler's
1935     /// source as well as std's catch implementation.
1936     pub fn r#try(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32;
1937
1938     /// Emits a `!nontemporal` store according to LLVM (see their docs).
1939     /// Probably will never become stable.
1940     pub fn nontemporal_store<T>(ptr: *mut T, val: T);
1941
1942     /// See documentation of `<*const T>::offset_from` for details.
1943     #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "41079")]
1944     pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
1945
1946     /// Internal hook used by Miri to implement unwinding.
1947     /// ICEs when encountered during non-Miri codegen.
1948     ///
1949     /// The `payload` ptr here will be exactly the one `do_catch` gets passed by `try`.
1950     ///
1951     /// Perma-unstable: do not use.
1952     pub fn miri_start_panic(payload: *mut u8) -> !;
1953
1954     /// Internal placeholder for injecting code coverage counters when the "instrument-coverage"
1955     /// option is enabled. The placeholder is replaced with `llvm.instrprof.increment` during code
1956     /// generation.
1957     #[cfg(not(bootstrap))]
1958     #[lang = "count_code_region"]
1959     pub fn count_code_region(index: u32);
1960
1961     /// See documentation of `<*const T>::guaranteed_eq` for details.
1962     #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
1963     #[cfg(not(bootstrap))]
1964     pub fn ptr_guaranteed_eq<T>(ptr: *const T, other: *const T) -> bool;
1965
1966     /// See documentation of `<*const T>::guaranteed_ne` for details.
1967     #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
1968     #[cfg(not(bootstrap))]
1969     pub fn ptr_guaranteed_ne<T>(ptr: *const T, other: *const T) -> bool;
1970 }
1971
1972 #[rustc_const_unstable(feature = "variant_count", issue = "73662")]
1973 #[cfg(bootstrap)]
1974 pub const fn variant_count<T>() -> usize {
1975     0
1976 }
1977
1978 // Some functions are defined here because they accidentally got made
1979 // available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
1980 // (`transmute` also falls into this category, but it cannot be wrapped due to the
1981 // check that `T` and `U` have the same size.)
1982
1983 /// Checks whether `ptr` is properly aligned with respect to
1984 /// `align_of::<T>()`.
1985 pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
1986     !ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0
1987 }
1988
1989 /// Checks whether the regions of memory starting at `src` and `dst` of size
1990 /// `count * size_of::<T>()` do *not* overlap.
1991 pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
1992     let src_usize = src as usize;
1993     let dst_usize = dst as usize;
1994     let size = mem::size_of::<T>().checked_mul(count).unwrap();
1995     let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
1996     // If the absolute distance between the ptrs is at least as big as the size of the buffer,
1997     // they do not overlap.
1998     diff >= size
1999 }
2000
2001 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
2002 /// and destination must *not* overlap.
2003 ///
2004 /// For regions of memory which might overlap, use [`copy`] instead.
2005 ///
2006 /// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
2007 /// with the argument order swapped.
2008 ///
2009 /// [`copy`]: ./fn.copy.html
2010 /// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy
2011 ///
2012 /// # Safety
2013 ///
2014 /// Behavior is undefined if any of the following conditions are violated:
2015 ///
2016 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
2017 ///
2018 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2019 ///
2020 /// * Both `src` and `dst` must be properly aligned.
2021 ///
2022 /// * The region of memory beginning at `src` with a size of `count *
2023 ///   size_of::<T>()` bytes must *not* overlap with the region of memory
2024 ///   beginning at `dst` with the same size.
2025 ///
2026 /// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of
2027 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values
2028 /// in the region beginning at `*src` and the region beginning at `*dst` can
2029 /// [violate memory safety][read-ownership].
2030 ///
2031 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2032 /// `0`, the pointers must be non-NULL and properly aligned.
2033 ///
2034 /// [`Copy`]: ../marker/trait.Copy.html
2035 /// [`read`]: ../ptr/fn.read.html
2036 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
2037 /// [valid]: ../ptr/index.html#safety
2038 ///
2039 /// # Examples
2040 ///
2041 /// Manually implement [`Vec::append`]:
2042 ///
2043 /// ```
2044 /// use std::ptr;
2045 ///
2046 /// /// Moves all the elements of `src` into `dst`, leaving `src` empty.
2047 /// fn append<T>(dst: &mut Vec<T>, src: &mut Vec<T>) {
2048 ///     let src_len = src.len();
2049 ///     let dst_len = dst.len();
2050 ///
2051 ///     // Ensure that `dst` has enough capacity to hold all of `src`.
2052 ///     dst.reserve(src_len);
2053 ///
2054 ///     unsafe {
2055 ///         // The call to offset is always safe because `Vec` will never
2056 ///         // allocate more than `isize::MAX` bytes.
2057 ///         let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize);
2058 ///         let src_ptr = src.as_ptr();
2059 ///
2060 ///         // Truncate `src` without dropping its contents. We do this first,
2061 ///         // to avoid problems in case something further down panics.
2062 ///         src.set_len(0);
2063 ///
2064 ///         // The two regions cannot overlap because mutable references do
2065 ///         // not alias, and two different vectors cannot own the same
2066 ///         // memory.
2067 ///         ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
2068 ///
2069 ///         // Notify `dst` that it now holds the contents of `src`.
2070 ///         dst.set_len(dst_len + src_len);
2071 ///     }
2072 /// }
2073 ///
2074 /// let mut a = vec!['r'];
2075 /// let mut b = vec!['u', 's', 't'];
2076 ///
2077 /// append(&mut a, &mut b);
2078 ///
2079 /// assert_eq!(a, &['r', 'u', 's', 't']);
2080 /// assert!(b.is_empty());
2081 /// ```
2082 ///
2083 /// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append
2084 #[doc(alias = "memcpy")]
2085 #[stable(feature = "rust1", since = "1.0.0")]
2086 #[inline]
2087 pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
2088     extern "rust-intrinsic" {
2089         fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
2090     }
2091
2092     if cfg!(debug_assertions)
2093         && !(is_aligned_and_not_null(src)
2094             && is_aligned_and_not_null(dst)
2095             && is_nonoverlapping(src, dst, count))
2096     {
2097         // Not panicking to keep codegen impact smaller.
2098         abort();
2099     }
2100
2101     // SAFETY: the safety contract for `copy_nonoverlapping` must be
2102     // upheld by the caller.
2103     unsafe { copy_nonoverlapping(src, dst, count) }
2104 }
2105
2106 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
2107 /// and destination may overlap.
2108 ///
2109 /// If the source and destination will *never* overlap,
2110 /// [`copy_nonoverlapping`] can be used instead.
2111 ///
2112 /// `copy` is semantically equivalent to C's [`memmove`], but with the argument
2113 /// order swapped. Copying takes place as if the bytes were copied from `src`
2114 /// to a temporary array and then copied from the array to `dst`.
2115 ///
2116 /// [`copy_nonoverlapping`]: ./fn.copy_nonoverlapping.html
2117 /// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove
2118 ///
2119 /// # Safety
2120 ///
2121 /// Behavior is undefined if any of the following conditions are violated:
2122 ///
2123 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
2124 ///
2125 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2126 ///
2127 /// * Both `src` and `dst` must be properly aligned.
2128 ///
2129 /// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of
2130 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the values
2131 /// in the region beginning at `*src` and the region beginning at `*dst` can
2132 /// [violate memory safety][read-ownership].
2133 ///
2134 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2135 /// `0`, the pointers must be non-NULL and properly aligned.
2136 ///
2137 /// [`Copy`]: ../marker/trait.Copy.html
2138 /// [`read`]: ../ptr/fn.read.html
2139 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
2140 /// [valid]: ../ptr/index.html#safety
2141 ///
2142 /// # Examples
2143 ///
2144 /// Efficiently create a Rust vector from an unsafe buffer:
2145 ///
2146 /// ```
2147 /// use std::ptr;
2148 ///
2149 /// # #[allow(dead_code)]
2150 /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
2151 ///     let mut dst = Vec::with_capacity(elts);
2152 ///     dst.set_len(elts);
2153 ///     ptr::copy(ptr, dst.as_mut_ptr(), elts);
2154 ///     dst
2155 /// }
2156 /// ```
2157 #[doc(alias = "memmove")]
2158 #[stable(feature = "rust1", since = "1.0.0")]
2159 #[inline]
2160 pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
2161     extern "rust-intrinsic" {
2162         fn copy<T>(src: *const T, dst: *mut T, count: usize);
2163     }
2164
2165     if cfg!(debug_assertions) && !(is_aligned_and_not_null(src) && is_aligned_and_not_null(dst)) {
2166         // Not panicking to keep codegen impact smaller.
2167         abort();
2168     }
2169
2170     // SAFETY: the safety contract for `copy` must be upheld by the caller.
2171     unsafe { copy(src, dst, count) }
2172 }
2173
2174 /// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
2175 /// `val`.
2176 ///
2177 /// `write_bytes` is similar to C's [`memset`], but sets `count *
2178 /// size_of::<T>()` bytes to `val`.
2179 ///
2180 /// [`memset`]: https://en.cppreference.com/w/c/string/byte/memset
2181 ///
2182 /// # Safety
2183 ///
2184 /// Behavior is undefined if any of the following conditions are violated:
2185 ///
2186 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2187 ///
2188 /// * `dst` must be properly aligned.
2189 ///
2190 /// Additionally, the caller must ensure that writing `count *
2191 /// size_of::<T>()` bytes to the given region of memory results in a valid
2192 /// value of `T`. Using a region of memory typed as a `T` that contains an
2193 /// invalid value of `T` is undefined behavior.
2194 ///
2195 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2196 /// `0`, the pointer must be non-NULL and properly aligned.
2197 ///
2198 /// [valid]: ../ptr/index.html#safety
2199 ///
2200 /// # Examples
2201 ///
2202 /// Basic usage:
2203 ///
2204 /// ```
2205 /// use std::ptr;
2206 ///
2207 /// let mut vec = vec![0u32; 4];
2208 /// unsafe {
2209 ///     let vec_ptr = vec.as_mut_ptr();
2210 ///     ptr::write_bytes(vec_ptr, 0xfe, 2);
2211 /// }
2212 /// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
2213 /// ```
2214 ///
2215 /// Creating an invalid value:
2216 ///
2217 /// ```
2218 /// use std::ptr;
2219 ///
2220 /// let mut v = Box::new(0i32);
2221 ///
2222 /// unsafe {
2223 ///     // Leaks the previously held value by overwriting the `Box<T>` with
2224 ///     // a null pointer.
2225 ///     ptr::write_bytes(&mut v as *mut Box<i32>, 0, 1);
2226 /// }
2227 ///
2228 /// // At this point, using or dropping `v` results in undefined behavior.
2229 /// // drop(v); // ERROR
2230 ///
2231 /// // Even leaking `v` "uses" it, and hence is undefined behavior.
2232 /// // mem::forget(v); // ERROR
2233 ///
2234 /// // In fact, `v` is invalid according to basic type layout invariants, so *any*
2235 /// // operation touching it is undefined behavior.
2236 /// // let v2 = v; // ERROR
2237 ///
2238 /// unsafe {
2239 ///     // Let us instead put in a valid value
2240 ///     ptr::write(&mut v as *mut Box<i32>, Box::new(42i32));
2241 /// }
2242 ///
2243 /// // Now the box is fine
2244 /// assert_eq!(*v, 42);
2245 /// ```
2246 #[stable(feature = "rust1", since = "1.0.0")]
2247 #[inline]
2248 pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
2249     extern "rust-intrinsic" {
2250         fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
2251     }
2252
2253     debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer");
2254
2255     // SAFETY: the safety contract for `write_bytes` must be upheld by the caller.
2256     unsafe { write_bytes(dst, val, count) }
2257 }