Author: Gerd Isenberg
Date: 00:58:31 01/21/04
Go up one level in this thread
On January 21, 2004 at 02:46:54, Steve Maughan wrote:
>Gerd,
>
>>May be your compiler settings are wrong, eg. for msvc6 "project settings / C-
>>C++ / optimization / Inline function expansion" should at least set on "Only
>>__inline", but not "disabled".
>
>Yes the options are set correctly.
>
>>As Anthony already meantioned, the function should be defined (and not only a
>>prototype declaration) in some common header file of course.
>
>It is defined in a header file (I think) - what's the difference between a
>definition and a prototype declaration. The function is listed in the protos.h
>file.
>
>I think this is probably the root of the problem but I still have not managed to
>get it to work!
Steve,
with prototype in header file i mean only a function declaration, without the
implementation, to make the function signature known to all cpp files that will
call this function.
// in protos.h
int bsf(bitboard a);
The none inlined function itself is implemented in one cpp-file and later linked
together with all other object files of the executable or dynamic link libary.
For inlining across several cpp-files, it is necessary to have the whole
implementation inside the header (like a macro):
// in some h-file
__forceinline int bsf(bitboard a)
{ __asm
{
bsf eax, dword ptr[a + 4]
add eax, 32
bsf eax, dword ptr[a]
}
}
but no prototype
// in protos.h
//int bsf(bitboard a);
You may use a preprocessor define to switch switch between inlining and none
inlining of several functions:
#define INLINE_BSF
// in protos.h
#ifdef INLINE_BSF
__forceinline int bsf(bitboard a)
{ __asm
{
bsf eax, dword ptr[a + 4]
add eax, 32
bsf eax, dword ptr[a]
}
}
#else
int bsf(bitboard a);
#endif
// in some cpp file
#ifndef INLINE_BSF
int bsf(bitboard a)
{ __asm
{
bsf eax, dword ptr[a + 4]
add eax, 32
bsf eax, dword ptr[a]
}
}
#endif
Even with none inlining a common shared implementation of short or medium sized
functions in header files makes sense, eg. to avoid "far-calls" over module
bounderies. In that case you have to use the static keyword, to make all
function-incarnations in every cpp-file local.
Gerd
>
>>You may try a safe conditional 64-bit bitscan, eg. "jnz found" after the first
>>bsf. May be the (often correct predicted) branch outperforms the expensive and
>>conditional skipped second "bsf".
>
>I'll give it a go
>
>Thanks,
>
>Steve
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.