Skip to content

Instantly share code, notes, and snippets.

@geneotech
Last active August 11, 2017 11:28
Show Gist options
  • Save geneotech/4c789229f7c8ccd67888019a9b605fdd to your computer and use it in GitHub Desktop.
Save geneotech/4c789229f7c8ccd67888019a9b605fdd to your computer and use it in GitHub Desktop.
struct A { int v; };
struct B { int v; };
struct C { int v; };
struct Ar { int& v; };
struct Br { int& v; };
struct Cr { int& v; };
void add_ref(A& a, B& b, C& c) {
a.v += c.v;
b.v += c.v;
}
void add_obj(const Ar a, const Br b, const Cr c) {
a.v += c.v;
b.v += c.v;
}
#include <ctime>
int main() {
time((time_t*)add_ref);
time((time_t*)add_obj);
return 0;
}
DISASSEMBLY:
void add_ref(A& a, B& b, C& c) {
01361002 in al,dx
a.v += c.v;
01361003 mov edx,dword ptr [c]
01361006 mov eax,dword ptr [a]
01361009 mov ecx,dword ptr [edx]
0136100B add dword ptr [eax],ecx
b.v += c.v;
0136100D mov eax,dword ptr [b]
01361010 mov ecx,dword ptr [edx]
01361012 add dword ptr [eax],ecx
}
01361014 pop ebp
01361015 ret
void add_obj(const Ar a, const Br b, const Cr c) {
01361020 push ebp
01361021 mov ebp,esp
a.v += c.v;
01361023 mov eax,dword ptr [c]
01361026 mov ecx,dword ptr [eax]
01361028 mov eax,dword ptr [a]
0136102B add dword ptr [eax],ecx
b.v += c.v;
0136102D mov eax,dword ptr [c] // WTF?
01361030 mov ecx,dword ptr [eax]
01361032 mov eax,dword ptr [b]
01361035 add dword ptr [eax],ecx
}
01361037 pop ebp
01361038 ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment