Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Speed of certain operations

Author: Eugene Nalimov

Date: 21:41:51 06/16/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

Don't use floating point - use scaled integers instead (e.g. use 100 instead
1.0, 150 instead of 1/50, etc). Theoretically, if you are writing in assembly,
you can use floating point if there are enough integer operations near it - your
program can even be faster this way. But I doubt you'll be lucky with C.

Multiplication by a constant is fine if you are using good optimizing compiler
(e.g. VC) - compiler will replace that by shifts and additions, if that is
benefitical. Multiplication by a non-constant is slightly more expensive, but
not much - but it'll be much more expensive in a future, for IA-64.

Division is *BAD*. If possible, use right shift for division by power of 2 - but
please notice that division of signed integers and shift have slightly different
semantics. Often that does not matter, but if matter, you can use the clever
tricks (if compiler does not do that for you), e.g.: y = (x >> 2) + (x == -1).

Addition and subtraction of 64-bit integers are relatively cheap. Multiplication
and division is *always* expensive.

Eugene



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.