Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

apocalexiz

another speed question (sin/cos)

This topic is 5656 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

hi and here is my question: is it really faster if i make a sin/cos table instead of calculatig the values? if yes why? bye apo

Share this post


Link to post
Share on other sites
Advertisement
It may or may not be. Caching can have a large and effect on lookup table performance, and caching isn''t always predictable.

Premature optimization is the root of all evil. Make your program with plain sin/cos first, find out if it''s too slow, find out if it''s sin/cos that''s causing the bottleneck, and if so fix it.

Share this post


Link to post
Share on other sites
Depending on how accurate you need your values you can gain a hugh speed increase. Just -calling- sin can be slower than getting the result from a table. I personally use wrads (65536 degrees per circle) and create a float look-up array for each value. For games like I write this is fine.

Mark
Cornutopia Games
http://www.cornutopia.net
Bytten Independent Games Magazine
http://www.bytten.com

Share this post


Link to post
Share on other sites
A 256 KB (if I understand you correctly) lookup table is exactly the kind of thing to avoid - you''re trashing your cache.

1) sin and cos can be had for 100-200 clocks (for both), which is less expensive than constant page misses
2) if your app can tolerate quantizing down to (say) 1024 units per circle, I''d use a LUT
3) try approximating the function yourself.

Share this post


Link to post
Share on other sites
BTW: if you need sin and cos of the same angle use something like:
[source}
static inline void SinCos(float in_angle, float &out_sin, float &out_cos)
{
__asm {
fld in_angle
fsincos
mov edi, out_cos
fstp dword ptr [edi]
mov edi, out_sin
fstp dword ptr [edi]
}
}

static inline void SinCos(double in_angle, double &out_sin, double &out_cos)
{
__asm {
fld in_angle
fsincos
mov edi, out_cos
fstp qword ptr [edi]
mov edi, out_sin
fstp qword ptr [edi]
}
}
[/source]

This is faster than calling sin and cos.

- Andre

Share this post


Link to post
Share on other sites
Calculating several terms of the taylor series can give a fast approximation, but you''d be better off looking for something else to optimise.

Share this post


Link to post
Share on other sites
quote:
Original post by apocalexiz
hmm...working with the fpu right? the angle argument should be RAD? or?



yes, radians

- Andre

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!