CppCon 2017: Matt Godbolt “What Has My Compiler Done for Me Lately? Unbolting the Compiler's Lid”

preview_player
Показать описание


In 2012, Matt and a colleague were arguing whether it was efficient to use the then-new-fangled range for. 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.

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.

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.

Matt Godbolt: DRW, Senior Software Engineer

Matt Godbolt is a software engineer with trading firm DRW, and the creator of the Compiler Explorer website. He is passionate about writing efficient code. He has previously worked at on mobile apps at Google, run his own C++ tools company and spent more than a decade making console games. When he's not hacking on Compiler Explorer, Matt enjoys writing emulators for old 8-bit computer hardware.


*-----*
*--*
*-----*
Рекомендации по теме
Комментарии
Автор

Man, this presentation made me tear up. What a humble guy to have made and provide such a great service and to ask so little for it.

Thanks Matt.

ChrisCox-wvoo
Автор

Its crazy how these talks are all free on youtube

colin
Автор

32:28
I'm sorry if this has been worked out by someone else in the comments before, but my old grad school instincts took "I haven't bothered to work it out" to mean "it's a good exercise to work out what this does, " which is exactly what I did.

The assembly in the output is just (a << 10 + a) << 6 - a. In multiplicative notation, this is (a*2^10 + a)*2^6 - a. If you distribute the 2^6, this is a*2^16 + a*2^6 - a. Going back to shift notation, this is just (a << 16) + (a << 6) - a, which was what Godbolt had written before.

Godbolt's "optimized" multiplication required a separate register (ecx) to shift by 16 at one time, while the compiler did it all within eax, saving a mov instruction in the process, by doing basic algebra.

MathNerdGamer
Автор

I love godbolting my code! I have learned so much from it!

andreaslegomovies
Автор

Really enjoyed this, had no idea quite how clever compilers were getting

Mike-gseo
Автор

Excellent, excellent talk! Every single piece of information was valuable and entertainingly delivered.

dementedchicken
Автор

Fun & instructive, I'm glad I watched this. Terrific work, Matt.

albertobastos
Автор

What a blast from the past. The good old days of programming a TRS-80 in assembly. Great lecture.

davidbrown
Автор

Yes, talking about execution of dynamically compiled codes. Few years back I wrote one directory traversal codes, online compiled it and managed to traversed the directory of the server. I highlighted this vulnerability to the site-owner.

tthtlc
Автор

Small mistake @44:51. Matt says the problem is if you pass INT_MAX, but that will overflow in both cases. The actual edge case is close to sqrt(INT_MAX), which will overflow in the first case but not the second. I'm guessing that's the objection that was raised by the audience member.

xfreeman
Автор

The bit halfway through made me wonder if there are any benchmarks where people recompile old code for old hardware on new compilers (and new machines to save time), and see if the old stuff runs faster afterwards.

JobvanderZwan
Автор

@31:40 :D

Also, I'm getting flashbacks from optimizing multiplication by 40 on the C64 in machine code. shift, shift, shift, store, shift, shift, add. The factor 40 comes up a lot because there are 40 bytes of characters per row.

emanuellandeholm
Автор

If you want to optimize virtual methods then use the "final" attribute on classes.

llothar
Автор

Thank you for the effort, it's an amazing tool and presentation was fun :)

olegpatraschku
Автор

22:13 -- notice that GCC emits an extra instruction. Two rets one after the other. The one on line 12 could simply be deleted.

alexreinking
Автор

>Wrote a whole IRC client with UI and scripting support in assembly while in high school.

ameynarkhede
Автор

Did he just call Google a 'small internet startup', there at 3:00?

pranjalagrawal
Автор

Wish I had watched this a couple month ago!

wawangsf
Автор

quite a few processors have popcount procedure

EllAntares
Автор

Anyone have a link for the talk he mentions at 6:53?

SwordQuake