Mesa (master): vtn/opencl: add ctz support

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Nov 6 07:48:04 UTC 2020


Module: Mesa
Branch: master
Commit: 9790fdf2cebb7cab657ee61e30f9d0b8860f0ddc
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9790fdf2cebb7cab657ee61e30f9d0b8860f0ddc

Author: Dave Airlie <airlied at redhat.com>
Date:   Fri Nov  6 13:14:07 2020 +1000

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 <currojerez at riseup.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7468>

---

 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:



More information about the mesa-commit mailing list