Archived

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

Operator speeds

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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites