diff options
author | Jason Ekstrand <[email protected]> | 2018-10-20 12:17:30 -0500 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2018-10-22 14:24:15 -0500 |
commit | 7bae7828aabc93bc575d637794ee4b236af62bc8 (patch) | |
tree | b14387e6c1acc42ed8ca24d26443a7fc7aad290d /src | |
parent | bca5c2c68830da8631a301b6c449810c1a8a4c3f (diff) |
nir/search: Use nir_src_is_const and friends
Reviewed-by: Bas Nieuwenhuizen <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/nir/nir_search.c | 70 |
1 files changed, 13 insertions, 57 deletions
diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c index 21fcbe7aaec..9c5cb547a70 100644 --- a/src/compiler/nir/nir_search.c +++ b/src/compiler/nir/nir_search.c @@ -181,33 +181,14 @@ match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src, case nir_search_value_constant: { nir_search_constant *const_val = nir_search_value_as_constant(value); - if (!instr->src[src].src.is_ssa) + if (!nir_src_is_const(instr->src[src].src)) return false; - if (instr->src[src].src.ssa->parent_instr->type != nir_instr_type_load_const) - return false; - - nir_load_const_instr *load = - nir_instr_as_load_const(instr->src[src].src.ssa->parent_instr); - switch (const_val->type) { case nir_type_float: for (unsigned i = 0; i < num_components; ++i) { - double val; - switch (load->def.bit_size) { - case 16: - val = _mesa_half_to_float(load->value.u16[new_swizzle[i]]); - break; - case 32: - val = load->value.f32[new_swizzle[i]]; - break; - case 64: - val = load->value.f64[new_swizzle[i]]; - break; - default: - unreachable("unknown bit size"); - } - + double val = nir_src_comp_as_float(instr->src[src].src, + new_swizzle[i]); if (val != const_val->data.d) return false; } @@ -215,42 +196,17 @@ match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src, case nir_type_int: case nir_type_uint: - case nir_type_bool32: - switch (load->def.bit_size) { - case 8: - for (unsigned i = 0; i < num_components; ++i) { - if (load->value.u8[new_swizzle[i]] != - (uint8_t)const_val->data.u) - return false; - } - return true; - - case 16: - for (unsigned i = 0; i < num_components; ++i) { - if (load->value.u16[new_swizzle[i]] != - (uint16_t)const_val->data.u) - return false; - } - return true; - - case 32: - for (unsigned i = 0; i < num_components; ++i) { - if (load->value.u32[new_swizzle[i]] != - (uint32_t)const_val->data.u) - return false; - } - return true; - - case 64: - for (unsigned i = 0; i < num_components; ++i) { - if (load->value.u64[new_swizzle[i]] != const_val->data.u) - return false; - } - return true; - - default: - unreachable("unknown bit size"); + case nir_type_bool32: { + unsigned bit_size = nir_src_bit_size(instr->src[src].src); + uint64_t mask = bit_size == 64 ? UINT64_MAX : (1ull << bit_size) - 1; + for (unsigned i = 0; i < num_components; ++i) { + uint64_t val = nir_src_comp_as_uint(instr->src[src].src, + new_swizzle[i]); + if ((val & mask) != (const_val->data.u & mask)) + return false; } + return true; + } default: unreachable("Invalid alu source type"); |