News for hackers. Stuff that matters.
Re:Do Not Taunt Happy Fun Branch Predictor by xKingfisher on Wednesday January 25, 2023 @08:19PM (#34526583)
An interesting application of this is massaging the branch predictor using tail calls to speed up a parser/interpreter:

https://blog.reverberate.org/2021/04/21/musttail-efficient-i...

Re:Do Not Taunt Happy Fun Branch Predictor by saagarjha on Wednesday January 25, 2023 @09:34PM (#34527079)
The wins from tail calls are generally more from being able to skip the overhead that comes from a function call rather than better branch prediction.
Re:Do Not Taunt Happy Fun Branch Predictor by xKingfisher on Wednesday January 25, 2023 @10:48PM (#34527464)
It's mentioned in passing at the end of the "the trouble with interpreter loops" section.

A traditional switch/goto loop can thrash the branch predictor. Separating into different tail calling functions gives you more slots and allows the branch predictor to learn relationships between ops.

Not to discount the many other benefits of tail calls.

*Edit: I misspoke slightly, computed gotos can also split the patch jump, but less reliably[0].

[0]https://gcc.gnu.org/pipermail/gcc/2021-April/235891.html