Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: a question about speed

Author: Matt Taylor

Date: 13:11:45 01/04/03

Go up one level in this thread


On January 04, 2003 at 15:32:40, Walter Faxon wrote:

>On January 03, 2003 at 19:52:06, Matt Taylor wrote:
>
>>On January 03, 2003 at 12:03:45, Uri Blass wrote:
>>
>>>code B is slightly faster than code A.
>>>I know that side can get only 0 or 1(something that the compiler does not know)
>>>and B is eqvivalent to A if you assume that side gets only 0 or 1.
>>>
>>>Is it possible to write a third code that will be even faster than B?
>>>
>>>I think that if the compiler can know that side is or 0 or 1 it can do B even
>>>faster.
>>>
>>>code A:
>>>
>>>if (side==LIGHT)
>>>{
>>>  if (to>=56)
>>>  {
>>>    gen_promote(from,to,bits);
>>>    return;
>>>  }
>>>}
>>>else
>>>{
>>>  if (to<=7)
>>>  {
>>>    gen_promote(from,to,bits);
>>>    return;
>>>  }
>>>}
>>>
>>>code B:
>>>if ((to+side*(63-2*to))>=56)
>>>{
>>>  gen_promote(from,to,bits);
>>>  return;
>>>}
>>>
>>>Uri
>>
>>Try this:
>>if ((to + (-side & (63 - 2 * to))) >= 56)
>>{
>>  gen_promote(from,to,bits);
>>  return;
>>}
>>
>>If side is 0 or 1, -side will be 0 or -1 and can be used as a mask here. It is
>>cheaper to do one's compliment and a bitwise and operation than a
>>multiplication.
>>
>>The compiler -should- recognize that 2 * to = to << 1
>
>
>ONLY IF 'to' is guaranteed positive.  Try:  "2 * (unsigned)to".  Or explicit
>shifting is always ok in my book.  Use a comment or #if'ed-out debug code if you
>want to keep things clear.
>
>-- Walter

For a shift left the signedness shouldn't matter. The shift right does, but x86
supports an "arithmatic" (signed) and a "logical" (unsigned) shift right.

I think the shift is just as clear here since we're already talking about
obfuscation. :-)

-Matt



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.