Module: Mesa
Branch: main
Commit: 2259e1e9329da8b4634473c8dba2f03b11fc56f2
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=2259e1e9329da8b4634473c8dba2f03b11fc56f2

Author: Lionel Landwerlin <[email protected]>
Date:   Tue Mar  7 13:09:43 2023 +0200

nir: reuse nir_component_mask() where it makes sense

Avoiding local bit field manipulations.

Signed-off-by: Lionel Landwerlin <[email protected]>
Reviewed-by: Kenneth Graunke <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21853>

---

 src/compiler/nir/nir_builder.c  | 4 ++--
 src/compiler/nir/nir_validate.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/compiler/nir/nir_builder.c b/src/compiler/nir/nir_builder.c
index 8a25316d65b..5db10dd974f 100644
--- a/src/compiler/nir/nir_builder.c
+++ b/src/compiler/nir/nir_builder.c
@@ -117,7 +117,7 @@ nir_builder_alu_instr_finish_and_insert(nir_builder *build, 
nir_alu_instr *instr
 
    nir_ssa_dest_init(&instr->instr, &instr->dest.dest, num_components,
                      bit_size, NULL);
-   instr->dest.write_mask = (1 << num_components) - 1;
+   instr->dest.write_mask = nir_component_mask(num_components);
 
    nir_builder_instr_insert(build, &instr->instr);
 
@@ -338,7 +338,7 @@ nir_vec_scalars(nir_builder *build, nir_ssa_scalar *comp, 
unsigned num_component
     */
    nir_ssa_dest_init(&instr->instr, &instr->dest.dest, num_components,
                      comp[0].def->bit_size, NULL);
-   instr->dest.write_mask = (1 << num_components) - 1;
+   instr->dest.write_mask = nir_component_mask(num_components);
 
    nir_builder_instr_insert(build, &instr->instr);
 
diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
index 40d78290e54..8edb1cf85fe 100644
--- a/src/compiler/nir/nir_validate.c
+++ b/src/compiler/nir/nir_validate.c
@@ -349,7 +349,7 @@ validate_alu_dest(nir_alu_instr *instr, validate_state 
*state)
     * validate that the instruction doesn't write to components not in the
     * register/SSA value
     */
-   validate_assert(state, !(dest->write_mask & ~((1 << dest_size) - 1)));
+   validate_assert(state, !(dest->write_mask & 
~nir_component_mask(dest_size)));
 
    /* validate that saturate is only ever used on instructions with
     * destinations of type float

Reply via email to