Noticed some patterns when calling a zig function(Debug) on windows
lea rcx, [rbp + offset]
, on general linux lea rdi, [rbp - offset]
instructions are there most of the times at least at the root function which is calling the function chain, just curious but when calling those C conv function these instrunctions are not there. This must be some zig abi things, but just was wondering turning a normal non-exporting zig function’s call convention to C convention will I be missing some features or some good enough things that I should care about?
A function that is callconv(.c)
can only take arguments and return values of types that are compatible with C. This means no error unions, tagged unions, tuples, slices, and so on. You also theoretically lose out on some optimizations that the compiler is allowed to make when a function is callconv(.auto)
.
Don’t know if the Zig compiler actually makes any optimizations around the ABI, tho—or if such optimizations would really make much of a difference. So the first one I think is the main downside.
1 Like
When compiling for 32-bit x86, the fastcall convention is used when callconv is auto. Instead of all arguments being pushed onto the stack, a couple registers are used for that purpose.