Skip to content

Commit b8ba2cb

Browse files
author
Matt Godbolt
committed
More WIP
1 parent b435055 commit b8ba2cb

File tree

3 files changed

+176
-83
lines changed

3 files changed

+176
-83
lines changed

Notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jj
2222
* Assembly! Wait, come back!
2323
* Compiler Explorer: The Right To Assembly
2424
* CE - Assembly is a right not a privilege
25+
* Unbolting the secrets of the compiler
2526

2627
Foemmel likes 16, 18 (cliched), 8. His ideas 22-24
2728

abstract-etc.md

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,68 @@
11
Bio
22
---
3-
4-
Matt Godbolt is a software engineer with trading firm DRW. He is passionate about efficient code. He has previously worked at Google, run his own C++ tools company and spent more than a decade making computer games.
3+
Matt Godbolt is a software engineer with trading firm DRW, and the creator of the Compiler Explorer website.
4+
He is passionate about writing efficient code. He has previously worked at on mobile apps at Google, run his own C++
5+
tools company and spent more than a decade making console games.
56

67
Title
78
-----
8-
Unbolting the Lid of your Compiler
9+
Unbolting the Compiler's Lid, or What Has My Compiler Done For Me Lately?
910

1011
Tags
1112
----
1213
compilers,assembly,optimization
1314

1415
Session Description
1516
-------------------
16-
In 2012, Matt and a colleague were discussing which approach to loop iteration would be more efficient. During the discussion a bash script was written to quickly compile C++ source and dump the assembly. Five years later and that script has grown into a website relied on by many to quickly see the code their compiler emits, to compare different compilers' code generation and behaviour, to quickly prototype and share code, and investigate the effect of optimization flags.
17+
In 2012, Matt and a colleague were arguing whether it was efficient to use the then-new-fangled range for. During the
18+
discussion a bash script was written to quickly compile C++ source and dump the assembly. Five years later and that
19+
script has grown into a website relied on by many to quickly see the code their compiler emits, to compare different
20+
compilers' code generation and behaviour, to quickly prototype and share code, and investigate the effect of optimization flags.
1721

18-
In this talk Matt will not only show you how easy (and fun!) it is to understand the assembly code generated by your compiler, but also how important it can be. He'll explain how he uses Compiler Explorer in his day job programming low-latency trading systems, and show some real-world examples. He'll demystify assembly code and give you the tools to understand and appreciate how hard your compiler works for you.
22+
In this talk Matt will not only show you how easy (and fun!) it is to understand the assembly code generated by your
23+
compiler, but also how important it can be. He'll explain how he uses Compiler Explorer in his day job programming
24+
low-latency trading systems, and show some real-world examples. He'll demystify assembly code and give you the tools
25+
to understand and appreciate how hard your compiler works for you.
1926

20-
He'll also talk a little about how Compiler Explorer works behind the scenes, how it is maintained and deployed, and share some stories about how it has changed over the years. By the end of this session you'll be itching to take your favourite code snippets and start exploring what your compiler does with them.
27+
He'll also talk a little about how Compiler Explorer works behind the scenes, how it is maintained and deployed, and
28+
share some stories about how it has changed over the years. By the end of this session you'll be itching to take your
29+
favourite code snippets and start exploring what your compiler does with them.
2130

2231
Material
2332
--------
2433
Slides, any links and source code used.
2534

2635
Outline
2736
-------
37+
* Backstory
38+
* Demo
39+
* Including assembly 101, or how to fake it at assembly
40+
* Compilers are super-smart!
41+
* Appropriately defeating the optimizer to see what you'd expect
42+
* Demo some "power features" that some people don't necessarily know about (diff view, multiple editors) - depends on
43+
screen resolution of the project and visibility.
44+
* A warning: MEASURE EVERYTHING! Limitations of "just" looking at the assembly output (dovetails with hash maps below)
45+
* Case Studies, including things like:
46+
* Loop iteration shoot-out, pre-increment vs post-increment vs range-for vs std::algorithms
47+
* Hash maps, GCC's STL unordered_map vs boost multi-index
48+
* Compiler Explorer in low-latency trading: formatting exchange orders (and/or processing market data)
49+
* Undefined behaviour is your friend, or how clang beats gcc with linked list iteration
50+
* Unpicking your object model, or devirtualisation for dummies
51+
* Plus, many, many more (allocation elision in clang, non-virtual thunks, write combining, address sanitisation)
52+
* How other people use it, including things like
53+
* Compiler teams (e.g. at Google)
54+
* Slack
55+
* Twitter competition to "generate most code from 140c of code"
56+
* Template metaprogramming REPL using constepr
57+
* Minimal bug reports for compilers / search for regressions
58+
* Peeking behind the curtain: how CE works
59+
* The code (and how to run it locally)
60+
* The compilers (and how to get most of them locally yourself)
61+
* The magic that runs on Amazon's infrastructure
62+
* Conclusions and call to action!
63+
* Everyone should be using this!
64+
* Thanks to my contributors and patreon supporters
65+
* Help wanted
2866

