Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualSimonForsman

Posted 19 February 2013 - 02:08 PM


Naturally, because my game is largely physics based, I felt the necessity to design a lookup table for my trig functions.

Why did you feel "the necessity" ?

Twenty or so years ago, when floating point was slow and memory access speeds were not a bottleneck, back then it made sense. On hardware that has software floating point, such as handhelds and certain older consoles, it can also make sense. But on most modern development they are the exception, not the rule.

On a modern desktop CPU --- any x86 processor since about 1997 or so --- the CPU operations are much faster and more accurate than a memory lookup.


On any x86 processor the CPU fails to meet Javas accuracy requirements for trig functions (Allthough the new intel CPUs(not sure if its just IA64 though) does have more accurate trig functions available, not sure if the JVM can use those yet though) so Java will perform a software argument reduction(possibly using fixed point arithmetics) for you before calling the native trig functions, this can get significantly more expensive(for large arguments) than a table lookup.

Allthough with a lookuptable you have to perform argument reduction in software anyway so unless your lookuptable fits in cache it should pretty much always be faster to do a quick and dirty argument reduction yourself and the cost to precision will be smaller.

if you don't need high accuracy the fastest method in java(on x86, normal trig is really fast on ARM, Sparc, etc) is most likely to use an aproximation function.

#3SimonForsman

Posted 19 February 2013 - 02:04 PM


Naturally, because my game is largely physics based, I felt the necessity to design a lookup table for my trig functions.

Why did you feel "the necessity" ?

Twenty or so years ago, when floating point was slow and memory access speeds were not a bottleneck, back then it made sense. On hardware that has software floating point, such as handhelds and certain older consoles, it can also make sense. But on most modern development they are the exception, not the rule.

On a modern desktop CPU --- any x86 processor since about 1997 or so --- the CPU operations are much faster and more accurate than a memory lookup.


On any x86 processor the CPU fails to meet Javas accuracy requirements for trig functions (Allthough the new intel CPUs does have more accurate trig functions available, not sure if the JVM can use those yet though) so Java will perform a software argument reduction(possibly using fixed point arithmetics) for you before calling the native trig functions, this can get significantly more expensive(for large arguments) than a table lookup.

Allthough with a lookuptable you have to perform argument reduction in software anyway so unless your lookuptable fits in cache it should pretty much always be faster to do a quick and dirty argument reduction yourself and the cost to precision will be smaller.

if you don't need high accuracy the fastest method in java(on x86, normal trig is really fast on ARM, Sparc, etc) is most likely to use an aproximation function.

#2SimonForsman

Posted 19 February 2013 - 01:20 PM


Naturally, because my game is largely physics based, I felt the necessity to design a lookup table for my trig functions.

Why did you feel "the necessity" ?

Twenty or so years ago, when floating point was slow and memory access speeds were not a bottleneck, back then it made sense. On hardware that has software floating point, such as handhelds and certain older consoles, it can also make sense. But on most modern development they are the exception, not the rule.

On a modern desktop CPU --- any x86 processor since about 1997 or so --- the CPU operations are much faster and more accurate than a memory lookup.


On any x86 processor the CPU fails to meet Javas accuracy requirements for trig functions (Allthough the new intel CPUs does have more accurate trig functions available, not sure if the JVM can use those yet though) so Java will perform a software argument reduction(possibly using fixed point arithmetics) for you before calling the native trig functions, this can get significantly more expensive(for large arguments) than a table lookup.

Allthough with a lookuptable you have to perform argument reduction in software anyway so unless your lookuptable fits in cache it should pretty much always be faster to do a quick and dirty argument reduction yourself and the cost to precision will be smaller.

if you don't need high accuracy the fastest method in java is most likely to use an aproximation function.

#1SimonForsman

Posted 19 February 2013 - 01:19 PM


Naturally, because my game is largely physics based, I felt the necessity to design a lookup table for my trig functions.

Why did you feel "the necessity" ?

Twenty or so years ago, when floating point was slow and memory access speeds were not a bottleneck, back then it made sense. On hardware that has software floating point, such as handhelds and certain older consoles, it can also make sense. But on most modern development they are the exception, not the rule.

On a modern desktop CPU --- any x86 processor since about 1997 or so --- the CPU operations are much faster and more accurate than a memory lookup.


On any x86 processor the CPU fails to meet Javas accuracy requirements for trig functions (Allthough the new intel CPUs does have more accurate trig functions available, not sure if the JVM can use those yet though) so Java will perform a software argument reduction(possibly using fixed point arithmetics) for you before calling the native trig functions, this can get significantly more expensive(for large arguments) than a table lookup.

Allthough with a lookuptable you have to perform argument reduction in software anyway so unless your lookuptable fits in cache it should pretty much always be faster to do a quick and dirty argument reduction yourself and the cost to precision will be smaller.

PARTNERS