From ca164ab49513101096788d38a4ba09cc64ba0268 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Thu, 16 May 2019 15:11:07 -0700 Subject: [PATCH] nir: Add functions to subtract and compare addresses v2: Fix comparing addresses from formats that have more than one component by using nir_ball_iequal(). (Jason) Reviewed-by: Jason Ekstrand --- src/compiler/nir/nir.h | 6 +++++ src/compiler/nir/nir_lower_io.c | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index a1bd9b954cf..632cf06c32c 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -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, diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index b0197399bdf..c54303b271e 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -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"); +} -- 2.30.2