Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Speed of certain operations

Author: Eugene Nalimov

Date: 10:51:09 06/17/99

Go up one level in this thread


On June 17, 1999 at 13:24:50, Dave Gomboc wrote:

>On June 17, 1999 at 03:13:08, David Blackman wrote:
>
>>On June 16, 1999 at 23:01:38, Dave Gomboc wrote:
>>
>>>On June 16, 1999 at 22:56:02, Greg Lazarou wrote:
>>>
>>>>Hi James,
>>>>
>>>>I don't have the straight answer to your question but if x is an integer then
>>>>multiplications by 2 and divisions by 2 (the 4th and 2nd cases respectively)
>>>>should be very fast left and right shifts. Now you can let the compiler figure
>>>>it out (and you may be able to help the compiler figure it out by expressing
>>>>x*=.5 as x /= 2) or you can code it as a shift yourself...
>>>
>>>N.B. (x /= 2) == (x >> 1) iff (x is unsigned)
>>>
>>>Dave
>>
>>But for signed numbers (x >> 1) is almost always what you really want. And if
>>you want to divide by something other than a power of two you curse hardware and
>>language designers for not making signed division work properly.
>
>This is true, if you really want "x >> 1", you'd better type it in yourself,
>because AFAIK optimizers explicitly do not change x/=2 into x>>1 when x is
>signed.
>
>Dave

I already posted it here, but once again: for signed division by a power of 2,
you can use something like that (if I remember it correctly):

y = x/2 --> y = (x >> 1) + (x == -1)
y = x/(2**N) --> y = (x >> N) + (((unsigned) (x + 2**N-1)) < 2**N-1)

And at least one of the optimizing compilers do that - I wrote it myself before
I came to MS.

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.