Skip to content

Commit 7d5343a

Browse files
committed
implement minmax intrinsics
1 parent 184156e commit 7d5343a

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

src/librustc_llvm/ffi.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,9 @@ extern "C" {
12471247
IsNaN: bool)
12481248
-> ValueRef;
12491249

1250+
pub fn LLVMRustBuildMinNum(B: BuilderRef, LHS: ValueRef, LHS: ValueRef) -> ValueRef;
1251+
pub fn LLVMRustBuildMaxNum(B: BuilderRef, LHS: ValueRef, LHS: ValueRef) -> ValueRef;
1252+
12501253
pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char) -> ValueRef;
12511254
pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char) -> ValueRef;
12521255
pub fn LLVMBuildPtrDiff(B: BuilderRef,

src/librustc_trans/builder.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
917917
}
918918
}
919919

920+
pub fn minnum(&self, lhs: ValueRef, rhs: ValueRef) -> ValueRef {
921+
self.count_insn("minnum");
922+
unsafe {
923+
llvm::LLVMRustBuildMinNum(self.llbuilder, lhs, rhs)
924+
}
925+
}
926+
pub fn maxnum(&self, lhs: ValueRef, rhs: ValueRef) -> ValueRef {
927+
self.count_insn("maxnum");
928+
unsafe {
929+
llvm::LLVMRustBuildMaxNum(self.llbuilder, lhs, rhs)
930+
}
931+
}
932+
920933
pub fn select(&self, cond: ValueRef, then_val: ValueRef, else_val: ValueRef) -> ValueRef {
921934
self.count_insn("select");
922935
unsafe {

src/librustc_trans/intrinsic.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,8 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
14321432
simd_and: TyUint, TyInt => and;
14331433
simd_or: TyUint, TyInt => or;
14341434
simd_xor: TyUint, TyInt => xor;
1435+
simd_fmax: TyFloat => maxnum;
1436+
simd_fmin: TyFloat => minnum;
14351437
}
14361438
span_bug!(span, "unknown SIMD intrinsic");
14371439
}

src/librustc_typeck/check/intrinsic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ pub fn check_platform_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
355355
}
356356
"simd_add" | "simd_sub" | "simd_mul" | "simd_rem" |
357357
"simd_div" | "simd_shl" | "simd_shr" |
358-
"simd_and" | "simd_or" | "simd_xor" => {
358+
"simd_and" | "simd_or" | "simd_xor" |
359+
"simd_fmin" | "simd_fmax" => {
359360
(1, vec![param(0), param(0)], param(0))
360361
}
361362
"simd_insert" => (2, vec![param(0), tcx.types.u32, param(1)], param(0)),

src/rustllvm/RustWrapper.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,3 +1500,12 @@ LLVMBuildExactUDiv(LLVMBuilderRef B, LLVMValueRef LHS,
15001500
return wrap(unwrap(B)->CreateExactUDiv(unwrap(LHS), unwrap(RHS), Name));
15011501
}
15021502
#endif
1503+
1504+
extern "C" LLVMValueRef
1505+
LLVMRustBuildMinNum(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS) {
1506+
return wrap(unwrap(B)->CreateMinNum(unwrap(LHS),unwrap(RHS)));
1507+
}
1508+
extern "C" LLVMValueRef
1509+
LLVMRustBuildMaxNum(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS) {
1510+
return wrap(unwrap(B)->CreateMaxNum(unwrap(LHS),unwrap(RHS)));
1511+
}

0 commit comments

Comments
 (0)