radeon/ac: add emit umsb shared code.
authorDave Airlie <airlied@redhat.com>
Thu, 16 Feb 2017 03:53:27 +0000 (03:53 +0000)
committerDave Airlie <airlied@redhat.com>
Thu, 16 Feb 2017 22:57:16 +0000 (22:57 +0000)
Since we shared imsb, makes sense to share umsb.

Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/amd/common/ac_llvm_build.c
src/amd/common/ac_llvm_build.h

index dda2c0b94216766b6befd7ba50e8ba599d54f3cf..ed31a5606e84cf30c1dc6655ce97f54afe3db950 100644 (file)
@@ -788,3 +788,28 @@ ac_emit_imsb(struct ac_llvm_context *ctx,
 
        return LLVMBuildSelect(ctx->builder, cond, all_ones, msb, "");
 }
+
+LLVMValueRef
+ac_emit_umsb(struct ac_llvm_context *ctx,
+            LLVMValueRef arg,
+            LLVMTypeRef dst_type)
+{
+       LLVMValueRef args[2] = {
+               arg,
+               LLVMConstInt(ctx->i32, 1, 0),
+       };
+       LLVMValueRef msb = ac_emit_llvm_intrinsic(ctx, "llvm.ctlz.i32",
+                                                 dst_type, args, ARRAY_SIZE(args),
+                                                 AC_FUNC_ATTR_READNONE);
+
+       /* The HW returns the last bit index from MSB, but TGSI/NIR wants
+        * the index from LSB. Invert it by doing "31 - msb". */
+       msb = LLVMBuildSub(ctx->builder, LLVMConstInt(ctx->i32, 31, false),
+                          msb, "");
+
+       /* check for zero */
+       return LLVMBuildSelect(ctx->builder,
+                              LLVMBuildICmp(ctx->builder, LLVMIntEQ, arg,
+                                            LLVMConstInt(ctx->i32, 0, 0), ""),
+                              LLVMConstInt(ctx->i32, -1, true), msb, "");
+}
index 0ff04e4c703599c7b685aecbd7e2995818865a13..3258e5ef54a227e049c51c27d9755b9aaf78594e 100644 (file)
@@ -186,6 +186,10 @@ LLVMValueRef ac_emit_imsb(struct ac_llvm_context *ctx,
                          LLVMValueRef arg,
                          LLVMTypeRef dst_type);
 
+LLVMValueRef ac_emit_umsb(struct ac_llvm_context *ctx,
+                         LLVMValueRef arg,
+                         LLVMTypeRef dst_type);
+
 #ifdef __cplusplus
 }
 #endif