3 ms·
... we saw how register allocation and calling conventions — supposedly the exclusive concern of assembly-spinning compiler writers — occasionally pop their he
by pavlov 10y ago
... we saw how register allocation and calling conventions — supposedly the exclusive concern of assembly-spinning compiler writers — occasionally pop their heads up in C ...
I don't know about "occasionally". At least on Windows, calling conventions used to be a constant headache. The C language default was cdecl, but the Win32 API default (most of the time) was stdcall. Then there was a variant (fastcall?) that tried to make use of registers.
Maybe it's all fixed now... But this being Win32, I rather expect they've managed to accumulate a few more "interesting" gotchas and edge cases as the platform expanded with 64-bit, WinRT, Universal Windows Platform and whatever.
- quotemstr 10y agoFortunately, in the amd64 Windows world, there's only one calling convention. (Edit: as cremno points out, there's now a new vectorcall convention. Dammit.) The 64-bit Windows ABI is a big improvement over the old 32-bit one. Other improvements are use of unwind tables for SEH and the requirement that all code be unwindable.
- pavlov 10y agoI'm happy to hear that! With a fixed ABI, C++ 1x language features and UWP, it sounds like doing C/C++ on Windows could actually be fun these days.
- jheriko 10y agodon't get ahead of yourself... that ABI isn't there yet. :P
- cremno 10y ago>Fortunately, in the amd64 Windows world, there's only one calling convention. Not anymore: https://blogs.msdn.microsoft.com/vcblog/2013/07/11/introducing-vector-calling-convention/ https://blogs.msdn.microsoft.com/vcblog/2013/07/11/introduci...
- jheriko 10y ago> the requirement that all code be unwindable. i would not call that an improvement in all cases... the extra code produced by enabling exceptions, even for the latest compilers, produces enough bloat and slow down for basically everyone seriously concerned with real-time performance to turn them off. small simple functions are forced to have prologue/epilogue, use a frame pointer and to preserve the return address on the stack. doesn't sound like much, but if your function does anything simple (float f() { return 1; } bool g(float a, float b) { return a < b; } etc...) you spend all the time paying for exceptions instead of the intended functionality.
- quotemstr 10y agoYou're confusing unwinding mechanisms. The whole point of using unwind tables is to avoid the need to preserve frame pointers. There zero cost in pure C code and minimal cost in C++ code just for preserving the ability to unwind. You absolutely do not need to have extra prologue and epilogue code or to burn a register for a frame pointer.
- jheriko 10y agofrom what i understood it only gets rid of those requirements in some cases.... there is a table i remember in some doc about this, the only reason i listed from memory was the lack of being able to find it quickly on google .. its a shame i can't find it. perhaps my memory is imply faulty.
- jheriko 10y agoits quite intentional that on x64 the default convention for the compiler and the default convention for the platform is identical. the "constant headache" you allude to played no small part in that decision i would say...