Re:Do Not Taunt Happy Fun Branch Predictor
by mncharity on Wednesday January 25, 2023 @08:21PM
(#34526593)
> Concatenation pretty much requires branches without unique characteristics, so no fast path
Discussion the other day, of optimizing dispatch overhead in no-jit-allowed lightweight-word vm's, raised a brainstormy idea of having multiple copies of some words, and the compiler juggling them with awareness of their varied branch predictor states. Sort of a dynamic version of reducing dispatch by identifying hot phrases and creating multi-word-composite new words for them.
Re:Do Not Taunt Happy Fun Branch Predictor
by tmzt on Thursday January 26, 2023 @11:30AM
(#34533895)
Would that be feasible on something like iOS that doesn't allow third-party JIT?
Could this allow for translating WASM or emulator workloads to something that runs fast with those restrictions?
Re:Do Not Taunt Happy Fun Branch Predictor
by mncharity on Monday January 30, 2023 @11:43AM
(#34582335)
Re iOS, yes. But runs fast? The words have to be small enough that the branch misprediction penalty (order-10 cycles) is significant. So for example, if a word is a single 3 cycle op then the dispatch matters, but with a dependency chain just a few ops long, the potential win drops under 50%. And having multiple copies of words will increase pressure on the instruction cache, so there will be a tradeoff, which may or may not be a win. So... perhaps this could be a way to dynamically optimize loop interiors? Or... perhaps to permit low-cost register shuffling words to glue together larger words with varied hard-wired register expectations? Or... insert creative idea here? There are blog posts around where someone writes a simple vm and incrementally optimizes it. But I don't recall seeing one yet with an iOS-ish focus of no-JIT, lots of registers, modern branch prediction... and so throws creative stuff against the wall and measures if anything sticks. It might be interesting to take such a blog post/series and do a followup?
But generalized branch prediction is expensive (multiple entries in the BTB hashed by the previous program flow, and mispredicts if the next function in the chain changes); the point of an RAS is that it’s a very cheap way to keep some 100% predictable branches from using those general resources. Concatenation pretty much requires branches without unique characteristics, so no fast path shortcuts and everything is a bit slower.