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

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Nov 21 19:18:07 UTC 2019


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

Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Nov 18 17:04:35 2019 +1000

vtn/opencl: add clz support

This is needed for OpenCL

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

---

 src/compiler/nir/nir_builtin_builder.h | 8 ++++++++
 src/compiler/spirv/vtn_opencl.c        | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/src/compiler/nir/nir_builtin_builder.h b/src/compiler/nir/nir_builtin_builder.h
index e2fbf02b3ea..0b4d1d0135e 100644
--- a/src/compiler/nir/nir_builtin_builder.h
+++ b/src/compiler/nir/nir_builtin_builder.h
@@ -253,6 +253,14 @@ nir_select(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y, nir_ssa_def *s)
    return nir_bcsel(b, nir_ieq(b, s, nir_imm_intN_t(b, 0, s->bit_size)), x, y);
 }
 
+static inline nir_ssa_def *
+nir_clz_u(nir_builder *b, nir_ssa_def *a)
+{
+   nir_ssa_def *val;
+   val = nir_isub(b, nir_imm_intN_t(b, a->bit_size - 1, 32), nir_ufind_msb(b, a));
+   return nir_u2u(b, val, a->bit_size);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/compiler/spirv/vtn_opencl.c b/src/compiler/spirv/vtn_opencl.c
index 165c0de4a7a..c41023256d4 100644
--- a/src/compiler/spirv/vtn_opencl.c
+++ b/src/compiler/spirv/vtn_opencl.c
@@ -185,6 +185,8 @@ handle_special(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode,
       return nir_rotate(nb, srcs[0], srcs[1]);
    case OpenCLstd_Smoothstep:
       return nir_smoothstep(nb, srcs[0], srcs[1], srcs[2]);
+   case OpenCLstd_Clz:
+      return nir_clz_u(nb, srcs[0]);
    case OpenCLstd_Select:
       return nir_select(nb, srcs[0], srcs[1], srcs[2]);
    case OpenCLstd_Step:




More information about the mesa-commit mailing list