[Mesa-dev] [PATCH v2 19/41] ac/nir: support half floats in emit_b2f
Rhys Perry
pendingchaos02 at gmail.com
Sat Feb 16 00:22:08 UTC 2019
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 0e5946dfdb3..e459001c1cf 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.20.1
More information about the mesa-dev
mailing list