[Mesa-dev] [PATCH 17/38] ac/nir: support half floats in emit_b2f

Rhys Perry pendingchaos02 at gmail.com
Fri Dec 7 17:22:10 UTC 2018


This seems to generate fine code, even though the IR is a bit ugly.

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
---
 src/amd/common/ac_nir_to_llvm.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index bb7c421606..459d9c119c 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -316,14 +316,20 @@ static LLVMValueRef emit_b2f(struct ac_llvm_context *ctx,
 			     unsigned bitsize)
 {
 	LLVMValueRef result = LLVMBuildAnd(ctx->builder, src0,
-					   LLVMBuildBitCast(ctx->builder, LLVMConstReal(ctx->f32, 1.0), ctx->i32, ""),
+					   LLVMBuildBitCast(ctx->builder, ctx->f32_1, ctx->i32, ""),
 					   "");
 	result = LLVMBuildBitCast(ctx->builder, result, ctx->f32, "");
 
-	if (bitsize == 32)
+	switch (bitsize) {
+	case 16:
+		return LLVMBuildFPTrunc(ctx->builder, result, ctx->f16, "");
+	case 32:
 		return result;
-
-	return LLVMBuildFPExt(ctx->builder, result, ctx->f64, "");
+	case 64:
+		return LLVMBuildFPExt(ctx->builder, result, ctx->f64, "");
+	default:
+		unreachable("Unsupported bit size.");
+	}
 }
 
 static LLVMValueRef emit_f2b(struct ac_llvm_context *ctx,
-- 
2.19.2



More information about the mesa-dev mailing list