Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Macros versus Inline

Author: Omid David Tabibi

Date: 05:11:24 09/27/03

Go up one level in this thread


Under MSVC 6, I have found macros to often work considerably faster than
inlines, and never worse. Even when you declare __forceinline and check to
ensure that the function was indeed inlined, still macros perform considerably
better (I haven't delved into the assembly output to find out why).

For a one line code, macros work much faster than inlined functions, e.g.:

#define sgn(x)  (((x) < 0) ? -1 : (((x) > 0) ? 1 : 0))

But for longer code the superiority of macros over inline is negligible and I
personally use inline to avoid many possible bugs which might arise from macros.

But of course, sometimes you have to use inline, even in small functions, e.g.:

__forceinline unsigned int firstBitTrue(unsigned int data) {
    __asm   bsf    eax, dword ptr[data]
};

__forceinline unsigned int firstBitFalse(unsigned int data) {
    __asm {
        mov    eax, dword ptr[data]
        not    eax
        bsf    eax, eax
    }
};





P.S. I was shocked to find out that there is no sign function in math.h. How
could it be left out?



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.