News for hackers. Stuff that matters.
Re:Switch Lowering in GCC by ahartmetz on Saturday October 31, 2026 @07:42AM (#50315143)
There is surprisingly little about the proper feeding of advanced hardware in that code, two or three constants in cost calculations of which one or two are hardware-dependent.

It is still possible that a later pass arranges jump targets to avoid false sharing of their entries (addresses) in prediction mechanisms and such.

Re:Switch Lowering in GCC by sylware on Saturday October 31, 2026 @08:08AM (#50315364)
Just look at the assembly output of significantly sized switch statements (with good random values): it's scary :)

Obvsiously engaging in pleasing as much as it can speculative/BTB hardware (to the cost of memory tables!)

Re:Switch Lowering in GCC by ahartmetz on Saturday October 31, 2026 @08:18PM (#50321565)
I've seen it and it's not pretty, but hopefully fast. You kinda need to single-step it in assembly to be (somewhat) able to see what it does.
Re:Switch Lowering in GCC by sylware on Sunday November 01, 2026 @06:17AM (#50324534)
Yep, this is a big issue with compilers: you cannot snoop in and skim the code even to have rough understanding of what it does because you need to embrace and be proficient, nearly all the time, with their 'hardcore abstracted' model.

I did dive in LLVM a long time ago, and OMG... we have to get rid of it.

On the long term, gcc and clang are cooked, better move to binary specifications with various ISA implementations. Ofc here, we would need a bit of optimization knowledge in order to write assembly code not too much under-performant (because the goal here would not be speed, but independence from compilers!)

But it is not that much horrible: most performant micro-architectures use the same speculative concepts, then it is a matter to find the sweet spot between all of them: a good generic conditional branch machine instruction layout of a cache line with some additional care for non-conditional branch, and use branchless logic as much as you can. It is a matter to know such patterns: hopefully all those "coding AIs" can help (never tested them, cannot access them).