[Mesa-dev] [PATCH 1/3] radeon/ac: add emit umsb shared code.

Marek Olšák maraeo at gmail.com
Thu Feb 16 10:15:06 UTC 2017


Reviewed-by: Marek Olšák <marek.olsak at amd.com>

Marek

On Thu, Feb 16, 2017 at 4:55 AM, Dave Airlie <airlied at gmail.com> wrote:
> From: Dave Airlie <airlied at redhat.com>
>
> Since we shared imsb, makes sense to share umsb.
>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  src/amd/common/ac_llvm_build.c | 25 +++++++++++++++++++++++++
>  src/amd/common/ac_llvm_build.h |  4 ++++
>  2 files changed, 29 insertions(+)
>
> diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
> index dda2c0b..ed31a56 100644
> --- a/src/amd/common/ac_llvm_build.c
> +++ b/src/amd/common/ac_llvm_build.c
> @@ -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, "");
> +}
> diff --git a/src/amd/common/ac_llvm_build.h b/src/amd/common/ac_llvm_build.h
> index 0ff04e4..3258e5e 100644
> --- a/src/amd/common/ac_llvm_build.h
> +++ b/src/amd/common/ac_llvm_build.h
> @@ -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
> --
> 2.7.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list