← Back to context

Comment by leni536

2 years ago

Yep. Also whether passing in registers is faster or not also depends on the function body. It doesn't make much sense if the first thing the function does is to take the address of the parameter and passes it to some opaque function. Then it needs to be spilled onto the stack anyway.

It would be interesting to see calling convention optimizations based on function body. I think that would be safe for static functions in C, as long as their address is not taken.

Dynamic calling conventions also won't work with dynamic linking

  • Even when dynamic linking a lot of calls will be internal to each library. So you can either:

    1. Use a stable calling convention for external interfaces.

    2. Use a stable calling convention for everything, but generate trampolines for external calls.

    Swift is actually pretty cool here. It basically does 2. But you can also specify which dependencies are "pinned" so that even if they are dynamically linked they can't be updated without a recompile. Then you can use the unstable calling convention when calling those dependencies.