nir_algebraic: Add basic optimizations for umul_low and imadsh_mix16
For umul_low (al * bl), zero is returned if the low 16-bits word of either source is zero. for imadsh_mix16 (ah * bl << 16 + c), c is returned if either 'ah' or 'bl' is zero. A couple of nir_search_helpers are added: is_upper_half_zero() returns true if the highest word of all components of an integer NIR alu src are zero. is_lower_half_zero() returns true if the lowest word of all components of an integer nir alu src are zero. Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
@@ -242,4 +242,50 @@ is_used_by_non_fsat(nir_alu_instr *instr)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a NIR ALU src represents a constant integer
|
||||
* of either 32 or 64 bits, and the higher word (bit-size / 2)
|
||||
* of all its components is zero.
|
||||
*/
|
||||
static inline bool
|
||||
is_upper_half_zero(nir_alu_instr *instr, unsigned src,
|
||||
unsigned num_components, const uint8_t *swizzle)
|
||||
{
|
||||
if (nir_src_as_const_value(instr->src[src].src) == NULL)
|
||||
return false;
|
||||
|
||||
for (unsigned i = 0; i < num_components; i++) {
|
||||
unsigned half_bit_size = nir_src_bit_size(instr->src[src].src) / 2;
|
||||
uint32_t high_bits = ((1 << half_bit_size) - 1) << half_bit_size;
|
||||
if ((nir_src_comp_as_uint(instr->src[src].src,
|
||||
swizzle[i]) & high_bits) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a NIR ALU src represents a constant integer
|
||||
* of either 32 or 64 bits, and the lower word (bit-size / 2)
|
||||
* of all its components is zero.
|
||||
*/
|
||||
static inline bool
|
||||
is_lower_half_zero(nir_alu_instr *instr, unsigned src,
|
||||
unsigned num_components, const uint8_t *swizzle)
|
||||
{
|
||||
if (nir_src_as_const_value(instr->src[src].src) == NULL)
|
||||
return false;
|
||||
|
||||
for (unsigned i = 0; i < num_components; i++) {
|
||||
uint32_t low_bits =
|
||||
(1 << (nir_src_bit_size(instr->src[src].src) / 2)) - 1;
|
||||
if ((nir_src_comp_as_int(instr->src[src].src, swizzle[i]) & low_bits) != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* _NIR_SEARCH_ */
|
||||
|
Reference in New Issue
Block a user