Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: asm question

Author: Bas Hamstra

Date: 16:55:19 06/18/00

Go up one level in this thread


On June 18, 2000 at 17:11:58, James Robertson wrote:

>On June 18, 2000 at 16:17:15, Bo Persson 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;
>>>
>>
>>There really isn't a 64-bit shift available, that's why its called a 32-bit
>>processor :-))
>
>Thanks for understanding my question. I know how to shift the upper 32 and lower
>32 bits in a 64 bit integer, but I didn't know how to move any bits shifted off
>the end of one into the other to simulate a single 64-bit shift.
>
>James

That is what

>>SHLD  EDX,EAX,CL    ; shift high part

is for. Only to do this ALWAYS is not optimal. If you shift more than 32 bits
one the 2 registers will end up zero. So you only have to shift one 32 bits
register, which is faster. That is what the above routine comes down to.


Bas Hamstra.


>
>>
>>So you have to do the shift in 2 steps, using a Double Precision shift, SHLD,
>>that can shift any 32 bits from a register pair. However, it only produces a
>>partial (32-bit) result, so you have to do an additional shift of the remaining
>>32 bits. It would look something like:
>>
>>MOV   EAX,[x]
>>MOV   EDX,[x + 4]   ; x now in EDX:EAX register pair
>>MOV   CL,[shift]
>>
>>SHLD  EDX,EAX,CL    ; shift high part
>>SHL   EAX,CL        ; shift low part
>>
>>MOV   [x],EAX
>>MOV   [x + 4],EDX
>>
>>
>>Not very efficient really. If you know the 'shift' to be a constant, like 8 or
>>16, that can be used to improve the performance. For example, move the white
>>pawns on a bitboard:
>>
>>   inline void BitBoard::CopyAndMove_Up(const BitBoard& SourceMap)
>>   {
>>      Half[1]     = SourceMap.Half[1] << 8;
>>      Rank[Rank5] = SourceMap.Rank[Rank4];
>>      Half[0]     = SourceMap.Half[0] << 8;
>>   }
>>
>>
>>
>>>Thanks,
>>>James
>>
>>
>>Bo Persson
>>bop@malmo.mail.telia.com





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.