PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Need help in optimizing operator*() (asm perhaps?)

Hi!
I wrote fixed point class to fasten physics calculations for my engine. But i found out that such code

Code:

inline fixed operator * (const fixed& a, const fixed& b)
{
fixed temp;
temp.Value = (a.Value * b.Value) >> STD_FIXED_PREC; //16
return temp;
}


overflows result if Value defined as long.
Now i fixed it by using
Code:

temp.Value = ((__int64)a.Value * b.Value) >> STD_FIXED_PREC; //16

such cast, but i suspect using __int64 will slow down real-time calculations.
Can anyone suggest optimisation that allow me get rid of __int64?
Can anyone suggest optimisation that allow me get rid of __int64?
Without losing accuracy, no (shift right before the multiply wouldn't overflow but it would kill accuracy).

However, the 64-bit multiply on the ARM is not particularly slow though (about twice the cost of a 32-bit one).

How much are you using that function, and how performance critical is it?
well, it called every time i rotate a vector, soo... it being used ALOT :)
Post the assembler for the function and we can have a giggle at the compiler.