Archived

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

another speed question (sin/cos)

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

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