Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: asm question

Author: Tom Kerrigan

Date: 10:16:06 06/19/00

Go up one level in this thread


On June 18, 2000 at 23:08:25, James Robertson 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.
>
>I am sure it is the fastest way if the function has no clue what to expect in
>terms of arguments. I know exactly what I will be shifting by, if there is a
>chance of trying to shift by 0 or > 64, if the 64-bit integer has a chance of
>being 0, etc.

Here's an interesting question...

What does the compiler do when you shift something by 0?

-Tom



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.