Lookup table and float to int conversion and performance

Boudewijn Rempt boud at valdyas.org
Wed Apr 21 10:35:44 CEST 2010


On Tuesday 20 April 2010, Cyrille Berger wrote:
> Hello,
> 
> Since pippin has been poking us on irc on using lookup table with floats, I
> wrote a class that do exactly that, code is in [1]. I did a few tests, and
> I get a 4 times improvement on computation of sinus, and 2.5 times
> improvement on computation of sqrt.
> 
> An other fact with floating point that have come to my attention recently
> is that conversion to integer is painfully slow, for more details see [2].
> And using a lookup table is a possible solution see [3] and [4] for what
> gegl people did. Using the floating point lookup table, I noticed 19 times
> improvement on float->uint8, and 1.22 times improvement on float->uint32.
> But more interestingly for our case is the suggestion by [2] to use the
> 'lrintf' function, which is part of the C99 standard, this function gives
> 44 times improvement on float->uint8 and 2.5 times on float->uint32, of
> course it is not totally a replacement for cast since it is a round
> function, but I think in most of our uses, it is good enough. Also
> 'lrintf' is not available under MSVC, so we will probably have to wrap it
> to be portable to Windows (most likely in KoColorSpaceMaths).

Sounds good.

> It is worth to note that there is an even faster way, but it involves
> assembly, and I am not sure the gain is worth the pain, not counting that
> it is assuming that the FPU is in a good state, which is generally the
> case, but not guaranteed.

I think that that isn't worth the pain.
 
> The conclusion I take from this is that we need to be careful in conversion
> from float to integer, check when it happen, and only do it when it is
> absolutely needed. And for 2.3, I intend to make the color spaces use
> 'lrintf', and start using the lut [1].

Cool! Feel free to commit it to the branch already :-)


-- 
Boudewijn Rempt | http://www.valdyas.org


More information about the kimageshop mailing list