diff options
| author | bors <bors@rust-lang.org> | 2019-06-03 22:05:55 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-06-03 22:05:55 +0000 |
| commit | e22b7a3eef962b1314d344ba7b2f27c986320b32 (patch) | |
| tree | b7b72745a3356825989af17c2dc079a7d378304f /src/libcore | |
| parent | 6ffb8f53ee1cb0903f9df7d2fdb37ad06d748566 (diff) | |
| parent | d7e0834c5f173c9ee58ccc1858e3ecff021c9f33 (diff) | |
Auto merge of #59148 - lcnr:unchecked_maths, r=eddyb
add support for unchecked math add compiler support for ```rust /// Returns the result of an unchecked addition, resulting in /// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`. pub fn unchecked_add<T>(x: T, y: T) -> T; /// Returns the result of an unchecked substraction, resulting in /// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`. pub fn unchecked_sub<T>(x: T, y: T) -> T; /// Returns the result of an unchecked multiplication, resulting in /// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`. pub fn unchecked_mul<T>(x: T, y: T) -> T; ``` cc https://github.com/rust-lang/rfcs/issues/2508
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/intrinsics.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 782a7ba4559..31a4e380a3d 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -1240,6 +1240,21 @@ extern "rust-intrinsic" { /// y < 0 or y >= N, where N is the width of T in bits. pub fn unchecked_shr<T>(x: T, y: T) -> T; + /// Returns the result of an unchecked addition, resulting in + /// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`. + #[cfg(not(stage0))] + pub fn unchecked_add<T>(x: T, y: T) -> T; + + /// Returns the result of an unchecked substraction, resulting in + /// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`. + #[cfg(not(stage0))] + pub fn unchecked_sub<T>(x: T, y: T) -> T; + + /// Returns the result of an unchecked multiplication, resulting in + /// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`. + #[cfg(not(stage0))] + pub fn unchecked_mul<T>(x: T, y: T) -> T; + /// Performs rotate left. /// The stabilized versions of this intrinsic are available on the integer /// primitives via the `rotate_left` method. For example, |
