ac: add ac_build_frex_exp() helper ans 16-bit/32-bit support
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 22 Mar 2019 10:59:32 +0000 (11:59 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Thu, 28 Mar 2019 12:02:48 +0000 (13:02 +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 4fd1d14b78f6a154c02469762d8b171df635ae3d..5572b244720c7d4f6c05ed681848e49390d289ab 100644 (file)
@@ -3927,6 +3927,30 @@ ac_build_shuffle(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef ind
                  AC_FUNC_ATTR_CONVERGENT);
 }
 
+LLVMValueRef
+ac_build_frexp_exp(struct ac_llvm_context *ctx, LLVMValueRef src0,
+                  unsigned bitsize)
+{
+       LLVMTypeRef type;
+       char *intr;
+
+       if (bitsize == 16) {
+               intr = "llvm.amdgcn.frexp.exp.i16.f16";
+               type = ctx->i16;
+       } else if (bitsize == 32) {
+               intr = "llvm.amdgcn.frexp.exp.i32.f32";
+               type = ctx->i32;
+       } else {
+               intr = "llvm.amdgcn.frexp.exp.i32.f64";
+               type = ctx->i64;
+       }
+
+       LLVMValueRef params[] = {
+               src0,
+       };
+       return ac_build_intrinsic(ctx, intr, type, params, 1,
+                                 AC_FUNC_ATTR_READNONE);
+}
 LLVMValueRef
 ac_build_frexp_mant(struct ac_llvm_context *ctx, LLVMValueRef src0,
                    unsigned bitsize)
index db20b39d4431a0425c7aecb3ee7f722cd156cd5a..c3277fd2d13f400a7b63db7b042f5657477b5599 100644 (file)
@@ -677,6 +677,10 @@ ac_build_quad_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src,
 LLVMValueRef
 ac_build_shuffle(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef index);
 
+LLVMValueRef
+ac_build_frexp_exp(struct ac_llvm_context *ctx, LLVMValueRef src0,
+                  unsigned bitsize);
+
 LLVMValueRef
 ac_build_frexp_mant(struct ac_llvm_context *ctx, LLVMValueRef src0,
                    unsigned bitsize);
index 936d1eec34f98590ecf22f696d123bab4fb79dce..2321fed69f370165aa2aaa1a69ca0d39ad36932a 100644 (file)
@@ -803,9 +803,11 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
                break;
        case nir_op_frexp_exp:
                src[0] = ac_to_float(&ctx->ac, src[0]);
-               result = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.frexp.exp.i32.f64",
-                                           ctx->ac.i32, src, 1, AC_FUNC_ATTR_READNONE);
-
+               result = ac_build_frexp_exp(&ctx->ac, src[0],
+                                           ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])));
+               if (ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])) == 16)
+                       result = LLVMBuildSExt(ctx->ac.builder, result,
+                                              ctx->ac.i32, "");
                break;
        case nir_op_frexp_sig:
                src[0] = ac_to_float(&ctx->ac, src[0]);