nir: Lower packing and unpacking of 64-bit integer types
authorIan Romanick <ian.d.romanick@intel.com>
Fri, 2 Sep 2016 15:09:53 +0000 (08:09 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 20 Jan 2017 23:41:23 +0000 (15:41 -0800)
This change makes me wonder whether double packing should be
reimplemented as int64BitsToDouble(packInt2x32(v)).  I'm a little on the
fence since not all platforms that support fp64 natively support int64.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
src/compiler/nir/nir_lower_double_packing.c

index ed1e7078e4dcff325e584a2967d984545543e640..6bb01ff190902c11e4d712c3d0961f24db62fbe8 100644 (file)
@@ -30,6 +30,8 @@
  *
  * packDouble2x32(foo) -> packDouble2x32Split(foo.x, foo.y)
  * unpackDouble2x32(foo) -> vec2(unpackDouble2x32_x(foo), unpackDouble2x32_y(foo))
+ * packInt2x32(foo) -> packInt2x32Split(foo.x, foo.y)
+ * unpackInt2x32(foo) -> vec2(unpackInt2x32_x(foo), unpackInt2x32_y(foo))
  */
 
 static nir_ssa_def *
@@ -46,6 +48,20 @@ lower_unpack_double(nir_builder *b, nir_ssa_def *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));
+}
+
 static void
 lower_double_pack_impl(nir_function_impl *impl)
 {
@@ -60,16 +76,32 @@ 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_unpack_double_2x32 &&
+             alu_instr->op != nir_op_pack_int_2x32 &&
+             alu_instr->op != nir_op_unpack_int_2x32)
             continue;
 
          b.cursor = nir_before_instr(&alu_instr->instr);
 
          nir_ssa_def *src = nir_ssa_for_alu_src(&b, alu_instr, 0);
-         nir_ssa_def *dest =
-            alu_instr->op == nir_op_pack_double_2x32 ?
-            lower_pack_double(&b, src) :
-            lower_unpack_double(&b, src);
+         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);
+            break;
+         case nir_op_unpack_int_2x32:
+            dest = lower_unpack_int(&b, src);
+            break;
+         default:
+            unreachable("Impossible opcode");
+         }
 
          nir_ssa_def_rewrite_uses(&alu_instr->dest.dest.ssa, nir_src_for_ssa(dest));
          nir_instr_remove(&alu_instr->instr);