summaryrefslogtreecommitdiffstats
path: root/src/mesa/tnl/t_vb_vertex.c
diff options
context:
space:
mode:
authorMathias Fröhlich <[email protected]>2016-05-22 14:10:19 +0200
committerMathias Fröhlich <[email protected]>2016-06-16 05:50:54 +0200
commitdc9e604ef16ee19cf7480325100e6edd768dbb16 (patch)
tree40052cf394cb694710869b8003fc04c8ced48837 /src/mesa/tnl/t_vb_vertex.c
parentd8a3ac90df67ab1b397b59acdaf4f8e5dc27203a (diff)
mesa: Use bitmask/ffs to iterate enabled clip planes.
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 <[email protected]> Signed-off-by: Mathias Fröhlich <[email protected]>
Diffstat (limited to 'src/mesa/tnl/t_vb_vertex.c')
-rw-r--r--src/mesa/tnl/t_vb_vertex.c59
1 files changed, 30 insertions, 29 deletions
diff --git a/src/mesa/tnl/t_vb_vertex.c b/src/mesa/tnl/t_vb_vertex.c
index b56d6803c99..71a32b49528 100644
--- a/src/mesa/tnl/t_vb_vertex.c
+++ b/src/mesa/tnl/t_vb_vertex.c
@@ -33,6 +33,8 @@
#include "math/m_xform.h"
+#include "util/bitscan.h"
+
#include "t_context.h"
#include "t_pipeline.h"
@@ -63,40 +65,39 @@ static void NAME( struct gl_context *ctx, \
GLubyte *clipormask, \
GLubyte *clipandmask ) \
{ \
- GLuint p; \
- \
- for (p = 0; p < ctx->Const.MaxClipPlanes; p++) \
- if (ctx->Transform.ClipPlanesEnabled & (1 << p)) { \
- GLuint nr, i; \
- const GLfloat a = ctx->Transform._ClipUserPlane[p][0]; \
- const GLfloat b = ctx->Transform._ClipUserPlane[p][1]; \
- const GLfloat c = ctx->Transform._ClipUserPlane[p][2]; \
- const GLfloat d = ctx->Transform._ClipUserPlane[p][3]; \
- GLfloat *coord = (GLfloat *)clip->data; \
- GLuint stride = clip->stride; \
- GLuint count = clip->count; \
+ GLbitfield mask = ctx->Transform.ClipPlanesEnabled; \
+ while (mask) { \
+ const int p = u_bit_scan(&mask); \
+ GLuint nr, i; \
+ const GLfloat a = ctx->Transform._ClipUserPlane[p][0]; \
+ const GLfloat b = ctx->Transform._ClipUserPlane[p][1]; \
+ const GLfloat c = ctx->Transform._ClipUserPlane[p][2]; \
+ const GLfloat d = ctx->Transform._ClipUserPlane[p][3]; \
+ GLfloat *coord = (GLfloat *)clip->data; \
+ GLuint stride = clip->stride; \
+ GLuint count = clip->count; \
\
- for (nr = 0, i = 0 ; i < count ; i++) { \
- GLfloat dp = coord[0] * a + coord[1] * b; \
- if (SZ > 2) dp += coord[2] * c; \
- if (SZ > 3) dp += coord[3] * d; else dp += d; \
+ for (nr = 0, i = 0 ; i < count ; i++) { \
+ GLfloat dp = coord[0] * a + coord[1] * b; \
+ if (SZ > 2) dp += coord[2] * c; \
+ if (SZ > 3) dp += coord[3] * d; else dp += d; \
\
- if (dp < 0) { \
- nr++; \
- clipmask[i] |= CLIP_USER_BIT; \
- } \
+ if (dp < 0) { \
+ nr++; \
+ clipmask[i] |= CLIP_USER_BIT; \
+ } \
\
- STRIDE_F(coord, stride); \
- } \
+ STRIDE_F(coord, stride); \
+ } \
\
- if (nr > 0) { \
- *clipormask |= CLIP_USER_BIT; \
- if (nr == count) { \
- *clipandmask |= CLIP_USER_BIT; \
- return; \
- } \
- } \
+ if (nr > 0) { \
+ *clipormask |= CLIP_USER_BIT; \
+ if (nr == count) { \
+ *clipandmask |= CLIP_USER_BIT; \
+ return; \
+ } \
} \
+ } \
}