nir: Combine the int and double [un]pack opcodes
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 15 Feb 2017 06:15:16 +0000 (22:15 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 17 Feb 2017 01:28:03 +0000 (17:28 -0800)
NIR is a typeless IR and the two opcodes, when considered bitwise, do
exactly the same thing.  There's no reason to have two versions.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/glsl/glsl_to_nir.cpp
src/compiler/nir/nir_lower_alu_to_scalar.c
src/compiler/nir/nir_lower_double_ops.c
src/compiler/nir/nir_lower_double_packing.c
src/compiler/nir/nir_opcodes.py
src/compiler/nir/nir_opt_algebraic.py
src/compiler/spirv/vtn_glsl450.c
src/mesa/drivers/dri/i965/brw_fs_nir.cpp
src/mesa/drivers/dri/i965/brw_vec4_nir.cpp

index 96d8164ea43c8ba939fc1c977d9d7090c19245dc..00f20dabd660b2888559315e890f3956f9f8120f 100644 (file)
@@ -1581,18 +1581,14 @@ nir_visitor::visit(ir_expression *ir)
       result = nir_unpack_half_2x16(&b, srcs[0]);
       break;
    case ir_unop_pack_double_2x32:
-      result = nir_pack_double_2x32(&b, srcs[0]);
-      break;
-   case ir_unop_unpack_double_2x32:
-      result = nir_unpack_double_2x32(&b, srcs[0]);
-      break;
    case ir_unop_pack_int_2x32:
    case ir_unop_pack_uint_2x32:
-      result = nir_pack_int_2x32(&b, srcs[0]);
+      result = nir_pack_64_2x32(&b, srcs[0]);
       break;
+   case ir_unop_unpack_double_2x32:
    case ir_unop_unpack_int_2x32:
    case ir_unop_unpack_uint_2x32:
-      result = nir_unpack_int_2x32(&b, srcs[0]);
+      result = nir_unpack_64_2x32(&b, srcs[0]);
       break;
    case ir_unop_bitfield_reverse:
       result = nir_bitfield_reverse(&b, srcs[0]);
index 8a967c56831b8e63287dba62dd0e95d181b23d2b..080d980f3479bc3c6dcf2166d885d938e6bde2b4 100644 (file)
@@ -188,8 +188,7 @@ lower_alu_instr_scalar(nir_alu_instr *instr, nir_builder *b)
       return true;
    }
 
-   case nir_op_unpack_double_2x32:
-   case nir_op_unpack_int_2x32:
+   case nir_op_unpack_64_2x32:
       return false;
 
       LOWER_REDUCTION(nir_op_fdot, nir_op_fmul, nir_op_fadd);
