Operator speeds

Started by
2 comments, last by eNGIMa 22 years, 6 months ago
At the moment I am trying to optimise some portions of my game. Would someone be able to tell me what operators are the fastest (eg. << ) and the slowest ??? I know that a few well chosen operations in tight loops can really bog your code down
-=- Murphy was an optimist -=-
Advertisement
Addition is faster then multiplication.
If you are multiplying(or dividing) by a power of two, use bit shifting. x << 1 is the same as x * 2, x << 2 is the same as x * 4, etc. There was an article in Hugi 22 or 23 on Optimization. You can find it on cfxweb.net.

Z.
______________"Evil is Loud"
Here's the link to that article: http://www.cfxweb.net/article.php?sid=630

Here is a portion of a clock cycle chart I have as well (for the P2), I'll list the common operator stuff. The variable number of cycles are because using two registers is a lot faster than using two portions of memory.

AND 1-3
OR 1-3
XOR 1-3
NOT (register/memory) 1/3
SHR (Shift right) 1-3
SHL (Shift left) 1-3
ADD 1-3
SUB 1-3
MUL (for 32 bit integers) 10
DIV (for 32 bit integers) 41
INC (register/memory) 1/3
DEC (register/memory) 1/3
FSIN 16-126
FCOS 18-124
FSINCOS 17-137
FSQRT 70

I hope that helps put it in perspective .

[Resist Windows XP's Invasive Production Activation Technology!]

Edited by - Null and Void on October 21, 2001 1:17:02 AM
Thanks guys, this type of stuff is exactly what i was looking for; all this in a matter of 43 minutes !!!
-=- Murphy was an optimist -=-

This topic is closed to new replies.

Advertisement