From f1b941aaecd555c0455ba5a6a41d70482519c63b Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 23 May 2024 10:15:03 -0700 Subject: [PATCH] nir/search: Refactor is_16_bits Reviewed-by: Jordan Justen Suggested-by: Jordan Justen Part-of: --- src/compiler/nir/nir_search_helpers.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/compiler/nir/nir_search_helpers.h b/src/compiler/nir/nir_search_helpers.h index 06d88eb9dc4..c0a68ed3681 100644 --- a/src/compiler/nir/nir_search_helpers.h +++ b/src/compiler/nir/nir_search_helpers.h @@ -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, - unsigned src, unsigned num_components, - const uint8_t *swizzle) +is_16_bits_with_scale(const nir_alu_instr *instr, + unsigned src, unsigned num_components, + 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,