Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: curiosity killed the cat... hi/lo bit C verses Assembly

Author: Walter Faxon

Date: 01:05:52 07/18/03

Go up one level in this thread


On July 18, 2003 at 03:22:21, Gerd Isenberg wrote:

>I tried PPRO it on the fly, see yourself:
>
>
>
>PUBLIC	?leastSigBit64@@YAH_K@Z				; leastSigBit64
>; Function compile flags: /Ogtay
>_TEXT	SEGMENT
>_bb$ = 8
>?leastSigBit64@@YAH_K@Z PROC NEAR			; leastSigBit64
>
>; 320  :     unsigned long bb0, bb1;
>; 321  :     int bbHalf;
>; 322  :
>; 323  :     bb0 = ((unsigned long*)&bb)[0];
>
>	mov	eax, DWORD PTR _bb$[esp-4]
>
>; 324  :     bb1 = ((unsigned long*)&bb)[1];     // if bb in registers, no code


Obviously not, here.


>; 325  :     bbHalf = (bb0 == 0);
>
>	xor	ecx, ecx
>	test	eax, eax
>	sete	cl
>
>; 326  :     if (bbHalf) bb0 = bb1;              // will code as cmov (ideally)
>
>	test	ecx, ecx
>	je	SHORT $L806
>	mov	eax, DWORD PTR _bb$[esp]
>$L806:
>


Stupid compiler, not only no cmov, it tests the result of something set to a
known value by a immediately previous test!

Though I agree I should have instead used the test (bb0 == 0) again, if only to
hold its hand.

I'll believe in a version of MSVC coding cmov when and if I see it.


>; 327  :     bb0 ^= bb0 - 1;
>
>	lea	edx, DWORD PTR [eax-1]
>	xor	edx, eax
>
>; 328  :     bb0 *= MT32magic;
>
>	imul	edx, 130329821				; 07c4acddH
>
>; 329  :     return (bbHalf << 5) | MT32table[bb0 >> 27];
>
>	shr	edx, 27					; 0000001bH
>	movzx	eax, BYTE PTR _MT32table[edx]
>	shl	ecx, 5
>	or	eax, ecx


Again, suboptimal code.  If bbHalf were kept in eax (and eax is being used),
then the table value could be or'ed in directly.  But the bbHalf shift would
need to be moved back, etc.

My head hurts.


>
>; 330  :         // if bbHalf in byte-addressable register, bitwise-or
>; 331  :         // preferred to avoid int+char type/sizing conflict
>; 332  : }
>
>	ret	0
>?leastSigBit64@@YAH_K@Z ENDP				; leastSigBit64


-- Walter



This page took 0.01 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.