VisualStudio - __fastcall instead of __cdecl?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

VisualStudio - __fastcall instead of __cdecl?

Post by mar »

Hi,
I just made my program ~3% faster, perhaps more (nothing to do with chess) by forcing the compiler to use __fastcall instead of the default __cdecl.
I wonder whether using __fastcall would have the same effect with PGO enabled.
Could someone verify this? I believe it may be a nice speedup for the windows build of a chess engine, if it would hold with PGO.
It may but it may not. I especially wonder what compiler experts have to say about it ;)

Martin
User avatar
Jim Ablett
Posts: 1383
Joined: Fri Jul 14, 2006 7:56 am
Location: London, England
Full name: Jim Ablett

Re: VisualStudio - __fastcall instead of __cdecl?

Post by Jim Ablett »

Hi Martin,

I read about this optimization tip many years ago from Dann Corbit and use it whenever possible with Msvc
although I found it produces instability with some chess engine code, so you must be careful. If I used with Intel, binary would always crash or become unstable.

http://www.playwitharena.com/?Tips_%2B_ ... r_Binaries

Jim.
User avatar
rvida
Posts: 481
Joined: Thu Apr 16, 2009 12:00 pm
Location: Slovakia, EU

Re: VisualStudio - __fastcall instead of __cdecl?

Post by rvida »

mar wrote:Hi,
I just made my program ~3% faster, perhaps more (nothing to do with chess) by forcing the compiler to use __fastcall instead of the default __cdecl.
I wonder whether using __fastcall would have the same effect with PGO enabled.
Could someone verify this? I believe it may be a nice speedup for the windows build of a chess engine, if it would hold with PGO.
It may but it may not. I especially wonder what compiler experts have to say about it ;)

Martin
Hi,

Just in case you didn't already know - this option is ignored for 64bit builds. The x64 ABI defines only one calling convention, __fastcall.

http://msdn.microsoft.com/en-us/library/ms235286.aspx


Richard
mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: VisualStudio - __fastcall instead of __cdecl?

Post by mar »

Jim Ablett wrote:Hi Martin,

I read about this optimization tip many years ago from Dann Corbit and use it whenever possible with Msvc
although I found it produces instability with some chess engine code, so you must be careful. If I used with Intel, binary would always crash or become unstable.

http://www.playwitharena.com/?Tips_%2B_ ... r_Binaries

Jim.
That's interesting Jim, I only noticed some compile time problems with libpng and tremor where some callback function ptrs were explicitly declared as __cdecl and thus incompatible with __fastcall, didn't know about stability issues though. I guess I'll be happy with cdecl then. Thanks for clarifying this to me.

Martin
mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: VisualStudio - __fastcall instead of __cdecl?

Post by mar »

rvida wrote: Hi,

Just in case you didn't already know - this option is ignored for 64bit builds. The x64 ABI defines only one calling convention, __fastcall.

http://msdn.microsoft.com/en-us/library/ms235286.aspx


Richard
Thanks Richard I didn't know that. It seems logical though because as far as I understand 64-bit mode has more registers available than x86 mode. Thanks for the insight.

Martin