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