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.
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.
11 //! rustc compiler intrinsics.
13 //! The corresponding definitions are in librustc_trans/trans/intrinsic.rs.
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
22 //! [volatile]: http://llvm.org/docs/LangRef.html#volatile-memory-accesses
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]].
30 //! [atomics]: http://llvm.org/docs/Atomics.html
32 //! A quick refresher on memory ordering:
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`.
42 #![unstable(feature = "core")]
43 #![allow(missing_docs)]
47 extern "rust-intrinsic" {
49 // NB: These intrinsics take raw pointers because they mutate aliased
50 // memory, which is not valid for either `&` or `&mut`.
52 pub fn atomic_cxchg<T>(dst: *mut T, old: T, src: T) -> T;
53 pub fn atomic_cxchg_acq<T>(dst: *mut T, old: T, src: T) -> T;
54 pub fn atomic_cxchg_rel<T>(dst: *mut T, old: T, src: T) -> T;
55 pub fn atomic_cxchg_acqrel<T>(dst: *mut T, old: T, src: T) -> T;
56 pub fn atomic_cxchg_relaxed<T>(dst: *mut T, old: T, src: T) -> T;
58 pub fn atomic_load<T>(src: *const T) -> T;
59 pub fn atomic_load_acq<T>(src: *const T) -> T;
60 pub fn atomic_load_relaxed<T>(src: *const T) -> T;
61 pub fn atomic_load_unordered<T>(src: *const T) -> T;
63 pub fn atomic_store<T>(dst: *mut T, val: T);
64 pub fn atomic_store_rel<T>(dst: *mut T, val: T);
65 pub fn atomic_store_relaxed<T>(dst: *mut T, val: T);
66 pub fn atomic_store_unordered<T>(dst: *mut T, val: T);
68 pub fn atomic_xchg<T>(dst: *mut T, src: T) -> T;
69 pub fn atomic_xchg_acq<T>(dst: *mut T, src: T) -> T;
70 pub fn atomic_xchg_rel<T>(dst: *mut T, src: T) -> T;
71 pub fn atomic_xchg_acqrel<T>(dst: *mut T, src: T) -> T;
72 pub fn atomic_xchg_relaxed<T>(dst: *mut T, src: T) -> T;
74 pub fn atomic_xadd<T>(dst: *mut T, src: T) -> T;
75 pub fn atomic_xadd_acq<T>(dst: *mut T, src: T) -> T;
76 pub fn atomic_xadd_rel<T>(dst: *mut T, src: T) -> T;
77 pub fn atomic_xadd_acqrel<T>(dst: *mut T, src: T) -> T;
78 pub fn atomic_xadd_relaxed<T>(dst: *mut T, src: T) -> T;
80 pub fn atomic_xsub<T>(dst: *mut T, src: T) -> T;
81 pub fn atomic_xsub_acq<T>(dst: *mut T, src: T) -> T;
82 pub fn atomic_xsub_rel<T>(dst: *mut T, src: T) -> T;
83 pub fn atomic_xsub_acqrel<T>(dst: *mut T, src: T) -> T;
84 pub fn atomic_xsub_relaxed<T>(dst: *mut T, src: T) -> T;
86 pub fn atomic_and<T>(dst: *mut T, src: T) -> T;
87 pub fn atomic_and_acq<T>(dst: *mut T, src: T) -> T;
88 pub fn atomic_and_rel<T>(dst: *mut T, src: T) -> T;
89 pub fn atomic_and_acqrel<T>(dst: *mut T, src: T) -> T;
90 pub fn atomic_and_relaxed<T>(dst: *mut T, src: T) -> T;
92 pub fn atomic_nand<T>(dst: *mut T, src: T) -> T;
93 pub fn atomic_nand_acq<T>(dst: *mut T, src: T) -> T;
94 pub fn atomic_nand_rel<T>(dst: *mut T, src: T) -> T;
95 pub fn atomic_nand_acqrel<T>(dst: *mut T, src: T) -> T;
96 pub fn atomic_nand_relaxed<T>(dst: *mut T, src: T) -> T;
98 pub fn atomic_or<T>(dst: *mut T, src: T) -> T;
99 pub fn atomic_or_acq<T>(dst: *mut T, src: T) -> T;
100 pub fn atomic_or_rel<T>(dst: *mut T, src: T) -> T;
101 pub fn atomic_or_acqrel<T>(dst: *mut T, src: T) -> T;
102 pub fn atomic_or_relaxed<T>(dst: *mut T, src: T) -> T;
104 pub fn atomic_xor<T>(dst: *mut T, src: T) -> T;
105 pub fn atomic_xor_acq<T>(dst: *mut T, src: T) -> T;
106 pub fn atomic_xor_rel<T>(dst: *mut T, src: T) -> T;
107 pub fn atomic_xor_acqrel<T>(dst: *mut T, src: T) -> T;
108 pub fn atomic_xor_relaxed<T>(dst: *mut T, src: T) -> T;
110 pub fn atomic_max<T>(dst: *mut T, src: T) -> T;
111 pub fn atomic_max_acq<T>(dst: *mut T, src: T) -> T;
112 pub fn atomic_max_rel<T>(dst: *mut T, src: T) -> T;
113 pub fn atomic_max_acqrel<T>(dst: *mut T, src: T) -> T;
114 pub fn atomic_max_relaxed<T>(dst: *mut T, src: T) -> T;
116 pub fn atomic_min<T>(dst: *mut T, src: T) -> T;
117 pub fn atomic_min_acq<T>(dst: *mut T, src: T) -> T;
118 pub fn atomic_min_rel<T>(dst: *mut T, src: T) -> T;
119 pub fn atomic_min_acqrel<T>(dst: *mut T, src: T) -> T;
120 pub fn atomic_min_relaxed<T>(dst: *mut T, src: T) -> T;
122 pub fn atomic_umin<T>(dst: *mut T, src: T) -> T;
123 pub fn atomic_umin_acq<T>(dst: *mut T, src: T) -> T;
124 pub fn atomic_umin_rel<T>(dst: *mut T, src: T) -> T;
125 pub fn atomic_umin_acqrel<T>(dst: *mut T, src: T) -> T;
126 pub fn atomic_umin_relaxed<T>(dst: *mut T, src: T) -> T;
128 pub fn atomic_umax<T>(dst: *mut T, src: T) -> T;
129 pub fn atomic_umax_acq<T>(dst: *mut T, src: T) -> T;
130 pub fn atomic_umax_rel<T>(dst: *mut T, src: T) -> T;
131 pub fn atomic_umax_acqrel<T>(dst: *mut T, src: T) -> T;
132 pub fn atomic_umax_relaxed<T>(dst: *mut T, src: T) -> T;
135 extern "rust-intrinsic" {
137 pub fn atomic_fence();
138 pub fn atomic_fence_acq();
139 pub fn atomic_fence_rel();
140 pub fn atomic_fence_acqrel();
142 /// A compiler-only memory barrier.
144 /// Memory accesses will never be reordered across this barrier by the compiler,
145 /// but no instructions will be emitted for it. This is appropriate for operations
146 /// on the same thread that may be preempted, such as when interacting with signal
148 pub fn atomic_singlethreadfence();
149 pub fn atomic_singlethreadfence_acq();
150 pub fn atomic_singlethreadfence_rel();
151 pub fn atomic_singlethreadfence_acqrel();
153 /// Aborts the execution of the process.
156 /// Tells LLVM that this point in the code is not reachable,
157 /// enabling further optimizations.
159 /// NB: This is very different from the `unreachable!()` macro!
160 pub fn unreachable() -> !;
162 /// Informs the optimizer that a condition is always true.
163 /// If the condition is false, the behavior is undefined.
165 /// No code is generated for this intrinsic, but the optimizer will try
166 /// to preserve it (and its condition) between passes, which may interfere
167 /// with optimization of surrounding code and reduce performance. It should
168 /// not be used if the invariant can be discovered by the optimizer on its
169 /// own, or if it does not enable any significant optimizations.
170 pub fn assume(b: bool);
172 /// Executes a breakpoint trap, for inspection by a debugger.
175 /// The size of a type in bytes.
177 /// This is the exact number of bytes in memory taken up by a
178 /// value of the given type. In other words, a memset of this size
179 /// would *exactly* overwrite a value. When laid out in vectors
180 /// and structures there may be additional padding between
182 pub fn size_of<T>() -> usize;
184 /// Moves a value to an uninitialized memory location.
186 /// Drop glue is not run on the destination.
187 pub fn move_val_init<T>(dst: &mut T, src: T);
189 pub fn min_align_of<T>() -> usize;
190 pub fn pref_align_of<T>() -> usize;
192 pub fn size_of_val<T: ?Sized>(_: &T) -> usize;
193 pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize;
194 pub fn drop_in_place<T: ?Sized>(_: *mut T);
196 /// Gets a static string slice containing the name of a type.
197 pub fn type_name<T: ?Sized>() -> &'static str;
199 /// Gets an identifier which is globally unique to the specified type. This
200 /// function will return the same value for a type regardless of whichever
201 /// crate it is invoked in.
202 pub fn type_id<T: ?Sized + 'static>() -> u64;
204 /// Creates a value initialized to so that its drop flag,
205 /// if any, says that it has been dropped.
207 /// `init_dropped` is unsafe because it returns a datum with all
208 /// of its bytes set to the drop flag, which generally does not
209 /// correspond to a valid value.
211 /// This intrinsic is likely to be deprecated in the future when
212 /// Rust moves to non-zeroing dynamic drop (and thus removes the
213 /// embedded drop flags that are being established by this
215 pub fn init_dropped<T>() -> T;
217 /// Creates a value initialized to zero.
219 /// `init` is unsafe because it returns a zeroed-out datum,
220 /// which is unsafe unless T is `Copy`. Also, even if T is
221 /// `Copy`, an all-zero value may not correspond to any legitimate
222 /// state for the type in question.
223 pub fn init<T>() -> T;
225 /// Creates an uninitialized value.
227 /// `uninit` is unsafe because there is no guarantee of what its
228 /// contents are. In particular its drop-flag may be set to any
229 /// state, which means it may claim either dropped or
230 /// undropped. In the general case one must use `ptr::write` to
231 /// initialize memory previous set to the result of `uninit`.
232 pub fn uninit<T>() -> T;
234 /// Moves a value out of scope without running drop glue.
235 pub fn forget<T>(_: T) -> ();
237 /// Unsafely transforms a value of one type into a value of another type.
239 /// Both types must have the same size.
246 /// let v: &[u8] = unsafe { mem::transmute("L") };
247 /// assert!(v == [76]);
249 #[stable(feature = "rust1", since = "1.0.0")]
250 pub fn transmute<T,U>(e: T) -> U;
252 /// Gives the address for the return value of the enclosing function.
254 /// Using this intrinsic in a function that does not use an out pointer
255 /// will trigger a compiler error.
256 pub fn return_address() -> *const u8;
258 /// Returns `true` if the actual type given as `T` requires drop
259 /// glue; returns `false` if the actual type provided for `T`
260 /// implements `Copy`.
262 /// If the actual type neither requires drop glue nor implements
263 /// `Copy`, then may return `true` or `false`.
264 pub fn needs_drop<T>() -> bool;
266 /// Calculates the offset from a pointer.
268 /// This is implemented as an intrinsic to avoid converting to and from an
269 /// integer, since the conversion would throw away aliasing information.
273 /// Both the starting and resulting pointer must be either in bounds or one
274 /// byte past the end of an allocated object. If either pointer is out of
275 /// bounds or arithmetic overflow occurs then any further use of the
276 /// returned value will result in undefined behavior.
277 pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
279 /// Calculates the offset from a pointer, potentially wrapping.
281 /// This is implemented as an intrinsic to avoid converting to and from an
282 /// integer, since the conversion inhibits certain optimizations.
286 /// Unlike the `offset` intrinsic, this intrinsic does not restrict the
287 /// resulting pointer to point into or one byte past the end of an allocated
288 /// object, and it wraps with two's complement arithmetic. The resulting
289 /// value is not necessarily valid to be used to actually access memory.
290 pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
292 /// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
293 /// and destination may *not* overlap.
295 /// `copy_nonoverlapping` is semantically equivalent to C's `memcpy`.
299 /// Beyond requiring that the program must be allowed to access both regions
300 /// of memory, it is Undefined Behaviour for source and destination to
301 /// overlap. Care must also be taken with the ownership of `src` and
302 /// `dst`. This method semantically moves the values of `src` into `dst`.
303 /// However it does not drop the contents of `dst`, or prevent the contents
304 /// of `src` from being dropped or used.
308 /// A safe swap function:
314 /// fn swap<T>(x: &mut T, y: &mut T) {
316 /// // Give ourselves some scratch space to work with
317 /// let mut t: T = mem::uninitialized();
319 /// // Perform the swap, `&mut` pointers never alias
320 /// ptr::copy_nonoverlapping(x, &mut t, 1);
321 /// ptr::copy_nonoverlapping(y, x, 1);
322 /// ptr::copy_nonoverlapping(&t, y, 1);
324 /// // y and t now point to the same thing, but we need to completely forget `tmp`
325 /// // because it's no longer relevant.
330 #[stable(feature = "rust1", since = "1.0.0")]
331 pub fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
333 /// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
334 /// and destination may overlap.
336 /// `copy` is semantically equivalent to C's `memmove`.
340 /// Care must be taken with the ownership of `src` and `dst`.
341 /// This method semantically moves the values of `src` into `dst`.
342 /// However it does not drop the contents of `dst`, or prevent the contents of `src`
343 /// from being dropped or used.
347 /// Efficiently create a Rust vector from an unsafe buffer:
352 /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
353 /// let mut dst = Vec::with_capacity(elts);
354 /// dst.set_len(elts);
355 /// ptr::copy(ptr, dst.as_mut_ptr(), elts);
360 #[stable(feature = "rust1", since = "1.0.0")]
361 pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
363 /// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
364 /// bytes of memory starting at `dst` to `c`.
365 #[stable(feature = "rust1", since = "1.0.0")]
366 pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
368 /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
369 /// a size of `count` * `size_of::<T>()` and an alignment of
370 /// `min_align_of::<T>()`
372 /// The volatile parameter parameter is set to `true`, so it will not be optimized out.
373 pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T,
375 /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
376 /// a size of `count` * `size_of::<T>()` and an alignment of
377 /// `min_align_of::<T>()`
379 /// The volatile parameter parameter is set to `true`, so it will not be optimized out.
380 pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
381 /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
382 /// size of `count` * `size_of::<T>()` and an alignment of
383 /// `min_align_of::<T>()`.
385 /// The volatile parameter parameter is set to `true`, so it will not be optimized out.
386 pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
388 /// Perform a volatile load from the `src` pointer.
389 pub fn volatile_load<T>(src: *const T) -> T;
390 /// Perform a volatile store to the `dst` pointer.
391 pub fn volatile_store<T>(dst: *mut T, val: T);
393 /// Returns the square root of an `f32`
394 pub fn sqrtf32(x: f32) -> f32;
395 /// Returns the square root of an `f64`
396 pub fn sqrtf64(x: f64) -> f64;
398 /// Raises an `f32` to an integer power.
399 pub fn powif32(a: f32, x: i32) -> f32;
400 /// Raises an `f64` to an integer power.
401 pub fn powif64(a: f64, x: i32) -> f64;
403 /// Returns the sine of an `f32`.
404 pub fn sinf32(x: f32) -> f32;
405 /// Returns the sine of an `f64`.
406 pub fn sinf64(x: f64) -> f64;
408 /// Returns the cosine of an `f32`.
409 pub fn cosf32(x: f32) -> f32;
410 /// Returns the cosine of an `f64`.
411 pub fn cosf64(x: f64) -> f64;
413 /// Raises an `f32` to an `f32` power.
414 pub fn powf32(a: f32, x: f32) -> f32;
415 /// Raises an `f64` to an `f64` power.
416 pub fn powf64(a: f64, x: f64) -> f64;
418 /// Returns the exponential of an `f32`.
419 pub fn expf32(x: f32) -> f32;
420 /// Returns the exponential of an `f64`.
421 pub fn expf64(x: f64) -> f64;
423 /// Returns 2 raised to the power of an `f32`.
424 pub fn exp2f32(x: f32) -> f32;
425 /// Returns 2 raised to the power of an `f64`.
426 pub fn exp2f64(x: f64) -> f64;
428 /// Returns the natural logarithm of an `f32`.
429 pub fn logf32(x: f32) -> f32;
430 /// Returns the natural logarithm of an `f64`.
431 pub fn logf64(x: f64) -> f64;
433 /// Returns the base 10 logarithm of an `f32`.
434 pub fn log10f32(x: f32) -> f32;
435 /// Returns the base 10 logarithm of an `f64`.
436 pub fn log10f64(x: f64) -> f64;
438 /// Returns the base 2 logarithm of an `f32`.
439 pub fn log2f32(x: f32) -> f32;
440 /// Returns the base 2 logarithm of an `f64`.
441 pub fn log2f64(x: f64) -> f64;
443 /// Returns `a * b + c` for `f32` values.
444 pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
445 /// Returns `a * b + c` for `f64` values.
446 pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
448 /// Returns the absolute value of an `f32`.
449 pub fn fabsf32(x: f32) -> f32;
450 /// Returns the absolute value of an `f64`.
451 pub fn fabsf64(x: f64) -> f64;
453 /// Copies the sign from `y` to `x` for `f32` values.
454 pub fn copysignf32(x: f32, y: f32) -> f32;
455 /// Copies the sign from `y` to `x` for `f64` values.
456 pub fn copysignf64(x: f64, y: f64) -> f64;
458 /// Returns the largest integer less than or equal to an `f32`.
459 pub fn floorf32(x: f32) -> f32;
460 /// Returns the largest integer less than or equal to an `f64`.
461 pub fn floorf64(x: f64) -> f64;
463 /// Returns the smallest integer greater than or equal to an `f32`.
464 pub fn ceilf32(x: f32) -> f32;
465 /// Returns the smallest integer greater than or equal to an `f64`.
466 pub fn ceilf64(x: f64) -> f64;
468 /// Returns the integer part of an `f32`.
469 pub fn truncf32(x: f32) -> f32;
470 /// Returns the integer part of an `f64`.
471 pub fn truncf64(x: f64) -> f64;
473 /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
474 /// if the argument is not an integer.
475 pub fn rintf32(x: f32) -> f32;
476 /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
477 /// if the argument is not an integer.
478 pub fn rintf64(x: f64) -> f64;
480 /// Returns the nearest integer to an `f32`.
481 pub fn nearbyintf32(x: f32) -> f32;
482 /// Returns the nearest integer to an `f64`.
483 pub fn nearbyintf64(x: f64) -> f64;
485 /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
486 pub fn roundf32(x: f32) -> f32;
487 /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
488 pub fn roundf64(x: f64) -> f64;
490 /// Returns the number of bits set in a `u8`.
491 pub fn ctpop8(x: u8) -> u8;
492 /// Returns the number of bits set in a `u16`.
493 pub fn ctpop16(x: u16) -> u16;
494 /// Returns the number of bits set in a `u32`.
495 pub fn ctpop32(x: u32) -> u32;
496 /// Returns the number of bits set in a `u64`.
497 pub fn ctpop64(x: u64) -> u64;
499 /// Returns the number of leading bits unset in a `u8`.
500 pub fn ctlz8(x: u8) -> u8;
501 /// Returns the number of leading bits unset in a `u16`.
502 pub fn ctlz16(x: u16) -> u16;
503 /// Returns the number of leading bits unset in a `u32`.
504 pub fn ctlz32(x: u32) -> u32;
505 /// Returns the number of leading bits unset in a `u64`.
506 pub fn ctlz64(x: u64) -> u64;
508 /// Returns the number of trailing bits unset in a `u8`.
509 pub fn cttz8(x: u8) -> u8;
510 /// Returns the number of trailing bits unset in a `u16`.
511 pub fn cttz16(x: u16) -> u16;
512 /// Returns the number of trailing bits unset in a `u32`.
513 pub fn cttz32(x: u32) -> u32;
514 /// Returns the number of trailing bits unset in a `u64`.
515 pub fn cttz64(x: u64) -> u64;
517 /// Reverses the bytes in a `u16`.
518 pub fn bswap16(x: u16) -> u16;
519 /// Reverses the bytes in a `u32`.
520 pub fn bswap32(x: u32) -> u32;
521 /// Reverses the bytes in a `u64`.
522 pub fn bswap64(x: u64) -> u64;
524 /// Performs checked `i8` addition.
525 pub fn i8_add_with_overflow(x: i8, y: i8) -> (i8, bool);
526 /// Performs checked `i16` addition.
527 pub fn i16_add_with_overflow(x: i16, y: i16) -> (i16, bool);
528 /// Performs checked `i32` addition.
529 pub fn i32_add_with_overflow(x: i32, y: i32) -> (i32, bool);
530 /// Performs checked `i64` addition.
531 pub fn i64_add_with_overflow(x: i64, y: i64) -> (i64, bool);
533 /// Performs checked `u8` addition.
534 pub fn u8_add_with_overflow(x: u8, y: u8) -> (u8, bool);
535 /// Performs checked `u16` addition.
536 pub fn u16_add_with_overflow(x: u16, y: u16) -> (u16, bool);
537 /// Performs checked `u32` addition.
538 pub fn u32_add_with_overflow(x: u32, y: u32) -> (u32, bool);
539 /// Performs checked `u64` addition.
540 pub fn u64_add_with_overflow(x: u64, y: u64) -> (u64, bool);
542 /// Performs checked `i8` subtraction.
543 pub fn i8_sub_with_overflow(x: i8, y: i8) -> (i8, bool);
544 /// Performs checked `i16` subtraction.
545 pub fn i16_sub_with_overflow(x: i16, y: i16) -> (i16, bool);
546 /// Performs checked `i32` subtraction.
547 pub fn i32_sub_with_overflow(x: i32, y: i32) -> (i32, bool);
548 /// Performs checked `i64` subtraction.
549 pub fn i64_sub_with_overflow(x: i64, y: i64) -> (i64, bool);
551 /// Performs checked `u8` subtraction.
552 pub fn u8_sub_with_overflow(x: u8, y: u8) -> (u8, bool);
553 /// Performs checked `u16` subtraction.
554 pub fn u16_sub_with_overflow(x: u16, y: u16) -> (u16, bool);
555 /// Performs checked `u32` subtraction.
556 pub fn u32_sub_with_overflow(x: u32, y: u32) -> (u32, bool);
557 /// Performs checked `u64` subtraction.
558 pub fn u64_sub_with_overflow(x: u64, y: u64) -> (u64, bool);
560 /// Performs checked `i8` multiplication.
561 pub fn i8_mul_with_overflow(x: i8, y: i8) -> (i8, bool);
562 /// Performs checked `i16` multiplication.
563 pub fn i16_mul_with_overflow(x: i16, y: i16) -> (i16, bool);
564 /// Performs checked `i32` multiplication.
565 pub fn i32_mul_with_overflow(x: i32, y: i32) -> (i32, bool);
566 /// Performs checked `i64` multiplication.
567 pub fn i64_mul_with_overflow(x: i64, y: i64) -> (i64, bool);
569 /// Performs checked `u8` multiplication.
570 pub fn u8_mul_with_overflow(x: u8, y: u8) -> (u8, bool);
571 /// Performs checked `u16` multiplication.
572 pub fn u16_mul_with_overflow(x: u16, y: u16) -> (u16, bool);
573 /// Performs checked `u32` multiplication.
574 pub fn u32_mul_with_overflow(x: u32, y: u32) -> (u32, bool);
575 /// Performs checked `u64` multiplication.
576 pub fn u64_mul_with_overflow(x: u64, y: u64) -> (u64, bool);
578 /// Returns (a + b) mod 2^N, where N is the width of N in bits.
579 pub fn overflowing_add<T>(a: T, b: T) -> T;
580 /// Returns (a - b) mod 2^N, where N is the width of N in bits.
581 pub fn overflowing_sub<T>(a: T, b: T) -> T;
582 /// Returns (a * b) mod 2^N, where N is the width of N in bits.
583 pub fn overflowing_mul<T>(a: T, b: T) -> T;
585 /// Performs an unchecked signed division, which results in undefined behavior,
586 /// in cases where y == 0, or x == int::MIN and y == -1
587 pub fn unchecked_sdiv<T>(x: T, y: T) -> T;
588 /// Performs an unchecked unsigned division, which results in undefined behavior,
589 /// in cases where y == 0
590 pub fn unchecked_udiv<T>(x: T, y: T) -> T;
592 /// Returns the remainder of an unchecked signed division, which results in
593 /// undefined behavior, in cases where y == 0, or x == int::MIN and y == -1
594 pub fn unchecked_urem<T>(x: T, y: T) -> T;
595 /// Returns the remainder of an unchecked signed division, which results in
596 /// undefined behavior, in cases where y == 0
597 pub fn unchecked_srem<T>(x: T, y: T) -> T;
599 /// Returns the value of the discriminant for the variant in 'v',
600 /// cast to a `u64`; if `T` has no discriminant, returns 0.
601 pub fn discriminant_value<T>(v: &T) -> u64;