[Mesa-dev] [PATCH 27/29] mesa: Use bitmask/ffs to iterate the active_samplers bitmask.

2016-06-13 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Replaces an iterate and test bit in a bitmask loop by a
loop only iterating over the bits set in the bitmask.

v2: Use _mesa_bit_scan{,64} instead of open coding.
v3: Use u_bit_scan{,64} instead of _mesa_bit_scan{,64}.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/uniform_query.cpp | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index eea611b..127f097 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -36,6 +36,7 @@
 #include "compiler/glsl/glsl_parser_extras.h"
 #include "compiler/glsl/program.h"
 #include "program/hash_table.h"
+#include "util/bitscan.h"
 
 
 extern "C" void GLAPIENTRY
@@ -843,9 +844,10 @@ _mesa_uniform(struct gl_context *ctx, struct 
gl_shader_program *shProg,
  * been modified.
  */
 bool changed = false;
-for (unsigned j = 0; j < ARRAY_SIZE(prog->SamplerUnits); j++) {
-   if ((sh->active_samplers & (1U << j)) != 0
-   && (prog->SamplerUnits[j] != sh->SamplerUnits[j])) {
+GLbitfield mask = sh->active_samplers;
+while (mask) {
+   const int j = u_bit_scan();
+   if (prog->SamplerUnits[j] != sh->SamplerUnits[j]) {
   changed = true;
   break;
}
-- 
2.5.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 27/29] mesa: Use bitmask/ffs to iterate the active_samplers bitmask.

2016-05-24 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Replaces an iterate and test bit in a bitmask loop by a
loop only iterating over the bits set in the bitmask.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/uniform_query.cpp | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index 997b0cb..7a09950 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -843,9 +843,11 @@ _mesa_uniform(struct gl_context *ctx, struct 
gl_shader_program *shProg,
  * been modified.
  */
 bool changed = false;
-for (unsigned j = 0; j < ARRAY_SIZE(prog->SamplerUnits); j++) {
-   if ((sh->active_samplers & (1U << j)) != 0
-   && (prog->SamplerUnits[j] != sh->SamplerUnits[j])) {
+GLbitfield mask = sh->active_samplers;
+while (mask) {
+   int j = ffs(mask) - 1;
+   mask ^= (1u << j);
+   if (prog->SamplerUnits[j] != sh->SamplerUnits[j]) {
   changed = true;
   break;
}
-- 
2.5.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev