nir/search: Refactor is_16_bits

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Suggested-by: Jordan Justen <jordan.l.justen@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29148>
This commit is contained in:
Ian Romanick
2024-05-23 10:15:03 -07:00
parent 6e53be2a0a
commit f1b941aaec

View File

@@ -345,11 +345,14 @@ is_first_5_bits_uge_2(UNUSED struct hash_table *ht, const nir_alu_instr *instr,
return true;
}
/** Is this a constant that could be either int16_t or uint16_t? */
/**
* Is this a constant that could be either int16_t or uint16_t after applying
* a scale factor?
*/
static inline bool
is_16_bits(UNUSED struct hash_table *ht, const nir_alu_instr *instr,
is_16_bits_with_scale(const nir_alu_instr *instr,
unsigned src, unsigned num_components,
const uint8_t *swizzle)
const uint8_t *swizzle, int scale)
{
/* only constant srcs: */
if (!nir_src_is_const(instr->src[src].src))
@@ -361,7 +364,7 @@ is_16_bits(UNUSED struct hash_table *ht, const nir_alu_instr *instr,
for (unsigned i = 0; i < num_components; i++) {
const int64_t val =
nir_src_comp_as_int(instr->src[src].src, swizzle[i]);
scale * nir_src_comp_as_int(instr->src[src].src, swizzle[i]);
if (val > 0xffff || val < -0x8000)
return false;
@@ -384,6 +387,15 @@ is_16_bits(UNUSED struct hash_table *ht, const nir_alu_instr *instr,
return true;
}
/** Is this a constant that could be either int16_t or uint16_t? */
static inline bool
is_16_bits(UNUSED struct hash_table *ht, const nir_alu_instr *instr,
unsigned src, unsigned num_components,
const uint8_t *swizzle)
{
return is_16_bits_with_scale(instr, src, num_components, swizzle, 1);
}
static inline bool
is_not_const(UNUSED struct hash_table *ht, const nir_alu_instr *instr,
unsigned src, UNUSED unsigned num_components,