[Mesa-dev] [PATCH 28/38] ac/nir: make ac_build_bitfield_reverse work on all bit sizes

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


Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
---
 src/amd/common/ac_llvm_build.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
index 3990a1f56d..68ea6078d3 100644
--- a/src/amd/common/ac_llvm_build.c
+++ b/src/amd/common/ac_llvm_build.c
@@ -2377,28 +2377,14 @@ LLVMValueRef ac_build_bit_count(struct ac_llvm_context *ctx, LLVMValueRef src0)
 LLVMValueRef ac_build_bitfield_reverse(struct ac_llvm_context *ctx,
 				       LLVMValueRef src0)
 {
-	LLVMValueRef result;
-	unsigned bitsize;
-
-	bitsize = ac_get_elem_bits(ctx, LLVMTypeOf(src0));
+	unsigned bitsize = ac_get_elem_bits(ctx, LLVMTypeOf(src0));
 
-	switch (bitsize) {
-	case 32:
-		result = ac_build_intrinsic(ctx, "llvm.bitreverse.i32", ctx->i32,
-					    (LLVMValueRef []) { src0 }, 1,
-					    AC_FUNC_ATTR_READNONE);
-		break;
-	case 16:
-		result = ac_build_intrinsic(ctx, "llvm.bitreverse.i16", ctx->i16,
-					    (LLVMValueRef []) { src0 }, 1,
-					    AC_FUNC_ATTR_READNONE);
-		break;
-	default:
-		unreachable(!"invalid bitsize");
-		break;
-	}
+	char name[64];
+	snprintf(name, sizeof(name), "llvm.bitreverse.i%d", bitsize);
 
-	return result;
+	return ac_build_intrinsic(ctx, name, LLVMTypeOf(src0),
+				  (LLVMValueRef []) { src0 }, 1,
+				  AC_FUNC_ATTR_READNONE);
 }
 
 #define AC_EXP_TARGET		0
-- 
2.19.2



More information about the mesa-dev mailing list