Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: asm question

Author: Bas Hamstra

Date: 16:51:09 06/18/00

Go up one level in this thread


On June 18, 2000 at 19:22:26, Bruce Moreland wrote:

>On June 18, 2000 at 19:06:23, Tom Kerrigan wrote:
>
>>On June 18, 2000 at 17:15:36, James Robertson wrote:
>>
>>>On June 18, 2000 at 16:44:15, Bruce Moreland wrote:
>>>
>>>>On June 18, 2000 at 15:25:23, James Robertson wrote:
>>>>
>>>>>I cannot remember how to do a shift in assembler and save any bits shifted off.
>>>>>Specifically, I want to shift a 64-bit integer. What is the assembler equivalent
>>>>>of:
>>>>>
>>>>>unsigned __int64 x;
>>>>>x <<= shift;
>>>>
>>>>If you are using MSVC, you can often answer these questions by compiling with
>>>>the -Fc option, and looking at the code.
>>>>
>>>>It is possible that they do a function call to do this, but if they do it
>>>>inline, the answer is right in front of you.
>>>
>>>I did this. To do a 64 bit shift, MSVC calls a function named _allshl or
>>>_allshr. This is the code it provides (copied and directly from the debug
>>>executable and uncleaned):
>>>
>>>_allshl:
>>>00408190   cmp         cl,40h
>>>00408193   jae         RETZERO(0x004081aa)
>>>00408195   cmp         cl,20h
>>>00408198   jae         MORE32(0x004081a0)
>>>0040819A   shld        edx,eax,cl
>>>0040819D   shl         eax,cl
>>>0040819F   ret
>>>MORE32:
>>>004081A0   mov         edx,eax
>>>004081A2   xor         eax,eax
>>>004081A4   and         cl,1Fh
>>>004081A7   shl         edx,cl
>>>004081A9   ret
>>>RETZERO:
>>>004081AA   xor         eax,eax
>>>004081AC   xor         edx,edx
>>>004081AE   ret
>>>
>>>I am sure the MUST be something faster than this.
>>
>>I didn't actually look at the assembly, but I'm 100% certain this is the fastest
>>way to do it. Think about it, the people who wrote this function are geniuses at
>>MS and their top priority was to make it as fast as possible. No offense, but I
>>really doubt you can do a better job.
>>
>>-Tom
>
>It's a general-purpose routine that handles shift counts that are larger than he
>is apt to see, if he is using constants or being very practical.  He can
>probably get rid of a lot of it, if it has to.
>
>The first two lines, for instance, tell the routine to zero out the whole thing
>if it is trying to shift by >= 64 bits.
>
>bruce

About beating the compiler: you can do it if you know the architecture. But it
is not easy. I bought an nice book about code optimizing. The author is an
absolute expert in using asm on the x86 architecture. And even he has to do a
lot of work, not only cycle counting, but also trial and error to be 30% faster
than the compiler on average. The thing is: he was using Watcom. I reckon VC to
be quite a bit faster than Watcom, so...

Doing my bitboard movegen stuff in macro assembler I can beat Borland by 30% but
NOT VC. I am just saying that you have to work very hard to be faster and even
then don't expect too much gain. Unless, maybe, you are an expert and you build
you whole program from the ground of in assembler.


Bas Hamstra.









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.