[Mesa-dev] [PATCH 19/29] mesa: Use bitmask/ffs to iterate color material attributes.

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/light.c | 11 ++-
 src/mesa/tnl/t_vb_light.c | 10 ++
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c
index ad9cef1..87a06db 100644
--- a/src/mesa/main/light.c
+++ b/src/mesa/main/light.c
@@ -706,13 +706,14 @@ _mesa_update_material( struct gl_context *ctx, GLuint 
bitmask )
 void
 _mesa_update_color_material( struct gl_context *ctx, const GLfloat color[4] )
 {
-   const GLbitfield bitmask = ctx->Light._ColorMaterialBitmask;
+   GLbitfield bitmask = ctx->Light._ColorMaterialBitmask;
struct gl_material *mat = >Light.Material;
-   int i;
 
-   for (i = 0 ; i < MAT_ATTRIB_MAX ; i++) 
-  if (bitmask & (1<Attrib[i], color );
+   while (bitmask) {
+  const int i = u_bit_scan();
+
+  COPY_4FV( mat->Attrib[i], color );
+   }
 
_mesa_update_material( ctx, bitmask );
 }
diff --git a/src/mesa/tnl/t_vb_light.c b/src/mesa/tnl/t_vb_light.c
index 4342b6e..8d13712 100644
--- a/src/mesa/tnl/t_vb_light.c
+++ b/src/mesa/tnl/t_vb_light.c
@@ -233,10 +233,12 @@ prepare_materials(struct gl_context *ctx,
 * with the color pointer for each one.
 */
if (ctx->Light.ColorMaterialEnabled) {
-  const GLuint bitmask = ctx->Light._ColorMaterialBitmask;
-  for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
-if (bitmask & (1<AttribPtr[_TNL_ATTRIB_MAT_FRONT_AMBIENT + i] = 
VB->AttribPtr[_TNL_ATTRIB_COLOR0];
+  GLbitfield bitmask = ctx->Light._ColorMaterialBitmask;
+  while (bitmask) {
+ const int i = u_bit_scan();
+ VB->AttribPtr[_TNL_ATTRIB_MAT_FRONT_AMBIENT + i] =
+VB->AttribPtr[_TNL_ATTRIB_COLOR0];
+  }
}
 
/* Now, for each material attribute that's tracking vertex color, save
-- 
2.5.5

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


[Mesa-dev] [PATCH 19/29] mesa: Use bitmask/ffs to iterate color material attributes.

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/light.c | 12 +++-
 src/mesa/tnl/t_vb_light.c | 11 +++
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c
index 4773ed6..e6d71d7 100644
--- a/src/mesa/main/light.c
+++ b/src/mesa/main/light.c
@@ -711,13 +711,15 @@ _mesa_update_material( struct gl_context *ctx, GLuint 
bitmask )
 void
 _mesa_update_color_material( struct gl_context *ctx, const GLfloat color[4] )
 {
-   const GLbitfield bitmask = ctx->Light._ColorMaterialBitmask;
+   GLbitfield bitmask = ctx->Light._ColorMaterialBitmask;
struct gl_material *mat = >Light.Material;
-   int i;
 
-   for (i = 0 ; i < MAT_ATTRIB_MAX ; i++) 
-  if (bitmask & (1<Attrib[i], color );
+   while (bitmask) {
+  int i = ffs(bitmask) - 1;
+  bitmask ^= 1u << i;
+
+  COPY_4FV( mat->Attrib[i], color );
+   }
 
_mesa_update_material( ctx, bitmask );
 }
diff --git a/src/mesa/tnl/t_vb_light.c b/src/mesa/tnl/t_vb_light.c
index 0cdb925..40b95c3 100644
--- a/src/mesa/tnl/t_vb_light.c
+++ b/src/mesa/tnl/t_vb_light.c
@@ -231,10 +231,13 @@ prepare_materials(struct gl_context *ctx,
 * with the color pointer for each one.
 */
if (ctx->Light.ColorMaterialEnabled) {
-  const GLuint bitmask = ctx->Light._ColorMaterialBitmask;
-  for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
-if (bitmask & (1<AttribPtr[_TNL_ATTRIB_MAT_FRONT_AMBIENT + i] = 
VB->AttribPtr[_TNL_ATTRIB_COLOR0];
+  GLbitfield bitmask = ctx->Light._ColorMaterialBitmask;
+  while (bitmask) {
+ int i = ffs(bitmask) - 1;
+ bitmask ^= 1u << i;
+ VB->AttribPtr[_TNL_ATTRIB_MAT_FRONT_AMBIENT + i] =
+VB->AttribPtr[_TNL_ATTRIB_COLOR0];
+  }
}
 
/* Now, for each material attribute that's tracking vertex color, save
-- 
2.5.5

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