Author: Gerd Isenberg
Date: 06:49:14 09/10/05
Go up one level in this thread
On September 10, 2005 at 08:32:35, Jan K. wrote: >Hi, I experimented a bit with bitboard move generator(on 32-bit machine) and I >found that MSVC compiler inserts _aullshr function call everytime I try to shift >a bitboard. That seems expensive to me. Could someone please comment why this >happens and what really this function does(in ASM)? Hi Jan, to shift a 64-bit integer right on x86-32 with a variable shift count of 0..64 one needs following instructions with one conditional branch whether shift count is greater or equal 32: 64-Bit Right Shift of edx:eax by cl from AMD64 optimization guide: shrd eax, edx, cl ; First apply shift count ... shr edx, cl ; ... mod 32 to EDX:EAX test ecx, 32 ; Need to shift by another 32? jz rshift_done ; No, done. mov eax, edx ; right shift EDX:EAX xor edx, edx ; by 32 bits. rshift_done: Similar code is inside the size saving subroutine you mentioned and there seems no way other than using a special intrinsic function to inlne the code. Constant 64-bit shifts with a 32-bit register pair and shift count of 0..31 may be implemented with only two instructions, most likely inlined by the compiler (with the "right" optimization settings): shrd eax, edx, 9 shr edx, 9 As far as i know there is even a special msc intrinsic (forgotten the name or reference, but Eugene Nalimov did it mention some time ago) to shift only with mod 32 shift counts which generates such inlined code. shrd eax, edx, cl shr edx, cl On athlons/opterons SHRD is a relative expensive vector path instruction (4 cycles). So 64-bit shifts become really shorter and faster in 64-bit mode: shr rax, cl Gerd
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.