nir: add nir_[fui]gt_imm and nir_[fui]le_imm helpers
These are similar to the nir_{cmp}_imm variants we already have, except they negate the condition (apart from equality) and flip the arguments. The reason we need this, is that we don't have all comparison directions that would be required to always pass the immediate in the second argument. This allows us to create any comparison with an immediate without having to manually create the immediate value. Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com> Reviewed-by: Timur Kristóf <timur.kristof@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23460>
This commit is contained in:
@@ -750,6 +750,18 @@ nir_iadd_nuw(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
|
||||
return d;
|
||||
}
|
||||
|
||||
static inline nir_ssa_def *
|
||||
nir_fgt_imm(nir_builder *build, nir_ssa_def *src1, double src2)
|
||||
{
|
||||
return nir_flt(build, nir_imm_floatN_t(build, src2, src1->bit_size), src1);
|
||||
}
|
||||
|
||||
static inline nir_ssa_def *
|
||||
nir_fle_imm(nir_builder *build, nir_ssa_def *src1, double src2)
|
||||
{
|
||||
return nir_fge(build, nir_imm_floatN_t(build, src2, src1->bit_size), src1);
|
||||
}
|
||||
|
||||
/* Use nir_iadd(x, -y) for reversing parameter ordering */
|
||||
static inline nir_ssa_def *
|
||||
nir_isub_imm(nir_builder *build, uint64_t y, nir_ssa_def *x)
|
||||
|
@@ -183,6 +183,20 @@ nir_${name}_imm(nir_builder *build, nir_ssa_def *src1, uint64_t src2)
|
||||
}
|
||||
% endfor
|
||||
|
||||
% for prefix in ['i', 'u']:
|
||||
static inline nir_ssa_def *
|
||||
nir_${prefix}gt_imm(nir_builder *build, nir_ssa_def *src1, uint64_t src2)
|
||||
{
|
||||
return nir_${prefix}lt(build, nir_imm_intN_t(build, src2, src1->bit_size), src1);
|
||||
}
|
||||
|
||||
static inline nir_ssa_def *
|
||||
nir_${prefix}le_imm(nir_builder *build, nir_ssa_def *src1, uint64_t src2)
|
||||
{
|
||||
return nir_${prefix}ge(build, nir_imm_intN_t(build, src2, src1->bit_size), src1);
|
||||
}
|
||||
% endfor
|
||||
|
||||
#endif /* _NIR_BUILDER_OPCODES_ */"""
|
||||
|
||||
from nir_opcodes import opcodes, type_size, type_base_type
|
||||
|
Reference in New Issue
Block a user