about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorNicholas Mazzuca <npmazzuca@gmail.com>2015-04-28 18:20:30 -0700
committerNicholas Mazzuca <npmazzuca@gmail.com>2015-04-28 18:20:30 -0700
commit83814325b45f9f53480f633d7d36ed005f9fa823 (patch)
treeaf86c9a013758c74a2d58364124ffd8d3a4b904a /src/libcore
parent8871c17b76a1e0ab36ce2bb51008b53f596e5b3c (diff)
downloadrust-83814325b45f9f53480f633d7d36ed005f9fa823.tar.gz
rust-83814325b45f9f53480f633d7d36ed005f9fa823.zip
Add intrinsics for unchecked division and modulo
The "unchecked_" div and rem functions will give UB in case of rhs == 0, or,
in the signed versions, lhs == INT::min and rhs == -1
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/intrinsics.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs
index 8ed89adec5b..c6bb1fb1cb1 100644
--- a/src/libcore/intrinsics.rs
+++ b/src/libcore/intrinsics.rs
@@ -576,3 +576,20 @@ extern "rust-intrinsic" {
     #[cfg(not(stage0))]
     pub fn discriminant_value<T>(v: &T) -> u64;
 }
+
+#[cfg(not(stage0))]
+extern "rust-intrinsic" {
+    /// Performs an unchecked signed division, which results in undefined behavior,
+    /// in cases where y == 0, or x == int::MIN and y == -1
+    pub fn unchecked_sdiv<T>(x: T, y: T) -> T;
+    /// Performs an unchecked unsigned division, which results in undefined behavior,
+    /// in cases where y == 0
+    pub fn unchecked_udiv<T>(x: T, y: T) -> T;
+
+    /// Returns the remainder of an unchecked signed division, which results in
+    /// undefined behavior, in cases where y == 0, or x == int::MIN and y == -1
+    pub fn unchecked_urem<T>(x: T, y: T) -> T;
+    /// Returns the remainder of an unchecked signed division, which results in
+    /// undefined behavior, in cases where y == 0
+    pub fn unchecked_srem<T>(x: T, y: T) -> T;
+}