Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Speed of certain operations

Author: David Blackman

Date: 00:09:25 06/17/99

Go up one level in this thread


On June 16, 1999 at 22:20:19, James Robertson wrote:

>If in my evaluation function I have numerous operations such as:
>
>x *= 5;
>x *= .5;
>x /= 5;
>x /= .5;
>
>[about] how many cycles will each of these take on a P/PII?
>
>Thanks,
>James

As others have said, it depends a bit whether it's floating point or integer.
Either way multiply is ok on most modern cpus. Probably 2 to 10 cycles on most,
and that can overlap with other calculations if they don't need the multiply
result. Divide is likely to be slower, maybe 10 to 40 cycles. If using floating
point, divide by a constant should be replaced by multiply by the reciprocal.
Some compilers are smart enough to do this for you. Some aren't. And some get
paranoid because in binary floating point 5 doesn't have an exact reciprocal. So
do it yourself.

For integers, again multiply is quite a bit faster than divide, but shift is
faster than either. So make the constants powers of two where possible, and
consider implementing them with shifts.

It should be noted that although multiply is a bit slow, and most people like to
avoid it, the slowest operations are likely to be:

Call to operating system (>500, usually much greater)
TLB miss (100 or more)
Cache miss to main memory (40 to 100)
Cache miss to second level cache (8 to 50)
Divide (10 to 40)
Wrongly predicted conditional branch (3 to lots)

Of course, first you get it working, then you check you are using good
algorithms, then you profile to find which areas of the code are taking most of
the time, then you worry about stuff like this :-)



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.