nir: Add functions to subtract and compare addresses
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Thu, 16 May 2019 22:11:07 +0000 (15:11 -0700)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Mon, 3 Jun 2019 20:45:09 +0000 (13:45 -0700)
v2: Fix comparing addresses from formats that have more than one
    component by using nir_ball_iequal().  (Jason)

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir.h
src/compiler/nir/nir_lower_io.c

index a1bd9b954cf74ef0592704877d8c0b74bf8748e4..632cf06c32c36e645689b0b9f2fac83bdee57ecd 100644 (file)
@@ -3198,6 +3198,12 @@ nir_address_format_to_glsl_type(nir_address_format addr_format)
 
 const nir_const_value *nir_address_format_null_value(nir_address_format addr_format);
 
+nir_ssa_def *nir_build_addr_ieq(struct nir_builder *b, nir_ssa_def *addr0, nir_ssa_def *addr1,
+                                nir_address_format addr_format);
+
+nir_ssa_def *nir_build_addr_isub(struct nir_builder *b, nir_ssa_def *addr0, nir_ssa_def *addr1,
+                                 nir_address_format addr_format);
+
 nir_ssa_def * nir_explicit_io_address_from_deref(struct nir_builder *b,
                                                  nir_deref_instr *deref,
                                                  nir_ssa_def *base_addr,
index b0197399bdf6f060f6751ca637b42ce0b5111244..c54303b271ef42019a05a551216ef38c1f9c89f9 100644 (file)
@@ -1258,3 +1258,51 @@ nir_address_format_null_value(nir_address_format addr_format)
    assert(addr_format < ARRAY_SIZE(null_values));
    return null_values[addr_format];
 }
+
+nir_ssa_def *
+nir_build_addr_ieq(nir_builder *b, nir_ssa_def *addr0, nir_ssa_def *addr1,
+                   nir_address_format addr_format)
+{
+   switch (addr_format) {
+   case nir_address_format_32bit_global:
+   case nir_address_format_64bit_global:
+   case nir_address_format_64bit_bounded_global:
+   case nir_address_format_32bit_index_offset:
+   case nir_address_format_32bit_offset:
+      return nir_ball_iequal(b, addr0, addr1);
+
+   case nir_address_format_logical:
+      unreachable("Unsupported address format");
+   }
+
+   unreachable("Invalid address format");
+}
+
+nir_ssa_def *
+nir_build_addr_isub(nir_builder *b, nir_ssa_def *addr0, nir_ssa_def *addr1,
+                    nir_address_format addr_format)
+{
+   switch (addr_format) {
+   case nir_address_format_32bit_global:
+   case nir_address_format_64bit_global:
+   case nir_address_format_32bit_offset:
+      assert(addr0->num_components == 1);
+      assert(addr1->num_components == 1);
+      return nir_isub(b, addr0, addr1);
+
+   case nir_address_format_64bit_bounded_global:
+      return nir_isub(b, addr_to_global(b, addr0, addr_format),
+                         addr_to_global(b, addr1, addr_format));
+
+   case nir_address_format_32bit_index_offset:
+      assert(addr0->num_components == 2);
+      assert(addr1->num_components == 2);
+      /* Assume the same buffer index. */
+      return nir_isub(b, nir_channel(b, addr0, 1), nir_channel(b, addr1, 1));
+
+   case nir_address_format_logical:
+      unreachable("Unsupported address format");
+   }
+
+   unreachable("Invalid address format");
+}