]> git.lizzy.rs Git - rust.git/blob - src/libcore/intrinsics.rs
eebb98b5e6d4580727bb8ceacab2204029e897ca
[rust.git] / src / libcore / intrinsics.rs
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! rustc compiler intrinsics.
12 //!
13 //! The corresponding definitions are in librustc_codegen_llvm/intrinsic.rs.
14 //!
15 //! # Volatiles
16 //!
17 //! The volatile intrinsics provide operations intended to act on I/O
18 //! memory, which are guaranteed to not be reordered by the compiler
19 //! across other volatile intrinsics. See the LLVM documentation on
20 //! [[volatile]].
21 //!
22 //! [volatile]: http://llvm.org/docs/LangRef.html#volatile-memory-accesses
23 //!
24 //! # Atomics
25 //!
26 //! The atomic intrinsics provide common atomic operations on machine
27 //! words, with multiple possible memory orderings. They obey the same
28 //! semantics as C++11. See the LLVM documentation on [[atomics]].
29 //!
30 //! [atomics]: http://llvm.org/docs/Atomics.html
31 //!
32 //! A quick refresher on memory ordering:
33 //!
34 //! * Acquire - a barrier for acquiring a lock. Subsequent reads and writes
35 //!   take place after the barrier.
36 //! * Release - a barrier for releasing a lock. Preceding reads and writes
37 //!   take place before the barrier.
38 //! * Sequentially consistent - sequentially consistent operations are
39 //!   guaranteed to happen in order. This is the standard mode for working
40 //!   with atomic types and is equivalent to Java's `volatile`.
41
42 #![unstable(feature = "core_intrinsics",
43             reason = "intrinsics are unlikely to ever be stabilized, instead \
44                       they should be used through stabilized interfaces \
45                       in the rest of the standard library",
46             issue = "0")]
47 #![allow(missing_docs)]
48
49 #[stable(feature = "drop_in_place", since = "1.8.0")]
50 #[rustc_deprecated(reason = "no longer an intrinsic - use `ptr::drop_in_place` directly",
51                    since = "1.18.0")]
52 pub use ptr::drop_in_place;
53
54 extern "rust-intrinsic" {
55     // N.B., these intrinsics take raw pointers because they mutate aliased
56     // memory, which is not valid for either `&` or `&mut`.
57
58     /// Stores a value if the current value is the same as the `old` value.
59     /// The stabilized version of this intrinsic is available on the
60     /// `std::sync::atomic` types via the `compare_exchange` method by passing
61     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
62     /// as both the `success` and `failure` parameters. For example,
63     /// [`AtomicBool::compare_exchange`][compare_exchange].
64     ///
65     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
66     pub fn atomic_cxchg<T>(dst: *mut T, old: T, src: T) -> (T, bool);
67     /// Stores a value if the current value is the same as the `old` value.
68     /// The stabilized version of this intrinsic is available on the
69     /// `std::sync::atomic` types via the `compare_exchange` method by passing
70     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
71     /// as both the `success` and `failure` parameters. For example,
72     /// [`AtomicBool::compare_exchange`][compare_exchange].
73     ///
74     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
75     pub fn atomic_cxchg_acq<T>(dst: *mut T, old: T, src: T) -> (T, bool);
76     /// Stores a value if the current value is the same as the `old` value.
77     /// The stabilized version of this intrinsic is available on the
78     /// `std::sync::atomic` types via the `compare_exchange` method by passing
79     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
80     /// as the `success` and
81     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
82     /// as the `failure` parameters. For example,
83     /// [`AtomicBool::compare_exchange`][compare_exchange].
84     ///
85     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
86     pub fn atomic_cxchg_rel<T>(dst: *mut T, old: T, src: T) -> (T, bool);
87     /// Stores a value if the current value is the same as the `old` value.
88     /// The stabilized version of this intrinsic is available on the
89     /// `std::sync::atomic` types via the `compare_exchange` method by passing
90     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
91     /// as the `success` and
92     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
93     /// as the `failure` parameters. For example,
94     /// [`AtomicBool::compare_exchange`][compare_exchange].
95     ///
96     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
97     pub fn atomic_cxchg_acqrel<T>(dst: *mut T, old: T, src: T) -> (T, bool);
98     /// Stores a value if the current value is the same as the `old` value.
99     /// The stabilized version of this intrinsic is available on the
100     /// `std::sync::atomic` types via the `compare_exchange` method by passing
101     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
102     /// as both the `success` and `failure` parameters. For example,
103     /// [`AtomicBool::compare_exchange`][compare_exchange].
104     ///
105     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
106     pub fn atomic_cxchg_relaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
107     /// Stores a value if the current value is the same as the `old` value.
108     /// The stabilized version of this intrinsic is available on the
109     /// `std::sync::atomic` types via the `compare_exchange` method by passing
110     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
111     /// as the `success` and
112     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
113     /// as the `failure` parameters. For example,
114     /// [`AtomicBool::compare_exchange`][compare_exchange].
115     ///
116     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
117     pub fn atomic_cxchg_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
118     /// Stores a value if the current value is the same as the `old` value.
119     /// The stabilized version of this intrinsic is available on the
120     /// `std::sync::atomic` types via the `compare_exchange` method by passing
121     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
122     /// as the `success` and
123     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
124     /// as the `failure` parameters. For example,
125     /// [`AtomicBool::compare_exchange`][compare_exchange].
126     ///
127     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
128     pub fn atomic_cxchg_failacq<T>(dst: *mut T, old: T, src: T) -> (T, bool);
129     /// Stores a value if the current value is the same as the `old` value.
130     /// The stabilized version of this intrinsic is available on the
131     /// `std::sync::atomic` types via the `compare_exchange` method by passing
132     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
133     /// as the `success` and
134     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
135     /// as the `failure` parameters. For example,
136     /// [`AtomicBool::compare_exchange`][compare_exchange].
137     ///
138     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
139     pub fn atomic_cxchg_acq_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
140     /// Stores a value if the current value is the same as the `old` value.
141     /// The stabilized version of this intrinsic is available on the
142     /// `std::sync::atomic` types via the `compare_exchange` method by passing
143     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
144     /// as the `success` and
145     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
146     /// as the `failure` parameters. For example,
147     /// [`AtomicBool::compare_exchange`][compare_exchange].
148     ///
149     /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
150     pub fn atomic_cxchg_acqrel_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
151
152     /// Stores a value if the current value is the same as the `old` value.
153     /// The stabilized version of this intrinsic is available on the
154     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
155     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
156     /// as both the `success` and `failure` parameters. For example,
157     /// [`AtomicBool::compare_exchange_weak`][cew].
158     ///
159     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
160     pub fn atomic_cxchgweak<T>(dst: *mut T, old: T, src: T) -> (T, bool);
161     /// Stores a value if the current value is the same as the `old` value.
162     /// The stabilized version of this intrinsic is available on the
163     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
164     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
165     /// as both the `success` and `failure` parameters. For example,
166     /// [`AtomicBool::compare_exchange_weak`][cew].
167     ///
168     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
169     pub fn atomic_cxchgweak_acq<T>(dst: *mut T, old: T, src: T) -> (T, bool);
170     /// Stores a value if the current value is the same as the `old` value.
171     /// The stabilized version of this intrinsic is available on the
172     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
173     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
174     /// as the `success` and
175     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
176     /// as the `failure` parameters. For example,
177     /// [`AtomicBool::compare_exchange_weak`][cew].
178     ///
179     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
180     pub fn atomic_cxchgweak_rel<T>(dst: *mut T, old: T, src: T) -> (T, bool);
181     /// Stores a value if the current value is the same as the `old` value.
182     /// The stabilized version of this intrinsic is available on the
183     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
184     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
185     /// as the `success` and
186     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
187     /// as the `failure` parameters. For example,
188     /// [`AtomicBool::compare_exchange_weak`][cew].
189     ///
190     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
191     pub fn atomic_cxchgweak_acqrel<T>(dst: *mut T, old: T, src: T) -> (T, bool);
192     /// Stores a value if the current value is the same as the `old` value.
193     /// The stabilized version of this intrinsic is available on the
194     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
195     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
196     /// as both the `success` and `failure` parameters. For example,
197     /// [`AtomicBool::compare_exchange_weak`][cew].
198     ///
199     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
200     pub fn atomic_cxchgweak_relaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
201     /// Stores a value if the current value is the same as the `old` value.
202     /// The stabilized version of this intrinsic is available on the
203     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
204     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
205     /// as the `success` and
206     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
207     /// as the `failure` parameters. For example,
208     /// [`AtomicBool::compare_exchange_weak`][cew].
209     ///
210     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
211     pub fn atomic_cxchgweak_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
212     /// Stores a value if the current value is the same as the `old` value.
213     /// The stabilized version of this intrinsic is available on the
214     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
215     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
216     /// as the `success` and
217     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
218     /// as the `failure` parameters. For example,
219     /// [`AtomicBool::compare_exchange_weak`][cew].
220     ///
221     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
222     pub fn atomic_cxchgweak_failacq<T>(dst: *mut T, old: T, src: T) -> (T, bool);
223     /// Stores a value if the current value is the same as the `old` value.
224     /// The stabilized version of this intrinsic is available on the
225     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
226     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
227     /// as the `success` and
228     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
229     /// as the `failure` parameters. For example,
230     /// [`AtomicBool::compare_exchange_weak`][cew].
231     ///
232     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
233     pub fn atomic_cxchgweak_acq_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
234     /// Stores a value if the current value is the same as the `old` value.
235     /// The stabilized version of this intrinsic is available on the
236     /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
237     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
238     /// as the `success` and
239     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
240     /// as the `failure` parameters. For example,
241     /// [`AtomicBool::compare_exchange_weak`][cew].
242     ///
243     /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
244     pub fn atomic_cxchgweak_acqrel_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
245
246     /// Loads the current value of the pointer.
247     /// The stabilized version of this intrinsic is available on the
248     /// `std::sync::atomic` types via the `load` method by passing
249     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
250     /// as the `order`. For example,
251     /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
252     pub fn atomic_load<T>(src: *const T) -> T;
253     /// Loads the current value of the pointer.
254     /// The stabilized version of this intrinsic is available on the
255     /// `std::sync::atomic` types via the `load` method by passing
256     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
257     /// as the `order`. For example,
258     /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
259     pub fn atomic_load_acq<T>(src: *const T) -> T;
260     /// Loads the current value of the pointer.
261     /// The stabilized version of this intrinsic is available on the
262     /// `std::sync::atomic` types via the `load` method by passing
263     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
264     /// as the `order`. For example,
265     /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
266     pub fn atomic_load_relaxed<T>(src: *const T) -> T;
267     pub fn atomic_load_unordered<T>(src: *const T) -> T;
268
269     /// Stores the value at the specified memory location.
270     /// The stabilized version of this intrinsic is available on the
271     /// `std::sync::atomic` types via the `store` method by passing
272     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
273     /// as the `order`. For example,
274     /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
275     pub fn atomic_store<T>(dst: *mut T, val: T);
276     /// Stores the value at the specified memory location.
277     /// The stabilized version of this intrinsic is available on the
278     /// `std::sync::atomic` types via the `store` method by passing
279     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
280     /// as the `order`. For example,
281     /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
282     pub fn atomic_store_rel<T>(dst: *mut T, val: T);
283     /// Stores the value at the specified memory location.
284     /// The stabilized version of this intrinsic is available on the
285     /// `std::sync::atomic` types via the `store` method by passing
286     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
287     /// as the `order`. For example,
288     /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
289     pub fn atomic_store_relaxed<T>(dst: *mut T, val: T);
290     pub fn atomic_store_unordered<T>(dst: *mut T, val: T);
291
292     /// Stores the value at the specified memory location, returning the old value.
293     /// The stabilized version of this intrinsic is available on the
294     /// `std::sync::atomic` types via the `swap` method by passing
295     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
296     /// as the `order`. For example,
297     /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
298     pub fn atomic_xchg<T>(dst: *mut T, src: T) -> T;
299     /// Stores the value at the specified memory location, returning the old value.
300     /// The stabilized version of this intrinsic is available on the
301     /// `std::sync::atomic` types via the `swap` method by passing
302     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
303     /// as the `order`. For example,
304     /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
305     pub fn atomic_xchg_acq<T>(dst: *mut T, src: T) -> T;
306     /// Stores the value at the specified memory location, returning the old value.
307     /// The stabilized version of this intrinsic is available on the
308     /// `std::sync::atomic` types via the `swap` method by passing
309     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
310     /// as the `order`. For example,
311     /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
312     pub fn atomic_xchg_rel<T>(dst: *mut T, src: T) -> T;
313     /// Stores the value at the specified memory location, returning the old value.
314     /// The stabilized version of this intrinsic is available on the
315     /// `std::sync::atomic` types via the `swap` method by passing
316     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
317     /// as the `order`. For example,
318     /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
319     pub fn atomic_xchg_acqrel<T>(dst: *mut T, src: T) -> T;
320     /// Stores the value at the specified memory location, returning the old value.
321     /// The stabilized version of this intrinsic is available on the
322     /// `std::sync::atomic` types via the `swap` method by passing
323     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
324     /// as the `order`. For example,
325     /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
326     pub fn atomic_xchg_relaxed<T>(dst: *mut T, src: T) -> T;
327
328     /// Add to the current value, returning the previous value.
329     /// The stabilized version of this intrinsic is available on the
330     /// `std::sync::atomic` types via the `fetch_add` method by passing
331     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
332     /// as the `order`. For example,
333     /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
334     pub fn atomic_xadd<T>(dst: *mut T, src: T) -> T;
335     /// Add to the current value, returning the previous value.
336     /// The stabilized version of this intrinsic is available on the
337     /// `std::sync::atomic` types via the `fetch_add` method by passing
338     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
339     /// as the `order`. For example,
340     /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
341     pub fn atomic_xadd_acq<T>(dst: *mut T, src: T) -> T;
342     /// Add to the current value, returning the previous value.
343     /// The stabilized version of this intrinsic is available on the
344     /// `std::sync::atomic` types via the `fetch_add` method by passing
345     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
346     /// as the `order`. For example,
347     /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
348     pub fn atomic_xadd_rel<T>(dst: *mut T, src: T) -> T;
349     /// Add to the current value, returning the previous value.
350     /// The stabilized version of this intrinsic is available on the
351     /// `std::sync::atomic` types via the `fetch_add` method by passing
352     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
353     /// as the `order`. For example,
354     /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
355     pub fn atomic_xadd_acqrel<T>(dst: *mut T, src: T) -> T;
356     /// Add to the current value, returning the previous value.
357     /// The stabilized version of this intrinsic is available on the
358     /// `std::sync::atomic` types via the `fetch_add` method by passing
359     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
360     /// as the `order`. For example,
361     /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
362     pub fn atomic_xadd_relaxed<T>(dst: *mut T, src: T) -> T;
363
364     /// Subtract from the current value, returning the previous value.
365     /// The stabilized version of this intrinsic is available on the
366     /// `std::sync::atomic` types via the `fetch_sub` method by passing
367     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
368     /// as the `order`. For example,
369     /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
370     pub fn atomic_xsub<T>(dst: *mut T, src: T) -> T;
371     /// Subtract from the current value, returning the previous value.
372     /// The stabilized version of this intrinsic is available on the
373     /// `std::sync::atomic` types via the `fetch_sub` method by passing
374     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
375     /// as the `order`. For example,
376     /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
377     pub fn atomic_xsub_acq<T>(dst: *mut T, src: T) -> T;
378     /// Subtract from the current value, returning the previous value.
379     /// The stabilized version of this intrinsic is available on the
380     /// `std::sync::atomic` types via the `fetch_sub` method by passing
381     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
382     /// as the `order`. For example,
383     /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
384     pub fn atomic_xsub_rel<T>(dst: *mut T, src: T) -> T;
385     /// Subtract from the current value, returning the previous value.
386     /// The stabilized version of this intrinsic is available on the
387     /// `std::sync::atomic` types via the `fetch_sub` method by passing
388     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
389     /// as the `order`. For example,
390     /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
391     pub fn atomic_xsub_acqrel<T>(dst: *mut T, src: T) -> T;
392     /// Subtract from the current value, returning the previous value.
393     /// The stabilized version of this intrinsic is available on the
394     /// `std::sync::atomic` types via the `fetch_sub` method by passing
395     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
396     /// as the `order`. For example,
397     /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
398     pub fn atomic_xsub_relaxed<T>(dst: *mut T, src: T) -> T;
399
400     /// Bitwise and with the current value, returning the previous value.
401     /// The stabilized version of this intrinsic is available on the
402     /// `std::sync::atomic` types via the `fetch_and` method by passing
403     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
404     /// as the `order`. For example,
405     /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
406     pub fn atomic_and<T>(dst: *mut T, src: T) -> T;
407     /// Bitwise and with the current value, returning the previous value.
408     /// The stabilized version of this intrinsic is available on the
409     /// `std::sync::atomic` types via the `fetch_and` method by passing
410     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
411     /// as the `order`. For example,
412     /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
413     pub fn atomic_and_acq<T>(dst: *mut T, src: T) -> T;
414     /// Bitwise and with the current value, returning the previous value.
415     /// The stabilized version of this intrinsic is available on the
416     /// `std::sync::atomic` types via the `fetch_and` method by passing
417     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
418     /// as the `order`. For example,
419     /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
420     pub fn atomic_and_rel<T>(dst: *mut T, src: T) -> T;
421     /// Bitwise and with the current value, returning the previous value.
422     /// The stabilized version of this intrinsic is available on the
423     /// `std::sync::atomic` types via the `fetch_and` method by passing
424     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
425     /// as the `order`. For example,
426     /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
427     pub fn atomic_and_acqrel<T>(dst: *mut T, src: T) -> T;
428     /// Bitwise and with the current value, returning the previous value.
429     /// The stabilized version of this intrinsic is available on the
430     /// `std::sync::atomic` types via the `fetch_and` method by passing
431     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
432     /// as the `order`. For example,
433     /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
434     pub fn atomic_and_relaxed<T>(dst: *mut T, src: T) -> T;
435
436     /// Bitwise nand with the current value, returning the previous value.
437     /// The stabilized version of this intrinsic is available on the
438     /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
439     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
440     /// as the `order`. For example,
441     /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
442     pub fn atomic_nand<T>(dst: *mut T, src: T) -> T;
443     /// Bitwise nand with the current value, returning the previous value.
444     /// The stabilized version of this intrinsic is available on the
445     /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
446     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
447     /// as the `order`. For example,
448     /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
449     pub fn atomic_nand_acq<T>(dst: *mut T, src: T) -> T;
450     /// Bitwise nand with the current value, returning the previous value.
451     /// The stabilized version of this intrinsic is available on the
452     /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
453     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
454     /// as the `order`. For example,
455     /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
456     pub fn atomic_nand_rel<T>(dst: *mut T, src: T) -> T;
457     /// Bitwise nand with the current value, returning the previous value.
458     /// The stabilized version of this intrinsic is available on the
459     /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
460     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
461     /// as the `order`. For example,
462     /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
463     pub fn atomic_nand_acqrel<T>(dst: *mut T, src: T) -> T;
464     /// Bitwise nand with the current value, returning the previous value.
465     /// The stabilized version of this intrinsic is available on the
466     /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
467     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
468     /// as the `order`. For example,
469     /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
470     pub fn atomic_nand_relaxed<T>(dst: *mut T, src: T) -> T;
471
472     /// Bitwise or with the current value, returning the previous value.
473     /// The stabilized version of this intrinsic is available on the
474     /// `std::sync::atomic` types via the `fetch_or` method by passing
475     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
476     /// as the `order`. For example,
477     /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
478     pub fn atomic_or<T>(dst: *mut T, src: T) -> T;
479     /// Bitwise or with the current value, returning the previous value.
480     /// The stabilized version of this intrinsic is available on the
481     /// `std::sync::atomic` types via the `fetch_or` method by passing
482     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
483     /// as the `order`. For example,
484     /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
485     pub fn atomic_or_acq<T>(dst: *mut T, src: T) -> T;
486     /// Bitwise or with the current value, returning the previous value.
487     /// The stabilized version of this intrinsic is available on the
488     /// `std::sync::atomic` types via the `fetch_or` method by passing
489     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
490     /// as the `order`. For example,
491     /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
492     pub fn atomic_or_rel<T>(dst: *mut T, src: T) -> T;
493     /// Bitwise or with the current value, returning the previous value.
494     /// The stabilized version of this intrinsic is available on the
495     /// `std::sync::atomic` types via the `fetch_or` method by passing
496     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
497     /// as the `order`. For example,
498     /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
499     pub fn atomic_or_acqrel<T>(dst: *mut T, src: T) -> T;
500     /// Bitwise or with the current value, returning the previous value.
501     /// The stabilized version of this intrinsic is available on the
502     /// `std::sync::atomic` types via the `fetch_or` method by passing
503     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
504     /// as the `order`. For example,
505     /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
506     pub fn atomic_or_relaxed<T>(dst: *mut T, src: T) -> T;
507
508     /// Bitwise xor with the current value, returning the previous value.
509     /// The stabilized version of this intrinsic is available on the
510     /// `std::sync::atomic` types via the `fetch_xor` method by passing
511     /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
512     /// as the `order`. For example,
513     /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
514     pub fn atomic_xor<T>(dst: *mut T, src: T) -> T;
515     /// Bitwise xor with the current value, returning the previous value.
516     /// The stabilized version of this intrinsic is available on the
517     /// `std::sync::atomic` types via the `fetch_xor` method by passing
518     /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
519     /// as the `order`. For example,
520     /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
521     pub fn atomic_xor_acq<T>(dst: *mut T, src: T) -> T;
522     /// Bitwise xor with the current value, returning the previous value.
523     /// The stabilized version of this intrinsic is available on the
524     /// `std::sync::atomic` types via the `fetch_xor` method by passing
525     /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
526     /// as the `order`. For example,
527     /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
528     pub fn atomic_xor_rel<T>(dst: *mut T, src: T) -> T;
529     /// Bitwise xor with the current value, returning the previous value.
530     /// The stabilized version of this intrinsic is available on the
531     /// `std::sync::atomic` types via the `fetch_xor` method by passing
532     /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
533     /// as the `order`. For example,
534     /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
535     pub fn atomic_xor_acqrel<T>(dst: *mut T, src: T) -> T;
536     /// Bitwise xor with the current value, returning the previous value.
537     /// The stabilized version of this intrinsic is available on the
538     /// `std::sync::atomic` types via the `fetch_xor` method by passing
539     /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
540     /// as the `order`. For example,
541     /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
542     pub fn atomic_xor_relaxed<T>(dst: *mut T, src: T) -> T;
543
544     pub fn atomic_max<T>(dst: *mut T, src: T) -> T;
545     pub fn atomic_max_acq<T>(dst: *mut T, src: T) -> T;
546     pub fn atomic_max_rel<T>(dst: *mut T, src: T) -> T;
547     pub fn atomic_max_acqrel<T>(dst: *mut T, src: T) -> T;
548     pub fn atomic_max_relaxed<T>(dst: *mut T, src: T) -> T;
549
550     pub fn atomic_min<T>(dst: *mut T, src: T) -> T;
551     pub fn atomic_min_acq<T>(dst: *mut T, src: T) -> T;
552     pub fn atomic_min_rel<T>(dst: *mut T, src: T) -> T;
553     pub fn atomic_min_acqrel<T>(dst: *mut T, src: T) -> T;
554     pub fn atomic_min_relaxed<T>(dst: *mut T, src: T) -> T;
555
556     pub fn atomic_umin<T>(dst: *mut T, src: T) -> T;
557     pub fn atomic_umin_acq<T>(dst: *mut T, src: T) -> T;
558     pub fn atomic_umin_rel<T>(dst: *mut T, src: T) -> T;
559     pub fn atomic_umin_acqrel<T>(dst: *mut T, src: T) -> T;
560     pub fn atomic_umin_relaxed<T>(dst: *mut T, src: T) -> T;
561
562     pub fn atomic_umax<T>(dst: *mut T, src: T) -> T;
563     pub fn atomic_umax_acq<T>(dst: *mut T, src: T) -> T;
564     pub fn atomic_umax_rel<T>(dst: *mut T, src: T) -> T;
565     pub fn atomic_umax_acqrel<T>(dst: *mut T, src: T) -> T;
566     pub fn atomic_umax_relaxed<T>(dst: *mut T, src: T) -> T;
567
568     /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
569     /// if supported; otherwise, it is a noop.
570     /// Prefetches have no effect on the behavior of the program but can change its performance
571     /// characteristics.
572     ///
573     /// The `locality` argument must be a constant integer and is a temporal locality specifier
574     /// ranging from (0) - no locality, to (3) - extremely local keep in cache
575     pub fn prefetch_read_data<T>(data: *const T, locality: i32);
576     /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
577     /// if supported; otherwise, it is a noop.
578     /// Prefetches have no effect on the behavior of the program but can change its performance
579     /// characteristics.
580     ///
581     /// The `locality` argument must be a constant integer and is a temporal locality specifier
582     /// ranging from (0) - no locality, to (3) - extremely local keep in cache
583     pub fn prefetch_write_data<T>(data: *const T, locality: i32);
584     /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
585     /// if supported; otherwise, it is a noop.
586     /// Prefetches have no effect on the behavior of the program but can change its performance
587     /// characteristics.
588     ///
589     /// The `locality` argument must be a constant integer and is a temporal locality specifier
590     /// ranging from (0) - no locality, to (3) - extremely local keep in cache
591     pub fn prefetch_read_instruction<T>(data: *const T, locality: i32);
592     /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
593     /// if supported; otherwise, it is a noop.
594     /// Prefetches have no effect on the behavior of the program but can change its performance
595     /// characteristics.
596     ///
597     /// The `locality` argument must be a constant integer and is a temporal locality specifier
598     /// ranging from (0) - no locality, to (3) - extremely local keep in cache
599     pub fn prefetch_write_instruction<T>(data: *const T, locality: i32);
600 }
601
602 extern "rust-intrinsic" {
603
604     pub fn atomic_fence();
605     pub fn atomic_fence_acq();
606     pub fn atomic_fence_rel();
607     pub fn atomic_fence_acqrel();
608
609     /// A compiler-only memory barrier.
610     ///
611     /// Memory accesses will never be reordered across this barrier by the
612     /// compiler, but no instructions will be emitted for it. This is
613     /// appropriate for operations on the same thread that may be preempted,
614     /// such as when interacting with signal handlers.
615     pub fn atomic_singlethreadfence();
616     pub fn atomic_singlethreadfence_acq();
617     pub fn atomic_singlethreadfence_rel();
618     pub fn atomic_singlethreadfence_acqrel();
619
620     /// Magic intrinsic that derives its meaning from attributes
621     /// attached to the function.
622     ///
623     /// For example, dataflow uses this to inject static assertions so
624     /// that `rustc_peek(potentially_uninitialized)` would actually
625     /// double-check that dataflow did indeed compute that it is
626     /// uninitialized at that point in the control flow.
627     pub fn rustc_peek<T>(_: T) -> T;
628
629     /// Aborts the execution of the process.
630     ///
631     /// The stabilized version of this intrinsic is
632     /// [`std::process::abort`](../../std/process/fn.abort.html)
633     pub fn abort() -> !;
634
635     /// Tells LLVM that this point in the code is not reachable, enabling
636     /// further optimizations.
637     ///
638     /// N.B., this is very different from the `unreachable!()` macro: Unlike the
639     /// macro, which panics when it is executed, it is *undefined behavior* to
640     /// reach code marked with this function.
641     ///
642     /// The stabilized version of this intrinsic is
643     /// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html).
644     pub fn unreachable() -> !;
645
646     /// Informs the optimizer that a condition is always true.
647     /// If the condition is false, the behavior is undefined.
648     ///
649     /// No code is generated for this intrinsic, but the optimizer will try
650     /// to preserve it (and its condition) between passes, which may interfere
651     /// with optimization of surrounding code and reduce performance. It should
652     /// not be used if the invariant can be discovered by the optimizer on its
653     /// own, or if it does not enable any significant optimizations.
654     pub fn assume(b: bool);
655
656     /// Hints to the compiler that branch condition is likely to be true.
657     /// Returns the value passed to it.
658     ///
659     /// Any use other than with `if` statements will probably not have an effect.
660     pub fn likely(b: bool) -> bool;
661
662     /// Hints to the compiler that branch condition is likely to be false.
663     /// Returns the value passed to it.
664     ///
665     /// Any use other than with `if` statements will probably not have an effect.
666     pub fn unlikely(b: bool) -> bool;
667
668     /// Executes a breakpoint trap, for inspection by a debugger.
669     pub fn breakpoint();
670
671     /// The size of a type in bytes.
672     ///
673     /// More specifically, this is the offset in bytes between successive
674     /// items of the same type, including alignment padding.
675     ///
676     /// The stabilized version of this intrinsic is
677     /// [`std::mem::size_of`](../../std/mem/fn.size_of.html).
678     pub fn size_of<T>() -> usize;
679
680     /// Moves a value to an uninitialized memory location.
681     ///
682     /// Drop glue is not run on the destination.
683     pub fn move_val_init<T>(dst: *mut T, src: T);
684
685     pub fn min_align_of<T>() -> usize;
686     pub fn pref_align_of<T>() -> usize;
687
688     /// The size of the referenced value in bytes.
689     ///
690     /// The stabilized version of this intrinsic is
691     /// [`std::mem::size_of_val`](../../std/mem/fn.size_of_val.html).
692     pub fn size_of_val<T: ?Sized>(_: &T) -> usize;
693     pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize;
694
695     /// Gets a static string slice containing the name of a type.
696     pub fn type_name<T: ?Sized>() -> &'static str;
697
698     /// Gets an identifier which is globally unique to the specified type. This
699     /// function will return the same value for a type regardless of whichever
700     /// crate it is invoked in.
701     pub fn type_id<T: ?Sized + 'static>() -> u64;
702
703     /// Creates a value initialized to zero.
704     ///
705     /// `init` is unsafe because it returns a zeroed-out datum,
706     /// which is unsafe unless T is `Copy`.  Also, even if T is
707     /// `Copy`, an all-zero value may not correspond to any legitimate
708     /// state for the type in question.
709     pub fn init<T>() -> T;
710
711     /// Creates an uninitialized value.
712     ///
713     /// `uninit` is unsafe because there is no guarantee of what its
714     /// contents are. In particular its drop-flag may be set to any
715     /// state, which means it may claim either dropped or
716     /// undropped. In the general case one must use `ptr::write` to
717     /// initialize memory previous set to the result of `uninit`.
718     pub fn uninit<T>() -> T;
719
720     /// Moves a value out of scope without running drop glue.
721     #[cfg(not(stage0))]
722     pub fn forget<T: ?Sized>(_: T);
723
724     /// Reinterprets the bits of a value of one type as another type.
725     ///
726     /// Both types must have the same size. Neither the original, nor the result,
727     /// may be an [invalid value](../../nomicon/what-unsafe-does.html).
728     ///
729     /// `transmute` is semantically equivalent to a bitwise move of one type
730     /// into another. It copies the bits from the source value into the
731     /// destination value, then forgets the original. It's equivalent to C's
732     /// `memcpy` under the hood, just like `transmute_copy`.
733     ///
734     /// `transmute` is **incredibly** unsafe. There are a vast number of ways to
735     /// cause [undefined behavior][ub] with this function. `transmute` should be
736     /// the absolute last resort.
737     ///
738     /// The [nomicon](../../nomicon/transmutes.html) has additional
739     /// documentation.
740     ///
741     /// [ub]: ../../reference/behavior-considered-undefined.html
742     ///
743     /// # Examples
744     ///
745     /// There are a few things that `transmute` is really useful for.
746     ///
747     /// Getting the bitpattern of a floating point type (or, more generally,
748     /// type punning, when `T` and `U` aren't pointers):
749     ///
750     /// ```
751     /// let bitpattern = unsafe {
752     ///     std::mem::transmute::<f32, u32>(1.0)
753     /// };
754     /// assert_eq!(bitpattern, 0x3F800000);
755     /// ```
756     ///
757     /// Turning a pointer into a function pointer. This is *not* portable to
758     /// machines where function pointers and data pointers have different sizes.
759     ///
760     /// ```
761     /// fn foo() -> i32 {
762     ///     0
763     /// }
764     /// let pointer = foo as *const ();
765     /// let function = unsafe {
766     ///     std::mem::transmute::<*const (), fn() -> i32>(pointer)
767     /// };
768     /// assert_eq!(function(), 0);
769     /// ```
770     ///
771     /// Extending a lifetime, or shortening an invariant lifetime. This is
772     /// advanced, very unsafe Rust!
773     ///
774     /// ```
775     /// struct R<'a>(&'a i32);
776     /// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
777     ///     std::mem::transmute::<R<'b>, R<'static>>(r)
778     /// }
779     ///
780     /// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
781     ///                                              -> &'b mut R<'c> {
782     ///     std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
783     /// }
784     /// ```
785     ///
786     /// # Alternatives
787     ///
788     /// Don't despair: many uses of `transmute` can be achieved through other means.
789     /// Below are common applications of `transmute` which can be replaced with safer
790     /// constructs.
791     ///
792     /// Turning a pointer into a `usize`:
793     ///
794     /// ```
795     /// let ptr = &0;
796     /// let ptr_num_transmute = unsafe {
797     ///     std::mem::transmute::<&i32, usize>(ptr)
798     /// };
799     ///
800     /// // Use an `as` cast instead
801     /// let ptr_num_cast = ptr as *const i32 as usize;
802     /// ```
803     ///
804     /// Turning a `*mut T` into an `&mut T`:
805     ///
806     /// ```
807     /// let ptr: *mut i32 = &mut 0;
808     /// let ref_transmuted = unsafe {
809     ///     std::mem::transmute::<*mut i32, &mut i32>(ptr)
810     /// };
811     ///
812     /// // Use a reborrow instead
813     /// let ref_casted = unsafe { &mut *ptr };
814     /// ```
815     ///
816     /// Turning an `&mut T` into an `&mut U`:
817     ///
818     /// ```
819     /// let ptr = &mut 0;
820     /// let val_transmuted = unsafe {
821     ///     std::mem::transmute::<&mut i32, &mut u32>(ptr)
822     /// };
823     ///
824     /// // Now, put together `as` and reborrowing - note the chaining of `as`
825     /// // `as` is not transitive
826     /// let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) };
827     /// ```
828     ///
829     /// Turning an `&str` into an `&[u8]`:
830     ///
831     /// ```
832     /// // this is not a good way to do this.
833     /// let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") };
834     /// assert_eq!(slice, &[82, 117, 115, 116]);
835     ///
836     /// // You could use `str::as_bytes`
837     /// let slice = "Rust".as_bytes();
838     /// assert_eq!(slice, &[82, 117, 115, 116]);
839     ///
840     /// // Or, just use a byte string, if you have control over the string
841     /// // literal
842     /// assert_eq!(b"Rust", &[82, 117, 115, 116]);
843     /// ```
844     ///
845     /// Turning a `Vec<&T>` into a `Vec<Option<&T>>`:
846     ///
847     /// ```
848     /// let store = [0, 1, 2, 3];
849     /// let mut v_orig = store.iter().collect::<Vec<&i32>>();
850     ///
851     /// // Using transmute: this is Undefined Behavior, and a bad idea.
852     /// // However, it is no-copy.
853     /// let v_transmuted = unsafe {
854     ///     std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(
855     ///         v_orig.clone())
856     /// };
857     ///
858     /// // This is the suggested, safe way.
859     /// // It does copy the entire vector, though, into a new array.
860     /// let v_collected = v_orig.clone()
861     ///                         .into_iter()
862     ///                         .map(|r| Some(r))
863     ///                         .collect::<Vec<Option<&i32>>>();
864     ///
865     /// // The no-copy, unsafe way, still using transmute, but not UB.
866     /// // This is equivalent to the original, but safer, and reuses the
867     /// // same Vec internals. Therefore the new inner type must have the
868     /// // exact same size, and the same alignment, as the old type.
869     /// // The same caveats exist for this method as transmute, for
870     /// // the original inner type (`&i32`) to the converted inner type
871     /// // (`Option<&i32>`), so read the nomicon pages linked above.
872     /// let v_from_raw = unsafe {
873     ///     Vec::from_raw_parts(v_orig.as_mut_ptr() as *mut Option<&i32>,
874     ///                         v_orig.len(),
875     ///                         v_orig.capacity())
876     /// };
877     /// std::mem::forget(v_orig);
878     /// ```
879     ///
880     /// Implementing `split_at_mut`:
881     ///
882     /// ```
883     /// use std::{slice, mem};
884     ///
885     /// // There are multiple ways to do this; and there are multiple problems
886     /// // with the following, transmute, way.
887     /// fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize)
888     ///                              -> (&mut [T], &mut [T]) {
889     ///     let len = slice.len();
890     ///     assert!(mid <= len);
891     ///     unsafe {
892     ///         let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
893     ///         // first: transmute is not typesafe; all it checks is that T and
894     ///         // U are of the same size. Second, right here, you have two
895     ///         // mutable references pointing to the same memory.
896     ///         (&mut slice[0..mid], &mut slice2[mid..len])
897     ///     }
898     /// }
899     ///
900     /// // This gets rid of the typesafety problems; `&mut *` will *only* give
901     /// // you an `&mut T` from an `&mut T` or `*mut T`.
902     /// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
903     ///                          -> (&mut [T], &mut [T]) {
904     ///     let len = slice.len();
905     ///     assert!(mid <= len);
906     ///     unsafe {
907     ///         let slice2 = &mut *(slice as *mut [T]);
908     ///         // however, you still have two mutable references pointing to
909     ///         // the same memory.
910     ///         (&mut slice[0..mid], &mut slice2[mid..len])
911     ///     }
912     /// }
913     ///
914     /// // This is how the standard library does it. This is the best method, if
915     /// // you need to do something like this
916     /// fn split_at_stdlib<T>(slice: &mut [T], mid: usize)
917     ///                       -> (&mut [T], &mut [T]) {
918     ///     let len = slice.len();
919     ///     assert!(mid <= len);
920     ///     unsafe {
921     ///         let ptr = slice.as_mut_ptr();
922     ///         // This now has three mutable references pointing at the same
923     ///         // memory. `slice`, the rvalue ret.0, and the rvalue ret.1.
924     ///         // `slice` is never used after `let ptr = ...`, and so one can
925     ///         // treat it as "dead", and therefore, you only have two real
926     ///         // mutable slices.
927     ///         (slice::from_raw_parts_mut(ptr, mid),
928     ///          slice::from_raw_parts_mut(ptr.add(mid), len - mid))
929     ///     }
930     /// }
931     /// ```
932     #[stable(feature = "rust1", since = "1.0.0")]
933     pub fn transmute<T, U>(e: T) -> U;
934
935     /// Returns `true` if the actual type given as `T` requires drop
936     /// glue; returns `false` if the actual type provided for `T`
937     /// implements `Copy`.
938     ///
939     /// If the actual type neither requires drop glue nor implements
940     /// `Copy`, then may return `true` or `false`.
941     ///
942     /// The stabilized version of this intrinsic is
943     /// [`std::mem::needs_drop`](../../std/mem/fn.needs_drop.html).
944     pub fn needs_drop<T>() -> bool;
945
946     /// Calculates the offset from a pointer.
947     ///
948     /// This is implemented as an intrinsic to avoid converting to and from an
949     /// integer, since the conversion would throw away aliasing information.
950     ///
951     /// # Safety
952     ///
953     /// Both the starting and resulting pointer must be either in bounds or one
954     /// byte past the end of an allocated object. If either pointer is out of
955     /// bounds or arithmetic overflow occurs then any further use of the
956     /// returned value will result in undefined behavior.
957     pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
958
959     /// Calculates the offset from a pointer, potentially wrapping.
960     ///
961     /// This is implemented as an intrinsic to avoid converting to and from an
962     /// integer, since the conversion inhibits certain optimizations.
963     ///
964     /// # Safety
965     ///
966     /// Unlike the `offset` intrinsic, this intrinsic does not restrict the
967     /// resulting pointer to point into or one byte past the end of an allocated
968     /// object, and it wraps with two's complement arithmetic. The resulting
969     /// value is not necessarily valid to be used to actually access memory.
970     pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
971
972     /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
973     /// and destination must *not* overlap.
974     ///
975     /// For regions of memory which might overlap, use [`copy`] instead.
976     ///
977     /// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
978     /// with the argument order swapped.
979     ///
980     /// [`copy`]: ./fn.copy.html
981     /// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy
982     ///
983     /// # Safety
984     ///
985     /// Behavior is undefined if any of the following conditions are violated:
986     ///
987     /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
988     ///
989     /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
990     ///
991     /// * Both `src` and `dst` must be properly aligned.
992     ///
993     /// * The region of memory beginning at `src` with a size of `count *
994     ///   size_of::<T>()` bytes must *not* overlap with the region of memory
995     ///   beginning at `dst` with the same size.
996     ///
997     /// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of
998     /// whether `T` is [`Copy`].  If `T` is not [`Copy`], using *both* the values
999     /// in the region beginning at `*src` and the region beginning at `*dst` can
1000     /// [violate memory safety][read-ownership].
1001     ///
1002     /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
1003     /// `0`, the pointers must be non-NULL and properly aligned.
1004     ///
1005     /// [`Copy`]: ../marker/trait.Copy.html
1006     /// [`read`]: ../ptr/fn.read.html
1007     /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
1008     /// [valid]: ../ptr/index.html#safety
1009     ///
1010     /// # Examples
1011     ///
1012     /// Manually implement [`Vec::append`]:
1013     ///
1014     /// ```
1015     /// use std::ptr;
1016     ///
1017     /// /// Moves all the elements of `src` into `dst`, leaving `src` empty.
1018     /// fn append<T>(dst: &mut Vec<T>, src: &mut Vec<T>) {
1019     ///     let src_len = src.len();
1020     ///     let dst_len = dst.len();
1021     ///
1022     ///     // Ensure that `dst` has enough capacity to hold all of `src`.
1023     ///     dst.reserve(src_len);
1024     ///
1025     ///     unsafe {
1026     ///         // The call to offset is always safe because `Vec` will never
1027     ///         // allocate more than `isize::MAX` bytes.
1028     ///         let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize);
1029     ///         let src_ptr = src.as_ptr();
1030     ///
1031     ///         // Truncate `src` without dropping its contents. We do this first,
1032     ///         // to avoid problems in case something further down panics.
1033     ///         src.set_len(0);
1034     ///
1035     ///         // The two regions cannot overlap because mutable references do
1036     ///         // not alias, and two different vectors cannot own the same
1037     ///         // memory.
1038     ///         ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
1039     ///
1040     ///         // Notify `dst` that it now holds the contents of `src`.
1041     ///         dst.set_len(dst_len + src_len);
1042     ///     }
1043     /// }
1044     ///
1045     /// let mut a = vec!['r'];
1046     /// let mut b = vec!['u', 's', 't'];
1047     ///
1048     /// append(&mut a, &mut b);
1049     ///
1050     /// assert_eq!(a, &['r', 'u', 's', 't']);
1051     /// assert!(b.is_empty());
1052     /// ```
1053     ///
1054     /// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append
1055     #[stable(feature = "rust1", since = "1.0.0")]
1056     pub fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
1057
1058     /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
1059     /// and destination may overlap.
1060     ///
1061     /// If the source and destination will *never* overlap,
1062     /// [`copy_nonoverlapping`] can be used instead.
1063     ///
1064     /// `copy` is semantically equivalent to C's [`memmove`], but with the argument
1065     /// order swapped.  Copying takes place as if the bytes were copied from `src`
1066     /// to a temporary array and then copied from the array to `dst`.
1067     ///
1068     /// [`copy_nonoverlapping`]: ./fn.copy_nonoverlapping.html
1069     /// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove
1070     ///
1071     /// # Safety
1072     ///
1073     /// Behavior is undefined if any of the following conditions are violated:
1074     ///
1075     /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
1076     ///
1077     /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
1078     ///
1079     /// * Both `src` and `dst` must be properly aligned.
1080     ///
1081     /// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of
1082     /// whether `T` is [`Copy`].  If `T` is not [`Copy`], using both the values
1083     /// in the region beginning at `*src` and the region beginning at `*dst` can
1084     /// [violate memory safety][read-ownership].
1085     ///
1086     /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
1087     /// `0`, the pointers must be non-NULL and properly aligned.
1088     ///
1089     /// [`Copy`]: ../marker/trait.Copy.html
1090     /// [`read`]: ../ptr/fn.read.html
1091     /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
1092     /// [valid]: ../ptr/index.html#safety
1093     ///
1094     /// # Examples
1095     ///
1096     /// Efficiently create a Rust vector from an unsafe buffer:
1097     ///
1098     /// ```
1099     /// use std::ptr;
1100     ///
1101     /// # #[allow(dead_code)]
1102     /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
1103     ///     let mut dst = Vec::with_capacity(elts);
1104     ///     dst.set_len(elts);
1105     ///     ptr::copy(ptr, dst.as_mut_ptr(), elts);
1106     ///     dst
1107     /// }
1108     /// ```
1109     #[stable(feature = "rust1", since = "1.0.0")]
1110     pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
1111
1112     /// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
1113     /// `val`.
1114     ///
1115     /// `write_bytes` is similar to C's [`memset`], but sets `count *
1116     /// size_of::<T>()` bytes to `val`.
1117     ///
1118     /// [`memset`]: https://en.cppreference.com/w/c/string/byte/memset
1119     ///
1120     /// # Safety
1121     ///
1122     /// Behavior is undefined if any of the following conditions are violated:
1123     ///
1124     /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
1125     ///
1126     /// * `dst` must be properly aligned.
1127     ///
1128     /// Additionally, the caller must ensure that writing `count *
1129     /// size_of::<T>()` bytes to the given region of memory results in a valid
1130     /// value of `T`. Using a region of memory typed as a `T` that contains an
1131     /// invalid value of `T` is undefined behavior.
1132     ///
1133     /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
1134     /// `0`, the pointer must be non-NULL and properly aligned.
1135     ///
1136     /// [valid]: ../ptr/index.html#safety
1137     ///
1138     /// # Examples
1139     ///
1140     /// Basic usage:
1141     ///
1142     /// ```
1143     /// use std::ptr;
1144     ///
1145     /// let mut vec = vec![0u32; 4];
1146     /// unsafe {
1147     ///     let vec_ptr = vec.as_mut_ptr();
1148     ///     ptr::write_bytes(vec_ptr, 0xfe, 2);
1149     /// }
1150     /// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
1151     /// ```
1152     ///
1153     /// Creating an invalid value:
1154     ///
1155     /// ```
1156     /// use std::ptr;
1157     ///
1158     /// let mut v = Box::new(0i32);
1159     ///
1160     /// unsafe {
1161     ///     // Leaks the previously held value by overwriting the `Box<T>` with
1162     ///     // a null pointer.
1163     ///     ptr::write_bytes(&mut v as *mut Box<i32>, 0, 1);
1164     /// }
1165     ///
1166     /// // At this point, using or dropping `v` results in undefined behavior.
1167     /// // drop(v); // ERROR
1168     ///
1169     /// // Even leaking `v` "uses" it, and hence is undefined behavior.
1170     /// // mem::forget(v); // ERROR
1171     ///
1172     /// // In fact, `v` is invalid according to basic type layout invariants, so *any*
1173     /// // operation touching it is undefined behavior.
1174     /// // let v2 = v; // ERROR
1175     ///
1176     /// unsafe {
1177     ///     // Let us instead put in a valid value
1178     ///     ptr::write(&mut v as *mut Box<i32>, Box::new(42i32));
1179     /// }
1180     ///
1181     /// // Now the box is fine
1182     /// assert_eq!(*v, 42);
1183     /// ```
1184     #[stable(feature = "rust1", since = "1.0.0")]
1185     pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
1186
1187     /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
1188     /// a size of `count` * `size_of::<T>()` and an alignment of
1189     /// `min_align_of::<T>()`
1190     ///
1191     /// The volatile parameter is set to `true`, so it will not be optimized out
1192     /// unless size is equal to zero.
1193     pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T,
1194                                                   count: usize);
1195     /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
1196     /// a size of `count` * `size_of::<T>()` and an alignment of
1197     /// `min_align_of::<T>()`
1198     ///
1199     /// The volatile parameter is set to `true`, so it will not be optimized out
1200     /// unless size is equal to zero.
1201     pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
1202     /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
1203     /// size of `count` * `size_of::<T>()` and an alignment of
1204     /// `min_align_of::<T>()`.
1205     ///
1206     /// The volatile parameter is set to `true`, so it will not be optimized out
1207     /// unless size is equal to zero.
1208     pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
1209
1210     /// Perform a volatile load from the `src` pointer.
1211     /// The stabilized version of this intrinsic is
1212     /// [`std::ptr::read_volatile`](../../std/ptr/fn.read_volatile.html).
1213     pub fn volatile_load<T>(src: *const T) -> T;
1214     /// Perform a volatile store to the `dst` pointer.
1215     /// The stabilized version of this intrinsic is
1216     /// [`std::ptr::write_volatile`](../../std/ptr/fn.write_volatile.html).
1217     pub fn volatile_store<T>(dst: *mut T, val: T);
1218
1219     /// Perform a volatile load from the `src` pointer
1220     /// The pointer is not required to be aligned.
1221     pub fn unaligned_volatile_load<T>(src: *const T) -> T;
1222     /// Perform a volatile store to the `dst` pointer.
1223     /// The pointer is not required to be aligned.
1224     pub fn unaligned_volatile_store<T>(dst: *mut T, val: T);
1225
1226     /// Returns the square root of an `f32`
1227     pub fn sqrtf32(x: f32) -> f32;
1228     /// Returns the square root of an `f64`
1229     pub fn sqrtf64(x: f64) -> f64;
1230
1231     /// Raises an `f32` to an integer power.
1232     pub fn powif32(a: f32, x: i32) -> f32;
1233     /// Raises an `f64` to an integer power.
1234     pub fn powif64(a: f64, x: i32) -> f64;
1235
1236     /// Returns the sine of an `f32`.
1237     pub fn sinf32(x: f32) -> f32;
1238     /// Returns the sine of an `f64`.
1239     pub fn sinf64(x: f64) -> f64;
1240
1241     /// Returns the cosine of an `f32`.
1242     pub fn cosf32(x: f32) -> f32;
1243     /// Returns the cosine of an `f64`.
1244     pub fn cosf64(x: f64) -> f64;
1245
1246     /// Raises an `f32` to an `f32` power.
1247     pub fn powf32(a: f32, x: f32) -> f32;
1248     /// Raises an `f64` to an `f64` power.
1249     pub fn powf64(a: f64, x: f64) -> f64;
1250
1251     /// Returns the exponential of an `f32`.
1252     pub fn expf32(x: f32) -> f32;
1253     /// Returns the exponential of an `f64`.
1254     pub fn expf64(x: f64) -> f64;
1255
1256     /// Returns 2 raised to the power of an `f32`.
1257     pub fn exp2f32(x: f32) -> f32;
1258     /// Returns 2 raised to the power of an `f64`.
1259     pub fn exp2f64(x: f64) -> f64;
1260
1261     /// Returns the natural logarithm of an `f32`.
1262     pub fn logf32(x: f32) -> f32;
1263     /// Returns the natural logarithm of an `f64`.
1264     pub fn logf64(x: f64) -> f64;
1265
1266     /// Returns the base 10 logarithm of an `f32`.
1267     pub fn log10f32(x: f32) -> f32;
1268     /// Returns the base 10 logarithm of an `f64`.
1269     pub fn log10f64(x: f64) -> f64;
1270
1271     /// Returns the base 2 logarithm of an `f32`.
1272     pub fn log2f32(x: f32) -> f32;
1273     /// Returns the base 2 logarithm of an `f64`.
1274     pub fn log2f64(x: f64) -> f64;
1275
1276     /// Returns `a * b + c` for `f32` values.
1277     pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
1278     /// Returns `a * b + c` for `f64` values.
1279     pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
1280
1281     /// Returns the absolute value of an `f32`.
1282     pub fn fabsf32(x: f32) -> f32;
1283     /// Returns the absolute value of an `f64`.
1284     pub fn fabsf64(x: f64) -> f64;
1285
1286     /// Copies the sign from `y` to `x` for `f32` values.
1287     pub fn copysignf32(x: f32, y: f32) -> f32;
1288     /// Copies the sign from `y` to `x` for `f64` values.
1289     pub fn copysignf64(x: f64, y: f64) -> f64;
1290
1291     /// Returns the largest integer less than or equal to an `f32`.
1292     pub fn floorf32(x: f32) -> f32;
1293     /// Returns the largest integer less than or equal to an `f64`.
1294     pub fn floorf64(x: f64) -> f64;
1295
1296     /// Returns the smallest integer greater than or equal to an `f32`.
1297     pub fn ceilf32(x: f32) -> f32;
1298     /// Returns the smallest integer greater than or equal to an `f64`.
1299     pub fn ceilf64(x: f64) -> f64;
1300
1301     /// Returns the integer part of an `f32`.
1302     pub fn truncf32(x: f32) -> f32;
1303     /// Returns the integer part of an `f64`.
1304     pub fn truncf64(x: f64) -> f64;
1305
1306     /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
1307     /// if the argument is not an integer.
1308     pub fn rintf32(x: f32) -> f32;
1309     /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
1310     /// if the argument is not an integer.
1311     pub fn rintf64(x: f64) -> f64;
1312
1313     /// Returns the nearest integer to an `f32`.
1314     pub fn nearbyintf32(x: f32) -> f32;
1315     /// Returns the nearest integer to an `f64`.
1316     pub fn nearbyintf64(x: f64) -> f64;
1317
1318     /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
1319     pub fn roundf32(x: f32) -> f32;
1320     /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
1321     pub fn roundf64(x: f64) -> f64;
1322
1323     /// Float addition that allows optimizations based on algebraic rules.
1324     /// May assume inputs are finite.
1325     pub fn fadd_fast<T>(a: T, b: T) -> T;
1326
1327     /// Float subtraction that allows optimizations based on algebraic rules.
1328     /// May assume inputs are finite.
1329     pub fn fsub_fast<T>(a: T, b: T) -> T;
1330
1331     /// Float multiplication that allows optimizations based on algebraic rules.
1332     /// May assume inputs are finite.
1333     pub fn fmul_fast<T>(a: T, b: T) -> T;
1334
1335     /// Float division that allows optimizations based on algebraic rules.
1336     /// May assume inputs are finite.
1337     pub fn fdiv_fast<T>(a: T, b: T) -> T;
1338
1339     /// Float remainder that allows optimizations based on algebraic rules.
1340     /// May assume inputs are finite.
1341     pub fn frem_fast<T>(a: T, b: T) -> T;
1342
1343
1344     /// Returns the number of bits set in an integer type `T`
1345     pub fn ctpop<T>(x: T) -> T;
1346
1347     /// Returns the number of leading unset bits (zeroes) in an integer type `T`.
1348     ///
1349     /// # Examples
1350     ///
1351     /// ```
1352     /// #![feature(core_intrinsics)]
1353     ///
1354     /// use std::intrinsics::ctlz;
1355     ///
1356     /// let x = 0b0001_1100_u8;
1357     /// let num_leading = unsafe { ctlz(x) };
1358     /// assert_eq!(num_leading, 3);
1359     /// ```
1360     ///
1361     /// An `x` with value `0` will return the bit width of `T`.
1362     ///
1363     /// ```
1364     /// #![feature(core_intrinsics)]
1365     ///
1366     /// use std::intrinsics::ctlz;
1367     ///
1368     /// let x = 0u16;
1369     /// let num_leading = unsafe { ctlz(x) };
1370     /// assert_eq!(num_leading, 16);
1371     /// ```
1372     pub fn ctlz<T>(x: T) -> T;
1373
1374     /// Like `ctlz`, but extra-unsafe as it returns `undef` when
1375     /// given an `x` with value `0`.
1376     ///
1377     /// # Examples
1378     ///
1379     /// ```
1380     /// #![feature(core_intrinsics)]
1381     ///
1382     /// use std::intrinsics::ctlz_nonzero;
1383     ///
1384     /// let x = 0b0001_1100_u8;
1385     /// let num_leading = unsafe { ctlz_nonzero(x) };
1386     /// assert_eq!(num_leading, 3);
1387     /// ```
1388     pub fn ctlz_nonzero<T>(x: T) -> T;
1389
1390     /// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
1391     ///
1392     /// # Examples
1393     ///
1394     /// ```
1395     /// #![feature(core_intrinsics)]
1396     ///
1397     /// use std::intrinsics::cttz;
1398     ///
1399     /// let x = 0b0011_1000_u8;
1400     /// let num_trailing = unsafe { cttz(x) };
1401     /// assert_eq!(num_trailing, 3);
1402     /// ```
1403     ///
1404     /// An `x` with value `0` will return the bit width of `T`:
1405     ///
1406     /// ```
1407     /// #![feature(core_intrinsics)]
1408     ///
1409     /// use std::intrinsics::cttz;
1410     ///
1411     /// let x = 0u16;
1412     /// let num_trailing = unsafe { cttz(x) };
1413     /// assert_eq!(num_trailing, 16);
1414     /// ```
1415     pub fn cttz<T>(x: T) -> T;
1416
1417     /// Like `cttz`, but extra-unsafe as it returns `undef` when
1418     /// given an `x` with value `0`.
1419     ///
1420     /// # Examples
1421     ///
1422     /// ```
1423     /// #![feature(core_intrinsics)]
1424     ///
1425     /// use std::intrinsics::cttz_nonzero;
1426     ///
1427     /// let x = 0b0011_1000_u8;
1428     /// let num_trailing = unsafe { cttz_nonzero(x) };
1429     /// assert_eq!(num_trailing, 3);
1430     /// ```
1431     pub fn cttz_nonzero<T>(x: T) -> T;
1432
1433     /// Reverses the bytes in an integer type `T`.
1434     pub fn bswap<T>(x: T) -> T;
1435
1436     /// Reverses the bits in an integer type `T`.
1437     pub fn bitreverse<T>(x: T) -> T;
1438
1439     /// Performs checked integer addition.
1440     /// The stabilized versions of this intrinsic are available on the integer
1441     /// primitives via the `overflowing_add` method. For example,
1442     /// [`std::u32::overflowing_add`](../../std/primitive.u32.html#method.overflowing_add)
1443     pub fn add_with_overflow<T>(x: T, y: T) -> (T, bool);
1444
1445     /// Performs checked integer subtraction
1446     /// The stabilized versions of this intrinsic are available on the integer
1447     /// primitives via the `overflowing_sub` method. For example,
1448     /// [`std::u32::overflowing_sub`](../../std/primitive.u32.html#method.overflowing_sub)
1449     pub fn sub_with_overflow<T>(x: T, y: T) -> (T, bool);
1450
1451     /// Performs checked integer multiplication
1452     /// The stabilized versions of this intrinsic are available on the integer
1453     /// primitives via the `overflowing_mul` method. For example,
1454     /// [`std::u32::overflowing_mul`](../../std/primitive.u32.html#method.overflowing_mul)
1455     pub fn mul_with_overflow<T>(x: T, y: T) -> (T, bool);
1456
1457     /// Performs an exact division, resulting in undefined behavior where
1458     /// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`
1459     pub fn exact_div<T>(x: T, y: T) -> T;
1460
1461     /// Performs an unchecked division, resulting in undefined behavior
1462     /// where y = 0 or x = `T::min_value()` and y = -1
1463     pub fn unchecked_div<T>(x: T, y: T) -> T;
1464     /// Returns the remainder of an unchecked division, resulting in
1465     /// undefined behavior where y = 0 or x = `T::min_value()` and y = -1
1466     pub fn unchecked_rem<T>(x: T, y: T) -> T;
1467
1468     /// Performs an unchecked left shift, resulting in undefined behavior when
1469     /// y < 0 or y >= N, where N is the width of T in bits.
1470     pub fn unchecked_shl<T>(x: T, y: T) -> T;
1471     /// Performs an unchecked right shift, resulting in undefined behavior when
1472     /// y < 0 or y >= N, where N is the width of T in bits.
1473     pub fn unchecked_shr<T>(x: T, y: T) -> T;
1474
1475     /// Performs rotate left.
1476     /// The stabilized versions of this intrinsic are available on the integer
1477     /// primitives via the `rotate_left` method. For example,
1478     /// [`std::u32::rotate_left`](../../std/primitive.u32.html#method.rotate_left)
1479     #[cfg(not(stage0))]
1480     pub fn rotate_left<T>(x: T, y: T) -> T;
1481
1482     /// Performs rotate right.
1483     /// The stabilized versions of this intrinsic are available on the integer
1484     /// primitives via the `rotate_right` method. For example,
1485     /// [`std::u32::rotate_right`](../../std/primitive.u32.html#method.rotate_right)
1486     #[cfg(not(stage0))]
1487     pub fn rotate_right<T>(x: T, y: T) -> T;
1488
1489     /// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
1490     /// The stabilized versions of this intrinsic are available on the integer
1491     /// primitives via the `wrapping_add` method. For example,
1492     /// [`std::u32::wrapping_add`](../../std/primitive.u32.html#method.wrapping_add)
1493     pub fn overflowing_add<T>(a: T, b: T) -> T;
1494     /// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
1495     /// The stabilized versions of this intrinsic are available on the integer
1496     /// primitives via the `wrapping_sub` method. For example,
1497     /// [`std::u32::wrapping_sub`](../../std/primitive.u32.html#method.wrapping_sub)
1498     pub fn overflowing_sub<T>(a: T, b: T) -> T;
1499     /// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
1500     /// The stabilized versions of this intrinsic are available on the integer
1501     /// primitives via the `wrapping_mul` method. For example,
1502     /// [`std::u32::wrapping_mul`](../../std/primitive.u32.html#method.wrapping_mul)
1503     pub fn overflowing_mul<T>(a: T, b: T) -> T;
1504
1505     /// Returns the value of the discriminant for the variant in 'v',
1506     /// cast to a `u64`; if `T` has no discriminant, returns 0.
1507     pub fn discriminant_value<T>(v: &T) -> u64;
1508
1509     /// Rust's "try catch" construct which invokes the function pointer `f` with
1510     /// the data pointer `data`.
1511     ///
1512     /// The third pointer is a target-specific data pointer which is filled in
1513     /// with the specifics of the exception that occurred. For examples on Unix
1514     /// platforms this is a `*mut *mut T` which is filled in by the compiler and
1515     /// on MSVC it's `*mut [usize; 2]`. For more information see the compiler's
1516     /// source as well as std's catch implementation.
1517     pub fn try(f: fn(*mut u8), data: *mut u8, local_ptr: *mut u8) -> i32;
1518
1519     /// Emits a `!nontemporal` store according to LLVM (see their docs).
1520     /// Probably will never become stable.
1521     pub fn nontemporal_store<T>(ptr: *mut T, val: T);
1522 }