←back to thread

49 points Bogdanp | 6 comments | | HN request time: 0.692s | source | bottom
1. nynx ◴[] No.44469206[source]
I must be missing something here. How would this help predict interpreter dispatch? Those won’t be a function of previous branch history or pc, which may very well be independent of the next opcode. They’d be a function of state in memory or registers.
replies(4): >>44469293 #>>44469360 #>>44469495 #>>44469524 #
2. achierius ◴[] No.44469293[source]
"very well may be" but oftentimes isn't. Branch history does in practice do a very good job of predicting what target you're going to take for an indirect branch.
replies(1): >>44469354 #
3. nynx ◴[] No.44469354[source]
Sure. I can easily see that often being the case for arbitrary code but not interpreter dispatch loops.
4. brigade ◴[] No.44469360[source]
In a hot loop, the next opcode can be predicted quite well from the history of previous opcodes executed, especially once have a couple iterations available in your history. And the opcodes executed in an interpreter are generally equivalent to the dispatch branch target.
5. saagarjha ◴[] No.44469495[source]
Interpreters are just like normal programs, but splatted out a bit. In particular, they have branches and loops just like normal programs. The challenge for processors is that these high level constructs are far apart and dispatched through an interpreter loop, which obfuscates them. Being able to reach further back in history lets you recover this kind of information "through" the intervening bits.
6. dzaima ◴[] No.44469524[source]
If your interpreter is interpreting a program with unpredictable branches, of course no predictor will magically make your interpreter get branches better predicted than an equivalent compiled program will.

The question here is about all other branching the interpreter will do. i.e. even if you have a unpredictable `if (a+b < 0)`, there's still the dispatching to the "load-variable" and "add" and "load-constant" and "less-than" and "do-branch" opcodes, that still will benefit from being predicted, and they could very well if you have it repeated in a loop (despite still having a single unpredictable branch), or potentially even if you just have a common pattern in the language (e.g. comparison opcodes being followed by a branch opcode).