another speed question (sin/cos)
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
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.
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.
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
Mark
Cornutopia Games
http://www.cornutopia.net
Bytten Independent Games Magazine
http://www.bytten.com
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.
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.
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
[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
Calculating several terms of the taylor series can give a fast approximation, but you''d be better off looking for something else to optimise.
quote:Original post by apocalexiz
hmm...working with the fpu right? the angle argument should be RAD? or?
yes, radians
- Andre
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement