nir/builder: Add nir_umod_imm helper
Like nir_udiv_imm, we can do a similar power-of-two trick. It's also really convenient. v2: Assert reasonable bounds on the modulus (Faith). Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> [v1] Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> [v1] Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22010>
This commit is contained in:
committed by
Marge Bot
parent
cec04adcee
commit
2933af7576
@@ -882,6 +882,18 @@ nir_udiv_imm(nir_builder *build, nir_ssa_def *x, uint64_t y)
|
||||
}
|
||||
}
|
||||
|
||||
static inline nir_ssa_def *
|
||||
nir_umod_imm(nir_builder *build, nir_ssa_def *x, uint64_t y)
|
||||
{
|
||||
assert(y > 0 && y <= u_uintN_max(x->bit_size));
|
||||
|
||||
if (util_is_power_of_two_nonzero(y)) {
|
||||
return nir_iand_imm(build, x, y - 1);
|
||||
} else {
|
||||
return nir_umod(build, x, nir_imm_intN_t(build, y, x->bit_size));
|
||||
}
|
||||
}
|
||||
|
||||
static inline nir_ssa_def *
|
||||
nir_ibfe_imm(nir_builder *build, nir_ssa_def *x, uint32_t offset, uint32_t size)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user