Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Porting to linux and inline assembly with gcc

Author: Dieter Buerssner

Date: 04:05:04 10/06/02

Go up one level in this thread


On October 05, 2002 at 00:53:39, Russell Reagan wrote:

>I have two questions. First...
>
>I'm trying to get my program to compile under linux, but I'm stuck on the inline
>assembly I use. Under VC++ I do:
>
>int LowBit (Bitboard b) {
>	_asm {
>		mov	eax, -33
>		bsf	eax, dword ptr [b+4]
>		add	eax, 32
>		bsf	eax, dword ptr [b]
>	}
>}
>
>But I'm lost at how to make that work under gcc.

/* Untested code */
int LowBit(unsigned long long a)
{
  int res;
  __asm__ volatile("
    movl -33, %0
    bsfl %2, %0
    addl 32, %0
    bsfl %1, %0"
    : "=q&" (res)
    : "g" ((unsigned long)a), "g" ((unsigned long)(a>>32))
    : "cc" /* condition code (flags register) clobbered */);
  return res;
}

But you really need to study the gcc manual, if you want to use inline assembly
with it. I think, it is a bit more flexible, than VC (register names don't need
to be hard coded, which should give the optimizer more freedem in register
allocation, especially when inlining), but harder to code.

>Secondly, there seems to be quite a long list of compiler options for gcc. VC++
>has always taken care of everything so I'm lost when it comes to compiling an
>optimized program under linux. I know you use the -O, -O2, etc. options, but I
>read all over about people using various options like -fomit-frame-pointer which
>he says, "will make your code faster and smaller," but I have no idea why, and
>it makes me wonder if this is a legitimate optimization, or if it's not going to
>matter.

For most of my programs, simple -O -fomit-frame-pointer does best. -O2 and -O3
usally make my progs slightly slower. You might want to try processor specific
optimization, (-mcpu or -march). It does not help much in my experience. If you
have a new gcc, you can try -fprofile-arcs and -fbranch-probabilites.

Regards,
Dieter



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.