Skip to content

Commit f6a35aa

Browse files
committed
implement minmax intrinsics
1 parent c19264f commit f6a35aa

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
@@ -1242,6 +1242,9 @@ extern "C" {
12421242
IsNaN: bool)
12431243
-> ValueRef;
12441244

1245+
pub fn LLVMRustBuildMinNum(B: BuilderRef, LHS: ValueRef, LHS: ValueRef) -> ValueRef;
1246+
pub fn LLVMRustBuildMaxNum(B: BuilderRef, LHS: ValueRef, LHS: ValueRef) -> ValueRef;
1247+
12451248
pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char) -> ValueRef;
12461249
pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char) -> ValueRef;
12471250
pub fn LLVMBuildPtrDiff(B: BuilderRef,

src/librustc_trans/builder.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
910910
}
911911
}
912912

913+
pub fn minnum(&self, lhs: ValueRef, rhs: ValueRef) -> ValueRef {
914+
self.count_insn("minnum");
915+
unsafe {
916+
llvm::LLVMRustBuildMinNum(self.llbuilder, lhs, rhs)
917+
}
918+
}
919+
pub fn maxnum(&self, lhs: ValueRef, rhs: ValueRef) -> ValueRef {
920+
self.count_insn("maxnum");
921+
unsafe {
922+
llvm::LLVMRustBuildMaxNum(self.llbuilder, lhs, rhs)
923+
}
924+
}
925+
913926
pub fn select(&self, cond: ValueRef, then_val: ValueRef, else_val: ValueRef) -> ValueRef {
914927
self.count_insn("select");
915928
unsafe {

src/librustc_trans/intrinsic.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,8 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
14051405
simd_and: TyUint, TyInt => and;
14061406
simd_or: TyUint, TyInt => or;
14071407
simd_xor: TyUint, TyInt => xor;
1408+
simd_fmax: TyFloat => maxnum;
1409+
simd_fmin: TyFloat => minnum;
14081410
}
14091411
span_bug!(span, "unknown SIMD intrinsic");
14101412
}

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
@@ -1492,3 +1492,12 @@ LLVMRustBuildVectorReduceFMax(LLVMBuilderRef, LLVMValueRef, bool) {
14921492
return nullptr;
14931493
}
14941494
#endif
1495+
1496+
extern "C" LLVMValueRef
1497+
LLVMRustBuildMinNum(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS) {
1498+
return wrap(unwrap(B)->CreateMinNum(unwrap(LHS),unwrap(RHS)));
1499+
}
1500+
extern "C" LLVMValueRef
1501+
LLVMRustBuildMaxNum(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS) {
1502+
return wrap(unwrap(B)->CreateMaxNum(unwrap(LHS),unwrap(RHS)));
1503+
}

0 commit comments

Comments
 (0)