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

  Рет қаралды 162,756

CppCon

CppCon

6 жыл бұрын

CppCon.org
-
Presentation Slides, PDFs, Source Code and other presenter materials are available at: github.com/CppCon/CppCon2017
-
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.
-
Videos Filmed & Edited by Bash Films: www.BashFilms.com
*-----*
*--*
*-----*

Пікірлер: 75
@ChrisCox-wv7oo
@ChrisCox-wv7oo 2 жыл бұрын
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.
@MathNerdGamer
@MathNerdGamer 5 жыл бұрын
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
@colin398
@colin398 Жыл бұрын
Its crazy how these talks are all free on youtube
@andreaslegomovies
@andreaslegomovies 6 жыл бұрын
I love godbolting my code! I have learned so much from it!
@Mike-gs7eo
@Mike-gs7eo 6 жыл бұрын
Really enjoyed this, had no idea quite how clever compilers were getting
@davidbrown552
@davidbrown552 5 жыл бұрын
What a blast from the past. The good old days of programming a TRS-80 in assembly. Great lecture.
@albertobastos
@albertobastos 2 жыл бұрын
Fun & instructive, I'm glad I watched this. Terrific work, Matt.
@dementedchicken1
@dementedchicken1 3 жыл бұрын
Excellent, excellent talk! Every single piece of information was valuable and entertainingly delivered.
@tthtlc
@tthtlc 6 жыл бұрын
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.
@angelcaru
@angelcaru Ай бұрын
It has compiled your code!
@emanuellandeholm5657
@emanuellandeholm5657 Жыл бұрын
@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.
@JobvanderZwan
@JobvanderZwan 6 жыл бұрын
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.
@AltamishM
@AltamishM 6 жыл бұрын
Good point! I'm sure a fresh compile would benefit a decade old program, given how clever the compilers have become.
@AltamishM
@AltamishM 6 жыл бұрын
narutofan9999 that's not very helpful haha XD
@commel
@commel 2 жыл бұрын
That's actually a neat point of Java. Just run the same code on another CPU (with an jvm that understands it) and you are good to go to use new instructions the CPU offers.
@FatbocSlin
@FatbocSlin 2 жыл бұрын
I saw that René compiled some basic program (gzip?) with the newest compiler on some ancient hardware kzbin.info It was slower. I think it might have been after mitigations, but larger code might not benefit the smaller caches from back then.
@ewancrow7020
@ewancrow7020 13 күн бұрын
I know it's been six years, but if you're still curious you should look into the efforts to improve the performance of mario 64
@xfreeman86
@xfreeman86 4 ай бұрын
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.
@kwccoin3115
@kwccoin3115 5 жыл бұрын
Such a great video and site !!!!
@ZarviroffSerge
@ZarviroffSerge 2 жыл бұрын
Brilliant!
@SwordQuake2
@SwordQuake2 4 жыл бұрын
Anyone have a link for the talk he mentions at 6:53?
@olegpatraschku3736
@olegpatraschku3736 2 жыл бұрын
Thank you for the effort, it's an amazing tool and presentation was fun :)
@CppCon
@CppCon 2 жыл бұрын
Glad it helped!
@pranjalagrawal969
@pranjalagrawal969 6 жыл бұрын
Did he just call Google a 'small internet startup', there at 3:00?
@Nobody1707
@Nobody1707 5 жыл бұрын
It was in 1998.
@wawangsf
@wawangsf 3 жыл бұрын
Wish I had watched this a couple month ago!
@ameynarkhede8264
@ameynarkhede8264 5 жыл бұрын
>Wrote a whole IRC client with UI and scripting support in assembly while in high school.
@pha1994
@pha1994 5 жыл бұрын
Amey Narkhede That seems like a huge undertaking.
@GeorgeTsiros
@GeorgeTsiros Жыл бұрын
@@pha1994 mostly drudgework writing assembly is nowhere near as incomprehensible as reading compiled code listings or, worse, disassembly
@llothar68
@llothar68 6 жыл бұрын
If you want to optimize virtual methods then use the "final" attribute on classes.
@MrSapps
@MrSapps 5 жыл бұрын
with LTCG/LTO it still works as Matt said :)
@gim913
@gim913 5 жыл бұрын
final does not guarantee in any way, that there won't be virtual calls... it's enough you have two classes both final, that implement a shared interface.
@alexreinking
@alexreinking 4 жыл бұрын
22:13 -- notice that GCC emits an extra instruction. Two rets one after the other. The one on line 12 could simply be deleted.
@jakobnissen5723
@jakobnissen5723 4 жыл бұрын
Not neccesarily. The compiler may add redundant instructions in order to align the instructions in the instruction cache.
@alexreinking
@alexreinking 2 жыл бұрын
@@jakobnissen5723 That is not the case here. The second-to-last `ret` on line 12 is already aligned; jumping to a redundant one after it is _completely_ pointless.
@VFPn96kQT
@VFPn96kQT 2 жыл бұрын
@@alexreinking I think Matt explains it here: kzbin.info/www/bejne/rWHWq2iNl7hod68
@EllAntares
@EllAntares 4 күн бұрын
quite a few processors have popcount procedure
@pavelponomarev1625
@pavelponomarev1625 8 ай бұрын
Is there a similar but for ARM 64bit architecture?
@AmeliusDex
@AmeliusDex 6 жыл бұрын
Does anyone know if the other talk Matt kept talking about has (or will) be uploaded?
@MattGodbolt
@MattGodbolt 6 жыл бұрын
The jsbeeb talk wasn't recorded, but a longer version is available here: kzbin.info/www/bejne/aWjNqnuHiZyZjrM (if that's the one you meant)
@gim913
@gim913 5 жыл бұрын
Once I heard you'll be using Intel syntax, I had to upvote.
@aliancemd
@aliancemd 6 жыл бұрын
He mentioned all the languages except for Rust, which was supported for a pretty long time :(
@cavesalamander6308
@cavesalamander6308 Жыл бұрын
47:28 "... making the code efficient and *_most_* *_often_* *_correct_* too." ROFL!!!
@xrafter
@xrafter 3 жыл бұрын
31:05 Lol
@mbabuskov
@mbabuskov 5 жыл бұрын
36:30 next time someone tells me Ubuntu is rock solid with no bugs
@henke37
@henke37 6 жыл бұрын
LD_PRELOAD? Lame. Ptrace the thing instead and catch the syscalls no matter how they were reached.
@MattGodbolt
@MattGodbolt 6 жыл бұрын
Thanks for the idea; I'll check it out
@ihatenumberinemail
@ihatenumberinemail 6 жыл бұрын
No, use seccomp with a BPF filter.This is why seccomp exists.
@MattGodbolt
@MattGodbolt 6 жыл бұрын
I'm currently considering both 'firejail' and 'isolate' which both use bpf filters and namespaces. Thanks all!
@peterSobieraj
@peterSobieraj Жыл бұрын
OMG. I though I'm so clever because I have made script that delete unused functions and variables. Dunning Kruger effect.
@alchemira
@alchemira Жыл бұрын
Wow, I could make a lot of videos on "what has my compiler done AGAINST me"
@LaurentLaborde
@LaurentLaborde 6 жыл бұрын
javascript x86 emulator exists (eg : v86) but they are not as complete as you'd like to :D (ho nvm, it was pointed out in Q&A)
@LemonChieff
@LemonChieff 6 жыл бұрын
:D
@p39483
@p39483 2 жыл бұрын
This cleverness is starting to make template generics look like premature optimization. A C generic using (void*), (*)(), size, offset, stride will become a compile time generic due to cleverness. That is, if the parameters are constant, the compiler is just as happy to inline an indirect function call and unroll loops as if it were a with T::dostuff(). The C generic, however, has the advantage that it is simultaneously a runtime generic which can be called from Python or whatnot. So I'm amused by the irony in saying 1. compilers are clever while 2. advising the use of std:: template stuff. Said another way, templates tell the compiler to force compile time parameters when they are already clever enough to turn runtime parameters into compile time parameters when possible and defer to runtime what they must.
@SimonBuchanNz
@SimonBuchanNz 2 жыл бұрын
If you're using templates for speed, your using them wrong. You use them because they will yell at you when you screw it up (eg you cast the state param wrong) or because you want to metaprogram on the types, for example using different parsing algorithms for different types automatically without the caller having to tell you which to use. Also keep in mind that classically you lose all the interprocedual optimization when you call across compilation units, so remember to use global optimization. Also it's generally also trivial to get a C ABI version of a template by simply passing the instantiation parameters to it!
@bartekkko
@bartekkko 6 жыл бұрын
so the main takeaway is to leave gcc and use clang instead? bit of a shame because compiling in gcc takes significantly less typing (g++ file.cpp) than compiling in clang (clang++ file.cpp) and that only gets you c++98 in clang
@cH3rtzb3rg
@cH3rtzb3rg 6 жыл бұрын
If the time you need to type to call the compiler is your bottleneck, just stay with g++ (or make an 1-letter alias for your favorite compiler + arguments). If you actually care about runtime performance, set up your build-system to compile with different compilers and do regular benchmarks.
@bartekkko
@bartekkko 6 жыл бұрын
i was making a joke in that second sentence, really. I'm a physics student so I mostly write small single-file prototype things and it's not worth bringing out the makefile for that. still, I'll probably do that aliasing thing, later, when i can be arsed
@nameguy101
@nameguy101 6 жыл бұрын
Fun fact: It is literally never worth bringing out the makefile. Makefiles and build systems of all kinds are shit.
@meekrab9027
@meekrab9027 6 жыл бұрын
Just alias g++ to clang++ like Apple does by default. :^)
@llothar68
@llothar68 6 жыл бұрын
I aliased my build system to "r" for run, beat me
@TheHappyDoomsayer
@TheHappyDoomsayer 6 жыл бұрын
First
@bietola75
@bietola75 6 жыл бұрын
Doomsayer_Hazel first to reply to first
@ongamex
@ongamex 6 жыл бұрын
I see no point of this lecture. Every year we have that talk multiple times.
@dipi71
@dipi71 6 жыл бұрын
That exact talk? Including the new stuff and Q&A? For example, I didn’t know about the JS-based x86 emulator.
@gabrielb.2886
@gabrielb.2886 6 жыл бұрын
He's not talking only for you. I hope you don't complain every time somebody says something you already know. I've never listened to such a talk before and I'm glad that it is not 5 year's old. BTW, many people still think that C++ abstractions have to be slower than C code and assembly is the fastest you can get while it is obvious that on any reasonably complex program, the compiler outperforms the best assembly writers. Still a lot of new tricks to learn to old dogs, which you apparently aren't ;)
@Runoratsu
@Runoratsu 6 жыл бұрын
And as long as people don't learn, there shall be more!
@makerofstartup7902
@makerofstartup7902 5 жыл бұрын
waste of time
Super sport🤯
00:15
Lexa_Merin
Рет қаралды 20 МЛН
Como ela fez isso? 😲
00:12
Los Wagners
Рет қаралды 26 МЛН
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 16 МЛН
22 Sending vs  Opening Snaps Snapchat SQL Interview Question
11:05
Master SQL with Harshit Bhadiyadra
Рет қаралды 7
CppCon 2016: Jason Turner “Practical Performance Practices"
1:00:29
CppCon 2017: Chandler Carruth “Going Nowhere Faster”
1:00:58
Branchless Programming in C++ - Fedor Pikus - CppCon 2021
1:03:57
Super sport🤯
00:15
Lexa_Merin
Рет қаралды 20 МЛН