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_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",
47 #![allow(missing_docs)]
51 extern "rust-intrinsic" {
53 // NB: These intrinsics take raw pointers because they mutate aliased
54 // memory, which is not valid for either `&` or `&mut`.
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
;
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
;
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
);
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
;
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
;
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
;
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
;
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
;
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
;
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
;
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
;
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
;
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
;
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
;
139 extern "rust-intrinsic" {
141 pub fn atomic_fence();
142 pub fn atomic_fence_acq();
143 pub fn atomic_fence_rel();
144 pub fn atomic_fence_acqrel();
146 /// A compiler-only memory barrier.
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();
157 /// Aborts the execution of the process.
160 /// Tells LLVM that this point in the code is not reachable,
161 /// enabling further optimizations.
163 /// NB: This is very different from the `unreachable!()` macro!
164 pub fn unreachable() -> !;
166 /// Informs the optimizer that a condition is always true.
167 /// If the condition is false, the behavior is undefined.
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
);
176 /// Executes a breakpoint trap, for inspection by a debugger.
179 /// The size of a type in bytes.
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
186 pub fn size_of
<T
>() -> usize;
188 /// Moves a value to an uninitialized memory location.
190 /// Drop glue is not run on the destination.
191 pub fn move_val_init
<T
>(dst
: *mut T
, src
: T
);
193 pub fn min_align_of
<T
>() -> usize;
194 pub fn pref_align_of
<T
>() -> usize;
196 pub fn size_of_val
<T
: ?Sized
>(_
: &T
) -> usize;
197 pub fn min_align_of_val
<T
: ?Sized
>(_
: &T
) -> usize;
198 pub fn drop_in_place
<T
: ?Sized
>(_
: *mut T
);
200 /// Gets a static string slice containing the name of a type.
201 pub fn type_name
<T
: ?Sized
>() -> &'
static str;
203 /// Gets an identifier which is globally unique to the specified type. This
204 /// function will return the same value for a type regardless of whichever
205 /// crate it is invoked in.
206 pub fn type_id
<T
: ?Sized
+ '
static>() -> u64;
208 /// Creates a value initialized to so that its drop flag,
209 /// if any, says that it has been dropped.
211 /// `init_dropped` is unsafe because it returns a datum with all
212 /// of its bytes set to the drop flag, which generally does not
213 /// correspond to a valid value.
215 /// This intrinsic is likely to be deprecated in the future when
216 /// Rust moves to non-zeroing dynamic drop (and thus removes the
217 /// embedded drop flags that are being established by this
219 pub fn init_dropped
<T
>() -> T
;
221 /// Creates a value initialized to zero.
223 /// `init` is unsafe because it returns a zeroed-out datum,
224 /// which is unsafe unless T is `Copy`. Also, even if T is
225 /// `Copy`, an all-zero value may not correspond to any legitimate
226 /// state for the type in question.
227 pub fn init
<T
>() -> T
;
229 /// Creates an uninitialized value.
231 /// `uninit` is unsafe because there is no guarantee of what its
232 /// contents are. In particular its drop-flag may be set to any
233 /// state, which means it may claim either dropped or
234 /// undropped. In the general case one must use `ptr::write` to
235 /// initialize memory previous set to the result of `uninit`.
236 pub fn uninit
<T
>() -> T
;
238 /// Moves a value out of scope without running drop glue.
239 pub fn forget
<T
>(_
: T
) -> ();
241 /// Unsafely transforms a value of one type into a value of another type.
243 /// Both types must have the same size.
250 /// let array: &[u8] = unsafe { mem::transmute("Rust") };
251 /// assert_eq!(array, [82, 117, 115, 116]);
253 #[stable(feature = "rust1", since = "1.0.0")]
254 pub fn transmute
<T
, U
>(e
: T
) -> U
;
256 /// Gives the address for the return value of the enclosing function.
258 /// Using this intrinsic in a function that does not use an out pointer
259 /// will trigger a compiler error.
260 pub fn return_address() -> *const u8;
262 /// Returns `true` if the actual type given as `T` requires drop
263 /// glue; returns `false` if the actual type provided for `T`
264 /// implements `Copy`.
266 /// If the actual type neither requires drop glue nor implements
267 /// `Copy`, then may return `true` or `false`.
268 pub fn needs_drop
<T
>() -> bool
;
270 /// Calculates the offset from a pointer.
272 /// This is implemented as an intrinsic to avoid converting to and from an
273 /// integer, since the conversion would throw away aliasing information.
277 /// Both the starting and resulting pointer must be either in bounds or one
278 /// byte past the end of an allocated object. If either pointer is out of
279 /// bounds or arithmetic overflow occurs then any further use of the
280 /// returned value will result in undefined behavior.
281 pub fn offset
<T
>(dst
: *const T
, offset
: isize) -> *const T
;
283 /// Calculates the offset from a pointer, potentially wrapping.
285 /// This is implemented as an intrinsic to avoid converting to and from an
286 /// integer, since the conversion inhibits certain optimizations.
290 /// Unlike the `offset` intrinsic, this intrinsic does not restrict the
291 /// resulting pointer to point into or one byte past the end of an allocated
292 /// object, and it wraps with two's complement arithmetic. The resulting
293 /// value is not necessarily valid to be used to actually access memory.
294 pub fn arith_offset
<T
>(dst
: *const T
, offset
: isize) -> *const T
;
296 /// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
297 /// and destination may *not* overlap.
299 /// `copy_nonoverlapping` is semantically equivalent to C's `memcpy`.
303 /// Beyond requiring that the program must be allowed to access both regions
304 /// of memory, it is Undefined Behaviour for source and destination to
305 /// overlap. Care must also be taken with the ownership of `src` and
306 /// `dst`. This method semantically moves the values of `src` into `dst`.
307 /// However it does not drop the contents of `dst`, or prevent the contents
308 /// of `src` from being dropped or used.
312 /// A safe swap function:
318 /// fn swap<T>(x: &mut T, y: &mut T) {
320 /// // Give ourselves some scratch space to work with
321 /// let mut t: T = mem::uninitialized();
323 /// // Perform the swap, `&mut` pointers never alias
324 /// ptr::copy_nonoverlapping(x, &mut t, 1);
325 /// ptr::copy_nonoverlapping(y, x, 1);
326 /// ptr::copy_nonoverlapping(&t, y, 1);
328 /// // y and t now point to the same thing, but we need to completely forget `tmp`
329 /// // because it's no longer relevant.
334 #[stable(feature = "rust1", since = "1.0.0")]
335 pub fn copy_nonoverlapping
<T
>(src
: *const T
, dst
: *mut T
, count
: usize);
337 /// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
338 /// and destination may overlap.
340 /// `copy` is semantically equivalent to C's `memmove`.
344 /// Care must be taken with the ownership of `src` and `dst`.
345 /// This method semantically moves the values of `src` into `dst`.
346 /// However it does not drop the contents of `dst`, or prevent the contents of `src`
347 /// from being dropped or used.
351 /// Efficiently create a Rust vector from an unsafe buffer:
356 /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
357 /// let mut dst = Vec::with_capacity(elts);
358 /// dst.set_len(elts);
359 /// ptr::copy(ptr, dst.as_mut_ptr(), elts);
364 #[stable(feature = "rust1", since = "1.0.0")]
365 pub fn copy
<T
>(src
: *const T
, dst
: *mut T
, count
: usize);
367 /// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
368 /// bytes of memory starting at `dst` to `c`.
369 #[stable(feature = "rust1", since = "1.0.0")]
370 pub fn write_bytes
<T
>(dst
: *mut T
, val
: u8, count
: usize);
372 /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
373 /// a size of `count` * `size_of::<T>()` and an alignment of
374 /// `min_align_of::<T>()`
376 /// The volatile parameter parameter is set to `true`, so it will not be optimized out.
377 pub fn volatile_copy_nonoverlapping_memory
<T
>(dst
: *mut T
, src
: *const T
,
379 /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
380 /// a size of `count` * `size_of::<T>()` and an alignment of
381 /// `min_align_of::<T>()`
383 /// The volatile parameter parameter is set to `true`, so it will not be optimized out.
384 pub fn volatile_copy_memory
<T
>(dst
: *mut T
, src
: *const T
, count
: usize);
385 /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
386 /// size of `count` * `size_of::<T>()` and an alignment of
387 /// `min_align_of::<T>()`.
389 /// The volatile parameter parameter is set to `true`, so it will not be optimized out.
390 pub fn volatile_set_memory
<T
>(dst
: *mut T
, val
: u8, count
: usize);
392 /// Perform a volatile load from the `src` pointer.
393 pub fn volatile_load
<T
>(src
: *const T
) -> T
;
394 /// Perform a volatile store to the `dst` pointer.
395 pub fn volatile_store
<T
>(dst
: *mut T
, val
: T
);
397 /// Returns the square root of an `f32`
398 pub fn sqrtf32(x
: f32) -> f32;
399 /// Returns the square root of an `f64`
400 pub fn sqrtf64(x
: f64) -> f64;
402 /// Raises an `f32` to an integer power.
403 pub fn powif32(a
: f32, x
: i32) -> f32;
404 /// Raises an `f64` to an integer power.
405 pub fn powif64(a
: f64, x
: i32) -> f64;
407 /// Returns the sine of an `f32`.
408 pub fn sinf32(x
: f32) -> f32;
409 /// Returns the sine of an `f64`.
410 pub fn sinf64(x
: f64) -> f64;
412 /// Returns the cosine of an `f32`.
413 pub fn cosf32(x
: f32) -> f32;
414 /// Returns the cosine of an `f64`.
415 pub fn cosf64(x
: f64) -> f64;
417 /// Raises an `f32` to an `f32` power.
418 pub fn powf32(a
: f32, x
: f32) -> f32;
419 /// Raises an `f64` to an `f64` power.
420 pub fn powf64(a
: f64, x
: f64) -> f64;
422 /// Returns the exponential of an `f32`.
423 pub fn expf32(x
: f32) -> f32;
424 /// Returns the exponential of an `f64`.
425 pub fn expf64(x
: f64) -> f64;
427 /// Returns 2 raised to the power of an `f32`.
428 pub fn exp2f32(x
: f32) -> f32;
429 /// Returns 2 raised to the power of an `f64`.
430 pub fn exp2f64(x
: f64) -> f64;
432 /// Returns the natural logarithm of an `f32`.
433 pub fn logf32(x
: f32) -> f32;
434 /// Returns the natural logarithm of an `f64`.
435 pub fn logf64(x
: f64) -> f64;
437 /// Returns the base 10 logarithm of an `f32`.
438 pub fn log10f32(x
: f32) -> f32;
439 /// Returns the base 10 logarithm of an `f64`.
440 pub fn log10f64(x
: f64) -> f64;
442 /// Returns the base 2 logarithm of an `f32`.
443 pub fn log2f32(x
: f32) -> f32;
444 /// Returns the base 2 logarithm of an `f64`.
445 pub fn log2f64(x
: f64) -> f64;
447 /// Returns `a * b + c` for `f32` values.
448 pub fn fmaf32(a
: f32, b
: f32, c
: f32) -> f32;
449 /// Returns `a * b + c` for `f64` values.
450 pub fn fmaf64(a
: f64, b
: f64, c
: f64) -> f64;
452 /// Returns the absolute value of an `f32`.
453 pub fn fabsf32(x
: f32) -> f32;
454 /// Returns the absolute value of an `f64`.
455 pub fn fabsf64(x
: f64) -> f64;
457 /// Copies the sign from `y` to `x` for `f32` values.
458 pub fn copysignf32(x
: f32, y
: f32) -> f32;
459 /// Copies the sign from `y` to `x` for `f64` values.
460 pub fn copysignf64(x
: f64, y
: f64) -> f64;
462 /// Returns the largest integer less than or equal to an `f32`.
463 pub fn floorf32(x
: f32) -> f32;
464 /// Returns the largest integer less than or equal to an `f64`.
465 pub fn floorf64(x
: f64) -> f64;
467 /// Returns the smallest integer greater than or equal to an `f32`.
468 pub fn ceilf32(x
: f32) -> f32;
469 /// Returns the smallest integer greater than or equal to an `f64`.
470 pub fn ceilf64(x
: f64) -> f64;
472 /// Returns the integer part of an `f32`.
473 pub fn truncf32(x
: f32) -> f32;
474 /// Returns the integer part of an `f64`.
475 pub fn truncf64(x
: f64) -> f64;
477 /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
478 /// if the argument is not an integer.
479 pub fn rintf32(x
: f32) -> f32;
480 /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
481 /// if the argument is not an integer.
482 pub fn rintf64(x
: f64) -> f64;
484 /// Returns the nearest integer to an `f32`.
485 pub fn nearbyintf32(x
: f32) -> f32;
486 /// Returns the nearest integer to an `f64`.
487 pub fn nearbyintf64(x
: f64) -> f64;
489 /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
490 pub fn roundf32(x
: f32) -> f32;
491 /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
492 pub fn roundf64(x
: f64) -> f64;
494 /// Returns the number of bits set in a `u8`.
495 pub fn ctpop8(x
: u8) -> u8;
496 /// Returns the number of bits set in a `u16`.
497 pub fn ctpop16(x
: u16) -> u16;
498 /// Returns the number of bits set in a `u32`.
499 pub fn ctpop32(x
: u32) -> u32;
500 /// Returns the number of bits set in a `u64`.
501 pub fn ctpop64(x
: u64) -> u64;
503 /// Returns the number of leading bits unset in a `u8`.
504 pub fn ctlz8(x
: u8) -> u8;
505 /// Returns the number of leading bits unset in a `u16`.
506 pub fn ctlz16(x
: u16) -> u16;
507 /// Returns the number of leading bits unset in a `u32`.
508 pub fn ctlz32(x
: u32) -> u32;
509 /// Returns the number of leading bits unset in a `u64`.
510 pub fn ctlz64(x
: u64) -> u64;
512 /// Returns the number of trailing bits unset in a `u8`.
513 pub fn cttz8(x
: u8) -> u8;
514 /// Returns the number of trailing bits unset in a `u16`.
515 pub fn cttz16(x
: u16) -> u16;
516 /// Returns the number of trailing bits unset in a `u32`.
517 pub fn cttz32(x
: u32) -> u32;
518 /// Returns the number of trailing bits unset in a `u64`.
519 pub fn cttz64(x
: u64) -> u64;
521 /// Reverses the bytes in a `u16`.
522 pub fn bswap16(x
: u16) -> u16;
523 /// Reverses the bytes in a `u32`.
524 pub fn bswap32(x
: u32) -> u32;
525 /// Reverses the bytes in a `u64`.
526 pub fn bswap64(x
: u64) -> u64;
528 /// Performs checked `i8` addition.
529 pub fn i8_add_with_overflow(x
: i8, y
: i8) -> (i8, bool
);
530 /// Performs checked `i16` addition.
531 pub fn i16_add_with_overflow(x
: i16, y
: i16) -> (i16, bool
);
532 /// Performs checked `i32` addition.
533 pub fn i32_add_with_overflow(x
: i32, y
: i32) -> (i32, bool
);
534 /// Performs checked `i64` addition.
535 pub fn i64_add_with_overflow(x
: i64, y
: i64) -> (i64, bool
);
537 /// Performs checked `u8` addition.
538 pub fn u8_add_with_overflow(x
: u8, y
: u8) -> (u8, bool
);
539 /// Performs checked `u16` addition.
540 pub fn u16_add_with_overflow(x
: u16, y
: u16) -> (u16, bool
);
541 /// Performs checked `u32` addition.
542 pub fn u32_add_with_overflow(x
: u32, y
: u32) -> (u32, bool
);
543 /// Performs checked `u64` addition.
544 pub fn u64_add_with_overflow(x
: u64, y
: u64) -> (u64, bool
);
546 /// Performs checked `i8` subtraction.
547 pub fn i8_sub_with_overflow(x
: i8, y
: i8) -> (i8, bool
);
548 /// Performs checked `i16` subtraction.
549 pub fn i16_sub_with_overflow(x
: i16, y
: i16) -> (i16, bool
);
550 /// Performs checked `i32` subtraction.
551 pub fn i32_sub_with_overflow(x
: i32, y
: i32) -> (i32, bool
);
552 /// Performs checked `i64` subtraction.
553 pub fn i64_sub_with_overflow(x
: i64, y
: i64) -> (i64, bool
);
555 /// Performs checked `u8` subtraction.
556 pub fn u8_sub_with_overflow(x
: u8, y
: u8) -> (u8, bool
);
557 /// Performs checked `u16` subtraction.
558 pub fn u16_sub_with_overflow(x
: u16, y
: u16) -> (u16, bool
);
559 /// Performs checked `u32` subtraction.
560 pub fn u32_sub_with_overflow(x
: u32, y
: u32) -> (u32, bool
);
561 /// Performs checked `u64` subtraction.
562 pub fn u64_sub_with_overflow(x
: u64, y
: u64) -> (u64, bool
);
564 /// Performs checked `i8` multiplication.
565 pub fn i8_mul_with_overflow(x
: i8, y
: i8) -> (i8, bool
);
566 /// Performs checked `i16` multiplication.
567 pub fn i16_mul_with_overflow(x
: i16, y
: i16) -> (i16, bool
);
568 /// Performs checked `i32` multiplication.
569 pub fn i32_mul_with_overflow(x
: i32, y
: i32) -> (i32, bool
);
570 /// Performs checked `i64` multiplication.
571 pub fn i64_mul_with_overflow(x
: i64, y
: i64) -> (i64, bool
);
573 /// Performs checked `u8` multiplication.
574 pub fn u8_mul_with_overflow(x
: u8, y
: u8) -> (u8, bool
);
575 /// Performs checked `u16` multiplication.
576 pub fn u16_mul_with_overflow(x
: u16, y
: u16) -> (u16, bool
);
577 /// Performs checked `u32` multiplication.
578 pub fn u32_mul_with_overflow(x
: u32, y
: u32) -> (u32, bool
);
579 /// Performs checked `u64` multiplication.
580 pub fn u64_mul_with_overflow(x
: u64, y
: u64) -> (u64, bool
);
582 /// Returns (a + b) mod 2^N, where N is the width of N in bits.
583 pub fn overflowing_add
<T
>(a
: T
, b
: T
) -> T
;
584 /// Returns (a - b) mod 2^N, where N is the width of N in bits.
585 pub fn overflowing_sub
<T
>(a
: T
, b
: T
) -> T
;
586 /// Returns (a * b) mod 2^N, where N is the width of N in bits.
587 pub fn overflowing_mul
<T
>(a
: T
, b
: T
) -> T
;
589 /// Performs an unchecked signed division, which results in undefined behavior,
590 /// in cases where y == 0, or x == isize::MIN and y == -1
591 pub fn unchecked_sdiv
<T
>(x
: T
, y
: T
) -> T
;
592 /// Performs an unchecked unsigned division, which results in undefined behavior,
593 /// in cases where y == 0
594 pub fn unchecked_udiv
<T
>(x
: T
, y
: T
) -> T
;
596 /// Returns the remainder of an unchecked signed division, which results in
597 /// undefined behavior, in cases where y == 0, or x == isize::MIN and y == -1
598 pub fn unchecked_srem
<T
>(x
: T
, y
: T
) -> T
;
599 /// Returns the remainder of an unchecked unsigned division, which results in
600 /// undefined behavior, in cases where y == 0
601 pub fn unchecked_urem
<T
>(x
: T
, y
: T
) -> T
;
603 /// Returns the value of the discriminant for the variant in 'v',
604 /// cast to a `u64`; if `T` has no discriminant, returns 0.
605 pub fn discriminant_value
<T
>(v
: &T
) -> u64;
607 /// Rust's "try catch" construct which invokes the function pointer `f` with
608 /// the data pointer `data`, returning the exception payload if an exception
609 /// is thrown (aka the thread panics).
610 pub fn try(f
: fn(*mut u8), data
: *mut u8) -> *mut u8;