Тёмный

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

CppCon
Подписаться 149 тыс.
Просмотров 163 тыс.
50% 1

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
*-----*
*--*
*-----*

Опубликовано:

 

1 окт 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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
@andreaslegomovies
@andreaslegomovies 6 лет назад
I love godbolting my code! I have learned so much from it!
@colin398
@colin398 Год назад
Its crazy how these talks are all free on youtube
@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.
@angelcaru
@angelcaru 2 месяца назад
It has compiled your code!
@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.
@kwccoin3115
@kwccoin3115 5 лет назад
Such a great video and site !!!!
@ZarviroffSerge
@ZarviroffSerge 3 года назад
Brilliant!
@olegpatraschku3736
@olegpatraschku3736 2 года назад
Thank you for the effort, it's an amazing tool and presentation was fun :)
@CppCon
@CppCon 2 года назад
Glad it helped!
@wawangsf
@wawangsf 3 года назад
Wish I had watched this a couple month ago!
@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.
@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
@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 ru-vid.com 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 Месяц назад
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
@pranjalagrawal969
@pranjalagrawal969 6 лет назад
Did he just call Google a 'small internet startup', there at 3:00?
@Nobody1707
@Nobody1707 5 лет назад
It was in 1998.
@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.
@xfreeman86
@xfreeman86 5 месяцев назад
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.
@SwordQuake2
@SwordQuake2 4 года назад
Anyone have a link for the talk he mentions at 6:53?
@gim913
@gim913 5 лет назад
Once I heard you'll be using Intel syntax, I had to upvote.
@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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-w0sz5WbS5AM.html
@EllAntares
@EllAntares 29 дней назад
quite a few processors have popcount procedure
@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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-37jyHQT7fXQ.html (if that's the one you meant)
@pavelponomarev1625
@pavelponomarev1625 9 месяцев назад
Is there a similar but for ARM 64bit architecture?
@mbabuskov
@mbabuskov 5 лет назад
36:30 next time someone tells me Ubuntu is rock solid with no bugs
@cavesalamander6308
@cavesalamander6308 Год назад
47:28 "... making the code efficient and *_most_* *_often_* *_correct_* too." ROFL!!!
@aliancemd
@aliancemd 6 лет назад
He mentioned all the languages except for Rust, which was supported for a pretty long time :(
@xrafter
@xrafter 3 года назад
31:05 Lol
@alchemira
@alchemira Год назад
Wow, I could make a lot of videos on "what has my compiler done AGAINST me"
@LemonChieff
@LemonChieff 6 лет назад
:D
@peterSobieraj
@peterSobieraj Год назад
OMG. I though I'm so clever because I have made script that delete unused functions and variables. Dunning Kruger effect.
@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)
@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!
@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
@kaboissonneault
@kaboissonneault 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
Далее
Turning trash into triumph, one can at a time!
00:18
Просмотров 2,3 млн
CppCon 2017: Chandler Carruth “Going Nowhere Faster”
1:00:58
The Thirty Million Line Problem
1:48:55
Просмотров 242 тыс.
CppCon 2018: Jason Turner “Applied Best Practices”
1:03:19