[Mesa-dev] [PATCH v2 3/3] ac: add 64bit support to ac_find_lsb()
Timothy Arceri
tarceri at itsqueeze.com
Thu Feb 8 00:25:21 UTC 2018
v2: use LLVMBuildTrunc()
---
src/amd/common/ac_llvm_build.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
index 6352ca44ea..d7e1f2bbdf 100644
--- a/src/amd/common/ac_llvm_build.c
+++ b/src/amd/common/ac_llvm_build.c
@@ -1984,6 +1984,20 @@ LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx,
LLVMTypeRef dst_type,
LLVMValueRef src0)
{
+ unsigned src0_bitsize = ac_get_elem_bits(ctx, LLVMTypeOf(src0));
+ const char *intrin_name;
+ LLVMTypeRef type;
+ LLVMValueRef zero;
+ if (src0_bitsize == 64) {
+ intrin_name = "llvm.cttz.i64";
+ type = ctx->i64;
+ zero = ctx->i64_0;
+ } else {
+ intrin_name = "llvm.cttz.i32";
+ type = ctx->i32;
+ zero = ctx->i32_0;
+ }
+
LLVMValueRef params[2] = {
src0,
@@ -1999,15 +2013,19 @@ LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx,
LLVMConstInt(ctx->i1, 1, false),
};
- LLVMValueRef lsb = ac_build_intrinsic(ctx, "llvm.cttz.i32", ctx->i32,
+ LLVMValueRef lsb = ac_build_intrinsic(ctx, intrin_name, type,
params, 2,
AC_FUNC_ATTR_READNONE);
+ if (src0_bitsize == 64) {
+ lsb = LLVMBuildTrunc(ctx->builder, lsb, ctx->i32, "");
+ }
+
/* TODO: We need an intrinsic to skip this conditional. */
/* Check for zero: */
return LLVMBuildSelect(ctx->builder, LLVMBuildICmp(ctx->builder,
LLVMIntEQ, src0,
- ctx->i32_0, ""),
+ zero, ""),
LLVMConstInt(ctx->i32, -1, 0), lsb, "");
}
--
2.14.3
More information about the mesa-dev
mailing list