nir/vtn: SPIR-V bit count opcodes (core and extension) dest size mismatches nir
[mesa.git] / src / compiler / spirv / vtn_opencl.c
index f60878819f51e8575d891150da69f4fec88a8840..b5e92dc3b85e1d53ccb321747bf8e74ec2201c73 100644 (file)
  */
 
 #include "math.h"
-
 #include "nir/nir_builtin_builder.h"
 
 #include "vtn_private.h"
 #include "OpenCL.std.h"
 
-typedef nir_ssa_def *(*nir_handler)(struct vtn_builder *b, enum OpenCLstd opcode,
+typedef nir_ssa_def *(*nir_handler)(struct vtn_builder *b,
+                                    enum OpenCLstd_Entrypoints opcode,
                                     unsigned num_srcs, nir_ssa_def **srcs,
                                     const struct glsl_type *dest_type);
 
 static void
-handle_instr(struct vtn_builder *b, enum OpenCLstd opcode, const uint32_t *w,
-             unsigned count, nir_handler handler)
+handle_instr(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode,
+             const uint32_t *w, unsigned count, nir_handler handler)
 {
-   const struct glsl_type *dest_type =
-      vtn_value(b, w[1], vtn_value_type_type)->type->type;
+   const struct glsl_type *dest_type = vtn_get_type(b, w[1])->type;
 
    unsigned num_srcs = count - 5;
    nir_ssa_def *srcs[3] = { NULL };
    vtn_assert(num_srcs <= ARRAY_SIZE(srcs));
    for (unsigned i = 0; i < num_srcs; i++) {
-      srcs[i] = vtn_ssa_value(b, w[i + 5])->def;
+      srcs[i] = vtn_get_nir_ssa(b, w[i + 5]);
    }
 
    nir_ssa_def *result = handler(b, opcode, num_srcs, srcs, dest_type);
    if (result) {
-      struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
-      val->ssa = vtn_create_ssa_value(b, dest_type);
-      val->ssa->def = result;
+      vtn_push_nir_ssa(b, w[2], result);
    } else {
       vtn_assert(dest_type == glsl_void_type());
    }
 }
 
 static nir_op
-nir_alu_op_for_opencl_opcode(struct vtn_builder *b, enum OpenCLstd opcode)
+nir_alu_op_for_opencl_opcode(struct vtn_builder *b,
+                             enum OpenCLstd_Entrypoints opcode)
 {
    switch (opcode) {
-   case Fabs: return nir_op_fabs;
-   case SAbs: return nir_op_iabs;
-   case SAdd_sat: return nir_op_iadd_sat;
-   case UAdd_sat: return nir_op_uadd_sat;
-   case Ceil: return nir_op_fceil;
-   case Cos: return nir_op_fcos;
-   case Exp2: return nir_op_fexp2;
-   case Log2: return nir_op_flog2;
-   case Floor: return nir_op_ffloor;
-   case SHadd: return nir_op_ihadd;
-   case UHadd: return nir_op_uhadd;
-   case Fma: return nir_op_ffma;
-   case Fmax: return nir_op_fmax;
-   case SMax: return nir_op_imax;
-   case UMax: return nir_op_umax;
-   case Fmin: return nir_op_fmin;
-   case SMin: return nir_op_imin;
-   case UMin: return nir_op_umin;
-   case Fmod: return nir_op_fmod;
-   case Mix: return nir_op_flrp;
-   case SMul_hi: return nir_op_imul_high;
-   case UMul_hi: return nir_op_umul_high;
-   case Popcount: return nir_op_bit_count;
-   case Pow: return nir_op_fpow;
-   case Remainder: return nir_op_frem;
-   case SRhadd: return nir_op_irhadd;
-   case URhadd: return nir_op_urhadd;
-   case Rsqrt: return nir_op_frsq;
-   case Sign: return nir_op_fsign;
-   case Sin: return nir_op_fsin;
-   case Sqrt: return nir_op_fsqrt;
-   case SSub_sat: return nir_op_isub_sat;
-   case USub_sat: return nir_op_usub_sat;
-   case Trunc: return nir_op_ftrunc;
+   case OpenCLstd_Fabs: return nir_op_fabs;
+   case OpenCLstd_SAbs: return nir_op_iabs;
+   case OpenCLstd_SAdd_sat: return nir_op_iadd_sat;
+   case OpenCLstd_UAdd_sat: return nir_op_uadd_sat;
+   case OpenCLstd_Ceil: return nir_op_fceil;
+   case OpenCLstd_Cos: return nir_op_fcos;
+   case OpenCLstd_Exp2: return nir_op_fexp2;
+   case OpenCLstd_Log2: return nir_op_flog2;
+   case OpenCLstd_Floor: return nir_op_ffloor;
+   case OpenCLstd_SHadd: return nir_op_ihadd;
+   case OpenCLstd_UHadd: return nir_op_uhadd;
+   case OpenCLstd_Fma: return nir_op_ffma;
+   case OpenCLstd_Fmax: return nir_op_fmax;
+   case OpenCLstd_SMax: return nir_op_imax;
+   case OpenCLstd_UMax: return nir_op_umax;
+   case OpenCLstd_Fmin: return nir_op_fmin;
+   case OpenCLstd_SMin: return nir_op_imin;
+   case OpenCLstd_UMin: return nir_op_umin;
+   case OpenCLstd_Fmod: return nir_op_fmod;
+   case OpenCLstd_Mix: return nir_op_flrp;
+   case OpenCLstd_Native_cos: return nir_op_fcos;
+   case OpenCLstd_Native_divide: return nir_op_fdiv;
+   case OpenCLstd_Native_exp2: return nir_op_fexp2;
+   case OpenCLstd_Native_log2: return nir_op_flog2;
+   case OpenCLstd_Native_powr: return nir_op_fpow;
+   case OpenCLstd_Native_recip: return nir_op_frcp;
+   case OpenCLstd_Native_rsqrt: return nir_op_frsq;
+   case OpenCLstd_Native_sin: return nir_op_fsin;
+   case OpenCLstd_Native_sqrt: return nir_op_fsqrt;
+   case OpenCLstd_SMul_hi: return nir_op_imul_high;
+   case OpenCLstd_UMul_hi: return nir_op_umul_high;
+   case OpenCLstd_Popcount: return nir_op_bit_count;
+   case OpenCLstd_Pow: return nir_op_fpow;
+   case OpenCLstd_Remainder: return nir_op_frem;
+   case OpenCLstd_SRhadd: return nir_op_irhadd;
+   case OpenCLstd_URhadd: return nir_op_urhadd;
+   case OpenCLstd_Rsqrt: return nir_op_frsq;
+   case OpenCLstd_Sign: return nir_op_fsign;
+   case OpenCLstd_Sin: return nir_op_fsin;
+   case OpenCLstd_Sqrt: return nir_op_fsqrt;
+   case OpenCLstd_SSub_sat: return nir_op_isub_sat;
+   case OpenCLstd_USub_sat: return nir_op_usub_sat;
+   case OpenCLstd_Trunc: return nir_op_ftrunc;
+   case OpenCLstd_Rint: return nir_op_fround_even;
    /* uhm... */
-   case UAbs: return nir_op_imov;
+   case OpenCLstd_UAbs: return nir_op_mov;
    default:
       vtn_fail("No NIR equivalent");
    }
 }
 
 static nir_ssa_def *
-handle_alu(struct vtn_builder *b, enum OpenCLstd opcode, unsigned num_srcs,
-           nir_ssa_def **srcs, const struct glsl_type *dest_type)
+handle_alu(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode,
+           unsigned num_srcs, nir_ssa_def **srcs,
+           const struct glsl_type *dest_type)
 {
-   return nir_build_alu(&b->nb, nir_alu_op_for_opencl_opcode(b, opcode),
-                        srcs[0], srcs[1], srcs[2], NULL);
+   nir_ssa_def *ret = nir_build_alu(&b->nb, nir_alu_op_for_opencl_opcode(b, opcode),
+                                    srcs[0], srcs[1], srcs[2], NULL);
+   if (opcode == OpenCLstd_Popcount)
+      ret = nir_u2u(&b->nb, ret, glsl_get_bit_size(dest_type));
+   return ret;
 }
 
 static nir_ssa_def *
-handle_special(struct vtn_builder *b, enum OpenCLstd opcode, unsigned num_srcs,
-               nir_ssa_def **srcs, const struct glsl_type *dest_type)
+handle_special(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode,
+               unsigned num_srcs, nir_ssa_def **srcs,
+               const struct glsl_type *dest_type)
 {
    nir_builder *nb = &b->nb;
 
    switch (opcode) {
-   case SAbs_diff:
+   case OpenCLstd_SAbs_diff:
       return nir_iabs_diff(nb, srcs[0], srcs[1]);
-   case UAbs_diff:
+   case OpenCLstd_UAbs_diff:
       return nir_uabs_diff(nb, srcs[0], srcs[1]);
-   case Bitselect:
+   case OpenCLstd_Bitselect:
       return nir_bitselect(nb, srcs[0], srcs[1], srcs[2]);
-   case FClamp:
+   case OpenCLstd_SMad_hi:
+      return nir_imad_hi(nb, srcs[0], srcs[1], srcs[2]);
+   case OpenCLstd_UMad_hi:
+      return nir_umad_hi(nb, srcs[0], srcs[1], srcs[2]);
+   case OpenCLstd_SMul24:
+      return nir_imul24(nb, srcs[0], srcs[1]);
+   case OpenCLstd_UMul24:
+      return nir_umul24(nb, srcs[0], srcs[1]);
+   case OpenCLstd_SMad24:
+      return nir_imad24(nb, srcs[0], srcs[1], srcs[2]);
+   case OpenCLstd_UMad24:
+      return nir_umad24(nb, srcs[0], srcs[1], srcs[2]);
+   case OpenCLstd_FClamp:
       return nir_fclamp(nb, srcs[0], srcs[1], srcs[2]);
-   case SClamp:
+   case OpenCLstd_SClamp:
       return nir_iclamp(nb, srcs[0], srcs[1], srcs[2]);
-   case UClamp:
+   case OpenCLstd_UClamp:
       return nir_uclamp(nb, srcs[0], srcs[1], srcs[2]);
-   case Copysign:
+   case OpenCLstd_Copysign:
       return nir_copysign(nb, srcs[0], srcs[1]);
-   case Cross:
+   case OpenCLstd_Cross:
       if (glsl_get_components(dest_type) == 4)
          return nir_cross4(nb, srcs[0], srcs[1]);
       return nir_cross3(nb, srcs[0], srcs[1]);
-   case Degrees:
+   case OpenCLstd_Degrees:
       return nir_degrees(nb, srcs[0]);
-   case Fdim:
+   case OpenCLstd_Fdim:
       return nir_fdim(nb, srcs[0], srcs[1]);
-   case Distance:
+   case OpenCLstd_Distance:
       return nir_distance(nb, srcs[0], srcs[1]);
-   case Fast_distance:
+   case OpenCLstd_Fast_distance:
       return nir_fast_distance(nb, srcs[0], srcs[1]);
-   case Fast_length:
+   case OpenCLstd_Fast_length:
       return nir_fast_length(nb, srcs[0]);
-   case Fast_normalize:
+   case OpenCLstd_Fast_normalize:
       return nir_fast_normalize(nb, srcs[0]);
-   case Length:
+   case OpenCLstd_Length:
       return nir_length(nb, srcs[0]);
-   case Mad:
+   case OpenCLstd_Mad:
       return nir_fmad(nb, srcs[0], srcs[1], srcs[2]);
-   case Maxmag:
+   case OpenCLstd_Maxmag:
       return nir_maxmag(nb, srcs[0], srcs[1]);
-   case Minmag:
+   case OpenCLstd_Minmag:
       return nir_minmag(nb, srcs[0], srcs[1]);
-   case Nan:
+   case OpenCLstd_Nan:
       return nir_nan(nb, srcs[0]);
-   case Nextafter:
+   case OpenCLstd_Nextafter:
       return nir_nextafter(nb, srcs[0], srcs[1]);
-   case Normalize:
+   case OpenCLstd_Normalize:
       return nir_normalize(nb, srcs[0]);
-   case Radians:
+   case OpenCLstd_Radians:
       return nir_radians(nb, srcs[0]);
-   case Rotate:
+   case OpenCLstd_Rotate:
       return nir_rotate(nb, srcs[0], srcs[1]);
-   case Smoothstep:
+   case OpenCLstd_Smoothstep:
       return nir_smoothstep(nb, srcs[0], srcs[1], srcs[2]);
-   case Select:
+   case OpenCLstd_Clz:
+      return nir_clz_u(nb, srcs[0]);
+   case OpenCLstd_Select:
       return nir_select(nb, srcs[0], srcs[1], srcs[2]);
-   case Step:
+   case OpenCLstd_Step:
       return nir_sge(nb, srcs[1], srcs[0]);
-   case S_Upsample:
-   case U_Upsample:
+   case OpenCLstd_S_Upsample:
+   case OpenCLstd_U_Upsample:
       return nir_upsample(nb, srcs[0], srcs[1]);
+   case OpenCLstd_Native_exp:
+      return nir_fexp(nb, srcs[0]);
+   case OpenCLstd_Native_exp10:
+      return nir_fexp2(nb, nir_fmul_imm(nb, srcs[0], log(10) / log(2)));
+   case OpenCLstd_Native_log:
+      return nir_flog(nb, srcs[0]);
+   case OpenCLstd_Native_log10:
+      return nir_fmul_imm(nb, nir_flog2(nb, srcs[0]), log(2) / log(10));
+   case OpenCLstd_Native_tan:
+      return nir_ftan(nb, srcs[0]);
    default:
       vtn_fail("No NIR equivalent");
       return NULL;
@@ -183,144 +220,246 @@ handle_special(struct vtn_builder *b, enum OpenCLstd opcode, unsigned num_srcs,
 }
 
 static void
-_handle_v_load_store(struct vtn_builder *b, enum OpenCLstd opcode,
+_handle_v_load_store(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode,
                      const uint32_t *w, unsigned count, bool load)
 {
    struct vtn_type *type;
    if (load)
-      type = vtn_value(b, w[1], vtn_value_type_type)->type;
+      type = vtn_get_type(b, w[1]);
    else
-      type = vtn_untyped_value(b, w[5])->type;
+      type = vtn_get_value_type(b, w[5]);
    unsigned a = load ? 0 : 1;
 
    const struct glsl_type *dest_type = type->type;
    unsigned components = glsl_get_vector_elements(dest_type);
-   unsigned stride = components * glsl_get_bit_size(dest_type) / 8;
 
-   nir_ssa_def *offset = vtn_ssa_value(b, w[5 + a])->def;
+   nir_ssa_def *offset = vtn_get_nir_ssa(b, w[5 + a]);
    struct vtn_value *p = vtn_value(b, w[6 + a], vtn_value_type_pointer);
 
+   struct vtn_ssa_value *comps[NIR_MAX_VEC_COMPONENTS];
+   nir_ssa_def *ncomps[NIR_MAX_VEC_COMPONENTS];
+
+   nir_ssa_def *moffset = nir_imul_imm(&b->nb, offset, components);
    nir_deref_instr *deref = vtn_pointer_to_deref(b, p->pointer);
 
-   /* 1. cast to vec type with adjusted stride */
-   deref = nir_build_deref_cast(&b->nb, &deref->dest.ssa, deref->mode,
-                                dest_type, stride);
-   /* 2. deref ptr_as_array */
-   deref = nir_build_deref_ptr_as_array(&b->nb, deref, offset);
+   for (int i = 0; i < components; i++) {
+      nir_ssa_def *coffset = nir_iadd_imm(&b->nb, moffset, i);
+      nir_deref_instr *arr_deref = nir_build_deref_ptr_as_array(&b->nb, deref, coffset);
 
+      if (load) {
+         comps[i] = vtn_local_load(b, arr_deref, p->type->access);
+         ncomps[i] = comps[i]->def;
+      } else {
+         struct vtn_ssa_value *ssa = vtn_create_ssa_value(b, glsl_scalar_type(glsl_get_base_type(dest_type)));
+         struct vtn_ssa_value *val = vtn_ssa_value(b, w[5]);
+         ssa->def = nir_channel(&b->nb, val->def, i);
+         vtn_local_store(b, ssa, arr_deref, p->type->access);
+      }
+   }
    if (load) {
-      struct vtn_ssa_value *val = vtn_local_load(b, deref, p->type->access);
-      vtn_push_ssa(b, w[2], type, val);
-   } else {
-      struct vtn_ssa_value *val = vtn_ssa_value(b, w[5]);
-      vtn_local_store(b, val, deref, p->type->access);
+      vtn_push_nir_ssa(b, w[2], nir_vec(&b->nb, ncomps, components));
    }
 }
 
 static void
-vtn_handle_opencl_vload(struct vtn_builder *b, enum OpenCLstd opcode,
+vtn_handle_opencl_vload(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode,
                         const uint32_t *w, unsigned count)
 {
    _handle_v_load_store(b, opcode, w, count, true);
 }
 
 static void
-vtn_handle_opencl_vstore(struct vtn_builder *b, enum OpenCLstd opcode,
+vtn_handle_opencl_vstore(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode,
                          const uint32_t *w, unsigned count)
 {
    _handle_v_load_store(b, opcode, w, count, false);
 }
 
 static nir_ssa_def *
-handle_printf(struct vtn_builder *b, enum OpenCLstd opcode, unsigned num_srcs,
-              nir_ssa_def **srcs, const struct glsl_type *dest_type)
+handle_printf(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode,
+              unsigned num_srcs, nir_ssa_def **srcs,
+              const struct glsl_type *dest_type)
 {
    /* hahah, yeah, right.. */
    return nir_imm_int(&b->nb, -1);
 }
 
+static nir_ssa_def *
+handle_round(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode,
+             unsigned num_srcs, nir_ssa_def **srcs,
+             const struct glsl_type *dest_type)
+{
+   nir_ssa_def *src = srcs[0];
+   nir_builder *nb = &b->nb;
+   nir_ssa_def *half = nir_imm_floatN_t(nb, 0.5, src->bit_size);
+   nir_ssa_def *truncated = nir_ftrunc(nb, src);
+   nir_ssa_def *remainder = nir_fsub(nb, src, truncated);
+
+   return nir_bcsel(nb, nir_fge(nb, nir_fabs(nb, remainder), half),
+                    nir_fadd(nb, truncated, nir_fsign(nb, src)), truncated);
+}
+
+static nir_ssa_def *
+handle_shuffle(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode, unsigned num_srcs,
+               nir_ssa_def **srcs, const struct glsl_type *dest_type)
+{
+   struct nir_ssa_def *input = srcs[0];
+   struct nir_ssa_def *mask = srcs[1];
+
+   unsigned out_elems = glsl_get_vector_elements(dest_type);
+   nir_ssa_def *outres[NIR_MAX_VEC_COMPONENTS];
+   unsigned in_elems = input->num_components;
+   if (mask->bit_size != 32)
+      mask = nir_u2u32(&b->nb, mask);
+   mask = nir_iand(&b->nb, mask, nir_imm_intN_t(&b->nb, in_elems - 1, mask->bit_size));
+   for (unsigned i = 0; i < out_elems; i++)
+      outres[i] = nir_vector_extract(&b->nb, input, nir_channel(&b->nb, mask, i));
+
+   return nir_vec(&b->nb, outres, out_elems);
+}
+
+static nir_ssa_def *
+handle_shuffle2(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode, unsigned num_srcs,
+                nir_ssa_def **srcs, const struct glsl_type *dest_type)
+{
+   struct nir_ssa_def *input0 = srcs[0];
+   struct nir_ssa_def *input1 = srcs[1];
+   struct nir_ssa_def *mask = srcs[2];
+
+   unsigned out_elems = glsl_get_vector_elements(dest_type);
+   nir_ssa_def *outres[NIR_MAX_VEC_COMPONENTS];
+   unsigned in_elems = input0->num_components;
+   unsigned total_mask = 2 * in_elems - 1;
+   unsigned half_mask = in_elems - 1;
+   if (mask->bit_size != 32)
+      mask = nir_u2u32(&b->nb, mask);
+   mask = nir_iand(&b->nb, mask, nir_imm_intN_t(&b->nb, total_mask, mask->bit_size));
+   for (unsigned i = 0; i < out_elems; i++) {
+      nir_ssa_def *this_mask = nir_channel(&b->nb, mask, i);
+      nir_ssa_def *vmask = nir_iand(&b->nb, this_mask, nir_imm_intN_t(&b->nb, half_mask, mask->bit_size));
+      nir_ssa_def *val0 = nir_vector_extract(&b->nb, input0, vmask);
+      nir_ssa_def *val1 = nir_vector_extract(&b->nb, input1, vmask);
+      nir_ssa_def *sel = nir_ilt(&b->nb, this_mask, nir_imm_intN_t(&b->nb, in_elems, mask->bit_size));
+      outres[i] = nir_bcsel(&b->nb, sel, val0, val1);
+   }
+   return nir_vec(&b->nb, outres, out_elems);
+}
+
 bool
-vtn_handle_opencl_instruction(struct vtn_builder *b, uint32_t ext_opcode,
+vtn_handle_opencl_instruction(struct vtn_builder *b, SpvOp ext_opcode,
                               const uint32_t *w, unsigned count)
 {
-   switch (ext_opcode) {
-   case Fabs:
-   case SAbs:
-   case UAbs:
-   case SAdd_sat:
-   case UAdd_sat:
-   case Ceil:
-   case Cos:
-   case Exp2:
-   case Log2:
-   case Floor:
-   case Fma:
-   case Fmax:
-   case SHadd:
-   case UHadd:
-   case SMax:
-   case UMax:
-   case Fmin:
-   case SMin:
-   case UMin:
-   case Mix:
-   case Fmod:
-   case SMul_hi:
-   case UMul_hi:
-   case Popcount:
-   case Pow:
-   case Remainder:
-   case SRhadd:
-   case URhadd:
-   case Rsqrt:
-   case Sign:
-   case Sin:
-   case Sqrt:
-   case SSub_sat:
-   case USub_sat:
-   case Trunc:
-      handle_instr(b, ext_opcode, w, count, handle_alu);
+   enum OpenCLstd_Entrypoints cl_opcode = (enum OpenCLstd_Entrypoints) ext_opcode;
+
+   switch (cl_opcode) {
+   case OpenCLstd_Fabs:
+   case OpenCLstd_SAbs:
+   case OpenCLstd_UAbs:
+   case OpenCLstd_SAdd_sat:
+   case OpenCLstd_UAdd_sat:
+   case OpenCLstd_Ceil:
+   case OpenCLstd_Cos:
+   case OpenCLstd_Exp2:
+   case OpenCLstd_Log2:
+   case OpenCLstd_Floor:
+   case OpenCLstd_Fma:
+   case OpenCLstd_Fmax:
+   case OpenCLstd_SHadd:
+   case OpenCLstd_UHadd:
+   case OpenCLstd_SMax:
+   case OpenCLstd_UMax:
+   case OpenCLstd_Fmin:
+   case OpenCLstd_SMin:
+   case OpenCLstd_UMin:
+   case OpenCLstd_Mix:
+   case OpenCLstd_Native_cos:
+   case OpenCLstd_Native_divide:
+   case OpenCLstd_Native_exp2:
+   case OpenCLstd_Native_log2:
+   case OpenCLstd_Native_powr:
+   case OpenCLstd_Native_recip:
+   case OpenCLstd_Native_rsqrt:
+   case OpenCLstd_Native_sin:
+   case OpenCLstd_Native_sqrt:
+   case OpenCLstd_Fmod:
+   case OpenCLstd_SMul_hi:
+   case OpenCLstd_UMul_hi:
+   case OpenCLstd_Popcount:
+   case OpenCLstd_Pow:
+   case OpenCLstd_Remainder:
+   case OpenCLstd_SRhadd:
+   case OpenCLstd_URhadd:
+   case OpenCLstd_Rsqrt:
+   case OpenCLstd_Sign:
+   case OpenCLstd_Sin:
+   case OpenCLstd_Sqrt:
+   case OpenCLstd_SSub_sat:
+   case OpenCLstd_USub_sat:
+   case OpenCLstd_Trunc:
+   case OpenCLstd_Rint:
+      handle_instr(b, cl_opcode, w, count, handle_alu);
+      return true;
+   case OpenCLstd_SAbs_diff:
+   case OpenCLstd_UAbs_diff:
+   case OpenCLstd_SMad_hi:
+   case OpenCLstd_UMad_hi:
+   case OpenCLstd_SMad24:
+   case OpenCLstd_UMad24:
+   case OpenCLstd_SMul24:
+   case OpenCLstd_UMul24:
+   case OpenCLstd_Bitselect:
+   case OpenCLstd_FClamp:
+   case OpenCLstd_SClamp:
+   case OpenCLstd_UClamp:
+   case OpenCLstd_Copysign:
+   case OpenCLstd_Cross:
+   case OpenCLstd_Degrees:
+   case OpenCLstd_Fdim:
+   case OpenCLstd_Distance:
+   case OpenCLstd_Fast_distance:
+   case OpenCLstd_Fast_length:
+   case OpenCLstd_Fast_normalize:
+   case OpenCLstd_Length:
+   case OpenCLstd_Mad:
+   case OpenCLstd_Maxmag:
+   case OpenCLstd_Minmag:
+   case OpenCLstd_Nan:
+   case OpenCLstd_Nextafter:
+   case OpenCLstd_Normalize:
+   case OpenCLstd_Radians:
+   case OpenCLstd_Rotate:
+   case OpenCLstd_Select:
+   case OpenCLstd_Step:
+   case OpenCLstd_Smoothstep:
+   case OpenCLstd_S_Upsample:
+   case OpenCLstd_U_Upsample:
+   case OpenCLstd_Clz:
+   case OpenCLstd_Native_exp:
+   case OpenCLstd_Native_exp10:
+   case OpenCLstd_Native_log:
+   case OpenCLstd_Native_log10:
+   case OpenCLstd_Native_tan:
+      handle_instr(b, cl_opcode, w, count, handle_special);
+      return true;
+   case OpenCLstd_Vloadn:
+      vtn_handle_opencl_vload(b, cl_opcode, w, count);
+      return true;
+   case OpenCLstd_Vstoren:
+      vtn_handle_opencl_vstore(b, cl_opcode, w, count);
       return true;
-   case SAbs_diff:
-   case UAbs_diff:
-   case Bitselect:
-   case FClamp:
-   case SClamp:
-   case UClamp:
-   case Copysign:
-   case Cross:
-   case Degrees:
-   case Fdim:
-   case Distance:
-   case Fast_distance:
-   case Fast_length:
-   case Fast_normalize:
-   case Length:
-   case Mad:
-   case Maxmag:
-   case Minmag:
-   case Nan:
-   case Nextafter:
-   case Normalize:
-   case Radians:
-   case Rotate:
-   case Select:
-   case Step:
-   case Smoothstep:
-   case S_Upsample:
-   case U_Upsample:
-      handle_instr(b, ext_opcode, w, count, handle_special);
+   case OpenCLstd_Shuffle:
+      handle_instr(b, cl_opcode, w, count, handle_shuffle);
       return true;
-   case Vloadn:
-      vtn_handle_opencl_vload(b, ext_opcode, w, count);
+   case OpenCLstd_Shuffle2:
+      handle_instr(b, cl_opcode, w, count, handle_shuffle2);
       return true;
-   case Vstoren:
-      vtn_handle_opencl_vstore(b, ext_opcode, w, count);
+   case OpenCLstd_Round:
+      handle_instr(b, cl_opcode, w, count, handle_round);
       return true;
-   case Printf:
-      handle_instr(b, ext_opcode, w, count, handle_printf);
+   case OpenCLstd_Printf:
+      handle_instr(b, cl_opcode, w, count, handle_printf);
       return true;
-   case Prefetch:
+   case OpenCLstd_Prefetch:
       /* TODO maybe add a nir instruction for this? */
       return true;
    default: