[Mesa-dev] [PATCH 22/29] i965: Use bitmask/ffs to iterate enabled clip planes.
Mathias.Froehlich at gmx.net
Mathias.Froehlich at gmx.net
Tue May 24 06:49:05 UTC 2016
From: Mathias Fröhlich <mathias.froehlich at web.de>
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 <Mathias.Froehlich at web.de>
---
src/mesa/drivers/dri/i965/brw_curbe.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/brw_curbe.c b/src/mesa/drivers/dri/i965/brw_curbe.c
index dfb90b1..0d53242 100644
--- a/src/mesa/drivers/dri/i965/brw_curbe.c
+++ b/src/mesa/drivers/dri/i965/brw_curbe.c
@@ -84,7 +84,7 @@ static void calculate_curbe_offsets( struct brw_context *brw )
/* _NEW_TRANSFORM */
if (ctx->Transform.ClipPlanesEnabled) {
- GLuint nr_planes = 6 + _mesa_bitcount_64(ctx->Transform.ClipPlanesEnabled);
+ GLuint nr_planes = 6 + _mesa_bitcount(ctx->Transform.ClipPlanesEnabled);
nr_clip_regs = (nr_planes * 4 + 15) / 16;
}
@@ -226,7 +226,7 @@ brw_upload_constant_buffer(struct brw_context *brw)
/* clipper constants */
if (brw->curbe.clip_size) {
GLuint offset = brw->curbe.clip_start * 16;
- GLuint j;
+ GLbitfield mask;
/* If any planes are going this way, send them all this way:
*/
@@ -241,14 +241,15 @@ brw_upload_constant_buffer(struct brw_context *brw)
* clip-space:
*/
clip_planes = brw_select_clip_planes(ctx);
- for (j = 0; j < MAX_CLIP_PLANES; j++) {
- if (ctx->Transform.ClipPlanesEnabled & (1<<j)) {
- buf[offset + i * 4 + 0].f = clip_planes[j][0];
- buf[offset + i * 4 + 1].f = clip_planes[j][1];
- buf[offset + i * 4 + 2].f = clip_planes[j][2];
- buf[offset + i * 4 + 3].f = clip_planes[j][3];
- i++;
- }
+ mask = ctx->Transform.ClipPlanesEnabled;
+ while (mask) {
+ const int j = ffs(mask) - 1;
+ mask ^= (1u << j);
+ buf[offset + i * 4 + 0].f = clip_planes[j][0];
+ buf[offset + i * 4 + 1].f = clip_planes[j][1];
+ buf[offset + i * 4 + 2].f = clip_planes[j][2];
+ buf[offset + i * 4 + 3].f = clip_planes[j][3];
+ i++;
}
}
--
2.5.5
More information about the mesa-dev
mailing list