<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 29, 2014 at 1:45 PM, Roland Scheidegger <span dir="ltr"><<a href="mailto:sroland@vmware.com" target="_blank">sroland@vmware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I like the idea of the series, however gallium still uses its own<br>
definitions (by the looks of it supporting more compilers for native<br>
definitions but in some cases with worse code for the fallback)<br>
sometimes with different names (fls/util_last_bit) and sometimes with<br>
the same even (ffs and util_bitcount) which looks like it might<br>
conflict. I think it would be great if these would be unified.<br></blockquote><div><br></div><div>I'm sending out a v2 with the gallium versions removed and gallium pointing at the util/ version. Please try and build it on MSVC and let me know if anything needs to be squashed in so we don't break the build.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Roland<br>
<br>
Am 29.10.2014 um 19:27 schrieb Jason Ekstrand:<br>
<div class="HOEnZb"><div class="h5">> ---<br>
> src/gallium/state_trackers/glx/xlib/glx_api.c | 6 +-<br>
> src/gallium/state_trackers/glx/xlib/xm_api.c | 10 +-<br>
> src/mesa/drivers/common/meta.c | 3 +-<br>
> src/mesa/drivers/dri/i965/brw_blorp_blit.cpp | 4 +-<br>
> src/mesa/drivers/dri/i965/brw_curbe.c | 2 +-<br>
> src/mesa/drivers/dri/i965/brw_draw.c | 6 +-<br>
> src/mesa/drivers/dri/i965/brw_fs.cpp | 12 +--<br>
> src/mesa/drivers/dri/i965/brw_shader.cpp | 2 +-<br>
> src/mesa/drivers/dri/i965/brw_vec4.cpp | 2 +-<br>
> src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp | 2 +-<br>
> src/mesa/drivers/dri/i965/brw_wm.c | 4 +-<br>
> src/mesa/drivers/dri/i965/brw_wm_surface_state.c | 2 +-<br>
> src/mesa/drivers/x11/fakeglx.c | 6 +-<br>
> src/mesa/drivers/x11/xm_api.c | 16 +--<br>
> src/mesa/main/bitset.h | 1 +<br>
> src/mesa/main/buffers.c | 6 +-<br>
> src/mesa/main/imports.c | 88 -----------------<br>
> src/mesa/main/imports.h | 54 +---------<br>
> src/mesa/program/program_parse.y | 2 +-<br>
> src/util/Makefile.sources | 1 +<br>
> src/util/bitcount.c | 115 ++++++++++++++++++++++<br>
> src/util/bitcount.h | 94 ++++++++++++++++++<br>
> 22 files changed, 255 insertions(+), 183 deletions(-)<br>
> create mode 100644 src/util/bitcount.c<br>
> create mode 100644 src/util/bitcount.h<br>
><br>
> diff --git a/src/gallium/state_trackers/glx/xlib/glx_api.c b/src/gallium/state_trackers/glx/xlib/glx_api.c<br>
> index 976791b..9914116 100644<br>
> --- a/src/gallium/state_trackers/glx/xlib/glx_api.c<br>
> +++ b/src/gallium/state_trackers/glx/xlib/glx_api.c<br>
> @@ -402,9 +402,9 @@ get_visual( Display *dpy, int scr, unsigned int depth, int xclass )<br>
> * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.<br>
> */<br>
> if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) {<br>
> - if (_mesa_bitcount((GLuint) vis->red_mask ) <= 8 &&<br>
> - _mesa_bitcount((GLuint) vis->green_mask) <= 8 &&<br>
> - _mesa_bitcount((GLuint) vis->blue_mask ) <= 8) {<br>
> + if (util_bitcount((GLuint) vis->red_mask ) <= 8 &&<br>
> + util_bitcount((GLuint) vis->green_mask) <= 8 &&<br>
> + util_bitcount((GLuint) vis->blue_mask ) <= 8) {<br>
> return vis;<br>
> }<br>
> else {<br>
> diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c<br>
> index 1b77729..74c5637 100644<br>
> --- a/src/gallium/state_trackers/glx/xlib/xm_api.c<br>
> +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c<br>
> @@ -736,9 +736,9 @@ XMesaVisual XMesaCreateVisual( Display *display,<br>
> {<br>
> const int xclass = v->visualType;<br>
> if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) {<br>
> - red_bits = _mesa_bitcount(GET_REDMASK(v));<br>
> - green_bits = _mesa_bitcount(GET_GREENMASK(v));<br>
> - blue_bits = _mesa_bitcount(GET_BLUEMASK(v));<br>
> + red_bits = util_bitcount(GET_REDMASK(v));<br>
> + green_bits = util_bitcount(GET_GREENMASK(v));<br>
> + blue_bits = util_bitcount(GET_BLUEMASK(v));<br>
> }<br>
> else {<br>
> /* this is an approximation */<br>
> @@ -1067,8 +1067,8 @@ XMesaCreatePixmapTextureBuffer(XMesaVisual v, Pixmap p,<br>
> if (ctx->Extensions.ARB_texture_non_power_of_two) {<br>
> target = GLX_TEXTURE_2D_EXT;<br>
> }<br>
> - else if ( _mesa_bitcount(b->width) == 1<br>
> - && _mesa_bitcount(b->height) == 1) {<br>
> + else if ( util_bitcount(b->width) == 1<br>
> + && util_bitcount(b->height) == 1) {<br>
> /* power of two size */<br>
> if (b->height == 1) {<br>
> target = GLX_TEXTURE_1D_EXT;<br>
> diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c<br>
> index 87532c1..22a5b3e 100644<br>
> --- a/src/mesa/drivers/common/meta.c<br>
> +++ b/src/mesa/drivers/common/meta.c<br>
> @@ -85,6 +85,7 @@<br>
> #include "main/enums.h"<br>
> #include "main/glformats.h"<br>
> #include "util/ralloc.h"<br>
> +#include "util/bitcount.h"<br>
><br>
> /** Return offset in bytes of the field within a vertex struct */<br>
> #define OFFSET(FIELD) ((void *) offsetof(struct vertex, FIELD))<br>
> @@ -1640,7 +1641,7 @@ _mesa_meta_drawbuffers_from_bitfield(GLbitfield bits)<br>
> assert((bits & ~BUFFER_BITS_COLOR) == 0);<br>
><br>
> /* Make sure we don't overflow any arrays. */<br>
> - assert(_mesa_bitcount(bits) <= MAX_DRAW_BUFFERS);<br>
> + assert(util_bitcount(bits) <= MAX_DRAW_BUFFERS);<br>
><br>
> enums[0] = GL_NONE;<br>
><br>
> diff --git a/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp b/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp<br>
> index 844f5e4..7ccdff5 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp<br>
> +++ b/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp<br>
> @@ -1346,7 +1346,7 @@ inline int count_trailing_one_bits(unsigned value)<br>
> #ifdef HAVE___BUILTIN_CTZ<br>
> return __builtin_ctz(~value);<br>
> #else<br>
> - return _mesa_bitcount(value & ~(value + 1));<br>
> + return util_bitcount(value & ~(value + 1));<br>
> #endif<br>
> }<br>
><br>
> @@ -1388,7 +1388,7 @@ brw_blorp_blit_program::manual_blend_average(unsigned num_samples)<br>
> */<br>
> unsigned stack_depth = 0;<br>
> for (unsigned i = 0; i < num_samples; ++i) {<br>
> - assert(stack_depth == _mesa_bitcount(i)); /* Loop invariant */<br>
> + assert(stack_depth == util_bitcount(i)); /* Loop invariant */<br>
><br>
> /* Push sample i onto the stack */<br>
> assert(stack_depth < ARRAY_SIZE(texture_data));<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_curbe.c b/src/mesa/drivers/dri/i965/brw_curbe.c<br>
> index 1a828ed..46a3ccb 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_curbe.c<br>
> +++ b/src/mesa/drivers/dri/i965/brw_curbe.c<br>
> @@ -85,7 +85,7 @@ static void calculate_curbe_offsets( struct brw_context *brw )<br>
><br>
> /* _NEW_TRANSFORM */<br>
> if (ctx->Transform.ClipPlanesEnabled) {<br>
> - GLuint nr_planes = 6 + _mesa_bitcount_64(ctx->Transform.ClipPlanesEnabled);<br>
> + GLuint nr_planes = 6 + util_bitcount_64(ctx->Transform.ClipPlanesEnabled);<br>
> nr_clip_regs = (nr_planes * 4 + 15) / 16;<br>
> }<br>
><br>
> diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c<br>
> index b28eaf2..fb843e4 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_draw.c<br>
> +++ b/src/mesa/drivers/dri/i965/brw_draw.c<br>
> @@ -369,11 +369,11 @@ static bool brw_try_draw_prims( struct gl_context *ctx,<br>
> * index.<br>
> */<br>
> brw->wm.base.sampler_count =<br>
> - _mesa_fls(ctx->FragmentProgram._Current->Base.SamplersUsed);<br>
> + util_fls(ctx->FragmentProgram._Current->Base.SamplersUsed);<br>
> brw->gs.base.sampler_count = ctx->GeometryProgram._Current ?<br>
> - _mesa_fls(ctx->GeometryProgram._Current->Base.SamplersUsed) : 0;<br>
> + util_fls(ctx->GeometryProgram._Current->Base.SamplersUsed) : 0;<br>
> brw->vs.base.sampler_count =<br>
> - _mesa_fls(ctx->VertexProgram._Current->Base.SamplersUsed);<br>
> + util_fls(ctx->VertexProgram._Current->Base.SamplersUsed);<br>
><br>
> /* We have to validate the textures *before* checking for fallbacks;<br>
> * otherwise, the software fallback won't be able to rely on the<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> index aa1d8d2..1732b7f 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> @@ -1719,8 +1719,8 @@ fs_visitor::calculate_urb_setup()<br>
> int urb_next = 0;<br>
> /* Figure out where each of the incoming setup attributes lands. */<br>
> if (brw->gen >= 6) {<br>
> - if (_mesa_bitcount_64(prog->InputsRead &<br>
> - BRW_FS_VARYING_INPUT_MASK) <= 16) {<br>
> + if (util_bitcount_64(prog->InputsRead &<br>
> + BRW_FS_VARYING_INPUT_MASK) <= 16) {<br>
> /* The SF/SBE pipeline stage can do arbitrary rearrangement of the<br>
> * first 16 varying inputs, so we can put them wherever we want.<br>
> * Just put them in order.<br>
> @@ -3791,11 +3791,11 @@ brw_fs_precompile(struct gl_context *ctx, struct gl_shader_program *prog)<br>
> key.iz_lookup |= IZ_DEPTH_WRITE_ENABLE_BIT;<br>
> }<br>
><br>
> - if (brw->gen < 6 || _mesa_bitcount_64(fp->Base.InputsRead &<br>
> - BRW_FS_VARYING_INPUT_MASK) > 16)<br>
> + if (brw->gen < 6 || util_bitcount_64(fp->Base.InputsRead &<br>
> + BRW_FS_VARYING_INPUT_MASK) > 16)<br>
> key.input_slots_valid = fp->Base.InputsRead | VARYING_BIT_POS;<br>
><br>
> - unsigned sampler_count = _mesa_fls(fp->Base.SamplersUsed);<br>
> + unsigned sampler_count = util_fls(fp->Base.SamplersUsed);<br>
> for (unsigned i = 0; i < sampler_count; i++) {<br>
> if (fp->Base.ShadowSamplers & (1 << i)) {<br>
> /* Assume DEPTH_TEXTURE_MODE is the default: X, X, X, 1 */<br>
> @@ -3811,7 +3811,7 @@ brw_fs_precompile(struct gl_context *ctx, struct gl_shader_program *prog)<br>
> key.drawable_height = ctx->DrawBuffer->Height;<br>
> }<br>
><br>
> - key.nr_color_regions = _mesa_bitcount_64(fp->Base.OutputsWritten &<br>
> + key.nr_color_regions = util_bitcount_64(fp->Base.OutputsWritten &<br>
> ~(BITFIELD64_BIT(FRAG_RESULT_DEPTH) |<br>
> BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK)));<br>
><br>
> diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
> index 21dcf2d..adfe3b0 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
> +++ b/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
> @@ -864,7 +864,7 @@ backend_visitor::invalidate_cfg()<br>
> void<br>
> backend_visitor::assign_common_binding_table_offsets(uint32_t next_binding_table_offset)<br>
> {<br>
> - int num_textures = _mesa_fls(prog->SamplersUsed);<br>
> + int num_textures = util_fls(prog->SamplersUsed);<br>
><br>
> stage_prog_data->binding_table.texture_start = next_binding_table_offset;<br>
> next_binding_table_offset += num_textures;<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
> index df589b8..89f9ee0 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
> +++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
> @@ -1918,7 +1918,7 @@ brw_vec4_setup_prog_key_for_precompile(struct gl_context *ctx,<br>
> key->program_string_id = id;<br>
> key->clamp_vertex_color = ctx->API == API_OPENGL_COMPAT;<br>
><br>
> - unsigned sampler_count = _mesa_fls(prog->SamplersUsed);<br>
> + unsigned sampler_count = util_fls(prog->SamplersUsed);<br>
> for (unsigned i = 0; i < sampler_count; i++) {<br>
> if (prog->ShadowSamplers & (1 << i)) {<br>
> /* Assume DEPTH_TEXTURE_MODE is the default: X, X, X, 1 */<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp<br>
> index db0e6cc..4da02c7 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp<br>
> +++ b/src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp<br>
> @@ -368,7 +368,7 @@ vec4_gs_visitor::emit_control_data_bits()<br>
> src_reg prev_count(this, glsl_type::uint_type);<br>
> emit(ADD(dst_reg(prev_count), this->vertex_count, 0xffffffffu));<br>
> unsigned log2_bits_per_vertex =<br>
> - _mesa_fls(c->control_data_bits_per_vertex);<br>
> + util_fls(c->control_data_bits_per_vertex);<br>
> emit(SHR(dst_reg(dword_index), prev_count,<br>
> (uint32_t) (6 - log2_bits_per_vertex)));<br>
> }<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c<br>
> index 5863573..5b692ee 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_wm.c<br>
> +++ b/src/mesa/drivers/dri/i965/brw_wm.c<br>
> @@ -539,8 +539,8 @@ static void brw_wm_populate_key( struct brw_context *brw,<br>
> (fp->program.Base.SystemValuesRead & SYSTEM_BIT_SAMPLE_ID);<br>
><br>
> /* BRW_NEW_VUE_MAP_GEOM_OUT */<br>
> - if (brw->gen < 6 || _mesa_bitcount_64(fp->program.Base.InputsRead &<br>
> - BRW_FS_VARYING_INPUT_MASK) > 16)<br>
> + if (brw->gen < 6 || util_bitcount_64(fp->program.Base.InputsRead &<br>
> + BRW_FS_VARYING_INPUT_MASK) > 16)<br>
> key->input_slots_valid = brw->vue_map_geom_out.slots_valid;<br>
><br>
><br>
> diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c<br>
> index ef46dd7..4bd1087 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c<br>
> +++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c<br>
> @@ -769,7 +769,7 @@ update_stage_texture_surfaces(struct brw_context *brw,<br>
> else<br>
> surf_offset += stage_state->prog_data->binding_table.texture_start;<br>
><br>
> - unsigned num_samplers = _mesa_fls(prog->SamplersUsed);<br>
> + unsigned num_samplers = util_fls(prog->SamplersUsed);<br>
> for (unsigned s = 0; s < num_samplers; s++) {<br>
> surf_offset[s] = 0;<br>
><br>
> diff --git a/src/mesa/drivers/x11/fakeglx.c b/src/mesa/drivers/x11/fakeglx.c<br>
> index ee05f8a..b1b470a 100644<br>
> --- a/src/mesa/drivers/x11/fakeglx.c<br>
> +++ b/src/mesa/drivers/x11/fakeglx.c<br>
> @@ -528,9 +528,9 @@ get_visual( Display *dpy, int scr, unsigned int depth, int xclass )<br>
> * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.<br>
> */<br>
> if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) {<br>
> - if (_mesa_bitcount((GLuint) vis->red_mask ) <= 8 &&<br>
> - _mesa_bitcount((GLuint) vis->green_mask) <= 8 &&<br>
> - _mesa_bitcount((GLuint) vis->blue_mask ) <= 8) {<br>
> + if (util_bitcount((GLuint) vis->red_mask ) <= 8 &&<br>
> + util_bitcount((GLuint) vis->green_mask) <= 8 &&<br>
> + util_bitcount((GLuint) vis->blue_mask ) <= 8) {<br>
> return vis;<br>
> }<br>
> else {<br>
> diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c<br>
> index 2d66dbd..c85b9f6 100644<br>
> --- a/src/mesa/drivers/x11/xm_api.c<br>
> +++ b/src/mesa/drivers/x11/xm_api.c<br>
> @@ -462,9 +462,9 @@ setup_truecolor(XMesaVisual v, XMesaBuffer buffer, XMesaColormap cmap)<br>
> 3*16, 11*16, 1*16, 9*16,<br>
> 15*16, 7*16, 13*16, 5*16,<br>
> };<br>
> - GLint rBits = _mesa_bitcount(rmask);<br>
> - GLint gBits = _mesa_bitcount(gmask);<br>
> - GLint bBits = _mesa_bitcount(bmask);<br>
> + GLint rBits = util_bitcount(rmask);<br>
> + GLint gBits = util_bitcount(gmask);<br>
> + GLint bBits = util_bitcount(bmask);<br>
> GLint maxBits;<br>
> GLuint i;<br>
><br>
> @@ -827,9 +827,9 @@ XMesaVisual XMesaCreateVisual( XMesaDisplay *display,<br>
> {<br>
> const int xclass = v->visualType;<br>
> if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) {<br>
> - red_bits = _mesa_bitcount(GET_REDMASK(v));<br>
> - green_bits = _mesa_bitcount(GET_GREENMASK(v));<br>
> - blue_bits = _mesa_bitcount(GET_BLUEMASK(v));<br>
> + red_bits = util_bitcount(GET_REDMASK(v));<br>
> + green_bits = util_bitcount(GET_GREENMASK(v));<br>
> + blue_bits = util_bitcount(GET_BLUEMASK(v));<br>
> }<br>
> else {<br>
> /* this is an approximation */<br>
> @@ -1091,8 +1091,8 @@ XMesaCreatePixmapTextureBuffer(XMesaVisual v, XMesaPixmap p,<br>
> if (ctx->Extensions.ARB_texture_non_power_of_two) {<br>
> target = GLX_TEXTURE_2D_EXT;<br>
> }<br>
> - else if ( _mesa_bitcount(width) == 1<br>
> - && _mesa_bitcount(height) == 1) {<br>
> + else if ( util_bitcount(width) == 1<br>
> + && util_bitcount(height) == 1) {<br>
> /* power of two size */<br>
> if (height == 1) {<br>
> target = GLX_TEXTURE_1D_EXT;<br>
> diff --git a/src/mesa/main/bitset.h b/src/mesa/main/bitset.h<br>
> index 601fd0e..f50b14f 100644<br>
> --- a/src/mesa/main/bitset.h<br>
> +++ b/src/mesa/main/bitset.h<br>
> @@ -32,6 +32,7 @@<br>
> #define BITSET_H<br>
><br>
> #include "imports.h"<br>
> +#include "util/bitcount.h"<br>
><br>
> /****************************************************************************<br>
> * generic bitset implementation<br>
> diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c<br>
> index 1ee2009..8d50447 100644<br>
> --- a/src/mesa/main/buffers.c<br>
> +++ b/src/mesa/main/buffers.c<br>
> @@ -374,7 +374,7 @@ _mesa_DrawBuffers(GLsizei n, const GLenum *buffers)<br>
> * Previous versions of the OpenGL specification say INVALID_OPERATION,<br>
> * but the Khronos conformance tests expect INVALID_ENUM.<br>
> */<br>
> - if (_mesa_bitcount(destMask[output]) > 1) {<br>
> + if (util_bitcount(destMask[output]) > 1) {<br>
> _mesa_error(ctx, GL_INVALID_ENUM, "glDrawBuffersARB(buffer)");<br>
> return;<br>
> }<br>
> @@ -497,7 +497,7 @@ _mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers,<br>
> * (ex: glDrawBuffer(GL_FRONT_AND_BACK)).<br>
> * Otherwise, destMask[x] can only have one bit set.<br>
> */<br>
> - if (n > 0 && _mesa_bitcount(destMask[0]) > 1) {<br>
> + if (n > 0 && util_bitcount(destMask[0]) > 1) {<br>
> GLuint count = 0, destMask0 = destMask[0];<br>
> while (destMask0) {<br>
> GLint bufIndex = ffs(destMask0) - 1;<br>
> @@ -517,7 +517,7 @@ _mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers,<br>
> if (destMask[buf]) {<br>
> GLint bufIndex = ffs(destMask[buf]) - 1;<br>
> /* only one bit should be set in the destMask[buf] field */<br>
> - ASSERT(_mesa_bitcount(destMask[buf]) == 1);<br>
> + ASSERT(util_bitcount(destMask[buf]) == 1);<br>
> if (fb->_ColorDrawBufferIndexes[buf] != bufIndex) {<br>
> updated_drawbuffers(ctx);<br>
> fb->_ColorDrawBufferIndexes[buf] = bufIndex;<br>
> diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c<br>
> index b8c7548..ac4b698 100644<br>
> --- a/src/mesa/main/imports.c<br>
> +++ b/src/mesa/main/imports.c<br>
> @@ -217,94 +217,6 @@ _mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,<br>
> /*@{*/<br>
><br>
><br>
> -#ifndef HAVE___BUILTIN_FFS<br>
> -/**<br>
> - * Find the first bit set in a word.<br>
> - */<br>
> -int<br>
> -ffs(int i)<br>
> -{<br>
> - register int bit = 0;<br>
> - if (i != 0) {<br>
> - if ((i & 0xffff) == 0) {<br>
> - bit += 16;<br>
> - i >>= 16;<br>
> - }<br>
> - if ((i & 0xff) == 0) {<br>
> - bit += 8;<br>
> - i >>= 8;<br>
> - }<br>
> - if ((i & 0xf) == 0) {<br>
> - bit += 4;<br>
> - i >>= 4;<br>
> - }<br>
> - while ((i & 1) == 0) {<br>
> - bit++;<br>
> - i >>= 1;<br>
> - }<br>
> - bit++;<br>
> - }<br>
> - return bit;<br>
> -}<br>
> -#endif<br>
> -<br>
> -#ifndef HAVE___BUILTIN_FFSLL<br>
> -/**<br>
> - * Find position of first bit set in given value.<br>
> - * XXX Warning: this function can only be used on 64-bit systems!<br>
> - * \return position of least-significant bit set, starting at 1, return zero<br>
> - * if no bits set.<br>
> - */<br>
> -int<br>
> -ffsll(long long int val)<br>
> -{<br>
> - int bit;<br>
> -<br>
> - assert(sizeof(val) == 8);<br>
> -<br>
> - bit = ffs((int) val);<br>
> - if (bit != 0)<br>
> - return bit;<br>
> -<br>
> - bit = ffs((int) (val >> 32));<br>
> - if (bit != 0)<br>
> - return 32 + bit;<br>
> -<br>
> - return 0;<br>
> -}<br>
> -#endif<br>
> -<br>
> -<br>
> -#ifndef HAVE___BUILTIN_POPCOUNT<br>
> -/**<br>
> - * Return number of bits set in given GLuint.<br>
> - */<br>
> -unsigned int<br>
> -_mesa_bitcount(unsigned int n)<br>
> -{<br>
> - unsigned int bits;<br>
> - for (bits = 0; n > 0; n = n >> 1) {<br>
> - bits += (n & 1);<br>
> - }<br>
> - return bits;<br>
> -}<br>
> -#endif<br>
> -<br>
> -#ifndef HAVE___BUILTIN_POPCOUNTLL<br>
> -/**<br>
> - * Return number of bits set in given 64-bit uint.<br>
> - */<br>
> -unsigned int<br>
> -_mesa_bitcount_64(uint64_t n)<br>
> -{<br>
> - unsigned int bits;<br>
> - for (bits = 0; n > 0; n = n >> 1) {<br>
> - bits += (n & 1);<br>
> - }<br>
> - return bits;<br>
> -}<br>
> -#endif<br>
> -<br>
><br>
> /* Using C99 rounding functions for roundToEven() implementation is<br>
> * difficult, because round(), rint, and nearbyint() are affected by<br>
> diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h<br>
> index 436d165..0b03816 100644<br>
> --- a/src/mesa/main/imports.h<br>
> +++ b/src/mesa/main/imports.h<br>
> @@ -39,6 +39,7 @@<br>
> #include "compiler.h"<br>
> #include "glheader.h"<br>
> #include "errors.h"<br>
> +#include "util/bitcount.h"<br>
><br>
> #ifdef __cplusplus<br>
> extern "C" {<br>
> @@ -469,59 +470,6 @@ extern void<br>
> _mesa_exec_free( void *addr );<br>
><br>
><br>
> -#ifndef FFS_DEFINED<br>
> -#define FFS_DEFINED 1<br>
> -#ifdef HAVE___BUILTIN_FFS<br>
> -#define ffs __builtin_ffs<br>
> -#else<br>
> -extern int ffs(int i);<br>
> -#endif<br>
> -<br>
> -#ifdef HAVE___BUILTIN_FFSLL<br>
> -#define ffsll __builtin_ffsll<br>
> -#else<br>
> -extern int ffsll(long long int i);<br>
> -#endif<br>
> -#endif /* FFS_DEFINED */<br>
> -<br>
> -<br>
> -#ifdef HAVE___BUILTIN_POPCOUNT<br>
> -#define _mesa_bitcount(i) __builtin_popcount(i)<br>
> -#else<br>
> -extern unsigned int<br>
> -_mesa_bitcount(unsigned int n);<br>
> -#endif<br>
> -<br>
> -#ifdef HAVE___BUILTIN_POPCOUNTLL<br>
> -#define _mesa_bitcount_64(i) __builtin_popcountll(i)<br>
> -#else<br>
> -extern unsigned int<br>
> -_mesa_bitcount_64(uint64_t n);<br>
> -#endif<br>
> -<br>
> -/**<br>
> - * Find the last (most significant) bit set in a word.<br>
> - *<br>
> - * Essentially ffs() in the reverse direction.<br>
> - */<br>
> -static inline unsigned int<br>
> -_mesa_fls(unsigned int n)<br>
> -{<br>
> -#ifdef HAVE___BUILTIN_CLZ<br>
> - return n == 0 ? 0 : 32 - __builtin_clz(n);<br>
> -#else<br>
> - unsigned int v = 1;<br>
> -<br>
> - if (n == 0)<br>
> - return 0;<br>
> -<br>
> - while (n >>= 1)<br>
> - v++;<br>
> -<br>
> - return v;<br>
> -#endif<br>
> -}<br>
> -<br>
> extern int<br>
> _mesa_round_to_even(float val);<br>
><br>
> diff --git a/src/mesa/program/program_parse.y b/src/mesa/program/program_parse.y<br>
> index 1664740..e79c944 100644<br>
> --- a/src/mesa/program/program_parse.y<br>
> +++ b/src/mesa/program/program_parse.y<br>
> @@ -2771,7 +2771,7 @@ _mesa_parse_arb_program(struct gl_context *ctx, GLenum target, const GLubyte *st<br>
> state->prog->NumInstructions++;<br>
><br>
> state->prog->NumParameters = state->prog->Parameters->NumParameters;<br>
> - state->prog->NumAttributes = _mesa_bitcount_64(state->prog->InputsRead);<br>
> + state->prog->NumAttributes = util_bitcount_64(state->prog->InputsRead);<br>
><br>
> /*<br>
> * Initialize native counts to logical counts. The device driver may<br>
> diff --git a/src/util/Makefile.sources b/src/util/Makefile.sources<br>
> index 952b799..605c524 100644<br>
> --- a/src/util/Makefile.sources<br>
> +++ b/src/util/Makefile.sources<br>
> @@ -1,6 +1,7 @@<br>
> MESA_UTIL_FILES := \<br>
> hash_table.c \<br>
> ralloc.c \<br>
> + bitcount.c \<br>
> register_allocate.c \<br>
> register_allocate.h \<br>
> rgtc.c<br>
> diff --git a/src/util/bitcount.c b/src/util/bitcount.c<br>
> new file mode 100644<br>
> index 0000000..1e65000<br>
> --- /dev/null<br>
> +++ b/src/util/bitcount.c<br>
> @@ -0,0 +1,115 @@<br>
> +/*<br>
> + * Mesa 3-D graphics library<br>
> + *<br>
> + * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.<br>
> + * Copyright (C) 2014 Intel Corporation<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice shall be included<br>
> + * in all copies or substantial portions of the Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS<br>
> + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR<br>
> + * OTHER DEALINGS IN THE SOFTWARE.<br>
> + */<br>
> +<br>
> +#include "bitcount.h"<br>
> +<br>
> +#ifndef HAVE___BUILTIN_FFS<br>
> +/**<br>
> + * Find the first bit set in a word.<br>
> + */<br>
> +int<br>
> +ffs(int i)<br>
> +{<br>
> + register int bit = 0;<br>
> + if (i != 0) {<br>
> + if ((i & 0xffff) == 0) {<br>
> + bit += 16;<br>
> + i >>= 16;<br>
> + }<br>
> + if ((i & 0xff) == 0) {<br>
> + bit += 8;<br>
> + i >>= 8;<br>
> + }<br>
> + if ((i & 0xf) == 0) {<br>
> + bit += 4;<br>
> + i >>= 4;<br>
> + }<br>
> + while ((i & 1) == 0) {<br>
> + bit++;<br>
> + i >>= 1;<br>
> + }<br>
> + bit++;<br>
> + }<br>
> + return bit;<br>
> +}<br>
> +#endif<br>
> +<br>
> +#ifndef HAVE___BUILTIN_FFSLL<br>
> +/**<br>
> + * Find position of first bit set in given value.<br>
> + * XXX Warning: this function can only be used on 64-bit systems!<br>
> + * \return position of least-significant bit set, starting at 1, return zero<br>
> + * if no bits set.<br>
> + */<br>
> +int<br>
> +ffsll(long long int val)<br>
> +{<br>
> + int bit;<br>
> +<br>
> + assert(sizeof(val) == 8);<br>
> +<br>
> + bit = ffs((int) val);<br>
> + if (bit != 0)<br>
> + return bit;<br>
> +<br>
> + bit = ffs((int) (val >> 32));<br>
> + if (bit != 0)<br>
> + return 32 + bit;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +#endif<br>
> +<br>
> +<br>
> +#ifndef HAVE___BUILTIN_POPCOUNT<br>
> +/**<br>
> + * Return number of bits set in given GLuint.<br>
> + */<br>
> +unsigned int<br>
> +util_bitcount(unsigned int n)<br>
> +{<br>
> + unsigned int bits;<br>
> + for (bits = 0; n > 0; n = n >> 1) {<br>
> + bits += (n & 1);<br>
> + }<br>
> + return bits;<br>
> +}<br>
> +#endif<br>
> +<br>
> +#ifndef HAVE___BUILTIN_POPCOUNTLL<br>
> +/**<br>
> + * Return number of bits set in given 64-bit uint.<br>
> + */<br>
> +unsigned int<br>
> +util_bitcount_64(uint64_t n)<br>
> +{<br>
> + unsigned int bits;<br>
> + for (bits = 0; n > 0; n = n >> 1) {<br>
> + bits += (n & 1);<br>
> + }<br>
> + return bits;<br>
> +}<br>
> +#endif<br>
> +<br>
> diff --git a/src/util/bitcount.h b/src/util/bitcount.h<br>
> new file mode 100644<br>
> index 0000000..a1ab2b3<br>
> --- /dev/null<br>
> +++ b/src/util/bitcount.h<br>
> @@ -0,0 +1,94 @@<br>
> +/*<br>
> + * Mesa 3-D graphics library<br>
> + *<br>
> + * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.<br>
> + * Copyright (C) 2014 Intel Corporation<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice shall be included<br>
> + * in all copies or substantial portions of the Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS<br>
> + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR<br>
> + * OTHER DEALINGS IN THE SOFTWARE.<br>
> + */<br>
> +<br>
> +/**<br>
> + * Various utilities for counting bits.<br>
> + */<br>
> +<br>
> +#ifndef UTIL_BITCOUNT_H<br>
> +#define UTIL_BITCOUNT_H<br>
> +<br>
> +#ifdef __cplusplus<br>
> +extern "C" {<br>
> +#endif<br>
> +<br>
> +#ifndef FFS_DEFINED<br>
> +#define FFS_DEFINED 1<br>
> +#ifdef HAVE___BUILTIN_FFS<br>
> +#define ffs __builtin_ffs<br>
> +#else<br>
> +extern int ffs(int i);<br>
> +#endif<br>
> +<br>
> +#ifdef HAVE___BUILTIN_FFSLL<br>
> +#define ffsll __builtin_ffsll<br>
> +#else<br>
> +extern int ffsll(long long int i);<br>
> +#endif<br>
> +#endif /* FFS_DEFINED */<br>
> +<br>
> +<br>
> +#ifdef HAVE___BUILTIN_POPCOUNT<br>
> +#define util_bitcount(i) __builtin_popcount(i)<br>
> +#else<br>
> +extern unsigned int<br>
> +util_bitcount(unsigned int n);<br>
> +#endif<br>
> +<br>
> +#ifdef HAVE___BUILTIN_POPCOUNTLL<br>
> +#define util_bitcount_64(i) __builtin_popcountll(i)<br>
> +#else<br>
> +extern unsigned int<br>
> +util_bitcount_64(uint64_t n);<br>
> +#endif<br>
> +<br>
> +/**<br>
> + * Find the last (most significant) bit set in a word.<br>
> + *<br>
> + * Essentially ffs() in the reverse direction.<br>
> + */<br>
> +static inline unsigned int<br>
> +util_fls(unsigned int n)<br>
> +{<br>
> +#ifdef HAVE___BUILTIN_CLZ<br>
> + return n == 0 ? 0 : 32 - __builtin_clz(n);<br>
> +#else<br>
> + unsigned int v = 1;<br>
> +<br>
> + if (n == 0)<br>
> + return 0;<br>
> +<br>
> + while (n >>= 1)<br>
> + v++;<br>
> +<br>
> + return v;<br>
> +#endif<br>
> +}<br>
> +<br>
> +#ifdef __cplusplus<br>
> +} /* extern "C" */<br>
> +#endif<br>
> +<br>
> +#endif /* UTIL_BITCOUNT_H */<br>
><br>
<br>
</div></div></blockquote></div><br></div></div>