Skip to content

Instantly share code, notes, and snippets.

@kinoshita-lab
Last active December 14, 2015 05:49
Show Gist options
  • Save kinoshita-lab/5038090 to your computer and use it in GitHub Desktop.
Save kinoshita-lab/5038090 to your computer and use it in GitHub Desktop.
Comparison between call by reference and call by value
The Code:
int add_ref(const int& a, const int& b)
{
return a + b;
}
int add_value(const int a, const int b)
{
return a + b;
}
----------------------------------------------------------------------------
Compile with:
clang++ -O3 -S -mllvm --x86-asm-syntax=intel hoge.cpp -o hoge.intel.s
where
clang++ -v
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.2.0
----------------------------------------------------------------------------
The Result (simpilified):
__Z7add_refRKiS0_: ## @_Z7add_refRKiS0_
push RBP
mov RBP, RSP
mov EAX, DWORD PTR [RSI]
add EAX, DWORD PTR [RDI]
pop RBP
ret
__Z9add_valueii: ## @_Z9add_valueii
push RBP
mov RBP, RSP
add EDI, ESI
mov EAX, EDI
pop RBP
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment