ac: use llvm.amdgcn.fmed3 intrinsic for nir_op_fmed3
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 25 Mar 2019 12:37:46 +0000 (13:37 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 27 Mar 2019 13:45:52 +0000 (14:45 +0100)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/common/ac_llvm_build.c
src/amd/common/ac_llvm_build.h
src/amd/common/ac_nir_to_llvm.c

index 1123dce2cc87c43e0d9776d53dc8e9a0c49e4085..04d4b377fd12d6fbfb9db63e770a0d9aeb1a6ce4 100644 (file)
@@ -2430,6 +2430,33 @@ void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned simm16)
                           ctx->voidt, args, 1, 0);
 }
 
+LLVMValueRef ac_build_fmed3(struct ac_llvm_context *ctx, LLVMValueRef src0,
+                           LLVMValueRef src1, LLVMValueRef src2,
+                           unsigned bitsize)
+{
+       LLVMTypeRef type;
+       char *intr;
+
+       if (bitsize == 16) {
+               intr = "llvm.amdgcn.fmed3.f16";
+               type = ctx->f16;
+       } else if (bitsize == 32) {
+               intr = "llvm.amdgcn.fmed3.f32";
+               type = ctx->f32;
+       } else {
+               intr = "llvm.amdgcn.fmed3.f64";
+               type = ctx->f64;
+       }
+
+       LLVMValueRef params[] = {
+               src0,
+               src1,
+               src2,
+       };
+       return ac_build_intrinsic(ctx, intr, type, params, 3,
+                                 AC_FUNC_ATTR_READNONE);
+}
+
 LLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0,
                            unsigned bitsize)
 {
index 9151c743bed94864ed5866b805d5bb4e82be37b8..14c1c56522b6e1698f17a2f48bfd6cc48b12fe54 100644 (file)
@@ -549,6 +549,10 @@ void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned simm16);
 LLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0,
                           unsigned bitsize);
 
+LLVMValueRef ac_build_fmed3(struct ac_llvm_context *ctx, LLVMValueRef src0,
+                           LLVMValueRef src1, LLVMValueRef src2,
+                           unsigned bitsize);
+
 LLVMValueRef ac_build_isign(struct ac_llvm_context *ctx, LLVMValueRef src0,
                            unsigned bitsize);
 
index b25cc6a0a846af7f109d9d772ad9da6de0b86ff9..f16be5c0f2aef8cf264adc63f2e7d296139b279e 100644 (file)
@@ -1111,14 +1111,11 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
                result = emit_minmax_int(&ctx->ac, LLVMIntSGT, result, src[2]);
                break;
        case nir_op_fmed3: {
-               LLVMValueRef tmp1 = emit_intrin_2f_param(&ctx->ac, "llvm.minnum",
-                                               ac_to_float_type(&ctx->ac, def_type), src[0], src[1]);
-               LLVMValueRef tmp2 = emit_intrin_2f_param(&ctx->ac, "llvm.maxnum",
-                                               ac_to_float_type(&ctx->ac, def_type), src[0], src[1]);
-               tmp2 = emit_intrin_2f_param(&ctx->ac, "llvm.minnum",
-                                               ac_to_float_type(&ctx->ac, def_type), tmp2, src[2]);
-               result = emit_intrin_2f_param(&ctx->ac, "llvm.maxnum",
-                                               ac_to_float_type(&ctx->ac, def_type), tmp1, tmp2);
+               src[0] = ac_to_float(&ctx->ac, src[0]);
+               src[1] = ac_to_float(&ctx->ac, src[1]);
+               src[2] = ac_to_float(&ctx->ac, src[2]);
+               result = ac_build_fmed3(&ctx->ac, src[0], src[1], src[2],
+                                       instr->dest.dest.ssa.bit_size);
                break;
        }
        case nir_op_imed3: {