[Mesa-dev] Optimize logbase2() function

Brian Paul brianp at vmware.com
Thu Jun 2 07:26:02 PDT 2011


On 06/02/2011 06:43 AM, Benjamin Bellec wrote:
> Hello,
>
> I performed several tests of the logbase2() function.
> This function is defined and used in these files:
>
> src/mesa/main/teximage.c
> src/mesa/drivers/dri/intel/intel_tex_image.c
> src/mesa/drivers/dri/unichrome/via_tex.c
> src/mesa/drivers/dri/i965/intel_tex_image.c
> src/mesa/drivers/dri/tdfx/tdfx_tex.c
>
> There is also a util_logbase2() function in
> src/gallium/auxiliary/util/u_math.c which do the same thing.
>
> Both functions from "src/mesa/main/teximage.c" and
> "src/gallium/auxiliary/util/u_math.c" are called when I play to ETQW
> with r600g.
>
> First thing: is it possible to merge this function in one place? The
> same function is implement in different place. I have no sufficient
> experience of the Mesa architecture to answer this myself.
>
> Second thing: there is a C implementation in Wikipedia (
> http://en.wikipedia.org/wiki/Binary_logarithm#Algorithm ), I merged it
> in Mesa and I noted that it is *at least* twice faster than logbase2()
> and util_logbase2() (with or without GCC optimization).
>
> Third thing: I think it's better to use an unsigned int than a int for
> the logbase2's parameter. At least in "teximage.c" and
> "intel_tex_image.c", the result is stored in a GLuint. But not in
> "via_tex.c"
>
> Here is a patch to merge it, at least in "src/mesa/main/teximage.c". I
> will understand any comments, especially on the relevance of this patch.
> (The patch still uses a integer parameter).

Thanks for the patch.

AFAIK, the logbase2() function isn't called from any hot-spot code so 
the performance of it isn't critical.  But who knows if that might 
change in the future.

I'll commit the patch in a bit.

There is some duplication of utility code between Mesa and Gallium. 
At some point we'll probably start consolidating it.

-Brian


More information about the mesa-dev mailing list