Author: Gerd Isenberg
Date: 00:41:57 08/22/03
Go up one level in this thread
On August 21, 2003 at 18:22:32, Omid David Tabibi wrote:
>I changed some data structures in my program and added two functions (the
>variables are renamed below):
>
>void func1(unsigned int &a, int b, int c) {
> a += array[b][c];
>}
>
>BOOL func2(unsigned int a, int b, int c) {
> return (a & mask[b][c]);
>}
>
>These two functions are very heavily used all over the program. In MSVC 6 I use
>the "inline any suitable" option for inlining, so I assumed that the compiler
>would definitely inline these functions. But again, "assumption is the mother of
>all f**k-ups", after turning the warning level to 4, I found out that these
>functions were not chosen for inlining... strange for itself.
>
>So I added a __forceinline to each of them and recompiled. But still the speedup
>was negligible. So instead I wrote the following two macros:
>
>#define func1(a,b,c) (a += array[b][c])
>#define func2(a,b,c) ((a) & mask[b][c])
>
>Wao! about 20% speedup! I was certain that the two functions were not inlined
>previously when I added __forceinline. So I checked it again in warning level of
>4, but didn't find any warning indicating that they were not inlined (if you
>mention __inline or __forceinline, and the compiler can't inline, a warning is
>typically displayed).
Hmm... strange - 20% speedup. I would like to see assembler output of some code
snippets, where __forceinlined functions verus macros are used.
Have you tried only func2 as inlined and func1 as macro?
I guess func1 is the "candidate" where something went wrong.
The func1 macro is not like a void function, rather than a function which
returns the already incremented a-value.
#define func1(a,b,c) (a += array[b][c])
__forceinline
unsigned int func1(unsigned int &a, int b, int c) {
return (a += array[b][c]);
maybe some aliasing effect and you may try func1 without "sideeffect":
__forceinline
unsigned int _func1(unsigned int a, int b, int c) {
return (a + array[b][c]);
and to call
a = _func1(a,b,c);
Cheers,
Gerd
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.