mesa: Use bitmask/ffs to iterate the active_samplers bitmask.
authorMathias Fröhlich <mathias.froehlich@web.de>
Sun, 22 May 2016 12:10:19 +0000 (14:10 +0200)
committerMathias Fröhlich <mathias.froehlich@web.de>
Thu, 16 Jun 2016 03:50:55 +0000 (05:50 +0200)
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 <brianp@vmware.com>
Signed-off-by: Mathias Fröhlich <Mathias.Froehlich@web.de>
src/mesa/main/uniform_query.cpp

index eea611b79544d4e17ad1583cc1e7fb3af0c8833f..127f097fe1f45430a8823463ca802898411a1b51 100644 (file)
@@ -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(&mask);
+           if (prog->SamplerUnits[j] != sh->SamplerUnits[j]) {
               changed = true;
               break;
            }