Pregunta

I was wondering, it is possible to explicitly specify a custom calling convention, but considering the maturity and amount of optimizations found in the compiler, when no calling convention is specified, can I expect the compiler to pick the best one for the particular function, for example if parameters are few and primitive use fastcall and so on...

¿Fue útil?

Solución

It is a "convention" for a reason. Everybody has to follow the convention or you couldn't call your function from another module.

However, if the function is not visible then GCC has options. It may inline the function or call it however it wants to. It might even split it into "hot" and "cold" parts and inline the hot code path. That usually only happens when building with profile guided optimization.

If you want GCC to make optimizations like that, work on hiding your functions. If you are building an executable look at -fwhole-program. If you are building libraries look at -fvisibility=hidden. Also look into -flto.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top