3 ms·
Performance. Storing to and retrieving from registers are typically much faster than writing to and then accessing memory. It's like keeping things in your 16 h
by wyc 10y ago
Performance. Storing to and retrieving from registers are typically much faster than writing to and then accessing memory. It's like keeping things in your 16 hands vs. keeping them in your backpack en transit. I believe this to be Linux-specific, as the BSDs have a different ABI that relies solely on the stack.
Some notes:
http://www.int80h.org/bsdasm/#default-calling-convention http://www.int80h.org/bsdasm/#default-calling-convention
- anonymousiam 10y agoThanks for the explanation everyone. I suppose it was my fault for interpreting "have to" as an absolute requirement rather than a preferred method.
- gpderetta 10y agoIt is a requirement in the sense that if the C code passes the aggregate parameter by value, the compiler is required to generate the assembler code to pass via the registers [1]. [1] inlining, calls to static functions and whole program optimization do give the compilers freedom to pick a different calling convention of course.
- anonymous_iam 10y agoI still don't understand this. If a blob of C code passes a large structure by value, doesn't it go on the stack? Why would the compiler be required to pass such an object only via the registers?
- taejo 10y agoIt's generally expected that functions compiled with different compilers (for the same target architecture) can call each other. This only works if the compilers agree on where function arguments go; since they are all required to do it in the same way, it's better to require everyone to do it the fast way rather than requiring everyone to do it the slow way.