[Mesa-dev] Optimize logbase2() function

Benjamin Bellec b.bellec at gmail.com
Thu Jun 2 05:43:11 PDT 2011


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).

Regards.

Benjamin Bellec
-------------- next part --------------
A non-text attachment was scrubbed...
Name: optimize_logbase2.patch
Type: text/x-diff
Size: 931 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110602/c24ecdf2/attachment.patch>


More information about the mesa-dev mailing list