index fdd0f44744846f824dc01b04e7bff80b77846173..ad9631327b4e116608994c80e4a460e99da6cf22 100644 (file)
@@ -41,22 +41,22 @@ static nir_ssa_def *
 set_exponent(nir_builder *b, nir_ssa_def *src, nir_ssa_def *exp)
 {
    /* Split into bits 0-31 and 32-63 */
-   nir_ssa_def *lo = nir_unpack_double_2x32_split_x(b, src);
-   nir_ssa_def *hi = nir_unpack_double_2x32_split_y(b, src);
+   nir_ssa_def *lo = nir_unpack_64_2x32_split_x(b, src);
+   nir_ssa_def *hi = nir_unpack_64_2x32_split_y(b, src);
 
    /* The exponent is bits 52-62, or 20-30 of the high word, so set the exponent
     * to 1023
     */
    nir_ssa_def *new_hi = nir_bfi(b, nir_imm_int(b, 0x7ff00000), exp, hi);
    /* recombine */
-   return nir_pack_double_2x32_split(b, lo, new_hi);
+   return nir_pack_64_2x32_split(b, lo, new_hi);
 }
 
 static nir_ssa_def *
 get_exponent(nir_builder *b, nir_ssa_def *src)
 {
    /* get bits 32-63 */
-   nir_ssa_def *hi = nir_unpack_double_2x32_split_y(b, src);
+   nir_ssa_def *hi = nir_unpack_64_2x32_split_y(b, src);
 
    /* extract bits 20-30 of the high word */
    return nir_ubitfield_extract(b, hi, nir_imm_int(b, 20), nir_imm_int(b, 11));
@@ -67,7 +67,7 @@ get_exponent(nir_builder *b, nir_ssa_def *src)
 static nir_ssa_def *
 get_signed_inf(nir_builder *b, nir_ssa_def *zero)
 {
-   nir_ssa_def *zero_hi = nir_unpack_double_2x32_split_y(b, zero);
+   nir_ssa_def *zero_hi = nir_unpack_64_2x32_split_y(b, zero);
 
    /* The bit pattern for infinity is 0x7ff0000000000000, where the sign bit
     * is the highest bit. Only the sign bit can be non-zero in the passed in
@@ -76,7 +76,7 @@ get_signed_inf(nir_builder *b, nir_ssa_def *zero)
     * bits and then pack it together with zero low 32 bits.
     */
    nir_ssa_def *inf_hi = nir_ior(b, nir_imm_int(b, 0x7ff00000), zero_hi);
-   return nir_pack_double_2x32_split(b, nir_imm_int(b, 0), inf_hi);
+   return nir_pack_64_2x32_split(b, nir_imm_int(b, 0), inf_hi);
 }
 
 /*
@@ -337,8 +337,8 @@ lower_trunc(nir_builder *b, nir_ssa_def *src)
                          nir_imm_int(b, ~0),
                          nir_isub(b, frac_bits, nir_imm_int(b, 32))));
 
-   nir_ssa_def *src_lo = nir_unpack_double_2x32_split_x(b, src);
-   nir_ssa_def *src_hi = nir_unpack_double_2x32_split_y(b, src);
+   nir_ssa_def *src_lo = nir_unpack_64_2x32_split_x(b, src);
+   nir_ssa_def *src_hi = nir_unpack_64_2x32_split_y(b, src);
 
    return
       nir_bcsel(b,
@@ -346,9 +346,9 @@ lower_trunc(nir_builder *b, nir_ssa_def *src)
                 nir_imm_double(b, 0.0),
                 nir_bcsel(b, nir_ige(b, unbiased_exp, nir_imm_int(b, 53)),
                           src,
-                          nir_pack_double_2x32_split(b,
-                                                     nir_iand(b, mask_lo, src_lo),
-                                                     nir_iand(b, mask_hi, src_hi))));
+                          nir_pack_64_2x32_split(b,
+                                                 nir_iand(b, mask_lo, src_lo),
+                                                 nir_iand(b, mask_hi, src_hi))));
 }
 
 static nir_ssa_def *
index 6bb01ff190902c11e4d712c3d0961f24db62fbe8..61c4ea65eaed62a54f001c745bca35033faf476b 100644 (file)
  */
 
 static nir_ssa_def *
-lower_pack_double(nir_builder *b, nir_ssa_def *src)
+lower_pack_64(nir_builder *b, nir_ssa_def *src)
 {
-   return nir_pack_double_2x32_split(b, nir_channel(b, src, 0),
-                                        nir_channel(b, src, 1));
+   return nir_pack_64_2x32_split(b, nir_channel(b, src, 0),
+                                    nir_channel(b, src, 1));
 }
 
 static nir_ssa_def *
-lower_unpack_double(nir_builder *b, nir_ssa_def *src)
+lower_unpack_64(nir_builder *b, nir_ssa_def *src)
 {
-   return nir_vec2(b, nir_unpack_double_2x32_split_x(b, src),
-                      nir_unpack_double_2x32_split_y(b, src));
-}
-
-static nir_ssa_def *
-lower_pack_int(nir_builder *b, nir_ssa_def *src)
-{
-   return nir_pack_int_2x32_split(b, nir_channel(b, src, 0),
-                                     nir_channel(b, src, 1));
-}
-
-static nir_ssa_def *
-lower_unpack_int(nir_builder *b, nir_ssa_def *src)
-{
-   return nir_vec2(b, nir_unpack_int_2x32_split_x(b, src),
-                      nir_unpack_int_2x32_split_y(b, src));
+   return nir_vec2(b, nir_unpack_64_2x32_split_x(b, src),
+                      nir_unpack_64_2x32_split_y(b, src));
 }
 
 static void
@@ -75,10 +61,8 @@ lower_double_pack_impl(nir_function_impl *impl)
 
          nir_alu_instr *alu_instr = (nir_alu_instr *) instr;
 
-         if (alu_instr->op != nir_op_pack_double_2x32 &&
-             alu_instr->op != nir_op_unpack_double_2x32 &&
-             alu_instr->op != nir_op_pack_int_2x32 &&
-             alu_instr->op != nir_op_unpack_int_2x32)
+         if (alu_instr->op != nir_op_pack_64_2x32 &&
+             alu_instr->op != nir_op_unpack_64_2x32)
             continue;
 
          b.cursor = nir_before_instr(&alu_instr->instr);
@@ -87,17 +71,11 @@ lower_double_pack_impl(nir_function_impl *impl)
          nir_ssa_def *dest;
 
          switch (alu_instr->op) {
-         case nir_op_pack_double_2x32:
-            dest = lower_pack_double(&b, src);
-            break;
-         case nir_op_unpack_double_2x32:
-            dest = lower_unpack_double(&b, src);
-            break;
-         case nir_op_pack_int_2x32:
-            dest = lower_pack_int(&b, src);
+         case nir_op_pack_64_2x32:
+            dest = lower_pack_64(&b, src);
             break;
-         case nir_op_unpack_int_2x32:
-            dest = lower_unpack_int(&b, src);
+         case nir_op_unpack_64_2x32:
+            dest = lower_unpack_64(&b, src);
             break;
          default:
             unreachable("Impossible opcode");
index ece673cda36d00c4a21e8ca5b000b77123e852ee..b116fcffcc740ca9719c4bea9fecf4d6c0cd5705 100644 (file)
@@ -285,16 +285,10 @@ dst.x = (src0.x <<  0) |
         (src0.w << 24);
 """)
 
-unop_horiz("pack_double_2x32", 1, tuint64, 2, tuint32,
+unop_horiz("pack_64_2x32", 1, tuint64, 2, tuint32,
            "dst.x = src0.x | ((uint64_t)src0.y << 32);")
 
-unop_horiz("pack_int_2x32", 1, tint64, 2, tint32,
-           "dst.x = src0.x | ((int64_t)src0.y << 32);")
-
-unop_horiz("unpack_double_2x32", 2, tuint32, 1, tuint64,
-           "dst.x = src0.x; dst.y = src0.x >> 32;")
-
-unop_horiz("unpack_int_2x32", 2, tint32, 1, tint64,
+unop_horiz("unpack_64_2x32", 2, tuint32, 1, tuint64,
            "dst.x = src0.x; dst.y = src0.x >> 32;")
 
 # Lowered floating point unpacking operations.
@@ -305,10 +299,8 @@ unop_horiz("unpack_half_2x16_split_x", 1, tfloat32, 1, tuint32,
 unop_horiz("unpack_half_2x16_split_y", 1, tfloat32, 1, tuint32,
            "unpack_half_1x16((uint16_t)(src0.x >> 16))")
 
-unop_convert("unpack_double_2x32_split_x", tuint32, tuint64, "src0")
-unop_convert("unpack_double_2x32_split_y", tuint32, tuint64, "src0 >> 32")
-unop_convert("unpack_int_2x32_split_x", tuint32, tuint64, "src0")
-unop_convert("unpack_int_2x32_split_y", tuint32, tuint64, "src0 >> 32")
+unop_convert("unpack_64_2x32_split_x", tuint32, tuint64, "src0")
+unop_convert("unpack_64_2x32_split_y", tuint32, tuint64, "src0 >> 32")
 
 # Bit operations, part of ARB_gpu_shader5.
 
@@ -588,10 +580,7 @@ binop("fpow", tfloat, "", "bit_size == 64 ? powf(src0, src1) : pow(src0, src1)")
 binop_horiz("pack_half_2x16_split", 1, tuint32, 1, tfloat32, 1, tfloat32,
             "pack_half_1x16(src0.x) | (pack_half_1x16(src1.x) << 16)")
 
-binop_convert("pack_double_2x32_split", tuint64, tuint32, "",
-              "src0 | ((uint64_t)src1 << 32)")
-
-binop_convert("pack_int_2x32_split", tuint64, tuint32, "",
+binop_convert("pack_64_2x32_split", tuint64, tuint32, "",
               "src0 | ((uint64_t)src1 << 32)")
 
 # bfm implements the behavior of the first operation of the SM5 "bfi" assembly
index aaad45a4c5af7037d9242c22cee0b75b0b81e09d..8a6dd073e9f07649196ede03ce887cb364e8fb76 100644 (file)
@@ -434,7 +434,7 @@ def fexp2i(exp, bits):
    if bits == 32:
       return ('ishl', ('iadd', exp, 127), 23)
    elif bits == 64:
-      return ('pack_double_2x32_split', 0, ('ishl', ('iadd', exp, 1023), 20))
+      return ('pack_64_2x32_split', 0, ('ishl', ('iadd', exp, 1023), 20))
    else:
       assert False
 
index dd38cc95ccf70709bdc193acfe622c3d4860d3ed..5d384319e0095e615e113b4e10e42280561bce69 100644 (file)
@@ -452,13 +452,13 @@ vtn_nir_alu_op_for_spirv_glsl_opcode(enum GLSLstd450 opcode)
    case GLSLstd450PackSnorm2x16:    return nir_op_pack_snorm_2x16;
    case GLSLstd450PackUnorm2x16:    return nir_op_pack_unorm_2x16;
    case GLSLstd450PackHalf2x16:     return nir_op_pack_half_2x16;
-   case GLSLstd450PackDouble2x32:   return nir_op_pack_double_2x32;
+   case GLSLstd450PackDouble2x32:   return nir_op_pack_64_2x32;
    case GLSLstd450UnpackSnorm4x8:   return nir_op_unpack_snorm_4x8;
    case GLSLstd450UnpackUnorm4x8:   return nir_op_unpack_unorm_4x8;
    case GLSLstd450UnpackSnorm2x16:  return nir_op_unpack_snorm_2x16;
    case GLSLstd450UnpackUnorm2x16:  return nir_op_unpack_unorm_2x16;
    case GLSLstd450UnpackHalf2x16:   return nir_op_unpack_half_2x16;
-   case GLSLstd450UnpackDouble2x32: return nir_op_unpack_double_2x32;
+   case GLSLstd450UnpackDouble2x32: return nir_op_unpack_64_2x32;
 
    default:
       unreachable("No NIR equivalent");
index 94f275189f30ac62b9b45579cd9c2f8f3e5a683f..91c14ebddfed3e471a0b553fbd1763ebc99cc1ba 100644 (file)
@@ -1212,7 +1212,7 @@ fs_visitor::nir_emit_alu(const fs_builder &bld, nir_alu_instr *instr)
       inst->saturate = instr->dest.saturate;
       break;
 
-   case nir_op_pack_double_2x32_split:
+   case nir_op_pack_64_2x32_split:
       /* Optimize the common case where we are re-packing a double with
        * the result of a previous double unpack. In this case we can take the
        * 32-bit value to use in the re-pack from the original double and bypass
@@ -1227,8 +1227,8 @@ fs_visitor::nir_emit_alu(const fs_builder &bld, nir_alu_instr *instr)
             continue;
 
          const nir_alu_instr *alu_parent = nir_instr_as_alu(parent_instr);
-         if (alu_parent->op == nir_op_unpack_double_2x32_split_x ||
-             alu_parent->op == nir_op_unpack_double_2x32_split_y)
+         if (alu_parent->op == nir_op_unpack_64_2x32_split_x ||
+             alu_parent->op == nir_op_unpack_64_2x32_split_y)
             continue;
 
          if (!alu_parent->src[0].src.is_ssa)
@@ -1237,7 +1237,7 @@ fs_visitor::nir_emit_alu(const fs_builder &bld, nir_alu_instr *instr)
          op[i] = get_nir_src(alu_parent->src[0].src);
          op[i] = offset(retype(op[i], BRW_REGISTER_TYPE_DF), bld,
                         alu_parent->src[0].swizzle[channel]);
-         if (alu_parent->op == nir_op_unpack_double_2x32_split_y)
+         if (alu_parent->op == nir_op_unpack_64_2x32_split_y)
             op[i] = subscript(op[i], BRW_REGISTER_TYPE_UD, 1);
          else
             op[i] = subscript(op[i], BRW_REGISTER_TYPE_UD, 0);
@@ -1245,18 +1245,18 @@ fs_visitor::nir_emit_alu(const fs_builder &bld, nir_alu_instr *instr)
       bld.emit(FS_OPCODE_PACK, result, op[0], op[1]);
       break;
 
-   case nir_op_unpack_double_2x32_split_x:
-   case nir_op_unpack_double_2x32_split_y: {
+   case nir_op_unpack_64_2x32_split_x:
+   case nir_op_unpack_64_2x32_split_y: {
       /* Optimize the common case where we are unpacking from a double we have
        * previously packed. In this case we can just bypass the pack operation
        * and source directly from its arguments.
        */
-      unsigned index = (instr->op == nir_op_unpack_double_2x32_split_x) ? 0 : 1;
+      unsigned index = (instr->op == nir_op_unpack_64_2x32_split_x) ? 0 : 1;
       if (instr->src[0].src.is_ssa) {
          nir_instr *parent_instr = instr->src[0].src.ssa->parent_instr;
          if (parent_instr->type == nir_instr_type_alu) {
             nir_alu_instr *alu_parent = nir_instr_as_alu(parent_instr);
-            if (alu_parent->op == nir_op_pack_double_2x32_split &&
+            if (alu_parent->op == nir_op_pack_64_2x32_split &&
                 alu_parent->src[index].src.is_ssa) {
                op[0] = retype(get_nir_src(alu_parent->src[index].src),
                               BRW_REGISTER_TYPE_UD);
@@ -1268,20 +1268,7 @@ fs_visitor::nir_emit_alu(const fs_builder &bld, nir_alu_instr *instr)
          }
       }
 
-      if (instr->op == nir_op_unpack_double_2x32_split_x)
-         bld.MOV(result, subscript(op[0], BRW_REGISTER_TYPE_UD, 0));
-      else
-         bld.MOV(result, subscript(op[0], BRW_REGISTER_TYPE_UD, 1));
-      break;
-   }
-
-   case nir_op_pack_int_2x32_split:
-      bld.emit(FS_OPCODE_PACK, result, op[0], op[1]);
-      break;
-
-   case nir_op_unpack_int_2x32_split_x:
-   case nir_op_unpack_int_2x32_split_y: {
-      if (instr->op == nir_op_unpack_int_2x32_split_x)
+      if (instr->op == nir_op_unpack_64_2x32_split_x)
          bld.MOV(result, subscript(op[0], BRW_REGISTER_TYPE_UD, 0));
       else
          bld.MOV(result, subscript(op[0], BRW_REGISTER_TYPE_UD, 1));
index 2127415be7a727c2350cc1f3364e0ac427e38d68..a7f048a0f8f3d5b603491d05e23a6ecc74839190 100644 (file)
@@ -1762,7 +1762,7 @@ vec4_visitor::nir_emit_alu(nir_alu_instr *instr)
       break;
    }
 
-   case nir_op_pack_double_2x32_split: {
+   case nir_op_pack_64_2x32_split: {
       dst_reg result = dst_reg(this, glsl_type::dvec4_type);
       dst_reg tmp = dst_reg(this, glsl_type::uvec4_type);
       emit(MOV(tmp, retype(op[0], BRW_REGISTER_TYPE_UD)));
@@ -1773,9 +1773,9 @@ vec4_visitor::nir_emit_alu(nir_alu_instr *instr)
       break;
    }
 
-   case nir_op_unpack_double_2x32_split_x:
-   case nir_op_unpack_double_2x32_split_y: {
-      enum opcode oper = (instr->op == nir_op_unpack_double_2x32_split_x) ?
+   case nir_op_unpack_64_2x32_split_x:
+   case nir_op_unpack_64_2x32_split_y: {
+      enum opcode oper = (instr->op == nir_op_unpack_64_2x32_split_x) ?
          VEC4_OPCODE_PICK_LOW_32BIT : VEC4_OPCODE_PICK_HIGH_32BIT;
       dst_reg tmp = dst_reg(this, glsl_type::dvec4_type);
       emit(MOV(tmp, op[0]));