Re: FFI newby question: importing C functions

  • From: Mike Pall <mike-1206@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 27 Jun 2012 14:56:19 +0200

QuentinC wrote:
> > I guess your best bet is to not use __stdcall exports. There's no
> good reason to use it, anyway.
> 
> So everything I read about __stdcall saying it was faster and
> produce smaller binaries are all wrong, or were right at a time but
> no longer ?

Urban myth. Only helped with really ancient C compilers and CPUs
where 'push' was used to pass arguments and the 'ret NN'
instruction cleaned these up.

Modern x86 C compilers keep the stack balanced inside a single
function and pass arguments by doing ESP-relative stores.

Modern CPUs (P4 and later) penalize 'push' instructions and a
'ret NN' is slower than a plain 'ret' on Core2 and later.

Summary: Do NOT use __stdcall for performance!

Corollary: only use __fastcall for performance if you pass up to
two integer/pointer arguments. Otherwise it may be slower than a
cdecl on x86.

BTW: None of this is an issue for x64, which only uses a single
calling convention (like most other architectures).

--Mike

Other related posts: