From 9790fdf2cebb7cab657ee61e30f9d0b8860f0ddc Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 6 Nov 2020 13:14:07 +1000 Subject: [PATCH] vtn/opencl: add ctz support ctz is a CL2.0 opcode but 3.0 requires it as well so just add support for it. Tested against CTS integer_ops integer_ctz test. (long line broken up) Reviewed-by: Francisco Jerez Part-of: --- src/compiler/nir/nir_builtin_builder.h | 10 ++++++++++ src/compiler/spirv/vtn_opencl.c | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/compiler/nir/nir_builtin_builder.h b/src/compiler/nir/nir_builtin_builder.h index 0ddfcd1656f..a9fc9a5f991 100644 --- a/src/compiler/nir/nir_builtin_builder.h +++ b/src/compiler/nir/nir_builtin_builder.h @@ -261,6 +261,16 @@ nir_clz_u(nir_builder *b, nir_ssa_def *a) return nir_u2u(b, val, a->bit_size); } +static inline nir_ssa_def * +nir_ctz_u(nir_builder *b, nir_ssa_def *a) +{ + nir_ssa_def *cond = nir_ieq(b, a, nir_imm_intN_t(b, 0, a->bit_size)); + + return nir_bcsel(b, cond, + nir_imm_intN_t(b, a->bit_size, a->bit_size), + nir_u2u(b, nir_find_lsb(b, a), a->bit_size)); +} + #ifdef __cplusplus } #endif diff --git a/src/compiler/spirv/vtn_opencl.c b/src/compiler/spirv/vtn_opencl.c index 301cb112550..127fc9e9a85 100644 --- a/src/compiler/spirv/vtn_opencl.c +++ b/src/compiler/spirv/vtn_opencl.c @@ -533,6 +533,8 @@ handle_special(struct vtn_builder *b, uint32_t opcode, return nir_normalize(nb, srcs[0]); case OpenCLstd_Clz: return nir_clz_u(nb, srcs[0]); + case OpenCLstd_Ctz: + return nir_ctz_u(nb, srcs[0]); case OpenCLstd_Select: return nir_select(nb, srcs[0], srcs[1], srcs[2]); case OpenCLstd_S_Upsample: @@ -876,6 +878,7 @@ vtn_handle_opencl_instruction(struct vtn_builder *b, SpvOp ext_opcode, case OpenCLstd_S_Upsample: case OpenCLstd_U_Upsample: case OpenCLstd_Clz: + case OpenCLstd_Ctz: case OpenCLstd_Native_exp: case OpenCLstd_Native_exp10: case OpenCLstd_Native_log: