Skip to content

Commit d6266a7

Browse files
committed
add support for unchecked math
1 parent d461555 commit d6266a7

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/librustc_codegen_llvm/builder.rs

+6
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
265265
neg(x) => LLVMBuildNeg,
266266
fneg(x) => LLVMBuildFNeg,
267267
not(x) => LLVMBuildNot,
268+
unchecked_sadd(x, y) => LLVMBuildNSWAdd,
269+
unchecked_uadd(x, y) => LLVMBuildNUWAdd,
270+
unchecked_ssub(x, y) => LLVMBuildNSWSub,
271+
unchecked_usub(x, y) => LLVMBuildNUWSub,
272+
unchecked_smul(x, y) => LLVMBuildNSWMul,
273+
unchecked_umul(x, y) => LLVMBuildNUWMul,
268274
}
269275

270276
fn fadd_fast(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {

src/librustc_codegen_llvm/llvm/ffi.rs

+30
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,36 @@ extern "C" {
10021002
RHS: &'a Value,
10031003
Name: *const c_char)
10041004
-> &'a Value;
1005+
pub fn LLVMBuildNSWAdd(B: &Builder<'a>,
1006+
LHS: &'a Value,
1007+
RHS: &'a Value,
1008+
Name: *const c_char)
1009+
-> &'a Value;
1010+
pub fn LLVMBuildNUWAdd(B: &Builder<'a>,
1011+
LHS: &'a Value,
1012+
RHS: &'a Value,
1013+
Name: *const c_char)
1014+
-> &'a Value;
1015+
pub fn LLVMBuildNSWSub(B: &Builder<'a>,
1016+
LHS: &'a Value,
1017+
RHS: &'a Value,
1018+
Name: *const c_char)
1019+
-> &'a Value;
1020+
pub fn LLVMBuildNUWSub(B: &Builder<'a>,
1021+
LHS: &'a Value,
1022+
RHS: &'a Value,
1023+
Name: *const c_char)
1024+
-> &'a Value;
1025+
pub fn LLVMBuildNSWMul(B: &Builder<'a>,
1026+
LHS: &'a Value,
1027+
RHS: &'a Value,
1028+
Name: *const c_char)
1029+
-> &'a Value;
1030+
pub fn LLVMBuildNUWMul(B: &Builder<'a>,
1031+
LHS: &'a Value,
1032+
RHS: &'a Value,
1033+
Name: *const c_char)
1034+
-> &'a Value;
10051035
pub fn LLVMBuildAnd(B: &Builder<'a>,
10061036
LHS: &'a Value,
10071037
RHS: &'a Value,

src/librustc_codegen_ssa/traits/builder.rs

+6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
8888
fn shl(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
8989
fn lshr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
9090
fn ashr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
91+
fn unchecked_sadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
92+
fn unchecked_uadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
93+
fn unchecked_ssub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
94+
fn unchecked_usub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
95+
fn unchecked_smul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
96+
fn unchecked_umul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
9197
fn and(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
9298
fn or(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
9399
fn xor(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;

0 commit comments

Comments
 (0)