I want to create a function with no arguments and unit return type with minimal code generation at the call site. Is there a calling convention that rust supports and that has no caller-saved registers? Alternatively, can I define my own calling convention somehow?
Depends on what do you mean by that: if you want to tell the compile that foreign function only clobbers very few registers then that's easy: just call it via asm!
If you want to ask compiler to save all register than it may need… no, that's not supported. That's property of the target OS and thus you would need to recompile rustc
to achieve that.
1 Like
There is one if you add #[cold]
to the function.
It also optimizes for size and moves it to a different section of the executable.
1 Like
#[cold]
can't affect the calling convention unless the function happens to not be exported from the codegen unit.
Even then it's not possible to ask compiler to save registers that are normally clobbered (like rdi
or rsi
).