Remix.run Logo
spacechild1 5 days ago

Yes. For example, if an argument fits into the size of a register, it's better to pass by value to avoid the extra indirection.

vitus 5 days ago | parent [-]

> if an argument fits into the size of a register, it's better to pass by value to avoid the extra indirection.

Whether an argument is passed in a register or not is unfortunately much more nuanced than this: it depends on the ABI calling conventions (which vary depending on OS as well as CPU architecture). There are some examples where the argument will not be passed in a register despite being "small enough", and some examples where the argument may be split across two or more registers.

For instance, in the x86-64 ELF ABI spec [0], the type needs to be <= 16 bytes (despite registers only being 8 bytes), and it must not have any nontrivial copy / move constructors. And, of course, only some registers are used in this way, and if those are used up, your value params will be passed on the stack regardless.

[0] Section 3.2.3 of https://gitlab.com/x86-psABIs/x86-64-ABI