Jump to content
  • Advertisement
Sign in to follow this  
Narf the Mouse

"pow table"

This topic is 2633 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So recently someone mentioned a "pow table", which I gather is a way to store the results of raising numbers to a power, so you don't have to do the calculation every single time.

I am unsure as to how such a thing would work and thus, ask the forum: How does such a thing work?

Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Keep in mind that on modern pipelined CPUs, the cost of using a lookup table can involve cache misses, branch mispredictions, pipeline flushes, and any number of other issues. The net result is that lookup tables are actually often slower than direct computations. It depends on so many factors that it's hard to just say one way or the other which will perform best in your particular situation.

As always, try both, and run a profiler. You may be surprised.

Share this post


Link to post
Share on other sites

Keep in mind that on modern pipelined CPUs, the cost of using a lookup table can involve cache misses, branch mispredictions, pipeline flushes, and any number of other issues. The net result is that lookup tables are actually often slower than direct computations. It depends on so many factors that it's hard to just say one way or the other which will perform best in your particular situation.

As always, try both, and run a profiler. You may be surprised.

Heh, yep. I speed profile.

Share this post


Link to post
Share on other sites
As the other said, be very careful when you want a look up table.
Nowadays process instructions (code) are quite cheap for performance, while memory data access maybe quite expensive.

I'd used a look up table to calculate bit count in 32 bit integer, later I replace it with just calculating with longer and loop code, but then it's faster!

Share this post


Link to post
Share on other sites
Make sure you profile your actual application, not a simple test program. Issues like cache pressure are often not a factor in trivial comparison programs.

Share this post


Link to post
Share on other sites
You are aware that using a lookup table plus interpolation is less accurate right?
This change trades accuracy, for (possibly but not necessarily) a little more speed.

However, you may be actually talking about caching the results of repeated calculations rather than a typical premade lookup table. That can work, but depends heavily on how you implement it. You can use a hash table for example, or just perform a linear or binary search on the cached result. You'd have to experiment to get a good table size too. This only gains you anything if the exact same arguments to pow are used rather frequently. If they change by even a tiny amount each time then at best it wont help.

Edit: Oh wait if this is for perlin noise then you most likely do want a premade lookup table with interpolation. I'd want to be absolutely sure that I was optimising the right thing before starting on it.

Share this post


Link to post
Share on other sites
Given that the original post is talking about the pow function, I suspect you are actually pre-computing the coefficients for the fractal octaves, correct? Which can result in a significant speedup in real-world applications, according to all of my tests and benchmarks. The relatively small size of the coefficient array means that the array is likely to be in the cache during the entire time that the fractal is being generated, turning an otherwise expensive power function into a simple array index operation.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!