Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Opteron Instruction Set

Author: Robert Hyatt

Date: 21:30:31 02/02/04

Go up one level in this thread


On February 02, 2004 at 23:14:12, Omid David Tabibi wrote:

>On February 02, 2004 at 22:41:19, Robert Hyatt wrote:
>
>>On February 02, 2004 at 20:06:29, David Rasmussen wrote:
>>
>>>Does the Opteron have firstBit, lastBit and popCount instructions? Or at least
>>>something that makes calculating them easier than on x86-32?
>>>
>>>/David
>>
>>
>>Has the same BSF/BSR instructions, but no popcnt that I have found.  Note
>>that BSF/BSR work on 64 bit values if you want.  I have inline asm to do
>>all three for gcc if you are interested.
>
>Currently, my only critical assembly parts are the following:
>
>__forceinline UINT32 findFirstBitTrue(UINT32 data) {
>	__asm   bsf		eax, dword ptr[data]
>};
>
>__forceinline UINT32 countBitsTrue(UINT32 data) {
>	__asm {
>		mov		ecx, dword ptr data
>		xor		eax, eax
>		test	ecx, ecx
>		jz		l1
>	l0:	lea		edx, [ecx-1]
>		inc		eax
>		and		ecx, edx
>		jnz		l0
>	l1:
>	}
>}
>
>If migrating to 64 bit, I can replace my popcount with:
>
>__forceinline UINT32 countBitsTrue(UINT32 data) {
>	UINT32 count = 0;
>	while (data) {
>		count++;
>		data &= data - 1;
>	};
>	return count;
>};
>
>But any replacement for findFirstBitTrue on 32 bit data in Opteron?

I don't know how to do any of that in MSVC.  But using gcc inline asm, you
should use %rax rather than %eax to access a 64 bit register.  And you can
_still_ use bsfl/bsrl (32 bit versions) using %eax.  Or you can use bsfq/bsrq
(64 bit versions) using %rax...

In windows MSVC for opteron, there is a built-in intrinsic for firstone/lastone,
you can find that in Eugene's inline stuff for Crafty.  Then you need no
assembly at all, but it obviously doesn't work for 32 bit compiles.



>
>The efficiency of findFirstBitTrue on 32 bit data is very important for me, as
>it is used very heavily throughout the program.

Should work perfectly if you use the right opcode/register name...




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.