r/cpp • u/JankoDedic • Aug 04 '24
C++ Exceptions Reduce Firmware Code Size - Khalil Estell - ACCU 2024
https://www.youtube.com/watch?v=BGmzMuSDt-Y
138
Upvotes
r/cpp • u/JankoDedic • Aug 04 '24
49
u/johannes1971 Aug 04 '24
It's great to see someone work on exceptions, instead of just dismissing them out of hand. I've thought for years that there was scope for improving what was already there, and would prefer such optimisation efforts over adding new mechanisms. And given the results presented here, I would suggest that potential new mechanisms are put on hold until it is clear whether they offer any kind of advantage at all over just optimising the existing mechanism.
I'm interested in seeing the follow-on talks. We've been hearing about exceptions being 'non-deterministic' for years but that never quite rang true to me. Sure, it allocates memory and might run into a cold cache line, but the same thing is true for lots of code, and yet exceptions is the only feature that receives this particular stigma.
To the speaker: would you happen to know if turning off RTTI but keeping exceptions is supported by other compilers, in particular clang and msvc?
Also, is your work specific to ARM, or will it also apply to other CPUs (like x64)?
19
u/mjklaim Aug 04 '24
Very interesting talk! I was wondering if the speaker has an opinion on the static exceptions proposal for the context of embedded P3166. Being both expert in embedded and a teacher makes such opinion very useful.
13
u/GabrielDosReis Aug 04 '24
Great content! I'm thrilled to see the work done here.
12
u/RobinDesBuissieres Aug 04 '24
That was a cool talk and i wonder if this can be translated to a non-embedded world.
8
u/darkmx0z Aug 04 '24
really cool!
7
u/DutchessVonBeep Aug 04 '24
Great video, thank you for this research and discussion on improving exception handling understanding and implementations.
17
u/pjmlp Aug 04 '24
One thing I really appreciate in other programming language communities is the ability to write libraries everyone can enjoy, instead of having to walk a maze of selectively enabled language features outside of the language standard.
It's great to see a talk being positive about exceptions instead of it is going to be the end of the world.
5
u/pavel_v Aug 05 '24
Great talk! For me, it also aligns with this paper from Bjarne Stroustrup.
8
u/hopa_cupa Aug 04 '24
Great talk. Especially liked distributed vs central error handling terminology, not to mention myth busting. Keep it up!
3
u/stick_figure Aug 05 '24
This is amazing work! I think the key takeaway is that, if you are going to spray result types so pervasively over your code that you start to reach for a macro to do basic error propagation, you should start to wonder why you aren't using exceptions, which let the compiler turn some of that code into data.
I've worked on LLVM exception handling for Windows, and it pains me to see C++ programmers argue about using macros and statement expressions to do error propagation when exceptions are already an implementation requirement for the compiler.
I do think that these code size savings may not translate as well to a non-embedded context due to the number of local variable destructors that deallocate memory (unique_ptr, string).
7
u/SkoomaDentist Antimodern C++, Embedded, Audio Aug 04 '24
Nice to see someone else validating my undying hatred of iostreams.
2
u/moreVCAs Aug 04 '24
Wow cannot wait to watch.
2
u/lestofante Aug 05 '24
very cool and very in deep, I was one of the "exception allocate" bell, is nice to be proven wrong (once in a while :P)
2
u/Alternative_Staff431 Aug 05 '24
Random question but what are you pointing at?
2
u/fwsGonzo IncludeOS, C++ bare metal Aug 06 '24
This talk is exactly what I have been hoping for all this time. I know that my RISC-V emulator in interpreter mode is one of the fastest emulators that exist simply because I use C++ exceptions for all errors that normally have to be propagated back to dispatch. Further, I also have C++ exceptions enabled in the (simulated) guest programs.
I am also working on low-latency emulation with a focus on avoiding JIT and binary translation, and this talk is giving me ideas. What I want to try is to do the same for RISC-V, and then see if I can do some of the exception handling outside of the emulator, effectively giving it native performance.
Wouldn't that be something?
1
u/CanadianTuero Aug 06 '24
Does anyone have recommendations for not so expensive embedded dev kits that are sort of plug and play (no soldering) to start playing around with? Hopefully something that also has support for the rust compiler so that I can compare/contrast the two.