Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: lookup tables

Hybrid View

  1. #1
    Member Regular Contributor
    Join Date
    Apr 2001
    Location
    Greece
    Posts
    496

    lookup tables

    Say I have a floating point value x taht is in the range [TINY...BIG].Now I want to take the square root of x and map it to an integer using a log scale.Of course I coudl do this:
    f=sqrt(x);
    i=(int)floor((float)MAX_VAL*((log(f)-log(TINY))/(log(BIG)-log(TINY))));
    That will take the sqrt of x and map it to an integer from 0 to MAX_VAL.That's what I'm doing now but it's slow.What I want to do is use the lookup table to do the sqrts and logs.Problem is how do I do that for the range {TINY...BIG].Does anybody know of any on-line docs about lookup tables?Thanks in advance for any help.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Sep 2000
    Location
    SWEDEN
    Posts
    718

    Re: lookup tables

    There's a LUT based sqrt function in nvidias collection of fast math routines on their dev-rel site. If the numbers you plug into the sqrt aren't very regular though, you probably won't get much of a speedup, at least on newer CPUs.

  3. #3
    Member Regular Contributor
    Join Date
    Apr 2001
    Location
    Greece
    Posts
    496

    Re: lookup tables

    I've seen a LUT based sqrt calculator(propably the same as the one you mention) but I think that the work quite differently,and for any floating point nimber.I need a way of making a table that will give me the outcome of the above function(which is an int between 0 and MAX_VAL) for a range of [1e-6...1e4].The floats in this range would have to somehow be converted to ints though to be useable as table indices.These are my main two problems.It's strange that I can't find any usefull info on it on the web.Looks like a major optimization to me.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,757

    Re: lookup tables

    Since you want to take the log of a value that you previously took the square root of, you can eliminate the square root all together since the log(sqrt(x))=.5*log(x)
    Also consider using a base two log, followed by a multiplication to get the values to the right base.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •