4 ms·
Instead of if( condition) then code1: else code2, computed goto will just switch the branch to unconditional jump to either code1/code2, which bypasses branch m
by countWSS 3y ago
Instead of if( condition) then code1: else code2, computed goto
will just switch the branch to unconditional jump to either code1/code2,
which bypasses branch misprediction penalty and is generally
more elegant.
- CarVac 3y agoDoes that not actually cause a mispredict if the speculative execution happened before the code change?
- messe 3y agoWorse. It's more than likely to cause a cache miss, and waiting on memory is going to be even slower than a mispredicted branch.
- monocasa 3y agoIt could be even worse. I've seen x86 cores where the icache/dcache consistency logic ended up internally being most of a page fault and recovery once noticed by the processor.
- messe 3y agoOof on that note: at least in the example in the article, it's going to cost a TLB miss as page permissions are getting changed. So that's a page-table walk which means %cr3 -> PML4 -> PDPT -> PD -> PT -> the actual address you want to access; potentially up to 5 memory accesses (6 if your system has more than 256TB of RAM and you're using 5-level paging). That being said, in a loop you'd only take this hit on the first run. You'd be back to cache misses after that.