Is that on the ps2 you timed them?
On 586+ architectures,
if ''s are evil. In tight loops it can be faster to do more work if you can eliminate an
if .
Next, destroy loops if possible.
For instance:
//this((DWORD*)∠)[1] &= 0x7FFFFFFF;//can replace thisif(ang<0.0) {ang=-ang;}
|
That shaves off 6 ticks
If you have a number of values that you need to take the cosine of, make a cosine function that takes an array of doubles, takes the cosine then sticks the results back into the array.
You could try making that array of cofactors constant.
If you really want to try to out-do the math cos, get the Intel instruction set reference manual and learn x786
manualsOn my K6-3, I have your Cos function clocked at 973 ticks and math''s cos at 124. There is an opcode for cosines now (fcos), I think it was introduced with the pentium.
Magmai Kai Holmlor
- Not For Rent
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara