]> git.lizzy.rs Git - rust.git/blob - src/libcore/intrinsics.rs
Rollup merge of #66059 - RalfJung:panic-on-non-zero, r=eddyb
[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     /// A guard for unsafe functions that cannot ever be executed if `T` does not permit
1011     /// zero-initialization: This will statically either panic, or do nothing.
1012     #[cfg(not(bootstrap))]
1013     pub fn panic_if_zero_invalid<T>();
1014
1015     /// A guard for unsafe functions that cannot ever be executed if `T` has invalid
1016     /// bit patterns: This will statically either panic, or do nothing.
1017     #[cfg(not(bootstrap))]
1018     pub fn panic_if_any_invalid<T>();
1019
1020     /// Gets a reference to a static `Location` indicating where it was called.
1021     #[rustc_const_unstable(feature = "const_caller_location", issue = "47809")]
1022     pub fn caller_location() -> &'static crate::panic::Location<'static>;
1023
1024     /// Creates a value initialized to zero.
1025     ///
1026     /// `init` is unsafe because it returns a zeroed-out datum,
1027     /// which is unsafe unless `T` is `Copy`. Also, even if T is
1028     /// `Copy`, an all-zero value may not correspond to any legitimate
1029     /// state for the type in question.
1030     ///
1031     /// The stabilized version of this intrinsic is
1032     /// [`std::mem::zeroed`](../../std/mem/fn.zeroed.html).
1033     #[unstable(
1034         feature = "core_intrinsics",
1035         reason = "intrinsics are unlikely to ever be stabilized, instead \
1036                          they should be used through stabilized interfaces \
1037                          in the rest of the standard library",
1038         issue = "none"
1039     )]
1040     #[rustc_deprecated(reason = "superseded by MaybeUninit, removal planned", since = "1.38.0")]
1041     pub fn init<T>() -> T;
1042
1043     /// Creates an uninitialized value.
1044     ///
1045     /// `uninit` is unsafe because there is no guarantee of what its
1046     /// contents are. In particular its drop-flag may be set to any
1047     /// state, which means it may claim either dropped or
1048     /// undropped. In the general case one must use `ptr::write` to
1049     /// initialize memory previous set to the result of `uninit`.
1050     ///
1051     /// The stabilized version of this intrinsic is
1052     /// [`std::mem::MaybeUninit`](../../std/mem/union.MaybeUninit.html).
1053     #[unstable(
1054         feature = "core_intrinsics",
1055         reason = "intrinsics are unlikely to ever be stabilized, instead \
1056                          they should be used through stabilized interfaces \
1057                          in the rest of the standard library",
1058         issue = "none"
1059     )]
1060     #[rustc_deprecated(reason = "superseded by MaybeUninit, removal planned", since = "1.38.0")]
1061     pub fn uninit<T>() -> T;
1062
1063     /// Moves a value out of scope without running drop glue.
1064     pub fn forget<T: ?Sized>(_: T);
1065
1066     /// Reinterprets the bits of a value of one type as another type.
1067     ///
1068     /// Both types must have the same size. Neither the original, nor the result,
1069     /// may be an [invalid value](../../nomicon/what-unsafe-does.html).
1070     ///
1071     /// `transmute` is semantically equivalent to a bitwise move of one type
1072     /// into another. It copies the bits from the source value into the
1073     /// destination value, then forgets the original. It's equivalent to C's
1074     /// `memcpy` under the hood, just like `transmute_copy`.
1075     ///
1076     /// `transmute` is **incredibly** unsafe. There are a vast number of ways to
1077     /// cause [undefined behavior][ub] with this function. `transmute` should be
1078     /// the absolute last resort.
1079     ///
1080     /// The [nomicon](../../nomicon/transmutes.html) has additional
1081     /// documentation.
1082     ///
1083     /// [ub]: ../../reference/behavior-considered-undefined.html
1084     ///
1085     /// # Examples
1086     ///
1087     /// There are a few things that `transmute` is really useful for.
1088     ///
1089     /// Turning a pointer into a function pointer. This is *not* portable to
1090     /// machines where function pointers and data pointers have different sizes.
1091     ///
1092     /// ```
1093     /// fn foo() -> i32 {
1094     ///     0
1095     /// }
1096     /// let pointer = foo as *const ();
1097     /// let function = unsafe {
1098     ///     std::mem::transmute::<*const (), fn() -> i32>(pointer)
1099     /// };
1100     /// assert_eq!(function(), 0);
1101     /// ```
1102     ///
1103     /// Extending a lifetime, or shortening an invariant lifetime. This is
1104     /// advanced, very unsafe Rust!
1105     ///
1106     /// ```
1107     /// struct R<'a>(&'a i32);
1108     /// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
1109     ///     std::mem::transmute::<R<'b>, R<'static>>(r)
1110     /// }
1111     ///
1112     /// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
1113     ///                                              -> &'b mut R<'c> {
1114     ///     std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
1115     /// }
1116     /// ```
1117     ///
1118     /// # Alternatives
1119     ///
1120     /// Don't despair: many uses of `transmute` can be achieved through other means.
1121     /// Below are common applications of `transmute` which can be replaced with safer
1122     /// constructs.
1123     ///
1124     /// Turning a pointer into a `usize`:
1125     ///
1126     /// ```
1127     /// let ptr = &0;
1128     /// let ptr_num_transmute = unsafe {
1129     ///     std::mem::transmute::<&i32, usize>(ptr)
1130     /// };
1131     ///
1132     /// // Use an `as` cast instead
1133     /// let ptr_num_cast = ptr as *const i32 as usize;
1134     /// ```
1135     ///
1136     /// Turning a `*mut T` into an `&mut T`:
1137     ///
1138     /// ```
1139     /// let ptr: *mut i32 = &mut 0;
1140     /// let ref_transmuted = unsafe {
1141     ///     std::mem::transmute::<*mut i32, &mut i32>(ptr)
1142     /// };
1143     ///
1144     /// // Use a reborrow instead
1145     /// let ref_casted = unsafe { &mut *ptr };
1146     /// ```
1147     ///
1148     /// Turning an `&mut T` into an `&mut U`:
1149     ///
1150     /// ```
1151     /// let ptr = &mut 0;
1152     /// let val_transmuted = unsafe {
1153     ///     std::mem::transmute::<&mut i32, &mut u32>(ptr)
1154     /// };
1155     ///
1156     /// // Now, put together `as` and reborrowing - note the chaining of `as`
1157     /// // `as` is not transitive
1158     /// let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) };
1159     /// ```
1160     ///
1161     /// Turning an `&str` into an `&[u8]`:
1162     ///
1163     /// ```
1164     /// // this is not a good way to do this.
1165     /// let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") };
1166     /// assert_eq!(slice, &[82, 117, 115, 116]);
1167     ///
1168     /// // You could use `str::as_bytes`
1169     /// let slice = "Rust".as_bytes();
1170     /// assert_eq!(slice, &[82, 117, 115, 116]);
1171     ///
1172     /// // Or, just use a byte string, if you have control over the string
1173     /// // literal
1174     /// assert_eq!(b"Rust", &[82, 117, 115, 116]);
1175     /// ```
1176     ///
1177     /// Turning a `Vec<&T>` into a `Vec<Option<&T>>`:
1178     ///
1179     /// ```
1180     /// let store = [0, 1, 2, 3];
1181     /// let v_orig = store.iter().collect::<Vec<&i32>>();
1182     ///
1183     /// // clone the vector as we will reuse them later
1184     /// let v_clone = v_orig.clone();
1185     ///
1186     /// // Using transmute: this relies on the unspecified data layout of `Vec`, which is a
1187     /// // bad idea and could cause Undefined Behavior.
1188     /// // However, it is no-copy.
1189     /// let v_transmuted = unsafe {
1190     ///     std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone)
1191     /// };
1192     ///
1193     /// let v_clone = v_orig.clone();
1194     ///
1195     /// // This is the suggested, safe way.
1196     /// // It does copy the entire vector, though, into a new array.
1197     /// let v_collected = v_clone.into_iter()
1198     ///                          .map(Some)
1199     ///                          .collect::<Vec<Option<&i32>>>();
1200     ///
1201     /// let v_clone = v_orig.clone();
1202     ///
1203     /// // The no-copy, unsafe way, still using transmute, but not relying on the data layout.
1204     /// // Like the first approach, this reuses the `Vec` internals.
1205     /// // Therefore, the new inner type must have the
1206     /// // exact same size, *and the same alignment*, as the old type.
1207     /// // The same caveats exist for this method as transmute, for
1208     /// // the original inner type (`&i32`) to the converted inner type
1209     /// // (`Option<&i32>`), so read the nomicon pages linked above and also
1210     /// // consult the [`from_raw_parts`] documentation.
1211     /// let v_from_raw = unsafe {
1212     // FIXME Update this when vec_into_raw_parts is stabilized
1213     ///     // Ensure the original vector is not dropped.
1214     ///     let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
1215     ///     Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
1216     ///                         v_clone.len(),
1217     ///                         v_clone.capacity())
1218     /// };
1219     /// ```
1220     ///
1221     /// [`from_raw_parts`]: ../../std/vec/struct.Vec.html#method.from_raw_parts
1222     ///
1223     /// Implementing `split_at_mut`:
1224     ///
1225     /// ```
1226     /// use std::{slice, mem};
1227     ///
1228     /// // There are multiple ways to do this, and there are multiple problems
1229     /// // with the following (transmute) way.
1230     /// fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize)
1231     ///                              -> (&mut [T], &mut [T]) {
1232     ///     let len = slice.len();
1233     ///     assert!(mid <= len);
1234     ///     unsafe {
1235     ///         let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
1236     ///         // first: transmute is not typesafe; all it checks is that T and
1237     ///         // U are of the same size. Second, right here, you have two
1238     ///         // mutable references pointing to the same memory.
1239     ///         (&mut slice[0..mid], &mut slice2[mid..len])
1240     ///     }
1241     /// }
1242     ///
1243     /// // This gets rid of the typesafety problems; `&mut *` will *only* give
1244     /// // you an `&mut T` from an `&mut T` or `*mut T`.
1245     /// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
1246     ///                          -> (&mut [T], &mut [T]) {
1247     ///     let len = slice.len();
1248     ///     assert!(mid <= len);
1249     ///     unsafe {
1250     ///         let slice2 = &mut *(slice as *mut [T]);
1251     ///         // however, you still have two mutable references pointing to
1252     ///         // the same memory.
1253     ///         (&mut slice[0..mid], &mut slice2[mid..len])
1254     ///     }
1255     /// }
1256     ///
1257     /// // This is how the standard library does it. This is the best method, if
1258     /// // you need to do something like this
1259     /// fn split_at_stdlib<T>(slice: &mut [T], mid: usize)
1260     ///                       -> (&mut [T], &mut [T]) {
1261     ///     let len = slice.len();
1262     ///     assert!(mid <= len);
1263     ///     unsafe {
1264     ///         let ptr = slice.as_mut_ptr();
1265     ///         // This now has three mutable references pointing at the same
1266     ///         // memory. `slice`, the rvalue ret.0, and the rvalue ret.1.
1267     ///         // `slice` is never used after `let ptr = ...`, and so one can
1268     ///         // treat it as "dead", and therefore, you only have two real
1269     ///         // mutable slices.
1270     ///         (slice::from_raw_parts_mut(ptr, mid),
1271     ///          slice::from_raw_parts_mut(ptr.add(mid), len - mid))
1272     ///     }
1273     /// }
1274     /// ```
1275     #[stable(feature = "rust1", since = "1.0.0")]
1276     #[rustc_const_unstable(feature = "const_transmute", issue = "53605")]
1277     pub fn transmute<T, U>(e: T) -> U;
1278
1279     /// Returns `true` if the actual type given as `T` requires drop
1280     /// glue; returns `false` if the actual type provided for `T`
1281     /// implements `Copy`.
1282     ///
1283     /// If the actual type neither requires drop glue nor implements
1284     /// `Copy`, then may return `true` or `false`.
1285     ///
1286     /// The stabilized version of this intrinsic is
1287     /// [`std::mem::needs_drop`](../../std/mem/fn.needs_drop.html).
1288     #[rustc_const_stable(feature = "const_needs_drop", since = "1.40.0")]
1289     pub fn needs_drop<T>() -> bool;
1290
1291     /// Calculates the offset from a pointer.
1292     ///
1293     /// This is implemented as an intrinsic to avoid converting to and from an
1294     /// integer, since the conversion would throw away aliasing information.
1295     ///
1296     /// # Safety
1297     ///
1298     /// Both the starting and resulting pointer must be either in bounds or one
1299     /// byte past the end of an allocated object. If either pointer is out of
1300     /// bounds or arithmetic overflow occurs then any further use of the
1301     /// returned value will result in undefined behavior.
1302     ///
1303     /// The stabilized version of this intrinsic is
1304     /// [`std::pointer::offset`](../../std/primitive.pointer.html#method.offset).
1305     pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
1306
1307     /// Calculates the offset from a pointer, potentially wrapping.
1308     ///
1309     /// This is implemented as an intrinsic to avoid converting to and from an
1310     /// integer, since the conversion inhibits certain optimizations.
1311     ///
1312     /// # Safety
1313     ///
1314     /// Unlike the `offset` intrinsic, this intrinsic does not restrict the
1315     /// resulting pointer to point into or one byte past the end of an allocated
1316     /// object, and it wraps with two's complement arithmetic. The resulting
1317     /// value is not necessarily valid to be used to actually access memory.
1318     ///
1319     /// The stabilized version of this intrinsic is
1320     /// [`std::pointer::wrapping_offset`](../../std/primitive.pointer.html#method.wrapping_offset).
1321     pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
1322
1323     /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
1324     /// a 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_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
1330     /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
1331     /// a size of `count` * `size_of::<T>()` and an alignment of
1332     /// `min_align_of::<T>()`
1333     ///
1334     /// The volatile parameter is set to `true`, so it will not be optimized out
1335     /// unless size is equal to zero.
1336     pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
1337     /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
1338     /// size of `count` * `size_of::<T>()` and an alignment of
1339     /// `min_align_of::<T>()`.
1340     ///
1341     /// The volatile parameter is set to `true`, so it will not be optimized out
1342     /// unless size is equal to zero.
1343     pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
1344
1345     /// Performs a volatile load from the `src` pointer.
1346     ///
1347     /// The stabilized version of this intrinsic is
1348     /// [`std::ptr::read_volatile`](../../std/ptr/fn.read_volatile.html).
1349     pub fn volatile_load<T>(src: *const T) -> T;
1350     /// Performs a volatile store to the `dst` pointer.
1351     ///
1352     /// The stabilized version of this intrinsic is
1353     /// [`std::ptr::write_volatile`](../../std/ptr/fn.write_volatile.html).
1354     pub fn volatile_store<T>(dst: *mut T, val: T);
1355
1356     /// Performs a volatile load from the `src` pointer
1357     /// The pointer is not required to be aligned.
1358     pub fn unaligned_volatile_load<T>(src: *const T) -> T;
1359     /// Performs a volatile store to the `dst` pointer.
1360     /// The pointer is not required to be aligned.
1361     pub fn unaligned_volatile_store<T>(dst: *mut T, val: T);
1362
1363     /// Returns the square root of an `f32`
1364     ///
1365     /// The stabilized version of this intrinsic is
1366     /// [`std::f32::sqrt`](../../std/primitive.f32.html#method.sqrt)
1367     pub fn sqrtf32(x: f32) -> f32;
1368     /// Returns the square root of an `f64`
1369     ///
1370     /// The stabilized version of this intrinsic is
1371     /// [`std::f64::sqrt`](../../std/primitive.f64.html#method.sqrt)
1372     pub fn sqrtf64(x: f64) -> f64;
1373
1374     /// Raises an `f32` to an integer power.
1375     ///
1376     /// The stabilized version of this intrinsic is
1377     /// [`std::f32::powi`](../../std/primitive.f32.html#method.powi)
1378     pub fn powif32(a: f32, x: i32) -> f32;
1379     /// Raises an `f64` to an integer power.
1380     ///
1381     /// The stabilized version of this intrinsic is
1382     /// [`std::f64::powi`](../../std/primitive.f64.html#method.powi)
1383     pub fn powif64(a: f64, x: i32) -> f64;
1384
1385     /// Returns the sine of an `f32`.
1386     ///
1387     /// The stabilized version of this intrinsic is
1388     /// [`std::f32::sin`](../../std/primitive.f32.html#method.sin)
1389     pub fn sinf32(x: f32) -> f32;
1390     /// Returns the sine of an `f64`.
1391     ///
1392     /// The stabilized version of this intrinsic is
1393     /// [`std::f64::sin`](../../std/primitive.f64.html#method.sin)
1394     pub fn sinf64(x: f64) -> f64;
1395
1396     /// Returns the cosine of an `f32`.
1397     ///
1398     /// The stabilized version of this intrinsic is
1399     /// [`std::f32::cos`](../../std/primitive.f32.html#method.cos)
1400     pub fn cosf32(x: f32) -> f32;
1401     /// Returns the cosine of an `f64`.
1402     ///
1403     /// The stabilized version of this intrinsic is
1404     /// [`std::f64::cos`](../../std/primitive.f64.html#method.cos)
1405     pub fn cosf64(x: f64) -> f64;
1406
1407     /// Raises an `f32` to an `f32` power.
1408     ///
1409     /// The stabilized version of this intrinsic is
1410     /// [`std::f32::powf`](../../std/primitive.f32.html#method.powf)
1411     pub fn powf32(a: f32, x: f32) -> f32;
1412     /// Raises an `f64` to an `f64` power.
1413     ///
1414     /// The stabilized version of this intrinsic is
1415     /// [`std::f64::powf`](../../std/primitive.f64.html#method.powf)
1416     pub fn powf64(a: f64, x: f64) -> f64;
1417
1418     /// Returns the exponential of an `f32`.
1419     ///
1420     /// The stabilized version of this intrinsic is
1421     /// [`std::f32::exp`](../../std/primitive.f32.html#method.exp)
1422     pub fn expf32(x: f32) -> f32;
1423     /// Returns the exponential of an `f64`.
1424     ///
1425     /// The stabilized version of this intrinsic is
1426     /// [`std::f64::exp`](../../std/primitive.f64.html#method.exp)
1427     pub fn expf64(x: f64) -> f64;
1428
1429     /// Returns 2 raised to the power of an `f32`.
1430     ///
1431     /// The stabilized version of this intrinsic is
1432     /// [`std::f32::exp2`](../../std/primitive.f32.html#method.exp2)
1433     pub fn exp2f32(x: f32) -> f32;
1434     /// Returns 2 raised to the power of an `f64`.
1435     ///
1436     /// The stabilized version of this intrinsic is
1437     /// [`std::f64::exp2`](../../std/primitive.f64.html#method.exp2)
1438     pub fn exp2f64(x: f64) -> f64;
1439
1440     /// Returns the natural logarithm of an `f32`.
1441     ///
1442     /// The stabilized version of this intrinsic is
1443     /// [`std::f32::ln`](../../std/primitive.f32.html#method.ln)
1444     pub fn logf32(x: f32) -> f32;
1445     /// Returns the natural logarithm of an `f64`.
1446     ///
1447     /// The stabilized version of this intrinsic is
1448     /// [`std::f64::ln`](../../std/primitive.f64.html#method.ln)
1449     pub fn logf64(x: f64) -> f64;
1450
1451     /// Returns the base 10 logarithm of an `f32`.
1452     ///
1453     /// The stabilized version of this intrinsic is
1454     /// [`std::f32::log10`](../../std/primitive.f32.html#method.log10)
1455     pub fn log10f32(x: f32) -> f32;
1456     /// Returns the base 10 logarithm of an `f64`.
1457     ///
1458     /// The stabilized version of this intrinsic is
1459     /// [`std::f64::log10`](../../std/primitive.f64.html#method.log10)
1460     pub fn log10f64(x: f64) -> f64;
1461
1462     /// Returns the base 2 logarithm of an `f32`.
1463     ///
1464     /// The stabilized version of this intrinsic is
1465     /// [`std::f32::log2`](../../std/primitive.f32.html#method.log2)
1466     pub fn log2f32(x: f32) -> f32;
1467     /// Returns the base 2 logarithm of an `f64`.
1468     ///
1469     /// The stabilized version of this intrinsic is
1470     /// [`std::f64::log2`](../../std/primitive.f64.html#method.log2)
1471     pub fn log2f64(x: f64) -> f64;
1472
1473     /// Returns `a * b + c` for `f32` values.
1474     ///
1475     /// The stabilized version of this intrinsic is
1476     /// [`std::f32::mul_add`](../../std/primitive.f32.html#method.mul_add)
1477     pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
1478     /// Returns `a * b + c` for `f64` values.
1479     ///
1480     /// The stabilized version of this intrinsic is
1481     /// [`std::f64::mul_add`](../../std/primitive.f64.html#method.mul_add)
1482     pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
1483
1484     /// Returns the absolute value of an `f32`.
1485     ///
1486     /// The stabilized version of this intrinsic is
1487     /// [`std::f32::abs`](../../std/primitive.f32.html#method.abs)
1488     pub fn fabsf32(x: f32) -> f32;
1489     /// Returns the absolute value of an `f64`.
1490     ///
1491     /// The stabilized version of this intrinsic is
1492     /// [`std::f64::abs`](../../std/primitive.f64.html#method.abs)
1493     pub fn fabsf64(x: f64) -> f64;
1494
1495     /// Returns the minimum of two `f32` values.
1496     ///
1497     /// The stabilized version of this intrinsic is
1498     /// [`std::f32::min`](../../std/primitive.f32.html#method.min)
1499     pub fn minnumf32(x: f32, y: f32) -> f32;
1500     /// Returns the minimum of two `f64` values.
1501     ///
1502     /// The stabilized version of this intrinsic is
1503     /// [`std::f64::min`](../../std/primitive.f64.html#method.min)
1504     pub fn minnumf64(x: f64, y: f64) -> f64;
1505     /// Returns the maximum of two `f32` values.
1506     ///
1507     /// The stabilized version of this intrinsic is
1508     /// [`std::f32::max`](../../std/primitive.f32.html#method.max)
1509     pub fn maxnumf32(x: f32, y: f32) -> f32;
1510     /// Returns the maximum of two `f64` values.
1511     ///
1512     /// The stabilized version of this intrinsic is
1513     /// [`std::f64::max`](../../std/primitive.f64.html#method.max)
1514     pub fn maxnumf64(x: f64, y: f64) -> f64;
1515
1516     /// Copies the sign from `y` to `x` for `f32` values.
1517     ///
1518     /// The stabilized version of this intrinsic is
1519     /// [`std::f32::copysign`](../../std/primitive.f32.html#method.copysign)
1520     pub fn copysignf32(x: f32, y: f32) -> f32;
1521     /// Copies the sign from `y` to `x` for `f64` values.
1522     ///
1523     /// The stabilized version of this intrinsic is
1524     /// [`std::f64::copysign`](../../std/primitive.f64.html#method.copysign)
1525     pub fn copysignf64(x: f64, y: f64) -> f64;
1526
1527     /// Returns the largest integer less than or equal to an `f32`.
1528     ///
1529     /// The stabilized version of this intrinsic is
1530     /// [`std::f32::floor`](../../std/primitive.f32.html#method.floor)
1531     pub fn floorf32(x: f32) -> f32;
1532     /// Returns the largest integer less than or equal to an `f64`.
1533     ///
1534     /// The stabilized version of this intrinsic is
1535     /// [`std::f64::floor`](../../std/primitive.f64.html#method.floor)
1536     pub fn floorf64(x: f64) -> f64;
1537
1538     /// Returns the smallest integer greater than or equal to an `f32`.
1539     ///
1540     /// The stabilized version of this intrinsic is
1541     /// [`std::f32::ceil`](../../std/primitive.f32.html#method.ceil)
1542     pub fn ceilf32(x: f32) -> f32;
1543     /// Returns the smallest integer greater than or equal to an `f64`.
1544     ///
1545     /// The stabilized version of this intrinsic is
1546     /// [`std::f64::ceil`](../../std/primitive.f64.html#method.ceil)
1547     pub fn ceilf64(x: f64) -> f64;
1548
1549     /// Returns the integer part of an `f32`.
1550     ///
1551     /// The stabilized version of this intrinsic is
1552     /// [`std::f32::trunc`](../../std/primitive.f32.html#method.trunc)
1553     pub fn truncf32(x: f32) -> f32;
1554     /// Returns the integer part of an `f64`.
1555     ///
1556     /// The stabilized version of this intrinsic is
1557     /// [`std::f64::trunc`](../../std/primitive.f64.html#method.trunc)
1558     pub fn truncf64(x: f64) -> f64;
1559
1560     /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
1561     /// if the argument is not an integer.
1562     pub fn rintf32(x: f32) -> f32;
1563     /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
1564     /// if the argument is not an integer.
1565     pub fn rintf64(x: f64) -> f64;
1566
1567     /// Returns the nearest integer to an `f32`.
1568     pub fn nearbyintf32(x: f32) -> f32;
1569     /// Returns the nearest integer to an `f64`.
1570     pub fn nearbyintf64(x: f64) -> f64;
1571
1572     /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
1573     ///
1574     /// The stabilized version of this intrinsic is
1575     /// [`std::f32::round`](../../std/primitive.f32.html#method.round)
1576     pub fn roundf32(x: f32) -> f32;
1577     /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
1578     ///
1579     /// The stabilized version of this intrinsic is
1580     /// [`std::f64::round`](../../std/primitive.f64.html#method.round)
1581     pub fn roundf64(x: f64) -> f64;
1582
1583     /// Float addition that allows optimizations based on algebraic rules.
1584     /// May assume inputs are finite.
1585     pub fn fadd_fast<T>(a: T, b: T) -> T;
1586
1587     /// Float subtraction that allows optimizations based on algebraic rules.
1588     /// May assume inputs are finite.
1589     pub fn fsub_fast<T>(a: T, b: T) -> T;
1590
1591     /// Float multiplication that allows optimizations based on algebraic rules.
1592     /// May assume inputs are finite.
1593     pub fn fmul_fast<T>(a: T, b: T) -> T;
1594
1595     /// Float division that allows optimizations based on algebraic rules.
1596     /// May assume inputs are finite.
1597     pub fn fdiv_fast<T>(a: T, b: T) -> T;
1598
1599     /// Float remainder that allows optimizations based on algebraic rules.
1600     /// May assume inputs are finite.
1601     pub fn frem_fast<T>(a: T, b: T) -> T;
1602
1603     /// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range
1604     /// (<https://github.com/rust-lang/rust/issues/10184>)
1605     /// This is under stabilization at <https://github.com/rust-lang/rust/issues/67058>
1606     pub fn float_to_int_approx_unchecked<Float, Int>(value: Float) -> Int;
1607
1608     /// Returns the number of bits set in an integer type `T`
1609     ///
1610     /// The stabilized versions of this intrinsic are available on the integer
1611     /// primitives via the `count_ones` method. For example,
1612     /// [`std::u32::count_ones`](../../std/primitive.u32.html#method.count_ones)
1613     #[rustc_const_stable(feature = "const_ctpop", since = "1.40.0")]
1614     pub fn ctpop<T>(x: T) -> T;
1615
1616     /// Returns the number of leading unset bits (zeroes) in an integer type `T`.
1617     ///
1618     /// The stabilized versions of this intrinsic are available on the integer
1619     /// primitives via the `leading_zeros` method. For example,
1620     /// [`std::u32::leading_zeros`](../../std/primitive.u32.html#method.leading_zeros)
1621     ///
1622     /// # Examples
1623     ///
1624     /// ```
1625     /// #![feature(core_intrinsics)]
1626     ///
1627     /// use std::intrinsics::ctlz;
1628     ///
1629     /// let x = 0b0001_1100_u8;
1630     /// let num_leading = ctlz(x);
1631     /// assert_eq!(num_leading, 3);
1632     /// ```
1633     ///
1634     /// An `x` with value `0` will return the bit width of `T`.
1635     ///
1636     /// ```
1637     /// #![feature(core_intrinsics)]
1638     ///
1639     /// use std::intrinsics::ctlz;
1640     ///
1641     /// let x = 0u16;
1642     /// let num_leading = ctlz(x);
1643     /// assert_eq!(num_leading, 16);
1644     /// ```
1645     #[rustc_const_stable(feature = "const_ctlz", since = "1.40.0")]
1646     pub fn ctlz<T>(x: T) -> T;
1647
1648     /// Like `ctlz`, but extra-unsafe as it returns `undef` when
1649     /// given an `x` with value `0`.
1650     ///
1651     /// # Examples
1652     ///
1653     /// ```
1654     /// #![feature(core_intrinsics)]
1655     ///
1656     /// use std::intrinsics::ctlz_nonzero;
1657     ///
1658     /// let x = 0b0001_1100_u8;
1659     /// let num_leading = unsafe { ctlz_nonzero(x) };
1660     /// assert_eq!(num_leading, 3);
1661     /// ```
1662     #[rustc_const_unstable(feature = "constctlz", issue = "none")]
1663     pub fn ctlz_nonzero<T>(x: T) -> T;
1664
1665     /// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
1666     ///
1667     /// The stabilized versions of this intrinsic are available on the integer
1668     /// primitives via the `trailing_zeros` method. For example,
1669     /// [`std::u32::trailing_zeros`](../../std/primitive.u32.html#method.trailing_zeros)
1670     ///
1671     /// # Examples
1672     ///
1673     /// ```
1674     /// #![feature(core_intrinsics)]
1675     ///
1676     /// use std::intrinsics::cttz;
1677     ///
1678     /// let x = 0b0011_1000_u8;
1679     /// let num_trailing = cttz(x);
1680     /// assert_eq!(num_trailing, 3);
1681     /// ```
1682     ///
1683     /// An `x` with value `0` will return the bit width of `T`:
1684     ///
1685     /// ```
1686     /// #![feature(core_intrinsics)]
1687     ///
1688     /// use std::intrinsics::cttz;
1689     ///
1690     /// let x = 0u16;
1691     /// let num_trailing = cttz(x);
1692     /// assert_eq!(num_trailing, 16);
1693     /// ```
1694     #[rustc_const_stable(feature = "const_cttz", since = "1.40.0")]
1695     pub fn cttz<T>(x: T) -> T;
1696
1697     /// Like `cttz`, but extra-unsafe as it returns `undef` when
1698     /// given an `x` with value `0`.
1699     ///
1700     /// # Examples
1701     ///
1702     /// ```
1703     /// #![feature(core_intrinsics)]
1704     ///
1705     /// use std::intrinsics::cttz_nonzero;
1706     ///
1707     /// let x = 0b0011_1000_u8;
1708     /// let num_trailing = unsafe { cttz_nonzero(x) };
1709     /// assert_eq!(num_trailing, 3);
1710     /// ```
1711     #[rustc_const_unstable(feature = "const_cttz", issue = "none")]
1712     pub fn cttz_nonzero<T>(x: T) -> T;
1713
1714     /// Reverses the bytes in an integer type `T`.
1715     ///
1716     /// The stabilized versions of this intrinsic are available on the integer
1717     /// primitives via the `swap_bytes` method. For example,
1718     /// [`std::u32::swap_bytes`](../../std/primitive.u32.html#method.swap_bytes)
1719     #[rustc_const_stable(feature = "const_bswap", since = "1.40.0")]
1720     pub fn bswap<T>(x: T) -> T;
1721
1722     /// Reverses the bits in an integer type `T`.
1723     ///
1724     /// The stabilized versions of this intrinsic are available on the integer
1725     /// primitives via the `reverse_bits` method. For example,
1726     /// [`std::u32::reverse_bits`](../../std/primitive.u32.html#method.reverse_bits)
1727     #[rustc_const_stable(feature = "const_bitreverse", since = "1.40.0")]
1728     pub fn bitreverse<T>(x: T) -> T;
1729
1730     /// Performs checked integer addition.
1731     ///
1732     /// The stabilized versions of this intrinsic are available on the integer
1733     /// primitives via the `overflowing_add` method. For example,
1734     /// [`std::u32::overflowing_add`](../../std/primitive.u32.html#method.overflowing_add)
1735     #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1736     pub fn add_with_overflow<T>(x: T, y: T) -> (T, bool);
1737
1738     /// Performs checked integer subtraction
1739     ///
1740     /// The stabilized versions of this intrinsic are available on the integer
1741     /// primitives via the `overflowing_sub` method. For example,
1742     /// [`std::u32::overflowing_sub`](../../std/primitive.u32.html#method.overflowing_sub)
1743     #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1744     pub fn sub_with_overflow<T>(x: T, y: T) -> (T, bool);
1745
1746     /// Performs checked integer multiplication
1747     ///
1748     /// The stabilized versions of this intrinsic are available on the integer
1749     /// primitives via the `overflowing_mul` method. For example,
1750     /// [`std::u32::overflowing_mul`](../../std/primitive.u32.html#method.overflowing_mul)
1751     #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1752     pub fn mul_with_overflow<T>(x: T, y: T) -> (T, bool);
1753
1754     /// Performs an exact division, resulting in undefined behavior where
1755     /// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`
1756     pub fn exact_div<T>(x: T, y: T) -> T;
1757
1758     /// Performs an unchecked division, resulting in undefined behavior
1759     /// where y = 0 or x = `T::min_value()` and y = -1
1760     ///
1761     /// The stabilized versions of this intrinsic are available on the integer
1762     /// primitives via the `checked_div` method. For example,
1763     /// [`std::u32::checked_div`](../../std/primitive.u32.html#method.checked_div)
1764     #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1765     pub fn unchecked_div<T>(x: T, y: T) -> T;
1766     /// Returns the remainder of an unchecked division, resulting in
1767     /// undefined behavior where y = 0 or x = `T::min_value()` and y = -1
1768     ///
1769     /// The stabilized versions of this intrinsic are available on the integer
1770     /// primitives via the `checked_rem` method. For example,
1771     /// [`std::u32::checked_rem`](../../std/primitive.u32.html#method.checked_rem)
1772     #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1773     pub fn unchecked_rem<T>(x: T, y: T) -> T;
1774
1775     /// Performs an unchecked left shift, resulting in undefined behavior when
1776     /// y < 0 or y >= N, where N is the width of T in bits.
1777     ///
1778     /// The stabilized versions of this intrinsic are available on the integer
1779     /// primitives via the `checked_shl` method. For example,
1780     /// [`std::u32::checked_shl`](../../std/primitive.u32.html#method.checked_shl)
1781     #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1782     pub fn unchecked_shl<T>(x: T, y: T) -> T;
1783     /// Performs an unchecked right shift, resulting in undefined behavior when
1784     /// y < 0 or y >= N, where N is the width of T in bits.
1785     ///
1786     /// The stabilized versions of this intrinsic are available on the integer
1787     /// primitives via the `checked_shr` method. For example,
1788     /// [`std::u32::checked_shr`](../../std/primitive.u32.html#method.checked_shr)
1789     #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1790     pub fn unchecked_shr<T>(x: T, y: T) -> T;
1791
1792     /// Returns the result of an unchecked addition, resulting in
1793     /// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`.
1794     #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1795     pub fn unchecked_add<T>(x: T, y: T) -> T;
1796
1797     /// Returns the result of an unchecked subtraction, resulting in
1798     /// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`.
1799     #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1800     pub fn unchecked_sub<T>(x: T, y: T) -> T;
1801
1802     /// Returns the result of an unchecked multiplication, resulting in
1803     /// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`.
1804     #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1805     pub fn unchecked_mul<T>(x: T, y: T) -> T;
1806
1807     /// Performs rotate left.
1808     ///
1809     /// The stabilized versions of this intrinsic are available on the integer
1810     /// primitives via the `rotate_left` method. For example,
1811     /// [`std::u32::rotate_left`](../../std/primitive.u32.html#method.rotate_left)
1812     #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1813     pub fn rotate_left<T>(x: T, y: T) -> T;
1814
1815     /// Performs rotate right.
1816     ///
1817     /// The stabilized versions of this intrinsic are available on the integer
1818     /// primitives via the `rotate_right` method. For example,
1819     /// [`std::u32::rotate_right`](../../std/primitive.u32.html#method.rotate_right)
1820     #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1821     pub fn rotate_right<T>(x: T, y: T) -> T;
1822
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_add` method. For example,
1827     /// [`std::u32::checked_add`](../../std/primitive.u32.html#method.checked_add)
1828     #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1829     pub fn wrapping_add<T>(a: T, b: T) -> T;
1830     /// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
1831     ///
1832     /// The stabilized versions of this intrinsic are available on the integer
1833     /// primitives via the `checked_sub` method. For example,
1834     /// [`std::u32::checked_sub`](../../std/primitive.u32.html#method.checked_sub)
1835     #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1836     pub fn wrapping_sub<T>(a: T, b: T) -> T;
1837     /// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
1838     ///
1839     /// The stabilized versions of this intrinsic are available on the integer
1840     /// primitives via the `checked_mul` method. For example,
1841     /// [`std::u32::checked_mul`](../../std/primitive.u32.html#method.checked_mul)
1842     #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1843     pub fn wrapping_mul<T>(a: T, b: T) -> T;
1844
1845     /// Computes `a + b`, while saturating at numeric bounds.
1846     ///
1847     /// The stabilized versions of this intrinsic are available on the integer
1848     /// primitives via the `saturating_add` method. For example,
1849     /// [`std::u32::saturating_add`](../../std/primitive.u32.html#method.saturating_add)
1850     #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1851     pub fn saturating_add<T>(a: T, b: T) -> T;
1852     /// Computes `a - b`, while saturating at numeric bounds.
1853     ///
1854     /// The stabilized versions of this intrinsic are available on the integer
1855     /// primitives via the `saturating_sub` method. For example,
1856     /// [`std::u32::saturating_sub`](../../std/primitive.u32.html#method.saturating_sub)
1857     #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1858     pub fn saturating_sub<T>(a: T, b: T) -> T;
1859
1860     /// Returns the value of the discriminant for the variant in 'v',
1861     /// cast to a `u64`; if `T` has no discriminant, returns 0.
1862     ///
1863     /// The stabilized version of this intrinsic is
1864     /// [`std::mem::discriminant`](../../std/mem/fn.discriminant.html)
1865     pub fn discriminant_value<T>(v: &T) -> u64;
1866
1867     /// Rust's "try catch" construct which invokes the function pointer `f` with
1868     /// the data pointer `data`.
1869     ///
1870     /// The third pointer is a target-specific data pointer which is filled in
1871     /// with the specifics of the exception that occurred. For examples on Unix
1872     /// platforms this is a `*mut *mut T` which is filled in by the compiler and
1873     /// on MSVC it's `*mut [usize; 2]`. For more information see the compiler's
1874     /// source as well as std's catch implementation.
1875     pub fn r#try(f: fn(*mut u8), data: *mut u8, local_ptr: *mut u8) -> i32;
1876
1877     /// Emits a `!nontemporal` store according to LLVM (see their docs).
1878     /// Probably will never become stable.
1879     pub fn nontemporal_store<T>(ptr: *mut T, val: T);
1880
1881     /// See documentation of `<*const T>::offset_from` for details.
1882     #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "none")]
1883     pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
1884
1885     /// Internal hook used by Miri to implement unwinding.
1886     /// Compiles to a NOP during non-Miri codegen.
1887     ///
1888     /// Perma-unstable: do not use
1889     pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> ();
1890 }
1891
1892 // Some functions are defined here because they accidentally got made
1893 // available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
1894 // (`transmute` also falls into this category, but it cannot be wrapped due to the
1895 // check that `T` and `U` have the same size.)
1896
1897 /// Checks whether `ptr` is properly aligned with respect to
1898 /// `align_of::<T>()`.
1899 pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
1900     !ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0
1901 }
1902
1903 /// Checks whether the regions of memory starting at `src` and `dst` of size
1904 /// `count * size_of::<T>()` do *not* overlap.
1905 pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
1906     let src_usize = src as usize;
1907     let dst_usize = dst as usize;
1908     let size = mem::size_of::<T>().checked_mul(count).unwrap();
1909     let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
1910     // If the absolute distance between the ptrs is at least as big as the size of the buffer,
1911     // they do not overlap.
1912     diff >= size
1913 }
1914
1915 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
1916 /// and destination must *not* overlap.
1917 ///
1918 /// For regions of memory which might overlap, use [`copy`] instead.
1919 ///
1920 /// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
1921 /// with the argument order swapped.
1922 ///
1923 /// [`copy`]: ./fn.copy.html
1924 /// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy
1925 ///
1926 /// # Safety
1927 ///
1928 /// Behavior is undefined if any of the following conditions are violated:
1929 ///
1930 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
1931 ///
1932 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
1933 ///
1934 /// * Both `src` and `dst` must be properly aligned.
1935 ///
1936 /// * The region of memory beginning at `src` with a size of `count *
1937 ///   size_of::<T>()` bytes must *not* overlap with the region of memory
1938 ///   beginning at `dst` with the same size.
1939 ///
1940 /// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of
1941 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values
1942 /// in the region beginning at `*src` and the region beginning at `*dst` can
1943 /// [violate memory safety][read-ownership].
1944 ///
1945 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
1946 /// `0`, the pointers must be non-NULL and properly aligned.
1947 ///
1948 /// [`Copy`]: ../marker/trait.Copy.html
1949 /// [`read`]: ../ptr/fn.read.html
1950 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
1951 /// [valid]: ../ptr/index.html#safety
1952 ///
1953 /// # Examples
1954 ///
1955 /// Manually implement [`Vec::append`]:
1956 ///
1957 /// ```
1958 /// use std::ptr;
1959 ///
1960 /// /// Moves all the elements of `src` into `dst`, leaving `src` empty.
1961 /// fn append<T>(dst: &mut Vec<T>, src: &mut Vec<T>) {
1962 ///     let src_len = src.len();
1963 ///     let dst_len = dst.len();
1964 ///
1965 ///     // Ensure that `dst` has enough capacity to hold all of `src`.
1966 ///     dst.reserve(src_len);
1967 ///
1968 ///     unsafe {
1969 ///         // The call to offset is always safe because `Vec` will never
1970 ///         // allocate more than `isize::MAX` bytes.
1971 ///         let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize);
1972 ///         let src_ptr = src.as_ptr();
1973 ///
1974 ///         // Truncate `src` without dropping its contents. We do this first,
1975 ///         // to avoid problems in case something further down panics.
1976 ///         src.set_len(0);
1977 ///
1978 ///         // The two regions cannot overlap because mutable references do
1979 ///         // not alias, and two different vectors cannot own the same
1980 ///         // memory.
1981 ///         ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
1982 ///
1983 ///         // Notify `dst` that it now holds the contents of `src`.
1984 ///         dst.set_len(dst_len + src_len);
1985 ///     }
1986 /// }
1987 ///
1988 /// let mut a = vec!['r'];
1989 /// let mut b = vec!['u', 's', 't'];
1990 ///
1991 /// append(&mut a, &mut b);
1992 ///
1993 /// assert_eq!(a, &['r', 'u', 's', 't']);
1994 /// assert!(b.is_empty());
1995 /// ```
1996 ///
1997 /// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append
1998 #[doc(alias = "memcpy")]
1999 #[stable(feature = "rust1", since = "1.0.0")]
2000 #[inline]
2001 pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
2002     extern "rust-intrinsic" {
2003         fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
2004     }
2005
2006     debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer");
2007     debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer");
2008     debug_assert!(is_nonoverlapping(src, dst, count), "attempt to copy to overlapping memory");
2009     copy_nonoverlapping(src, dst, count)
2010 }
2011
2012 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
2013 /// and destination may overlap.
2014 ///
2015 /// If the source and destination will *never* overlap,
2016 /// [`copy_nonoverlapping`] can be used instead.
2017 ///
2018 /// `copy` is semantically equivalent to C's [`memmove`], but with the argument
2019 /// order swapped. Copying takes place as if the bytes were copied from `src`
2020 /// to a temporary array and then copied from the array to `dst`.
2021 ///
2022 /// [`copy_nonoverlapping`]: ./fn.copy_nonoverlapping.html
2023 /// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove
2024 ///
2025 /// # Safety
2026 ///
2027 /// Behavior is undefined if any of the following conditions are violated:
2028 ///
2029 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
2030 ///
2031 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2032 ///
2033 /// * Both `src` and `dst` must be properly aligned.
2034 ///
2035 /// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of
2036 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the values
2037 /// in the region beginning at `*src` and the region beginning at `*dst` can
2038 /// [violate memory safety][read-ownership].
2039 ///
2040 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2041 /// `0`, the pointers must be non-NULL and properly aligned.
2042 ///
2043 /// [`Copy`]: ../marker/trait.Copy.html
2044 /// [`read`]: ../ptr/fn.read.html
2045 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
2046 /// [valid]: ../ptr/index.html#safety
2047 ///
2048 /// # Examples
2049 ///
2050 /// Efficiently create a Rust vector from an unsafe buffer:
2051 ///
2052 /// ```
2053 /// use std::ptr;
2054 ///
2055 /// # #[allow(dead_code)]
2056 /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
2057 ///     let mut dst = Vec::with_capacity(elts);
2058 ///     dst.set_len(elts);
2059 ///     ptr::copy(ptr, dst.as_mut_ptr(), elts);
2060 ///     dst
2061 /// }
2062 /// ```
2063 #[doc(alias = "memmove")]
2064 #[stable(feature = "rust1", since = "1.0.0")]
2065 #[inline]
2066 pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
2067     extern "rust-intrinsic" {
2068         fn copy<T>(src: *const T, dst: *mut T, count: usize);
2069     }
2070
2071     debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer");
2072     debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer");
2073     copy(src, dst, count)
2074 }
2075
2076 /// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
2077 /// `val`.
2078 ///
2079 /// `write_bytes` is similar to C's [`memset`], but sets `count *
2080 /// size_of::<T>()` bytes to `val`.
2081 ///
2082 /// [`memset`]: https://en.cppreference.com/w/c/string/byte/memset
2083 ///
2084 /// # Safety
2085 ///
2086 /// Behavior is undefined if any of the following conditions are violated:
2087 ///
2088 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2089 ///
2090 /// * `dst` must be properly aligned.
2091 ///
2092 /// Additionally, the caller must ensure that writing `count *
2093 /// size_of::<T>()` bytes to the given region of memory results in a valid
2094 /// value of `T`. Using a region of memory typed as a `T` that contains an
2095 /// invalid value of `T` is undefined behavior.
2096 ///
2097 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2098 /// `0`, the pointer must be non-NULL and properly aligned.
2099 ///
2100 /// [valid]: ../ptr/index.html#safety
2101 ///
2102 /// # Examples
2103 ///
2104 /// Basic usage:
2105 ///
2106 /// ```
2107 /// use std::ptr;
2108 ///
2109 /// let mut vec = vec![0u32; 4];
2110 /// unsafe {
2111 ///     let vec_ptr = vec.as_mut_ptr();
2112 ///     ptr::write_bytes(vec_ptr, 0xfe, 2);
2113 /// }
2114 /// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
2115 /// ```
2116 ///
2117 /// Creating an invalid value:
2118 ///
2119 /// ```
2120 /// use std::ptr;
2121 ///
2122 /// let mut v = Box::new(0i32);
2123 ///
2124 /// unsafe {
2125 ///     // Leaks the previously held value by overwriting the `Box<T>` with
2126 ///     // a null pointer.
2127 ///     ptr::write_bytes(&mut v as *mut Box<i32>, 0, 1);
2128 /// }
2129 ///
2130 /// // At this point, using or dropping `v` results in undefined behavior.
2131 /// // drop(v); // ERROR
2132 ///
2133 /// // Even leaking `v` "uses" it, and hence is undefined behavior.
2134 /// // mem::forget(v); // ERROR
2135 ///
2136 /// // In fact, `v` is invalid according to basic type layout invariants, so *any*
2137 /// // operation touching it is undefined behavior.
2138 /// // let v2 = v; // ERROR
2139 ///
2140 /// unsafe {
2141 ///     // Let us instead put in a valid value
2142 ///     ptr::write(&mut v as *mut Box<i32>, Box::new(42i32));
2143 /// }
2144 ///
2145 /// // Now the box is fine
2146 /// assert_eq!(*v, 42);
2147 /// ```
2148 #[stable(feature = "rust1", since = "1.0.0")]
2149 #[inline]
2150 pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
2151     extern "rust-intrinsic" {
2152         fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
2153     }
2154
2155     debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer");
2156     write_bytes(dst, val, count)
2157 }