]> git.lizzy.rs Git - rust.git/blob - src/libcore/intrinsics.rs
Auto merge of #31326 - sdleffler:master, r=nikomatsakis
[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_trans/trans/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 use marker::Sized;
50
51 extern "rust-intrinsic" {
52
53     // NB: These intrinsics take raw pointers because they mutate aliased
54     // memory, which is not valid for either `&` or `&mut`.
55
56     pub fn atomic_cxchg<T>(dst: *mut T, old: T, src: T) -> T;
57     pub fn atomic_cxchg_acq<T>(dst: *mut T, old: T, src: T) -> T;
58     pub fn atomic_cxchg_rel<T>(dst: *mut T, old: T, src: T) -> T;
59     pub fn atomic_cxchg_acqrel<T>(dst: *mut T, old: T, src: T) -> T;
60     pub fn atomic_cxchg_relaxed<T>(dst: *mut T, old: T, src: T) -> T;
61
62     pub fn atomic_load<T>(src: *const T) -> T;
63     pub fn atomic_load_acq<T>(src: *const T) -> T;
64     pub fn atomic_load_relaxed<T>(src: *const T) -> T;
65     pub fn atomic_load_unordered<T>(src: *const T) -> T;
66
67     pub fn atomic_store<T>(dst: *mut T, val: T);
68     pub fn atomic_store_rel<T>(dst: *mut T, val: T);
69     pub fn atomic_store_relaxed<T>(dst: *mut T, val: T);
70     pub fn atomic_store_unordered<T>(dst: *mut T, val: T);
71
72     pub fn atomic_xchg<T>(dst: *mut T, src: T) -> T;
73     pub fn atomic_xchg_acq<T>(dst: *mut T, src: T) -> T;
74     pub fn atomic_xchg_rel<T>(dst: *mut T, src: T) -> T;
75     pub fn atomic_xchg_acqrel<T>(dst: *mut T, src: T) -> T;
76     pub fn atomic_xchg_relaxed<T>(dst: *mut T, src: T) -> T;
77
78     pub fn atomic_xadd<T>(dst: *mut T, src: T) -> T;
79     pub fn atomic_xadd_acq<T>(dst: *mut T, src: T) -> T;
80     pub fn atomic_xadd_rel<T>(dst: *mut T, src: T) -> T;
81     pub fn atomic_xadd_acqrel<T>(dst: *mut T, src: T) -> T;
82     pub fn atomic_xadd_relaxed<T>(dst: *mut T, src: T) -> T;
83
84     pub fn atomic_xsub<T>(dst: *mut T, src: T) -> T;
85     pub fn atomic_xsub_acq<T>(dst: *mut T, src: T) -> T;
86     pub fn atomic_xsub_rel<T>(dst: *mut T, src: T) -> T;
87     pub fn atomic_xsub_acqrel<T>(dst: *mut T, src: T) -> T;
88     pub fn atomic_xsub_relaxed<T>(dst: *mut T, src: T) -> T;
89
90     pub fn atomic_and<T>(dst: *mut T, src: T) -> T;
91     pub fn atomic_and_acq<T>(dst: *mut T, src: T) -> T;
92     pub fn atomic_and_rel<T>(dst: *mut T, src: T) -> T;
93     pub fn atomic_and_acqrel<T>(dst: *mut T, src: T) -> T;
94     pub fn atomic_and_relaxed<T>(dst: *mut T, src: T) -> T;
95
96     pub fn atomic_nand<T>(dst: *mut T, src: T) -> T;
97     pub fn atomic_nand_acq<T>(dst: *mut T, src: T) -> T;
98     pub fn atomic_nand_rel<T>(dst: *mut T, src: T) -> T;
99     pub fn atomic_nand_acqrel<T>(dst: *mut T, src: T) -> T;
100     pub fn atomic_nand_relaxed<T>(dst: *mut T, src: T) -> T;
101
102     pub fn atomic_or<T>(dst: *mut T, src: T) -> T;
103     pub fn atomic_or_acq<T>(dst: *mut T, src: T) -> T;
104     pub fn atomic_or_rel<T>(dst: *mut T, src: T) -> T;
105     pub fn atomic_or_acqrel<T>(dst: *mut T, src: T) -> T;
106     pub fn atomic_or_relaxed<T>(dst: *mut T, src: T) -> T;
107
108     pub fn atomic_xor<T>(dst: *mut T, src: T) -> T;
109     pub fn atomic_xor_acq<T>(dst: *mut T, src: T) -> T;
110     pub fn atomic_xor_rel<T>(dst: *mut T, src: T) -> T;
111     pub fn atomic_xor_acqrel<T>(dst: *mut T, src: T) -> T;
112     pub fn atomic_xor_relaxed<T>(dst: *mut T, src: T) -> T;
113
114     pub fn atomic_max<T>(dst: *mut T, src: T) -> T;
115     pub fn atomic_max_acq<T>(dst: *mut T, src: T) -> T;
116     pub fn atomic_max_rel<T>(dst: *mut T, src: T) -> T;
117     pub fn atomic_max_acqrel<T>(dst: *mut T, src: T) -> T;
118     pub fn atomic_max_relaxed<T>(dst: *mut T, src: T) -> T;
119
120     pub fn atomic_min<T>(dst: *mut T, src: T) -> T;
121     pub fn atomic_min_acq<T>(dst: *mut T, src: T) -> T;
122     pub fn atomic_min_rel<T>(dst: *mut T, src: T) -> T;
123     pub fn atomic_min_acqrel<T>(dst: *mut T, src: T) -> T;
124     pub fn atomic_min_relaxed<T>(dst: *mut T, src: T) -> T;
125
126     pub fn atomic_umin<T>(dst: *mut T, src: T) -> T;
127     pub fn atomic_umin_acq<T>(dst: *mut T, src: T) -> T;
128     pub fn atomic_umin_rel<T>(dst: *mut T, src: T) -> T;
129     pub fn atomic_umin_acqrel<T>(dst: *mut T, src: T) -> T;
130     pub fn atomic_umin_relaxed<T>(dst: *mut T, src: T) -> T;
131
132     pub fn atomic_umax<T>(dst: *mut T, src: T) -> T;
133     pub fn atomic_umax_acq<T>(dst: *mut T, src: T) -> T;
134     pub fn atomic_umax_rel<T>(dst: *mut T, src: T) -> T;
135     pub fn atomic_umax_acqrel<T>(dst: *mut T, src: T) -> T;
136     pub fn atomic_umax_relaxed<T>(dst: *mut T, src: T) -> T;
137 }
138
139 extern "rust-intrinsic" {
140
141     pub fn atomic_fence();
142     pub fn atomic_fence_acq();
143     pub fn atomic_fence_rel();
144     pub fn atomic_fence_acqrel();
145
146     /// A compiler-only memory barrier.
147     ///
148     /// Memory accesses will never be reordered across this barrier by the
149     /// compiler, but no instructions will be emitted for it. This is
150     /// appropriate for operations on the same thread that may be preempted,
151     /// such as when interacting with signal handlers.
152     pub fn atomic_singlethreadfence();
153     pub fn atomic_singlethreadfence_acq();
154     pub fn atomic_singlethreadfence_rel();
155     pub fn atomic_singlethreadfence_acqrel();
156
157     /// Aborts the execution of the process.
158     pub fn abort() -> !;
159
160     /// Tells LLVM that this point in the code is not reachable,
161     /// enabling further optimizations.
162     ///
163     /// NB: This is very different from the `unreachable!()` macro!
164     pub fn unreachable() -> !;
165
166     /// Informs the optimizer that a condition is always true.
167     /// If the condition is false, the behavior is undefined.
168     ///
169     /// No code is generated for this intrinsic, but the optimizer will try
170     /// to preserve it (and its condition) between passes, which may interfere
171     /// with optimization of surrounding code and reduce performance. It should
172     /// not be used if the invariant can be discovered by the optimizer on its
173     /// own, or if it does not enable any significant optimizations.
174     pub fn assume(b: bool);
175
176     /// Executes a breakpoint trap, for inspection by a debugger.
177     pub fn breakpoint();
178
179     /// The size of a type in bytes.
180     ///
181     /// This is the exact number of bytes in memory taken up by a
182     /// value of the given type. In other words, a memset of this size
183     /// would *exactly* overwrite a value. When laid out in vectors
184     /// and structures there may be additional padding between
185     /// elements.
186     pub fn size_of<T>() -> usize;
187
188     /// Moves a value to an uninitialized memory location.
189     ///
190     /// Drop glue is not run on the destination.
191     pub fn move_val_init<T>(dst: *mut T, src: T);
192
193     pub fn min_align_of<T>() -> usize;
194     pub fn pref_align_of<T>() -> usize;
195
196     pub fn size_of_val<T: ?Sized>(_: &T) -> usize;
197     pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize;
198
199     /// Executes the destructor (if any) of the pointed-to value.
200     ///
201     /// This has two use cases:
202     ///
203     /// * It is *required* to use `drop_in_place` to drop unsized types like
204     ///   trait objects, because they can't be read out onto the stack and
205     ///   dropped normally.
206     ///
207     /// * It is friendlier to the optimizer to do this over `ptr::read` when
208     ///   dropping manually allocated memory (e.g. when writing Box/Rc/Vec),
209     ///   as the compiler doesn't need to prove that it's sound to elide the
210     ///   copy.
211     ///
212     /// # Undefined Behavior
213     ///
214     /// This has all the same safety problems as `ptr::read` with respect to
215     /// invalid pointers, types, and double drops.
216     #[unstable(feature = "drop_in_place", reason = "just exposed, needs FCP", issue = "27908")]
217     pub fn drop_in_place<T: ?Sized>(to_drop: *mut T);
218
219     /// Gets a static string slice containing the name of a type.
220     pub fn type_name<T: ?Sized>() -> &'static str;
221
222     /// Gets an identifier which is globally unique to the specified type. This
223     /// function will return the same value for a type regardless of whichever
224     /// crate it is invoked in.
225     pub fn type_id<T: ?Sized + 'static>() -> u64;
226
227     /// Creates a value initialized to so that its drop flag,
228     /// if any, says that it has been dropped.
229     ///
230     /// `init_dropped` is unsafe because it returns a datum with all
231     /// of its bytes set to the drop flag, which generally does not
232     /// correspond to a valid value.
233     ///
234     /// This intrinsic is likely to be deprecated in the future when
235     /// Rust moves to non-zeroing dynamic drop (and thus removes the
236     /// embedded drop flags that are being established by this
237     /// intrinsic).
238     pub fn init_dropped<T>() -> T;
239
240     /// Creates a value initialized to zero.
241     ///
242     /// `init` is unsafe because it returns a zeroed-out datum,
243     /// which is unsafe unless T is `Copy`.  Also, even if T is
244     /// `Copy`, an all-zero value may not correspond to any legitimate
245     /// state for the type in question.
246     pub fn init<T>() -> T;
247
248     /// Creates an uninitialized value.
249     ///
250     /// `uninit` is unsafe because there is no guarantee of what its
251     /// contents are. In particular its drop-flag may be set to any
252     /// state, which means it may claim either dropped or
253     /// undropped. In the general case one must use `ptr::write` to
254     /// initialize memory previous set to the result of `uninit`.
255     pub fn uninit<T>() -> T;
256
257     /// Moves a value out of scope without running drop glue.
258     pub fn forget<T>(_: T) -> ();
259
260     /// Unsafely transforms a value of one type into a value of another type.
261     ///
262     /// Both types must have the same size.
263     ///
264     /// # Examples
265     ///
266     /// ```
267     /// use std::mem;
268     ///
269     /// let array: &[u8] = unsafe { mem::transmute("Rust") };
270     /// assert_eq!(array, [82, 117, 115, 116]);
271     /// ```
272     #[stable(feature = "rust1", since = "1.0.0")]
273     pub fn transmute<T, U>(e: T) -> U;
274
275     /// Gives the address for the return value of the enclosing function.
276     ///
277     /// Using this intrinsic in a function that does not use an out pointer
278     /// will trigger a compiler error.
279     pub fn return_address() -> *const u8;
280
281     /// Returns `true` if the actual type given as `T` requires drop
282     /// glue; returns `false` if the actual type provided for `T`
283     /// implements `Copy`.
284     ///
285     /// If the actual type neither requires drop glue nor implements
286     /// `Copy`, then may return `true` or `false`.
287     pub fn needs_drop<T>() -> bool;
288
289     /// Calculates the offset from a pointer.
290     ///
291     /// This is implemented as an intrinsic to avoid converting to and from an
292     /// integer, since the conversion would throw away aliasing information.
293     ///
294     /// # Safety
295     ///
296     /// Both the starting and resulting pointer must be either in bounds or one
297     /// byte past the end of an allocated object. If either pointer is out of
298     /// bounds or arithmetic overflow occurs then any further use of the
299     /// returned value will result in undefined behavior.
300     pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
301
302     /// Calculates the offset from a pointer, potentially wrapping.
303     ///
304     /// This is implemented as an intrinsic to avoid converting to and from an
305     /// integer, since the conversion inhibits certain optimizations.
306     ///
307     /// # Safety
308     ///
309     /// Unlike the `offset` intrinsic, this intrinsic does not restrict the
310     /// resulting pointer to point into or one byte past the end of an allocated
311     /// object, and it wraps with two's complement arithmetic. The resulting
312     /// value is not necessarily valid to be used to actually access memory.
313     pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
314
315     /// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
316     /// and destination may *not* overlap.
317     ///
318     /// `copy_nonoverlapping` is semantically equivalent to C's `memcpy`.
319     ///
320     /// # Safety
321     ///
322     /// Beyond requiring that the program must be allowed to access both regions
323     /// of memory, it is Undefined Behavior for source and destination to
324     /// overlap. Care must also be taken with the ownership of `src` and
325     /// `dst`. This method semantically moves the values of `src` into `dst`.
326     /// However it does not drop the contents of `dst`, or prevent the contents
327     /// of `src` from being dropped or used.
328     ///
329     /// # Examples
330     ///
331     /// A safe swap function:
332     ///
333     /// ```
334     /// use std::mem;
335     /// use std::ptr;
336     ///
337     /// # #[allow(dead_code)]
338     /// fn swap<T>(x: &mut T, y: &mut T) {
339     ///     unsafe {
340     ///         // Give ourselves some scratch space to work with
341     ///         let mut t: T = mem::uninitialized();
342     ///
343     ///         // Perform the swap, `&mut` pointers never alias
344     ///         ptr::copy_nonoverlapping(x, &mut t, 1);
345     ///         ptr::copy_nonoverlapping(y, x, 1);
346     ///         ptr::copy_nonoverlapping(&t, y, 1);
347     ///
348     ///         // y and t now point to the same thing, but we need to completely forget `tmp`
349     ///         // because it's no longer relevant.
350     ///         mem::forget(t);
351     ///     }
352     /// }
353     /// ```
354     #[stable(feature = "rust1", since = "1.0.0")]
355     pub fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
356
357     /// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
358     /// and destination may overlap.
359     ///
360     /// `copy` is semantically equivalent to C's `memmove`.
361     ///
362     /// # Safety
363     ///
364     /// Care must be taken with the ownership of `src` and `dst`.
365     /// This method semantically moves the values of `src` into `dst`.
366     /// However it does not drop the contents of `dst`, or prevent the contents of `src`
367     /// from being dropped or used.
368     ///
369     /// # Examples
370     ///
371     /// Efficiently create a Rust vector from an unsafe buffer:
372     ///
373     /// ```
374     /// use std::ptr;
375     ///
376     /// # #[allow(dead_code)]
377     /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
378     ///     let mut dst = Vec::with_capacity(elts);
379     ///     dst.set_len(elts);
380     ///     ptr::copy(ptr, dst.as_mut_ptr(), elts);
381     ///     dst
382     /// }
383     /// ```
384     ///
385     #[stable(feature = "rust1", since = "1.0.0")]
386     pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
387
388     /// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
389     /// bytes of memory starting at `dst` to `val`.
390     #[stable(feature = "rust1", since = "1.0.0")]
391     pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
392
393     /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
394     /// a size of `count` * `size_of::<T>()` and an alignment of
395     /// `min_align_of::<T>()`
396     ///
397     /// The volatile parameter is set to `true`, so it will not be optimized out.
398     pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T,
399                                                   count: usize);
400     /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
401     /// a size of `count` * `size_of::<T>()` and an alignment of
402     /// `min_align_of::<T>()`
403     ///
404     /// The volatile parameter is set to `true`, so it will not be optimized out.
405     pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
406     /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
407     /// size of `count` * `size_of::<T>()` and an alignment of
408     /// `min_align_of::<T>()`.
409     ///
410     /// The volatile parameter is set to `true`, so it will not be optimized out.
411     pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
412
413     /// Perform a volatile load from the `src` pointer.
414     pub fn volatile_load<T>(src: *const T) -> T;
415     /// Perform a volatile store to the `dst` pointer.
416     pub fn volatile_store<T>(dst: *mut T, val: T);
417
418     /// Returns the square root of an `f32`
419     pub fn sqrtf32(x: f32) -> f32;
420     /// Returns the square root of an `f64`
421     pub fn sqrtf64(x: f64) -> f64;
422
423     /// Raises an `f32` to an integer power.
424     pub fn powif32(a: f32, x: i32) -> f32;
425     /// Raises an `f64` to an integer power.
426     pub fn powif64(a: f64, x: i32) -> f64;
427
428     /// Returns the sine of an `f32`.
429     pub fn sinf32(x: f32) -> f32;
430     /// Returns the sine of an `f64`.
431     pub fn sinf64(x: f64) -> f64;
432
433     /// Returns the cosine of an `f32`.
434     pub fn cosf32(x: f32) -> f32;
435     /// Returns the cosine of an `f64`.
436     pub fn cosf64(x: f64) -> f64;
437
438     /// Raises an `f32` to an `f32` power.
439     pub fn powf32(a: f32, x: f32) -> f32;
440     /// Raises an `f64` to an `f64` power.
441     pub fn powf64(a: f64, x: f64) -> f64;
442
443     /// Returns the exponential of an `f32`.
444     pub fn expf32(x: f32) -> f32;
445     /// Returns the exponential of an `f64`.
446     pub fn expf64(x: f64) -> f64;
447
448     /// Returns 2 raised to the power of an `f32`.
449     pub fn exp2f32(x: f32) -> f32;
450     /// Returns 2 raised to the power of an `f64`.
451     pub fn exp2f64(x: f64) -> f64;
452
453     /// Returns the natural logarithm of an `f32`.
454     pub fn logf32(x: f32) -> f32;
455     /// Returns the natural logarithm of an `f64`.
456     pub fn logf64(x: f64) -> f64;
457
458     /// Returns the base 10 logarithm of an `f32`.
459     pub fn log10f32(x: f32) -> f32;
460     /// Returns the base 10 logarithm of an `f64`.
461     pub fn log10f64(x: f64) -> f64;
462
463     /// Returns the base 2 logarithm of an `f32`.
464     pub fn log2f32(x: f32) -> f32;
465     /// Returns the base 2 logarithm of an `f64`.
466     pub fn log2f64(x: f64) -> f64;
467
468     /// Returns `a * b + c` for `f32` values.
469     pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
470     /// Returns `a * b + c` for `f64` values.
471     pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
472
473     /// Returns the absolute value of an `f32`.
474     pub fn fabsf32(x: f32) -> f32;
475     /// Returns the absolute value of an `f64`.
476     pub fn fabsf64(x: f64) -> f64;
477
478     /// Copies the sign from `y` to `x` for `f32` values.
479     pub fn copysignf32(x: f32, y: f32) -> f32;
480     /// Copies the sign from `y` to `x` for `f64` values.
481     pub fn copysignf64(x: f64, y: f64) -> f64;
482
483     /// Returns the largest integer less than or equal to an `f32`.
484     pub fn floorf32(x: f32) -> f32;
485     /// Returns the largest integer less than or equal to an `f64`.
486     pub fn floorf64(x: f64) -> f64;
487
488     /// Returns the smallest integer greater than or equal to an `f32`.
489     pub fn ceilf32(x: f32) -> f32;
490     /// Returns the smallest integer greater than or equal to an `f64`.
491     pub fn ceilf64(x: f64) -> f64;
492
493     /// Returns the integer part of an `f32`.
494     pub fn truncf32(x: f32) -> f32;
495     /// Returns the integer part of an `f64`.
496     pub fn truncf64(x: f64) -> f64;
497
498     /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
499     /// if the argument is not an integer.
500     pub fn rintf32(x: f32) -> f32;
501     /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
502     /// if the argument is not an integer.
503     pub fn rintf64(x: f64) -> f64;
504
505     /// Returns the nearest integer to an `f32`.
506     pub fn nearbyintf32(x: f32) -> f32;
507     /// Returns the nearest integer to an `f64`.
508     pub fn nearbyintf64(x: f64) -> f64;
509
510     /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
511     pub fn roundf32(x: f32) -> f32;
512     /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
513     pub fn roundf64(x: f64) -> f64;
514
515     /// Returns the number of bits set in an integer type `T`
516     pub fn ctpop<T>(x: T) -> T;
517
518     /// Returns the number of leading bits unset in an integer type `T`
519     pub fn ctlz<T>(x: T) -> T;
520
521     /// Returns the number of trailing bits unset in an integer type `T`
522     pub fn cttz<T>(x: T) -> T;
523
524     /// Reverses the bytes in an integer type `T`.
525     pub fn bswap<T>(x: T) -> T;
526
527     /// Performs checked integer addition.
528     pub fn add_with_overflow<T>(x: T, y: T) -> (T, bool);
529
530     /// Performs checked integer subtraction
531     pub fn sub_with_overflow<T>(x: T, y: T) -> (T, bool);
532
533     /// Performs checked integer multiplication
534     pub fn mul_with_overflow<T>(x: T, y: T) -> (T, bool);
535
536     /// Performs an unchecked division, resulting in undefined behavior
537     /// where y = 0 or x = `T::min_value()` and y = -1
538     pub fn unchecked_div<T>(x: T, y: T) -> T;
539     /// Returns the remainder of an unchecked division, resulting in
540     /// undefined behavior where y = 0 or x = `T::min_value()` and y = -1
541     pub fn unchecked_rem<T>(x: T, y: T) -> T;
542
543     /// Returns (a + b) mod 2^N, where N is the width of T in bits.
544     pub fn overflowing_add<T>(a: T, b: T) -> T;
545     /// Returns (a - b) mod 2^N, where N is the width of T in bits.
546     pub fn overflowing_sub<T>(a: T, b: T) -> T;
547     /// Returns (a * b) mod 2^N, where N is the width of T in bits.
548     pub fn overflowing_mul<T>(a: T, b: T) -> T;
549
550     /// Returns the value of the discriminant for the variant in 'v',
551     /// cast to a `u64`; if `T` has no discriminant, returns 0.
552     pub fn discriminant_value<T>(v: &T) -> u64;
553
554     /// Rust's "try catch" construct which invokes the function pointer `f` with
555     /// the data pointer `data`.
556     ///
557     /// The third pointer is a target-specific data pointer which is filled in
558     /// with the specifics of the exception that occurred. For examples on Unix
559     /// platforms this is a `*mut *mut T` which is filled in by the compiler and
560     /// on MSVC it's `*mut [usize; 2]`. For more information see the compiler's
561     /// source as well as std's catch implementation.
562     #[cfg(not(stage0))]
563     pub fn try(f: fn(*mut u8), data: *mut u8, local_ptr: *mut u8) -> i32;
564     #[cfg(stage0)]
565     pub fn try(f: fn(*mut u8), data: *mut u8) -> *mut u8;
566 }