Last active
February 23, 2017 21:00
-
-
Save primiano/2473ac16db614ffa1fc1f33b4dc0e15b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Foo { | |
int a; | |
int b; | |
int c; | |
int d; | |
int e; | |
int f; | |
int g; | |
int h; | |
}; | |
Foo g_foo[30]; | |
Foo* g_foo_ptr; | |
extern void Alias(void*); | |
void __attribute__((noinline)) no_optimizations_please() { | |
Alias(g_foo_ptr); | |
Alias(g_foo); | |
Alias(g_foo_ptr); | |
} | |
int main() { | |
no_optimizations_please(); | |
g_foo[1].c = 7; | |
asm volatile("nop"); // just a marker to identify the relevant assembly lines | |
g_foo_ptr[1].c = 8; | |
no_optimizations_please(); | |
return 0; | |
} | |
----- | |
$ g++ -o - -S -c -O2 test.cc | |
... | |
.cfi_def_cfa_register %rbp | |
callq __Z23no_optimizations_pleasev | |
movl $7, _g_foo+40(%rip) | |
## InlineAsm Start | |
nop | |
## InlineAsm End | |
movq _g_foo_ptr(%rip), %rax | |
movl $8, 40(%rax) | |
callq __Z23no_optimizations_pleasev | |
xorl %eax, %eax | |
popq %rbp | |
retq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment