From 9a548c27aa704236cc1d8a5d4ebf68cea9c5c99c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 12 Jan 2012 07:30:48 -0700 Subject: mesa: remove _mesa_ffs(), implement ffs() for non-GNU platforms Call ffs() and ffsll() everywhere. Define our own ffs(), ffsll() functions when the platform doesn't have them. v2: remove #ifdef _WIN32, __IBMC__, __IBMCPP_ tests inside ffs() implementation. The #else clause was recursive. Reviewed-by: Kenneth Graunke Tested-by: Alexander von Gluck --- src/mesa/drivers/dri/i965/brw_wm_emit.c | 12 ++++++------ src/mesa/drivers/dri/i965/brw_wm_fp.c | 4 ++-- src/mesa/drivers/dri/intel/intel_blit.c | 2 +- src/mesa/drivers/dri/intel/intel_clear.c | 2 +- src/mesa/main/arrayobj.c | 2 +- src/mesa/main/bitset.h | 2 +- src/mesa/main/buffers.c | 4 ++-- src/mesa/main/ff_fragment_shader.cpp | 2 +- src/mesa/main/ffvertex_prog.c | 2 +- src/mesa/main/imports.c | 15 ++++++--------- src/mesa/main/imports.h | 21 ++++++++------------- src/mesa/main/shaderapi.c | 1 + src/mesa/program/prog_print.c | 4 ++-- src/mesa/swrast/s_texture.c | 4 ++-- 14 files changed, 35 insertions(+), 42 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_wm_emit.c b/src/mesa/drivers/dri/i965/brw_wm_emit.c index 270e32142de..2647a386f4f 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_emit.c +++ b/src/mesa/drivers/dri/i965/brw_wm_emit.c @@ -766,7 +766,7 @@ void emit_dp2(struct brw_compile *p, const struct brw_reg *arg0, const struct brw_reg *arg1) { - int dst_chan = _mesa_ffs(mask & WRITEMASK_XYZW) - 1; + int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1; if (!(mask & WRITEMASK_XYZW)) return; /* Do not emit dead code */ @@ -787,7 +787,7 @@ void emit_dp3(struct brw_compile *p, const struct brw_reg *arg0, const struct brw_reg *arg1) { - int dst_chan = _mesa_ffs(mask & WRITEMASK_XYZW) - 1; + int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1; if (!(mask & WRITEMASK_XYZW)) return; /* Do not emit dead code */ @@ -809,7 +809,7 @@ void emit_dp4(struct brw_compile *p, const struct brw_reg *arg0, const struct brw_reg *arg1) { - int dst_chan = _mesa_ffs(mask & WRITEMASK_XYZW) - 1; + int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1; if (!(mask & WRITEMASK_XYZW)) return; /* Do not emit dead code */ @@ -832,7 +832,7 @@ void emit_dph(struct brw_compile *p, const struct brw_reg *arg0, const struct brw_reg *arg1) { - const int dst_chan = _mesa_ffs(mask & WRITEMASK_XYZW) - 1; + const int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1; if (!(mask & WRITEMASK_XYZW)) return; /* Do not emit dead code */ @@ -882,7 +882,7 @@ void emit_math1(struct brw_wm_compile *c, { struct brw_compile *p = &c->func; struct intel_context *intel = &p->brw->intel; - int dst_chan = _mesa_ffs(mask & WRITEMASK_XYZW) - 1; + int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1; GLuint saturate = ((mask & SATURATE) ? BRW_MATH_SATURATE_SATURATE : BRW_MATH_SATURATE_NONE); @@ -945,7 +945,7 @@ void emit_math2(struct brw_wm_compile *c, { struct brw_compile *p = &c->func; struct intel_context *intel = &p->brw->intel; - int dst_chan = _mesa_ffs(mask & WRITEMASK_XYZW) - 1; + int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1; if (!(mask & WRITEMASK_XYZW)) return; /* Do not emit dead code */ diff --git a/src/mesa/drivers/dri/i965/brw_wm_fp.c b/src/mesa/drivers/dri/i965/brw_wm_fp.c index 1358e749558..b40c501257b 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_fp.c +++ b/src/mesa/drivers/dri/i965/brw_wm_fp.c @@ -159,7 +159,7 @@ static struct prog_dst_register dst_undef( void ) static struct prog_dst_register get_temp( struct brw_wm_compile *c ) { - int bit = _mesa_ffs( ~c->fp_temp ); + int bit = ffs( ~c->fp_temp ); if (!bit) { printf("%s: out of temporaries\n", __FILE__); @@ -260,7 +260,7 @@ static struct prog_instruction *emit_scalar_insn(struct brw_wm_compile *c, if (inst0->DstReg.WriteMask == 0) return NULL; - dst_chan = _mesa_ffs(inst0->DstReg.WriteMask) - 1; + dst_chan = ffs(inst0->DstReg.WriteMask) - 1; inst = get_fp_inst(c); *inst = *inst0; inst->DstReg.WriteMask = 1 << dst_chan; diff --git a/src/mesa/drivers/dri/intel/intel_blit.c b/src/mesa/drivers/dri/intel/intel_blit.c index 1369e63ba55..e484fd34bfd 100644 --- a/src/mesa/drivers/dri/intel/intel_blit.c +++ b/src/mesa/drivers/dri/intel/intel_blit.c @@ -261,7 +261,7 @@ intelClearWithBlit(struct gl_context *ctx, GLbitfield mask) /* Loop over all renderbuffers */ mask &= (1 << BUFFER_COUNT) - 1; while (mask) { - GLuint buf = _mesa_ffs(mask) - 1; + GLuint buf = ffs(mask) - 1; bool is_depth_stencil = buf == BUFFER_DEPTH || buf == BUFFER_STENCIL; struct intel_renderbuffer *irb; int x1, y1, x2, y2; diff --git a/src/mesa/drivers/dri/intel/intel_clear.c b/src/mesa/drivers/dri/intel/intel_clear.c index e60fa662566..dee4956d9d4 100644 --- a/src/mesa/drivers/dri/intel/intel_clear.c +++ b/src/mesa/drivers/dri/intel/intel_clear.c @@ -171,7 +171,7 @@ intelClear(struct gl_context *ctx, GLbitfield mask) * buffer with it. */ if (mask & (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL)) { - int color_bit = _mesa_ffs(mask & BUFFER_BITS_COLOR); + int color_bit = ffs(mask & BUFFER_BITS_COLOR); if (color_bit != 0) { tri_mask |= blit_mask & (1 << (color_bit - 1)); blit_mask &= ~(1 << (color_bit - 1)); diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c index 4b3e07b8517..29bfed8f51e 100644 --- a/src/mesa/main/arrayobj.c +++ b/src/mesa/main/arrayobj.c @@ -303,7 +303,7 @@ _mesa_update_array_object_max_element(struct gl_context *ctx, GLuint min = ~0u; while (enabled) { - GLint attrib = _mesa_ffsll(enabled) - 1; + GLint attrib = ffsll(enabled) - 1; enabled &= ~BITFIELD64_BIT(attrib); min = update_min(min, &arrayObj->VertexAttrib[attrib]); } diff --git a/src/mesa/main/bitset.h b/src/mesa/main/bitset.h index c27b4c474e0..28b3c127e75 100644 --- a/src/mesa/main/bitset.h +++ b/src/mesa/main/bitset.h @@ -88,7 +88,7 @@ __bitset_ffs(const BITSET_WORD *x, int n) for (i = 0; i < n; i++) { if (x[i]) - return _mesa_ffs(x[i]) + BITSET_WORDBITS * i; + return ffs(x[i]) + BITSET_WORDBITS * i; } return 0; diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c index adea0f5f78e..46c785fc4dc 100644 --- a/src/mesa/main/buffers.c +++ b/src/mesa/main/buffers.c @@ -402,7 +402,7 @@ _mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers, if (n == 1) { GLuint count = 0, destMask0 = destMask[0]; while (destMask0) { - GLint bufIndex = _mesa_ffs(destMask0) - 1; + GLint bufIndex = ffs(destMask0) - 1; if (fb->_ColorDrawBufferIndexes[count] != bufIndex) { updated_drawbuffers(ctx); fb->_ColorDrawBufferIndexes[count] = bufIndex; @@ -417,7 +417,7 @@ _mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers, GLuint count = 0; for (buf = 0; buf < n; buf++ ) { if (destMask[buf]) { - GLint bufIndex = _mesa_ffs(destMask[buf]) - 1; + GLint bufIndex = ffs(destMask[buf]) - 1; /* only one bit should be set in the destMask[buf] field */ ASSERT(_mesa_bitcount(destMask[buf]) == 1); if (fb->_ColorDrawBufferIndexes[buf] != bufIndex) { diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp index 3596a3d3e0c..7b8d1fe9b50 100644 --- a/src/mesa/main/ff_fragment_shader.cpp +++ b/src/mesa/main/ff_fragment_shader.cpp @@ -295,7 +295,7 @@ need_saturate( GLuint mode ) static GLuint translate_tex_src_bit( GLbitfield bit ) { ASSERT(bit); - return _mesa_ffs(bit) - 1; + return ffs(bit) - 1; } diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c index 19d319a56fe..f1ab7533395 100644 --- a/src/mesa/main/ffvertex_prog.c +++ b/src/mesa/main/ffvertex_prog.c @@ -378,7 +378,7 @@ static struct ureg swizzle1( struct ureg reg, int x ) static struct ureg get_temp( struct tnl_program *p ) { - int bit = _mesa_ffs( ~p->temp_in_use ); + int bit = ffs( ~p->temp_in_use ); if (!bit) { _mesa_problem(NULL, "%s: out of temporaries\n", __FILE__); exit(1); diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index 2469e426595..bbc6ac6e240 100644 --- a/src/mesa/main/imports.c +++ b/src/mesa/main/imports.c @@ -458,9 +458,8 @@ _mesa_inv_sqrtf(float n) * Find the first bit set in a word. */ int -_mesa_ffs(int32_t i) +ffs(int i) { -#if (defined(_WIN32) ) || defined(__IBMC__) || defined(__IBMCPP__) register int bit = 0; if (i != 0) { if ((i & 0xffff) == 0) { @@ -482,9 +481,6 @@ _mesa_ffs(int32_t i) bit++; } return bit; -#else - return ffs(i); -#endif } @@ -495,23 +491,24 @@ _mesa_ffs(int32_t i) * if no bits set. */ int -_mesa_ffsll(int64_t val) +ffsll(long long int val) { int bit; assert(sizeof(val) == 8); - bit = _mesa_ffs((int32_t)val); + bit = ffs((int) val); if (bit != 0) return bit; - bit = _mesa_ffs((int32_t)(val >> 32)); + bit = ffs((int) (val >> 32)); if (bit != 0) return 32 + bit; return 0; } -#endif +#endif /* __GNUC__ */ + #if !defined(__GNUC__) ||\ ((__GNUC__ * 100 + __GNUC_MINOR__) < 304) /* Not gcc 3.4 or later */ diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h index b7e87439f4c..bcf125ada76 100644 --- a/src/mesa/main/imports.h +++ b/src/mesa/main/imports.h @@ -573,10 +573,15 @@ _mesa_init_sqrt_table(void); #define ffsll __builtin_ffsll #endif -#define _mesa_ffs(i) ffs(i) -#define _mesa_ffsll(i) ffsll(i) +#else + +extern int ffs(int i); +extern int ffsll(long long int i); + +#endif /*__ GNUC__ */ -#if ((__GNUC__ * 100 + __GNUC_MINOR__) >= 304) /* gcc 3.4 or later */ + +#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 304) /* gcc 3.4 or later */ #define _mesa_bitcount(i) __builtin_popcount(i) #define _mesa_bitcount_64(i) __builtin_popcountll(i) #else @@ -586,16 +591,6 @@ extern unsigned int _mesa_bitcount_64(uint64_t n); #endif -#else -extern int -_mesa_ffs(int32_t i); - -extern int -_mesa_ffsll(int64_t i); - -extern unsigned int -_mesa_bitcount(unsigned int n); -#endif extern GLhalfARB _mesa_float_to_half(float f); diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index 8b68ebf9c87..0e655a0d8ef 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -928,6 +928,7 @@ _mesa_use_program(struct gl_context *ctx, struct gl_shader_program *shProg) ctx->Driver.UseProgram(ctx, shProg); } + /** * Do validation of the given shader program. * \param errMsg returns error message if validation fails. diff --git a/src/mesa/program/prog_print.c b/src/mesa/program/prog_print.c index 352a80f2718..46f1df0fcd7 100644 --- a/src/mesa/program/prog_print.c +++ b/src/mesa/program/prog_print.c @@ -194,7 +194,7 @@ _mesa_print_vp_inputs(GLbitfield inputs) { printf("VP Inputs 0x%x: \n", inputs); while (inputs) { - GLint attr = _mesa_ffs(inputs) - 1; + GLint attr = ffs(inputs) - 1; const char *name = arb_input_attrib_string(attr, GL_VERTEX_PROGRAM_ARB); printf(" %d: %s\n", attr, name); @@ -212,7 +212,7 @@ _mesa_print_fp_inputs(GLbitfield inputs) { printf("FP Inputs 0x%x: \n", inputs); while (inputs) { - GLint attr = _mesa_ffs(inputs) - 1; + GLint attr = ffs(inputs) - 1; const char *name = arb_input_attrib_string(attr, GL_FRAGMENT_PROGRAM_ARB); printf(" %d: %s\n", attr, name); diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c index ffd78a2b895..337a52f32a0 100644 --- a/src/mesa/swrast/s_texture.c +++ b/src/mesa/swrast/s_texture.c @@ -285,7 +285,7 @@ _swrast_map_textures(struct gl_context *ctx) /* loop over enabled texture units */ while (enabledUnits) { - GLuint unit = _mesa_ffs(enabledUnits) - 1; + GLuint unit = ffs(enabledUnits) - 1; struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current; _swrast_map_texture(ctx, texObj); @@ -305,7 +305,7 @@ _swrast_unmap_textures(struct gl_context *ctx) /* loop over enabled texture units */ while (enabledUnits) { - GLuint unit = _mesa_ffs(enabledUnits) - 1; + GLuint unit = ffs(enabledUnits) - 1; struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current; _swrast_unmap_texture(ctx, texObj); -- cgit v1.2.3