2967
History
3068
-------

index.html

Lines changed: 131 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -56,90 +56,144 @@ <h3>Backstory</h3>
5656
doSomething(x);
5757
}</code></pre>
5858
</section>
59-
<section>
60-
<h3>Compiler Explorer v1</h3>
61-
<pre><code class="bash">$ watch 'g++ -O2 -S /tmp/test.cc -o - | c++filt'</code></pre>
62-
<a href="http://localhost:10240/#z:OYLghAFBqd5TKALEBjA9gEwKYFFMCWALugE4A0BIEAZugHZEDKqAhgDbYgCMAdABwBWAOyCATAAYAnGIBsw7lKVTh5AFY9yAZ3QBXUqi4ByAKRiAzAXqp2unAGoT5gMKotRTOwIAjJ7hMSAIJmlta2Dk7OAG7YqCSkfgHBQdgAHkTYpPT2UegEmPaY6EzoALbYREhWwBBWRACUTgBCSUm5%2BfZ0pNisqEgQGPTu9u6YICAxcWSRdX6OclH1jsItQfadZPYQWgQAXtgA%2BkT2BI7mACL2Es0nZ845vDv7EI3mTfMtYk0EjWvrhcUyhUqvQalETIJvhDzq9VsFhOcjPVyOwQEZBEZyPQ0RJMeg0c4zJ93jp9IZ5uZuJiiDikciANYgQQSFFogAsmNKTJZ2KMuPI%2BKMmK0IBZNL5SPIcFgKAwpQADgROBQqAMyorlSAAPS6LSkLXeKxa4BEonkGhKjKkEUQby08hy8qMADy9HYAE97YRunECDERRLKIxsKiJci6IwWBwuHwhKJJDJ5IplKp0PKiAQGAGALTOsTCvQGGPI0MYrH2wU6vUGo0mr5Erb4YibELccj2ZzqpWZCncerU2n1ZFIHo4UjUBnc1lGDnlwOC4Wi8ji3FD6f58hc5lz/kL5eDqWIaXINBYPCEeKUagR5hsTg8AQicTSOQKZQqdQgMTaQuGNEhKwbDsbA7jcDwvF8cx/CCACwmAu5JniRIYJSdJMmydoCiKEpykqapakYWFWiCTCNm6Xp%2BkGYZRnGRDphcWYoPmWRFmWOF1i6LY6nsVJ7BAHJfkCf4ARw4F8NSIiYIRSVS0xXldwJU0vhGX8QJCDcVzpcgR1YMcJ3IRlt1DWctx5Cs0UXMUD2PCBZS7ZUrzVBVu3HKt9UNehjSUppzUtTIbTtQNHWwF03U9QNvViDN/XtOoQwPG8o3vWMnwTV9kyUVN00zIY0VzDdSSLL8SzRMt5LxNE3JrTy62JRsLxbCxvw7eye3U/t9zDYdR0yfTDJZYy5PMoVtCXTS11DDdTJ3CqRvGyduAkAa0XMIb5wszrV2RGJrRykA2SAA%3D%3D">Or
63-
here</a>
64-
</section>
65-
<section>
66-
<h3>Some assembly</h3>
67-
<iframe width="1000px" height="300px"
68-
src="http://localhost:10240/e#g:!((g:!((g:!((h:codeEditor,i:(fontScale:1.5479341055999998,j:1,source:'int+square(int+num)+%7B%0A++++return+num+*+num%3B%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:/usr/bin/g%2B%2B,filters:(b:'0',commentOnly:'0',directives:'0',intel:'0'),fontScale:1.5479341055999998,options:'',source:1),l:'5',n:'0',o:'/usr/bin/g%2B%2B+(Editor+%231,+Compiler+%231)',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4"></iframe>
59+
<section><h3>Why we care</h3></section>
60+
<section><h3>Demo</h3></section>
61+
<section><h3>How it works</h3></section>
62+
<section><h3>New compilers</h3></section>
63+
<section><h3>Running Locally</h3></section>
64+
<section><h3>Hacking attempts</h3></section>
65+
<section><h3>Measure everything</h3></section>
66+
<section><h3>ASM 101</h3></section>
67+
<section><h3>Defeating the optimizer</h3></section>
68+
<section><h3>Case Study: range for and pre-post increment, vs std::algorithm</h3>
69+
https://godbolt.org/g/gS9NOV
6970
</section>
70-
<section>
71-
<h3>Intel asm 101</h3>
72-
<pre><code data-trim class="asm">
73-
mov dest, src
74-
add dest, arg
75-
cmp reg, arg
76-
jmp dest
77-
</code></pre>
71+
<section><h3>Case Study: hash maps</h3>
72+
boost multi_index
7873
</section>
79-
<section>
80-
<h3>Intel registers</h3>
81-
<ul>
82-
<li>rax</li>
83-
<li>rcx</li>
84-
<li>rdx</li>
85-
<li>rbx</li>
86-
<li>rsp</li>
87-
<li>rbp</li>
88-
<li>rsi</li>
89-
<li>rdi</li>
90-
<li>r8-r15</li>
91-
</ul>
74+
<section><h3>Case Study: order formatting</h3></section>
75+
<section><h3>Power Features</h3></section>
76+
<section><h3>Case Study: auto copy / move / etc (Chrome xopied all its images moved instead of moved..)</h3>
9277
</section>
93-
<section>
94-
<h3>Intel registers</h3>
95-
<table class="reg">
96-
<tr>
97-
<td colspan="8" class="reg">rax</td>
98-
</tr>
99-
<tr>
100-
<td colspan="4"></td>
101-
<td colspan="4" class="reg">eax</td>
102-
</tr>
103-
<tr>
104-
<td colspan="6"></td>
105-
<td colspan="2" class="reg">ax</td>
106-
</tr>
107-
<tr>
108-
<td colspan="6"></td>
109-
<td colspan="1" class="reg">ah</td>
110-
<td colspan="1" class="reg">al</td>
111-
</tr>
112-
<tr>
113-
<td>...</td>
114-
<td>...</td>
115-
<td>...</td>
116-
<td>...</td>
117-
<td>...</td>
118-
<td>...</td>
119-
<td>...</td>
120-
<td>...</td>
121-
</tr>
122-
</table>
78+
<section><h3>Case Study: clever compiler optimizations</h3></section>
79+
<section><h3>Case Study: clang vs GCC inf loop detect</h3></section>
80+
<section><h3>Case Study: closed form summation</h3></section>
81+
<section><h3>Case Study: devirtulaise</h3>
82+
https://godbolt.org/g/tuO5Ij - devirtualisation
12383
</section>
12484
<section>
125-
<h3>Intel registers</h3>
126-
<pre><code data-trim class="cpp">
127-
union {
128-
struct {
129-
uint8_t al;
130-
uint8_t ah;
131-
};
132-
uint16_t ax;
133-
uint32_t eax;
134-
uint64_t rax;
135-
};
136-
</code></pre>
85+
pass by value / pass by reference https://godbolt.org/g/XWFR7s
86+
aliasing: https://godbolt.org/g/wczpd3
87+
https://bugs.llvm.org/show_bug.cgi?id=28343 - type based aliasing
88+
New int; leak memory thing? (memory alloc elision)
89+
https://bugs.llvm.org/show_bug.cgi?id=28343
90+
memory allocation elision
91+
-fsanitize=address
92+
entire smallpt
93+
auto lambda demo: https://godbolt.org/g/5fOC4q
94+
variant stuff, clang opts out
95+
Non virtual thunks
96+
cute opt: https://godbolt.org/g/Tk8Af4 and https://godbolt.org/g/Zdvzke (ordering? interesting)
97+
https://gcc.godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,source:'namespace+%7B%0A++struct+Iface+%7B%0A++++virtual+~Iface()+%7B%7D%0A++++virtual+int+doThing()+const+%3D+0%3B%0A++%7D%3B%0A%0A++struct+Bob+:+Iface+%7B+%0A++++int+doThing()+const+override+%7B+return+1%3B+%7D%0A++%7D%3B%0A%0A++struct+Ian+:+Iface+%7B+%0A++++int+doThing()+const+override+%7B+return+2%3B+%7D%0A++%7D%3B%0A%0A++int+test(const+Iface+%26obj)+%7B%0A++++int+a+%3D+0%3B%0A++++for+(int+i+%3D+0%3B+i+%3C+10000%3B+%2B%2Bi)%0A++++++a+%2B%3D+obj.doThing()%3B%0A++++return+a%3B%0A++%7D%0A%7D%0A%0Aint+main(int+argc,+const+char+*argv%5B%5D)+%7B%0A++Ian+ian%3B%0A++Bob+bob%3B%0A++if+(argc+%3D%3D+2)+%0A++++return+test(ian)%3B%0A++else%0A++++return+test(bob)%3B%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:50,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((g:!((h:compiler,i:(compiler:g7snapshot,filters:(b:'0',commentOnly:'0',directives:'0',intel:'0'),options:'-O3',source:1),l:'5',n:'0',o:'x86-64+gcc+7+(snapshot)+(Editor+%231,+Compiler+%231)',t:'0')),k:50,l:'4',m:50.05471818428769,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang_trunk,filters:(b:'0',commentOnly:'0',directives:'0',intel:'0'),options:'-O3',source:1),l:'5',n:'0',o:'x86-64+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),l:'4',m:49.94528181571231,n:'0',o:'',s:0,t:'0')),k:50,l:'3',n:'0',o:'',t:'0')),l:'2',n:'0',o:'',t:'0')),version:4`
13798
</section>
138-
<section>
139-
<h3>Cleverness</h3>
140-
<iframe width="1000px" height="300px"
141-
src="http://localhost:10240/e#g:!((g:!((g:!((h:codeEditor,i:(fontScale:1.2899450879999999,j:1,source:'int+times9(int+num)+%7B%0A++++return+num+*+9%3B%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:/usr/bin/g%2B%2B,filters:(b:'0',commentOnly:'0',directives:'0',intel:'0'),fontScale:1.2899450879999999,options:'-O1',source:1),l:'5',n:'0',o:'/usr/bin/g%2B%2B+(Editor+%231,+Compiler+%231)',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4"></iframe>
99+
<section><h3>Case Study: other people's usage</h3>
100+
<ul>
101+
<li>Trying out new features</li>
102+
<li>Demoing compiler optimizations</li>
103+
<li>"most output from a tweet" competition</li>
104+
<li>creating minimal bug reports for compilers</li>
105+
<li>TMP repl using static_assert</li>
106+
<li>ease of use means people try things out they would never have thought of</li>
107+
<li>Compiler optimization team at Google</li>
108+
<li>"Works on my machine" / Godbolt</li>
109+
</ul>
142110
</section>
111+
<!--
112+
<section>
113+
<h3>Compiler Explorer v1</h3>
114+
<pre><code class="bash">$ watch 'g++ -O2 -S /tmp/test.cc -o - | c++filt'</code></pre>
115+
<a href="http://localhost:10240/#z:OYLghAFBqd5TKALEBjA9gEwKYFFMCWALugE4A0BIEAZugHZEDKqAhgDbYgCMAdABwBWAOyCATAAYAnGIBsw7lKVTh5AFY9yAZ3QBXUqi4ByAKRiAzAXqp2unAGoT5gMKotRTOwIAjJ7hMSAIJmlta2Dk7OAG7YqCSkfgHBQdgAHkTYpPT2UegEmPaY6EzoALbYREhWwBBWRACUTgBCSUm5%2BfZ0pNisqEgQGPTu9u6YICAxcWSRdX6OclH1jsItQfadZPYQWgQAXtgA%2BkT2BI7mACL2Es0nZ845vDv7EI3mTfMtYk0EjWvrhcUyhUqvQalETIJvhDzq9VsFhOcjPVyOwQEZBEZyPQ0RJMeg0c4zJ93jp9IZ5uZuJiiDikciANYgQQSFFogAsmNKTJZ2KMuPI%2BKMmK0IBZNL5SPIcFgKAwpQADgROBQqAMyorlSAAPS6LSkLXeKxa4BEonkGhKjKkEUQby08hy8qMADy9HYAE97YRunECDERRLKIxsKiJci6IwWBwuHwhKJJDJ5IplKp0PKiAQGAGALTOsTCvQGGPI0MYrH2wU6vUGo0mr5Erb4YibELccj2ZzqpWZCncerU2n1ZFIHo4UjUBnc1lGDnlwOC4Wi8ji3FD6f58hc5lz/kL5eDqWIaXINBYPCEeKUagR5hsTg8AQicTSOQKZQqdQgMTaQuGNEhKwbDsbA7jcDwvF8cx/CCACwmAu5JniRIYJSdJMmydoCiKEpykqapakYWFWiCTCNm6Xp%2BkGYZRnGRDphcWYoPmWRFmWOF1i6LY6nsVJ7BAHJfkCf4ARw4F8NSIiYIRSVS0xXldwJU0vhGX8QJCDcVzpcgR1YMcJ3IRlt1DWctx5Cs0UXMUD2PCBZS7ZUrzVBVu3HKt9UNehjSUppzUtTIbTtQNHWwF03U9QNvViDN/XtOoQwPG8o3vWMnwTV9kyUVN00zIY0VzDdSSLL8SzRMt5LxNE3JrTy62JRsLxbCxvw7eye3U/t9zDYdR0yfTDJZYy5PMoVtCXTS11DDdTJ3CqRvGyduAkAa0XMIb5wszrV2RGJrRykA2SAA%3D%3D">Or
116+
here</a>
117+
</section>
118+
<section>
119+
<h3>Some assembly</h3>
120+
<iframe width="1000px" height="300px"
121+
src="http://localhost:10240/e#g:!((g:!((g:!((h:codeEditor,i:(fontScale:1.5479341055999998,j:1,source:'int+square(int+num)+%7B%0A++++return+num+*+num%3B%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:/usr/bin/g%2B%2B,filters:(b:'0',commentOnly:'0',directives:'0',intel:'0'),fontScale:1.5479341055999998,options:'',source:1),l:'5',n:'0',o:'/usr/bin/g%2B%2B+(Editor+%231,+Compiler+%231)',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4"></iframe>
122+
</section>
123+
<section>
124+
<h3>Intel asm 101</h3>
125+
<pre><code data-trim class="asm">
126+
mov dest, src
127+
add dest, arg
128+
cmp reg, arg
129+
jmp dest
130+
</code></pre>
131+
</section>
132+
<section>
133+
<h3>Intel registers</h3>
134+
<ul>
135+
<li>rax</li>
136+
<li>rcx</li>
137+
<li>rdx</li>
138+
<li>rbx</li>
139+
<li>rsp</li>
140+
<li>rbp</li>
141+
<li>rsi</li>
142+
<li>rdi</li>
143+
<li>r8-r15</li>
144+
</ul>
145+
</section>
146+
<section>
147+
<h3>Intel registers</h3>
148+
<table class="reg">
149+
<tr>
150+
<td colspan="8" class="reg">rax</td>
151+
</tr>
152+
<tr>
153+
<td colspan="4"></td>
154+
<td colspan="4" class="reg">eax</td>
155+
</tr>
156+
<tr>
157+
<td colspan="6"></td>
158+
<td colspan="2" class="reg">ax</td>
159+
</tr>
160+
<tr>
161+
<td colspan="6"></td>
162+
<td colspan="1" class="reg">ah</td>
163+
<td colspan="1" class="reg">al</td>
164+
</tr>
165+
<tr>
166+
<td>...</td>
167+
<td>...</td>
168+
<td>...</td>
169+
<td>...</td>
170+
<td>...</td>
171+
<td>...</td>
172+
<td>...</td>
173+
<td>...</td>
174+
</tr>
175+
</table>
176+
</section>
177+
<section>
178+
<h3>Intel registers</h3>
179+
<pre><code data-trim class="cpp">
180+
union {
181+
struct {
182+
uint8_t al;
183+
uint8_t ah;
184+
};
185+
uint16_t ax;
186+
uint32_t eax;
187+
uint64_t rax;
188+
};
189+
</code></pre>
190+
</section>
191+
<section>
192+
<h3>Cleverness</h3>
193+
<iframe width="1000px" height="300px"
194+
src="http://localhost:10240/e#g:!((g:!((g:!((h:codeEditor,i:(fontScale:1.2899450879999999,j:1,source:'int+times9(int+num)+%7B%0A++++return+num+*+9%3B%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:/usr/bin/g%2B%2B,filters:(b:'0',commentOnly:'0',directives:'0',intel:'0'),fontScale:1.2899450879999999,options:'-O1',source:1),l:'5',n:'0',o:'/usr/bin/g%2B%2B+(Editor+%231,+Compiler+%231)',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4"></iframe>
195+
</section>
196+
-->
143197
<div class="footer">
144198
<hr>
145199
<img src="DRWSmallLogo.png" width="50" height="16">

0 commit comments

Comments
 (0)