From d6266a7666c22b4a64bbc9252e4ad080f5950d01 Mon Sep 17 00:00:00 2001 From: lcnr/Bastian Kauschke Date: Mon, 3 Jun 2019 12:59:17 +0200 Subject: [PATCH] add support for unchecked math --- src/librustc_codegen_llvm/builder.rs | 6 +++++ src/librustc_codegen_llvm/llvm/ffi.rs | 30 ++++++++++++++++++++++ src/librustc_codegen_ssa/traits/builder.rs | 6 +++++ 3 files changed, 42 insertions(+) diff --git a/src/librustc_codegen_llvm/builder.rs b/src/librustc_codegen_llvm/builder.rs index f37fd0cb8338..102e9e38612e 100644 --- a/src/librustc_codegen_llvm/builder.rs +++ b/src/librustc_codegen_llvm/builder.rs @@ -265,6 +265,12 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { neg(x) => LLVMBuildNeg, fneg(x) => LLVMBuildFNeg, not(x) => LLVMBuildNot, + unchecked_sadd(x, y) => LLVMBuildNSWAdd, + unchecked_uadd(x, y) => LLVMBuildNUWAdd, + unchecked_ssub(x, y) => LLVMBuildNSWSub, + unchecked_usub(x, y) => LLVMBuildNUWSub, + unchecked_smul(x, y) => LLVMBuildNSWMul, + unchecked_umul(x, y) => LLVMBuildNUWMul, } fn fadd_fast(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value { diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs index f88923fc9f1c..a71243c7c826 100644 --- a/src/librustc_codegen_llvm/llvm/ffi.rs +++ b/src/librustc_codegen_llvm/llvm/ffi.rs @@ -1002,6 +1002,36 @@ extern "C" { RHS: &'a Value, Name: *const c_char) -> &'a Value; + pub fn LLVMBuildNSWAdd(B: &Builder<'a>, + LHS: &'a Value, + RHS: &'a Value, + Name: *const c_char) + -> &'a Value; + pub fn LLVMBuildNUWAdd(B: &Builder<'a>, + LHS: &'a Value, + RHS: &'a Value, + Name: *const c_char) + -> &'a Value; + pub fn LLVMBuildNSWSub(B: &Builder<'a>, + LHS: &'a Value, + RHS: &'a Value, + Name: *const c_char) + -> &'a Value; + pub fn LLVMBuildNUWSub(B: &Builder<'a>, + LHS: &'a Value, + RHS: &'a Value, + Name: *const c_char) + -> &'a Value; + pub fn LLVMBuildNSWMul(B: &Builder<'a>, + LHS: &'a Value, + RHS: &'a Value, + Name: *const c_char) + -> &'a Value; + pub fn LLVMBuildNUWMul(B: &Builder<'a>, + LHS: &'a Value, + RHS: &'a Value, + Name: *const c_char) + -> &'a Value; pub fn LLVMBuildAnd(B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, diff --git a/src/librustc_codegen_ssa/traits/builder.rs b/src/librustc_codegen_ssa/traits/builder.rs index 0c4c4547a795..a11d1ba9231c 100644 --- a/src/librustc_codegen_ssa/traits/builder.rs +++ b/src/librustc_codegen_ssa/traits/builder.rs @@ -88,6 +88,12 @@ pub trait BuilderMethods<'a, 'tcx: 'a>: fn shl(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value; fn lshr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value; fn ashr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value; + fn unchecked_sadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value; + fn unchecked_uadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value; + fn unchecked_ssub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value; + fn unchecked_usub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value; + fn unchecked_smul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value; + fn unchecked_umul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value; fn and(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value; fn or(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value; fn xor(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;