Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: asm question

Author: James Robertson

Date: 14:15:36 06/18/00

Go up one level in this thread


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.


>
>Which brings up another issue.  Why are you messing with assembly code, which is
>non-portable, more difficult to maintain than C, and these days very hard to
>write so it goes faster than optimized C code?  If you are doing this because
>you want to speed up a C function, make sure that you do some stop-watch timing
>on the code before and after.  I suggest that if you can't detect any
>difference, you put the C back.

My assembler code is much faster than what the optimized compiler produces. :)
Also, certain instructions, such as bsf/bsr are impossible to use in C/C++, and
so inline assembler is a necessity, if for those commands only.

James

>
>bruce



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.